Skip to contentSkip to conversation

Add asm-generic/io.h; virt_to_phys(), phys_to_virt() for all arches

PATCH New Paul Burton 3 participants 29 messages Sep 14, 2017 – Oct 3, 2017

Subsystems (11)
Arm (32-bit) x86 PowerPC MIPS +7 more subsystems
lore
Share & tools
lore
#0 lore raw

v2 cover Add asm-generic/io.h; virt_to_phys(), phys_to_virt() for all arches

This series introduces a new asm-generic/io.h header & makes use of it to reduce duplication between architectures & ensure they all consistently provide implementations of virt_to_phys() & phys_to_virt().

This was split out from an earlier series which goes on to use phys_to_virt(), in order to simplify the process of getting it merged by doing so piecemeal. The v1 patches can be seen at [1].

Thanks,
Paul

[1] https://patchwork.ozlabs.org/bundle/paulburton/old-asm-generic-io/?state=*

Paul Burton (13):
Provide a generic io.h & address mapping functions
arc: Use asm-generic/io.h
arm: Use asm-generic/io.h
m68k: Use asm-generic/io.h
microblaze: Use asm-generic/io.h
nds32: Use asm-generic/io.h
sh: Use asm-generic/io.h
x86: Use asm-generic/io.h
xtensa: Use asm-generic/io.h
mips: Use asm-generic/io.h
nios2: Use asm-generic/io.h
powerpc: Use asm-generic/io.h
sandbox: Use asm-generic/io.h

 arch/arc/include/asm/io.h        |  29 +----------
 arch/arm/include/asm/io.h        |  30 +----------
 arch/m68k/include/asm/io.h       |  29 +----------
 arch/microblaze/include/asm/io.h |  29 +----------
 arch/mips/include/asm/io.h       |  17 +++---
 arch/nds32/include/asm/io.h      |  32 ++----------
 arch/nios2/include/asm/io.h      |  15 +++---
 arch/powerpc/include/asm/io.h    |  25 ++-------
 arch/sandbox/cpu/cpu.c           |  12 ++++-
 arch/sandbox/include/asm/io.h    |  18 +++----
 arch/sh/include/asm/io.h         |  29 +----------
 arch/x86/include/asm/io.h        |  31 +----------
 arch/xtensa/include/asm/io.h     |  25 +--------
 include/asm-generic/io.h         | 110 +++++++++++++++++++++++++++++++++++++++
 14 files changed, 161 insertions(+), 270 deletions(-)
 create mode 100644 include/asm-generic/io.h
Signature · 1 line
2.14.1
#1 lore raw

PATCH v2 1/13 Provide a generic io.h & address mapping functions

Most architectures currently supported by U-Boot use trivial implementations of map_to_physmem & virt_to_phys which simply cast a physical address to a pointer for use a virtual address & vice-versa. This results in a lot of duplicate implementations of these mapping functions.

The set of functions provided by different architectures also differs, with some having implementations of phys_to_virt & others not. A later patch will make use of phys_to_virt in architecture-neutral code, and so requires that it be provided for all architectures.

This patch introduces an asm-generic/io.h which provides generic implementations of address mapping functions, allowing the duplication of them between architectures to be removed. Once architectures are converted to make use of this generic header it will also ensure that all of phys_to_virt, virt_to_phys, map_physmem & unmap_physmem are provided. The 2 families of functions differ in that map_physmem may create dynamic mappings whilst phys_to_virt may not & therefore is more limited in scope but doesn't require information such as a length & flags.

This patch doesn't convert any architectures to make use of this generic header - later patches in the series will do so.

Cc Albert Aribaud <[email protected]>
Cc Alexey Brodkin <[email protected]>
Cc Angelo Dureghello <[email protected]>
Cc Bin Meng <[email protected]>
Cc Daniel Schwierzeck <[email protected]>
Cc Macpaul Lin <[email protected]>
Cc Michal Simek <[email protected]>
Cc Nobuhiro Iwamatsu <[email protected]>
Cc Thomas Chou <[email protected]>
Cc Wolfgang Denk <[email protected]>

---

Changes in v2:
- Reformat map_physmem to split args across lines, rather than return type.

 include/asm-generic/io.h | 110 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 110 insertions(+)
 create mode 100644 include/asm-generic/io.h
include/asm-generic/io.h new file +110 -0
new file mode 100644
index 0000000000..0f5160c6f1
@@ -0,0 +1,110 @@
+/*
+ * Generic I/O functions.
+ *
+ * Copyright (c) 2016 Imagination Technologies Ltd.
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#ifndef __ASM_GENERIC_IO_H__
+#define __ASM_GENERIC_IO_H__
+
+/*
+ * This file should be included at the end of each architecture-specific
+ * asm/io.h such that we may provide generic implementations without
+ * conflicting with architecture-specific code.
+ */
+
+#ifndef __ASSEMBLY__
+
+/**
+ * phys_to_virt() - Return a virtual address mapped to a given physical address
+ * @paddr: the physical address
+ *
+ * Returns a virtual address which the CPU can access that maps to the physical
+ * address @paddr. This should only be used where it is known that no dynamic
+ * mapping is required. In general, map_physmem should be used instead.
+ *
+ * Returns: a virtual address which maps to @paddr
+ */
+#ifndef phys_to_virt
+static inline void *phys_to_virt(phys_addr_t paddr)
+{
+	return (void *)(unsigned long)paddr;
+}
+#endif
+
+/**
+ * virt_to_phys() - Return the physical address that a virtual address maps to
+ * @vaddr: the virtual address
+ *
+ * Returns the physical address which the CPU-accessible virtual address @vaddr
+ * maps to.
+ *
+ * Returns: the physical address which @vaddr maps to
+ */
+#ifndef virt_to_phys
+static inline phys_addr_t virt_to_phys(void *vaddr)
+{
+	return (phys_addr_t)((unsigned long)vaddr);
+}
+#endif
+
+/*
+ * Flags for use with map_physmem() & unmap_physmem(). Architectures need not
+ * support all of these, in which case they will be defined as zero here &
+ * ignored. Callers that may run on multiple architectures should therefore
+ * treat them as hints rather than requirements.
+ */
+#ifndef MAP_NOCACHE
+# define MAP_NOCACHE	0	/* Produce an uncached mapping */
+#endif
+#ifndef MAP_WRCOMBINE
+# define MAP_WRCOMBINE	0	/* Allow write-combining on the mapping */
+#endif
+#ifndef MAP_WRBACK
+# define MAP_WRBACK	0	/* Map using write-back caching */
+#endif
+#ifndef MAP_WRTHROUGH
+# define MAP_WRTHROUGH	0	/* Map using write-through caching */
+#endif
+
+/**
+ * map_physmem() - Return a virtual address mapped to a given physical address
+ * @paddr: the physical address
+ * @len: the length of the required mapping
+ * @flags: flags affecting the type of mapping
+ *
+ * Return a virtual address through which the CPU may access the memory at
+ * physical address @paddr. The mapping will be valid for at least @len bytes,
+ * and may be affected by flags passed to the @flags argument. This function
+ * may create new mappings, so should generally be paired with a matching call
+ * to unmap_physmem once the caller is finished with the memory in question.
+ *
+ * Returns: a virtual address suitably mapped to @paddr
+ */
+#ifndef map_physmem
+static inline void *map_physmem(phys_addr_t paddr, unsigned long len,
+				unsigned long flags)
+{
+	return phys_to_virt(paddr);
+}
+#endif
+
+/**
+ * unmap_physmem() - Remove mappings created by a prior call to map_physmem()
+ * @vaddr: the virtual address which map_physmem() previously returned
+ * @flags: flags matching those originally passed to map_physmem()
+ *
+ * Unmap memory which was previously mapped by a call to map_physmem(). If
+ * map_physmem() dynamically created a mapping for the memory in question then
+ * unmap_physmem() will remove that mapping.
+ */
+#ifndef unmap_physmem
+static inline void unmap_physmem(void *vaddr, unsigned long flags)
+{
+}
+#endif
+
+#endif /* !__ASSEMBLY__ */
+#endif /* __ASM_GENERIC_IO_H__ */
Signature · 1 line
2.14.1
#2 lore raw

PATCH v2 1/13 Provide a generic io.h & address mapping functions

Am 15.09.2017 um 00:05 schrieb Paul Burton:

Quoted 24 lines

Most architectures currently supported by U-Boot use trivial implementations of map_to_physmem & virt_to_phys which simply cast a physical address to a pointer for use a virtual address & vice-versa. This results in a lot of duplicate implementations of these mapping functions.

The set of functions provided by different architectures also differs, with some having implementations of phys_to_virt & others not. A later patch will make use of phys_to_virt in architecture-neutral code, and so requires that it be provided for all architectures.

This patch introduces an asm-generic/io.h which provides generic implementations of address mapping functions, allowing the duplication of them between architectures to be removed. Once architectures are converted to make use of this generic header it will also ensure that all of phys_to_virt, virt_to_phys, map_physmem & unmap_physmem are provided. The 2 families of functions differ in that map_physmem may create dynamic mappings whilst phys_to_virt may not & therefore is more limited in scope but doesn't require information such as a length & flags.

This patch doesn't convert any architectures to make use of this generic header - later patches in the series will do so.

Quoted 15 lines
Cc Albert Aribaud <[email protected]>
Cc Alexey Brodkin <[email protected]>
Cc Angelo Dureghello <[email protected]>
Cc Bin Meng <[email protected]>
Cc Daniel Schwierzeck <[email protected]>
Cc Macpaul Lin <[email protected]>
Cc Michal Simek <[email protected]>
Cc Nobuhiro Iwamatsu <[email protected]>
Cc Thomas Chou <[email protected]>
Cc Wolfgang Denk <[email protected]>
Signature · 1 line
- Daniel
#3 lore raw

PATCH v2 1/13 Provide a generic io.h & address mapping functions

In reply to Paul Burton
Quoted 24 lines · Paul Burton

Most architectures currently supported by U-Boot use trivial implementations of map_to_physmem & virt_to_phys which simply cast a physical address to a pointer for use a virtual address & vice-versa. This results in a lot of duplicate implementations of these mapping functions.

The set of functions provided by different architectures also differs, with some having implementations of phys_to_virt & others not. A later patch will make use of phys_to_virt in architecture-neutral code, and so requires that it be provided for all architectures.

This patch introduces an asm-generic/io.h which provides generic implementations of address mapping functions, allowing the duplication of them between architectures to be removed. Once architectures are converted to make use of this generic header it will also ensure that all of phys_to_virt, virt_to_phys, map_physmem & unmap_physmem are provided. The 2 families of functions differ in that map_physmem may create dynamic mappings whilst phys_to_virt may not & therefore is more limited in scope but doesn't require information such as a length & flags.

This patch doesn't convert any architectures to make use of this generic header - later patches in the series will do so.

Quoted 15 lines
Cc Albert Aribaud <[email protected]>
Cc Alexey Brodkin <[email protected]>
Cc Angelo Dureghello <[email protected]>
Cc Bin Meng <[email protected]>
Cc Daniel Schwierzeck <[email protected]>
Cc Macpaul Lin <[email protected]>
Cc Michal Simek <[email protected]>
Cc Nobuhiro Iwamatsu <[email protected]>
Cc Thomas Chou <[email protected]>
Cc Wolfgang Denk <[email protected]>

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20171003/7757e922/attachment.sig>
#4 lore raw

PATCH v2 2/13 arc: Use asm-generic/io.h

In reply to Paul Burton

Convert the arc architecture to make use of the new asm-generic/io.h to provide address mapping functions. As the generic implementations are suitable for arc this is primarily a matter of removing code.

Feedback from architecture maintainers is welcome.

---

Changes in v2: None

 arch/arc/include/asm/io.h | 29 +----------------------------
 1 file changed, 1 insertion(+), 28 deletions(-)
arch/arc/include/asm/io.h +1 -28
index 42e7f22b28..a12303bc73 100644
@@ -50,30 +50,6 @@
 #define __iowmb()		do { } while (0)
 #endif
 
-/*
- * Given a physical address and a length, return a virtual address
- * that can be used to access the memory range with the caching
- * properties specified by "flags".
- */
-#define MAP_NOCACHE	(0)
-#define MAP_WRCOMBINE	(0)
-#define MAP_WRBACK	(0)
-#define MAP_WRTHROUGH	(0)
-
-static inline void *
-map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags)
-{
-	return (void *)((unsigned long)paddr);
-}
-
-/*
- * Take down a mapping set up by map_physmem().
- */
-static inline void unmap_physmem(void *vaddr, unsigned long flags)
-{
-
-}
-
 static inline void sync(void)
 {
 	/* Not yet implemented */
@@ -302,9 +278,6 @@ static inline int __raw_writesl(unsigned int addr, void *data, int longlen)
 #define setbits_8(addr, set) setbits(8, addr, set)
 #define clrsetbits_8(addr, clear, set) clrsetbits(8, addr, clear, set)
 
-static inline phys_addr_t virt_to_phys(void *vaddr)
-{
-	return (phys_addr_t)((unsigned long)vaddr);
-}
+#include <asm-generic/io.h>
 
 #endif	/* __ASM_ARC_IO_H */
Signature · 1 line
2.14.1
#5 lore raw

PATCH v2 2/13 arc: Use asm-generic/io.h

Quoted 9 lines · Paul Burton

Convert the arc architecture to make use of the new asm-generic/io.h to provide address mapping functions. As the generic implementations are suitable for arc this is primarily a matter of removing code.

Feedback from architecture maintainers is welcome.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20171003/47fb0851/attachment.sig>
#6 lore raw

PATCH v2 3/13 arm: Use asm-generic/io.h

In reply to Paul Burton

Convert the arm architecture to make use of the new asm-generic/io.h to provide address mapping functions. As the generic implementations are suitable for arm this is primarily a matter of removing code.

This has only been build-tested, feedback from architecture maintainers is welcome.

---

Changes in v2: None

 arch/arm/include/asm/io.h | 30 +-----------------------------
 1 file changed, 1 insertion(+), 29 deletions(-)
arch/arm/include/asm/io.h +1 -29
index 5834f5b3dc..5df74728de 100644
@@ -34,35 +34,6 @@ static inline void sync(void)
 {
 }
 
-/*
- * Given a physical address and a length, return a virtual address
- * that can be used to access the memory range with the caching
- * properties specified by "flags".
- */
-#define MAP_NOCACHE	(0)
-#define MAP_WRCOMBINE	(0)
-#define MAP_WRBACK	(0)
-#define MAP_WRTHROUGH	(0)
-
-static inline void *
-map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags)
-{
-	return (void *)((unsigned long)paddr);
-}
-
-/*
- * Take down a mapping set up by map_physmem().
- */
-static inline void unmap_physmem(void *vaddr, unsigned long flags)
-{
-
-}
-
-static inline phys_addr_t virt_to_phys(void * vaddr)
-{
-	return (phys_addr_t)((unsigned long)vaddr);
-}
-
 /*
  * Generic virtual read/write.  Note that we don't support half-word
  * read/writes.  We define __arch_*[bl] here, and leave __arch_*w
@@ -426,6 +397,7 @@ out:
 #endif	/* __mem_isa */
 #endif	/* __KERNEL__ */
 
+#include <asm-generic/io.h>
 #include <iotrace.h>
 
 #endif	/* __ASM_ARM_IO_H */
Signature · 1 line
2.14.1
#7 lore raw

PATCH v2 3/13 arm: Use asm-generic/io.h

Quoted 10 lines · Paul Burton

Convert the arm architecture to make use of the new asm-generic/io.h to provide address mapping functions. As the generic implementations are suitable for arm this is primarily a matter of removing code.

This has only been build-tested, feedback from architecture maintainers is welcome.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20171003/014b10ec/attachment.sig>
#8 lore raw

PATCH v2 4/13 m68k: Use asm-generic/io.h

In reply to Paul Burton

Convert the m68k architecture to make use of the new asm-generic/io.h to provide address mapping functions. As the generic implementations are suitable for m68k this is primarily a matter of emoving code.

Feedback from architecture maintainers is welcome.

---

Changes in v2: None

 arch/m68k/include/asm/io.h | 29 +----------------------------
 1 file changed, 1 insertion(+), 28 deletions(-)
arch/m68k/include/asm/io.h +1 -28
index 384308b747..dfe77f0756 100644
@@ -253,33 +253,6 @@ static inline void sync(void)
 	 */
 }
 
-/*
- * Given a physical address and a length, return a virtual address
- * that can be used to access the memory range with the caching
- * properties specified by "flags".
- */
-#define MAP_NOCACHE	(0)
-#define MAP_WRCOMBINE	(0)
-#define MAP_WRBACK	(0)
-#define MAP_WRTHROUGH	(0)
-
-static inline void *map_physmem(phys_addr_t paddr, unsigned long len,
-				unsigned long flags)
-{
-	return (void *)paddr;
-}
-
-/*
- * Take down a mapping set up by map_physmem().
- */
-static inline void unmap_physmem(void *vaddr, unsigned long flags)
-{
-
-}
-
-static inline phys_addr_t virt_to_phys(void * vaddr)
-{
-	return (phys_addr_t)(vaddr);
-}
+#include <asm-generic/io.h>
 
 #endif				/* __ASM_M68K_IO_H__ */
Signature · 1 line
2.14.1
#9 lore raw

PATCH v2 4/13 m68k: Use asm-generic/io.h

Quoted 11 lines · Paul Burton

Convert the m68k architecture to make use of the new asm-generic/io.h to provide address mapping functions. As the generic implementations are suitable for m68k this is primarily a matter of emoving code.

Feedback from architecture maintainers is welcome.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20171003/ab1a9d27/attachment.sig>
#10 lore raw

PATCH v2 5/13 microblaze: Use asm-generic/io.h

In reply to Paul Burton

Convert the microblaze architecture to make use of the new asm-generic/io.h to provide address mapping functions. As the generic implementations are suitable for microblaze this is primarily a matter of removing code.

Feedback from architecture maintainers is welcome.

---

Changes in v2: None

 arch/microblaze/include/asm/io.h | 29 +----------------------------
 1 file changed, 1 insertion(+), 28 deletions(-)
arch/microblaze/include/asm/io.h +1 -28
index 584cbce358..c7516a47e8 100644
@@ -131,33 +131,6 @@ static inline void sync(void)
 {
 }
 
-/*
- * Given a physical address and a length, return a virtual address
- * that can be used to access the memory range with the caching
- * properties specified by "flags".
- */
-#define MAP_NOCACHE	(0)
-#define MAP_WRCOMBINE	(0)
-#define MAP_WRBACK	(0)
-#define MAP_WRTHROUGH	(0)
-
-static inline void *
-map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags)
-{
-	return (void *)paddr;
-}
-
-/*
- * Take down a mapping set up by map_physmem().
- */
-static inline void unmap_physmem(void *vaddr, unsigned long flags)
-{
-
-}
-
-static inline phys_addr_t virt_to_phys(void * vaddr)
-{
-	return (phys_addr_t)(vaddr);
-}
+#include <asm-generic/io.h>
 
 #endif /* __MICROBLAZE_IO_H__ */
Signature · 1 line
2.14.1
#11 lore raw

PATCH v2 5/13 microblaze: Use asm-generic/io.h

Quoted 9 lines · Paul Burton

Convert the microblaze architecture to make use of the new asm-generic/io.h to provide address mapping functions. As the generic implementations are suitable for microblaze this is primarily a matter of removing code.

Feedback from architecture maintainers is welcome.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20171003/f8e34624/attachment.sig>
#12 lore raw

PATCH v2 6/13 nds32: Use asm-generic/io.h

In reply to Paul Burton

Convert the nds32 architecture to make use of the new asm-generic/io.h to provide address mapping functions. As the generic implementations are suitable for nds32 this is primarily a matter of removing code.

Feedback from architecture maintainers is welcome.

---

Changes in v2: None

 arch/nds32/include/asm/io.h | 32 +++-----------------------------
 1 file changed, 3 insertions(+), 29 deletions(-)
arch/nds32/include/asm/io.h +3 -29
index b2c4d0ef8c..46ce8c4a13 100644
@@ -38,35 +38,6 @@ static inline void sync(void)
 {
 }
 
-/*
- * Given a physical address and a length, return a virtual address
- * that can be used to access the memory range with the caching
- * properties specified by "flags".
- */
-#define MAP_NOCACHE	(0)
-#define MAP_WRCOMBINE	(0)
-#define MAP_WRBACK	(0)
-#define MAP_WRTHROUGH	(0)
-
-static inline void *
-map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags)
-{
-	return (void *)paddr;
-}
-
-/*
- * Take down a mapping set up by map_physmem().
- */
-static inline void unmap_physmem(void *vaddr, unsigned long flags)
-{
-
-}
-
-static inline phys_addr_t virt_to_phys(void *vaddr)
-{
-	return (phys_addr_t)(vaddr);
-}
-
 /*
  * Generic virtual read/write.  Note that we don't support half-word
  * read/writes.  We define __arch_*[bl] here, and leave __arch_*w
@@ -459,5 +430,8 @@ out:
 #define isa_check_signature(io, sig, len)	(0)
 
 #endif	/* __mem_isa */
+
+#include <asm-generic/io.h>
+
 #endif	/* __KERNEL__ */
 #endif	/* __ASM_NDS_IO_H */
Signature · 1 line
2.14.1
#13 lore raw

PATCH v2 6/13 nds32: Use asm-generic/io.h

Quoted 8 lines · Paul Burton

Convert the nds32 architecture to make use of the new asm-generic/io.h to provide address mapping functions. As the generic implementations are suitable for nds32 this is primarily a matter of removing code.

Feedback from architecture maintainers is welcome.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20171003/ee562d6a/attachment.sig>
#14 lore raw

PATCH v2 7/13 sh: Use asm-generic/io.h

In reply to Paul Burton

Convert the sh architecture to make use of the new asm-generic/io.h to provide address mapping functions. As the generic implementations are suitable for sh this is primarily a matter of moving code.

Feedback from architecture maintainers is welcome.

Cc Nobuhiro Iwamatsu <[email protected]>

---

Changes in v2: None

 arch/sh/include/asm/io.h | 29 +----------------------------
 1 file changed, 1 insertion(+), 28 deletions(-)
arch/sh/include/asm/io.h +1 -28
index 5cb000cada..be1ff4ad70 100644
@@ -231,34 +231,7 @@ static inline void sync(void)
 #define setbits_8(addr, set) setbits(8, addr, set)
 #define clrsetbits_8(addr, clear, set) clrsetbits(8, addr, clear, set)
 
-/*
- * Given a physical address and a length, return a virtual address
- * that can be used to access the memory range with the caching
- * properties specified by "flags".
- */
-#define MAP_NOCACHE     (0)
-#define MAP_WRCOMBINE   (0)
-#define MAP_WRBACK      (0)
-#define MAP_WRTHROUGH   (0)
-
-static inline void *
-map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags)
-{
-	return (void *)paddr;
-}
-
-/*
- * Take down a mapping set up by map_physmem().
- */
-static inline void unmap_physmem(void *vaddr, unsigned long flags)
-{
-
-}
-
-static inline phys_addr_t virt_to_phys(void *vaddr)
-{
-	return (phys_addr_t)(vaddr);
-}
+#include <asm-generic/io.h>
 
 #endif	/* __KERNEL__ */
 #endif	/* __ASM_SH_IO_H */
Signature · 1 line
2.14.1
#15 lore raw

PATCH v2 7/13 sh: Use asm-generic/io.h

Quoted 8 lines · Paul Burton

Convert the sh architecture to make use of the new asm-generic/io.h to provide address mapping functions. As the generic implementations are suitable for sh this is primarily a matter of moving code.

Feedback from architecture maintainers is welcome.

Cc Nobuhiro Iwamatsu <[email protected]>

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20171003/ab09d30b/attachment.sig>
#16 lore raw

PATCH v2 8/13 x86: Use asm-generic/io.h

In reply to Paul Burton

Convert the x86 architecture to make use of the new asm-generic/io.h to provide address mapping functions. As the generic implementations are suitable for x86 this is primarily a matter of moving code.

This has only been build-tested, feedback from architecture maintainers is welcome.

---

Changes in v2: None

 arch/x86/include/asm/io.h | 31 ++-----------------------------
 1 file changed, 2 insertions(+), 29 deletions(-)
arch/x86/include/asm/io.h +2 -29
index a72daf2263..263dd8fd17 100644
@@ -230,35 +230,6 @@ static inline void sync(void)
 {
 }
 
-/*
- * Given a physical address and a length, return a virtual address
- * that can be used to access the memory range with the caching
- * properties specified by "flags".
- */
-#define MAP_NOCACHE	(0)
-#define MAP_WRCOMBINE	(0)
-#define MAP_WRBACK	(0)
-#define MAP_WRTHROUGH	(0)
-
-static inline void *
-map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags)
-{
-	return (void *)(uintptr_t)paddr;
-}
-
-/*
- * Take down a mapping set up by map_physmem().
- */
-static inline void unmap_physmem(void *vaddr, unsigned long flags)
-{
-
-}
-
-static inline phys_addr_t virt_to_phys(void * vaddr)
-{
-	return (phys_addr_t)(uintptr_t)(vaddr);
-}
-
 /*
  * TODO: The kernel offers some more advanced versions of barriers, it might
  * have some advantages to use them instead of the simple one here.
@@ -267,4 +238,6 @@ static inline phys_addr_t virt_to_phys(void * vaddr)
 #define __iormb()	dmb()
 #define __iowmb()	dmb()
 
+#include <asm-generic/io.h>
+
 #endif /* _ASM_IO_H */
Signature · 1 line
2.14.1
#17 lore raw

PATCH v2 8/13 x86: Use asm-generic/io.h

Quoted 10 lines · Paul Burton

Convert the x86 architecture to make use of the new asm-generic/io.h to provide address mapping functions. As the generic implementations are suitable for x86 this is primarily a matter of moving code.

This has only been build-tested, feedback from architecture maintainers is welcome.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20171003/b5ec148e/attachment.sig>
#18 lore raw

PATCH v2 9/13 xtensa: Use asm-generic/io.h

In reply to Paul Burton

Convert the xtensa architecture to make use of the new asm-generic/io.h to provide address mapping functions. As the generic implementations are suitable for xtensa this is primarily a matter of moving code.

This has only been build-tested, feedback from architecture maintainers is welcome.

---

Changes in v2: None

 arch/xtensa/include/asm/io.h | 25 ++-----------------------
 1 file changed, 2 insertions(+), 23 deletions(-)
arch/xtensa/include/asm/io.h +2 -23
index e34d6e1d7f..c9e335f4f6 100644
@@ -115,29 +115,6 @@ void outsl(unsigned long port, const void *src, unsigned long count);
  */
 #define xlate_dev_kmem_ptr(p)   p
 
-#define MAP_NOCACHE	(0)
-#define MAP_WRCOMBINE	(0)
-#define MAP_WRBACK	(0)
-#define MAP_WRTHROUGH	(0)
-
-static inline void *
-map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags)
-{
-	return (void *)paddr;
-}
-
-/*
- * Take down a mapping set up by map_physmem().
- */
-static inline void unmap_physmem(void *vaddr, unsigned long flags)
-{
-}
-
-static inline phys_addr_t virt_to_phys(void *vaddr)
-{
-	return (phys_addr_t)((unsigned long)vaddr);
-}
-
 /*
  * Dummy function to keep U-Boot's cfi_flash.c driver happy.
  */
@@ -145,4 +122,6 @@ static inline void sync(void)
 {
 }
 
+#include <asm-generic/io.h>
+
 #endif	/* _XTENSA_IO_H */
Signature · 1 line
2.14.1
#19 lore raw

PATCH v2 9/13 xtensa: Use asm-generic/io.h

Quoted 10 lines · Paul Burton

Convert the xtensa architecture to make use of the new asm-generic/io.h to provide address mapping functions. As the generic implementations are suitable for xtensa this is primarily a matter of moving code.

This has only been build-tested, feedback from architecture maintainers is welcome.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20171003/3fb3a5f9/attachment.sig>
#20 lore raw

PATCH v2 10/13 mips: Use asm-generic/io.h

In reply to Paul Burton

Convert the mips architecture to make use of the new asm-generic/io.h to provide address mapping functions. As mips actually performs non-identity mapping between physical & virtual addresses we can't simply make use of the generic functions, with the exception of being able to drop our no-op unmap_physmem() and definitions of unused map flags.

Cc Daniel Schwierzeck <[email protected]>

---

Changes in v2: None

 arch/mips/include/asm/io.h | 17 ++++++-----------
 1 file changed, 6 insertions(+), 11 deletions(-)
arch/mips/include/asm/io.h +6 -11
index ee7a59290d..45d7ca0cc6 100644
@@ -95,6 +95,7 @@ static inline unsigned long virt_to_phys(volatile const void *address)
 #endif
 	return CPHYSADDR(addr);
 }
+#define virt_to_phys virt_to_phys
 
 /*
  *     phys_to_virt    -       map physical address to virtual
@@ -112,6 +113,7 @@ static inline void *phys_to_virt(unsigned long address)
 {
 	return (void *)(address + PAGE_OFFSET - PHYS_OFFSET);
 }
+#define phys_to_virt phys_to_virt
 
 /*
  * ISA I/O bus memory addresses are 1:1 with the physical address.
@@ -490,10 +492,7 @@ static inline void memcpy_toio(volatile void __iomem *dst, const void *src, int
  */
 #define sync()		mmiowb()
 
-#define MAP_NOCACHE	(1)
-#define MAP_WRCOMBINE	(0)
-#define MAP_WRBACK	(0)
-#define MAP_WRTHROUGH	(0)
+#define MAP_NOCACHE	1
 
 static inline void *
 map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags)
@@ -503,13 +502,7 @@ map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags)
 
 	return (void *)CKSEG0ADDR(paddr);
 }
-
-/*
- * Take down a mapping set up by map_physmem().
- */
-static inline void unmap_physmem(void *vaddr, unsigned long flags)
-{
-}
+#define map_physmem map_physmem
 
 #define __BUILD_CLRBITS(bwlq, sfx, end, type)				\
 									\
@@ -566,4 +559,6 @@ BUILD_CLRSETBITS(q, le64, le64, u64)
 BUILD_CLRSETBITS(q, be64, be64, u64)
 BUILD_CLRSETBITS(q, 64, _, u64)
 
+#include <asm-generic/io.h>
+
 #endif /* _ASM_IO_H */
Signature · 1 line
2.14.1
#21 lore raw

PATCH v2 10/13 mips: Use asm-generic/io.h

Am 15.09.2017 um 00:05 schrieb Paul Burton:

Quoted 9 lines

Convert the mips architecture to make use of the new asm-generic/io.h to provide address mapping functions. As mips actually performs non-identity mapping between physical & virtual addresses we can't simply make use of the generic functions, with the exception of being able to drop our no-op unmap_physmem() and definitions of unused map flags.

Cc Daniel Schwierzeck <[email protected]>
Signature · 1 line
- Daniel
#22 lore raw

PATCH v2 10/13 mips: Use asm-generic/io.h

In reply to Paul Burton
Quoted 11 lines · Paul Burton

Convert the mips architecture to make use of the new asm-generic/io.h to provide address mapping functions. As mips actually performs non-identity mapping between physical & virtual addresses we can't simply make use of the generic functions, with the exception of being able to drop our no-op unmap_physmem() and definitions of unused map flags.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20171003/0dab801d/attachment.sig>
#23 lore raw

PATCH v2 11/13 nios2: Use asm-generic/io.h

In reply to Paul Burton

Convert the nios2 architecture to make use of the new asm-generic/io.h to provide address mapping functions. As nios2 actually performs non-identity mapping between physical & virtual addresses we can't simply make use of the generic functions, with the exception of being able to drop our no-op unmap_physmem() and definitions of unused map flags.

Feedback from architecture maintainers is welcome.

---

Changes in v2: None

 arch/nios2/include/asm/io.h | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
arch/nios2/include/asm/io.h +8 -7
index e951500190..4e5b44a4e4 100644
@@ -19,9 +19,6 @@ static inline void sync(void)
  * properties specified by "flags".
  */
 #define MAP_NOCACHE	1
-#define MAP_WRCOMBINE	0
-#define MAP_WRBACK	0
-#define MAP_WRTHROUGH	0
 
 static inline void *
 map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags)
@@ -32,20 +29,22 @@ map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags)
 	else
 		return (void *)(paddr | gd->arch.mem_region_base);
 }
+#define map_physmem map_physmem
 
-/*
- * Take down a mapping set up by map_physmem().
- */
-static inline void unmap_physmem(void *vaddr, unsigned long flags)
+static inline void *phys_to_virt(phys_addr_t paddr)
 {
+	DECLARE_GLOBAL_DATA_PTR;
 
+	return (void *)(paddr | gd->arch.mem_region_base);
 }
+#define phys_to_virt phys_to_virt
 
 static inline phys_addr_t virt_to_phys(void * vaddr)
 {
 	DECLARE_GLOBAL_DATA_PTR;
 	return (phys_addr_t)vaddr & gd->arch.physaddr_mask;
 }
+#define virt_to_phys virt_to_phys
 
 #define __raw_writeb(v,a)       (*(volatile unsigned char  *)(a) = (v))
 #define __raw_writew(v,a)       (*(volatile unsigned short *)(a) = (v))
@@ -171,4 +170,6 @@ static inline void outsl (unsigned long port, const void *src, unsigned long cou
 #define memcpy_fromio(a, b, c)		memcpy((a), (void *)(b), (c))
 #define memcpy_toio(a, b, c)		memcpy((void *)(a), (b), (c))
 
+#include <asm-generic/io.h>
+
 #endif /* __ASM_NIOS2_IO_H_ */
Signature · 1 line
2.14.1
#24 lore raw

PATCH v2 11/13 nios2: Use asm-generic/io.h

Quoted 11 lines · Paul Burton

Convert the nios2 architecture to make use of the new asm-generic/io.h to provide address mapping functions. As nios2 actually performs non-identity mapping between physical & virtual addresses we can't simply make use of the generic functions, with the exception of being able to drop our no-op unmap_physmem() and definitions of unused map flags.

Feedback from architecture maintainers is welcome.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20171003/cc2782da/attachment.sig>
#25 lore raw

PATCH v2 12/13 powerpc: Use asm-generic/io.h

In reply to Paul Burton

Convert the powerpc architecture to make use of the new asm-generic/io.h to provide address mapping functions. As powerpc can actually perform non-identity mapping between physical & virtual addresses we can't simply make use of the generic phys_to_virt() & virt_to_phys() functions. However since map_physmem() already effectively implemented the same thing as virt_to_phys() we can simply implement virt_to_phys() instead of map_physmem() & use the generic map_physmem(). We also drop the no-op unmap_physmem().

This has only been build-tested, feedback from architecture maintainers is welcome.

---

Changes in v2: None

 arch/powerpc/include/asm/io.h | 25 +++++--------------------
 1 file changed, 5 insertions(+), 20 deletions(-)
arch/powerpc/include/asm/io.h +5 -20
index a54fc468d5..34fbfdf1cf 100644
@@ -282,18 +282,7 @@ static inline void out_be32(volatile unsigned __iomem *addr, u32 val)
 #define setbits_8(addr, set) setbits(8, addr, set)
 #define clrsetbits_8(addr, clear, set) clrsetbits(8, addr, clear, set)
 
-/*
- * Given a physical address and a length, return a virtual address
- * that can be used to access the memory range with the caching
- * properties specified by "flags".
- */
-#define MAP_NOCACHE	(0)
-#define MAP_WRCOMBINE	(0)
-#define MAP_WRBACK	(0)
-#define MAP_WRTHROUGH	(0)
-
-static inline void *
-map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags)
+static inline void *phys_to_virt(phys_addr_t paddr)
 {
 #ifdef CONFIG_ADDR_MAP
 	return addrmap_phys_to_virt(paddr);
@@ -301,14 +290,7 @@ map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags)
 	return (void *)((unsigned long)paddr);
 #endif
 }
-
-/*
- * Take down a mapping set up by map_physmem().
- */
-static inline void unmap_physmem(void *vaddr, unsigned long flags)
-{
-
-}
+#define phys_to_virt phys_to_virt
 
 static inline phys_addr_t virt_to_phys(void * vaddr)
 {
@@ -318,5 +300,8 @@ static inline phys_addr_t virt_to_phys(void * vaddr)
 	return (phys_addr_t)((unsigned long)vaddr);
 #endif
 }
+#define virt_to_phys virt_to_phys
+
+#include <asm-generic/io.h>
 
 #endif
Signature · 1 line
2.14.1
#26 lore raw

PATCH v2 12/13 powerpc: Use asm-generic/io.h

Quoted 9 lines · Paul Burton

Convert the powerpc architecture to make use of the new asm-generic/io.h to provide address mapping functions. As powerpc can actually perform non-identity mapping between physical & virtual addresses we can't simply make use of the generic phys_to_virt() & virt_to_phys() functions. However since map_physmem() already effectively implemented the same thing as virt_to_phys() we can simply implement virt_to_phys() instead of map_physmem() & use the generic map_physmem(). We also drop the no-op unmap_physmem().

Quoted 5 lines

This has only been build-tested, feedback from architecture maintainers is welcome.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20171003/a26a4e60/attachment.sig>
#27 lore raw

PATCH v2 13/13 sandbox: Use asm-generic/io.h

In reply to Paul Burton

Convert the sandbox architecture to make use of the new asm-generic/io.h to provide address mapping functions. As sandbox actually performs non-identity mapping between physical & virtual addresses we can't simply make use of the generic mapping functions, but are able to implement phys_to_virt() & make use of it from map_physmem().

---

Changes in v2:
- Move include earlier to get MAP_WRBACK for (un)map_sysmem()
- Cast vaddr to uint8_t* in virt_to_phys() for arithmetic with ram_buf

 arch/sandbox/cpu/cpu.c        | 12 +++++++++++-
 arch/sandbox/include/asm/io.h | 18 +++++++++---------
 2 files changed, 20 insertions(+), 10 deletions(-)
arch/sandbox/cpu/cpu.c +11 -1
index 01991049cc..66c3a6a88a 100644
@@ -56,6 +56,16 @@ int cleanup_before_linux_select(int flags)
 	return 0;
 }
 
+void *phys_to_virt(phys_addr_t paddr)
+{
+	return (void *)(gd->arch.ram_buf + paddr);
+}
+
+phys_addr_t virt_to_phys(void *vaddr)
+{
+	return (phys_addr_t)((uint8_t *)vaddr - gd->arch.ram_buf);
+}
+
 void *map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags)
 {
 #if defined(CONFIG_PCI) && !defined(CONFIG_SPL_BUILD)
@@ -73,7 +83,7 @@ void *map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags)
 	}
 #endif
 
-	return (void *)(gd->arch.ram_buf + paddr);
+	return phys_to_virt(paddr);
 }
 
 void unmap_physmem(const void *vaddr, unsigned long flags)
arch/sandbox/include/asm/io.h +9 -9
index a6856356df..fd3c2478f7 100644
@@ -7,22 +7,22 @@
 #ifndef __SANDBOX_ASM_IO_H
 #define __SANDBOX_ASM_IO_H
 
-/*
- * Given a physical address and a length, return a virtual address
- * that can be used to access the memory range with the caching
- * properties specified by "flags".
- */
-#define MAP_NOCACHE	(0)
-#define MAP_WRCOMBINE	(0)
-#define MAP_WRBACK	(0)
-#define MAP_WRTHROUGH	(0)
+void *phys_to_virt(phys_addr_t paddr);
+#define phys_to_virt phys_to_virt
+
+phys_addr_t virt_to_phys(void *vaddr);
+#define virt_to_phys virt_to_phys
 
 void *map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags);
+#define map_physmem map_physmem
 
 /*
  * Take down a mapping set up by map_physmem().
  */
 void unmap_physmem(const void *vaddr, unsigned long flags);
+#define unmap_physmem unmap_physmem
+
+#include <asm-generic/io.h>
 
 /* For sandbox, we want addresses to point into our RAM buffer */
 static inline void *map_sysmem(phys_addr_t paddr, unsigned long len)
Signature · 1 line
2.14.1
#28 lore raw

PATCH v2 13/13 sandbox: Use asm-generic/io.h

Quoted 9 lines · Paul Burton

Convert the sandbox architecture to make use of the new asm-generic/io.h to provide address mapping functions. As sandbox actually performs non-identity mapping between physical & virtual addresses we can't simply make use of the generic mapping functions, but are able to implement phys_to_virt() & make use of it from map_physmem().

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20171003/767cda10/attachment.sig>