diff options
author | Martin Mares <mj@ucw.cz> | 2004-08-13 20:36:33 +0000 |
---|---|---|
committer | Martin Mares <mj@ucw.cz> | 2006-05-05 14:18:24 +0200 |
commit | 489233b45bc68e94b2d065f696ed22bc6e6eec02 (patch) | |
tree | c3e94f6b3112058d73ce8cc284df2455649c0228 /lib | |
parent | 9bb4b4ea9c4fe02c45d0c8087a2342a44eda450d (diff) | |
download | pciutils-489233b45bc68e94b2d065f696ed22bc6e6eec02.tar.gz |
Include file splits and namespace cleanups.
git-archimport-id: mj@ucw.cz--public/pciutils--main--2.2--patch-60
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Makefile | 22 | ||||
-rw-r--r-- | lib/access.c | 16 | ||||
-rwxr-xr-x | lib/configure | 36 | ||||
-rw-r--r-- | lib/fbsd-device.c | 2 | ||||
-rw-r--r-- | lib/generic.c | 2 | ||||
-rw-r--r-- | lib/i386-ports.c | 8 | ||||
-rw-r--r-- | lib/internal.h | 71 | ||||
-rw-r--r-- | lib/nbsd-libpci.c | 2 | ||||
-rw-r--r-- | lib/pci.h | 48 | ||||
-rw-r--r-- | lib/pread.h | 6 | ||||
-rw-r--r-- | lib/proc.c | 2 | ||||
-rw-r--r-- | lib/sysdep.h | 73 | ||||
-rw-r--r-- | lib/sysfs.c | 2 | ||||
-rw-r--r-- | lib/types.h | 57 |
14 files changed, 180 insertions, 167 deletions
diff --git a/lib/Makefile b/lib/Makefile index b0a2de8..44296ca 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -4,31 +4,31 @@ include config.mk OBJS=access.o generic.o dump.o names.o filter.o -INCL=internal.h pci.h config.h +INCL=internal.h pci.h config.h header.h sysdep.h types.h PCILIB=libpci.a -ifdef HAVE_PM_LINUX_SYSFS +ifdef PCI_HAVE_PM_LINUX_SYSFS OBJS += sysfs.o endif -ifdef HAVE_PM_LINUX_PROC +ifdef PCI_HAVE_PM_LINUX_PROC OBJS += proc.o endif -ifdef HAVE_PM_INTEL_CONF +ifdef PCI_HAVE_PM_INTEL_CONF OBJS += i386-ports.o endif -ifdef HAVE_PM_DUMP +ifdef PCI_HAVE_PM_DUMP OBJS += dump.o endif -ifdef HAVE_PM_SYSCALLS +ifdef PCI_HAVE_PM_SYSCALLS OBJS += syscalls.o endif -ifdef HAVE_PM_FBSD_DEVICE +ifdef PCI_HAVE_PM_FBSD_DEVICE OBJS += fbsd-device.o CFLAGS += -I/usr/src/sys ifdef FREEBSD_SYS @@ -36,19 +36,15 @@ CFLAGS += -I${FREEBSD_SYS} endif endif -ifdef HAVE_PM_AIX_DEVICE +ifdef PCI_HAVE_PM_AIX_DEVICE OBJS += aix-device.o endif -ifdef HAVE_PM_NBSD_LIBPCI +ifdef PCI_HAVE_PM_NBSD_LIBPCI OBJS += nbsd-libpci.o PCILIB=libpciutils.a endif -ifdef HAVE_OWN_HEADER_H -INCL += header.h -endif - all: $(PCILIB) $(PCILIB): $(OBJS) diff --git a/lib/access.c b/lib/access.c index eee22d2..5683eac 100644 --- a/lib/access.c +++ b/lib/access.c @@ -15,39 +15,39 @@ static struct pci_methods *pci_methods[PCI_ACCESS_MAX] = { NULL, -#ifdef HAVE_PM_LINUX_SYSFS +#ifdef PCI_HAVE_PM_LINUX_SYSFS &pm_linux_sysfs, #else NULL, #endif -#ifdef HAVE_PM_LINUX_PROC +#ifdef PCI_HAVE_PM_LINUX_PROC &pm_linux_proc, #else NULL, #endif -#ifdef HAVE_PM_INTEL_CONF +#ifdef PCI_HAVE_PM_INTEL_CONF &pm_intel_conf1, &pm_intel_conf2, #else NULL, NULL, #endif -#ifdef HAVE_PM_FBSD_DEVICE +#ifdef PCI_HAVE_PM_FBSD_DEVICE &pm_fbsd_device, #else NULL, #endif -#ifdef HAVE_PM_AIX_DEVICE +#ifdef PCI_HAVE_PM_AIX_DEVICE &pm_aix_device, #else NULL, #endif -#ifdef HAVE_PM_NBSD_LIBPCI +#ifdef PCI_HAVE_PM_NBSD_LIBPCI &pm_nbsd_libpci, #else NULL, #endif -#ifdef HAVE_PM_DUMP +#ifdef PCI_HAVE_PM_DUMP &pm_dump, #else NULL, @@ -61,7 +61,7 @@ pci_alloc(void) int i; bzero(a, sizeof(*a)); - a->id_file_name = PATH_PCI_IDS; + a->id_file_name = PCI_PATH_IDS; for(i=0; i<PCI_ACCESS_MAX; i++) if (pci_methods[i] && pci_methods[i]->config) pci_methods[i]->config(a); diff --git a/lib/configure b/lib/configure index 8ff9040..dd70651 100755 --- a/lib/configure +++ b/lib/configure @@ -30,8 +30,8 @@ rel=${4:-$rel} echo " $host $rel" c=config.h -echo >$c "#define ARCH_`echo $cpu | tr 'a-z' 'A-Z'`" -echo >>$c "#define OS_`echo $sys | tr 'a-z' 'A-Z'`" +echo >$c "#define PCI_ARCH_`echo $cpu | tr 'a-z' 'A-Z'`" +echo >>$c "#define PCI_OS_`echo $sys | tr 'a-z' 'A-Z'`" echo_n "Looking for access methods..." @@ -39,28 +39,28 @@ case $sys in linux*) case $rel in 2.[1-9]*|[3-9]*) echo_n "sysfs proc" - echo >>$c '#define HAVE_PM_LINUX_SYSFS' - echo >>$c '#define HAVE_PM_LINUX_PROC' - echo >>$c '#define HAVE_LINUX_BYTEORDER_H' - echo >>$c '#define PATH_PROC_BUS_PCI "/proc/bus/pci"' - echo >>$c '#define PATH_SYS_BUS_PCI "/sys/bus/pci"' + echo >>$c '#define PCI_HAVE_PM_LINUX_SYSFS' + echo >>$c '#define PCI_HAVE_PM_LINUX_PROC' + echo >>$c '#define PCI_HAVE_LINUX_BYTEORDER_H' + echo >>$c '#define PCI_PATH_PROC_BUS_PCI "/proc/bus/pci"' + echo >>$c '#define PCI_PATH_SYS_BUS_PCI "/sys/bus/pci"' ok=1 ;; esac case $cpu in i386) echo_n " i386-ports" - echo >>$c '#define HAVE_PM_INTEL_CONF' + echo >>$c '#define PCI_HAVE_PM_INTEL_CONF' ok=1 ;; alpha|ia64|sparc|sparc64|ppc|ppc64) - echo >>$c '#define HAVE_64BIT_ADDRESS' + echo >>$c '#define PCI_HAVE_64BIT_ADDRESS' ;; esac ;; sunos) case $cpu in i386) echo_n " i386-ports" - echo >>$c "#define HAVE_PM_INTEL_CONF" + echo >>$c "#define PCI_HAVE_PM_INTEL_CONF" ok=1 ;; *) @@ -72,24 +72,24 @@ case $sys in freebsd) echo_n " fbsd-device" - echo >>$c '#define HAVE_PM_FBSD_DEVICE' - echo >>$c '#define PATH_FBSD_DEVICE "/dev/pci"' + echo >>$c '#define PCI_HAVE_PM_FBSD_DEVICE' + echo >>$c '#define PCI_PATH_FBSD_DEVICE "/dev/pci"' ok=1 ;; aix) echo_n " aix-device" - echo >>$c '#define HAVE_PM_AIX_DEVICE' + echo >>$c '#define PCI_HAVE_PM_AIX_DEVICE' ok=1 ;; netbsd) echo_n " nbsd-libpci" - echo >>$c '#define HAVE_PM_NBSD_LIBPCI' - echo >>$c '#define PATH_NBSD_DEVICE "/dev/pci0"' + echo >>$c '#define PCI_HAVE_PM_NBSD_LIBPCI' + echo >>$c '#define PCI_PATH_NBSD_DEVICE "/dev/pci0"' ok=1 ;; gnu) echo_n " i386-ports" - echo >>$c '#define HAVE_PM_INTEL_CONF' + echo >>$c '#define PCI_HAVE_PM_INTEL_CONF' ok=1 ;; *) @@ -98,11 +98,11 @@ case $sys in ;; esac -echo >>$c '#define HAVE_PM_DUMP' +echo >>$c '#define PCI_HAVE_PM_DUMP' echo " dump" if [ -z "$ok" ] ; then echo "WARNING: No real configuration access method is available." fi -echo >>$c "#define PATH_PCI_IDS \"$sharedir/pci.ids\"" +echo >>$c "#define PCI_PATH_IDS \"$sharedir/pci.ids\"" echo >>$c "#define PCILIB_VERSION \"$version\"" sed '/^#define [^ ]*$/!d;s/^#define \(.*\)/\1=1/' <$c >config.mk diff --git a/lib/fbsd-device.c b/lib/fbsd-device.c index c0af6a1..833af56 100644 --- a/lib/fbsd-device.c +++ b/lib/fbsd-device.c @@ -29,7 +29,7 @@ static void fbsd_config(struct pci_access *a) { - a->method_params[PCI_ACCESS_FBSD_DEVICE] = PATH_FBSD_DEVICE; + a->method_params[PCI_ACCESS_FBSD_DEVICE] = PCI_PATH_FBSD_DEVICE; } static int diff --git a/lib/generic.c b/lib/generic.c index 0402ad1..a47bc15 100644 --- a/lib/generic.c +++ b/lib/generic.c @@ -122,7 +122,7 @@ pci_generic_fill_info(struct pci_dev *d, int flags) else { u32 y = pci_read_long(d, PCI_BASE_ADDRESS_0 + (++i)*4); -#ifdef HAVE_64BIT_ADDRESS +#ifdef PCI_HAVE_64BIT_ADDRESS d->base_addr[i-1] = x | (((pciaddr_t) y) << 32); #else if (y) diff --git a/lib/i386-ports.c b/lib/i386-ports.c index f225d24..9307ce9 100644 --- a/lib/i386-ports.c +++ b/lib/i386-ports.c @@ -10,13 +10,13 @@ #include "internal.h" -#if defined(OS_LINUX) +#if defined(PCI_OS_LINUX) #include "i386-io-linux.h" -#elif defined(OS_GNU) +#elif defined(PCI_OS_GNU) #include "i386-io-hurd.h" -#elif defined(OS_SUNOS) +#elif defined(PCI_OS_SUNOS) #include "i386-io-sunos.h" -#elif defined(OS_WINDOWS) +#elif defined(PCI_OS_WINDOWS) #include "i386-io-windows.h" #else #error Do not know how to access I/O ports on this OS. diff --git a/lib/internal.h b/lib/internal.h index a591f50..cae1800 100644 --- a/lib/internal.h +++ b/lib/internal.h @@ -1,5 +1,5 @@ /* - * The PCI Library -- Internal Include File + * The PCI Library -- Internal Stuff * * Copyright (c) 1997--2004 Martin Mares <mj@ucw.cz> * @@ -7,74 +7,7 @@ */ #include "pci.h" - -#ifdef __GNUC__ -#define UNUSED __attribute__((unused)) -#else -#define UNUSED -#define inline -#endif - -#ifdef HAVE_LINUX_BYTEORDER_H - -#include <asm/byteorder.h> -#define cpu_to_le16 __cpu_to_le16 -#define cpu_to_le32 __cpu_to_le32 -#define le16_to_cpu __le16_to_cpu -#define le32_to_cpu __le32_to_cpu - -#else - -#ifdef OS_LINUX -#include <endian.h> -#define BYTE_ORDER __BYTE_ORDER -#define BIG_ENDIAN __BIG_ENDIAN -#endif - -#ifdef OS_FREEBSD -#include <sys/types.h> -#endif - -#ifdef OS_SUNOS -#include <sys/byteorder.h> -#define BIG_ENDIAN 4321 -#ifdef _LITTLE_ENDIAN -#define BYTE_ORDER 1234 -#else -#define BYTE_ORDER 4321 -#endif -#endif - -#ifdef OS_WINDOWS -#include <sys/param.h> -#endif - -#if BYTE_ORDER == BIG_ENDIAN -#define cpu_to_le16 swab16 -#define cpu_to_le32 swab32 -#define le16_to_cpu swab16 -#define le32_to_cpu swab32 - -static inline word swab16(word w) -{ - return (w << 8) | ((w >> 8) & 0xff); -} - -static inline u32 swab32(u32 w) -{ - return ((w & 0xff000000) >> 24) | - ((w & 0x00ff0000) >> 8) | - ((w & 0x0000ff00) << 8) | - ((w & 0x000000ff) << 24); -} -#else -#define cpu_to_le16(x) (x) -#define cpu_to_le32(x) (x) -#define le16_to_cpu(x) (x) -#define le32_to_cpu(x) (x) -#endif - -#endif +#include "sysdep.h" struct pci_methods { char *name; diff --git a/lib/nbsd-libpci.c b/lib/nbsd-libpci.c index 6507287..c930501 100644 --- a/lib/nbsd-libpci.c +++ b/lib/nbsd-libpci.c @@ -25,7 +25,7 @@ static void nbsd_config(struct pci_access *a) { - a->method_params[PCI_ACCESS_NBSD_LIBPCI] = PATH_NBSD_DEVICE; + a->method_params[PCI_ACCESS_NBSD_LIBPCI] = PCI_PATH_NBSD_DEVICE; } static int @@ -11,53 +11,7 @@ #include "config.h" #include "header.h" - -/* - * Types and format strings - */ - -#include <sys/types.h> - -#ifdef OS_WINDOWS -typedef unsigned char byte; -typedef char u8; -typedef unsigned short word; -typedef short u16; -typedef unsigned long u32; -#else -typedef u_int8_t byte; -typedef u_int8_t u8; -typedef u_int16_t word; -typedef u_int16_t u16; -typedef u_int32_t u32; -#endif - -#ifdef HAVE_64BIT_ADDRESS -#include <limits.h> -#if ULONG_MAX > 0xffffffff -typedef unsigned long u64; -#define PCIADDR_T_FMT "%016lx" -#define PCIADDR_PORT_FMT "%04lx" -#else -typedef unsigned long long u64; -#define PCIADDR_T_FMT "%016llx" -#define PCIADDR_PORT_FMT "%04llx" -#endif -typedef u64 pciaddr_t; -#else -typedef u32 pciaddr_t; -#define PCIADDR_T_FMT "%08x" -#define PCIADDR_PORT_FMT "%04x" -#endif - -#ifdef ARCH_SPARC64 -/* On sparc64 Linux the kernel reports remapped port addresses and IRQ numbers */ -#undef PCIADDR_PORT_FMT -#define PCIADDR_PORT_FMT PCIADDR_T_FMT -#define PCIIRQ_FMT "%08x" -#else -#define PCIIRQ_FMT "%d" -#endif +#include "types.h" /* * PCI Access Structure diff --git a/lib/pread.h b/lib/pread.h index 4637078..0e64326 100644 --- a/lib/pread.h +++ b/lib/pread.h @@ -37,7 +37,7 @@ static _syscall5(int, pread, unsigned int, fd, void *, buf, size_t, size, u32, w static _syscall5(int, pwrite, unsigned int, fd, void *, buf, size_t, size, u32, where_lo, u32, where_hi); static int do_read(struct pci_dev *d UNUSED, int fd, void *buf, size_t size, int where) { return pread(fd, buf, size, where, 0); } static int do_write(struct pci_dev *d UNUSED, int fd, void *buf, size_t size, int where) { return pwrite(fd, buf, size, where, 0); } -#define HAVE_DO_READ +#define PCI_HAVE_DO_READ #else /* In all other cases we use lseek/read/write instead to be safe */ @@ -57,10 +57,10 @@ static int do_write(struct pci_dev *d UNUSED, int fd, void *buf, size_t size, in } make_rw_glue(read) make_rw_glue(write) -#define HAVE_DO_READ +#define PCI_HAVE_DO_READ #endif -#ifndef HAVE_DO_READ +#ifndef PCI_HAVE_DO_READ #define do_read(d,f,b,l,p) pread(f,b,l,p) #define do_write(d,f,b,l,p) pwrite(f,b,l,p) #endif @@ -21,7 +21,7 @@ static void proc_config(struct pci_access *a) { - a->method_params[PCI_ACCESS_PROC_BUS_PCI] = PATH_PROC_BUS_PCI; + a->method_params[PCI_ACCESS_PROC_BUS_PCI] = PCI_PATH_PROC_BUS_PCI; } static int diff --git a/lib/sysdep.h b/lib/sysdep.h new file mode 100644 index 0000000..70a407a --- /dev/null +++ b/lib/sysdep.h @@ -0,0 +1,73 @@ +/* + * The PCI Library -- System-Dependent Stuff + * + * Copyright (c) 1997--2004 Martin Mares <mj@ucw.cz> + * + * Can be freely distributed and used under the terms of the GNU GPL. + */ + +#ifdef __GNUC__ +#define UNUSED __attribute__((unused)) +#define NONRET __attribute__((noreturn)) +#else +#define UNUSED +#define NONRET +#define inline +#endif + +#ifdef PCI_HAVE_LINUX_BYTEORDER_H + +#include <asm/byteorder.h> +#define cpu_to_le16 __cpu_to_le16 +#define cpu_to_le32 __cpu_to_le32 +#define le16_to_cpu __le16_to_cpu +#define le32_to_cpu __le32_to_cpu + +#else + +#ifdef PCI_OS_LINUX +#include <endian.h> +#define BYTE_ORDER __BYTE_ORDER +#define BIG_ENDIAN __BIG_ENDIAN +#endif + +#ifdef PCI_OS_SUNOS +#include <sys/byteorder.h> +#define BIG_ENDIAN 4321 +#ifdef _LITTLE_ENDIAN +#define BYTE_ORDER 1234 +#else +#define BYTE_ORDER 4321 +#endif +#endif + +#ifdef PCI_OS_WINDOWS +#include <sys/param.h> +#endif + +#if BYTE_ORDER == BIG_ENDIAN +#define cpu_to_le16 swab16 +#define cpu_to_le32 swab32 +#define le16_to_cpu swab16 +#define le32_to_cpu swab32 + +static inline word swab16(word w) +{ + return (w << 8) | ((w >> 8) & 0xff); +} + +static inline u32 swab32(u32 w) +{ + return ((w & 0xff000000) >> 24) | + ((w & 0x00ff0000) >> 8) | + ((w & 0x0000ff00) << 8) | + ((w & 0x000000ff) << 24); +} +#else +#define cpu_to_le16(x) (x) +#define cpu_to_le32(x) (x) +#define le16_to_cpu(x) (x) +#define le32_to_cpu(x) (x) +#endif + +#endif diff --git a/lib/sysfs.c b/lib/sysfs.c index 74f6992..2c0a46f 100644 --- a/lib/sysfs.c +++ b/lib/sysfs.c @@ -25,7 +25,7 @@ static void sysfs_config(struct pci_access *a) { - a->method_params[PCI_ACCESS_SYS_BUS_PCI] = PATH_SYS_BUS_PCI; + a->method_params[PCI_ACCESS_SYS_BUS_PCI] = PCI_PATH_SYS_BUS_PCI; } static inline char * diff --git a/lib/types.h b/lib/types.h new file mode 100644 index 0000000..807bf37 --- /dev/null +++ b/lib/types.h @@ -0,0 +1,57 @@ +/* + * The PCI Library -- Types and Format Strings + * + * Copyright (c) 1997--2004 Martin Mares <mj@ucw.cz> + * + * Can be freely distributed and used under the terms of the GNU GPL. + */ + +#include <sys/types.h> + +#ifndef PCI_HAVE_Uxx_TYPES + +#ifdef PCI_OS_WINDOWS +typedef unsigned char byte; +typedef char u8; +typedef unsigned short word; +typedef short u16; +typedef unsigned long u32; +#else +typedef u_int8_t byte; +typedef u_int8_t u8; +typedef u_int16_t word; +typedef u_int16_t u16; +typedef u_int32_t u32; +#endif + +#ifdef PCI_HAVE_64BIT_ADDRESS +#include <limits.h> +#if ULONG_MAX > 0xffffffff +typedef unsigned long u64; +#define PCI_U64_FMT "l" +#else +typedef unsigned long long u64 +#define PCI_U64_FMT "ll" +#endif +#endif + +#endif /* PCI_HAVE_Uxx_TYPES */ + +#ifdef PCI_HAVE_64BIT_ADDRESS +typedef u64 pciaddr_t; +#define PCIADDR_T_FMT "%016" PCI_U64_FMT "x" +#define PCIADDR_PORT_FMT "%04" PCI_U64_FMT "x" +#else +typedef u32 pciaddr_t; +#define PCIADDR_T_FMT "%08x" +#define PCIADDR_PORT_FMT "%04x" +#endif + +#ifdef PCI_ARCH_SPARC64 +/* On sparc64 Linux the kernel reports remapped port addresses and IRQ numbers */ +#undef PCIADDR_PORT_FMT +#define PCIADDR_PORT_FMT PCIADDR_T_FMT +#define PCIIRQ_FMT "%08x" +#else +#define PCIIRQ_FMT "%d" +#endif |