xref: /freebsd/sys/dev/pci/pcib_if.m (revision d773f48b1e9cc955d95f4d18b0ab5e13dc1f5ed3)
1#-
2# Copyright (c) 2000 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# $FreeBSD$
27#
28
29#include <sys/bus.h>
30#include <dev/pci/pcivar.h>
31
32INTERFACE pcib;
33
34CODE {
35	static int
36	null_route_interrupt(device_t pcib, device_t dev, int pin)
37	{
38		return (PCI_INVALID_IRQ);
39	}
40};
41
42#
43# Return the number of slots on the attached PCI bus.
44#
45METHOD int maxslots {
46	device_t	dev;
47};
48
49#
50#
51# Return the number of functions on the attached PCI bus.
52#
53METHOD int maxfuncs {
54	device_t	dev;
55} default pcib_maxfuncs;
56
57#
58# Read configuration space on the PCI bus. The bus, slot and func
59# arguments determine the device which is being read and the reg
60# argument is a byte offset into configuration space for that
61# device. The width argument (which should be 1, 2 or 4) specifies how
62# many byte of configuration space to read from that offset.
63#
64METHOD u_int32_t read_config {
65	device_t	dev;
66	u_int		bus;
67	u_int		slot;
68	u_int		func;
69	u_int		reg;
70	int		width;
71};
72
73#
74# Write configuration space on the PCI bus. The bus, slot and func
75# arguments determine the device which is being written and the reg
76# argument is a byte offset into configuration space for that
77# device. The value field is written to the configuration space, with
78# the number of bytes written depending on the width argument.
79#
80METHOD void write_config {
81	device_t	dev;
82	u_int		bus;
83	u_int		slot;
84	u_int		func;
85	u_int		reg;
86	u_int32_t	value;
87	int		width;
88};
89
90#
91# Route an interrupt.  Returns a value suitable for stuffing into
92# a device's interrupt register.
93#
94METHOD int route_interrupt {
95	device_t	pcib;
96	device_t	dev;
97	int		pin;
98} DEFAULT null_route_interrupt;
99
100#
101# Allocate 'count' MSI messsages mapped onto 'count' IRQs.  'irq' points
102# to an array of at least 'count' ints.  The max number of messages this
103# device supports is included so that the MD code can take that into
104# account when assigning resources so that the proper number of low bits
105# are clear in the resulting message data value.
106#
107METHOD int alloc_msi {
108	device_t	pcib;
109	device_t	dev;
110	int		count;
111	int		maxcount;
112	int		*irqs;
113};
114
115#
116# Release 'count' MSI messages mapped onto 'count' IRQs stored in the
117# array pointed to by 'irqs'.
118#
119METHOD int release_msi {
120	device_t	pcib;
121	device_t	dev;
122	int		count;
123	int		*irqs;
124};
125
126#
127# Allocate a single MSI-X message mapped onto '*irq'.
128#
129METHOD int alloc_msix {
130	device_t	pcib;
131	device_t	dev;
132	int		*irq;
133};
134
135#
136# Release a single MSI-X message mapped onto 'irq'.
137#
138METHOD int release_msix {
139	device_t	pcib;
140	device_t	dev;
141	int		irq;
142};
143
144#
145# Determine the MSI/MSI-X message address and data for 'irq'.  The address
146# is returned in '*addr', and the data in '*data'.
147#
148METHOD int map_msi {
149	device_t	pcib;
150	device_t	dev;
151	int		irq;
152	uint64_t	*addr;
153	uint32_t	*data;
154};
155
156#
157# Return the device power state to be used during a system sleep state
158# transition such as suspend and resume.
159#
160METHOD int power_for_sleep {
161	device_t	pcib;
162	device_t	dev;
163	int		*pstate;
164};
165
166#
167# Return the PCI Routing Identifier (RID) for the device.
168#
169METHOD uint16_t get_rid {
170	device_t pcib;
171	device_t dev;
172};
173
174
175#
176# Enable Alternative RID Interpretation if both the downstream port (pcib)
177# and the endpoint device (dev) both support it.
178#
179METHOD int try_enable_ari {
180	device_t	pcib;
181	device_t	dev;
182};
183