unsigned long is not the right type for manipulating pointer values. Since C99 there are suitable unsigned and signed types available, namely uintptr_t and intptr_t respectively.
Use them in functions assigned to programmers' map_flash_region fields and their callers where applicable.
This patch also changes the display width of all associated address values in physmap.c to 16/8 hex characters depending on the actual size by introducing a macro PRIxPTR_WIDTH and exploiting printf's * field width specifier.
Signed-off-by: Stefan Tauner stefan.tauner@student.tuwien.ac.at Acked-by: Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net ---
Can you please verify that this is what you want? I put the _WIDTH macro in flash.h now for obvious reasons.
dummyflasher.c | 6 +++--- flash.h | 4 ++-- flashrom.c | 3 +-- physmap.c | 33 ++++++++++++++++----------------- programmer.c | 2 +- programmer.h | 10 +++++----- 6 files changed, 28 insertions(+), 30 deletions(-)
diff --git a/dummyflasher.c b/dummyflasher.c index e2ec036..cc15b00 100644 --- a/dummyflasher.c +++ b/dummyflasher.c @@ -412,10 +412,10 @@ dummy_init_out: return 0; }
-void *dummy_map(const char *descr, unsigned long phys_addr, size_t len) +void *dummy_map(const char *descr, uintptr_t phys_addr, size_t len) { - msg_pspew("%s: Mapping %s, 0x%lx bytes at 0x%08lx\n", - __func__, descr, (unsigned long)len, phys_addr); + msg_pspew("%s: Mapping %s, 0x%lx bytes at 0x%*" PRIxPTR "\n", + __func__, descr, (unsigned long)len, PRIxPTR_WIDTH, phys_addr); return (void *)phys_addr; }
diff --git a/flash.h b/flash.h index 9e787c0..cba7bd8 100644 --- a/flash.h +++ b/flash.h @@ -43,10 +43,10 @@
/* TODO: check using code for correct usage of types */ typedef uintptr_t chipaddr; +#define PRIxPTR_WIDTH ((int)(sizeof(uintptr_t)*2))
int register_shutdown(int (*function) (void *data), void *data); -void *programmer_map_flash_region(const char *descr, unsigned long phys_addr, - size_t len); +void *programmer_map_flash_region(const char *descr, uintptr_t phys_addr, size_t len); void programmer_unmap_flash_region(void *virt_addr, size_t len); void programmer_delay(int usecs);
diff --git a/flashrom.c b/flashrom.c index b9c0395..b05faf3 100644 --- a/flashrom.c +++ b/flashrom.c @@ -417,8 +417,7 @@ int programmer_shutdown(void) return ret; }
-void *programmer_map_flash_region(const char *descr, unsigned long phys_addr, - size_t len) +void *programmer_map_flash_region(const char *descr, uintptr_t phys_addr, size_t len) { return programmer_table[programmer].map_flash_region(descr, phys_addr, len); diff --git a/physmap.c b/physmap.c index 6e3d646..5e22883 100644 --- a/physmap.c +++ b/physmap.c @@ -42,7 +42,7 @@
static void *realmem_map;
-static void *map_first_meg(unsigned long phys_addr, size_t len) +static void *map_first_meg(uintptr_t phys_addr, size_t len) { if (realmem_map) return realmem_map + phys_addr; @@ -61,7 +61,7 @@ static void *map_first_meg(unsigned long phys_addr, size_t len) return realmem_map + phys_addr; }
-static void *sys_physmap(unsigned long phys_addr, size_t len) +static void *sys_physmap(uintptr_t phys_addr, size_t len) { int ret; __dpmi_meminfo mi; @@ -109,7 +109,7 @@ void physunmap(void *virt_addr, size_t len)
#define MEM_DEV ""
-void *sys_physmap(unsigned long phys_addr, size_t len) +void *sys_physmap(uintptr_t phys_addr, size_t len) { return (void *)phys_to_virt(phys_addr); } @@ -124,7 +124,7 @@ void physunmap(void *virt_addr, size_t len)
#define MEM_DEV "DirectHW"
-static void *sys_physmap(unsigned long phys_addr, size_t len) +static void *sys_physmap(uintptr_t phys_addr, size_t len) { /* The short form of ?: is a GNU extension. * FIXME: map_physical returns NULL both for errors and for success @@ -156,7 +156,7 @@ static int fd_mem = -1; static int fd_mem_cached = -1;
/* For MMIO access. Must be uncached, doesn't make sense to restrict to ro. */ -static void *sys_physmap_rw_uncached(unsigned long phys_addr, size_t len) +static void *sys_physmap_rw_uncached(uintptr_t phys_addr, size_t len) { void *virt_addr;
@@ -176,7 +176,7 @@ static void *sys_physmap_rw_uncached(unsigned long phys_addr, size_t len) /* For reading DMI/coreboot/whatever tables. We should never write, and we * do not care about caching. */ -static void *sys_physmap_ro_cached(unsigned long phys_addr, size_t len) +static void *sys_physmap_ro_cached(uintptr_t phys_addr, size_t len) { void *virt_addr;
@@ -209,25 +209,24 @@ void physunmap(void *virt_addr, size_t len) #define PHYSMAP_RW 0 #define PHYSMAP_RO 1
-static void *physmap_common(const char *descr, unsigned long phys_addr, +static void *physmap_common(const char *descr, uintptr_t phys_addr, size_t len, int mayfail, int readonly) { void *virt_addr;
if (len == 0) { - msg_pspew("Not mapping %s, zero size at 0x%08lx.\n", - descr, phys_addr); + msg_pspew("Not mapping %s, zero size at 0x%0*" PRIxPTR ".\n", descr, PRIxPTR_WIDTH, phys_addr); return ERROR_PTR; }
if ((getpagesize() - 1) & len) { - msg_perr("Mapping %s at 0x%08lx, unaligned size 0x%lx.\n", - descr, phys_addr, (unsigned long)len); + msg_perr("Mapping %s at 0x%0*" PRIxPTR ", unaligned size 0x%lx.\n", + descr, PRIxPTR_WIDTH, phys_addr, (unsigned long)len); }
if ((getpagesize() - 1) & phys_addr) { - msg_perr("Mapping %s, 0x%lx bytes at unaligned 0x%08lx.\n", - descr, (unsigned long)len, phys_addr); + msg_perr("Mapping %s, 0x%lx bytes at unaligned 0x%0*" PRIxPTR ".\n", + descr, (unsigned long)len, PRIxPTR_WIDTH, phys_addr); }
if (readonly) @@ -238,8 +237,8 @@ static void *physmap_common(const char *descr, unsigned long phys_addr, if (ERROR_PTR == virt_addr) { if (NULL == descr) descr = "memory"; - msg_perr("Error accessing %s, 0x%lx bytes at 0x%08lx\n", descr, - (unsigned long)len, phys_addr); + msg_perr("Error accessing %s, 0x%lx bytes at 0x%0*" PRIxPTR "\n", + descr, (unsigned long)len, PRIxPTR_WIDTH, phys_addr); msg_perr(MEM_DEV " mmap failed: %s\n", strerror(errno)); #ifdef __linux__ if (EINVAL == errno) { @@ -261,13 +260,13 @@ static void *physmap_common(const char *descr, unsigned long phys_addr, return virt_addr; }
-void *physmap(const char *descr, unsigned long phys_addr, size_t len) +void *physmap(const char *descr, uintptr_t phys_addr, size_t len) { return physmap_common(descr, phys_addr, len, PHYSMAP_NOFAIL, PHYSMAP_RW); }
-void *physmap_try_ro(const char *descr, unsigned long phys_addr, size_t len) +void *physmap_try_ro(const char *descr, uintptr_t phys_addr, size_t len) { return physmap_common(descr, phys_addr, len, PHYSMAP_MAYFAIL, PHYSMAP_RO); diff --git a/programmer.c b/programmer.c index 3b4def0..bf7dca1 100644 --- a/programmer.c +++ b/programmer.c @@ -28,7 +28,7 @@ int noop_shutdown(void) }
/* Fallback map() for programmers which don't need special handling */ -void *fallback_map(const char *descr, unsigned long phys_addr, size_t len) +void *fallback_map(const char *descr, uintptr_t phys_addr, size_t len) { /* FIXME: Should return phys_addr. */ return NULL; diff --git a/programmer.h b/programmer.h index 2ea7b48..db914cb 100644 --- a/programmer.h +++ b/programmer.h @@ -117,7 +117,7 @@ struct programmer_entry {
int (*init) (void);
- void *(*map_flash_region) (const char *descr, unsigned long phys_addr, size_t len); + void *(*map_flash_region) (const char *descr, uintptr_t phys_addr, size_t len); void (*unmap_flash_region) (void *virt_addr, size_t len);
void (*delay) (int usecs); @@ -275,8 +275,8 @@ int processor_flash_enable(void); #endif
/* physmap.c */ -void *physmap(const char *descr, unsigned long phys_addr, size_t len); -void *physmap_try_ro(const char *descr, unsigned long phys_addr, size_t len); +void *physmap(const char *descr, uintptr_t phys_addr, size_t len); +void *physmap_try_ro(const char *descr, uintptr_t phys_addr, size_t len); void physunmap(void *virt_addr, size_t len); #if CONFIG_INTERNAL == 1 int setup_cpu_msr(int cpu); @@ -359,7 +359,7 @@ void rmmio_vall(void *addr); /* dummyflasher.c */ #if CONFIG_DUMMY == 1 int dummy_init(void); -void *dummy_map(const char *descr, unsigned long phys_addr, size_t len); +void *dummy_map(const char *descr, uintptr_t phys_addr, size_t len); void dummy_unmap(void *virt_addr, size_t len); #endif
@@ -606,7 +606,7 @@ int register_opaque_programmer(const struct opaque_programmer *pgm);
/* programmer.c */ int noop_shutdown(void); -void *fallback_map(const char *descr, unsigned long phys_addr, size_t len); +void *fallback_map(const char *descr, uintptr_t phys_addr, size_t len); void fallback_unmap(void *virt_addr, size_t len); void noop_chip_writeb(const struct flashctx *flash, uint8_t val, chipaddr addr); void fallback_chip_writew(const struct flashctx *flash, uint16_t val, chipaddr addr);