xref: /freebsd/sys/dev/pci/pci_if.m (revision d0b2dbfa0ecf2bbc9709efc5e20baf8e4b44bbbf)
1#-
2# Copyright (c) 1998 Doug Rabson
3# All rights reserved.
4#
5# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions
7# are met:
8# 1. Redistributions of source code must retain the above copyright
9#    notice, this list of conditions and the following disclaimer.
10# 2. Redistributions in binary form must reproduce the above copyright
11#    notice, this list of conditions and the following disclaimer in the
12#    documentation and/or other materials provided with the distribution.
13#
14# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24# SUCH DAMAGE.
25#
26#
27
28#include <sys/bus.h>
29#include <dev/pci/pcivar.h>
30
31INTERFACE pci;
32
33CODE {
34	static int
35	null_msi_count(device_t dev, device_t child)
36	{
37		return (0);
38	}
39
40	static int
41	null_msix_bar(device_t dev, device_t child)
42	{
43		return (-1);
44	}
45
46	static device_t
47	null_create_iov_child(device_t bus, device_t pf, uint16_t rid,
48	    uint16_t vid, uint16_t did)
49	{
50		device_printf(bus, "PCI_IOV not implemented on this bus.\n");
51		return (NULL);
52	}
53};
54
55HEADER {
56	struct nvlist;
57
58	enum pci_id_type {
59	    PCI_ID_RID,
60	    PCI_ID_MSI,
61	    PCI_ID_OFW_IOMMU,
62	};
63
64	enum pci_feature {
65	    PCI_FEATURE_HP,		/* Hot Plug feature */
66	    PCI_FEATURE_AER,		/* Advanced Error Reporting */
67	};
68}
69
70
71METHOD u_int32_t read_config {
72	device_t	dev;
73	device_t	child;
74	int		reg;
75	int		width;
76};
77
78METHOD void write_config {
79	device_t	dev;
80	device_t	child;
81	int		reg;
82	u_int32_t	val;
83	int		width;
84};
85
86METHOD int get_powerstate {
87	device_t	dev;
88	device_t	child;
89};
90
91METHOD int set_powerstate {
92	device_t	dev;
93	device_t	child;
94	int		state;
95};
96
97METHOD int get_vpd_ident {
98	device_t	dev;
99	device_t	child;
100	const char	**identptr;
101};
102
103METHOD int get_vpd_readonly {
104	device_t	dev;
105	device_t	child;
106	const char	*kw;
107	const char	**vptr;
108};
109
110METHOD int enable_busmaster {
111	device_t	dev;
112	device_t	child;
113};
114
115METHOD int disable_busmaster {
116	device_t	dev;
117	device_t	child;
118};
119
120METHOD int enable_io {
121	device_t	dev;
122	device_t	child;
123	int		space;
124};
125
126METHOD int disable_io {
127	device_t	dev;
128	device_t	child;
129	int		space;
130};
131
132METHOD int assign_interrupt {
133	device_t	dev;
134	device_t	child;
135};
136
137METHOD int find_cap {
138	device_t	dev;
139	device_t	child;
140	int		capability;
141	int		*capreg;
142};
143
144METHOD int find_next_cap {
145	device_t	dev;
146	device_t	child;
147	int		capability;
148	int		start;
149	int		*capreg;
150};
151
152METHOD int find_extcap {
153	device_t	dev;
154	device_t	child;
155	int		capability;
156	int		*capreg;
157};
158
159METHOD int find_next_extcap {
160	device_t	dev;
161	device_t	child;
162	int		capability;
163	int		start;
164	int		*capreg;
165};
166
167METHOD int find_htcap {
168	device_t	dev;
169	device_t	child;
170	int		capability;
171	int		*capreg;
172};
173
174METHOD int find_next_htcap {
175	device_t	dev;
176	device_t	child;
177	int		capability;
178	int		start;
179	int		*capreg;
180};
181
182METHOD int alloc_msi {
183	device_t	dev;
184	device_t	child;
185	int		*count;
186};
187
188METHOD int alloc_msix {
189	device_t	dev;
190	device_t	child;
191	int		*count;
192};
193
194METHOD void enable_msi {
195	device_t	dev;
196	device_t	child;
197	uint64_t	address;
198	uint16_t	data;
199};
200
201METHOD void enable_msix {
202	device_t	dev;
203	device_t	child;
204	u_int		index;
205	uint64_t	address;
206	uint32_t	data;
207};
208
209METHOD void disable_msi {
210	device_t	dev;
211	device_t	child;
212};
213
214METHOD int remap_msix {
215	device_t	dev;
216	device_t	child;
217	int		count;
218	const u_int	*vectors;
219};
220
221METHOD int release_msi {
222	device_t	dev;
223	device_t	child;
224};
225
226METHOD int msi_count {
227	device_t	dev;
228	device_t	child;
229} DEFAULT null_msi_count;
230
231METHOD int msix_count {
232	device_t	dev;
233	device_t	child;
234} DEFAULT null_msi_count;
235
236METHOD int msix_pba_bar {
237	device_t	dev;
238	device_t	child;
239} DEFAULT null_msix_bar;
240
241METHOD int msix_table_bar {
242	device_t	dev;
243	device_t	child;
244} DEFAULT null_msix_bar;
245
246METHOD int get_id {
247	device_t	dev;
248	device_t	child;
249	enum pci_id_type type;
250	uintptr_t	*id;
251};
252
253METHOD struct pci_devinfo * alloc_devinfo {
254	device_t	dev;
255};
256
257METHOD void child_added {
258	device_t	dev;
259	device_t	child;
260};
261
262METHOD int iov_attach {
263	device_t	dev;
264	device_t	child;
265	struct nvlist	*pf_schema;
266	struct nvlist	*vf_schema;
267	const char	*name;
268};
269
270METHOD int iov_detach {
271	device_t	dev;
272	device_t	child;
273};
274
275METHOD device_t create_iov_child {
276	device_t bus;
277	device_t pf;
278	uint16_t rid;
279	uint16_t vid;
280	uint16_t did;
281} DEFAULT null_create_iov_child;
282