xref: /freebsd/sys/dev/pci/pci_if.m (revision 031beb4e239bfce798af17f5fe8dba8bcaf13d99)
1098ca2bdSWarner Losh#-
26182fdbdSPeter Wemm# Copyright (c) 1998 Doug Rabson
36182fdbdSPeter Wemm# All rights reserved.
46182fdbdSPeter Wemm#
56182fdbdSPeter Wemm# Redistribution and use in source and binary forms, with or without
66182fdbdSPeter Wemm# modification, are permitted provided that the following conditions
76182fdbdSPeter Wemm# are met:
86182fdbdSPeter Wemm# 1. Redistributions of source code must retain the above copyright
96182fdbdSPeter Wemm#    notice, this list of conditions and the following disclaimer.
106182fdbdSPeter Wemm# 2. Redistributions in binary form must reproduce the above copyright
116182fdbdSPeter Wemm#    notice, this list of conditions and the following disclaimer in the
126182fdbdSPeter Wemm#    documentation and/or other materials provided with the distribution.
136182fdbdSPeter Wemm#
146182fdbdSPeter Wemm# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
156182fdbdSPeter Wemm# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
166182fdbdSPeter Wemm# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
176182fdbdSPeter Wemm# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
186182fdbdSPeter Wemm# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
196182fdbdSPeter Wemm# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
206182fdbdSPeter Wemm# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
216182fdbdSPeter Wemm# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
226182fdbdSPeter Wemm# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
236182fdbdSPeter Wemm# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
246182fdbdSPeter Wemm# SUCH DAMAGE.
256182fdbdSPeter Wemm#
266182fdbdSPeter Wemm#
276182fdbdSPeter Wemm
28f7b77691SDoug Rabson#include <sys/bus.h>
29d7be980dSAndrew Turner#include <dev/pci/pcivar.h>
30f7b77691SDoug Rabson
316182fdbdSPeter WemmINTERFACE pci;
326182fdbdSPeter Wemm
339bf4c9c1SJohn BaldwinCODE {
349bf4c9c1SJohn Baldwin	static int
359bf4c9c1SJohn Baldwin	null_msi_count(device_t dev, device_t child)
369bf4c9c1SJohn Baldwin	{
379bf4c9c1SJohn Baldwin		return (0);
389bf4c9c1SJohn Baldwin	}
399bfb1e36SRyan Stone
40ce204e1bSJohn Baldwin	static int
41ce204e1bSJohn Baldwin	null_msix_bar(device_t dev, device_t child)
42ce204e1bSJohn Baldwin	{
43ce204e1bSJohn Baldwin		return (-1);
44ce204e1bSJohn Baldwin	}
45ce204e1bSJohn Baldwin
469bfb1e36SRyan Stone	static device_t
479bfb1e36SRyan Stone	null_create_iov_child(device_t bus, device_t pf, uint16_t rid,
489bfb1e36SRyan Stone	    uint16_t vid, uint16_t did)
499bfb1e36SRyan Stone	{
509bfb1e36SRyan Stone		device_printf(bus, "PCI_IOV not implemented on this bus.\n");
519bfb1e36SRyan Stone		return (NULL);
529bfb1e36SRyan Stone	}
539bf4c9c1SJohn Baldwin};
549bf4c9c1SJohn Baldwin
551191f715SRyan StoneHEADER {
561191f715SRyan Stone	struct nvlist;
57d7be980dSAndrew Turner
58d7be980dSAndrew Turner	enum pci_id_type {
59d7be980dSAndrew Turner	    PCI_ID_RID,
601e43b18cSAndrew Turner	    PCI_ID_MSI,
61*b7672a70SRuslan Bukin	    PCI_ID_OFW_IOMMU,
62d7be980dSAndrew Turner	};
634cb67729SWarner Losh
644cb67729SWarner Losh	enum pci_feature {
654cb67729SWarner Losh	    PCI_FEATURE_HP,		/* Hot Plug feature */
664cb67729SWarner Losh	    PCI_FEATURE_AER,		/* Advanced Error Reporting */
674cb67729SWarner Losh	};
681191f715SRyan Stone}
691191f715SRyan Stone
709bf4c9c1SJohn Baldwin
716182fdbdSPeter WemmMETHOD u_int32_t read_config {
726182fdbdSPeter Wemm	device_t	dev;
736182fdbdSPeter Wemm	device_t	child;
746182fdbdSPeter Wemm	int		reg;
756182fdbdSPeter Wemm	int		width;
766182fdbdSPeter Wemm};
776182fdbdSPeter Wemm
786182fdbdSPeter WemmMETHOD void write_config {
796182fdbdSPeter Wemm	device_t	dev;
806182fdbdSPeter Wemm	device_t	child;
816182fdbdSPeter Wemm	int		reg;
826182fdbdSPeter Wemm	u_int32_t	val;
836182fdbdSPeter Wemm	int		width;
846182fdbdSPeter Wemm};
859eb13b39SPeter Wemm
869eb13b39SPeter WemmMETHOD int get_powerstate {
879eb13b39SPeter Wemm	device_t	dev;
889eb13b39SPeter Wemm	device_t	child;
899eb13b39SPeter Wemm};
909eb13b39SPeter Wemm
919eb13b39SPeter WemmMETHOD int set_powerstate {
929eb13b39SPeter Wemm	device_t	dev;
939eb13b39SPeter Wemm	device_t	child;
949eb13b39SPeter Wemm	int		state;
959eb13b39SPeter Wemm};
969eb13b39SPeter Wemm
97667dc26eSJohn-Mark GurneyMETHOD int get_vpd_ident {
98667dc26eSJohn-Mark Gurney	device_t	dev;
99667dc26eSJohn-Mark Gurney	device_t	child;
100667dc26eSJohn-Mark Gurney	const char	**identptr;
101667dc26eSJohn-Mark Gurney};
102667dc26eSJohn-Mark Gurney
103667dc26eSJohn-Mark GurneyMETHOD int get_vpd_readonly {
104667dc26eSJohn-Mark Gurney	device_t	dev;
105667dc26eSJohn-Mark Gurney	device_t	child;
106667dc26eSJohn-Mark Gurney	const char	*kw;
107667dc26eSJohn-Mark Gurney	const char	**vptr;
108667dc26eSJohn-Mark Gurney};
109667dc26eSJohn-Mark Gurney
110c047e5b1SMatthew N. DoddMETHOD int enable_busmaster {
1119eb13b39SPeter Wemm	device_t	dev;
1129eb13b39SPeter Wemm	device_t	child;
1139eb13b39SPeter Wemm};
1149eb13b39SPeter Wemm
115c047e5b1SMatthew N. DoddMETHOD int disable_busmaster {
1169eb13b39SPeter Wemm	device_t	dev;
1179eb13b39SPeter Wemm	device_t	child;
1189eb13b39SPeter Wemm};
1199eb13b39SPeter Wemm
120c047e5b1SMatthew N. DoddMETHOD int enable_io {
1219eb13b39SPeter Wemm	device_t	dev;
1229eb13b39SPeter Wemm	device_t	child;
1239eb13b39SPeter Wemm	int		space;
1249eb13b39SPeter Wemm};
1259eb13b39SPeter Wemm
126c047e5b1SMatthew N. DoddMETHOD int disable_io {
1279eb13b39SPeter Wemm	device_t	dev;
1289eb13b39SPeter Wemm	device_t	child;
1299eb13b39SPeter Wemm	int		space;
1309eb13b39SPeter Wemm};
1313920999dSThomas Moestl
1323920999dSThomas MoestlMETHOD int assign_interrupt {
1333920999dSThomas Moestl	device_t	dev;
1343920999dSThomas Moestl	device_t	child;
1353920999dSThomas Moestl};
1364f9795b9SJohn Baldwin
137c668000bSJohn BaldwinMETHOD int find_cap {
138c668000bSJohn Baldwin	device_t	dev;
139c668000bSJohn Baldwin	device_t	child;
140c668000bSJohn Baldwin	int		capability;
141c668000bSJohn Baldwin	int		*capreg;
142c668000bSJohn Baldwin};
143c668000bSJohn Baldwin
1447a16dacdSBryan VenteicherMETHOD int find_next_cap {
1457a16dacdSBryan Venteicher	device_t	dev;
1467a16dacdSBryan Venteicher	device_t	child;
1477a16dacdSBryan Venteicher	int		capability;
1487a16dacdSBryan Venteicher	int		start;
1497a16dacdSBryan Venteicher	int		*capreg;
1507a16dacdSBryan Venteicher};
1517a16dacdSBryan Venteicher
1524f9795b9SJohn BaldwinMETHOD int find_extcap {
1534f9795b9SJohn Baldwin	device_t	dev;
1544f9795b9SJohn Baldwin	device_t	child;
1554f9795b9SJohn Baldwin	int		capability;
1564f9795b9SJohn Baldwin	int		*capreg;
1574f9795b9SJohn Baldwin};
1589bf4c9c1SJohn Baldwin
1597a16dacdSBryan VenteicherMETHOD int find_next_extcap {
1607a16dacdSBryan Venteicher	device_t	dev;
1617a16dacdSBryan Venteicher	device_t	child;
1627a16dacdSBryan Venteicher	int		capability;
1637a16dacdSBryan Venteicher	int		start;
1647a16dacdSBryan Venteicher	int		*capreg;
1657a16dacdSBryan Venteicher};
1667a16dacdSBryan Venteicher
167c668000bSJohn BaldwinMETHOD int find_htcap {
168c668000bSJohn Baldwin	device_t	dev;
169c668000bSJohn Baldwin	device_t	child;
170c668000bSJohn Baldwin	int		capability;
171c668000bSJohn Baldwin	int		*capreg;
172c668000bSJohn Baldwin};
173c668000bSJohn Baldwin
1747a16dacdSBryan VenteicherMETHOD int find_next_htcap {
1757a16dacdSBryan Venteicher	device_t	dev;
1767a16dacdSBryan Venteicher	device_t	child;
1777a16dacdSBryan Venteicher	int		capability;
1787a16dacdSBryan Venteicher	int		start;
1797a16dacdSBryan Venteicher	int		*capreg;
1807a16dacdSBryan Venteicher};
1817a16dacdSBryan Venteicher
1829bf4c9c1SJohn BaldwinMETHOD int alloc_msi {
1839bf4c9c1SJohn Baldwin	device_t	dev;
1849bf4c9c1SJohn Baldwin	device_t	child;
1859bf4c9c1SJohn Baldwin	int		*count;
1869bf4c9c1SJohn Baldwin};
1879bf4c9c1SJohn Baldwin
1885fe82bcaSJohn BaldwinMETHOD int alloc_msix {
1895fe82bcaSJohn Baldwin	device_t	dev;
1905fe82bcaSJohn Baldwin	device_t	child;
1915fe82bcaSJohn Baldwin	int		*count;
1925fe82bcaSJohn Baldwin};
1935fe82bcaSJohn Baldwin
194073bf9ddSRoger Pau MonnéMETHOD void enable_msi {
195073bf9ddSRoger Pau Monné	device_t	dev;
196073bf9ddSRoger Pau Monné	device_t	child;
197073bf9ddSRoger Pau Monné	uint64_t	address;
198073bf9ddSRoger Pau Monné	uint16_t	data;
199073bf9ddSRoger Pau Monné};
200073bf9ddSRoger Pau Monné
201073bf9ddSRoger Pau MonnéMETHOD void enable_msix {
202073bf9ddSRoger Pau Monné	device_t	dev;
203073bf9ddSRoger Pau Monné	device_t	child;
204073bf9ddSRoger Pau Monné	u_int		index;
205073bf9ddSRoger Pau Monné	uint64_t	address;
206073bf9ddSRoger Pau Monné	uint32_t	data;
207073bf9ddSRoger Pau Monné};
208073bf9ddSRoger Pau Monné
209073bf9ddSRoger Pau MonnéMETHOD void disable_msi {
210073bf9ddSRoger Pau Monné	device_t	dev;
211073bf9ddSRoger Pau Monné	device_t	child;
212073bf9ddSRoger Pau Monné};
213073bf9ddSRoger Pau Monné
2145fe82bcaSJohn BaldwinMETHOD int remap_msix {
2155fe82bcaSJohn Baldwin	device_t	dev;
2165fe82bcaSJohn Baldwin	device_t	child;
217e706f7f0SJohn Baldwin	int		count;
218e706f7f0SJohn Baldwin	const u_int	*vectors;
2195fe82bcaSJohn Baldwin};
2205fe82bcaSJohn Baldwin
2219bf4c9c1SJohn BaldwinMETHOD int release_msi {
2229bf4c9c1SJohn Baldwin	device_t	dev;
2239bf4c9c1SJohn Baldwin	device_t	child;
2249bf4c9c1SJohn Baldwin};
2259bf4c9c1SJohn Baldwin
2269bf4c9c1SJohn BaldwinMETHOD int msi_count {
2279bf4c9c1SJohn Baldwin	device_t	dev;
2289bf4c9c1SJohn Baldwin	device_t	child;
2299bf4c9c1SJohn Baldwin} DEFAULT null_msi_count;
2305fe82bcaSJohn Baldwin
2315fe82bcaSJohn BaldwinMETHOD int msix_count {
2325fe82bcaSJohn Baldwin	device_t	dev;
2335fe82bcaSJohn Baldwin	device_t	child;
2345fe82bcaSJohn Baldwin} DEFAULT null_msi_count;
2355605a99eSRyan Stone
236ce204e1bSJohn BaldwinMETHOD int msix_pba_bar {
237ce204e1bSJohn Baldwin	device_t	dev;
238ce204e1bSJohn Baldwin	device_t	child;
239ce204e1bSJohn Baldwin} DEFAULT null_msix_bar;
240ce204e1bSJohn Baldwin
241ce204e1bSJohn BaldwinMETHOD int msix_table_bar {
242ce204e1bSJohn Baldwin	device_t	dev;
243ce204e1bSJohn Baldwin	device_t	child;
244ce204e1bSJohn Baldwin} DEFAULT null_msix_bar;
245ce204e1bSJohn Baldwin
246d7be980dSAndrew TurnerMETHOD int get_id {
2475605a99eSRyan Stone	device_t	dev;
2485605a99eSRyan Stone	device_t	child;
249d7be980dSAndrew Turner	enum pci_id_type type;
250d7be980dSAndrew Turner	uintptr_t	*id;
2515605a99eSRyan Stone};
2525605a99eSRyan Stone
2536cd99ae8SJohn BaldwinMETHOD struct pci_devinfo * alloc_devinfo {
2546cd99ae8SJohn Baldwin	device_t	dev;
2556cd99ae8SJohn Baldwin};
2566cd99ae8SJohn Baldwin
257cd407ca2SRoger Pau MonnéMETHOD void child_added {
258cd407ca2SRoger Pau Monné	device_t	dev;
259cd407ca2SRoger Pau Monné	device_t	child;
260cd407ca2SRoger Pau Monné};
2619bfb1e36SRyan Stone
2629bfb1e36SRyan StoneMETHOD int iov_attach {
2639bfb1e36SRyan Stone	device_t	dev;
2649bfb1e36SRyan Stone	device_t	child;
2651191f715SRyan Stone	struct nvlist	*pf_schema;
2661191f715SRyan Stone	struct nvlist	*vf_schema;
2670aee83ccSJohn Baldwin	const char	*name;
2689bfb1e36SRyan Stone};
2699bfb1e36SRyan Stone
2709bfb1e36SRyan StoneMETHOD int iov_detach {
2719bfb1e36SRyan Stone	device_t	dev;
2729bfb1e36SRyan Stone	device_t	child;
2739bfb1e36SRyan Stone};
2749bfb1e36SRyan Stone
2759bfb1e36SRyan StoneMETHOD device_t create_iov_child {
2769bfb1e36SRyan Stone	device_t bus;
2779bfb1e36SRyan Stone	device_t pf;
2789bfb1e36SRyan Stone	uint16_t rid;
2799bfb1e36SRyan Stone	uint16_t vid;
2809bfb1e36SRyan Stone	uint16_t did;
2819bfb1e36SRyan Stone} DEFAULT null_create_iov_child;
282