]> git.ipfire.org Git - thirdparty/pciutils.git/blob - lib/pci.h
Added support for GNU Hurd
[thirdparty/pciutils.git] / lib / pci.h
1 /*
2 * The PCI Library
3 *
4 * Copyright (c) 1997--2002 Martin Mares <mj@ucw.cz>
5 *
6 * Can be freely distributed and used under the terms of the GNU GPL.
7 */
8
9 #ifndef _PCI_LIB_H
10 #define _PCI_LIB_H
11
12 #include "config.h"
13 #include "header.h"
14
15 /*
16 * Types
17 */
18
19 #ifdef OS_LINUX
20 #include <linux/types.h>
21
22 typedef __u8 byte;
23 typedef __u8 u8;
24 typedef __u16 word;
25 typedef __u16 u16;
26 typedef __u32 u32;
27
28 #endif
29
30 #ifdef OS_FREEBSD
31 #include <sys/types.h>
32
33 typedef u_int8_t byte;
34 typedef u_int8_t u8;
35 typedef u_int16_t word;
36 typedef u_int16_t u16;
37 typedef u_int32_t u32;
38 #endif
39
40 #ifdef OS_NETBSD
41 #include <sys/types.h>
42
43 typedef u_int8_t byte;
44 typedef u_int8_t u8;
45 typedef u_int16_t word;
46 typedef u_int16_t u16;
47 typedef u_int32_t u32;
48 #endif
49
50 #ifdef OS_AIX
51 #include <sys/param.h>
52
53 typedef u_int8_t byte;
54 typedef u_int8_t u8;
55 typedef u_int16_t word;
56 typedef u_int16_t u16;
57 typedef u_int32_t u32;
58 #endif
59
60 #ifdef OS_GNU
61 #include <sys/types.h>
62
63 typedef u_int8_t byte;
64 typedef u_int8_t u8;
65 typedef u_int16_t word;
66 typedef u_int16_t u16;
67 typedef u_int32_t u32;
68 #endif
69
70 #ifdef HAVE_LONG_ADDRESS
71 typedef unsigned long long pciaddr_t;
72 #else
73 typedef unsigned long pciaddr_t;
74 #endif
75
76 /*
77 * PCI Access Structure
78 */
79
80 struct pci_methods;
81 struct nl_entry;
82
83 enum pci_access_type {
84 /* Known access methods, remember to update access.c as well */
85 PCI_ACCESS_AUTO, /* Autodetection (params: none) */
86 PCI_ACCESS_PROC_BUS_PCI, /* Linux /proc/bus/pci (params: path) */
87 PCI_ACCESS_I386_TYPE1, /* i386 ports, type 1 (params: none) */
88 PCI_ACCESS_I386_TYPE2, /* i386 ports, type 2 (params: none) */
89 PCI_ACCESS_FBSD_DEVICE, /* FreeBSD /dev/pci (params: path) */
90 PCI_ACCESS_AIX_DEVICE, /* /dev/pci0, /dev/bus0, etc. */
91 PCI_ACCESS_NBSD_LIBPCI, /* NetBSD libpci */
92 PCI_ACCESS_DUMP, /* Dump file (params: filename) */
93 PCI_ACCESS_MAX
94 };
95
96 struct pci_access {
97 /* Options you can change: */
98 unsigned int method; /* Access method */
99 char *method_params[PCI_ACCESS_MAX]; /* Parameters for the methods */
100 int writeable; /* Open in read/write mode */
101 int buscentric; /* Bus-centric view of the world */
102 char *id_file_name; /* Name of ID list file */
103 int numeric_ids; /* Don't resolve device IDs to names */
104 int debugging; /* Turn on debugging messages */
105
106 /* Functions you can override: */
107 void (*error)(char *msg, ...); /* Write error message and quit */
108 void (*warning)(char *msg, ...); /* Write a warning message */
109 void (*debug)(char *msg, ...); /* Write a debugging message */
110
111 struct pci_dev *devices; /* Devices found on this bus */
112
113 /* Fields used internally: */
114 struct pci_methods *methods;
115 char *nl_list; /* Name list cache */
116 struct nl_entry **nl_hash;
117 int fd; /* proc: fd */
118 int fd_rw; /* proc: fd opened read-write */
119 struct pci_dev *cached_dev; /* proc: device the fd is for */
120 int fd_pos; /* proc: current position */
121 };
122
123 /* Initialize PCI access */
124 struct pci_access *pci_alloc(void);
125 void pci_init(struct pci_access *);
126 void pci_cleanup(struct pci_access *);
127
128 /* Scanning of devices */
129 void pci_scan_bus(struct pci_access *acc);
130 struct pci_dev *pci_get_dev(struct pci_access *acc, int bus, int dev, int func); /* Raw access to specified device */
131 void pci_free_dev(struct pci_dev *);
132
133 /*
134 * Devices
135 */
136
137 struct pci_dev {
138 struct pci_dev *next; /* Next device in the chain */
139 word bus; /* Higher byte can select host bridges */
140 byte dev, func; /* Device and function */
141
142 /* These fields are set by pci_fill_info() */
143 int known_fields; /* Set of info fields already known */
144 word vendor_id, device_id; /* Identity of the device */
145 int irq; /* IRQ number */
146 pciaddr_t base_addr[6]; /* Base addresses */
147 pciaddr_t size[6]; /* Region sizes */
148 pciaddr_t rom_base_addr; /* Expansion ROM base address */
149 pciaddr_t rom_size; /* Expansion ROM size */
150
151 /* Fields used internally: */
152 struct pci_access *access;
153 struct pci_methods *methods;
154 byte *cache; /* Cached information */
155 int cache_len;
156 int hdrtype; /* Direct methods: header type */
157 void *aux; /* Auxillary data */
158 };
159
160 #define PCI_ADDR_IO_MASK (~(pciaddr_t) 0x3)
161 #define PCI_ADDR_MEM_MASK (~(pciaddr_t) 0xf)
162
163 byte pci_read_byte(struct pci_dev *, int pos); /* Access to configuration space */
164 word pci_read_word(struct pci_dev *, int pos);
165 u32 pci_read_long(struct pci_dev *, int pos);
166 int pci_read_block(struct pci_dev *, int pos, byte *buf, int len);
167 int pci_write_byte(struct pci_dev *, int pos, byte data);
168 int pci_write_word(struct pci_dev *, int pos, word data);
169 int pci_write_long(struct pci_dev *, int pos, u32 data);
170 int pci_write_block(struct pci_dev *, int pos, byte *buf, int len);
171
172 int pci_fill_info(struct pci_dev *, int flags); /* Fill in device information */
173
174 #define PCI_FILL_IDENT 1
175 #define PCI_FILL_IRQ 2
176 #define PCI_FILL_BASES 4
177 #define PCI_FILL_ROM_BASE 8
178 #define PCI_FILL_SIZES 16
179 #define PCI_FILL_RESCAN 0x10000
180
181 void pci_setup_cache(struct pci_dev *, byte *cache, int len);
182
183 /*
184 * Filters
185 */
186
187 struct pci_filter {
188 int bus, slot, func; /* -1 = ANY */
189 int vendor, device;
190 };
191
192 void pci_filter_init(struct pci_access *, struct pci_filter *);
193 char *pci_filter_parse_slot(struct pci_filter *, char *);
194 char *pci_filter_parse_id(struct pci_filter *, char *);
195 int pci_filter_match(struct pci_filter *, struct pci_dev *);
196
197 /*
198 * Device names
199 */
200
201 char *pci_lookup_name(struct pci_access *a, char *buf, int size, int flags, u32 arg1, u32 arg2, u32 arg3, u32 arg4);
202 void pci_free_name_list(struct pci_access *a);
203
204 #define PCI_LOOKUP_VENDOR 1
205 #define PCI_LOOKUP_DEVICE 2
206 #define PCI_LOOKUP_CLASS 4
207 #define PCI_LOOKUP_SUBSYSTEM 8
208 #define PCI_LOOKUP_PROGIF 16
209 #define PCI_LOOKUP_NUMERIC 0x10000
210
211 #endif