* lib/header.h (PCI_*_MASK): Cast to pciaddr_t explicitly.
* lib/pci.h: Types declared in <sys/types.h> 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
+2003-12-26 Martin Mares <mj@ucw.cz>
+
+ * lib/header.h (PCI_*_MASK): Cast to pciaddr_t explicitly.
+
+ * lib/pci.h: Types declared in <sys/types.h> 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 <metgerards@student.han.nl>
Added support for the GNU Hurd (cleaned up by Martin Mares):
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
;;
#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) */
#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 */
/*
* The PCI Library
*
- * Copyright (c) 1997--2002 Martin Mares <mj@ucw.cz>
+ * Copyright (c) 1997--2003 Martin Mares <mj@ucw.cz>
*
* Can be freely distributed and used under the terms of the GNU GPL.
*/
#include "header.h"
/*
- * Types
+ * Types and format strings
*/
-#ifdef OS_LINUX
-#include <linux/types.h>
-
-typedef __u8 byte;
-typedef __u8 u8;
-typedef __u16 word;
-typedef __u16 u16;
-typedef __u32 u32;
-
-#endif
-
-#ifdef OS_FREEBSD
#include <sys/types.h>
typedef u_int8_t byte;
typedef u_int16_t word;
typedef u_int16_t u16;
typedef u_int32_t u32;
-#endif
-
-#ifdef OS_NETBSD
-#include <sys/types.h>
-
-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 <sys/param.h>
-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 <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 "%016Lx"
+#define PCIADDR_PORT_FMT "%04Lx"
#endif
-
-#ifdef OS_GNU
-#include <sys/types.h>
-
-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
/*
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,
&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;
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
else if (x < 0x80000000)
printf("%dM", (int)(x / 1048576));
else
- printf(ADDR_FORMAT, x);
+ printf(PCIADDR_T_FMT, x);
putchar(']');
}
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("<ignored>");
else
if (buscentric_view)
{
if (a || z)
- printf("%08x" ADDR_FORMAT, z, a);
+ printf("%08x" PCIADDR_T_FMT, z, a);
else
printf("<unassigned>");
done = 1;
if (!done)
{
if (a)
- printf(ADDR_FORMAT, a);
+ printf(PCIADDR_T_FMT, a);
else
printf(((flg & PCI_BASE_ADDRESS_MEM_MASK) || z) ? "<ignored>" : "<unassigned>");
}
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("<unassigned>");
if (!(rom & PCI_ROM_ADDRESS_ENABLE))
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
if (cmd & PCI_COMMAND_MASTER)
printf(", latency %d", latency);
if (irq)
- printf(", IRQ " IRQ_FORMAT, irq);
+ printf(", IRQ " PCIIRQ_FMT, irq);
putchar('\n');
}