[U-Boot] [PATCH 00/27] 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

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.
Signed-off-by: Paul Burton paul.burton@imgtec.com Cc: Albert Aribaud albert.u.boot@aribaud.net Cc: Alexey Brodkin alexey.brodkin@synopsys.com Cc: Alison Wang alison.wang@freescale.com Cc: Angelo Dureghello angelo@sysam.it Cc: Bin Meng bmeng.cn@gmail.com Cc: Daniel Schwierzeck daniel.schwierzeck@gmail.com Cc: Francois Retief fgretief@spaceteq.co.za Cc: Macpaul Lin macpaul@andestech.com Cc: Michal Simek monstr@monstr.eu Cc: Mike Frysinger vapier@gentoo.org Cc: Nobuhiro Iwamatsu iwamatsu@nigauri.org Cc: Scott McNutt smcnutt@psyent.com Cc: Sonic Zhang sonic.adi@gmail.com Cc: Thomas Chou thomas@wytron.com.tw Cc: Wolfgang Denk wd@denx.de ---
include/asm-generic/io.h | 110 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 include/asm-generic/io.h
diff --git a/include/asm-generic/io.h b/include/asm-generic/io.h new file mode 100644 index 0000000..dd3a46d --- /dev/null +++ b/include/asm-generic/io.h @@ -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__ */

Hi Paul,
On 01/10/2016 16:19, Paul Burton wrote:
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.
Signed-off-by: Paul Burton paul.burton@imgtec.com Cc: Albert Aribaud albert.u.boot@aribaud.net Cc: Alexey Brodkin alexey.brodkin@synopsys.com Cc: Alison Wang alison.wang@freescale.com Cc: Angelo Dureghello angelo@sysam.it Cc: Bin Meng bmeng.cn@gmail.com Cc: Daniel Schwierzeck daniel.schwierzeck@gmail.com Cc: Francois Retief fgretief@spaceteq.co.za Cc: Macpaul Lin macpaul@andestech.com Cc: Michal Simek monstr@monstr.eu Cc: Mike Frysinger vapier@gentoo.org Cc: Nobuhiro Iwamatsu iwamatsu@nigauri.org Cc: Scott McNutt smcnutt@psyent.com Cc: Sonic Zhang sonic.adi@gmail.com Cc: Thomas Chou thomas@wytron.com.tw Cc: Wolfgang Denk wd@denx.de
include/asm-generic/io.h | 110 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 include/asm-generic/io.h
diff --git a/include/asm-generic/io.h b/include/asm-generic/io.h new file mode 100644 index 0000000..dd3a46d --- /dev/null +++ b/include/asm-generic/io.h @@ -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__ */
tested on mcf5307 amcore board, (that btw is not using those functions), tested buildall for m68k boards,
Acked-by: Angelo Dureghello <angelo at sysam.it> Tested-by: Angelo Dureghello <angelo at sysam.it>
many thanks, Best regards, Angelo Dureghello

Hi Paul,
On 1 October 2016 at 08:19, Paul Burton paul.burton@imgtec.com wrote:
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.
Signed-off-by: Paul Burton paul.burton@imgtec.com Cc: Albert Aribaud albert.u.boot@aribaud.net Cc: Alexey Brodkin alexey.brodkin@synopsys.com Cc: Alison Wang alison.wang@freescale.com Cc: Angelo Dureghello angelo@sysam.it Cc: Bin Meng bmeng.cn@gmail.com Cc: Daniel Schwierzeck daniel.schwierzeck@gmail.com Cc: Francois Retief fgretief@spaceteq.co.za Cc: Macpaul Lin macpaul@andestech.com Cc: Michal Simek monstr@monstr.eu Cc: Mike Frysinger vapier@gentoo.org Cc: Nobuhiro Iwamatsu iwamatsu@nigauri.org Cc: Scott McNutt smcnutt@psyent.com Cc: Sonic Zhang sonic.adi@gmail.com Cc: Thomas Chou thomas@wytron.com.tw Cc: Wolfgang Denk wd@denx.de
include/asm-generic/io.h | 110 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 include/asm-generic/io.h
Reviewed-by: Simon Glass sjg@chromium.org
Question and nits below.
diff --git a/include/asm-generic/io.h b/include/asm-generic/io.h new file mode 100644 index 0000000..dd3a46d --- /dev/null +++ b/include/asm-generic/io.h @@ -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
@return
- 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?
- */
+#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
- Returns the physical address which the CPU-accessible virtual address @vaddr
- maps to.
- Returns: the physical address which @vaddr maps to
Why two Returns?
- */
+#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
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?
+/**
- 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
- 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
- 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??
+{
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__ */
2.10.0
REgards, Simon

On Monday, 3 October 2016 15:49:33 GMT Simon Glass wrote:
Hi Paul,
On 1 October 2016 at 08:19, Paul Burton paul.burton@imgtec.com wrote:
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.
Signed-off-by: Paul Burton paul.burton@imgtec.com Cc: Albert Aribaud albert.u.boot@aribaud.net Cc: Alexey Brodkin alexey.brodkin@synopsys.com Cc: Alison Wang alison.wang@freescale.com Cc: Angelo Dureghello angelo@sysam.it Cc: Bin Meng bmeng.cn@gmail.com Cc: Daniel Schwierzeck daniel.schwierzeck@gmail.com Cc: Francois Retief fgretief@spaceteq.co.za Cc: Macpaul Lin macpaul@andestech.com Cc: Michal Simek monstr@monstr.eu Cc: Mike Frysinger vapier@gentoo.org Cc: Nobuhiro Iwamatsu iwamatsu@nigauri.org Cc: Scott McNutt smcnutt@psyent.com Cc: Sonic Zhang sonic.adi@gmail.com Cc: Thomas Chou thomas@wytron.com.tw Cc: Wolfgang Denk wd@denx.de
include/asm-generic/io.h | 110 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 include/asm-generic/io.h
Reviewed-by: Simon Glass sjg@chromium.org
Question and nits below.
diff --git a/include/asm-generic/io.h b/include/asm-generic/io.h new file mode 100644 index 0000000..dd3a46d --- /dev/null +++ b/include/asm-generic/io.h @@ -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
@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.
- 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.
- */
+#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
Ditto.
- 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.
- */
+#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
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.
+/**
- 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.
- 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.
- 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??
Sure.
Thanks, Paul
+{
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__ */
2.10.0
REgards, Simon

Hi Paul,
On 17 November 2016 at 08:32, Paul Burton paul.burton@imgtec.com wrote:
On Monday, 3 October 2016 15:49:33 GMT Simon Glass wrote:
Hi Paul,
On 1 October 2016 at 08:19, Paul Burton paul.burton@imgtec.com wrote:
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.
Signed-off-by: Paul Burton paul.burton@imgtec.com Cc: Albert Aribaud albert.u.boot@aribaud.net Cc: Alexey Brodkin alexey.brodkin@synopsys.com Cc: Alison Wang alison.wang@freescale.com Cc: Angelo Dureghello angelo@sysam.it Cc: Bin Meng bmeng.cn@gmail.com Cc: Daniel Schwierzeck daniel.schwierzeck@gmail.com Cc: Francois Retief fgretief@spaceteq.co.za Cc: Macpaul Lin macpaul@andestech.com Cc: Michal Simek monstr@monstr.eu Cc: Mike Frysinger vapier@gentoo.org Cc: Nobuhiro Iwamatsu iwamatsu@nigauri.org Cc: Scott McNutt smcnutt@psyent.com Cc: Sonic Zhang sonic.adi@gmail.com Cc: Thomas Chou thomas@wytron.com.tw Cc: Wolfgang Denk wd@denx.de
include/asm-generic/io.h | 110 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 include/asm-generic/io.h
Reviewed-by: Simon Glass sjg@chromium.org
Question and nits below.
diff --git a/include/asm-generic/io.h b/include/asm-generic/io.h new file mode 100644 index 0000000..dd3a46d --- /dev/null +++ b/include/asm-generic/io.h @@ -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
@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.
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

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.
Signed-off-by: Paul Burton paul.burton@imgtec.com Cc: Alexey Brodkin alexey.brodkin@synopsys.com ---
arch/arc/include/asm/io.h | 29 +---------------------------- 1 file changed, 1 insertion(+), 28 deletions(-)
diff --git a/arch/arc/include/asm/io.h b/arch/arc/include/asm/io.h index 42e7f22..a12303b 100644 --- a/arch/arc/include/asm/io.h +++ b/arch/arc/include/asm/io.h @@ -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 */

Hi Paul,
On Sat, 2016-10-01 at 15:19 +0100, Paul Burton wrote:
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.
Signed-off-by: Paul Burton paul.burton@imgtec.com Cc: Alexey Brodkin alexey.brodkin@synopsys.com
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
Acked-by: Alexey Brodkin abrodkin@synopsys.com

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.
Signed-off-by: Paul Burton paul.burton@imgtec.com Cc: Albert Aribaud albert.u.boot@aribaud.net ---
arch/arm/include/asm/io.h | 30 +----------------------------- 1 file changed, 1 insertion(+), 29 deletions(-)
diff --git a/arch/arm/include/asm/io.h b/arch/arm/include/asm/io.h index 5834f5b..5df7472 100644 --- a/arch/arm/include/asm/io.h +++ b/arch/arm/include/asm/io.h @@ -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 */

On 1 October 2016 at 08:19, Paul Burton paul.burton@imgtec.com wrote:
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.
Signed-off-by: Paul Burton paul.burton@imgtec.com Cc: Albert Aribaud albert.u.boot@aribaud.net
arch/arm/include/asm/io.h | 30 +----------------------------- 1 file changed, 1 insertion(+), 29 deletions(-)
Reviewed-by: Simon Glass sjg@chromium.org

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.
Signed-off-by: Paul Burton paul.burton@imgtec.com Cc: Sonic Zhang sonic.adi@gmail.com ---
arch/blackfin/include/asm/io.h | 31 ++----------------------------- 1 file changed, 2 insertions(+), 29 deletions(-)
diff --git a/arch/blackfin/include/asm/io.h b/arch/blackfin/include/asm/io.h index d3337e4..dad8ac6 100644 --- a/arch/blackfin/include/asm/io.h +++ b/arch/blackfin/include/asm/io.h @@ -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

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.
Signed-off-by: Paul Burton paul.burton@imgtec.com Cc: Huan Wang alison.wang@freescale.com Cc: Angelo Dureghello angelo@sysam.it ---
arch/m68k/include/asm/io.h | 29 +---------------------------- 1 file changed, 1 insertion(+), 28 deletions(-)
diff --git a/arch/m68k/include/asm/io.h b/arch/m68k/include/asm/io.h index 384308b..dfe77f0 100644 --- a/arch/m68k/include/asm/io.h +++ b/arch/m68k/include/asm/io.h @@ -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__ */

Dear Paul,
On 01/10/2016 16:19, Paul Burton wrote:
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.
Signed-off-by: Paul Burton paul.burton@imgtec.com Cc: Huan Wang alison.wang@freescale.com Cc: Angelo Dureghello angelo@sysam.it
arch/m68k/include/asm/io.h | 29 +---------------------------- 1 file changed, 1 insertion(+), 28 deletions(-)
diff --git a/arch/m68k/include/asm/io.h b/arch/m68k/include/asm/io.h index 384308b..dfe77f0 100644 --- a/arch/m68k/include/asm/io.h +++ b/arch/m68k/include/asm/io.h @@ -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__ */
tested on mcf5307 amcore board.
Acked-by: Angelo Dureghello angelo@sysam.it Tested-by: Angelo Dureghello angelo@sysam.it
many thanks, Best regards, Angelo Dureghello

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.
Signed-off-by: Paul Burton paul.burton@imgtec.com Cc: Michal Simek monstr@monstr.eu ---
arch/microblaze/include/asm/io.h | 29 +---------------------------- 1 file changed, 1 insertion(+), 28 deletions(-)
diff --git a/arch/microblaze/include/asm/io.h b/arch/microblaze/include/asm/io.h index 584cbce..c7516a4 100644 --- a/arch/microblaze/include/asm/io.h +++ b/arch/microblaze/include/asm/io.h @@ -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__ */

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.
Signed-off-by: Paul Burton paul.burton@imgtec.com Cc: Macpaul Lin macpaul@andestech.com ---
arch/nds32/include/asm/io.h | 32 +++----------------------------- 1 file changed, 3 insertions(+), 29 deletions(-)
diff --git a/arch/nds32/include/asm/io.h b/arch/nds32/include/asm/io.h index b2c4d0e..46ce8c4 100644 --- a/arch/nds32/include/asm/io.h +++ b/arch/nds32/include/asm/io.h @@ -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 */

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.
Signed-off-by: Paul Burton paul.burton@imgtec.com Cc: Stefan Kristiansson stefan.kristiansson@saunalahti.fi ---
arch/openrisc/include/asm/io.h | 35 ++--------------------------------- 1 file changed, 2 insertions(+), 33 deletions(-)
diff --git a/arch/openrisc/include/asm/io.h b/arch/openrisc/include/asm/io.h index 86fbbc4..45c41b7 100644 --- a/arch/openrisc/include/asm/io.h +++ b/arch/openrisc/include/asm/io.h @@ -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

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.
Signed-off-by: Paul Burton paul.burton@imgtec.com Cc: Nobuhiro Iwamatsu iwamatsu@nigauri.org ---
arch/sh/include/asm/io.h | 29 +---------------------------- 1 file changed, 1 insertion(+), 28 deletions(-)
diff --git a/arch/sh/include/asm/io.h b/arch/sh/include/asm/io.h index 5dc27be..2847d8d 100644 --- a/arch/sh/include/asm/io.h +++ b/arch/sh/include/asm/io.h @@ -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 */

On 10/01/2016 05:19 PM, Paul Burton wrote:
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.
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.
Signed-off-by: Paul Burton paul.burton@imgtec.com Cc: Nobuhiro Iwamatsu iwamatsu@nigauri.org
-- Best wishes, Vladimir

On 10/01/2016 05:19 PM, Paul Burton wrote:
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.
Signed-off-by: Paul Burton paul.burton@imgtec.com Cc: Nobuhiro Iwamatsu iwamatsu@nigauri.org
Reviewed-by: Vladimir Zapolskiy vz@mleia.com Tested-by: Vladimir Zapolskiy vz@mleia.com
Thank you for the change.
-- With best wishes, Vladimir

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.
Signed-off-by: Paul Burton paul.burton@imgtec.com ---
arch/sparc/include/asm/io.h | 30 +----------------------------- 1 file changed, 1 insertion(+), 29 deletions(-)
diff --git a/arch/sparc/include/asm/io.h b/arch/sparc/include/asm/io.h index a317d13..08ec7d5 100644 --- a/arch/sparc/include/asm/io.h +++ b/arch/sparc/include/asm/io.h @@ -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

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.
Signed-off-by: Paul Burton paul.burton@imgtec.com Cc: Simon Glass sjg@chromium.org ---
arch/x86/include/asm/io.h | 31 ++----------------------------- 1 file changed, 2 insertions(+), 29 deletions(-)
diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h index 3156781..6f29a73 100644 --- a/arch/x86/include/asm/io.h +++ b/arch/x86/include/asm/io.h @@ -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

On 1 October 2016 at 08:19, Paul Burton paul.burton@imgtec.com wrote:
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.
Signed-off-by: Paul Burton paul.burton@imgtec.com Cc: Simon Glass sjg@chromium.org
arch/x86/include/asm/io.h | 31 ++----------------------------- 1 file changed, 2 insertions(+), 29 deletions(-)
Reviewed-by: Simon Glass sjg@chromium.org

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.
Signed-off-by: Paul Burton paul.burton@imgtec.com Cc: Max Filippov jcmvbkbc@gmail.com ---
arch/xtensa/include/asm/io.h | 25 ++----------------------- 1 file changed, 2 insertions(+), 23 deletions(-)
diff --git a/arch/xtensa/include/asm/io.h b/arch/xtensa/include/asm/io.h index e34d6e1..c9e335f 100644 --- a/arch/xtensa/include/asm/io.h +++ b/arch/xtensa/include/asm/io.h @@ -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 */

On Sat, Oct 1, 2016 at 7:19 AM, Paul Burton paul.burton@imgtec.com wrote:
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.
Signed-off-by: Paul Burton paul.burton@imgtec.com Cc: Max Filippov jcmvbkbc@gmail.com
arch/xtensa/include/asm/io.h | 25 ++----------------------- 1 file changed, 2 insertions(+), 23 deletions(-)
Acked-by: Max Filippov jcmvbkbc@gmail.com

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.
Signed-off-by: Paul Burton paul.burton@imgtec.com Cc: Daniel Schwierzeck daniel.schwierzeck@gmail.com ---
arch/mips/include/asm/io.h | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-)
diff --git a/arch/mips/include/asm/io.h b/arch/mips/include/asm/io.h index 5b86386..be9616a 100644 --- a/arch/mips/include/asm/io.h +++ b/arch/mips/include/asm/io.h @@ -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 */

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.
Signed-off-by: Paul Burton paul.burton@imgtec.com Cc: Daniel Schwierzeck daniel.schwierzeck@gmail.com ---
arch/mips/include/asm/io.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/mips/include/asm/io.h b/arch/mips/include/asm/io.h index be9616a..45d7ca0 100644 --- a/arch/mips/include/asm/io.h +++ b/arch/mips/include/asm/io.h @@ -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

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.
Signed-off-by: Paul Burton paul.burton@imgtec.com Cc: Thomas Chou thomas@wytron.com.tw ---
arch/nios2/include/asm/io.h | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/arch/nios2/include/asm/io.h b/arch/nios2/include/asm/io.h index e951500..4e5b44a 100644 --- a/arch/nios2/include/asm/io.h +++ b/arch/nios2/include/asm/io.h @@ -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_ */

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.
Signed-off-by: Paul Burton paul.burton@imgtec.com Cc: Wolfgang Denk wd@denx.de ---
arch/powerpc/include/asm/io.h | 25 +++++-------------------- 1 file changed, 5 insertions(+), 20 deletions(-)
diff --git a/arch/powerpc/include/asm/io.h b/arch/powerpc/include/asm/io.h index a54fc46..34fbfdf 100644 --- a/arch/powerpc/include/asm/io.h +++ b/arch/powerpc/include/asm/io.h @@ -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

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().
Signed-off-by: Paul Burton paul.burton@imgtec.com Cc: Simon Glass sjg@chromium.org ---
arch/sandbox/cpu/cpu.c | 12 +++++++++++- arch/sandbox/include/asm/io.h | 17 ++++++++--------- 2 files changed, 19 insertions(+), 10 deletions(-)
diff --git a/arch/sandbox/cpu/cpu.c b/arch/sandbox/cpu/cpu.c index 2def722..e160f62 100644 --- a/arch/sandbox/cpu/cpu.c +++ b/arch/sandbox/cpu/cpu.c @@ -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) diff --git a/arch/sandbox/include/asm/io.h b/arch/sandbox/include/asm/io.h index 6919632..3afbcea 100644 --- a/arch/sandbox/include/asm/io.h +++ b/arch/sandbox/include/asm/io.h @@ -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>

On 1 October 2016 at 08:19, Paul Burton paul.burton@imgtec.com wrote:
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().
Signed-off-by: Paul Burton paul.burton@imgtec.com Cc: Simon Glass sjg@chromium.org
arch/sandbox/cpu/cpu.c | 12 +++++++++++- arch/sandbox/include/asm/io.h | 17 ++++++++--------- 2 files changed, 19 insertions(+), 10 deletions(-)
Acked-by: Simon Glass sjg@chromium.org

On Sat, Oct 01, 2016 at 03:19:20PM +0100, Paul Burton wrote:
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]
+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]
-/*
- 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]
@@ -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!

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.
Signed-off-by: Paul Burton paul.burton@imgtec.com ---
common/board_f.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/common/board_f.c b/common/board_f.c index 2c88595..1afc80d 100644 --- a/common/board_f.c +++ b/common/board_f.c @@ -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);

On 1 October 2016 at 08:19, Paul Burton paul.burton@imgtec.com wrote:
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.
Signed-off-by: Paul Burton paul.burton@imgtec.com
common/board_f.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Reviewed-by: Simon Glass sjg@chromium.org

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.
Signed-off-by: Paul Burton paul.burton@imgtec.com ---
common/image.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/common/image.c b/common/image.c index a5d19ab..1581022 100644 --- a/common/image.c +++ b/common/image.c @@ -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

On 1 October 2016 at 08:19, Paul Burton paul.burton@imgtec.com wrote:
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.
Signed-off-by: Paul Burton paul.burton@imgtec.com
common/image.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Reviewed-by: Simon Glass sjg@chromium.org

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.
Signed-off-by: Paul Burton paul.burton@imgtec.com ---
common/image.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/common/image.c b/common/image.c index 1581022..25e632b 100644 --- a/common/image.c +++ b/common/image.c @@ -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");

Hi Paul,
On 1 October 2016 at 08:19, Paul Burton paul.burton@imgtec.com wrote:
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?
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.
Signed-off-by: Paul Burton paul.burton@imgtec.com
common/image.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/common/image.c b/common/image.c index 1581022..25e632b 100644 --- a/common/image.c +++ b/common/image.c @@ -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");
-- 2.10.0
Regards, Simon

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.
Signed-off-by: Paul Burton paul.burton@imgtec.com Cc: Daniel Schwierzeck daniel.schwierzeck@gmail.com ---
arch/mips/lib/bootm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/mips/lib/bootm.c b/arch/mips/lib/bootm.c index 0c6a4ab..9fec4ad 100644 --- a/arch/mips/lib/bootm.c +++ b/arch/mips/lib/bootm.c @@ -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)

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.
Signed-off-by: Paul Burton paul.burton@imgtec.com Cc: Daniel Schwierzeck daniel.schwierzeck@gmail.com ---
arch/mips/cpu/start.S | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/arch/mips/cpu/start.S b/arch/mips/cpu/start.S index 3f0fc12..936d63c 100644 --- a/arch/mips/cpu/start.S +++ b/arch/mips/cpu/start.S @@ -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

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().
Signed-off-by: Paul Burton paul.burton@imgtec.com Cc: Daniel Schwierzeck daniel.schwierzeck@gmail.com ---
board/imgtec/boston/ddr.c | 8 ++------ include/configs/boston.h | 21 ++++++++++----------- 2 files changed, 12 insertions(+), 17 deletions(-)
diff --git a/board/imgtec/boston/ddr.c b/board/imgtec/boston/ddr.c index ceffef6..e765627 100644 --- a/board/imgtec/boston/ddr.c +++ b/board/imgtec/boston/ddr.c @@ -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)); } diff --git a/include/configs/boston.h b/include/configs/boston.h index e958054..37060b0 100644 --- a/include/configs/boston.h +++ b/include/configs/boston.h @@ -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)

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.
Signed-off-by: Paul Burton paul.burton@imgtec.com Cc: Daniel Schwierzeck daniel.schwierzeck@gmail.com ---
include/configs/malta.h | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-)
diff --git a/include/configs/malta.h b/include/configs/malta.h index fc4baba..5bc9f23 100644 --- a/include/configs/malta.h +++ b/include/configs/malta.h @@ -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)

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.
Signed-off-by: Paul Burton paul.burton@imgtec.com Cc: Daniel Schwierzeck daniel.schwierzeck@gmail.com Cc: Zubair Lutfullah Kakakhel Zubair.Kakakhel@imgtec.com ---
include/configs/imgtec_xilfpga.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/include/configs/imgtec_xilfpga.h b/include/configs/imgtec_xilfpga.h index 0a7fe60..1583f21 100644 --- a/include/configs/imgtec_xilfpga.h +++ b/include/configs/imgtec_xilfpga.h @@ -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

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.
Signed-off-by: Paul Burton paul.burton@imgtec.com Cc: Daniel Schwierzeck daniel.schwierzeck@gmail.com Cc: Marek Vasut marex@denx.de Cc: Purna Chandra Mandal purna.mandal@microchip.com Cc: Wills Wang wills.wang@live.com ---
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(-)
diff --git a/include/configs/ap121.h b/include/configs/ap121.h index bf5746f..63e0015 100644 --- a/include/configs/ap121.h +++ b/include/configs/ap121.h @@ -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 diff --git a/include/configs/ap143.h b/include/configs/ap143.h index 5d7e49e..a8721e6 100644 --- a/include/configs/ap143.h +++ b/include/configs/ap143.h @@ -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 diff --git a/include/configs/dbau1x00.h b/include/configs/dbau1x00.h index dbd2bb3..b369d71 100644 --- a/include/configs/dbau1x00.h +++ b/include/configs/dbau1x00.h @@ -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 */
diff --git a/include/configs/pb1x00.h b/include/configs/pb1x00.h index fb5278f..8ef334f 100644 --- a/include/configs/pb1x00.h +++ b/include/configs/pb1x00.h @@ -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 */
diff --git a/include/configs/pic32mzdask.h b/include/configs/pic32mzdask.h index 49c98d8..5b80b46 100644 --- a/include/configs/pic32mzdask.h +++ b/include/configs/pic32mzdask.h @@ -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 */ diff --git a/include/configs/qemu-mips.h b/include/configs/qemu-mips.h index 546c508..7e839a8 100644 --- a/include/configs/qemu-mips.h +++ b/include/configs/qemu-mips.h @@ -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 diff --git a/include/configs/qemu-mips64.h b/include/configs/qemu-mips64.h index 6cab719..18e3294 100644 --- a/include/configs/qemu-mips64.h +++ b/include/configs/qemu-mips64.h @@ -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 diff --git a/include/configs/tplink_wdr4300.h b/include/configs/tplink_wdr4300.h index 7bf8e4c..5a6a0d4 100644 --- a/include/configs/tplink_wdr4300.h +++ b/include/configs/tplink_wdr4300.h @@ -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
diff --git a/include/configs/vct.h b/include/configs/vct.h index f2e0e5c..3e50619 100644 --- a/include/configs/vct.h +++ b/include/configs/vct.h @@ -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

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.
Signed-off-by: Paul Burton paul.burton@imgtec.com Cc: Daniel Schwierzeck daniel.schwierzeck@gmail.com
---
arch/mips/lib/bootm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/mips/lib/bootm.c b/arch/mips/lib/bootm.c index 9fec4ad..00991cb 100644 --- a/arch/mips/lib/bootm.c +++ b/arch/mips/lib/bootm.c @@ -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);

Hi Paul,
2016-10-01 23:19 GMT+09:00 Paul Burton paul.burton@imgtec.com:
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.
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,

On Sunday, 2 October 2016 22:46:45 BST Masahiro Yamada wrote:
Hi Paul,
2016-10-01 23:19 GMT+09:00 Paul Burton paul.burton@imgtec.com:
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.
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).
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
participants (8)
-
Alexey Brodkin
-
Angelo Dureghello
-
Masahiro Yamada
-
Max Filippov
-
Paul Burton
-
Simon Glass
-
Tom Rini
-
Vladimir Zapolskiy