]> mj.ucw.cz Git - pciutils.git/commitdiff
Clean up types
authorMartin Mares <mj@ucw.cz>
Fri, 26 Dec 2003 22:52:21 +0000 (22:52 +0000)
committerMartin Mares <mj@ucw.cz>
Fri, 5 May 2006 12:18:11 +0000 (14:18 +0200)
* 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

ChangeLog
lib/configure
lib/header.h
lib/pci.h
lib/proc.c
lspci.c

index 1931228aa4acc378872a3ba296bc25fd39dbb651..bc5648c59f61cd6c4a6c636afd8c4c573773817b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+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):
index c169c8bc5fd16b43590fc68d1e72d62f2943a60c..43f7c5fd1f74f62d80d6710712e7541427082df3 100755 (executable)
@@ -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
                ;;
index 019eaeaf222d3b3a6fadc3dd3d25d291bb8223e2..5fb4101e87aa04623688d068d27e4b0bc10d1246 100644 (file)
@@ -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 */
 
index 263f3e77fd88024cc268e4978ec00076e5d26e69..782d6bcdbaf5fdc65066c751580eaa0630a16673 100644 (file)
--- a/lib/pci.h
+++ b/lib/pci.h
@@ -1,7 +1,7 @@
 /*
  *     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;
@@ -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 <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
 
 /*
index 3e09a2801eee6955806e1d6ca9dec8c8104b4ba0..7a1191da55af2df93a63676b58fd44e5cf2aa791 100644 (file)
@@ -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 a634fb50f915fd87e44ce8383beb26719f3de78d..6bdcf38f33dc281c609389f0232891ce95895b26 100644 (file)
--- 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("<ignored>");
          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("<unassigned>");
                      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) ? "<ignored>" : "<unassigned>");
            }
@@ -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("<unassigned>");
   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');
     }