Skip to contentSkip to conversation

Clean up address mapping functions & CONFIG_SYS_SDRAM_BASE

PATCH Superseded Paul Burton 8 participants 46 messages Oct 1, 2016 – Nov 27, 2016

Subsystems (13)
Arm (32-bit) x86 PowerPC MIPS +9 more subsystems

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Clean up address mapping functions & CONFIG_SYS_SDRAM_BASE

README states that CONFIG_SYS_SDRAM_BASE should be the physical address of the base of SDRAM memory. This is expected by some code such as the PCI layer, which uses CONFIG_SYS_SDRAM_BASE to set up a region for system memory. Other code such as the image loading code used by bootm or the generic board_f.c expect CONFIG_SYS_SDRAM_BASE to be directly accessible by the CPU, which necessitates that it be a virtual address.

Where virtual & physical addresses aren't identity mapped, as is the case for MIPS, we cannot possibly satisfy both. Until now MIPS has used a virtual CONFIG_SYS_SDRAM_BASE. This series fixes up the mess by doing a few things:

- Ensuring that we provide virt_to_phys() on all architectures.

- Fixing code that expects to use CONFIG_SYS_SDRAM_BASE as a virtual address to instead convert it to a physical address using virt_to_phys().

- Converts MIPS code & all MIPS boards to provide a physical CONFIG_SYS_SDRAM_BASE, which typically is zero.

Paul Burton (27):
Provide a generic io.h & address mapping functions
arc: Use asm-generic/io.h
arm: Use asm-generic/io.h
blackfin: Use asm-generic/io.h
m68k: Use asm-generic/io.h
microblaze: Use asm-generic/io.h
nds32: Use asm-generic/io.h
openrisc: Use asm-generic/io.h
sh: Use asm-generic/io.h
sparc: Use asm-generic/io.h
x86: Use asm-generic/io.h
xtensa: Use asm-generic/io.h
mips: Use asm-generic/io.h
mips: Fix map_physmem for cached mappings
nios2: Use asm-generic/io.h
powerpc: Use asm-generic/io.h
sandbox: Use asm-generic/io.h
board_f: Account for CONFIG_SYS_SDRAM_BASE being physical
image: Account for CONFIG_SYS_SDRAM_BASE being physical
image: Use ram_top, not bi_memsize, in getenv_bootm_size
mips: Use ram_top, not bi_memsize, in arch_lmb_reserve
mips: Ensure stack is at a virtual address
boston: Provide physical CONFIG_SYS_SDRAM_BASE
malta: Use a physical CONFIG_SYS_SDRAM_BASE
xilfpga: Use a physical CONFIG_SYS_SDRAM_BASE
mips: Use a physical CONFIG_SYS_SDRAM_BASE for remaining boards
mips: Remove virt_to_phys call on bi_memstart

 arch/arc/include/asm/io.h        |  29 +----------
 arch/arm/include/asm/io.h        |  30 +----------
 arch/blackfin/include/asm/io.h   |  31 +----------
 arch/m68k/include/asm/io.h       |  29 +----------
 arch/microblaze/include/asm/io.h |  29 +----------
 arch/mips/cpu/start.S            |   3 +-
 arch/mips/include/asm/io.h       |  19 +++----
 arch/mips/lib/bootm.c            |   4 +-
 arch/nds32/include/asm/io.h      |  32 ++----------
 arch/nios2/include/asm/io.h      |  15 +++---
 arch/openrisc/include/asm/io.h   |  35 +------------
 arch/powerpc/include/asm/io.h    |  25 ++-------
 arch/sandbox/cpu/cpu.c           |  12 ++++-
 arch/sandbox/include/asm/io.h    |  17 +++---
 arch/sh/include/asm/io.h         |  29 +----------
 arch/sparc/include/asm/io.h      |  30 +----------
 arch/x86/include/asm/io.h        |  31 +----------
 arch/xtensa/include/asm/io.h     |  25 +--------
 board/imgtec/boston/ddr.c        |   8 +--
 common/board_f.c                 |   4 +-
 common/image.c                   |   6 +--
 include/asm-generic/io.h         | 110 +++++++++++++++++++++++++++++++++++++++
 include/configs/ap121.h          |   2 +-
 include/configs/ap143.h          |   2 +-
 include/configs/boston.h         |  21 ++++----
 include/configs/dbau1x00.h       |   2 +-
 include/configs/imgtec_xilfpga.h |   4 +-
 include/configs/malta.h          |  18 ++++---
 include/configs/pb1x00.h         |   2 +-
 include/configs/pic32mzdask.h    |   2 +-
 include/configs/qemu-mips.h      |   2 +-
 include/configs/qemu-mips64.h    |   2 +-
 include/configs/tplink_wdr4300.h |   2 +-
 include/configs/vct.h            |   2 +-
 34 files changed, 208 insertions(+), 406 deletions(-)
 create mode 100644 include/asm-generic/io.h
Signature · 1 line
2.10.0
#1 lore raw

PATCH 1/27 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 functions provided by different architectures also differs, with some having implementations of phys_to_virt & others not. A later patch in this series will make use of phys_to_virt, 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 Alison Wang <[email protected]>
Cc Angelo Dureghello <[email protected]>
Cc Bin Meng <[email protected]>
Cc Daniel Schwierzeck <[email protected]>
Cc Francois Retief <[email protected]>
Cc Macpaul Lin <[email protected]>
Cc Michal Simek <[email protected]>
Cc Mike Frysinger <[email protected]>
Cc Nobuhiro Iwamatsu <[email protected]>
Cc Scott McNutt <[email protected]>
Cc Sonic Zhang <[email protected]>
Cc Thomas Chou <[email protected]>
Cc Wolfgang Denk <[email protected]>

---

 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 0000000..dd3a46d
@@ -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.10.0
#2 lore raw

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

Hi Paul,

Quoted 153 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 functions provided by different architectures also differs, with some having implementations of phys_to_virt & others not. A later patch in this series will make use of phys_to_virt, 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 Alison Wang <[email protected]>
Cc Angelo Dureghello <[email protected]>
Cc Bin Meng <[email protected]>
Cc Daniel Schwierzeck <[email protected]>
Cc Francois Retief <[email protected]>
Cc Macpaul Lin <[email protected]>
Cc Michal Simek <[email protected]>
Cc Mike Frysinger <[email protected]>
Cc Nobuhiro Iwamatsu <[email protected]>
Cc Scott McNutt <[email protected]>
Cc Sonic Zhang <[email protected]>
Cc Thomas Chou <[email protected]>
Cc Wolfgang Denk <[email protected]>

---

 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 +100 -0
new file mode 100644
index 0000000..dd3a46d
@@ -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

include/asm-generic/io.h line 110

Quoted 10 lines
include/asm-generic/io.h new file +10 -0
+ * 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__ */

tested on mcf5307 amcore board, (that btw is not using those functions), tested buildall for m68k boards,

many thanks,
Best regards,
Angelo Dureghello

#3 lore raw

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

In reply to Paul Burton

Hi Paul,

Quoted 40 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 functions provided by different architectures also differs, with some having implementations of phys_to_virt & others not. A later patch in this series will make use of phys_to_virt, 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 Alison Wang <[email protected]>
Cc Angelo Dureghello <[email protected]>
Cc Bin Meng <[email protected]>
Cc Daniel Schwierzeck <[email protected]>
Cc Francois Retief <[email protected]>
Cc Macpaul Lin <[email protected]>
Cc Michal Simek <[email protected]>
Cc Mike Frysinger <[email protected]>
Cc Nobuhiro Iwamatsu <[email protected]>
Cc Scott McNutt <[email protected]>
Cc Sonic Zhang <[email protected]>
Cc Thomas Chou <[email protected]>
Cc Wolfgang Denk <[email protected]>
Quoted 5 lines

---

 include/asm-generic/io.h | 110 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 110 insertions(+)
 create mode 100644 include/asm-generic/io.h

Question and nits below.

Quoted 20 lines
include/asm-generic/io.h new file +13 -0
new file mode 100644
index 0000000..dd3a46d
@@ -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

include/asm-generic/io.h line 23

Quoted 10 lines
include/asm-generic/io.h new file +10 -0
+ * 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
+ *

@return

include/asm-generic/io.h line 28

Quoted 5 lines
include/asm-generic/io.h new file +5 -0
+ * 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

Why two Returns?

include/asm-generic/io.h line 40

Quoted 12 lines
include/asm-generic/io.h new file +12 -0
+ */
+#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
+ *

@return

include/asm-generic/io.h line 44

Quoted 4 lines
include/asm-generic/io.h new file +4 -0
+ * Returns the physical address which the CPU-accessible virtual address @vaddr
+ * maps to.
+ *
+ * Returns: the physical address which @vaddr maps to

Why two Returns?

Quoted 16 lines
include/asm-generic/io.h new file +16 -0
+ */
+#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 */

include/asm-generic/io.h line 70

Quoted 10 lines
include/asm-generic/io.h new file +10 -0
+#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

It seems odd to make these 0 when not supported. How could an arch know that it was requested, and then complain when an unsupported flag is passed?

include/asm-generic/io.h line 76

Quoted 6 lines
include/asm-generic/io.h new file +6 -0
+
+/**
+ * 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

include/asm-generic/io.h line 83

Quoted 7 lines
include/asm-generic/io.h new file +7 -0
+ *
+ * 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.
+ *

@return

include/asm-generic/io.h line 88

Quoted 5 lines
include/asm-generic/io.h new file +5 -0
+ * 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)

Can you join those two lines and wrap the args if needed??

Quoted 23 lines
include/asm-generic/io.h new file +22 -1
+{
+       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__ */
--
Quoted 2 lines

2.10.0

REgards,
Simon

#4 lore raw

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

Quoted 77 lines · On Monday, 3 October 2016 15:49:33 GMT Simon Glass wrote:

Hi Paul,

Quoted 40 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 functions provided by different architectures also differs, with some having implementations of phys_to_virt & others not. A later patch in this series will make use of phys_to_virt, 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 Alison Wang <[email protected]>
Cc Angelo Dureghello <[email protected]>
Cc Bin Meng <[email protected]>
Cc Daniel Schwierzeck <[email protected]>
Cc Francois Retief <[email protected]>
Cc Macpaul Lin <[email protected]>
Cc Michal Simek <[email protected]>
Cc Mike Frysinger <[email protected]>
Cc Nobuhiro Iwamatsu <[email protected]>
Cc Scott McNutt <[email protected]>
Cc Sonic Zhang <[email protected]>
Cc Thomas Chou <[email protected]>
Cc Wolfgang Denk <[email protected]>
Quoted 6 lines

---

 include/asm-generic/io.h | 110
 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110
 insertions(+)
 create mode 100644 include/asm-generic/io.h

Question and nits below.

Quoted 23 lines
include/asm-generic/io.h new file +17 -0
new file mode 100644
index 0000000..dd3a46d
@@ -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.
+ */
+
Quoted 8 lines
Quoted 6 lines
include/asm-generic/io.h new file +4 -0
+#ifndef __ASSEMBLY__
+
+/**
+ * phys_to_virt() - Return a virtual address mapped to a given physical

address + * @paddr: the physical address
+ *

@return

Hi Simon,

I was under the impression that we're following the kernel-doc style, both based on the style of existing comments & the statement from the CodingStyle page of the wiki:

U-Boot adopted the kernel-doc annotation style, this is the only exception from multi-line comment rule of Coding Style. While not mandatory, adding documentation is strongly advised. The Linux kernel kernel-doc document applies with no changes.

(From http://www.denx.de/wiki/U-Boot/CodingStyle)

The kernel-doc-nano-HOWTO.txt file linked to from that wiki paragraph & included in the Linux kernel source shows this example:

/**
* foobar() - short function description of foobar
* @arg1: Describe the first argument to foobar.
* @arg2: Describe the second argument to foobar.
* One can provide multiple line descriptions
* for arguments.
*
* A longer description, with more discussion of the function foobar()
* that might be useful to those using or modifying it. Begins with
* empty comment line, and may include additional embedded empty
* comment lines.
*
* The longer description can have multiple paragraphs.
*
* Return: Describe the return value of foobar.
*/

Nowhere does it use @return & that's not what's done in Linux, so my belief is that having a "Return:" line at the end of the comment is the right way.

Quoted 8 lines
Quoted 6 lines

+ * 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

Why two Returns?

The first is just a part of the paragraph explaining what the function does. I could start it with "This function returns" if you really want, but I don't see as that makes it any clearer. The second is the kernel-doc style description of what the function returns, as described above.

Quoted 15 lines
Quoted 11 lines

+ */

include/asm-generic/io.h new file +9 -0
+#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
Quoted 2 lines

maps to + * @vaddr: the virtual address
+ *

@return

Ditto.

Quoted 7 lines
Quoted 5 lines

+ * Returns the physical address which the CPU-accessible virtual address @vaddr + * maps to.
+ *
+ * Returns: the physical address which @vaddr maps to

Why two Returns?

Ditto.

Quoted 23 lines
Quoted 23 lines

+ */

include/asm-generic/io.h new file +9 -0
+#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.
+ */

include/asm-generic/io.h new file +8 -0
+#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 */
Quoted 8 lines

include/asm-generic/io.h line 70

Quoted 4 lines
include/asm-generic/io.h new file +4 -0
+#endif
+#ifndef MAP_WRTHROUGH
+# define MAP_WRTHROUGH 0       /* Map using write-through caching */
+#endif

It seems odd to make these 0 when not supported. How could an arch know that it was requested, and then complain when an unsupported flag is passed?

That's true, it couldn't unless it explicitly defined ones that it doesn't support. Given that architectures already #define each of the above to 0 in the cases that they don't support this doesn't change that problem though. I'd suggest that we improve this separately, otherwise we'd risk this change breaking anything which sets flags that some architectures might simply want to ignore.

Quoted 9 lines
Quoted 7 lines
include/asm-generic/io.h new file +3 -0
+
+/**
+ * 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

See above.

Quoted 11 lines
Quoted 9 lines

+ *
+ * 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. + *

@return

Ditto.

Quoted 8 lines

include/asm-generic/io.h line 88

Quoted 6 lines

+ * Returns: a virtual address suitably mapped to @paddr
+ */

include/asm-generic/io.h new file +3 -0
+#ifndef map_physmem
+static inline void *
+map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags)

Can you join those two lines and wrap the args if needed??

Sure.

Thanks,
Paul

Quoted 21 lines
Quoted 21 lines
include/asm-generic/io.h new file +7 -0
+{
+       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.
+ */

include/asm-generic/io.h new file +5 -0
+#ifndef unmap_physmem
+static inline void unmap_physmem(void *vaddr, unsigned long flags)
+{
+}
+#endif
Quoted 8 lines
Quoted 5 lines
include/asm-generic/io.h new file +3 -1
+
+#endif /* !__ASSEMBLY__ */
+#endif /* __ASM_GENERIC_IO_H__ */
--

2.10.0

REgards,
Simon

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20161117/27cd0ef4/attachment.sig>

#5 lore raw

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

Hi Paul,

Quoted 120 lines · Paul Burton
Quoted 77 lines · On Monday, 3 October 2016 15:49:33 GMT Simon Glass wrote:

Hi Paul,

Quoted 40 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 functions provided by different architectures also differs, with some having implementations of phys_to_virt & others not. A later patch in this series will make use of phys_to_virt, 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 Alison Wang <[email protected]>
Cc Angelo Dureghello <[email protected]>
Cc Bin Meng <[email protected]>
Cc Daniel Schwierzeck <[email protected]>
Cc Francois Retief <[email protected]>
Cc Macpaul Lin <[email protected]>
Cc Michal Simek <[email protected]>
Cc Mike Frysinger <[email protected]>
Cc Nobuhiro Iwamatsu <[email protected]>
Cc Scott McNutt <[email protected]>
Cc Sonic Zhang <[email protected]>
Cc Thomas Chou <[email protected]>
Cc Wolfgang Denk <[email protected]>
Quoted 6 lines

---

 include/asm-generic/io.h | 110
 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110
 insertions(+)
 create mode 100644 include/asm-generic/io.h

Question and nits below.

Quoted 23 lines
include/asm-generic/io.h new file +17 -0
new file mode 100644
index 0000000..dd3a46d
@@ -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.
+ */
+
Quoted 8 lines
Quoted 6 lines
include/asm-generic/io.h new file +4 -0
+#ifndef __ASSEMBLY__
+
+/**
+ * phys_to_virt() - Return a virtual address mapped to a given physical

address + * @paddr: the physical address
+ *

@return

Hi Simon,

I was under the impression that we're following the kernel-doc style, both based on the style of existing comments & the statement from the CodingStyle page of the wiki:

U-Boot adopted the kernel-doc annotation style, this is the only exception from multi-line comment rule of Coding Style. While not mandatory, adding documentation is strongly advised. The Linux kernel kernel-doc document applies with no changes.

(From http://www.denx.de/wiki/U-Boot/CodingStyle)

The kernel-doc-nano-HOWTO.txt file linked to from that wiki paragraph & included in the Linux kernel source shows this example:

/**
* foobar() - short function description of foobar

   * @arg1:     Describe the first argument to foobar.
   * @arg2:     Describe the second argument to foobar.
   *            One can provide multiple line descriptions
   *            for arguments.

*
* A longer description, with more discussion of the function foobar()
* that might be useful to those using or modifying it. Begins with
* empty comment line, and may include additional embedded empty
* comment lines.
*
* The longer description can have multiple paragraphs.
*
* Return: Describe the return value of foobar.
*/

Quoted 2 lines

Nowhere does it use @return & that's not what's done in Linux, so my belief is that having a "Return:" line at the end of the comment is the right way.

Well there are about 900 instances of @return in Linux and U-Boot has both as well. Does the docbook tool decode 'Returns' just as well as @return?

Regards,
Simon

#6 lore raw

PATCH 2/27 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.

Cc Alexey Brodkin <[email protected]>

---

 arch/arc/include/asm/io.h | 29 +----------------------------
 1 file changed, 1 insertion(+), 28 deletions(-)
arch/arc/include/asm/io.h +1 -28
index 42e7f22..a12303b 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.10.0
#7 lore raw

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

Hi Paul,

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.

Cc Alexey Brodkin <[email protected]>

---

This is a very welcome patch really!
I've been thinking about it since the submission of ARC port but was so lazy to do all that hard work.

So thanks for doing that and

#8 lore raw

PATCH 3/27 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.

Cc Albert Aribaud <[email protected]>

---

 arch/arm/include/asm/io.h | 30 +-----------------------------
 1 file changed, 1 insertion(+), 29 deletions(-)
arch/arm/include/asm/io.h +1 -29
index 5834f5b..5df7472 100644
@@ -35,35 +35,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
  * to the architecture specific code.
@@ -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.10.0
#9 lore raw

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

Quoted 7 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.

Quoted 6 lines
Cc Albert Aribaud <[email protected]>

---

 arch/arm/include/asm/io.h | 30 +-----------------------------
 1 file changed, 1 insertion(+), 29 deletions(-)
#10 lore raw

PATCH 4/27 blackfin: Use asm-generic/io.h

In reply to Paul Burton

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

Feedback from architecture maintainers is welcome.

---

 arch/blackfin/include/asm/io.h | 31 ++-----------------------------
 1 file changed, 2 insertions(+), 29 deletions(-)
arch/blackfin/include/asm/io.h +2 -29
index d3337e4..dad8ac6 100644
@@ -20,35 +20,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);
-}
-
-/*
  * These are for ISA/PCI shared memory _only_ and should never be used
  * on any other type of memory, including Zorro memory. They are meant to
  * access the bus in the bus byte order which is little-endian!.
@@ -223,6 +194,8 @@ extern void cf_outb(unsigned char val, volatile unsigned char *addr);
 
 #endif
 
+#include <asm-generic/io.h>
+
 #endif				/* __KERNEL__ */
 
 #endif
Signature · 1 line
2.10.0
#11 lore raw

PATCH 5/27 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.

Cc Huan Wang <[email protected]>
Cc Angelo Dureghello <[email protected]>

---

 arch/m68k/include/asm/io.h | 29 +----------------------------
 1 file changed, 1 insertion(+), 28 deletions(-)
arch/m68k/include/asm/io.h +1 -28
index 384308b..dfe77f0 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.10.0
#12 lore raw

PATCH 5/27 m68k: Use asm-generic/io.h

Dear Paul,

Quoted 44 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.

Cc Huan Wang <[email protected]>
Cc Angelo Dureghello <[email protected]>

---

 arch/m68k/include/asm/io.h | 29 +----------------------------
 1 file changed, 1 insertion(+), 28 deletions(-)
arch/m68k/include/asm/io.h +0 -21
index 384308b..dfe77f0 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)
-{

arch/m68k/include/asm/io.h static inline void sync(void) · line 258

Quoted 10 lines
arch/m68k/include/asm/io.h +1 -7
-
-}
-
-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__ */

tested on mcf5307 amcore board.

many thanks,
Best regards,
Angelo Dureghello

#13 lore raw

PATCH 6/27 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.

---

 arch/microblaze/include/asm/io.h | 29 +----------------------------
 1 file changed, 1 insertion(+), 28 deletions(-)
arch/microblaze/include/asm/io.h +1 -28
index 584cbce..c7516a4 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.10.0
#14 lore raw

PATCH 7/27 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.

---

 arch/nds32/include/asm/io.h | 32 +++-----------------------------
 1 file changed, 3 insertions(+), 29 deletions(-)
arch/nds32/include/asm/io.h +3 -29
index b2c4d0e..46ce8c4 100644
@@ -39,35 +39,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
  * to the architecture specific code.
@@ -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.10.0
#15 lore raw

PATCH 8/27 openrisc: Use asm-generic/io.h

In reply to Paul Burton

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

Feedback from architecture maintainers is welcome.

Cc Stefan Kristiansson <[email protected]>

---

 arch/openrisc/include/asm/io.h | 35 ++---------------------------------
 1 file changed, 2 insertions(+), 33 deletions(-)
arch/openrisc/include/asm/io.h +2 -33
index 86fbbc4..45c41b7 100644
@@ -8,39 +8,6 @@
 #define __ASM_OPENRISC_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)
-
-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)
-{
-
-}
-
-/*
- * Change virtual addresses to physical addresses
- */
-static inline phys_addr_t virt_to_phys(void *vaddr)
-{
-	return (phys_addr_t)(vaddr);
-}
-
-
-/*
  * readX/writeX() are used to access memory mapped devices. On some
  * architectures the memory mapped IO stuff needs to be accessed
  * differently. On the openrisc architecture, we just read/write the
@@ -96,4 +63,6 @@ static inline phys_addr_t virt_to_phys(void *vaddr)
 #define iowrite16(v, addr)	writew((v), (addr))
 #define iowrite32(v, addr)	writel((v), (addr))
 
+#include <asm-generic/io.h>
+
 #endif
Signature · 1 line
2.10.0
#16 lore raw

PATCH 9/27 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]>

---

 arch/sh/include/asm/io.h | 29 +----------------------------
 1 file changed, 1 insertion(+), 28 deletions(-)
arch/sh/include/asm/io.h +1 -28
index 5dc27be..2847d8d 100644
@@ -241,34 +241,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.10.0
#17 lore raw

PATCH 9/27 sh: Use asm-generic/io.h

Quoted 3 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.

I'll try to find time and test this change on top of my fixes during the weekend.

Quoted 1 line

Feedback from architecture maintainers is welcome.

The unmodified U-boot from the last two releases can not run on any SH board, you can consider that SH arch is unmaintained.

Quoted 3 lines
Cc Nobuhiro Iwamatsu <[email protected]>

---

--
Best wishes,
Vladimir

#18 lore raw

PATCH 9/27 sh: Use asm-generic/io.h

In reply to Paul Burton
Quoted 10 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]>

---

Thank you for the change.

--
With best wishes,
Vladimir

#19 lore raw

PATCH 10/27 sparc: Use asm-generic/io.h

In reply to Paul Burton

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

Feedback from architecture maintainers is welcome.

---

 arch/sparc/include/asm/io.h | 30 +-----------------------------
 1 file changed, 1 insertion(+), 29 deletions(-)
arch/sparc/include/asm/io.h +1 -29
index a317d13..08ec7d5 100644
@@ -63,34 +63,6 @@
 #define readl				__raw_readl
 #define readq				__raw_readq
 
-/*
- * 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
Signature · 1 line
2.10.0
#20 lore raw

PATCH 11/27 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.

---

 arch/x86/include/asm/io.h | 31 ++-----------------------------
 1 file changed, 2 insertions(+), 29 deletions(-)
arch/x86/include/asm/io.h +2 -29
index 3156781..6f29a73 100644
@@ -289,35 +289,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.
  */
@@ -325,4 +296,6 @@ static inline phys_addr_t virt_to_phys(void * vaddr)
 #define __iormb()	dmb()
 #define __iowmb()	dmb()
 
+#include <asm-generic/io.h>
+
 #endif
Signature · 1 line
2.10.0
#21 lore raw

PATCH 11/27 x86: Use asm-generic/io.h

Quoted 7 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.

Quoted 6 lines

---

 arch/x86/include/asm/io.h | 31 ++-----------------------------
 1 file changed, 2 insertions(+), 29 deletions(-)
#22 lore raw

PATCH 12/27 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.

---

 arch/xtensa/include/asm/io.h | 25 ++-----------------------
 1 file changed, 2 insertions(+), 23 deletions(-)
arch/xtensa/include/asm/io.h +2 -23
index e34d6e1..c9e335f 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.10.0
maintainer
#23 lore raw

PATCH 12/27 xtensa: Use asm-generic/io.h

Quoted 7 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.

Quoted 6 lines

---

 arch/xtensa/include/asm/io.h | 25 ++-----------------------
 1 file changed, 2 insertions(+), 23 deletions(-)
Signature · 2 lines
Thanks.
-- Max
#24 lore raw

PATCH 13/27 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]>

---

 arch/mips/include/asm/io.h | 17 ++++++-----------
 1 file changed, 6 insertions(+), 11 deletions(-)
arch/mips/include/asm/io.h +6 -11
index 5b86386..be9616a 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 *)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.10.0
#25 lore raw

PATCH 14/27 mips: Fix map_physmem for cached mappings

In reply to Paul Burton

map_physmem should return a pointer that can be used by the CPU to access the given memory - on MIPS simply returning the physical address as it does prior to this patch doesn't achieve that. Instead return a pointer to the memory within (c)kseg0, which matches up consistently with the (c)kseg1 pointer that uncached mappings return via ioremap.

Cc Daniel Schwierzeck <[email protected]>

---

 arch/mips/include/asm/io.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/mips/include/asm/io.h +1 -1
index be9616a..45d7ca0 100644
@@ -500,7 +500,7 @@ map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags)
 	if (flags == MAP_NOCACHE)
 		return ioremap(paddr, len);
 
-	return (void *)paddr;
+	return (void *)CKSEG0ADDR(paddr);
 }
 #define map_physmem map_physmem
 
Signature · 1 line
2.10.0
#26 lore raw

PATCH 15/27 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.

---

 arch/nios2/include/asm/io.h | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
arch/nios2/include/asm/io.h +8 -7
index e951500..4e5b44a 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.10.0
#27 lore raw

PATCH 16/27 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.

---

 arch/powerpc/include/asm/io.h | 25 +++++--------------------
 1 file changed, 5 insertions(+), 20 deletions(-)
arch/powerpc/include/asm/io.h +5 -20
index a54fc46..34fbfdf 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.10.0
#28 lore raw

PATCH 17/27 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().

---

 arch/sandbox/cpu/cpu.c        | 12 +++++++++++-
 arch/sandbox/include/asm/io.h | 17 ++++++++---------
 2 files changed, 19 insertions(+), 10 deletions(-)
arch/sandbox/cpu/cpu.c +11 -1
index 2def722..e160f62 100644
@@ -55,6 +55,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)(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)
@@ -72,7 +82,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 +8 -9
index 6919632..3afbcea 100644
@@ -7,22 +7,20 @@
 #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
 
 /* For sandbox, we want addresses to point into our RAM buffer */
 static inline void *map_sysmem(phys_addr_t paddr, unsigned long len)
@@ -71,6 +69,7 @@ static inline void _outsw(volatile u16 *port, const void *buf, int ns)
 #define out16(addr, val)
 #define in16(addr)		0
 
+#include <asm-generic/io.h>
 #include <iotrace.h>
 #include <asm/types.h>
 
Signature · 1 line
2.10.0
#29 lore raw

PATCH 17/27 sandbox: Use asm-generic/io.h

Quoted 6 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().

Quoted 7 lines

---

 arch/sandbox/cpu/cpu.c        | 12 +++++++++++-
 arch/sandbox/include/asm/io.h | 17 ++++++++---------
 2 files changed, 19 insertions(+), 10 deletions(-)
#30 lore raw

PATCH 17/27 sandbox: Use asm-generic/io.h

In reply to Paul Burton
Quoted 5 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().

[snip]

arch/sandbox/cpu/cpu.c int cleanup_before_linux_select(int flags) · line 65

Quoted 3 lines
arch/sandbox/cpu/cpu.c +3 -0
+phys_addr_t virt_to_phys(void *vaddr)
+{
+	return (phys_addr_t)(vaddr - gd->arch.ram_buf);

../arch/sandbox/cpu/cpu.c: In function ?virt_to_phys?:
../arch/sandbox/cpu/cpu.c:65:29: error: invalid operands to binary - (have ?void *? and ?uint8_t *?)
return (phys_addr_t)(vaddr - gd->arch.ram_buf);

[snip]

Quoted 9 lines
arch/sandbox/include/asm/io.h +0 -9
-/*
- * 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)

[snip]

arch/sandbox/include/asm/io.h static inline void _outsw(volatile u16 *port, const void *buf, int ns) · line 72

Quoted 5 lines
arch/sandbox/include/asm/io.h +1 -0
@@ -71,6 +69,7 @@ static inline void _outsw(volatile u16 *port, const void *buf, int ns)
 #define out16(addr, val)
 #define in16(addr)		0
 
+#include <asm-generic/io.h>

... but we use MAP_WRBACK in map/unmap_sysmem which are before we include this so they don't compile.

Please fix and run test/py/test.py for sandbox when you're done to ensure it's still all happy, thanks!

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

PATCH 18/27 board_f: Account for CONFIG_SYS_SDRAM_BASE being physical

In reply to Paul Burton

README declares that CONFIG_SYS_SDRAM_BASE is meant to be the physical address of SDRAM, but right now that is not the case on MIPS systems. In preparation for making it so, use phys_to_virt to translate CONFIG_SYS_SDRAM_BASE to the ram_top field of struct global_data which is then used to calculate most memory addresses used by U-Boot.

---

 common/board_f.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
common/board_f.c +2 -2
index 2c88595..1afc80d 100644
@@ -315,7 +315,7 @@ __weak ulong board_get_usable_ram_top(ulong total_size)
 	 * Detect whether we have so much RAM that it goes past the end of our
 	 * 32-bit address space. If so, clip the usable RAM so it doesn't.
 	 */
-	if (gd->ram_top < CONFIG_SYS_SDRAM_BASE)
+	if (gd->ram_top < (ulong)phys_to_virt(CONFIG_SYS_SDRAM_BASE))
 		/*
 		 * Will wrap back to top of 32-bit space when reservations
 		 * are made.
@@ -362,7 +362,7 @@ static int setup_dest_addr(void)
 	gd->ram_size = board_reserve_ram_top(gd->ram_size);
 
 #ifdef CONFIG_SYS_SDRAM_BASE
-	gd->ram_top = CONFIG_SYS_SDRAM_BASE;
+	gd->ram_top = (ulong)phys_to_virt(CONFIG_SYS_SDRAM_BASE);
 #endif
 	gd->ram_top += get_effective_memsize();
 	gd->ram_top = board_get_usable_ram_top(gd->mon_len);
Signature · 1 line
2.10.0
#32 lore raw

PATCH 18/27 board_f: Account for CONFIG_SYS_SDRAM_BASE being physical

Quoted 11 lines · Paul Burton

README declares that CONFIG_SYS_SDRAM_BASE is meant to be the physical address of SDRAM, but right now that is not the case on MIPS systems. In preparation for making it so, use phys_to_virt to translate CONFIG_SYS_SDRAM_BASE to the ram_top field of struct global_data which is then used to calculate most memory addresses used by U-Boot.

---

 common/board_f.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
#33 lore raw

PATCH 19/27 image: Account for CONFIG_SYS_SDRAM_BASE being physical

In reply to Paul Burton

README declares that CONFIG_SYS_SDRAM_BASE is meant to be the physical address of SDRAM, but right now that is not the case on MIPS systems, where it is instead a virtual address. In preparation for making it physical, use phys_to_virt to translate CONFIG_SYS_SDRAM_BASE & the associated bi_memstart field of struct bd_info to virtual addresses for use.

---

 common/image.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
common/image.c +2 -2
index a5d19ab..1581022 100644
@@ -466,7 +466,7 @@ ulong getenv_bootm_low(void)
 	}
 
 #if defined(CONFIG_SYS_SDRAM_BASE)
-	return CONFIG_SYS_SDRAM_BASE;
+	return (ulong)phys_to_virt(CONFIG_SYS_SDRAM_BASE);
 #elif defined(CONFIG_ARM)
 	return gd->bd->bi_dram[0].start;
 #else
@@ -488,7 +488,7 @@ phys_size_t getenv_bootm_size(void)
 	start = gd->bd->bi_dram[0].start;
 	size = gd->bd->bi_dram[0].size;
 #else
-	start = gd->bd->bi_memstart;
+	start = (ulong)phys_to_virt(gd->bd->bi_memstart);
 	size = gd->bd->bi_memsize;
 #endif
 
Signature · 1 line
2.10.0
#34 lore raw

PATCH 19/27 image: Account for CONFIG_SYS_SDRAM_BASE being physical

Quoted 7 lines · Paul Burton

README declares that CONFIG_SYS_SDRAM_BASE is meant to be the physical address of SDRAM, but right now that is not the case on MIPS systems, where it is instead a virtual address. In preparation for making it physical, use phys_to_virt to translate CONFIG_SYS_SDRAM_BASE & the associated bi_memstart field of struct bd_info to virtual addresses for use.

Quoted 5 lines

---

 common/image.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
#35 lore raw

PATCH 20/27 image: Use ram_top, not bi_memsize, in getenv_bootm_size

In reply to Paul Burton

When determining the region of memory to allow for use by bootm, using bi_memstart & adding bi_memsize can cause problems if that leads to an integer overflow. For example on some MIPS systems bi_memstart would be 0xffffffff80000000 (ie. the start of the MIPS ckseg0 region) and if the system has 2GB of memory then the addition would wrap around to 0.

The maximum amount of memory to be used by U-Boot is already accounted for by the ram_top field of struct global_data, so make use of that for the calculation instead.

---

 common/image.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
common/image.c +1 -1
index 1581022..25e632b 100644
@@ -489,7 +489,7 @@ phys_size_t getenv_bootm_size(void)
 	size = gd->bd->bi_dram[0].size;
 #else
 	start = (ulong)phys_to_virt(gd->bd->bi_memstart);
-	size = gd->bd->bi_memsize;
+	size = gd->ram_top - start;
 #endif
 
 	s = getenv("bootm_low");
Signature · 1 line
2.10.0
#36 lore raw

PATCH 20/27 image: Use ram_top, not bi_memsize, in getenv_bootm_size

Hi Paul,

Quoted 5 lines · Paul Burton

When determining the region of memory to allow for use by bootm, using bi_memstart & adding bi_memsize can cause problems if that leads to an integer overflow. For example on some MIPS systems bi_memstart would be 0xffffffff80000000 (ie. the start of the MIPS ckseg0 region) and if the system has 2GB of memory then the addition would wrap around to 0.

What will wrap around to 0? Isn't gd->bd->bi_memsize equal to 2GB, and gd->ram_top - start the same?

Quoted 25 lines

The maximum amount of memory to be used by U-Boot is already accounted for by the ram_top field of struct global_data, so make use of that for the calculation instead.

---

 common/image.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
common/image.c +1 -2
index 1581022..25e632b 100644
@@ -489,7 +489,7 @@ phys_size_t getenv_bootm_size(void)
        size = gd->bd->bi_dram[0].size;
 #else
        start = (ulong)phys_to_virt(gd->bd->bi_memstart);
-       size = gd->bd->bi_memsize;
+       size = gd->ram_top - start;
 #endif
 
        s = getenv("bootm_low");
--
Quoted 2 lines

2.10.0

Regards,
Simon

#37 lore raw

PATCH 21/27 mips: Use ram_top, not bi_memsize, in arch_lmb_reserve

In reply to Paul Burton

When calculating the region to reserve for the stack in arch_lmb_reserve, make use of ram_top instead of adding bi_memsize to CONFIG_SYS_SDRAM_BASE. This avoids overflow if the system has enough memory to reach the end of the address space.

Cc Daniel Schwierzeck <[email protected]>

---

 arch/mips/lib/bootm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/mips/lib/bootm.c +1 -1
index 0c6a4ab..9fec4ad 100644
@@ -42,7 +42,7 @@ void arch_lmb_reserve(struct lmb *lmb)
 
 	/* adjust sp by 4K to be safe */
 	sp -= 4096;
-	lmb_reserve(lmb, sp, CONFIG_SYS_SDRAM_BASE + gd->ram_size - sp);
+	lmb_reserve(lmb, sp, gd->ram_top - sp);
 }
 
 static void linux_cmdline_init(void)
Signature · 1 line
2.10.0
#38 lore raw

PATCH 22/27 mips: Ensure stack is at a virtual address

In reply to Paul Burton

In preparation for making CONFIG_SYS_SDRAM_BASE a physical address on MIPS as README says it should be, ensure that our default CONFIG_SYS_INIT_SP_ADDR is placed in (c)kseg0 rather than being a simple offset addition to CONFIG_SYS_SDRAM_BASE.

Cc Daniel Schwierzeck <[email protected]>

---

 arch/mips/cpu/start.S | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/mips/cpu/start.S +2 -1
index 3f0fc12..936d63c 100644
@@ -8,12 +8,13 @@
 
 #include <asm-offsets.h>
 #include <config.h>
+#include <asm/addrspace.h>
 #include <asm/asm.h>
 #include <asm/regdef.h>
 #include <asm/mipsregs.h>
 
 #ifndef CONFIG_SYS_INIT_SP_ADDR
-#define CONFIG_SYS_INIT_SP_ADDR	(CONFIG_SYS_SDRAM_BASE + \
+#define CONFIG_SYS_INIT_SP_ADDR	CKSEG0ADDR(CONFIG_SYS_SDRAM_BASE + \
 				CONFIG_SYS_INIT_SP_OFFSET)
 #endif
 
Signature · 1 line
2.10.0
#39 lore raw

PATCH 23/27 boston: Provide physical CONFIG_SYS_SDRAM_BASE

In reply to Paul Burton

README states that CONFIG_SYS_SDRAM_BASE should the physical base address of SDRAM, whilst up until now various pieces of generic code have presumed that it can be directly accessed by the CPU & MIPS has provided a virtual address for CONFIG_SYS_SDRAM_BASE. Other generic code expects CONFIG_SYS_SDRAM_BASE to be a physical address, which makes the inconsistency a mess.

Now that the preceding patches have prepared us to handle using a physical CONFIG_SYS_SDRAM_BASE, clean up the inconsistency for boston by providing a physical CONFIG_SYS_SDRAM_BASE. A side effect of this & use of phys_to_virt is that on MIPS64 U-Boot will now access DDR through the xkphys region of the virtual address space rather than ckseg0, which necessitates the change to board_get_usable_ram_top().

Cc Daniel Schwierzeck <[email protected]>

---

 board/imgtec/boston/ddr.c |  8 ++------
 include/configs/boston.h  | 21 ++++++++++-----------
 2 files changed, 12 insertions(+), 17 deletions(-)
board/imgtec/boston/ddr.c +2 -6
index ceffef6..e765627 100644
@@ -5,6 +5,7 @@
  */
 
 #include <common.h>
+#include <linux/sizes.h>
 
 #include <asm/io.h>
 
@@ -21,10 +22,5 @@ ulong board_get_usable_ram_top(ulong total_size)
 {
 	DECLARE_GLOBAL_DATA_PTR;
 
-	if (gd->ram_top < CONFIG_SYS_SDRAM_BASE) {
-		/* 2GB wrapped around to 0 */
-		return CKSEG0ADDR(256 << 20);
-	}
-
-	return min_t(unsigned long, gd->ram_top, CKSEG0ADDR(256 << 20));
+	return min_t(ulong, gd->ram_top, (ulong)phys_to_virt(SZ_256M));
 }
include/configs/boston.h +10 -11
index e958054..37060b0 100644
@@ -27,20 +27,19 @@
 /*
  * Memory map
  */
-#ifdef CONFIG_64BIT
-# define CONFIG_SYS_SDRAM_BASE		0xffffffff80000000
-#else
-# define CONFIG_SYS_SDRAM_BASE		0x80000000
-#endif
-
+#define CONFIG_SYS_SDRAM_BASE		0x0
 #define CONFIG_SYS_INIT_SP_OFFSET	0x400000
-
 #define CONFIG_SYS_MONITOR_BASE		CONFIG_SYS_TEXT_BASE
 
-#define CONFIG_SYS_LOAD_ADDR		(CONFIG_SYS_SDRAM_BASE + 0x100000)
-
-#define CONFIG_SYS_MEMTEST_START	(CONFIG_SYS_SDRAM_BASE + 0)
-#define CONFIG_SYS_MEMTEST_END		(CONFIG_SYS_SDRAM_BASE + 0x10000000)
+#ifdef CONFIG_64BIT
+# define CONFIG_SYS_LOAD_ADDR		0xffffffff80100000
+# define CONFIG_SYS_MEMTEST_START	0xffffffff80000000
+# define CONFIG_SYS_MEMTEST_END		0xffffffff90000000
+#else
+# define CONFIG_SYS_LOAD_ADDR		0x80100000
+# define CONFIG_SYS_MEMTEST_START	0x80000000
+# define CONFIG_SYS_MEMTEST_END		0x90000000
+#endif
 
 #define CONFIG_SYS_MALLOC_LEN		(256 * 1024)
 
Signature · 1 line
2.10.0
#40 lore raw

PATCH 24/27 malta: Use a physical CONFIG_SYS_SDRAM_BASE

In reply to Paul Burton

README states that CONFIG_SYS_SDRAM_BASE should the physical base address of SDRAM, whilst up until now various pieces of generic code have presumed that it can be directly accessed by the CPU & MIPS has provided a virtual address for CONFIG_SYS_SDRAM_BASE. Other generic code expects CONFIG_SYS_SDRAM_BASE to be a physical address, which makes the inconsistency a mess.

Now that the preceding patches have prepared us to handle using a physical CONFIG_SYS_SDRAM_BASE, clean up the inconsistency for malta by providing a physical CONFIG_SYS_SDRAM_BASE.

Cc Daniel Schwierzeck <[email protected]>

---

 include/configs/malta.h | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)
include/configs/malta.h +10 -8
index fc4baba..5bc9f23 100644
@@ -39,18 +39,20 @@
  */
 #define CONFIG_SYS_MONITOR_BASE		CONFIG_SYS_TEXT_BASE
 
-#ifdef CONFIG_64BIT
-# define CONFIG_SYS_SDRAM_BASE		0xffffffff80000000
-#else
-# define CONFIG_SYS_SDRAM_BASE		0x80000000
-#endif
+#define CONFIG_SYS_SDRAM_BASE		0x0
 #define CONFIG_SYS_MEM_SIZE		(256 * 1024 * 1024)
 
 #define CONFIG_SYS_INIT_SP_OFFSET	0x400000
 
-#define CONFIG_SYS_LOAD_ADDR		(CONFIG_SYS_SDRAM_BASE + 0x01000000)
-#define CONFIG_SYS_MEMTEST_START	(CONFIG_SYS_SDRAM_BASE + 0x00100000)
-#define CONFIG_SYS_MEMTEST_END		(CONFIG_SYS_SDRAM_BASE + 0x00800000)
+#ifdef CONFIG_64BIT
+# define CONFIG_SYS_LOAD_ADDR		0xffffffff81000000
+# define CONFIG_SYS_MEMTEST_START	0xffffffff80100000
+# define CONFIG_SYS_MEMTEST_END		0xffffffff80800000
+#else
+# define CONFIG_SYS_LOAD_ADDR		0x81000000
+# define CONFIG_SYS_MEMTEST_START	0x80100000
+# define CONFIG_SYS_MEMTEST_END		0x80800000
+#endif
 
 #define CONFIG_SYS_MALLOC_LEN		(128 * 1024)
 #define CONFIG_SYS_BOOTPARAMS_LEN	(128 * 1024)
Signature · 1 line
2.10.0
#41 lore raw

PATCH 25/27 xilfpga: Use a physical CONFIG_SYS_SDRAM_BASE

In reply to Paul Burton

README states that CONFIG_SYS_SDRAM_BASE should the physical base address of SDRAM, whilst up until now various pieces of generic code have presumed that it can be directly accessed by the CPU & MIPS has provided a virtual address for CONFIG_SYS_SDRAM_BASE. Other generic code expects CONFIG_SYS_SDRAM_BASE to be a physical address, which makes the inconsistency a mess.

Now that the preceding patches have prepared us to handle using a physical CONFIG_SYS_SDRAM_BASE, clean up the inconsistency for malta by providing a physical CONFIG_SYS_SDRAM_BASE.

This has only been build-tested, feedback welcome.

Cc Daniel Schwierzeck <[email protected]>
Cc Zubair Lutfullah Kakakhel <[email protected]>

---

 include/configs/imgtec_xilfpga.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
include/configs/imgtec_xilfpga.h +2 -2
index 0a7fe60..1583f21 100644
@@ -28,10 +28,10 @@
  */
 
 /* SDRAM Configuration (for final code, data, stack, heap) */
-#define CONFIG_SYS_SDRAM_BASE		0x80000000
+#define CONFIG_SYS_SDRAM_BASE		0x0
 #define CONFIG_SYS_SDRAM_SIZE		0x08000000	/* 128 Mbytes */
 #define CONFIG_SYS_INIT_SP_ADDR		\
-	(CONFIG_SYS_SDRAM_BASE + CONFIG_SYS_SDRAM_SIZE - 0x1000)
+	(0x80000000 + CONFIG_SYS_SDRAM_SIZE - 0x1000)
 
 #define CONFIG_SYS_MALLOC_LEN		(256 << 10)
 #define CONFIG_SYS_MONITOR_BASE		CONFIG_SYS_TEXT_BASE
Signature · 1 line
2.10.0
#42 lore raw

PATCH 26/27 mips: Use a physical CONFIG_SYS_SDRAM_BASE for remaining boards

In reply to Paul Burton

README states that CONFIG_SYS_SDRAM_BASE should the physical base address of SDRAM, whilst up until now various pieces of generic code have presumed that it can be directly accessed by the CPU & MIPS has provided a virtual address for CONFIG_SYS_SDRAM_BASE. Other generic code expects CONFIG_SYS_SDRAM_BASE to be a physical address, which makes the inconsistency a mess.

Now that the preceding patches have prepared us to handle using a physical CONFIG_SYS_SDRAM_BASE, clean up the inconsistency for the remaining MIPS boards by providing a physical CONFIG_SYS_SDRAM_BASE.

None of these boards use CONFIG_SYS_SDRAM_BASE in their code, so they're handled together.

This has only been build-tested, feedback welcome.

Cc Daniel Schwierzeck <[email protected]>
Cc Marek Vasut <[email protected]>
Cc Purna Chandra Mandal <[email protected]>
Cc Wills Wang <[email protected]>

---

 include/configs/ap121.h          | 2 +-
 include/configs/ap143.h          | 2 +-
 include/configs/dbau1x00.h       | 2 +-
 include/configs/pb1x00.h         | 2 +-
 include/configs/pic32mzdask.h    | 2 +-
 include/configs/qemu-mips.h      | 2 +-
 include/configs/qemu-mips64.h    | 2 +-
 include/configs/tplink_wdr4300.h | 2 +-
 include/configs/vct.h            | 2 +-
 9 files changed, 9 insertions(+), 9 deletions(-)
include/configs/ap121.h +1 -1
index bf5746f..63e0015 100644
@@ -20,7 +20,7 @@
 #define CONFIG_SYS_MALLOC_LEN           0x40000
 #define CONFIG_SYS_BOOTPARAMS_LEN       0x20000
 
-#define CONFIG_SYS_SDRAM_BASE           0x80000000
+#define CONFIG_SYS_SDRAM_BASE           0x0
 #define CONFIG_SYS_LOAD_ADDR            0x81000000
 
 #define CONFIG_SYS_NO_FLASH
include/configs/ap143.h +1 -1
index 5d7e49e..a8721e6 100644
@@ -20,7 +20,7 @@
 #define CONFIG_SYS_MALLOC_LEN           0x40000
 #define CONFIG_SYS_BOOTPARAMS_LEN       0x20000
 
-#define CONFIG_SYS_SDRAM_BASE           0x80000000
+#define CONFIG_SYS_SDRAM_BASE           0x0
 #define CONFIG_SYS_LOAD_ADDR            0x81000000
 
 #define CONFIG_SYS_NO_FLASH
include/configs/dbau1x00.h +1 -1
index dbd2bb3..b369d71 100644
@@ -105,7 +105,7 @@
 
 #define CONFIG_SYS_MIPS_TIMER_FREQ	(CONFIG_SYS_MHZ * 1000000)
 
-#define CONFIG_SYS_SDRAM_BASE		0x80000000     /* Cached addr */
+#define CONFIG_SYS_SDRAM_BASE		0x0            /* Cached addr */
 
 #define	CONFIG_SYS_LOAD_ADDR		0x81000000     /* default load address	*/
 
include/configs/pb1x00.h +1 -1
index fb5278f..8ef334f 100644
@@ -61,7 +61,7 @@
 
 #define CONFIG_SYS_MIPS_TIMER_FREQ	396000000
 
-#define CONFIG_SYS_SDRAM_BASE		0x80000000     /* Cached addr */
+#define CONFIG_SYS_SDRAM_BASE		0x0            /* Cached addr */
 
 #define	CONFIG_SYS_LOAD_ADDR		0x81000000     /* default load address	*/
 
include/configs/pic32mzdask.h +1 -1
index 49c98d8..5b80b46 100644
@@ -35,7 +35,7 @@
 	(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_SIZE - 1)
 
 /* SDRAM Configuration (for final code, data, stack, heap) */
-#define CONFIG_SYS_SDRAM_BASE		0x88000000
+#define CONFIG_SYS_SDRAM_BASE		0x08000000
 #define CONFIG_SYS_MALLOC_LEN		(256 << 10)
 #define CONFIG_SYS_BOOTPARAMS_LEN	(4 << 10)
 #define CONFIG_STACKSIZE		(4 << 10) /* regular stack */
include/configs/qemu-mips.h +1 -1
index 546c508..7e839a8 100644
@@ -94,7 +94,7 @@
 #define CONFIG_SYS_MIPS_TIMER_FREQ	(CONFIG_SYS_MHZ * 1000000)
 
 /* Cached addr */
-#define CONFIG_SYS_SDRAM_BASE		0x80000000
+#define CONFIG_SYS_SDRAM_BASE		0x0
 
 /* default load address */
 #define CONFIG_SYS_LOAD_ADDR		0x81000000
include/configs/qemu-mips64.h +1 -1
index 6cab719..18e3294 100644
@@ -94,7 +94,7 @@
 #define CONFIG_SYS_MIPS_TIMER_FREQ	(CONFIG_SYS_MHZ * 1000000)
 
 /* Cached addr */
-#define CONFIG_SYS_SDRAM_BASE		0xffffffff80000000
+#define CONFIG_SYS_SDRAM_BASE		0x0
 
 /* default load address */
 #define CONFIG_SYS_LOAD_ADDR		0xffffffff81000000
include/configs/tplink_wdr4300.h +1 -1
index 7bf8e4c..5a6a0d4 100644
@@ -20,7 +20,7 @@
 #define CONFIG_SYS_MALLOC_LEN		0x40000
 #define CONFIG_SYS_BOOTPARAMS_LEN	0x20000
 
-#define CONFIG_SYS_SDRAM_BASE		0xa0000000
+#define CONFIG_SYS_SDRAM_BASE		0x0
 #define CONFIG_SYS_LOAD_ADDR		0xa1000000
 #define CONFIG_LOADADDR			CONFIG_SYS_LOAD_ADDR
 
include/configs/vct.h +1 -1
index f2e0e5c..3e50619 100644
@@ -63,7 +63,7 @@
 /*
  * SDRAM
  */
-#define CONFIG_SYS_SDRAM_BASE		0x80000000
+#define CONFIG_SYS_SDRAM_BASE		0x0
 #define CONFIG_SYS_MBYTES_SDRAM		128
 #define CONFIG_SYS_MEMTEST_START	0x80200000
 #define CONFIG_SYS_MEMTEST_END		0x80400000
Signature · 1 line
2.10.0
#43 lore raw

PATCH 27/27 mips: Remove virt_to_phys call on bi_memstart

In reply to Paul Burton

CONFIG_SYS_SDRAM_BASE & by extension bi_memstart are now physical addresses, so there's no need to call virt_to_phys in arch_fixup_fdt. Remove the call.

Cc Daniel Schwierzeck <[email protected]>

---

 arch/mips/lib/bootm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/mips/lib/bootm.c +1 -1
index 9fec4ad..00991cb 100644
@@ -257,7 +257,7 @@ static int boot_reloc_fdt(bootm_headers_t *images)
 int arch_fixup_fdt(void *blob)
 {
 #if CONFIG_IS_ENABLED(MIPS_BOOT_FDT) && CONFIG_IS_ENABLED(OF_LIBFDT)
-	u64 mem_start = virt_to_phys((void *)gd->bd->bi_memstart);
+	u64 mem_start = gd->bd->bi_memstart;
 	u64 mem_size = gd->ram_size;
 
 	return fdt_fixup_memory_banks(blob, &mem_start, &mem_size, 1);
Signature · 1 line
2.10.0
#44 lore raw

cover Clean up address mapping functions & CONFIG_SYS_SDRAM_BASE

In reply to Paul Burton

Hi Paul,

2016-10-01 23:19 GMT+09:00 Paul Burton <[email protected]>:

Quoted 12 lines

README states that CONFIG_SYS_SDRAM_BASE should be the physical address of the base of SDRAM memory. This is expected by some code such as the PCI layer, which uses CONFIG_SYS_SDRAM_BASE to set up a region for system memory. Other code such as the image loading code used by bootm or the generic board_f.c expect CONFIG_SYS_SDRAM_BASE to be directly accessible by the CPU, which necessitates that it be a virtual address.

Where virtual & physical addresses aren't identity mapped, as is the case for MIPS, we cannot possibly satisfy both. Until now MIPS has used a virtual CONFIG_SYS_SDRAM_BASE. This series fixes up the mess by doing a few things:

Quoted 9 lines

- Ensuring that we provide virt_to_phys() on all architectures.

- Fixing code that expects to use CONFIG_SYS_SDRAM_BASE as a virtual address to instead convert it to a physical address using virt_to_phys().

- Converts MIPS code & all MIPS boards to provide a physical CONFIG_SYS_SDRAM_BASE, which typically is zero.

Thanks for working on this.

As you may notice, include/linux/io.h defines the generic implementation of ioremap().

(It is guarded by #ifndef CONFIG_HAVE_ARCH_IOREMAP so that MIPS can work-around it.)

If you go with asm-generic/io.h,
perhaps should we be consistent, that is, move the generic ioremap() to asm-generic/io.h?

We do not have to do it in this series, but it would be appreciated
if you volunteer to make it in a better way.

Thanks,

Signature · 2 lines
Best Regards
Masahiro Yamada
#45 lore raw

cover Clean up address mapping functions & CONFIG_SYS_SDRAM_BASE

Quoted 26 lines · On Sunday, 2 October 2016 22:46:45 BST Masahiro Yamada wrote:

Hi Paul,

2016-10-01 23:19 GMT+09:00 Paul Burton <[email protected]>:

Quoted 14 lines

README states that CONFIG_SYS_SDRAM_BASE should be the physical address of the base of SDRAM memory. This is expected by some code such as the PCI layer, which uses CONFIG_SYS_SDRAM_BASE to set up a region for system memory. Other code such as the image loading code used by bootm or the generic board_f.c expect CONFIG_SYS_SDRAM_BASE to be directly accessible by the CPU, which necessitates that it be a virtual address.

Where virtual & physical addresses aren't identity mapped, as is the case for MIPS, we cannot possibly satisfy both. Until now MIPS has used a virtual CONFIG_SYS_SDRAM_BASE. This series fixes up the mess by doing

a few things:
- Ensuring that we provide virt_to_phys() on all architectures.

Quoted 8 lines

- Fixing code that expects to use CONFIG_SYS_SDRAM_BASE as a virtual

address to instead convert it to a physical address using virt_to_phys().

- Converts MIPS code & all MIPS boards to provide a physical

CONFIG_SYS_SDRAM_BASE, which typically is zero.

Quoted 7 lines

Thanks for working on this.

As you may notice, include/linux/io.h defines the generic implementation of ioremap().

(It is guarded by #ifndef CONFIG_HAVE_ARCH_IOREMAP so that MIPS can work-around it.)

Hi Masahiro,

I hadn't actually noticed the generic ioremap - I suspect few do since you don't get it by including asm/io.h as you would in Linux. It'll also be wrong for other architectures that don't do a simple 1:1 physical:virtual translation but don't select CONFIG_HAVE_ARCH_IOREMAP (nios2, sandbox).

Quoted 7 lines

If you go with asm-generic/io.h,
perhaps should we be consistent, that is, move the generic ioremap() to asm-generic/io.h?

We do not have to do it in this series, but it would be appreciated
if you volunteer to make it in a better way.

Yeah I'd be fine with cleaning that up, preferrably after this series is merged so I don't have more out of tree patches to juggle. I'd propose that we implement the generic ioremap atop map_physmem, which we ought to be able to do for every arch if we clean up MIPS a little.

Thanks,
Paul
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20161003/76f77660/attachment.sig>