pcivar.h revision 1.83.12.2 1 /* $NetBSD: pcivar.h,v 1.83.12.2 2014/02/15 10:17:20 matt Exp $ */
2
3 /*
4 * Copyright (c) 1996, 1997 Christopher G. Demetriou. All rights reserved.
5 * Copyright (c) 1994 Charles M. Hannum. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by Charles M. Hannum.
18 * 4. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 #ifndef _DEV_PCI_PCIVAR_H_
34 #define _DEV_PCI_PCIVAR_H_
35
36 /*
37 * Definitions for PCI autoconfiguration.
38 *
39 * This file describes types and functions which are used for PCI
40 * configuration. Some of this information is machine-specific, and is
41 * provided by pci_machdep.h.
42 */
43
44 #include <sys/device.h>
45 #include <sys/pmf.h>
46 #include <sys/bus.h>
47 #include <dev/pci/pcireg.h>
48
49 /*
50 * Structures and definitions needed by the machine-dependent header.
51 */
52 typedef u_int32_t pcireg_t; /* configuration space register XXX */
53 struct pcibus_attach_args;
54 struct pci_softc;
55
56 #ifdef _KERNEL
57 /*
58 * Machine-dependent definitions.
59 */
60 #include <machine/pci_machdep.h>
61
62 /*
63 * PCI bus attach arguments.
64 */
65 struct pcibus_attach_args {
66 char *_pba_busname; /* XXX placeholder */
67 bus_space_tag_t pba_iot; /* pci i/o space tag */
68 bus_space_tag_t pba_memt; /* pci mem space tag */
69 bus_dma_tag_t pba_dmat; /* DMA tag */
70 bus_dma_tag_t pba_dmat64; /* DMA tag */
71 pci_chipset_tag_t pba_pc;
72 int pba_flags; /* flags; see below */
73
74 int pba_bus; /* PCI bus number */
75
76 /*
77 * Pointer to the pcitag of our parent bridge. If there is no
78 * parent bridge, then we assume we are a root bus.
79 */
80 pcitag_t *pba_bridgetag;
81
82 /*
83 * Interrupt swizzling information. These fields
84 * are only used by secondary busses.
85 */
86 u_int pba_intrswiz; /* how to swizzle pins */
87 pcitag_t pba_intrtag; /* intr. appears to come from here */
88 };
89
90 /*
91 * PCI device attach arguments.
92 */
93 struct pci_attach_args {
94 bus_space_tag_t pa_iot; /* pci i/o space tag */
95 bus_space_tag_t pa_memt; /* pci mem space tag */
96 bus_dma_tag_t pa_dmat; /* DMA tag */
97 bus_dma_tag_t pa_dmat64; /* DMA tag */
98 pci_chipset_tag_t pa_pc;
99 int pa_flags; /* flags; see below */
100
101 u_int pa_bus;
102 u_int pa_device;
103 u_int pa_function;
104 pcitag_t pa_tag;
105 pcireg_t pa_id, pa_class;
106
107 /*
108 * Interrupt information.
109 *
110 * "Intrline" is used on systems whose firmware puts
111 * the right routing data into the line register in
112 * configuration space. The rest are used on systems
113 * that do not.
114 */
115 u_int pa_intrswiz; /* how to swizzle pins if ppb */
116 pcitag_t pa_intrtag; /* intr. appears to come from here */
117 pci_intr_pin_t pa_intrpin; /* intr. appears on this pin */
118 pci_intr_line_t pa_intrline; /* intr. routing information */
119 pci_intr_pin_t pa_rawintrpin; /* unswizzled pin */
120 };
121
122 /*
123 * Flags given in the bus and device attachment args.
124 */
125 #define PCI_FLAGS_IO_ENABLED 0x01 /* I/O space is enabled */
126 #define PCI_FLAGS_IO_OKAY PCI_FLAGS_IO_ENABLED
127 #define PCI_FLAGS_MEM_ENABLED 0x02 /* memory space is enabled */
128 #define PCI_FLAGS_MEM_OKAY PCI_FLAGS_MEM_ENABLED
129 #define PCI_FLAGS_MRL_OKAY 0x04 /* Memory Read Line okay */
130 #define PCI_FLAGS_MRM_OKAY 0x08 /* Memory Read Multiple okay */
131 #define PCI_FLAGS_MWI_OKAY 0x10 /* Memory Write and Invalidate
132 okay */
133 #define PCI_FLAGS_MSI_OKAY 0x20 /* Message Signaled Interrupts
134 okay */
135 #define PCI_FLAGS_MSIX_OKAY 0x40 /* Message Signaled Interrupts
136 (Extended) okay */
137
138
139 /*
140 * PCI device 'quirks'.
141 *
142 * In general strange behaviour which can be handled by a driver (e.g.
143 * a bridge's inability to pass a type of access correctly) should be.
144 * The quirks table should only contain information which impacts
145 * the operation of the MI PCI code and which can't be pushed lower
146 * (e.g. because it's unacceptable to require a driver to be present
147 * for the information to be known).
148 */
149 struct pci_quirkdata {
150 pci_vendor_id_t vendor; /* Vendor ID */
151 pci_product_id_t product; /* Product ID */
152 int quirks; /* quirks; see below */
153 };
154 #define PCI_QUIRK_MULTIFUNCTION 1
155 #define PCI_QUIRK_MONOFUNCTION 2
156 #define PCI_QUIRK_SKIP_FUNC(n) (4 << n)
157 #define PCI_QUIRK_SKIP_FUNC0 PCI_QUIRK_SKIP_FUNC(0)
158 #define PCI_QUIRK_SKIP_FUNC1 PCI_QUIRK_SKIP_FUNC(1)
159 #define PCI_QUIRK_SKIP_FUNC2 PCI_QUIRK_SKIP_FUNC(2)
160 #define PCI_QUIRK_SKIP_FUNC3 PCI_QUIRK_SKIP_FUNC(3)
161 #define PCI_QUIRK_SKIP_FUNC4 PCI_QUIRK_SKIP_FUNC(4)
162 #define PCI_QUIRK_SKIP_FUNC5 PCI_QUIRK_SKIP_FUNC(5)
163 #define PCI_QUIRK_SKIP_FUNC6 PCI_QUIRK_SKIP_FUNC(6)
164 #define PCI_QUIRK_SKIP_FUNC7 PCI_QUIRK_SKIP_FUNC(7)
165
166 struct pci_conf_state {
167 pcireg_t reg[16];
168 };
169
170 struct pci_child {
171 device_t c_dev;
172 bool c_psok;
173 pcireg_t c_powerstate;
174 struct pci_conf_state c_conf;
175 };
176
177 struct pci_softc {
178 device_t sc_dev;
179 bus_space_tag_t sc_iot, sc_memt;
180 bus_dma_tag_t sc_dmat;
181 bus_dma_tag_t sc_dmat64;
182 pci_chipset_tag_t sc_pc;
183 int sc_bus, sc_maxndevs;
184 pcitag_t *sc_bridgetag;
185 u_int sc_intrswiz;
186 pcitag_t sc_intrtag;
187 int sc_flags;
188 /* accounting of child devices */
189 struct pci_child sc_devices[32*8];
190 #define PCI_SC_DEVICESC(d, f) sc_devices[(d) * 8 + (f)]
191 };
192
193 extern struct cfdriver pci_cd;
194
195 int pcibusprint(void *, const char *);
196
197 /*
198 * Configuration space access and utility functions. (Note that most,
199 * e.g. make_tag, conf_read, conf_write are declared by pci_machdep.h.)
200 */
201 int pci_mapreg_probe(pci_chipset_tag_t, pcitag_t, int, pcireg_t *);
202 pcireg_t pci_mapreg_type(pci_chipset_tag_t, pcitag_t, int);
203 int pci_mapreg_info(pci_chipset_tag_t, pcitag_t, int, pcireg_t,
204 bus_addr_t *, bus_size_t *, int *);
205 int pci_mapreg_map(struct pci_attach_args *, int, pcireg_t, int,
206 bus_space_tag_t *, bus_space_handle_t *, bus_addr_t *,
207 bus_size_t *);
208 int pci_mapreg_submap(struct pci_attach_args *, int, pcireg_t, int,
209 bus_size_t, bus_size_t, bus_space_tag_t *, bus_space_handle_t *,
210 bus_addr_t *, bus_size_t *);
211
212 int pci_find_rom(struct pci_attach_args *, bus_space_tag_t, bus_space_handle_t,
213 int, bus_space_handle_t *, bus_size_t *);
214
215 int pci_get_capability(pci_chipset_tag_t, pcitag_t, int, int *, pcireg_t *);
216
217 /*
218 * Helper functions for autoconfiguration.
219 */
220 int pci_probe_device(struct pci_softc *, pcitag_t tag,
221 int (*)(struct pci_attach_args *), struct pci_attach_args *);
222 void pci_devinfo(pcireg_t, pcireg_t, int, char *, size_t);
223 void pci_aprint_devinfo_fancy(const struct pci_attach_args *,
224 const char *, const char *, int);
225 #define pci_aprint_devinfo(pap, naive) \
226 pci_aprint_devinfo_fancy(pap, naive, NULL, 0);
227 void pci_conf_print(pci_chipset_tag_t, pcitag_t,
228 void (*)(pci_chipset_tag_t, pcitag_t, const pcireg_t *));
229 const struct pci_quirkdata *
230 pci_lookup_quirkdata(pci_vendor_id_t, pci_product_id_t);
231
232 /*
233 * Helper functions for user access to the PCI bus.
234 */
235 struct proc;
236 int pci_devioctl(pci_chipset_tag_t, pcitag_t, u_long, void *,
237 int flag, struct lwp *);
238
239 /*
240 * Power Management (PCI 2.2)
241 */
242
243 #define PCI_PWR_D0 0
244 #define PCI_PWR_D1 1
245 #define PCI_PWR_D2 2
246 #define PCI_PWR_D3 3
247 int pci_powerstate(pci_chipset_tag_t, pcitag_t, const int *, int *);
248
249 /*
250 * Vital Product Data (PCI 2.2)
251 */
252 int pci_vpd_read(pci_chipset_tag_t, pcitag_t, int, int, pcireg_t *);
253 int pci_vpd_write(pci_chipset_tag_t, pcitag_t, int, int, pcireg_t *);
254
255 /*
256 * Misc.
257 */
258 const char *pci_findvendor(pcireg_t);
259 const char *pci_findproduct(pcireg_t);
260 int pci_find_device(struct pci_attach_args *pa,
261 int (*match)(struct pci_attach_args *));
262 int pci_dma64_available(struct pci_attach_args *);
263 void pci_conf_capture(pci_chipset_tag_t, pcitag_t, struct pci_conf_state *);
264 void pci_conf_restore(pci_chipset_tag_t, pcitag_t, struct pci_conf_state *);
265 int pci_get_powerstate(pci_chipset_tag_t, pcitag_t, pcireg_t *);
266 int pci_set_powerstate(pci_chipset_tag_t, pcitag_t, pcireg_t);
267 int pci_activate(pci_chipset_tag_t, pcitag_t, device_t,
268 int (*)(pci_chipset_tag_t, pcitag_t, device_t, pcireg_t));
269 int pci_activate_null(pci_chipset_tag_t, pcitag_t, device_t, pcireg_t);
270 void pci_disable_retry(pci_chipset_tag_t, pcitag_t);
271
272 /*
273 * Device abstraction for inheritance by elanpci(4), for example.
274 */
275 int pcimatch(device_t, cfdata_t, void *);
276 void pciattach(device_t, device_t, void *);
277 int pcidetach(device_t, int);
278 void pcidevdetached(device_t, device_t);
279 int pcirescan(device_t, const char *, const int *);
280
281 /*
282 * Interrupts.
283 */
284 #define PCI_INTR_MPSAFE 1
285
286 int pci_intr_setattr(pci_chipset_tag_t, pci_intr_handle_t *, int, uint64_t);
287
288 #endif /* _KERNEL */
289
290 #endif /* _DEV_PCI_PCIVAR_H_ */
291