pci.h revision 1.38 1 /* $NetBSD: pci.h,v 1.38 2020/01/18 03:00:04 jmcneill Exp $ */
2
3 /*-
4 * Copyright (c) 2013 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Taylor R. Campbell.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 #ifndef _LINUX_PCI_H_
33 #define _LINUX_PCI_H_
34
35 #ifdef _KERNEL_OPT
36 #if defined(i386) || defined(amd64) || defined(__aarch64__)
37 #include "acpica.h"
38 #else /* !(i386 || amd64) */
39 #define NACPICA 0
40 #endif /* i386 || amd64 */
41 #endif
42
43 #include <sys/types.h>
44 #include <sys/param.h>
45 #include <sys/bus.h>
46 #include <sys/cdefs.h>
47 #include <sys/kmem.h>
48 #include <sys/systm.h>
49
50 #include <machine/limits.h>
51
52 #include <dev/pci/pcidevs.h>
53 #include <dev/pci/pcireg.h>
54 #include <dev/pci/pcivar.h>
55 #include <dev/pci/agpvar.h>
56
57 #if NACPICA > 0
58 #include <dev/acpi/acpivar.h>
59 #include <dev/acpi/acpi_pci.h>
60 #else
61 struct acpi_devnode;
62 #endif
63
64 #include <linux/dma-mapping.h>
65 #include <linux/ioport.h>
66 #include <linux/kernel.h>
67
68 struct pci_driver;
69
70 struct pci_bus {
71 /* NetBSD private members */
72 pci_chipset_tag_t pb_pc;
73 device_t pb_dev;
74
75 /* Linux API */
76 u_int number;
77 };
78
79 struct pci_device_id {
80 uint32_t vendor;
81 uint32_t device;
82 uint32_t subvendor;
83 uint32_t subdevice;
84 uint32_t class;
85 uint32_t class_mask;
86 unsigned long driver_data;
87 };
88
89 #define PCI_ANY_ID (~0)
90
91 #define PCI_BASE_CLASS_DISPLAY PCI_CLASS_DISPLAY
92
93 #define PCI_CLASS_DISPLAY_VGA \
94 ((PCI_CLASS_DISPLAY << 8) | PCI_SUBCLASS_DISPLAY_VGA)
95 #define PCI_CLASS_BRIDGE_ISA \
96 ((PCI_CLASS_BRIDGE << 8) | PCI_SUBCLASS_BRIDGE_ISA)
97 CTASSERT(PCI_CLASS_BRIDGE_ISA == 0x0601);
98
99 /* XXX This is getting silly... */
100 #define PCI_VENDOR_ID_APPLE PCI_VENDOR_APPLE
101 #define PCI_VENDOR_ID_ASUSTEK PCI_VENDOR_ASUSTEK
102 #define PCI_VENDOR_ID_ATI PCI_VENDOR_ATI
103 #define PCI_VENDOR_ID_DELL PCI_VENDOR_DELL
104 #define PCI_VENDOR_ID_IBM PCI_VENDOR_IBM
105 #define PCI_VENDOR_ID_HP PCI_VENDOR_HP
106 #define PCI_VENDOR_ID_INTEL PCI_VENDOR_INTEL
107 #define PCI_VENDOR_ID_NVIDIA PCI_VENDOR_NVIDIA
108 #define PCI_VENDOR_ID_SI PCI_VENDOR_SIS
109 #define PCI_VENDOR_ID_SONY PCI_VENDOR_SONY
110 #define PCI_VENDOR_ID_VIA PCI_VENDOR_VIATECH
111
112 #define PCI_DEVICE_ID_ATI_RADEON_QY PCI_PRODUCT_ATI_RADEON_RV100_QY
113
114 #define PCI_DEVFN(DEV, FN) \
115 (__SHIFTIN((DEV), __BITS(3, 7)) | __SHIFTIN((FN), __BITS(0, 2)))
116 #define PCI_SLOT(DEVFN) __SHIFTOUT((DEVFN), __BITS(3, 7))
117 #define PCI_FUNC(DEVFN) __SHIFTOUT((DEVFN), __BITS(0, 2))
118
119 #define PCI_NUM_RESOURCES ((PCI_MAPREG_END - PCI_MAPREG_START) / 4)
120 #define DEVICE_COUNT_RESOURCE PCI_NUM_RESOURCES
121
122 #define PCI_CAP_ID_AGP PCI_CAP_AGP
123
124 typedef int pci_power_t;
125
126 #define PCI_D0 0
127 #define PCI_D1 1
128 #define PCI_D2 2
129 #define PCI_D3hot 3
130 #define PCI_D3cold 4
131
132 #define __pci_iomem
133
134 struct pci_dev {
135 struct pci_attach_args pd_pa;
136 int pd_kludges; /* Gotta lose 'em... */
137 #define NBPCI_KLUDGE_GET_MUMBLE 0x01
138 #define NBPCI_KLUDGE_MAP_ROM 0x02
139 bus_space_tag_t pd_rom_bst;
140 bus_space_handle_t pd_rom_bsh;
141 bus_size_t pd_rom_size;
142 bus_space_handle_t pd_rom_found_bsh;
143 bus_size_t pd_rom_found_size;
144 void *pd_rom_vaddr;
145 device_t pd_dev;
146 struct drm_device *pd_drm_dev; /* XXX Nouveau kludge! */
147 struct {
148 pcireg_t type;
149 bus_addr_t addr;
150 bus_size_t size;
151 int flags;
152 bus_space_tag_t bst;
153 bus_space_handle_t bsh;
154 void __pci_iomem *kva;
155 bool mapped;
156 } pd_resources[PCI_NUM_RESOURCES];
157 struct pci_conf_state *pd_saved_state;
158 struct acpi_devnode *pd_ad;
159 pci_intr_handle_t *pd_intr_handles;
160 unsigned pd_enablecnt;
161
162 /* Linx API only below */
163 struct pci_bus *bus;
164 uint32_t devfn;
165 uint16_t vendor;
166 uint16_t device;
167 uint16_t subsystem_vendor;
168 uint16_t subsystem_device;
169 uint8_t revision;
170 uint32_t class;
171 bool msi_enabled;
172 bool no_64bit_msi;
173 };
174
175 #define PCIBIOS_MIN_MEM 0x100000 /* XXX bogus x86 kludge bollocks */
176
177 #define __pci_rom_iomem
178
179 /* Namespace. */
180 #define pci_bus_alloc_resource linux_pci_bus_alloc_resource
181 #define pci_bus_read_config_byte linux_pci_bus_read_config_byte
182 #define pci_bus_read_config_dword linux_pci_bus_read_config_dword
183 #define pci_bus_read_config_word linux_pci_bus_read_config_word
184 #define pci_bus_write_config_byte linux_pci_bus_write_config_byte
185 #define pci_bus_write_config_dword linux_pci_bus_write_config_dword
186 #define pci_bus_write_config_word linux_pci_bus_write_config_word
187 #define pci_clear_master linux_pci_clear_master
188 #define pci_dev_dev linux_pci_dev_dev
189 #define pci_dev_put linux_pci_dev_put
190 #define pci_disable_msi linux_pci_disable_msi
191 #define pci_disable_rom linux_pci_disable_rom
192 #define pci_dma_supported linux_pci_dma_supported
193 #define pci_domain_nr linux_pci_domain_nr
194 #define pci_enable_msi linux_pci_enable_msi
195 #define pci_enable_rom linux_pci_enable_rom
196 #define pci_find_capability linux_pci_find_capability
197 #define pci_get_bus_and_slot linux_pci_get_bus_and_slot
198 #define pci_get_class linux_pci_get_class
199 #define pci_get_drvdata linux_pci_get_drvdata
200 #define pci_iomap linux_pci_iomap
201 #define pci_iounmap linux_pci_iounmap
202 #define pci_is_pcie linux_pci_is_pcie
203 #define pci_is_root_bus linux_pci_is_root_bus
204 #define pci_map_rom linux_pci_map_rom
205 #define pci_platform_rom linux_pci_platform_rom
206 #define pci_read_config_byte linux_pci_read_config_byte
207 #define pci_read_config_dword linux_pci_read_config_dword
208 #define pci_read_config_word linux_pci_read_config_word
209 #define pci_resource_end linux_pci_resource_end
210 #define pci_resource_flags linux_pci_resource_flags
211 #define pci_resource_len linux_pci_resource_len
212 #define pci_resource_start linux_pci_resource_start
213 #define pci_restore_state linux_pci_restore_state
214 #define pci_save_state linux_pci_save_state
215 #define pci_set_master linux_pci_set_master
216 #define pci_unmap_rom linux_pci_unmap_rom
217 #define pci_write_config_byte linux_pci_write_config_byte
218 #define pci_write_config_dword linux_pci_write_config_dword
219 #define pci_write_config_word linux_pci_write_config_word
220 #define pcibios_align_resource linux_pcibios_align_resource
221
222 /* NetBSD local additions. */
223 void linux_pci_dev_init(struct pci_dev *, device_t, device_t,
224 const struct pci_attach_args *, int);
225 void linux_pci_dev_destroy(struct pci_dev *);
226
227 /* NetBSD no-renames because use requires review. */
228 int linux_pci_enable_device(struct pci_dev *);
229 void linux_pci_disable_device(struct pci_dev *);
230
231 bool pci_is_root_bus(struct pci_bus *);
232 int pci_domain_nr(struct pci_bus *);
233
234 device_t pci_dev_dev(struct pci_dev *);
235 struct drm_device * /* XXX Nouveau kludge! */
236 pci_get_drvdata(struct pci_dev *);
237
238 int pci_find_capability(struct pci_dev *, int);
239 bool pci_is_pcie(struct pci_dev *);
240 bool pci_dma_supported(struct pci_dev *, uintmax_t);
241
242 int pci_read_config_dword(struct pci_dev *, int, uint32_t *);
243 int pci_read_config_word(struct pci_dev *, int, uint16_t *);
244 int pci_read_config_byte(struct pci_dev *, int, uint8_t *);
245 int pci_write_config_dword(struct pci_dev *, int, uint32_t);
246 int pci_write_config_word(struct pci_dev *, int, uint16_t);
247 int pci_write_config_byte(struct pci_dev *, int, uint8_t);
248
249 int pci_bus_read_config_dword(struct pci_bus *, unsigned, int,
250 uint32_t *);
251 int pci_bus_read_config_word(struct pci_bus *, unsigned, int,
252 uint16_t *);
253 int pci_bus_read_config_byte(struct pci_bus *, unsigned, int,
254 uint8_t *);
255 int pci_bus_write_config_dword(struct pci_bus *, unsigned, int,
256 uint32_t);
257 int pci_bus_write_config_word(struct pci_bus *, unsigned, int,
258 uint16_t);
259 int pci_bus_write_config_byte(struct pci_bus *, unsigned, int,
260 uint8_t);
261
262 int pci_enable_msi(struct pci_dev *);
263 void pci_disable_msi(struct pci_dev *);
264 void pci_set_master(struct pci_dev *);
265 void pci_clear_master(struct pci_dev *);
266
267 bus_addr_t pcibios_align_resource(void *, const struct resource *,
268 bus_addr_t, bus_size_t);
269 int pci_bus_alloc_resource(struct pci_bus *, struct resource *,
270 bus_size_t, bus_size_t, bus_addr_t, int,
271 bus_addr_t (*)(void *, const struct resource *, bus_addr_t,
272 bus_size_t), struct pci_dev *);
273
274 /* XXX Kludges only -- do not use without checking the implementation! */
275 struct pci_dev *pci_get_bus_and_slot(int, int);
276 struct pci_dev *pci_get_class(uint32_t, struct pci_dev *); /* i915 kludge */
277 void pci_dev_put(struct pci_dev *);
278
279 void __pci_rom_iomem *
280 pci_map_rom(struct pci_dev *, size_t *);
281 void __pci_rom_iomem *
282 pci_platform_rom(struct pci_dev *, size_t *);
283 void pci_unmap_rom(struct pci_dev *, void __pci_rom_iomem *);
284 int pci_enable_rom(struct pci_dev *);
285 void pci_disable_rom(struct pci_dev *);
286
287 bus_addr_t pci_resource_start(struct pci_dev *, unsigned);
288 bus_size_t pci_resource_len(struct pci_dev *, unsigned);
289 bus_addr_t pci_resource_end(struct pci_dev *, unsigned);
290 int pci_resource_flags(struct pci_dev *, unsigned);
291
292 void __pci_iomem *
293 pci_iomap(struct pci_dev *, unsigned, bus_size_t);
294 void pci_iounmap(struct pci_dev *, void __pci_iomem *);
295
296 void pci_save_state(struct pci_dev *);
297 void pci_restore_state(struct pci_dev *);
298
299 #endif /* _LINUX_PCI_H_ */
300