From 0f51f62c6265af5977fec7425596b65a3926c42b Mon Sep 17 00:00:00 2001 From: Thomas Heijligen Date: Thu, 20 Jan 2022 16:45:14 +0100 Subject: hwaccess_x86_io: clean header concept Move all function implementations into the .c file TEST: `[g]make [WARNERROR=no]` on Linux, FreeBSD, NetBSD, OpenBSD, DragonflyBSD, OpenIndiana, Debian-GNU/Hurd Change-Id: I1400704e9ac5fed00c096796536108d5bfb875e3 Signed-off-by: Thomas Heijligen Reviewed-on: https://review.coreboot.org/c/flashrom/+/61276 Tested-by: build bot (Jenkins) Reviewed-by: Nico Huber --- hwaccess_x86_io.h | 149 ++++++------------------------------------------------ 1 file changed, 15 insertions(+), 134 deletions(-) (limited to 'hwaccess_x86_io.h') diff --git a/hwaccess_x86_io.h b/hwaccess_x86_io.h index 0d16fdde4..31d1e86c8 100644 --- a/hwaccess_x86_io.h +++ b/hwaccess_x86_io.h @@ -2,6 +2,8 @@ * This file is part of the flashrom project. * * Copyright (C) 2009 Carl-Daniel Hailfinger + * Copyright (C) 2022 secunet Security Networks AG + * (Written by Thomas Heijligen -#elif defined(__linux__) || defined(__GLIBC__) -#include -#endif - -/* for iopl and outb under Solaris */ -#if defined (__sun) -#include -#include -#include -#endif - -int rget_io_perms(void); - -/* Clarification about OUTB/OUTW/OUTL argument order: - * OUT[BWL](val, port) +#include +/** */ +int rget_io_perms(void); -#if defined(__FreeBSD__) || defined(__DragonFly__) - /* Note that Debian/kFreeBSD (FreeBSD kernel with glibc) has conflicting - * out[bwl] definitions in machine/cpufunc.h and sys/io.h at least in some - * versions. Use machine/cpufunc.h only for plain FreeBSD/DragonFlyBSD. - */ - #include - #include - #define OUTB(x, y) do { u_int outb_tmp = (y); outb(outb_tmp, (x)); } while (0) - #define OUTW(x, y) do { u_int outw_tmp = (y); outw(outw_tmp, (x)); } while (0) - #define OUTL(x, y) do { u_int outl_tmp = (y); outl(outl_tmp, (x)); } while (0) - #define INB(x) __extension__ ({ u_int inb_tmp = (x); inb(inb_tmp); }) - #define INW(x) __extension__ ({ u_int inw_tmp = (x); inw(inw_tmp); }) - #define INL(x) __extension__ ({ u_int inl_tmp = (x); inl(inl_tmp); }) -#else - -#if defined (__sun) - /* Note different order for outb */ - #define OUTB(x,y) outb(y, x) - #define OUTW(x,y) outw(y, x) - #define OUTL(x,y) outl(y, x) - #define INB inb - #define INW inw - #define INL inl -#else - -#ifdef __DJGPP__ - -#include - - #define OUTB(x,y) outportb(y, x) - #define OUTW(x,y) outportw(y, x) - #define OUTL(x,y) outportl(y, x) - - #define INB inportb - #define INW inportw - #define INL inportl - -#else - -#if defined(__MACH__) && defined(__APPLE__) - /* Header is part of the DirectHW library. */ - #include -#endif - - /* This is the usual glibc interface. */ - #define OUTB outb - #define OUTW outw - #define OUTL outl - #define INB inb - #define INW inw - #define INL inl -#endif -#endif -#endif - -#if defined(__NetBSD__) || defined (__OpenBSD__) - #if defined(__i386__) || defined(__x86_64__) - #include - #include - #if defined(__NetBSD__) - #if defined(__i386__) - #define iopl i386_iopl - #elif defined(__x86_64__) - #define iopl x86_64_iopl - #endif - #elif defined (__OpenBSD__) - #if defined(__i386__) - #define iopl i386_iopl - #elif defined(__amd64__) - #define iopl amd64_iopl - #endif - #endif - -static inline void outb(uint8_t value, uint16_t port) -{ - __asm__ volatile ("outb %b0,%w1": :"a" (value), "Nd" (port)); -} - -static inline uint8_t inb(uint16_t port) -{ - uint8_t value; - __asm__ volatile ("inb %w1,%0":"=a" (value):"Nd" (port)); - return value; -} - -static inline void outw(uint16_t value, uint16_t port) -{ - __asm__ volatile ("outw %w0,%w1": :"a" (value), "Nd" (port)); -} - -static inline uint16_t inw(uint16_t port) -{ - uint16_t value; - __asm__ volatile ("inw %w1,%0":"=a" (value):"Nd" (port)); - return value; -} - -static inline void outl(uint32_t value, uint16_t port) -{ - __asm__ volatile ("outl %0,%w1": :"a" (value), "Nd" (port)); -} - -static inline uint32_t inl(uint16_t port) -{ - uint32_t value; - __asm__ volatile ("inl %1,%0":"=a" (value):"Nd" (port)); - return value; -} - #endif -#endif +void OUTB(uint8_t value, uint16_t port); +void OUTW(uint16_t value, uint16_t port); +void OUTL(uint32_t value, uint16_t port); +uint8_t INB(uint16_t port); +uint16_t INW(uint16_t port); +uint32_t INL(uint16_t port); #endif /* __HWACCESS_X86_IO_H__ */ -- cgit v1.2.3