4 * Copyright (c) 1997--2005 Martin Mares <mj@ucw.cz>
6 * Can be freely distributed and used under the terms of the GNU GPL.
16 #define PCI_LIB_VERSION 0x020200
19 * PCI Access Structure
24 enum pci_access_type {
25 /* Known access methods, remember to update access.c as well */
26 PCI_ACCESS_AUTO, /* Autodetection (params: none) */
27 PCI_ACCESS_SYS_BUS_PCI, /* Linux /sys/bus/pci (params: path) */
28 PCI_ACCESS_PROC_BUS_PCI, /* Linux /proc/bus/pci (params: path) */
29 PCI_ACCESS_I386_TYPE1, /* i386 ports, type 1 (params: none) */
30 PCI_ACCESS_I386_TYPE2, /* i386 ports, type 2 (params: none) */
31 PCI_ACCESS_FBSD_DEVICE, /* FreeBSD /dev/pci (params: path) */
32 PCI_ACCESS_AIX_DEVICE, /* /dev/pci0, /dev/bus0, etc. */
33 PCI_ACCESS_NBSD_LIBPCI, /* NetBSD libpci */
34 PCI_ACCESS_OBSD_DEVICE, /* OpenBSD /dev/pci */
35 PCI_ACCESS_DUMP, /* Dump file (params: filename) */
40 /* Options you can change: */
41 unsigned int method; /* Access method */
42 char *method_params[PCI_ACCESS_MAX]; /* Parameters for the methods */
43 int writeable; /* Open in read/write mode */
44 int buscentric; /* Bus-centric view of the world */
45 char *id_file_name; /* Name of ID list file */
46 int numeric_ids; /* Don't resolve device IDs to names */
47 int debugging; /* Turn on debugging messages */
49 /* Functions you can override: */
50 void (*error)(char *msg, ...); /* Write error message and quit */
51 void (*warning)(char *msg, ...); /* Write a warning message */
52 void (*debug)(char *msg, ...); /* Write a debugging message */
54 struct pci_dev *devices; /* Devices found on this bus */
56 /* Fields used internally: */
57 struct pci_methods *methods;
58 struct id_entry **id_hash; /* names.c */
59 struct id_bucket *current_id_bucket;
60 int fd; /* proc: fd */
61 int fd_rw; /* proc: fd opened read-write */
62 struct pci_dev *cached_dev; /* proc: device the fd is for */
63 int fd_pos; /* proc: current position */
66 /* Initialize PCI access */
67 struct pci_access *pci_alloc(void);
68 void pci_init(struct pci_access *);
69 void pci_cleanup(struct pci_access *);
71 /* Scanning of devices */
72 void pci_scan_bus(struct pci_access *acc);
73 struct pci_dev *pci_get_dev(struct pci_access *acc, int domain, int bus, int dev, int func); /* Raw access to specified device */
74 void pci_free_dev(struct pci_dev *);
81 struct pci_dev *next; /* Next device in the chain */
82 u16 domain; /* PCI domain (host bridge) */
83 u8 bus, dev, func; /* Bus inside domain, device and function */
85 /* These fields are set by pci_fill_info() */
86 int known_fields; /* Set of info fields already known */
87 u16 vendor_id, device_id; /* Identity of the device */
88 int irq; /* IRQ number */
89 pciaddr_t base_addr[6]; /* Base addresses */
90 pciaddr_t size[6]; /* Region sizes */
91 pciaddr_t rom_base_addr; /* Expansion ROM base address */
92 pciaddr_t rom_size; /* Expansion ROM size */
94 /* Fields used internally: */
95 struct pci_access *access;
96 struct pci_methods *methods;
97 u8 *cache; /* Cached config registers */
99 int hdrtype; /* Cached low 7 bits of header type, -1 if unknown */
100 void *aux; /* Auxillary data */
103 #define PCI_ADDR_IO_MASK (~(pciaddr_t) 0x3)
104 #define PCI_ADDR_MEM_MASK (~(pciaddr_t) 0xf)
106 u8 pci_read_byte(struct pci_dev *, int pos); /* Access to configuration space */
107 u16 pci_read_word(struct pci_dev *, int pos);
108 u32 pci_read_long(struct pci_dev *, int pos);
109 int pci_read_block(struct pci_dev *, int pos, u8 *buf, int len);
110 int pci_write_byte(struct pci_dev *, int pos, u8 data);
111 int pci_write_word(struct pci_dev *, int pos, u16 data);
112 int pci_write_long(struct pci_dev *, int pos, u32 data);
113 int pci_write_block(struct pci_dev *, int pos, u8 *buf, int len);
115 int pci_fill_info(struct pci_dev *, int flags); /* Fill in device information */
117 #define PCI_FILL_IDENT 1
118 #define PCI_FILL_IRQ 2
119 #define PCI_FILL_BASES 4
120 #define PCI_FILL_ROM_BASE 8
121 #define PCI_FILL_SIZES 16
122 #define PCI_FILL_RESCAN 0x10000
124 void pci_setup_cache(struct pci_dev *, u8 *cache, int len);
131 int domain, bus, slot, func; /* -1 = ANY */
135 void pci_filter_init(struct pci_access *, struct pci_filter *);
136 char *pci_filter_parse_slot(struct pci_filter *, char *);
137 char *pci_filter_parse_id(struct pci_filter *, char *);
138 int pci_filter_match(struct pci_filter *, struct pci_dev *);
141 * Conversion of PCI ID's to names (according to the pci.ids file)
143 * Call pci_lookup_name() to identify different types of ID's:
145 * VENDOR (vendorID) -> vendor
146 * DEVICE (vendorID, deviceID) -> device
147 * VENDOR | DEVICE (vendorID, deviceID) -> combined vendor and device
148 * SUBSYSTEM | VENDOR (subvendorID) -> subsystem vendor
149 * SUBSYSTEM | DEVICE (vendorID, deviceID, subvendorID, subdevID) -> subsystem device
150 * SUBSYSTEM | VENDOR | DEVICE (vendorID, deviceID, subvendorID, subdevID) -> combined subsystem v+d
151 * SUBSYSTEM | ... (-1, -1, subvendorID, subdevID) -> generic subsystem
152 * CLASS (classID) -> class
153 * PROGIF (classID, progif) -> programming interface
156 char *pci_lookup_name(struct pci_access *a, char *buf, int size, int flags, ...);
158 int pci_load_name_list(struct pci_access *a); /* Called automatically by pci_lookup_*() when needed; returns success */
159 void pci_free_name_list(struct pci_access *a); /* Called automatically by pci_cleanup() */
161 enum pci_lookup_mode {
162 PCI_LOOKUP_VENDOR = 1, /* Vendor name (args: vendorID) */
163 PCI_LOOKUP_DEVICE = 2, /* Device name (args: vendorID, deviceID) */
164 PCI_LOOKUP_CLASS = 4, /* Device class (args: classID) */
165 PCI_LOOKUP_SUBSYSTEM = 8,
166 PCI_LOOKUP_PROGIF = 16, /* Programming interface (args: classID, prog_if) */
167 PCI_LOOKUP_NUMERIC = 0x10000, /* Want only formatted numbers; default if access->numeric_ids is set */
168 PCI_LOOKUP_NO_NUMBERS = 0x20000 /* Return NULL if not found in the database; default is to print numerically */