xref: /titanic_41/usr/src/uts/i86pc/sys/acpidev.h (revision de5d74c22760a6d2cefd94d0e7f0fd87214fb71f)
1b72d5b75SMichael Corcoran /*
2b72d5b75SMichael Corcoran  * CDDL HEADER START
3b72d5b75SMichael Corcoran  *
4b72d5b75SMichael Corcoran  * The contents of this file are subject to the terms of the
5b72d5b75SMichael Corcoran  * Common Development and Distribution License (the "License").
6b72d5b75SMichael Corcoran  * You may not use this file except in compliance with the License.
7b72d5b75SMichael Corcoran  *
8b72d5b75SMichael Corcoran  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9b72d5b75SMichael Corcoran  * or http://www.opensolaris.org/os/licensing.
10b72d5b75SMichael Corcoran  * See the License for the specific language governing permissions
11b72d5b75SMichael Corcoran  * and limitations under the License.
12b72d5b75SMichael Corcoran  *
13b72d5b75SMichael Corcoran  * When distributing Covered Code, include this CDDL HEADER in each
14b72d5b75SMichael Corcoran  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15b72d5b75SMichael Corcoran  * If applicable, add the following below this CDDL HEADER, with the
16b72d5b75SMichael Corcoran  * fields enclosed by brackets "[]" replaced with your own identifying
17b72d5b75SMichael Corcoran  * information: Portions Copyright [yyyy] [name of copyright owner]
18b72d5b75SMichael Corcoran  *
19b72d5b75SMichael Corcoran  * CDDL HEADER END
20b72d5b75SMichael Corcoran  */
21b72d5b75SMichael Corcoran /*
22a3114836SGerry Liu  * Copyright (c) 2009-2010, Intel Corporation.
23b72d5b75SMichael Corcoran  * All rights reserved.
24*de5d74c2SJerry Jelinek  * Copyright (c) 2012, Joyent, Inc. All rights reserved.
25b72d5b75SMichael Corcoran  */
26b72d5b75SMichael Corcoran 
27b72d5b75SMichael Corcoran #ifndef	_SYS_ACPIDEV_H
28b72d5b75SMichael Corcoran #define	_SYS_ACPIDEV_H
29b72d5b75SMichael Corcoran #include <sys/types.h>
30b72d5b75SMichael Corcoran #include <sys/obpdefs.h>
31b72d5b75SMichael Corcoran #include <sys/sunddi.h>
32a3114836SGerry Liu #ifdef	_KERNEL
33b72d5b75SMichael Corcoran #include <sys/acpi/acpi.h>
34b72d5b75SMichael Corcoran #include <sys/acpica.h>
35a3114836SGerry Liu #endif
36b72d5b75SMichael Corcoran 
37b72d5b75SMichael Corcoran #ifdef __cplusplus
38b72d5b75SMichael Corcoran extern "C" {
39b72d5b75SMichael Corcoran #endif
40b72d5b75SMichael Corcoran 
41b72d5b75SMichael Corcoran /* Maximum recursion levels when enumerating objects in ACPI namespace. */
42b72d5b75SMichael Corcoran #define	ACPIDEV_MAX_ENUM_LEVELS		32
43b72d5b75SMichael Corcoran 
44b72d5b75SMichael Corcoran /* Maximum length of device name for ACPI object. */
45b72d5b75SMichael Corcoran #define	ACPIDEV_MAX_NAMELEN		OBP_MAXDRVNAME
46b72d5b75SMichael Corcoran 
47b72d5b75SMichael Corcoran /* Pseudo ACPI device HID for ACPI root object. */
48b72d5b75SMichael Corcoran #define	ACPIDEV_HID_ROOTNEX		"SOLA0001"
49b72d5b75SMichael Corcoran /* Pseudo ACPI device HID for ACPI virtual bus. */
50b72d5b75SMichael Corcoran #define	ACPIDEV_HID_VIRTNEX		"SOLA0002"
51b72d5b75SMichael Corcoran #define	ACPIDEV_HID_SCOPE		"SOLA0003"
52b72d5b75SMichael Corcoran #define	ACPIDEV_HID_PROCESSOR		"SOLA0004"
53b72d5b75SMichael Corcoran 
54b72d5b75SMichael Corcoran /* ACPI device HIDs/CIDs defined by ACPI specification. */
55b72d5b75SMichael Corcoran #define	ACPIDEV_HID_CONTAINER1		"PNP0A05"
56b72d5b75SMichael Corcoran #define	ACPIDEV_HID_CONTAINER2		"PNP0A06"
57b72d5b75SMichael Corcoran #define	ACPIDEV_HID_MODULE		"ACPI0004"
58b72d5b75SMichael Corcoran #define	ACPIDEV_HID_CPU			"ACPI0007"
59b72d5b75SMichael Corcoran #define	ACPIDEV_HID_PCI_HOSTBRIDGE	"PNP0A03"
60b72d5b75SMichael Corcoran #define	ACPIDEV_HID_PCIE_HOSTBRIDGE	"PNP0A08"
61a3114836SGerry Liu #define	ACPIDEV_HID_PCIEX_HOSTBRIDGE	"PNP0A08"
62b72d5b75SMichael Corcoran #define	ACPIDEV_HID_MEMORY		"PNP0C80"
63b72d5b75SMichael Corcoran 
64b72d5b75SMichael Corcoran /* Device names for ACPI objects. */
65b72d5b75SMichael Corcoran #define	ACPIDEV_NODE_NAME_ROOT		"fw"
66a3114836SGerry Liu #define	ACPIDEV_NODE_NAME_ACPIDR	"acpidr"
67b72d5b75SMichael Corcoran #define	ACPIDEV_NODE_NAME_CONTAINER	"container"
68b72d5b75SMichael Corcoran #define	ACPIDEV_NODE_NAME_MODULE_SBD	"sb"
69b72d5b75SMichael Corcoran #define	ACPIDEV_NODE_NAME_MODULE_CPU	"socket"
70b72d5b75SMichael Corcoran #define	ACPIDEV_NODE_NAME_CPU		"cpu"
71b72d5b75SMichael Corcoran #define	ACPIDEV_NODE_NAME_PROCESSOR	"cpus"
72b72d5b75SMichael Corcoran #define	ACPIDEV_NODE_NAME_MEMORY	"mem"
73a3114836SGerry Liu #define	ACPIDEV_NODE_NAME_PCI		"pci"
74b72d5b75SMichael Corcoran 
75b72d5b75SMichael Corcoran /* Device types for ACPI objects. */
76b72d5b75SMichael Corcoran #define	ACPIDEV_TYPE_ROOTNEX		"acpirootnex"
77b72d5b75SMichael Corcoran #define	ACPIDEV_TYPE_VIRTNEX		"acpivirtnex"
78b72d5b75SMichael Corcoran #define	ACPIDEV_TYPE_SCOPE		"acpiscope"
79b72d5b75SMichael Corcoran #define	ACPIDEV_TYPE_DEVICE		"acpidevice"
80b72d5b75SMichael Corcoran #define	ACPIDEV_TYPE_CONTAINER		"acpicontainer"
813b17bf65SMichael Corcoran #define	ACPIDEV_TYPE_CPU		"acpicpu"
82b72d5b75SMichael Corcoran #define	ACPIDEV_TYPE_MEMORY		"acpimemory"
83a3114836SGerry Liu #define	ACPIDEV_TYPE_PCI		"pci"
84a3114836SGerry Liu #define	ACPIDEV_TYPE_PCIEX		"pciex"
85b72d5b75SMichael Corcoran 
86b72d5b75SMichael Corcoran /* Device property names for ACPI objects. */
87b72d5b75SMichael Corcoran #define	ACPIDEV_PROP_NAME_UNIT_ADDR	"unit-address"
88b72d5b75SMichael Corcoran #define	ACPIDEV_PROP_NAME_ACPI_UID	"acpi-uid"
89b72d5b75SMichael Corcoran #define	ACPIDEV_PROP_NAME_PROCESSOR_ID	"acpi-processor-id"
90b72d5b75SMichael Corcoran #define	ACPIDEV_PROP_NAME_LOCALAPIC_ID	"apic-id"
91a3114836SGerry Liu #define	ACPIDEV_PROP_NAME_PROXIMITY_ID	"proximity-id"
92b72d5b75SMichael Corcoran 
93b72d5b75SMichael Corcoran #define	ACPIDEV_PROP_NAME_UID_FORMAT	"acpidev-uid-format"
94b72d5b75SMichael Corcoran 
95a3114836SGerry Liu /* Miscellaneous strings. */
96a3114836SGerry Liu #define	ACPIDEV_CMD_OST_PREFIX		"acpi-update-status"
97a3114836SGerry Liu #define	ACPIDEV_CMD_OST_INPROGRESS	"acpi-update-status=inprogress"
98a3114836SGerry Liu #define	ACPIDEV_CMD_OST_SUCCESS		"acpi-update-status=success"
99a3114836SGerry Liu #define	ACPIDEV_CMD_OST_FAILURE		"acpi-update-status=failure"
100a3114836SGerry Liu #define	ACPIDEV_CMD_OST_NOOP		"acpi-update-status=noop"
101a3114836SGerry Liu 
102a3114836SGerry Liu #define	ACPIDEV_EVENT_TYPE_ATTR_NAME	"acpi-event-type"
103a3114836SGerry Liu #define	ACPIDEV_EVENT_TYPE_BUS_CHECK	"bus_check"
104a3114836SGerry Liu #define	ACPIDEV_EVENT_TYPE_DEVICE_CHECK	"device_check"
105a3114836SGerry Liu #define	ACPIDEV_EVENT_TYPE_DEVICE_CHECK_LIGHT	"device_check_light"
106a3114836SGerry Liu #define	ACPIDEV_EVENT_TYPE_EJECT_REQUEST	"eject_request"
107a3114836SGerry Liu 
108b72d5b75SMichael Corcoran /* ACPI device class Id. */
109b72d5b75SMichael Corcoran typedef enum acpidev_class_id {
110b72d5b75SMichael Corcoran 	ACPIDEV_CLASS_ID_INVALID = 0,
111b72d5b75SMichael Corcoran 	ACPIDEV_CLASS_ID_ROOTNEX = 1,
112b72d5b75SMichael Corcoran 	ACPIDEV_CLASS_ID_SCOPE = 2,
113b72d5b75SMichael Corcoran 	ACPIDEV_CLASS_ID_DEVICE = 3,
114b72d5b75SMichael Corcoran 	ACPIDEV_CLASS_ID_CONTAINER = 4,
115b72d5b75SMichael Corcoran 	ACPIDEV_CLASS_ID_CPU = 5,
116b72d5b75SMichael Corcoran 	ACPIDEV_CLASS_ID_MEMORY = 6,
117a3114836SGerry Liu 	ACPIDEV_CLASS_ID_PCI = 7,
118a3114836SGerry Liu 	ACPIDEV_CLASS_ID_PCIEX = 8,
119b72d5b75SMichael Corcoran 	ACPIDEV_CLASS_ID_MAX
120b72d5b75SMichael Corcoran } acpidev_class_id_t;
121b72d5b75SMichael Corcoran 
122b72d5b75SMichael Corcoran /* Flags for acpidev_options boot options. */
123b72d5b75SMichael Corcoran #define	ACPIDEV_OUSER_NO_CPU		0x1
124b72d5b75SMichael Corcoran #define	ACPIDEV_OUSER_NO_MEM		0x2
125b72d5b75SMichael Corcoran #define	ACPIDEV_OUSER_NO_CONTAINER	0x4
126a3114836SGerry Liu #define	ACPIDEV_OUSER_NO_PCI		0x8
127a3114836SGerry Liu #define	ACPIDEV_OUSER_NO_CACHE		0x10000
128b72d5b75SMichael Corcoran 
129b72d5b75SMichael Corcoran #ifdef	_KERNEL
130b72d5b75SMichael Corcoran 
131a3114836SGerry Liu /* Common ACPI object names. */
132*de5d74c2SJerry Jelinek #define	ACPIDEV_OBJECT_NAME_SB		METHOD_NAME__SB_
133a3114836SGerry Liu #define	ACPIDEV_OBJECT_NAME_PR		"_PR_"
134a3114836SGerry Liu 
135a3114836SGerry Liu /* Common ACPI method names. */
136a3114836SGerry Liu #define	ACPIDEV_METHOD_NAME_MAT		"_MAT"
137a3114836SGerry Liu #define	ACPIDEV_METHOD_NAME_EJ0		"_EJ0"
138a3114836SGerry Liu #define	ACPIDEV_METHOD_NAME_EDL		"_EDL"
139a3114836SGerry Liu #define	ACPIDEV_METHOD_NAME_EJD		"_EJD"
140a3114836SGerry Liu #define	ACPIDEV_METHOD_NAME_OST		"_OST"
141a3114836SGerry Liu #define	ACPIDEV_METHOD_NAME_PXM		"_PXM"
142a3114836SGerry Liu #define	ACPIDEV_METHOD_NAME_SLI		"_SLI"
143a3114836SGerry Liu 
144a3114836SGerry Liu /* Source event code for _OST. */
145a3114836SGerry Liu #define	ACPI_OST_EVENT_EJECTING		0x103
146a3114836SGerry Liu #define	ACPI_OST_EVENT_INSERTING	0x200
147a3114836SGerry Liu 
148a3114836SGerry Liu /* Status code for _OST. */
149a3114836SGerry Liu #define	ACPI_OST_STA_SUCCESS		0x0
150a3114836SGerry Liu 
151a3114836SGerry Liu /* Non-specific failure. */
152a3114836SGerry Liu #define	ACPI_OST_STA_FAILURE		0x1
153a3114836SGerry Liu 
154a3114836SGerry Liu /* Unrecognized Notify Code. */
155a3114836SGerry Liu #define	ACPI_OST_STA_NOT_SUPPORT	0x2
156a3114836SGerry Liu 
157a3114836SGerry Liu /* Device ejection not supported by OSPM. */
158a3114836SGerry Liu #define	ACPI_OST_STA_EJECT_NOT_SUPPORT	0x80
159a3114836SGerry Liu 
160a3114836SGerry Liu /* Device in use by application. */
161a3114836SGerry Liu #define	ACPI_OST_STA_EJECT_IN_USE	0x81
162a3114836SGerry Liu 
163a3114836SGerry Liu /* Device Busy. */
164a3114836SGerry Liu #define	ACPI_OST_STA_EJECT_BUSY		0x82
165a3114836SGerry Liu 
166a3114836SGerry Liu /* Ejection dependency is busy or not supported for ejection by OSPM. */
167a3114836SGerry Liu #define	ACPI_OST_STA_EJECT_DEPENDENCY	0x83
168a3114836SGerry Liu 
169a3114836SGerry Liu /* Ejection is in progress (pending). */
170a3114836SGerry Liu #define	ACPI_OST_STA_EJECT_IN_PROGRESS	0x84
171a3114836SGerry Liu 
172a3114836SGerry Liu /* Device insertion in progress (pending). */
173a3114836SGerry Liu #define	ACPI_OST_STA_INSERT_IN_PROGRESS	0x80
174a3114836SGerry Liu 
175a3114836SGerry Liu /* Device driver load failure. */
176a3114836SGerry Liu #define	ACPI_OST_STA_INSERT_DRIVER	0x81
177a3114836SGerry Liu 
178a3114836SGerry Liu /* Device insertion not supported by OSPM. */
179a3114836SGerry Liu #define	ACPI_OST_STA_INSERT_NOT_SUPPORT	0x82
180a3114836SGerry Liu 
181a3114836SGerry Liu /*
182a3114836SGerry Liu  * Insertion failure
183a3114836SGerry Liu  * Resources Unavailable as described by the following bit encodings:
184a3114836SGerry Liu  * Bit[3] Bus Numbers
185a3114836SGerry Liu  * Bit[2] Interrupts
186a3114836SGerry Liu  * Bit[1] I/O
187a3114836SGerry Liu  * Bit[0] Memory
188a3114836SGerry Liu  */
189a3114836SGerry Liu #define	ACPI_OST_STA_INSERT_NO_RESOURCE	0x90
190a3114836SGerry Liu #define	ACPI_OST_STA_INSERT_NO_BUS	0x8
191a3114836SGerry Liu #define	ACPI_OST_STA_INSERT_NO_INTR	0x4
192a3114836SGerry Liu #define	ACPI_OST_STA_INSERT_NO_IO	0x2
193a3114836SGerry Liu #define	ACPI_OST_STA_INSERT_NO_MEM	0x1
194a3114836SGerry Liu 
195a3114836SGerry Liu /*
196a3114836SGerry Liu  * According to the ACPI specification, self latency (entry[n][n]) in the
197a3114836SGerry Liu  * SLIT table should be 10.
198a3114836SGerry Liu  */
199a3114836SGerry Liu #define	ACPI_SLIT_SELF_LATENCY		10
200a3114836SGerry Liu 
201a3114836SGerry Liu /*
202a3114836SGerry Liu  * The DR driver assigns a unique device id for each hot-added memory device.
203a3114836SGerry Liu  * ACPI_MEMNODE_DEVID_BOOT is assigned to memory devices present at boot,
204a3114836SGerry Liu  * which is distinguished from device ids assigned by the DR driver.
205a3114836SGerry Liu  */
206a3114836SGerry Liu #define	ACPI_MEMNODE_DEVID_BOOT		UINT32_MAX
207a3114836SGerry Liu 
208b72d5b75SMichael Corcoran /* Forward declaration */
209b72d5b75SMichael Corcoran typedef	struct acpidev_data_impl	*acpidev_data_handle_t;
210b72d5b75SMichael Corcoran typedef struct acpidev_walk_info	acpidev_walk_info_t;
211b72d5b75SMichael Corcoran typedef struct acpidev_filter_rule	acpidev_filter_rule_t;
212b72d5b75SMichael Corcoran typedef struct acpidev_class		acpidev_class_t;
213b72d5b75SMichael Corcoran typedef struct acpidev_class_list	acpidev_class_list_t;
214b72d5b75SMichael Corcoran 
215b72d5b75SMichael Corcoran /* Type of ACPI device enumerating operation. */
216b72d5b75SMichael Corcoran typedef enum acpidev_op_type {
217b72d5b75SMichael Corcoran 	ACPIDEV_OP_BOOT_PROBE = 0,	/* First pass probing at boot time. */
218b72d5b75SMichael Corcoran 	ACPIDEV_OP_BOOT_REPROBE,	/* Second pass probing at boot time. */
219b72d5b75SMichael Corcoran 	ACPIDEV_OP_HOTPLUG_PROBE	/* Probing for hotplug at runtime. */
220b72d5b75SMichael Corcoran } acpidev_op_type_t;
221b72d5b75SMichael Corcoran 
222b72d5b75SMichael Corcoran /*
223b72d5b75SMichael Corcoran  * Structure to pass arguments when enumerating ACPI namespace.
224b72d5b75SMichael Corcoran  */
225b72d5b75SMichael Corcoran struct acpidev_walk_info {
226b72d5b75SMichael Corcoran 	/* Always valid for all callbacks. */
227b72d5b75SMichael Corcoran 	acpidev_op_type_t		awi_op_type;
228b72d5b75SMichael Corcoran 	int				awi_level;
229b72d5b75SMichael Corcoran 	acpidev_walk_info_t		*awi_parent;
230b72d5b75SMichael Corcoran 	acpidev_class_t			*awi_class_curr;
231b72d5b75SMichael Corcoran 
232b72d5b75SMichael Corcoran 	/* Valid for all callbacks except pre_probe and post_probe. */
233b72d5b75SMichael Corcoran 	int				awi_flags;
234b72d5b75SMichael Corcoran 	ACPI_HANDLE			awi_hdl;
235b72d5b75SMichael Corcoran 	ACPI_DEVICE_INFO		*awi_info;
236b72d5b75SMichael Corcoran 	char				*awi_name;
237b72d5b75SMichael Corcoran 	acpidev_data_handle_t		awi_data;
238b72d5b75SMichael Corcoran 
239b72d5b75SMichael Corcoran 	/* Need to validate it before access. */
240b72d5b75SMichael Corcoran 	dev_info_t			*awi_dip;
241b72d5b75SMichael Corcoran 	acpidev_class_list_t		**awi_class_list;
242b72d5b75SMichael Corcoran 
243b72d5b75SMichael Corcoran 	/* Used by class to store data temporarily. */
244b72d5b75SMichael Corcoran 	intptr_t			awi_scratchpad[4];
245b72d5b75SMichael Corcoran };
246b72d5b75SMichael Corcoran 
247b72d5b75SMichael Corcoran /* Disable creating device nodes for ACPI objects. */
248b72d5b75SMichael Corcoran #define	ACPIDEV_WI_DISABLE_CREATE	0x1
249b72d5b75SMichael Corcoran /* Device node has already been created for an ACPI object. */
250b72d5b75SMichael Corcoran #define	ACPIDEV_WI_DEVICE_CREATED	0x2
251b72d5b75SMichael Corcoran /* Disable enumerating children of ACPI objects. */
252b72d5b75SMichael Corcoran #define	ACPIDEV_WI_DISABLE_SCAN		0x10
253b72d5b75SMichael Corcoran /* Children of ACPI objects have already been enumerated. */
254b72d5b75SMichael Corcoran #define	ACPIDEV_WI_CHILD_SCANNED	0x20
255b72d5b75SMichael Corcoran 
256b72d5b75SMichael Corcoran /*
257b72d5b75SMichael Corcoran  * Device filtering result code.
258b72d5b75SMichael Corcoran  * Device filtering logic will be applied to determine how to handle ACPI
259b72d5b75SMichael Corcoran  * objects according to the filtering result code when enumerating ACPI objects.
260b72d5b75SMichael Corcoran  */
261b72d5b75SMichael Corcoran typedef enum acpidev_filter_result {
262b72d5b75SMichael Corcoran 	ACPIDEV_FILTER_FAILED = -1,	/* operation failed */
263b72d5b75SMichael Corcoran 	ACPIDEV_FILTER_CONTINUE = 0,	/* continue to evaluate filter rules */
264b72d5b75SMichael Corcoran 	ACPIDEV_FILTER_DEFAULT,		/* create node and scan child */
265b72d5b75SMichael Corcoran 	ACPIDEV_FILTER_SCAN,		/* scan child of current node only */
266b72d5b75SMichael Corcoran 	ACPIDEV_FILTER_CREATE,		/* create device node only */
267b72d5b75SMichael Corcoran 	ACPIDEV_FILTER_SKIP,		/* skip current node */
268b72d5b75SMichael Corcoran } acpidev_filter_result_t;
269b72d5b75SMichael Corcoran 
270b72d5b75SMichael Corcoran typedef acpidev_filter_result_t (* acpidev_filter_func_t)(acpidev_walk_info_t *,
271b72d5b75SMichael Corcoran     ACPI_HANDLE, acpidev_filter_rule_t *, char *, int);
272b72d5b75SMichael Corcoran 
273b72d5b75SMichael Corcoran /*
274b72d5b75SMichael Corcoran  * Device filter rule data structure.
275b72d5b75SMichael Corcoran  * User provided callback will be called if adf_filter_func is not NULL,
276b72d5b75SMichael Corcoran  * otherwise default filtering algorithm will be applied.
277b72d5b75SMichael Corcoran  */
278b72d5b75SMichael Corcoran struct acpidev_filter_rule {
279b72d5b75SMichael Corcoran 	acpidev_filter_func_t		adf_filter_func;
280b72d5b75SMichael Corcoran 	intptr_t			adf_filter_arg;
281b72d5b75SMichael Corcoran 	acpidev_filter_result_t		adf_retcode;
282b72d5b75SMichael Corcoran 	acpidev_class_list_t		**adf_class_list;
283b72d5b75SMichael Corcoran 	intptr_t			adf_minlvl;
284b72d5b75SMichael Corcoran 	intptr_t			adf_maxlvl;
285b72d5b75SMichael Corcoran 	char				*adf_pattern;
286b72d5b75SMichael Corcoran 	char				*adf_replace;
287b72d5b75SMichael Corcoran };
288b72d5b75SMichael Corcoran 
289b72d5b75SMichael Corcoran /* Callback function prototypes for ACPI device class driver. */
290b72d5b75SMichael Corcoran typedef ACPI_STATUS (* acpidev_pre_probe_t)(acpidev_walk_info_t *);
291b72d5b75SMichael Corcoran typedef ACPI_STATUS (* acpidev_post_probe_t)(acpidev_walk_info_t *);
292b72d5b75SMichael Corcoran typedef ACPI_STATUS (* acpidev_probe_t)(acpidev_walk_info_t *);
293b72d5b75SMichael Corcoran typedef acpidev_filter_result_t (* acpidev_filter_t)(acpidev_walk_info_t *,
294b72d5b75SMichael Corcoran     char *, int);
295b72d5b75SMichael Corcoran typedef ACPI_STATUS (* acpidev_init_t)(acpidev_walk_info_t *);
296a3114836SGerry Liu typedef void (* acpidev_fini_t)(ACPI_HANDLE, acpidev_data_handle_t,
297b72d5b75SMichael Corcoran     acpidev_class_t *);
298b72d5b75SMichael Corcoran 
299b72d5b75SMichael Corcoran /* Device class driver interface. */
300b72d5b75SMichael Corcoran struct acpidev_class {
301b72d5b75SMichael Corcoran 	volatile uint32_t		adc_refcnt;
302b72d5b75SMichael Corcoran 	int				adc_version;
303b72d5b75SMichael Corcoran 	acpidev_class_id_t		adc_class_id;
304b72d5b75SMichael Corcoran 	/* Name of device class, used in log messages. */
305b72d5b75SMichael Corcoran 	char				*adc_class_name;
306b72d5b75SMichael Corcoran 	/* Used as "device_type" property. */
307b72d5b75SMichael Corcoran 	char				*adc_dev_type;
308b72d5b75SMichael Corcoran 	/* Private storage for device driver. */
309b72d5b75SMichael Corcoran 	void				*adc_private;
310b72d5b75SMichael Corcoran 	/* Callback to setup environment before probing child objects. */
311b72d5b75SMichael Corcoran 	acpidev_pre_probe_t		adc_pre_probe;
312b72d5b75SMichael Corcoran 	/* Callback to clean environment after probing child objects. */
313b72d5b75SMichael Corcoran 	acpidev_post_probe_t		adc_post_probe;
314b72d5b75SMichael Corcoran 	/* Callback to probe child objects. */
315b72d5b75SMichael Corcoran 	acpidev_probe_t			adc_probe;
316b72d5b75SMichael Corcoran 	/* Callback to figure out policy to handle objects. */
317b72d5b75SMichael Corcoran 	acpidev_filter_t		adc_filter;
318b72d5b75SMichael Corcoran 	/* Callback to set device class specific device properties. */
319b72d5b75SMichael Corcoran 	acpidev_init_t			adc_init;
320b72d5b75SMichael Corcoran 	/* Callback to clean up resources when destroying device nodes. */
321b72d5b75SMichael Corcoran 	acpidev_fini_t			adc_fini;
322b72d5b75SMichael Corcoran };
323b72d5b75SMichael Corcoran 
324b72d5b75SMichael Corcoran /* Versions of the ACPI device class driver data structure. */
325b72d5b75SMichael Corcoran #define	ACPIDEV_CLASS_REV1		1
326b72d5b75SMichael Corcoran #define	ACPIDEV_CLASS_REV		ACPIDEV_CLASS_REV1
327b72d5b75SMichael Corcoran 
328b72d5b75SMichael Corcoran /*
329b72d5b75SMichael Corcoran  * Class drivers.
330b72d5b75SMichael Corcoran  */
331b72d5b75SMichael Corcoran extern acpidev_class_t			acpidev_class_scope;
332b72d5b75SMichael Corcoran extern acpidev_class_t			acpidev_class_device;
333b72d5b75SMichael Corcoran extern acpidev_class_t			acpidev_class_container;
334b72d5b75SMichael Corcoran extern acpidev_class_t			acpidev_class_cpu;
335b72d5b75SMichael Corcoran extern acpidev_class_t			acpidev_class_memory;
336a3114836SGerry Liu extern acpidev_class_t			acpidev_class_pci;
337b72d5b75SMichael Corcoran 
338b72d5b75SMichael Corcoran /*
339b72d5b75SMichael Corcoran  * Class driver lists.
340b72d5b75SMichael Corcoran  */
341b72d5b75SMichael Corcoran extern acpidev_class_list_t		*acpidev_class_list_root;
342b72d5b75SMichael Corcoran extern acpidev_class_list_t		*acpidev_class_list_scope;
343b72d5b75SMichael Corcoran extern acpidev_class_list_t		*acpidev_class_list_device;
344b72d5b75SMichael Corcoran extern acpidev_class_list_t		*acpidev_class_list_cpu;
345b72d5b75SMichael Corcoran extern acpidev_class_list_t		*acpidev_class_list_memory;
346b72d5b75SMichael Corcoran 
347b72d5b75SMichael Corcoran /*
348b72d5b75SMichael Corcoran  * Register a device class driver onto a driver list. All class drivers on the
349b72d5b75SMichael Corcoran  * same list will be called in order when processing an ACPI object.
350b72d5b75SMichael Corcoran  * This interface can be used to support machine/platform specific object
351b72d5b75SMichael Corcoran  * handling by registering special plug-in class drivers to override system
352b72d5b75SMichael Corcoran  * default behaviors.
353b72d5b75SMichael Corcoran  * listpp:	pointer to driver list header
354b72d5b75SMichael Corcoran  * clsp:	device class driver to register
355b72d5b75SMichael Corcoran  * tail:	insert at tail of list if true
356b72d5b75SMichael Corcoran  * Return values:
357b72d5b75SMichael Corcoran  *	AE_OK: success
358b72d5b75SMichael Corcoran  *	AE_BAD_PARAMETER: invalid parameter
359b72d5b75SMichael Corcoran  *	AE_BAD_DATA: driver version mismatch
360b72d5b75SMichael Corcoran  *	AE_ALREADY_EXISTS: class driver already exists on the list
361b72d5b75SMichael Corcoran  */
362b72d5b75SMichael Corcoran extern ACPI_STATUS acpidev_register_class(acpidev_class_list_t **listpp,
363b72d5b75SMichael Corcoran     acpidev_class_t *clsp, boolean_t tail);
364b72d5b75SMichael Corcoran 
365b72d5b75SMichael Corcoran /*
366b72d5b75SMichael Corcoran  * Unregister a device class driver from a driver list.
367b72d5b75SMichael Corcoran  * listpp: pointer to driver list header
368b72d5b75SMichael Corcoran  * clsp: device class driver to unregister
369b72d5b75SMichael Corcoran  * Return values:
370b72d5b75SMichael Corcoran  *	AE_OK: success
371b72d5b75SMichael Corcoran  *	AE_BAD_PARAMETER: invalid parameter
372b72d5b75SMichael Corcoran  *	AE_NOT_FOUND: class driver doesn't exist in list
373b72d5b75SMichael Corcoran  *	AE_ERROR: class driver is still in use.
374b72d5b75SMichael Corcoran  */
375b72d5b75SMichael Corcoran extern ACPI_STATUS acpidev_unregister_class(acpidev_class_list_t **listpp,
376b72d5b75SMichael Corcoran     acpidev_class_t *clsp);
377b72d5b75SMichael Corcoran 
378b72d5b75SMichael Corcoran /*
379b72d5b75SMichael Corcoran  * Recursively enumerate child objects of an ACPI object.
380b72d5b75SMichael Corcoran  * It does following things in turn:
381b72d5b75SMichael Corcoran  * 1) Call pre_probe callback for each registered handler
382b72d5b75SMichael Corcoran  * 2) Enumerate child objects and call probe callbacks for each object
383b72d5b75SMichael Corcoran  * 3) Call post_probe callback for each registered handler
384b72d5b75SMichael Corcoran  * Return AE_OK on success and error code on failure.
385b72d5b75SMichael Corcoran  */
386b72d5b75SMichael Corcoran extern ACPI_STATUS acpidev_probe_child(acpidev_walk_info_t *infop);
387b72d5b75SMichael Corcoran 
388b72d5b75SMichael Corcoran /*
389b72d5b75SMichael Corcoran  * Default handler to process ACPI objects.
390b72d5b75SMichael Corcoran  * It creates a device node for an ACPI object and scans all child objects on
391b72d5b75SMichael Corcoran  * demand.
392b72d5b75SMichael Corcoran  * Return values:
393b72d5b75SMichael Corcoran  * AE_OK: on success
394b72d5b75SMichael Corcoran  * AE_NOT_EXIST: device doesn't exist according to _STA value.
395b72d5b75SMichael Corcoran  * AE_ALREADY_EXISTS: object already handled by other handler.
396b72d5b75SMichael Corcoran  * AE_ERROR: on other failure
397b72d5b75SMichael Corcoran  */
398b72d5b75SMichael Corcoran extern ACPI_STATUS acpidev_process_object(acpidev_walk_info_t *infop,
399b72d5b75SMichael Corcoran     int flags);
400b72d5b75SMichael Corcoran 
401b72d5b75SMichael Corcoran /* Flags for acpidev_process_device() */
402b72d5b75SMichael Corcoran #define	ACPIDEV_PROCESS_FLAG_CREATE	0x1	/* Create device */
403b72d5b75SMichael Corcoran #define	ACPIDEV_PROCESS_FLAG_SCAN	0x2	/* Scan child objects */
404b72d5b75SMichael Corcoran #define	ACPIDEV_PROCESS_FLAG_CHECK	0x100	/* Check status */
405b72d5b75SMichael Corcoran #define	ACPIDEV_PROCESS_FLAG_NOBIND	0x200	/* Skip binding driver */
406b72d5b75SMichael Corcoran #define	ACPIDEV_PROCESS_FLAG_OFFLINE	0x400	/* Put device into offline. */
407b72d5b75SMichael Corcoran #define	ACPIDEV_PROCESS_FLAG_NOTAG	0x800	/* Skip tag dip with object. */
408b72d5b75SMichael Corcoran #define	ACPIDEV_PROCESS_FLAG_SYNCSTATUS	0x1000	/* Sync object status. */
409a3114836SGerry Liu #define	ACPIDEV_PROCESS_FLAG_HOLDBRANCH	0x10000	/* Hold device branch. */
410b72d5b75SMichael Corcoran 
411b72d5b75SMichael Corcoran /*
412b72d5b75SMichael Corcoran  * Filter ACPI objects according to filter rules, generate devname if needed.
413b72d5b75SMichael Corcoran  * infop:	pointer to walker information structure
414b72d5b75SMichael Corcoran  * hdl:		handle of ACPI object in question
415b72d5b75SMichael Corcoran  * afrp:	pointer to filter rule array
416b72d5b75SMichael Corcoran  * entries:	number of filter rules in array
417b72d5b75SMichael Corcoran  * devname:	buffer to store generated device name
418b72d5b75SMichael Corcoran  * len:		sizeof devname buffer
419b72d5b75SMichael Corcoran  */
420b72d5b75SMichael Corcoran extern acpidev_filter_result_t acpidev_filter_device(acpidev_walk_info_t *infop,
421b72d5b75SMichael Corcoran     ACPI_HANDLE hdl, acpidev_filter_rule_t *afrp, int entries,
422b72d5b75SMichael Corcoran     char *devname, int len);
423b72d5b75SMichael Corcoran 
424b72d5b75SMichael Corcoran /* Default object filtering algorithm. */
425b72d5b75SMichael Corcoran extern acpidev_filter_result_t acpidev_filter_default(
426b72d5b75SMichael Corcoran     acpidev_walk_info_t *infop, ACPI_HANDLE hdl, acpidev_filter_rule_t *afrp,
427b72d5b75SMichael Corcoran     char *devname, int len);
428b72d5b75SMichael Corcoran 
429b72d5b75SMichael Corcoran /* Utility routines */
430b72d5b75SMichael Corcoran extern dev_info_t *acpidev_root_node(void);
431b72d5b75SMichael Corcoran extern char *acpidev_get_object_name(ACPI_HANDLE hdl);
432b72d5b75SMichael Corcoran extern void acpidev_free_object_name(char *objname);
433b72d5b75SMichael Corcoran 
434b72d5b75SMichael Corcoran extern acpidev_walk_info_t *acpidev_alloc_walk_info(acpidev_op_type_t op_type,
435b72d5b75SMichael Corcoran     int lvl, ACPI_HANDLE hdl, acpidev_class_list_t **listpp,
436b72d5b75SMichael Corcoran     acpidev_walk_info_t *pinfop);
437b72d5b75SMichael Corcoran extern void acpidev_free_walk_info(acpidev_walk_info_t *infop);
438b72d5b75SMichael Corcoran extern dev_info_t *acpidev_walk_info_get_pdip(acpidev_walk_info_t *infop);
439b72d5b75SMichael Corcoran 
440b72d5b75SMichael Corcoran /* Interfaces to access data associated with ACPI object. */
441b72d5b75SMichael Corcoran extern acpidev_data_handle_t acpidev_data_get_handle(ACPI_HANDLE hdl);
442b72d5b75SMichael Corcoran extern acpidev_data_handle_t acpidev_data_create_handle(ACPI_HANDLE hdl);
443b72d5b75SMichael Corcoran extern void acpidev_data_destroy_handle(ACPI_HANDLE hdl);
444b72d5b75SMichael Corcoran extern ACPI_HANDLE acpidev_data_get_object(acpidev_data_handle_t hdl);
445b72d5b75SMichael Corcoran extern dev_info_t *acpidev_data_get_devinfo(acpidev_data_handle_t hdl);
446b72d5b75SMichael Corcoran extern int acpidev_data_get_status(acpidev_data_handle_t hdl);
447a3114836SGerry Liu extern boolean_t acpidev_data_dr_capable(acpidev_data_handle_t hdl);
448a3114836SGerry Liu extern boolean_t acpidev_data_dr_ready(acpidev_data_handle_t hdl);
449a3114836SGerry Liu extern boolean_t acpidev_data_dr_failed(acpidev_data_handle_t hdl);
450b72d5b75SMichael Corcoran extern void acpidev_data_set_flag(acpidev_data_handle_t hdl, uint32_t flag);
451b72d5b75SMichael Corcoran extern void acpidev_data_clear_flag(acpidev_data_handle_t hdl, uint32_t flag);
452b72d5b75SMichael Corcoran extern uint32_t acpidev_data_get_flag(acpidev_data_handle_t hdl, uint32_t flag);
453b72d5b75SMichael Corcoran 
454a3114836SGerry Liu /* ACPI system event handler has been registered. */
455a3114836SGerry Liu #define	ACPIDEV_DATA_HANDLER_READY	0x1
456a3114836SGerry Liu 
457b72d5b75SMichael Corcoran /*
458b72d5b75SMichael Corcoran  * Try to generate meaningful device unit address from uid.
459b72d5b75SMichael Corcoran  * Return buf on success and NULL on failure.
460b72d5b75SMichael Corcoran  */
461b72d5b75SMichael Corcoran extern char *acpidev_generate_unitaddr(char *uid, char **fmts, size_t nfmt,
462b72d5b75SMichael Corcoran     char *buf, size_t len);
463b72d5b75SMichael Corcoran 
464b72d5b75SMichael Corcoran /*
465b72d5b75SMichael Corcoran  * Set device unit address property if _UID is available or unitaddr is valid.
466b72d5b75SMichael Corcoran  * Return AE_OK on success and error code on failure.
467b72d5b75SMichael Corcoran  * N.B.: it returns AE_OK if _UID is unavailable and unitaddr is NULL.
468b72d5b75SMichael Corcoran  */
469b72d5b75SMichael Corcoran extern ACPI_STATUS acpidev_set_unitaddr(acpidev_walk_info_t *infop,
470b72d5b75SMichael Corcoran     char **fmts, size_t nfmt, char *unitaddr);
471b72d5b75SMichael Corcoran 
472b72d5b75SMichael Corcoran /*
473b72d5b75SMichael Corcoran  * Generate the device 'compatible' property list for a device based on:
474b72d5b75SMichael Corcoran  *	* Device HID if available
475b72d5b75SMichael Corcoran  *	* Device CIDs if available
476b72d5b75SMichael Corcoran  *	* property array passed in
477b72d5b75SMichael Corcoran  * infop:	pointer to walk information structure
478b72d5b75SMichael Corcoran  * compat:	pointer to property array
479b72d5b75SMichael Corcoran  * acount:	entries in property array
480b72d5b75SMichael Corcoran  * Return AE_OK on success and error code on failure.
481b72d5b75SMichael Corcoran  */
482b72d5b75SMichael Corcoran extern ACPI_STATUS acpidev_set_compatible(acpidev_walk_info_t *infop,
483b72d5b75SMichael Corcoran     char **compat, int acount);
484b72d5b75SMichael Corcoran 
485b72d5b75SMichael Corcoran /*
486b72d5b75SMichael Corcoran  * Query ACPI device status.
487b72d5b75SMichael Corcoran  * N.B.: it returns with all status bits set if _STA is not available.
488b72d5b75SMichael Corcoran  */
489b72d5b75SMichael Corcoran extern int acpidev_query_device_status(ACPI_HANDLE hdl);
490b72d5b75SMichael Corcoran 
491b72d5b75SMichael Corcoran /*
492b72d5b75SMichael Corcoran  * Check whether device exists.
493b72d5b75SMichael Corcoran  * Return false if device doesn't exist.
494b72d5b75SMichael Corcoran  */
495b72d5b75SMichael Corcoran extern boolean_t acpidev_check_device_present(int status);
496b72d5b75SMichael Corcoran 
497b72d5b75SMichael Corcoran /*
498b72d5b75SMichael Corcoran  * Check whether device is enabled.
499b72d5b75SMichael Corcoran  * Return false if device doesn't exist or hasn't been enabled.
500b72d5b75SMichael Corcoran  */
501b72d5b75SMichael Corcoran extern boolean_t acpidev_check_device_enabled(int status);
502b72d5b75SMichael Corcoran 
503b72d5b75SMichael Corcoran /*
504b72d5b75SMichael Corcoran  * Match device ids with ACPI object's _HID and _CIDs.
505b72d5b75SMichael Corcoran  * infop: ACPI object information structure
506b72d5b75SMichael Corcoran  * ids: array of ACPI HIDs and CIDs
507b72d5b75SMichael Corcoran  * count: entries in array
508b72d5b75SMichael Corcoran  * Return TRUE if one item matches or num is zero, else FALSE.
509b72d5b75SMichael Corcoran  */
510b72d5b75SMichael Corcoran extern boolean_t acpidev_match_device_id(ACPI_DEVICE_INFO *infop,
511b72d5b75SMichael Corcoran     char **ids, int count);
512b72d5b75SMichael Corcoran 
513b72d5b75SMichael Corcoran /*
514b72d5b75SMichael Corcoran  * Implement almost the same function as AcpiGetDevices() with the following
515b72d5b75SMichael Corcoran  * changes/enhancements:
516b72d5b75SMichael Corcoran  * 1) Support limiting recursive levels.
517b72d5b75SMichael Corcoran  * 2) Support matching multiple ids instead of one.
518b72d5b75SMichael Corcoran  * 3) Report device without ACPI_STA_DEVICE_PRESENT flag which will be ignored
519b72d5b75SMichael Corcoran  *    by AcpiGetDevices().
520b72d5b75SMichael Corcoran  */
521b72d5b75SMichael Corcoran extern ACPI_STATUS acpidev_get_device_by_id(ACPI_HANDLE hdl,
522b72d5b75SMichael Corcoran     char **ids, int count, int maxdepth, boolean_t skip_non_exist,
523b72d5b75SMichael Corcoran     ACPI_WALK_CALLBACK userfunc, void *userarg, void** retval);
524b72d5b75SMichael Corcoran 
525b72d5b75SMichael Corcoran /* Callback for APIC entry walker. */
526b72d5b75SMichael Corcoran typedef ACPI_STATUS (* acpidev_apic_walker_t)(ACPI_SUBTABLE_HEADER *, void *);
527b72d5b75SMichael Corcoran 
528b72d5b75SMichael Corcoran /*
529b72d5b75SMichael Corcoran  * Walk ACPI APIC entries from the first source available in following order:
530b72d5b75SMichael Corcoran  * 1) ACPI buffer passed in if bufp isn't NULL.
531b72d5b75SMichael Corcoran  * 2) Buffer returned by evaluating method if it isn't NULL.
532b72d5b75SMichael Corcoran  * 3) MADT table as last resort.
533b72d5b75SMichael Corcoran  */
534b72d5b75SMichael Corcoran extern ACPI_STATUS acpidev_walk_apic(ACPI_BUFFER *bufp, ACPI_HANDLE hdl,
535b72d5b75SMichael Corcoran     char *method, acpidev_apic_walker_t func, void *context);
536b72d5b75SMichael Corcoran 
537a3114836SGerry Liu /*
538a3114836SGerry Liu  * Evaluate _OST method under object, which is used to support hotplug event.
539a3114836SGerry Liu  * hdl: object handle
540a3114836SGerry Liu  * code: _OST source event code
541a3114836SGerry Liu  * stauts: _OST result status code
542a3114836SGerry Liu  * bufp and len: optional third parameter for _OST.
543a3114836SGerry Liu  */
544a3114836SGerry Liu extern ACPI_STATUS acpidev_eval_ost(ACPI_HANDLE hdl, uint32_t code,
545a3114836SGerry Liu     uint32_t status, char *bufp, size_t len);
546a3114836SGerry Liu 
547a3114836SGerry Liu /*
548a3114836SGerry Liu  * Evaluate _EJ0 method under object.
549a3114836SGerry Liu  */
550a3114836SGerry Liu extern ACPI_STATUS acpidev_eval_ej0(ACPI_HANDLE hdl);
551a3114836SGerry Liu 
552a3114836SGerry Liu /*
553a3114836SGerry Liu  * Evaluate _PXM method under object.
554a3114836SGerry Liu  */
555a3114836SGerry Liu extern ACPI_STATUS acpidev_eval_pxm(ACPI_HANDLE hdl, uint32_t *idp);
556a3114836SGerry Liu 
557b72d5b75SMichael Corcoran #endif	/* _KERNEL */
558b72d5b75SMichael Corcoran 
559b72d5b75SMichael Corcoran #ifdef __cplusplus
560b72d5b75SMichael Corcoran }
561b72d5b75SMichael Corcoran #endif
562b72d5b75SMichael Corcoran 
563b72d5b75SMichael Corcoran #endif	/* _SYS_ACPIDEV_H */
564