Author: stefanct Date: Thu Jul 18 01:46:44 2013 New Revision: 1701 URL: http://flashrom.org/trac/flashrom/changeset/1701
Log: uintptr_t-ify map_flash_region functions.
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
Modified: trunk/dummyflasher.c trunk/flash.h trunk/flashrom.c trunk/physmap.c trunk/programmer.c trunk/programmer.h
Modified: trunk/dummyflasher.c ============================================================================== --- trunk/dummyflasher.c Wed Jul 17 11:28:00 2013 (r1700) +++ trunk/dummyflasher.c Thu Jul 18 01:46:44 2013 (r1701) @@ -412,10 +412,10 @@ 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; }
Modified: trunk/flash.h ============================================================================== --- trunk/flash.h Wed Jul 17 11:28:00 2013 (r1700) +++ trunk/flash.h Thu Jul 18 01:46:44 2013 (r1701) @@ -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);
Modified: trunk/flashrom.c ============================================================================== --- trunk/flashrom.c Wed Jul 17 11:28:00 2013 (r1700) +++ trunk/flashrom.c Thu Jul 18 01:46:44 2013 (r1701) @@ -417,8 +417,7 @@ 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);
Modified: trunk/physmap.c ============================================================================== --- trunk/physmap.c Wed Jul 17 11:28:00 2013 (r1700) +++ trunk/physmap.c Thu Jul 18 01:46:44 2013 (r1701) @@ -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 @@ 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 @@
#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 @@
#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_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 @@ /* 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 @@ #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 @@ 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 @@ 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);
Modified: trunk/programmer.c ============================================================================== --- trunk/programmer.c Wed Jul 17 11:28:00 2013 (r1700) +++ trunk/programmer.c Thu Jul 18 01:46:44 2013 (r1701) @@ -28,7 +28,7 @@ }
/* 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;
Modified: trunk/programmer.h ============================================================================== --- trunk/programmer.h Wed Jul 17 11:28:00 2013 (r1700) +++ trunk/programmer.h Thu Jul 18 01:46:44 2013 (r1701) @@ -117,7 +117,7 @@
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 @@ #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 @@ /* 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 @@
/* 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);