xref: /illumos-gate/usr/src/contrib/bhyve/sys/pciio.h (revision 32640292339b07090f10ce34d455f98711077343)
1 /*
2  * Copyright (c) 1997, Stefan Esser <se@FreeBSD.ORG>
3  * Copyright (c) 1997, 1998, 1999, Kenneth D. Merry <ken@FreeBSD.ORG>
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice unmodified, this list of conditions, and the following
11  *    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  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #ifndef _SYS_PCIIO_H_
29 #define	_SYS_PCIIO_H_
30 
31 #include <sys/ioccom.h>
32 
33 #define PCI_MAXNAMELEN	16
34 
35 typedef enum {
36 	PCI_GETCONF_LAST_DEVICE,
37 	PCI_GETCONF_LIST_CHANGED,
38 	PCI_GETCONF_MORE_DEVS,
39 	PCI_GETCONF_ERROR
40 } pci_getconf_status;
41 
42 typedef enum {
43 	PCI_GETCONF_NO_MATCH		= 0x0000,
44 	PCI_GETCONF_MATCH_DOMAIN	= 0x0001,
45 	PCI_GETCONF_MATCH_BUS		= 0x0002,
46 	PCI_GETCONF_MATCH_DEV		= 0x0004,
47 	PCI_GETCONF_MATCH_FUNC		= 0x0008,
48 	PCI_GETCONF_MATCH_NAME		= 0x0010,
49 	PCI_GETCONF_MATCH_UNIT		= 0x0020,
50 	PCI_GETCONF_MATCH_VENDOR	= 0x0040,
51 	PCI_GETCONF_MATCH_DEVICE	= 0x0080,
52 	PCI_GETCONF_MATCH_CLASS		= 0x0100
53 } pci_getconf_flags;
54 
55 struct pcisel {
56 	u_int32_t	pc_domain;	/* domain number */
57 	u_int8_t	pc_bus;		/* bus number */
58 	u_int8_t	pc_dev;		/* device on this bus */
59 	u_int8_t	pc_func;	/* function on this device */
60 };
61 
62 struct pci_conf {
63 	struct pcisel	pc_sel;		/* domain+bus+slot+function */
64 	u_int8_t	pc_hdr;		/* PCI header type */
65 	u_int16_t	pc_subvendor;	/* card vendor ID */
66 	u_int16_t	pc_subdevice;	/* card device ID, assigned by
67 					   card vendor */
68 	u_int16_t	pc_vendor;	/* chip vendor ID */
69 	u_int16_t	pc_device;	/* chip device ID, assigned by
70 					   chip vendor */
71 	u_int8_t	pc_class;	/* chip PCI class */
72 	u_int8_t	pc_subclass;	/* chip PCI subclass */
73 	u_int8_t	pc_progif;	/* chip PCI programming interface */
74 	u_int8_t	pc_revid;	/* chip revision ID */
75 	char		pd_name[PCI_MAXNAMELEN + 1];  /* device name */
76 	u_long		pd_unit;	/* device unit number */
77 };
78 
79 struct pci_match_conf {
80 	struct pcisel		pc_sel;		/* domain+bus+slot+function */
81 	char			pd_name[PCI_MAXNAMELEN + 1];  /* device name */
82 	u_long			pd_unit;	/* Unit number */
83 	u_int16_t		pc_vendor;	/* PCI Vendor ID */
84 	u_int16_t		pc_device;	/* PCI Device ID */
85 	u_int8_t		pc_class;	/* PCI class */
86 	pci_getconf_flags	flags;		/* Matching expression */
87 };
88 
89 struct pci_conf_io {
90 	u_int32_t		pat_buf_len;	/* pattern buffer length */
91 	u_int32_t		num_patterns;	/* number of patterns */
92 	struct pci_match_conf	*patterns;	/* pattern buffer */
93 	u_int32_t		match_buf_len;	/* match buffer length */
94 	u_int32_t		num_matches;	/* number of matches returned */
95 	struct pci_conf		*matches;	/* match buffer */
96 	u_int32_t		offset;		/* offset into device list */
97 	u_int32_t		generation;	/* device list generation */
98 	pci_getconf_status	status;		/* request status */
99 };
100 
101 struct pci_io {
102 	struct pcisel	pi_sel;		/* device to operate on */
103 	int		pi_reg;		/* configuration register to examine */
104 	int		pi_width;	/* width (in bytes) of read or write */
105 	u_int32_t	pi_data;	/* data to write or result of read */
106 };
107 
108 struct pci_bar_io {
109 	struct pcisel	pbi_sel;	/* device to operate on */
110 	int		pbi_reg;	/* starting address of BAR */
111 	int		pbi_enabled;	/* decoding enabled */
112 	uint64_t	pbi_base;	/* current value of BAR */
113 	uint64_t	pbi_length;	/* length of BAR */
114 };
115 
116 struct pci_vpd_element {
117 	char		pve_keyword[2];
118 	uint8_t		pve_flags;
119 	uint8_t		pve_datalen;
120 	uint8_t		pve_data[0];
121 };
122 
123 #define	PVE_FLAG_IDENT		0x01	/* Element is the string identifier */
124 #define	PVE_FLAG_RW		0x02	/* Element is read/write */
125 
126 #define	PVE_NEXT(pve)							\
127 	((struct pci_vpd_element *)((char *)(pve) +			\
128 	    sizeof(struct pci_vpd_element) + (pve)->pve_datalen))
129 
130 struct pci_list_vpd_io {
131 	struct pcisel	plvi_sel;	/* device to operate on */
132 	size_t		plvi_len;	/* size of the data area */
133 	struct pci_vpd_element *plvi_data;
134 };
135 
136 #define	PCIOCGETCONF	_IOWR('p', 5, struct pci_conf_io)
137 #define	PCIOCREAD	_IOWR('p', 2, struct pci_io)
138 #define	PCIOCWRITE	_IOWR('p', 3, struct pci_io)
139 #define	PCIOCATTACHED	_IOWR('p', 4, struct pci_io)
140 #define	PCIOCGETBAR	_IOWR('p', 6, struct pci_bar_io)
141 #define	PCIOCLISTVPD	_IOWR('p', 7, struct pci_list_vpd_io)
142 
143 #endif /* !_SYS_PCIIO_H_ */
144