2 * $Id: pci.h,v 1.10 2002/12/26 19:28:33 mj Exp $
6 * Copyright (c) 1997--1999 Martin Mares <mj@ucw.cz>
8 * Can be freely distributed and used under the terms of the GNU GPL.
16 #ifdef HAVE_OWN_HEADER_H
19 #include <linux/pci.h>
27 #include <linux/types.h>
37 #include <sys/types.h>
39 typedef u_int8_t byte;
41 typedef u_int16_t word;
42 typedef u_int16_t u16;
43 typedef u_int32_t u32;
47 #include <sys/types.h>
49 typedef u_int8_t byte;
51 typedef u_int16_t word;
52 typedef u_int16_t u16;
53 typedef u_int32_t u32;
57 #include <sys/param.h>
59 typedef u_int8_t byte;
61 typedef u_int16_t word;
62 typedef u_int16_t u16;
63 typedef u_int32_t u32;
66 #ifdef HAVE_LONG_ADDRESS
67 typedef unsigned long long pciaddr_t;
69 typedef unsigned long pciaddr_t;
73 * PCI Access Structure
79 #define PCI_ACCESS_AUTO 0 /* Autodetection (params: none) */
80 #define PCI_ACCESS_PROC_BUS_PCI 1 /* Linux /proc/bus/pci (params: path) */
81 #define PCI_ACCESS_SYSCALLS 2 /* pciconfig_read() syscalls (params: none) */
82 #define PCI_ACCESS_I386_TYPE1 3 /* i386 ports, type 1 (params: none) */
83 #define PCI_ACCESS_I386_TYPE2 4 /* i386 ports, type 2 (params: none) */
84 #define PCI_ACCESS_FBSD_DEVICE 5 /* FreeBSD /dev/pci (params: path) */
85 #define PCI_ACCESS_AIX_DEVICE 6 /* /dev/pci0, /dev/bus0, etc. */
86 #define PCI_ACCESS_NBSD_LIBPCI 7
87 #define PCI_ACCESS_DUMP 8 /* Dump file (params: filename) */
88 #define PCI_ACCESS_MAX 9
91 /* Options you can change: */
92 unsigned int method; /* Access method */
93 char *method_params[PCI_ACCESS_MAX]; /* Parameters for the methods */
94 int writeable; /* Open in read/write mode */
95 int buscentric; /* Bus-centric view of the world */
96 char *id_file_name; /* Name of ID list file */
97 int numeric_ids; /* Don't resolve device IDs to names */
98 int debugging; /* Turn on debugging messages */
100 /* Functions you can override: */
101 void (*error)(char *msg, ...); /* Write error message and quit */
102 void (*warning)(char *msg, ...); /* Write a warning message */
103 void (*debug)(char *msg, ...); /* Write a debugging message */
105 struct pci_dev *devices; /* Devices found on this bus */
107 /* Fields used internally: */
108 struct pci_methods *methods;
109 char *nl_list; /* Name list cache */
110 struct nl_entry **nl_hash;
111 int fd; /* proc: fd */
112 int fd_rw; /* proc: fd opened read-write */
113 struct pci_dev *cached_dev; /* proc: device the fd is for */
114 int fd_pos; /* proc: current position */
117 /* Initialize PCI access */
118 struct pci_access *pci_alloc(void);
119 void pci_init(struct pci_access *);
120 void pci_cleanup(struct pci_access *);
122 /* Scanning of devices */
123 void pci_scan_bus(struct pci_access *acc);
124 struct pci_dev *pci_get_dev(struct pci_access *acc, int bus, int dev, int func); /* Raw access to specified device */
125 void pci_free_dev(struct pci_dev *);
132 struct pci_dev *next; /* Next device in the chain */
133 word bus; /* Higher byte can select host bridges */
134 byte dev, func; /* Device and function */
136 /* These fields are set by pci_fill_info() */
137 int known_fields; /* Set of info fields already known */
138 word vendor_id, device_id; /* Identity of the device */
139 int irq; /* IRQ number */
140 pciaddr_t base_addr[6]; /* Base addresses */
141 pciaddr_t size[6]; /* Region sizes */
142 pciaddr_t rom_base_addr; /* Expansion ROM base address */
143 pciaddr_t rom_size; /* Expansion ROM size */
145 /* Fields used internally: */
146 struct pci_access *access;
147 struct pci_methods *methods;
148 byte *cache; /* Cached information */
150 int hdrtype; /* Direct methods: header type */
151 void *aux; /* Auxillary data */
154 #define PCI_ADDR_IO_MASK (~(pciaddr_t) 0x3)
155 #define PCI_ADDR_MEM_MASK (~(pciaddr_t) 0xf)
157 byte pci_read_byte(struct pci_dev *, int pos); /* Access to configuration space */
158 word pci_read_word(struct pci_dev *, int pos);
159 u32 pci_read_long(struct pci_dev *, int pos);
160 int pci_read_block(struct pci_dev *, int pos, byte *buf, int len);
161 int pci_write_byte(struct pci_dev *, int pos, byte data);
162 int pci_write_word(struct pci_dev *, int pos, word data);
163 int pci_write_long(struct pci_dev *, int pos, u32 data);
164 int pci_write_block(struct pci_dev *, int pos, byte *buf, int len);
166 int pci_fill_info(struct pci_dev *, int flags); /* Fill in device information */
168 #define PCI_FILL_IDENT 1
169 #define PCI_FILL_IRQ 2
170 #define PCI_FILL_BASES 4
171 #define PCI_FILL_ROM_BASE 8
172 #define PCI_FILL_SIZES 16
173 #define PCI_FILL_RESCAN 0x10000
175 void pci_setup_cache(struct pci_dev *, byte *cache, int len);
182 int bus, slot, func; /* -1 = ANY */
186 void pci_filter_init(struct pci_access *, struct pci_filter *);
187 char *pci_filter_parse_slot(struct pci_filter *, char *);
188 char *pci_filter_parse_id(struct pci_filter *, char *);
189 int pci_filter_match(struct pci_filter *, struct pci_dev *);
195 char *pci_lookup_name(struct pci_access *a, char *buf, int size, int flags, u32 arg1, u32 arg2, u32 arg3, u32 arg4);
196 void pci_free_name_list(struct pci_access *a);
198 #define PCI_LOOKUP_VENDOR 1
199 #define PCI_LOOKUP_DEVICE 2
200 #define PCI_LOOKUP_CLASS 4
201 #define PCI_LOOKUP_SUBSYSTEM 8
202 #define PCI_LOOKUP_PROGIF 16
203 #define PCI_LOOKUP_NUMERIC 0x10000