Patchwork [U-Boot,RFC,29/44] sandbox: Provide a way to map from host RAM to U-Boot RAM

login
register
mail settings
Submitter Simon Glass
Date Jan. 5, 2013, 1:51 a.m.
Message ID <1357350734-13737-30-git-send-email-sjg@chromium.org>
Download mbox | patch
Permalink /patch/209626/
State Superseded, archived
Headers show

Comments

Simon Glass - Jan. 5, 2013, 1:51 a.m.
In many cases, pointers to memory are passed around, and these pointers
refer to U-Boot memory, not host memory. This in itself is not a
problem.

However, in a few places, we cast that pointer back to a ulong (being
a U-Boot memory address). It is possible to convert many of these cases
to avoid this. However there are data structures (e.g. struct
bootm_headers) which use pointers. We could with a lot of effort adjust
the structs and all code that uses them to use ulong instead of pointers.

This seems like an unacceptable cost, since our objective with sandbox
is to minimise the impact on U-Boot code while maximising the features
available to sandbox.

Therefore, create a map_to_sysmem() function which converts from a
pointer to a U-Boot address. This can be used sparingly when needed.

Signed-off-by: Simon Glass <sjg@chromium.org>
---
 arch/sandbox/cpu/cpu.c        |    5 +++++
 arch/sandbox/include/asm/io.h |    2 ++
 include/common.h              |    5 +++++
 3 files changed, 12 insertions(+), 0 deletions(-)

Patch

diff --git a/arch/sandbox/cpu/cpu.c b/arch/sandbox/cpu/cpu.c
index d7684d3..6459b01 100644
--- a/arch/sandbox/cpu/cpu.c
+++ b/arch/sandbox/cpu/cpu.c
@@ -57,6 +57,11 @@  void *map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags)
 	return (void *)(gd->ram_buf + paddr);
 }
 
+phys_addr_t map_to_sysmem(void *ptr)
+{
+	return (u8 *)ptr - gd->ram_buf;
+}
+
 void flush_dcache_range(unsigned long start, unsigned long stop)
 {
 }
diff --git a/arch/sandbox/include/asm/io.h b/arch/sandbox/include/asm/io.h
index d8c0236..4ce7a84 100644
--- a/arch/sandbox/include/asm/io.h
+++ b/arch/sandbox/include/asm/io.h
@@ -49,3 +49,5 @@  static inline void *map_sysmem(phys_addr_t paddr, unsigned long len)
 static inline void unmap_sysmem(const void *vaddr)
 {
 }
+
+phys_addr_t map_to_sysmem(void *ptr);
diff --git a/include/common.h b/include/common.h
index cc6bf5e..d2249b1 100644
--- a/include/common.h
+++ b/include/common.h
@@ -896,6 +896,11 @@  static inline void *map_sysmem(phys_addr_t paddr, unsigned long len)
 static inline void unmap_sysmem(const void *vaddr)
 {
 }
+
+static inline phys_addr_t map_to_sysmem(void *ptr)
+{
+	return (phys_addr_t)ptr;
+}
 # endif
 
 #endif /* __ASSEMBLY__ */