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 /*
22*a3114836SGerry Liu  * Copyright (c) 2009-2010, Intel Corporation.
23b72d5b75SMichael Corcoran  * All rights reserved.
24b72d5b75SMichael Corcoran  */
25b72d5b75SMichael Corcoran 
26b72d5b75SMichael Corcoran #include <sys/types.h>
27b72d5b75SMichael Corcoran #include <sys/atomic.h>
28b72d5b75SMichael Corcoran #include <sys/sunddi.h>
29b72d5b75SMichael Corcoran #include <sys/sunndi.h>
30b72d5b75SMichael Corcoran #include <sys/acpi/acpi.h>
31b72d5b75SMichael Corcoran #include <sys/acpica.h>
32b72d5b75SMichael Corcoran #include <sys/acpidev.h>
33b72d5b75SMichael Corcoran #include <sys/acpidev_impl.h>
34b72d5b75SMichael Corcoran 
35b72d5b75SMichael Corcoran static ACPI_STATUS acpidev_scope_probe(acpidev_walk_info_t *infop);
36b72d5b75SMichael Corcoran static acpidev_filter_result_t acpidev_scope_filter(acpidev_walk_info_t *infop,
37b72d5b75SMichael Corcoran     char *devname, int maxlen);
38b72d5b75SMichael Corcoran static ACPI_STATUS acpidev_scope_init(acpidev_walk_info_t *infop);
39b72d5b75SMichael Corcoran 
40b72d5b75SMichael Corcoran /*
41b72d5b75SMichael Corcoran  * Default class driver for ACPI scope objects.
42b72d5b75SMichael Corcoran  * This class driver is used to handle predefined ACPI SCOPE objects
43b72d5b75SMichael Corcoran  * under the ACPI root object, such as _PR_, _SB_ and _TZ_ etc.
44b72d5b75SMichael Corcoran  * The default policy for ACPI SCOPE objects is SKIP.
45b72d5b75SMichael Corcoran  */
46b72d5b75SMichael Corcoran acpidev_class_t acpidev_class_scope = {
47b72d5b75SMichael Corcoran 	0,				/* adc_refcnt */
48b72d5b75SMichael Corcoran 	ACPIDEV_CLASS_REV1,		/* adc_version */
49b72d5b75SMichael Corcoran 	ACPIDEV_CLASS_ID_SCOPE,		/* adc_class_id */
50b72d5b75SMichael Corcoran 	"ACPI Scope",			/* adc_class_name */
51b72d5b75SMichael Corcoran 	ACPIDEV_TYPE_SCOPE,		/* adc_dev_type */
52b72d5b75SMichael Corcoran 	NULL,				/* adc_private */
53b72d5b75SMichael Corcoran 	NULL,				/* adc_pre_probe */
54b72d5b75SMichael Corcoran 	NULL,				/* adc_post_probe */
55b72d5b75SMichael Corcoran 	acpidev_scope_probe,		/* adc_probe */
56b72d5b75SMichael Corcoran 	acpidev_scope_filter,		/* adc_filter */
57b72d5b75SMichael Corcoran 	acpidev_scope_init,		/* adc_init */
58b72d5b75SMichael Corcoran 	NULL,				/* adc_fini */
59b72d5b75SMichael Corcoran };
60b72d5b75SMichael Corcoran 
61b72d5b75SMichael Corcoran acpidev_class_list_t *acpidev_class_list_scope = NULL;
62b72d5b75SMichael Corcoran 
63b72d5b75SMichael Corcoran /*
64b72d5b75SMichael Corcoran  * All SCOPE objects share a global pseudo unit address space across the system.
65b72d5b75SMichael Corcoran  */
66b72d5b75SMichael Corcoran static uint32_t acpidev_scope_unitaddr = 0;
67b72d5b75SMichael Corcoran 
68b72d5b75SMichael Corcoran /* Filter rule table for ACPI SCOPE objects. */
69b72d5b75SMichael Corcoran static acpidev_filter_rule_t acpidev_scope_filters[] = {
70b72d5b75SMichael Corcoran 	{	/* For safety, _SB_ is hardcoded as DEVICE by acpica */
71b72d5b75SMichael Corcoran 		NULL,
72b72d5b75SMichael Corcoran 		0,
73b72d5b75SMichael Corcoran 		ACPIDEV_FILTER_DEFAULT,
74b72d5b75SMichael Corcoran 		&acpidev_class_list_device,
75b72d5b75SMichael Corcoran 		1,
76b72d5b75SMichael Corcoran 		1,
77b72d5b75SMichael Corcoran 		ACPIDEV_OBJECT_NAME_SB,
78b72d5b75SMichael Corcoran 		ACPIDEV_NODE_NAME_MODULE_SBD,
79b72d5b75SMichael Corcoran 	},
80b72d5b75SMichael Corcoran 	{	/* Handle _PR_ object. */
81b72d5b75SMichael Corcoran 		NULL,
82b72d5b75SMichael Corcoran 		0,
83b72d5b75SMichael Corcoran 		ACPIDEV_FILTER_SCAN,
84b72d5b75SMichael Corcoran 		&acpidev_class_list_scope,
85b72d5b75SMichael Corcoran 		1,
86b72d5b75SMichael Corcoran 		1,
87b72d5b75SMichael Corcoran 		ACPIDEV_OBJECT_NAME_PR,
88b72d5b75SMichael Corcoran 		ACPIDEV_NODE_NAME_PROCESSOR,
89b72d5b75SMichael Corcoran 	},
90b72d5b75SMichael Corcoran 	{	/* Ignore all other scope objects. */
91b72d5b75SMichael Corcoran 		NULL,
92b72d5b75SMichael Corcoran 		0,
93b72d5b75SMichael Corcoran 		ACPIDEV_FILTER_SKIP,
94b72d5b75SMichael Corcoran 		NULL,
95b72d5b75SMichael Corcoran 		1,
96b72d5b75SMichael Corcoran 		INT_MAX,
97b72d5b75SMichael Corcoran 		NULL,
98b72d5b75SMichael Corcoran 		NULL,
99b72d5b75SMichael Corcoran 	}
100b72d5b75SMichael Corcoran };
101b72d5b75SMichael Corcoran 
102b72d5b75SMichael Corcoran static ACPI_STATUS
acpidev_scope_probe(acpidev_walk_info_t * infop)103b72d5b75SMichael Corcoran acpidev_scope_probe(acpidev_walk_info_t *infop)
104b72d5b75SMichael Corcoran {
105*a3114836SGerry Liu 	ACPI_STATUS rc = AE_OK;
106b72d5b75SMichael Corcoran 	int flags;
107b72d5b75SMichael Corcoran 
108b72d5b75SMichael Corcoran 	ASSERT(infop != NULL);
109b72d5b75SMichael Corcoran 	ASSERT(infop->awi_hdl != NULL);
110b72d5b75SMichael Corcoran 	ASSERT(infop->awi_info != NULL);
111b72d5b75SMichael Corcoran 	if (infop->awi_info->Type != ACPI_TYPE_LOCAL_SCOPE) {
112b72d5b75SMichael Corcoran 		return (AE_OK);
113b72d5b75SMichael Corcoran 	}
114b72d5b75SMichael Corcoran 
115b72d5b75SMichael Corcoran 	flags = ACPIDEV_PROCESS_FLAG_SCAN;
116*a3114836SGerry Liu 	switch (infop->awi_op_type) {
117*a3114836SGerry Liu 	case ACPIDEV_OP_BOOT_PROBE:
118*a3114836SGerry Liu 		flags |= ACPIDEV_PROCESS_FLAG_CREATE;
119*a3114836SGerry Liu 		break;
120*a3114836SGerry Liu 
121*a3114836SGerry Liu 	case ACPIDEV_OP_BOOT_REPROBE:
122*a3114836SGerry Liu 		break;
123*a3114836SGerry Liu 
124*a3114836SGerry Liu 	case ACPIDEV_OP_HOTPLUG_PROBE:
125*a3114836SGerry Liu 		flags |= ACPIDEV_PROCESS_FLAG_SYNCSTATUS |
126*a3114836SGerry Liu 		    ACPIDEV_PROCESS_FLAG_HOLDBRANCH;
127*a3114836SGerry Liu 		break;
128*a3114836SGerry Liu 
129*a3114836SGerry Liu 	default:
130*a3114836SGerry Liu 		ACPIDEV_DEBUG(CE_WARN, "!acpidev: unknown operation type %u "
131b72d5b75SMichael Corcoran 		    "in acpidev_scope_probe().", infop->awi_op_type);
132b72d5b75SMichael Corcoran 		rc = AE_BAD_PARAMETER;
133*a3114836SGerry Liu 		break;
134*a3114836SGerry Liu 	}
135*a3114836SGerry Liu 
136*a3114836SGerry Liu 	if (rc == AE_OK) {
137*a3114836SGerry Liu 		rc = acpidev_process_object(infop, flags);
138b72d5b75SMichael Corcoran 	}
139b72d5b75SMichael Corcoran 	if (ACPI_FAILURE(rc) && rc != AE_NOT_EXIST && rc != AE_ALREADY_EXISTS) {
140b72d5b75SMichael Corcoran 		cmn_err(CE_WARN,
141b72d5b75SMichael Corcoran 		    "!acpidev: failed to process scope object %s.",
142b72d5b75SMichael Corcoran 		    infop->awi_name);
143b72d5b75SMichael Corcoran 	} else {
144b72d5b75SMichael Corcoran 		rc = AE_OK;
145b72d5b75SMichael Corcoran 	}
146b72d5b75SMichael Corcoran 
147b72d5b75SMichael Corcoran 	return (rc);
148b72d5b75SMichael Corcoran }
149b72d5b75SMichael Corcoran 
150b72d5b75SMichael Corcoran static acpidev_filter_result_t
acpidev_scope_filter(acpidev_walk_info_t * infop,char * devname,int maxlen)151b72d5b75SMichael Corcoran acpidev_scope_filter(acpidev_walk_info_t *infop, char *devname, int maxlen)
152b72d5b75SMichael Corcoran {
153b72d5b75SMichael Corcoran 	acpidev_filter_result_t res;
154b72d5b75SMichael Corcoran 
155b72d5b75SMichael Corcoran 	ASSERT(infop != NULL);
156b72d5b75SMichael Corcoran 	if (infop->awi_op_type == ACPIDEV_OP_BOOT_PROBE ||
157b72d5b75SMichael Corcoran 	    infop->awi_op_type == ACPIDEV_OP_BOOT_REPROBE ||
158b72d5b75SMichael Corcoran 	    infop->awi_op_type == ACPIDEV_OP_HOTPLUG_PROBE) {
159b72d5b75SMichael Corcoran 		res = acpidev_filter_device(infop, infop->awi_hdl,
160b72d5b75SMichael Corcoran 		    ACPIDEV_ARRAY_PARAM(acpidev_scope_filters),
161b72d5b75SMichael Corcoran 		    devname, maxlen);
162b72d5b75SMichael Corcoran 	} else {
163*a3114836SGerry Liu 		ACPIDEV_DEBUG(CE_WARN, "!acpidev: unknown operation type %u "
164b72d5b75SMichael Corcoran 		    "in acpidev_scope_filter().", infop->awi_op_type);
165b72d5b75SMichael Corcoran 		res = ACPIDEV_FILTER_FAILED;
166b72d5b75SMichael Corcoran 	}
167b72d5b75SMichael Corcoran 
168b72d5b75SMichael Corcoran 	return (res);
169b72d5b75SMichael Corcoran }
170b72d5b75SMichael Corcoran 
171b72d5b75SMichael Corcoran static ACPI_STATUS
acpidev_scope_init(acpidev_walk_info_t * infop)172b72d5b75SMichael Corcoran acpidev_scope_init(acpidev_walk_info_t *infop)
173b72d5b75SMichael Corcoran {
174b72d5b75SMichael Corcoran 	char unitaddr[32];
175b72d5b75SMichael Corcoran 	char *compatible[] = {
176b72d5b75SMichael Corcoran 		ACPIDEV_HID_SCOPE,
177b72d5b75SMichael Corcoran 		ACPIDEV_TYPE_SCOPE,
178b72d5b75SMichael Corcoran 		ACPIDEV_HID_VIRTNEX,
179b72d5b75SMichael Corcoran 		ACPIDEV_TYPE_VIRTNEX,
180b72d5b75SMichael Corcoran 	};
181b72d5b75SMichael Corcoran 
182b72d5b75SMichael Corcoran 	ASSERT(infop != NULL);
183b72d5b75SMichael Corcoran 	ASSERT(infop->awi_hdl != NULL);
184b72d5b75SMichael Corcoran 	ASSERT(infop->awi_dip != NULL);
185b72d5b75SMichael Corcoran 	if (ACPI_FAILURE(acpidev_set_compatible(infop,
186b72d5b75SMichael Corcoran 	    ACPIDEV_ARRAY_PARAM(compatible)))) {
187b72d5b75SMichael Corcoran 		return (AE_ERROR);
188b72d5b75SMichael Corcoran 	}
189b72d5b75SMichael Corcoran 	(void) snprintf(unitaddr, sizeof (unitaddr), "%u",
190b72d5b75SMichael Corcoran 	    atomic_inc_32_nv(&acpidev_scope_unitaddr) - 1);
191b72d5b75SMichael Corcoran 	if (ACPI_FAILURE(acpidev_set_unitaddr(infop, NULL, 0, unitaddr))) {
192b72d5b75SMichael Corcoran 		return (AE_ERROR);
193b72d5b75SMichael Corcoran 	}
194b72d5b75SMichael Corcoran 
195b72d5b75SMichael Corcoran 	return (AE_OK);
196b72d5b75SMichael Corcoran }
197