diff mbox

[U-Boot,17/27] sandbox: Use asm-generic/io.h

Message ID 20161001141931.32354-18-paul.burton@imgtec.com
State Changes Requested
Delegated to: Tom Rini
Headers show

Commit Message

Paul Burton Oct. 1, 2016, 2:19 p.m. UTC
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(-)

Comments

Simon Glass Oct. 3, 2016, 9:49 p.m. UTC | #1
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>
Tom Rini Oct. 13, 2016, 4:16 p.m. UTC | #2
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!
diff mbox

Patch

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>