1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /*
3  * ACPI PCI Hot Plug Controller Driver
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  * Copyright (C) 2002 Hiroshi Aono (h-aono@ap.jp.nec.com)
9  * Copyright (C) 2002,2003 Takayoshi Kochi (t-kochi@bq.jp.nec.com)
10  * Copyright (C) 2002,2003 NEC Corporation
11  * Copyright (C) 2003-2005 Matthew Wilcox (matthew.wilcox@hp.com)
12  * Copyright (C) 2003-2005 Hewlett Packard
13  *
14  * All rights reserved.
15  *
16  * Send feedback to <gregkh@us.ibm.com>,
17  *		    <t-kochi@bq.jp.nec.com>
18  *
19  */
20 
21 #ifndef _ACPIPHP_H
22 #define _ACPIPHP_H
23 
24 #include <linux/acpi.h>
25 #include <linux/mutex.h>
26 #include <linux/pci_hotplug.h>
27 
28 struct acpiphp_context;
29 struct acpiphp_bridge;
30 struct acpiphp_slot;
31 
32 /*
33  * struct slot - slot information for each *physical* slot
34  */
35 struct slot {
36 	struct hotplug_slot	*hotplug_slot;
37 	struct acpiphp_slot	*acpi_slot;
38 	struct hotplug_slot_info info;
39 	unsigned int sun;	/* ACPI _SUN (Slot User Number) value */
40 };
41 
slot_name(struct slot * slot)42 static inline const char *slot_name(struct slot *slot)
43 {
44 	return hotplug_slot_name(slot->hotplug_slot);
45 }
46 
47 /*
48  * struct acpiphp_bridge - PCI bridge information
49  *
50  * for each bridge device in ACPI namespace
51  */
52 struct acpiphp_bridge {
53 	struct list_head list;
54 	struct list_head slots;
55 	struct kref ref;
56 
57 	struct acpiphp_context *context;
58 
59 	int nr_slots;
60 
61 	/* This bus (host bridge) or Secondary bus (PCI-to-PCI bridge) */
62 	struct pci_bus *pci_bus;
63 
64 	/* PCI-to-PCI bridge device */
65 	struct pci_dev *pci_dev;
66 
67 	bool is_going_away;
68 };
69 
70 
71 /*
72  * struct acpiphp_slot - PCI slot information
73  *
74  * PCI slot information for each *physical* PCI slot
75  */
76 struct acpiphp_slot {
77 	struct list_head node;
78 	struct pci_bus *bus;
79 	struct list_head funcs;		/* one slot may have different
80 					   objects (i.e. for each function) */
81 	struct slot *slot;
82 
83 	u8		device;		/* pci device# */
84 	u32		flags;		/* see below */
85 };
86 
87 
88 /*
89  * struct acpiphp_func - PCI function information
90  *
91  * PCI function information for each object in ACPI namespace
92  * typically 8 objects per slot (i.e. for each PCI function)
93  */
94 struct acpiphp_func {
95 	struct acpiphp_bridge *parent;
96 	struct acpiphp_slot *slot;
97 
98 	struct list_head sibling;
99 
100 	u8		function;	/* pci function# */
101 	u32		flags;		/* see below */
102 };
103 
104 struct acpiphp_context {
105 	struct acpi_hotplug_context hp;
106 	struct acpiphp_func func;
107 	struct acpiphp_bridge *bridge;
108 	unsigned int refcount;
109 };
110 
to_acpiphp_context(struct acpi_hotplug_context * hp)111 static inline struct acpiphp_context *to_acpiphp_context(struct acpi_hotplug_context *hp)
112 {
113 	return container_of(hp, struct acpiphp_context, hp);
114 }
115 
func_to_context(struct acpiphp_func * func)116 static inline struct acpiphp_context *func_to_context(struct acpiphp_func *func)
117 {
118 	return container_of(func, struct acpiphp_context, func);
119 }
120 
func_to_acpi_device(struct acpiphp_func * func)121 static inline struct acpi_device *func_to_acpi_device(struct acpiphp_func *func)
122 {
123 	return func_to_context(func)->hp.self;
124 }
125 
func_to_handle(struct acpiphp_func * func)126 static inline acpi_handle func_to_handle(struct acpiphp_func *func)
127 {
128 	return func_to_acpi_device(func)->handle;
129 }
130 
131 struct acpiphp_root_context {
132 	struct acpi_hotplug_context hp;
133 	struct acpiphp_bridge *root_bridge;
134 };
135 
to_acpiphp_root_context(struct acpi_hotplug_context * hp)136 static inline struct acpiphp_root_context *to_acpiphp_root_context(struct acpi_hotplug_context *hp)
137 {
138 	return container_of(hp, struct acpiphp_root_context, hp);
139 }
140 
141 /*
142  * struct acpiphp_attention_info - device specific attention registration
143  *
144  * ACPI has no generic method of setting/getting attention status
145  * this allows for device specific driver registration
146  */
147 struct acpiphp_attention_info
148 {
149 	int (*set_attn)(struct hotplug_slot *slot, u8 status);
150 	int (*get_attn)(struct hotplug_slot *slot, u8 *status);
151 	struct module *owner;
152 };
153 
154 /* ACPI _STA method value (ignore bit 4; battery present) */
155 #define ACPI_STA_ALL			(0x0000000f)
156 
157 /* slot flags */
158 
159 #define SLOT_ENABLED		(0x00000001)
160 #define SLOT_IS_GOING_AWAY	(0x00000002)
161 
162 /* function flags */
163 
164 #define FUNC_HAS_STA		(0x00000001)
165 #define FUNC_HAS_EJ0		(0x00000002)
166 
167 /* function prototypes */
168 
169 /* acpiphp_core.c */
170 int acpiphp_register_attention(struct acpiphp_attention_info *info);
171 int acpiphp_unregister_attention(struct acpiphp_attention_info *info);
172 int acpiphp_register_hotplug_slot(struct acpiphp_slot *slot, unsigned int sun);
173 void acpiphp_unregister_hotplug_slot(struct acpiphp_slot *slot);
174 
175 /* acpiphp_glue.c */
176 typedef int (*acpiphp_callback)(struct acpiphp_slot *slot, void *data);
177 
178 int acpiphp_enable_slot(struct acpiphp_slot *slot);
179 int acpiphp_disable_slot(struct acpiphp_slot *slot);
180 u8 acpiphp_get_power_status(struct acpiphp_slot *slot);
181 u8 acpiphp_get_attention_status(struct acpiphp_slot *slot);
182 u8 acpiphp_get_latch_status(struct acpiphp_slot *slot);
183 u8 acpiphp_get_adapter_status(struct acpiphp_slot *slot);
184 
185 /* variables */
186 extern bool acpiphp_disabled;
187 
188 #endif /* _ACPIPHP_H */
189