Don't make assumptions about device address size

Prefer phys_addr_t for physical addresses.

Resort to uintptr_t where a conversion to pointer occurs,
since the physical address may be larger (e.g., sparc32).

v2:
* Use phys_addr_t.

Signed-off-by: Andreas Färber <andreas.faerber@web.de>


git-svn-id: svn://coreboot.org/openbios/trunk/openbios-devel@933 f158a5a8-5612-0410-a976-696ce0be7e32
This commit is contained in:
Andreas Färber
2010-10-30 16:26:02 +00:00
committed by Andreas Färber
parent 70bbfcf6ce
commit 8356ea4eb9
8 changed files with 43 additions and 43 deletions

View File

@@ -369,7 +369,7 @@ rtc_init(char *path)
} }
cuda_t *cuda_init (const char *path, uint32_t base) cuda_t *cuda_init (const char *path, phys_addr_t base)
{ {
cuda_t *cuda; cuda_t *cuda;
char buf[64]; char buf[64];

View File

@@ -1,7 +1,7 @@
#include "adb_bus.h" #include "adb_bus.h"
struct cuda_t { struct cuda_t {
uint32_t base; phys_addr_t base;
adb_bus_t *adb_bus; adb_bus_t *adb_bus;
}; };
typedef struct cuda_t cuda_t; typedef struct cuda_t cuda_t;
@@ -14,4 +14,4 @@ enum {
CHARDEV_LAST, CHARDEV_LAST,
}; };
cuda_t *cuda_init (const char *path, uint32_t base); cuda_t *cuda_init (const char *path, phys_addr_t base);

View File

@@ -13,11 +13,11 @@
static volatile unsigned char *serial_dev; static volatile unsigned char *serial_dev;
#define CTRL(addr) (*(volatile unsigned char *)(addr)) #define CTRL(addr) (*(volatile unsigned char *)(uintptr_t)(addr))
#ifdef CONFIG_DRIVER_ESCC_SUN #ifdef CONFIG_DRIVER_ESCC_SUN
#define DATA(addr) (*(volatile unsigned char *)(addr + 2)) #define DATA(addr) (*(volatile unsigned char *)(uintptr_t)(addr + 2))
#else #else
#define DATA(addr) (*(volatile unsigned char *)(addr + 16)) #define DATA(addr) (*(volatile unsigned char *)(uintptr_t)(addr + 16))
#endif #endif
/* Conversion routines to/from brg time constants from/to bits /* Conversion routines to/from brg time constants from/to bits
@@ -54,19 +54,19 @@ static volatile unsigned char *serial_dev;
#define Rx_CH_AV 0x1 /* Rx Character Available */ #define Rx_CH_AV 0x1 /* Rx Character Available */
#define Tx_BUF_EMP 0x4 /* Tx Buffer empty */ #define Tx_BUF_EMP 0x4 /* Tx Buffer empty */
int uart_charav(int port) int uart_charav(uintptr_t port)
{ {
return (CTRL(port) & Rx_CH_AV) != 0; return (CTRL(port) & Rx_CH_AV) != 0;
} }
char uart_getchar(int port) char uart_getchar(uintptr_t port)
{ {
while (!uart_charav(port)) while (!uart_charav(port))
; ;
return DATA(port) & 0177; return DATA(port) & 0177;
} }
static void uart_putchar(int port, unsigned char c) static void uart_putchar(uintptr_t port, unsigned char c)
{ {
if (!serial_dev) if (!serial_dev)
return; return;
@@ -102,13 +102,13 @@ static void uart_init_line(volatile unsigned char *port, unsigned long baud)
} }
int uart_init(uint64_t port, unsigned long speed) int uart_init(phys_addr_t port, unsigned long speed)
{ {
#ifdef CONFIG_DRIVER_ESCC_SUN #ifdef CONFIG_DRIVER_ESCC_SUN
serial_dev = map_io(port & ~7ULL, ZS_REGS); serial_dev = map_io(port & ~7ULL, ZS_REGS);
serial_dev += port & 7ULL; serial_dev += port & 7ULL;
#else #else
serial_dev = (unsigned char *)(unsigned long)port; serial_dev = (unsigned char *)(uintptr_t)port;
#endif #endif
uart_init_line(serial_dev, speed); uart_init_line(serial_dev, speed);
return -1; return -1;
@@ -116,7 +116,7 @@ int uart_init(uint64_t port, unsigned long speed)
void serial_putchar(int c) void serial_putchar(int c)
{ {
uart_putchar((int)serial_dev, (unsigned char) (c & 0xff)); uart_putchar((uintptr_t)serial_dev, (unsigned char) (c & 0xff));
} }
void serial_cls(void) void serial_cls(void)
@@ -131,7 +131,7 @@ void serial_cls(void)
/* ( addr len -- actual ) */ /* ( addr len -- actual ) */
static void static void
escc_read(unsigned long *address) escc_read(phys_addr_t *address)
{ {
char *addr; char *addr;
int len; int len;
@@ -140,7 +140,7 @@ escc_read(unsigned long *address)
addr = (char *)cell2pointer(POP()); addr = (char *)cell2pointer(POP());
if (len < 1) if (len < 1)
printk("escc_read: bad len, addr %x len %x\n", (unsigned int)addr, len); printk("escc_read: bad len, addr %p len %x\n", addr, len);
if (uart_charav(*address)) { if (uart_charav(*address)) {
*addr = (char)uart_getchar(*address); *addr = (char)uart_getchar(*address);
@@ -152,7 +152,7 @@ escc_read(unsigned long *address)
/* ( addr len -- actual ) */ /* ( addr len -- actual ) */
static void static void
escc_write(unsigned long *address) escc_write(phys_addr_t *address)
{ {
unsigned char *addr; unsigned char *addr;
int i, len; int i, len;
@@ -172,7 +172,7 @@ escc_close(void)
} }
static void static void
escc_open(unsigned long *address) escc_open(phys_addr_t *address)
{ {
#ifdef CONFIG_DRIVER_ESCC_SUN #ifdef CONFIG_DRIVER_ESCC_SUN
int len; int len;
@@ -199,7 +199,7 @@ escc_open(unsigned long *address)
RET ( -1 ); RET ( -1 );
} }
DECLARE_UNNAMED_NODE(escc, INSTALL_OPEN, sizeof(unsigned long)); DECLARE_UNNAMED_NODE(escc, INSTALL_OPEN, sizeof(phys_addr_t));
NODE_METHODS(escc) = { NODE_METHODS(escc) = {
{ "open", escc_open }, { "open", escc_open },
@@ -211,7 +211,7 @@ NODE_METHODS(escc) = {
#ifdef CONFIG_DRIVER_ESCC_SUN #ifdef CONFIG_DRIVER_ESCC_SUN
static volatile unsigned char *kbd_dev; static volatile unsigned char *kbd_dev;
void kbd_init(uint64_t base) void kbd_init(phys_addr_t base)
{ {
kbd_dev = map_io(base, 2 * 4); kbd_dev = map_io(base, 2 * 4);
kbd_dev += 4; kbd_dev += 4;
@@ -295,7 +295,7 @@ escc_read_keyboard(void)
addr = (unsigned char *)POP(); addr = (unsigned char *)POP();
if (len < 1) if (len < 1)
printk("escc_read: bad len, addr %x len %x\n", (unsigned int)addr, len); printk("escc_read: bad len, addr %p len %x\n", addr, len);
if (keyboard_dataready()) { if (keyboard_dataready()) {
*addr = keyboard_readdata(); *addr = keyboard_readdata();
@@ -305,7 +305,7 @@ escc_read_keyboard(void)
} }
} }
DECLARE_UNNAMED_NODE(escc_keyboard, INSTALL_OPEN, sizeof(unsigned long)); DECLARE_UNNAMED_NODE(escc_keyboard, INSTALL_OPEN, sizeof(phys_addr_t));
NODE_METHODS(escc_keyboard) = { NODE_METHODS(escc_keyboard) = {
{ "open", escc_open }, { "open", escc_open },
@@ -314,7 +314,7 @@ NODE_METHODS(escc_keyboard) = {
}; };
void void
ob_zs_init(uint64_t base, uint64_t offset, int intr, int slave, int keyboard) ob_zs_init(phys_addr_t base, uint64_t offset, int intr, int slave, int keyboard)
{ {
char nodebuff[256]; char nodebuff[256];
phandle_t aliases; phandle_t aliases;
@@ -369,7 +369,7 @@ ob_zs_init(uint64_t base, uint64_t offset, int intr, int slave, int keyboard)
#else #else
static void static void
escc_add_channel(const char *path, const char *node, uint32_t addr, escc_add_channel(const char *path, const char *node, phys_addr_t addr,
uint32_t offset) uint32_t offset)
{ {
char buf[64], tty[32]; char buf[64], tty[32];
@@ -430,7 +430,7 @@ escc_add_channel(const char *path, const char *node, uint32_t addr,
} }
void void
escc_init(const char *path, unsigned long addr) escc_init(const char *path, phys_addr_t addr)
{ {
char buf[64]; char buf[64];
int props[2]; int props[2];

View File

@@ -4,6 +4,6 @@
#define ZS_REGS 8 #define ZS_REGS 8
void escc_init(const char *path, unsigned long addr); void escc_init(const char *path, phys_addr_t addr);
void ob_zs_init(uint64_t base, uint64_t offset, int intr, int slave, void ob_zs_init(phys_addr_t base, uint64_t offset, int intr, int slave,
int keyboard); int keyboard);

View File

@@ -43,7 +43,7 @@ arch_nvram_size( void )
return NW_IO_NVRAM_SIZE >> NW_IO_NVRAM_SHIFT; return NW_IO_NVRAM_SIZE >> NW_IO_NVRAM_SHIFT;
} }
void macio_nvram_init(const char *path, uint32_t addr) void macio_nvram_init(const char *path, phys_addr_t addr)
{ {
phandle_t chosen, aliases; phandle_t chosen, aliases;
phandle_t dnode; phandle_t dnode;
@@ -145,7 +145,7 @@ arch_nvram_get( char *buf )
} }
static void static void
openpic_init(const char *path, uint32_t addr) openpic_init(const char *path, phys_addr_t addr)
{ {
phandle_t target_node; phandle_t target_node;
phandle_t dnode; phandle_t dnode;
@@ -238,7 +238,7 @@ NODE_METHODS(ob_macio) = {
}; };
void void
ob_macio_heathrow_init(const char *path, uint32_t addr) ob_macio_heathrow_init(const char *path, phys_addr_t addr)
{ {
phandle_t aliases; phandle_t aliases;
@@ -253,7 +253,7 @@ ob_macio_heathrow_init(const char *path, uint32_t addr)
} }
void void
ob_macio_keylargo_init(const char *path, uint32_t addr) ob_macio_keylargo_init(const char *path, phys_addr_t addr)
{ {
phandle_t aliases; phandle_t aliases;

View File

@@ -1,5 +1,5 @@
extern phandle_t pic_handle; extern phandle_t pic_handle;
void ob_macio_heathrow_init(const char *path, uint32_t addr); void ob_macio_heathrow_init(const char *path, phys_addr_t addr);
void ob_macio_keylargo_init(const char *path, uint32_t addr); void ob_macio_keylargo_init(const char *path, phys_addr_t addr);
void macio_nvram_init(const char *path, uint32_t addr); void macio_nvram_init(const char *path, phys_addr_t addr);

View File

@@ -22,15 +22,15 @@ extern uint32_t isa_io_base;
* are arrays of bytes, and byte-swapping is not appropriate in * are arrays of bytes, and byte-swapping is not appropriate in
* that case. - paulus * that case. - paulus
*/ */
#define insw(port, buf, ns) _insw((uint16_t *)((port)+isa_io_base), (buf), (ns)) #define insw(port, buf, ns) _insw((uint16_t *)(uintptr_t)((port)+isa_io_base), (buf), (ns))
#define outsw(port, buf, ns) _outsw((uint16_t *)((port)+isa_io_base), (buf), (ns)) #define outsw(port, buf, ns) _outsw((uint16_t *)(uintptr_t)((port)+isa_io_base), (buf), (ns))
#define inb(port) in_8((uint8_t *)((port)+isa_io_base)) #define inb(port) in_8((uint8_t *)(uintptr_t)((port)+isa_io_base))
#define outb(val, port) out_8((uint8_t *)((port)+isa_io_base), (val)) #define outb(val, port) out_8((uint8_t *)(uintptr_t)((port)+isa_io_base), (val))
#define inw(port) in_le16((uint16_t *)((port)+isa_io_base)) #define inw(port) in_le16((uint16_t *)(uintptr_t)((port)+isa_io_base))
#define outw(val, port) out_le16((uint16_t *)((port)+isa_io_base), (val)) #define outw(val, port) out_le16((uint16_t *)(uintptr_t)((port)+isa_io_base), (val))
#define inl(port) in_le32((uint32_t *)((port)+isa_io_base)) #define inl(port) in_le32((uint32_t *)(uintptr_t)((port)+isa_io_base))
#define outl(val, port) out_le32((uint32_t *)((port)+isa_io_base), (val)) #define outl(val, port) out_le32((uint32_t *)(uintptr_t)((port)+isa_io_base), (val))
/* /*
* 8, 16 and 32 bit, big and little endian I/O operations, with barrier. * 8, 16 and 32 bit, big and little endian I/O operations, with barrier.

View File

@@ -113,9 +113,9 @@ char uart_getchar(int port);
void serial_putchar(int c); void serial_putchar(int c);
#endif #endif
#ifdef CONFIG_DRIVER_ESCC #ifdef CONFIG_DRIVER_ESCC
int uart_init(uint64_t port, unsigned long speed); int uart_init(phys_addr_t port, unsigned long speed);
int uart_charav(int port); int uart_charav(uintptr_t port);
char uart_getchar(int port); char uart_getchar(uintptr_t port);
void serial_putchar(int c); void serial_putchar(int c);
void serial_cls(void); void serial_cls(void);
#ifdef CONFIG_DRIVER_ESCC_SUN #ifdef CONFIG_DRIVER_ESCC_SUN