xref: /illumos-gate/usr/src/uts/common/sys/pci_props.h (revision e00bdde3c6d406f40f53f3025defadc22f7ec31a)
1 /*
2  * This file and its contents are supplied under the terms of the
3  * Common Development and Distribution License ("CDDL"), version 1.0.
4  * You may only use this file in accordance with the terms of version
5  * 1.0 of the CDDL.
6  *
7  * A full copy of the text of the CDDL should have accompanied this
8  * source.  A copy of the CDDL is also available via the Internet at
9  * http://www.illumos.org/license/CDDL.
10  */
11 
12 /*
13  * Copyright 2023 Oxide Computer Company
14  */
15 
16 #ifndef _SYS_PCI_PROPS_H
17 #define	_SYS_PCI_PROPS_H
18 
19 /*
20  * This contains common structures and functions that are used to initialize and
21  * set up PCI related nodes. As we move further towards unifying the PCI boot
22  * time and hotplug settings several of the functions here can be consolidated
23  * into that single path.
24  */
25 
26 #include <sys/stdint.h>
27 #include <sys/dditypes.h>
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 typedef enum {
34 	PCI_PROP_F_MULT_FUNC	= 1 << 0,
35 	PCI_PROP_F_PCIE		= 1 << 1,
36 	PCI_PROP_F_SLOT_VALID	= 1 << 2
37 } pci_prop_flags_t;
38 
39 typedef struct pci_prop_data {
40 	pci_prop_flags_t ppd_flags;
41 	uint8_t ppd_bus;
42 	uint8_t ppd_dev;
43 	uint8_t ppd_func;
44 	uint8_t ppd_rev;
45 	uint8_t ppd_header;
46 	uint8_t ppd_class;
47 	uint8_t ppd_subclass;
48 	uint8_t ppd_pi;
49 	uint16_t ppd_vendid;
50 	uint16_t ppd_devid;
51 	uint16_t ppd_subvid;
52 	uint16_t ppd_subsys;
53 	uint16_t ppd_pcie_type;
54 	uint16_t ppd_slotno;
55 	uint8_t ppd_pcie_cap_off;
56 	uint8_t ppd_ipin;
57 	uint8_t ppd_mingrt;
58 	uint8_t ppd_maxlat;
59 	uint16_t ppd_status;
60 } pci_prop_data_t;
61 
62 typedef enum {
63 	PCI_PROP_OK	= 0,
64 	/*
65 	 * Indicates that we could not successfully read a given field from the
66 	 * device (e.g. getting all 1s when reading the vendor ID).
67 	 */
68 	PCI_PROP_E_BAD_READ,
69 	/*
70 	 * Indicates that we encountered an unknown header type. The ppd_header
71 	 * field will be valid on this failure as will the basic device, vendor,
72 	 * revision, and class IDs.
73 	 */
74 	PCI_PROP_E_UNKNOWN_HEADER,
75 	/*
76 	 * Indicates that we found an unknown and unsupported PCIe capability
77 	 * structure.
78 	 */
79 	PCI_PROP_E_BAD_PCIE_CAP,
80 	/*
81 	 * Indicates that an NDI or DDI failure occurred respectively.
82 	 */
83 	PCI_PROP_E_NDI,
84 	PCI_PROP_E_DDI
85 } pci_prop_failure_t;
86 
87 extern pci_prop_failure_t pci_prop_data_fill(ddi_acc_handle_t, uint8_t, uint8_t,
88     uint8_t, pci_prop_data_t *);
89 extern pci_prop_failure_t pci_prop_name_node(dev_info_t *,
90     const pci_prop_data_t *);
91 extern pci_prop_failure_t pci_prop_set_common_props(dev_info_t *,
92     const pci_prop_data_t *);
93 extern pci_prop_failure_t pci_prop_set_compatible(dev_info_t *,
94     const pci_prop_data_t *);
95 
96 /*
97  * This is currently exported so there is a single implementation of this logic.
98  */
99 extern boolean_t pci_prop_class_is_vga(const pci_prop_data_t *);
100 extern boolean_t pci_prop_class_is_isa(const pci_prop_data_t *);
101 extern boolean_t pci_prop_class_is_ioapic(const pci_prop_data_t *);
102 extern boolean_t pci_prop_class_is_pcibridge(const pci_prop_data_t *);
103 
104 #ifdef __cplusplus
105 }
106 #endif
107 
108 #endif /* _SYS_PCI_PROPS_H */
109