From 9739916e9827883e27c82beabac1586fef01543a Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Fri, 26 Dec 2003 22:52:21 +0000 Subject: [PATCH] Clean up types * lib/header.h (PCI_*_MASK): Cast to pciaddr_t explicitly. * lib/pci.h: Types declared in should be usable on all platforms we currently support, so kill the forest of #ifdef's and use them in all cases. * lib/pci.h: Use ULONG_MASK to decide whether we should use long or long long to represent a 64-bit address. Killed HAVE_LONG_ADDRESS. Define format strings for addresses, port numbers and IRQ numbers directly in pci.h. * lib/proc.c (proc_scan): Use PCIADDR_T_FMT for scanf'ing addresses. git-archimport-id: mj@ucw.cz--public/pciutils--main--2.2--patch-17 --- ChangeLog | 15 ++++++++++++ lib/configure | 6 ++--- lib/header.h | 6 ++--- lib/pci.h | 68 +++++++++++++++++---------------------------------- lib/proc.c | 9 +++---- lspci.c | 40 ++++++------------------------ 6 files changed, 53 insertions(+), 91 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1931228..bc5648c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2003-12-26 Martin Mares + + * lib/header.h (PCI_*_MASK): Cast to pciaddr_t explicitly. + + * lib/pci.h: Types declared in should be usable on all + platforms we currently support, so kill the forest of #ifdef's and + use them in all cases. + + * lib/pci.h: Use ULONG_MASK to decide whether we should use long + or long long to represent a 64-bit address. Killed HAVE_LONG_ADDRESS. + Define format strings for addresses, port numbers and IRQ numbers + directly in pci.h. + + * lib/proc.c (proc_scan): Use PCIADDR_T_FMT for scanf'ing addresses. + 2003-12-26 Marco Gerards Added support for the GNU Hurd (cleaned up by Martin Mares): diff --git a/lib/configure b/lib/configure index c169c8b..43f7c5f 100755 --- a/lib/configure +++ b/lib/configure @@ -45,10 +45,8 @@ case $sys in echo >>$c '#define HAVE_PM_INTEL_CONF' ok=1 ;; - alpha|ia64) echo >>$c '#define HAVE_64BIT_ADDRESS' - ;; - sparc|sparc64) echo >>$c '#define HAVE_64BIT_ADDRESS' - echo >>$c '#define HAVE_LONG_ADDRESS' + alpha|ia64|sparc|sparc64) + echo >>$c '#define HAVE_64BIT_ADDRESS' ;; esac ;; diff --git a/lib/header.h b/lib/header.h index 019eaea..5fb4101 100644 --- a/lib/header.h +++ b/lib/header.h @@ -78,8 +78,8 @@ #define PCI_BASE_ADDRESS_MEM_TYPE_1M 0x02 /* Below 1M [obsolete] */ #define PCI_BASE_ADDRESS_MEM_TYPE_64 0x04 /* 64 bit address */ #define PCI_BASE_ADDRESS_MEM_PREFETCH 0x08 /* prefetchable? */ -#define PCI_BASE_ADDRESS_MEM_MASK (~0x0fUL) -#define PCI_BASE_ADDRESS_IO_MASK (~0x03UL) +#define PCI_BASE_ADDRESS_MEM_MASK (~(pciaddr_t)0x0f) +#define PCI_BASE_ADDRESS_IO_MASK (~(pciaddr_t)0x03) /* bit 1 is reserved if address_space = 1 */ /* Header type 0 (normal devices) */ @@ -88,7 +88,7 @@ #define PCI_SUBSYSTEM_ID 0x2e #define PCI_ROM_ADDRESS 0x30 /* Bits 31..11 are address, 10..1 reserved */ #define PCI_ROM_ADDRESS_ENABLE 0x01 -#define PCI_ROM_ADDRESS_MASK (~0x7ffUL) +#define PCI_ROM_ADDRESS_MASK (~(pciaddr_t)0x7ff) #define PCI_CAPABILITY_LIST 0x34 /* Offset of first capability list entry */ diff --git a/lib/pci.h b/lib/pci.h index 263f3e7..782d6bc 100644 --- a/lib/pci.h +++ b/lib/pci.h @@ -1,7 +1,7 @@ /* * The PCI Library * - * Copyright (c) 1997--2002 Martin Mares + * Copyright (c) 1997--2003 Martin Mares * * Can be freely distributed and used under the terms of the GNU GPL. */ @@ -13,21 +13,9 @@ #include "header.h" /* - * Types + * Types and format strings */ -#ifdef OS_LINUX -#include - -typedef __u8 byte; -typedef __u8 u8; -typedef __u16 word; -typedef __u16 u16; -typedef __u32 u32; - -#endif - -#ifdef OS_FREEBSD #include typedef u_int8_t byte; @@ -35,42 +23,32 @@ typedef u_int8_t u8; typedef u_int16_t word; typedef u_int16_t u16; typedef u_int32_t u32; -#endif - -#ifdef OS_NETBSD -#include - -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 OS_AIX -#include -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; +#ifdef HAVE_64BIT_ADDRESS +#include +#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 "%016Lx" +#define PCIADDR_PORT_FMT "%04Lx" #endif - -#ifdef OS_GNU -#include - -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; +typedef u64 pciaddr_t; +#else +typedef u32 pciaddr_t; +#define PCIADDR_T_FMT "%08x" +#define PCIADDR_PORT_FMT "%04x" #endif -#ifdef HAVE_LONG_ADDRESS -typedef unsigned long long pciaddr_t; +#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 -typedef unsigned long pciaddr_t; +#define PCIIRQ_FMT "%d" #endif /* diff --git a/lib/proc.c b/lib/proc.c index 3e09a28..7a1191d 100644 --- a/lib/proc.c +++ b/lib/proc.c @@ -128,12 +128,8 @@ proc_scan(struct pci_access *a) struct pci_dev *d = pci_alloc_dev(a); unsigned int dfn, vend, cnt, known; - cnt = sscanf(buf, -#ifdef HAVE_LONG_ADDRESS - "%x %x %x %llx %llx %llx %llx %llx %llx %llx %llx %llx %llx %llx %llx %llx %llx", -#else - "%x %x %x %lx %lx %lx %lx %lx %lx %lx %lx %lx %lx %lx %lx %lx %lx", -#endif +#define F " " PCIADDR_T_FMT + cnt = sscanf(buf, "%x %x %x" F F F F F F F F F F F F F F, &dfn, &vend, &d->irq, @@ -151,6 +147,7 @@ proc_scan(struct pci_access *a) &d->size[4], &d->size[5], &d->rom_size); +#undef F if (cnt != 9 && cnt != 10 && cnt != 17) a->error("proc: parse error (read only %d items)", cnt); d->bus = dfn >> 8U; diff --git a/lspci.c b/lspci.c index a634fb5..6bdcf38 100644 --- a/lspci.c +++ b/lspci.c @@ -47,32 +47,6 @@ GENERIC_HELP static struct pci_access *pacc; -/* Format strings used for IRQ numbers and memory addresses */ - -#ifdef ARCH_SPARC64 -#define IRQ_FORMAT "%08x" -#else -#define IRQ_FORMAT "%d" -#endif - -#ifdef HAVE_64BIT_ADDRESS -#ifdef HAVE_LONG_ADDRESS -#define ADDR_FORMAT "%016Lx" -#else -#define ADDR_FORMAT "%016lx" -#endif -#else -#define ADDR_FORMAT "%08lx" -#endif - -#ifdef ARCH_SPARC64 -#define IO_FORMAT "%016Lx" -#elif defined(HAVE_LONG_ADDRESS) -#define IO_FORMAT "%04Lx" -#else -#define IO_FORMAT "%04lx" -#endif - /* * If we aren't being compiled by GCC, use malloc() instead of alloca(). * This increases our memory footprint, but only slightly since we don't @@ -280,7 +254,7 @@ show_size(pciaddr_t x) else if (x < 0x80000000) printf("%dM", (int)(x / 1048576)); else - printf(ADDR_FORMAT, x); + printf(PCIADDR_T_FMT, x); putchar(']'); } @@ -314,7 +288,7 @@ show_bases(struct device *d, int cnt) pciaddr_t a = pos & PCI_BASE_ADDRESS_IO_MASK; printf("I/O ports at "); if (a) - printf(IO_FORMAT, a); + printf(PCIADDR_PORT_FMT, a); else if (flg & PCI_BASE_ADDRESS_IO_MASK) printf(""); else @@ -344,7 +318,7 @@ show_bases(struct device *d, int cnt) if (buscentric_view) { if (a || z) - printf("%08x" ADDR_FORMAT, z, a); + printf("%08x" PCIADDR_T_FMT, z, a); else printf(""); done = 1; @@ -354,7 +328,7 @@ show_bases(struct device *d, int cnt) if (!done) { if (a) - printf(ADDR_FORMAT, a); + printf(PCIADDR_T_FMT, a); else printf(((flg & PCI_BASE_ADDRESS_MEM_MASK) || z) ? "" : ""); } @@ -579,7 +553,7 @@ show_rom(struct device *d) return; printf("\tExpansion ROM at "); if (rom & PCI_ROM_ADDRESS_MASK) - printf(ADDR_FORMAT, rom & PCI_ROM_ADDRESS_MASK); + printf(PCIADDR_T_FMT, rom & PCI_ROM_ADDRESS_MASK); else printf(""); if (!(rom & PCI_ROM_ADDRESS_ENABLE)) @@ -934,7 +908,7 @@ show_verbose(struct device *d) putchar('\n'); } if (int_pin || irq) - printf("\tInterrupt: pin %c routed to IRQ " IRQ_FORMAT "\n", + printf("\tInterrupt: pin %c routed to IRQ " PCIIRQ_FMT "\n", (int_pin ? 'A' + int_pin - 1 : '?'), irq); } else @@ -959,7 +933,7 @@ show_verbose(struct device *d) if (cmd & PCI_COMMAND_MASTER) printf(", latency %d", latency); if (irq) - printf(", IRQ " IRQ_FORMAT, irq); + printf(", IRQ " PCIIRQ_FMT, irq); putchar('\n'); } -- 2.39.2