j
: Next unread message k
: Previous unread message j a
: Jump to all threads
j l
: Jump to MailingList overview
Author: afaerber Date: Sun Nov 21 20:20:54 2010 New Revision: 965 URL: http://tracker.coreboot.org/trac/openbios/changeset/965
Log: ppc: Convert I/O macros to inline functions
Suggested by Blue.
Clean up function signatures while at it.
v4: * Convert all I/O functions to use POSIX types for value. Suggested by Alex.
v3: * Split off isa_io_base changes.
v2: * Make port uint16_t, suggested by Alex. * Adapt isa_io_base for ppc64.
Cc: Blue Swirl blauwirbel@gmail.com Signed-off-by: Andreas Färber andreas.faerber@web.de Signed-off-by: Alexander Graf agraf@suse.de
Modified: trunk/openbios-devel/include/arch/ppc/io.h
Modified: trunk/openbios-devel/include/arch/ppc/io.h ============================================================================== --- trunk/openbios-devel/include/arch/ppc/io.h Sun Nov 21 14:32:37 2010 (r964) +++ trunk/openbios-devel/include/arch/ppc/io.h Sun Nov 21 20:20:54 2010 (r965) @@ -17,89 +17,73 @@ extern unsigned long isa_io_base;
/* - * The insw/outsw/insl/outsl macros don't do byte-swapping. - * They are only used in practice for transferring buffers which - * are arrays of bytes, and byte-swapping is not appropriate in - * that case. - paulus - */ -#define insw(port, buf, ns) _insw((uint16_t *)(uintptr_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 *)(uintptr_t)((port)+isa_io_base)) -#define outb(val, port) out_8((uint8_t *)(uintptr_t)((port)+isa_io_base), (val)) -#define inw(port) in_le16((uint16_t *)(uintptr_t)((port)+isa_io_base)) -#define outw(val, port) out_le16((uint16_t *)(uintptr_t)((port)+isa_io_base), (val)) -#define inl(port) in_le32((uint32_t *)(uintptr_t)((port)+isa_io_base)) -#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. */ -static inline int in_8(volatile unsigned char *addr) +static inline uint8_t in_8(volatile uint8_t *addr) { - int ret; + uint8_t ret;
__asm__ __volatile__("lbz%U1%X1 %0,%1; eieio":"=r"(ret):"m"(*addr)); return ret; }
-static inline void out_8(volatile unsigned char *addr, int val) +static inline void out_8(volatile uint8_t *addr, uint8_t val) { __asm__ __volatile__("stb%U0%X0 %1,%0; eieio":"=m"(*addr):"r"(val)); }
-static inline int in_le16(volatile unsigned short *addr) +static inline uint16_t in_le16(volatile uint16_t *addr) { - int ret; + uint16_t ret;
__asm__ __volatile__("lhbrx %0,0,%1; eieio":"=r"(ret): "r"(addr), "m"(*addr)); return ret; }
-static inline int in_be16(volatile unsigned short *addr) +static inline uint16_t in_be16(volatile uint16_t *addr) { - int ret; + uint16_t ret;
__asm__ __volatile__("lhz%U1%X1 %0,%1; eieio":"=r"(ret):"m"(*addr)); return ret; }
-static inline void out_le16(volatile unsigned short *addr, int val) +static inline void out_le16(volatile uint16_t *addr, uint16_t val) { __asm__ __volatile__("sthbrx %1,0,%2; eieio":"=m"(*addr):"r"(val), "r"(addr)); }
-static inline void out_be16(volatile unsigned short *addr, int val) +static inline void out_be16(volatile uint16_t *addr, uint16_t val) { __asm__ __volatile__("sth%U0%X0 %1,%0; eieio":"=m"(*addr):"r"(val)); }
-static inline unsigned in_le32(volatile unsigned *addr) +static inline uint32_t in_le32(volatile uint32_t *addr) { - unsigned ret; + uint32_t ret;
__asm__ __volatile__("lwbrx %0,0,%1; eieio":"=r"(ret): "r"(addr), "m"(*addr)); return ret; }
-static inline unsigned in_be32(volatile unsigned *addr) +static inline uint32_t in_be32(volatile uint32_t *addr) { - unsigned ret; + uint32_t ret;
__asm__ __volatile__("lwz%U1%X1 %0,%1; eieio":"=r"(ret):"m"(*addr)); return ret; }
-static inline void out_le32(volatile unsigned *addr, int val) +static inline void out_le32(volatile uint32_t *addr, uint32_t val) { __asm__ __volatile__("stwbrx %1,0,%2; eieio":"=m"(*addr):"r"(val), "r"(addr)); }
-static inline void out_be32(volatile unsigned *addr, int val) +static inline void out_be32(volatile unsigned *addr, uint32_t val) { __asm__ __volatile__("stw%U0%X0 %1,%0; eieio":"=m"(*addr):"r"(val)); } @@ -145,6 +129,56 @@ ns--; } } + + +/* + * The insw/outsw/insl/outsl functions don't do byte-swapping. + * They are only used in practice for transferring buffers which + * are arrays of bytes, and byte-swapping is not appropriate in + * that case. - paulus + */ + +static inline void insw(uint16_t port, void *buf, int ns) +{ + _insw((uint16_t *)(port + isa_io_base), buf, ns); +} + +static inline void outsw(uint16_t port, void *buf, int ns) +{ + _outsw((uint16_t *)(port + isa_io_base), buf, ns); +} + + +static inline uint8_t inb(uint16_t port) +{ + return in_8((uint8_t *)(port + isa_io_base)); +} + +static inline void outb(uint8_t val, uint16_t port) +{ + out_8((uint8_t *)(port + isa_io_base), val); +} + +static inline uint16_t inw(uint16_t port) +{ + return in_le16((uint16_t *)(port + isa_io_base)); +} + +static inline void outw(uint16_t val, uint16_t port) +{ + out_le16((uint16_t *)(port + isa_io_base), val); +} + +static inline uint32_t inl(uint16_t port) +{ + return in_le32((uint32_t *)(port + isa_io_base)); +} + +static inline void outl(uint32_t val, uint16_t port) +{ + out_le32((uint32_t *)(port + isa_io_base), val); +} + #else /* BOOTSTRAP */ #ifdef FCOMPILER #define inb(reg) ((u8)0xff)