/*
- * $Id: pci.h,v 1.11 2002/12/26 20:24:32 mj Exp $
- *
* 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;
+#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
-
-#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;
+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_methods;
struct nl_entry;
-#define PCI_ACCESS_AUTO 0 /* Autodetection (params: none) */
-#define PCI_ACCESS_PROC_BUS_PCI 1 /* Linux /proc/bus/pci (params: path) */
-#define PCI_ACCESS_SYSCALLS 2 /* pciconfig_read() syscalls (params: none) */
-#define PCI_ACCESS_I386_TYPE1 3 /* i386 ports, type 1 (params: none) */
-#define PCI_ACCESS_I386_TYPE2 4 /* i386 ports, type 2 (params: none) */
-#define PCI_ACCESS_FBSD_DEVICE 5 /* FreeBSD /dev/pci (params: path) */
-#define PCI_ACCESS_AIX_DEVICE 6 /* /dev/pci0, /dev/bus0, etc. */
-#define PCI_ACCESS_NBSD_LIBPCI 7
-#define PCI_ACCESS_DUMP 8 /* Dump file (params: filename) */
-#define PCI_ACCESS_MAX 9
+enum pci_access_type {
+ /* Known access methods, remember to update access.c as well */
+ PCI_ACCESS_AUTO, /* Autodetection (params: none) */
+ PCI_ACCESS_SYS_BUS_PCI, /* Linux /sys/bus/pci (params: path) */
+ PCI_ACCESS_PROC_BUS_PCI, /* Linux /proc/bus/pci (params: path) */
+ PCI_ACCESS_I386_TYPE1, /* i386 ports, type 1 (params: none) */
+ PCI_ACCESS_I386_TYPE2, /* i386 ports, type 2 (params: none) */
+ PCI_ACCESS_FBSD_DEVICE, /* FreeBSD /dev/pci (params: path) */
+ PCI_ACCESS_AIX_DEVICE, /* /dev/pci0, /dev/bus0, etc. */
+ PCI_ACCESS_NBSD_LIBPCI, /* NetBSD libpci */
+ PCI_ACCESS_DUMP, /* Dump file (params: filename) */
+ PCI_ACCESS_MAX
+};
struct pci_access {
/* Options you can change: */
/* Scanning of devices */
void pci_scan_bus(struct pci_access *acc);
-struct pci_dev *pci_get_dev(struct pci_access *acc, int bus, int dev, int func); /* Raw access to specified device */
+struct pci_dev *pci_get_dev(struct pci_access *acc, int domain, int bus, int dev, int func); /* Raw access to specified device */
void pci_free_dev(struct pci_dev *);
/*
struct pci_dev {
struct pci_dev *next; /* Next device in the chain */
- word bus; /* Higher byte can select host bridges */
- byte dev, func; /* Device and function */
+ u16 domain; /* PCI domain (host bridge) */
+ byte bus, dev, func; /* Bus inside domain, device and function */
/* These fields are set by pci_fill_info() */
int known_fields; /* Set of info fields already known */
/* Fields used internally: */
struct pci_access *access;
struct pci_methods *methods;
- byte *cache; /* Cached information */
+ byte *cache; /* Cached config registers */
int cache_len;
- int hdrtype; /* Direct methods: header type */
+ int hdrtype; /* Cached header type, -1 if unknown */
void *aux; /* Auxillary data */
};
*/
struct pci_filter {
- int bus, slot, func; /* -1 = ANY */
+ int domain, bus, slot, func; /* -1 = ANY */
int vendor, device;
};