1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /*
3  * PCI HotPlug Core Functions
4  *
5  * Copyright (C) 1995,2001 Compaq Computer Corporation
6  * Copyright (C) 2001 Greg Kroah-Hartman (greg@kroah.com)
7  * Copyright (C) 2001 IBM Corp.
8  *
9  * All rights reserved.
10  *
11  * Send feedback to <kristen.c.accardi@intel.com>
12  *
13  */
14 #ifndef _PCI_HOTPLUG_H
15 #define _PCI_HOTPLUG_H
16 
17 /**
18  * struct hotplug_slot_ops -the callbacks that the hotplug pci core can use
19  * @owner: The module owner of this structure
20  * @mod_name: The module name (KBUILD_MODNAME) of this structure
21  * @enable_slot: Called when the user wants to enable a specific pci slot
22  * @disable_slot: Called when the user wants to disable a specific pci slot
23  * @set_attention_status: Called to set the specific slot's attention LED to
24  * the specified value
25  * @hardware_test: Called to run a specified hardware test on the specified
26  * slot.
27  * @get_power_status: Called to get the current power status of a slot.
28  *	If this field is NULL, the value passed in the struct hotplug_slot_info
29  *	will be used when this value is requested by a user.
30  * @get_attention_status: Called to get the current attention status of a slot.
31  *	If this field is NULL, the value passed in the struct hotplug_slot_info
32  *	will be used when this value is requested by a user.
33  * @get_latch_status: Called to get the current latch status of a slot.
34  *	If this field is NULL, the value passed in the struct hotplug_slot_info
35  *	will be used when this value is requested by a user.
36  * @get_adapter_status: Called to get see if an adapter is present in the slot or not.
37  *	If this field is NULL, the value passed in the struct hotplug_slot_info
38  *	will be used when this value is requested by a user.
39  * @reset_slot: Optional interface to allow override of a bus reset for the
40  *	slot for cases where a secondary bus reset can result in spurious
41  *	hotplug events or where a slot can be reset independent of the bus.
42  *
43  * The table of function pointers that is passed to the hotplug pci core by a
44  * hotplug pci driver.  These functions are called by the hotplug pci core when
45  * the user wants to do something to a specific slot (query it for information,
46  * set an LED, enable / disable power, etc.)
47  */
48 struct hotplug_slot_ops {
49 	struct module *owner;
50 	const char *mod_name;
51 	int (*enable_slot)		(struct hotplug_slot *slot);
52 	int (*disable_slot)		(struct hotplug_slot *slot);
53 	int (*set_attention_status)	(struct hotplug_slot *slot, u8 value);
54 	int (*hardware_test)		(struct hotplug_slot *slot, u32 value);
55 	int (*get_power_status)		(struct hotplug_slot *slot, u8 *value);
56 	int (*get_attention_status)	(struct hotplug_slot *slot, u8 *value);
57 	int (*get_latch_status)		(struct hotplug_slot *slot, u8 *value);
58 	int (*get_adapter_status)	(struct hotplug_slot *slot, u8 *value);
59 	int (*reset_slot)		(struct hotplug_slot *slot, int probe);
60 };
61 
62 /**
63  * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
64  * @power_status: if power is enabled or not (1/0)
65  * @attention_status: if the attention light is enabled or not (1/0)
66  * @latch_status: if the latch (if any) is open or closed (1/0)
67  * @adapter_status: if there is a pci board present in the slot or not (1/0)
68  *
69  * Used to notify the hotplug pci core of the status of a specific slot.
70  */
71 struct hotplug_slot_info {
72 	u8	power_status;
73 	u8	attention_status;
74 	u8	latch_status;
75 	u8	adapter_status;
76 };
77 
78 /**
79  * struct hotplug_slot - used to register a physical slot with the hotplug pci core
80  * @ops: pointer to the &struct hotplug_slot_ops to be used for this slot
81  * @info: pointer to the &struct hotplug_slot_info for the initial values for
82  * this slot.
83  * @private: used by the hotplug pci controller driver to store whatever it
84  * needs.
85  */
86 struct hotplug_slot {
87 	struct hotplug_slot_ops		*ops;
88 	struct hotplug_slot_info	*info;
89 	void				*private;
90 
91 	/* Variables below this are for use only by the hotplug pci core. */
92 	struct list_head		slot_list;
93 	struct pci_slot			*pci_slot;
94 };
95 
hotplug_slot_name(const struct hotplug_slot * slot)96 static inline const char *hotplug_slot_name(const struct hotplug_slot *slot)
97 {
98 	return pci_slot_name(slot->pci_slot);
99 }
100 
101 int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *pbus, int nr,
102 		      const char *name, struct module *owner,
103 		      const char *mod_name);
104 int __pci_hp_initialize(struct hotplug_slot *slot, struct pci_bus *bus, int nr,
105 			const char *name, struct module *owner,
106 			const char *mod_name);
107 int pci_hp_add(struct hotplug_slot *slot);
108 
109 void pci_hp_del(struct hotplug_slot *slot);
110 void pci_hp_destroy(struct hotplug_slot *slot);
111 void pci_hp_deregister(struct hotplug_slot *slot);
112 
113 int __must_check pci_hp_change_slot_info(struct hotplug_slot *slot,
114 					 struct hotplug_slot_info *info);
115 
116 /* use a define to avoid include chaining to get THIS_MODULE & friends */
117 #define pci_hp_register(slot, pbus, devnr, name) \
118 	__pci_hp_register(slot, pbus, devnr, name, THIS_MODULE, KBUILD_MODNAME)
119 #define pci_hp_initialize(slot, bus, nr, name) \
120 	__pci_hp_initialize(slot, bus, nr, name, THIS_MODULE, KBUILD_MODNAME)
121 
122 /* PCI Setting Record (Type 0) */
123 struct hpp_type0 {
124 	u32 revision;
125 	u8  cache_line_size;
126 	u8  latency_timer;
127 	u8  enable_serr;
128 	u8  enable_perr;
129 };
130 
131 /* PCI-X Setting Record (Type 1) */
132 struct hpp_type1 {
133 	u32 revision;
134 	u8  max_mem_read;
135 	u8  avg_max_split;
136 	u16 tot_max_split;
137 };
138 
139 /* PCI Express Setting Record (Type 2) */
140 struct hpp_type2 {
141 	u32 revision;
142 	u32 unc_err_mask_and;
143 	u32 unc_err_mask_or;
144 	u32 unc_err_sever_and;
145 	u32 unc_err_sever_or;
146 	u32 cor_err_mask_and;
147 	u32 cor_err_mask_or;
148 	u32 adv_err_cap_and;
149 	u32 adv_err_cap_or;
150 	u16 pci_exp_devctl_and;
151 	u16 pci_exp_devctl_or;
152 	u16 pci_exp_lnkctl_and;
153 	u16 pci_exp_lnkctl_or;
154 	u32 sec_unc_err_sever_and;
155 	u32 sec_unc_err_sever_or;
156 	u32 sec_unc_err_mask_and;
157 	u32 sec_unc_err_mask_or;
158 };
159 
160 struct hotplug_params {
161 	struct hpp_type0 *t0;		/* Type0: NULL if not available */
162 	struct hpp_type1 *t1;		/* Type1: NULL if not available */
163 	struct hpp_type2 *t2;		/* Type2: NULL if not available */
164 	struct hpp_type0 type0_data;
165 	struct hpp_type1 type1_data;
166 	struct hpp_type2 type2_data;
167 };
168 
169 #ifdef CONFIG_ACPI
170 #include <linux/acpi.h>
171 int pci_get_hp_params(struct pci_dev *dev, struct hotplug_params *hpp);
172 bool pciehp_is_native(struct pci_dev *bridge);
173 int acpi_get_hp_hw_control_from_firmware(struct pci_dev *bridge);
174 bool shpchp_is_native(struct pci_dev *bridge);
175 int acpi_pci_check_ejectable(struct pci_bus *pbus, acpi_handle handle);
176 int acpi_pci_detect_ejectable(acpi_handle handle);
177 #else
pci_get_hp_params(struct pci_dev * dev,struct hotplug_params * hpp)178 static inline int pci_get_hp_params(struct pci_dev *dev,
179 				    struct hotplug_params *hpp)
180 {
181 	return -ENODEV;
182 }
183 
acpi_get_hp_hw_control_from_firmware(struct pci_dev * bridge)184 static inline int acpi_get_hp_hw_control_from_firmware(struct pci_dev *bridge)
185 {
186 	return 0;
187 }
pciehp_is_native(struct pci_dev * bridge)188 static inline bool pciehp_is_native(struct pci_dev *bridge) { return true; }
shpchp_is_native(struct pci_dev * bridge)189 static inline bool shpchp_is_native(struct pci_dev *bridge) { return true; }
190 #endif
191 
hotplug_is_native(struct pci_dev * bridge)192 static inline bool hotplug_is_native(struct pci_dev *bridge)
193 {
194 	return pciehp_is_native(bridge) || shpchp_is_native(bridge);
195 }
196 #endif
197