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_rsc.h>
34*a3114836SGerry Liu #include <sys/acpidev_dr.h>
35b72d5b75SMichael Corcoran #include <sys/acpidev_impl.h>
36b72d5b75SMichael Corcoran
37b72d5b75SMichael Corcoran static ACPI_STATUS acpidev_memory_probe(acpidev_walk_info_t *infop);
38b72d5b75SMichael Corcoran static acpidev_filter_result_t acpidev_memory_filter(
39b72d5b75SMichael Corcoran acpidev_walk_info_t *infop, char *devname, int maxlen);
40b72d5b75SMichael Corcoran static ACPI_STATUS acpidev_memory_init(acpidev_walk_info_t *infop);
41b72d5b75SMichael Corcoran
42b72d5b75SMichael Corcoran /*
43b72d5b75SMichael Corcoran * Default class driver for ACPI memory objects.
44b72d5b75SMichael Corcoran */
45b72d5b75SMichael Corcoran acpidev_class_t acpidev_class_memory = {
46b72d5b75SMichael Corcoran 0, /* adc_refcnt */
47b72d5b75SMichael Corcoran ACPIDEV_CLASS_REV1, /* adc_version */
48b72d5b75SMichael Corcoran ACPIDEV_CLASS_ID_MEMORY, /* adc_class_id */
49b72d5b75SMichael Corcoran "ACPI memory", /* adc_class_name */
50b72d5b75SMichael Corcoran ACPIDEV_TYPE_MEMORY, /* adc_dev_type */
51b72d5b75SMichael Corcoran NULL, /* adc_private */
52b72d5b75SMichael Corcoran NULL, /* adc_pre_probe */
53b72d5b75SMichael Corcoran NULL, /* adc_post_probe */
54b72d5b75SMichael Corcoran acpidev_memory_probe, /* adc_probe */
55b72d5b75SMichael Corcoran acpidev_memory_filter, /* adc_filter */
56b72d5b75SMichael Corcoran acpidev_memory_init, /* adc_init */
57b72d5b75SMichael Corcoran NULL, /* adc_fini */
58b72d5b75SMichael Corcoran };
59b72d5b75SMichael Corcoran
60b72d5b75SMichael Corcoran /*
61b72d5b75SMichael Corcoran * List of class drivers which will be called in order when handling
62b72d5b75SMichael Corcoran * children of ACPI memory objects.
63b72d5b75SMichael Corcoran */
64b72d5b75SMichael Corcoran acpidev_class_list_t *acpidev_class_list_memory = NULL;
65b72d5b75SMichael Corcoran
66b72d5b75SMichael Corcoran static char *acpidev_memory_device_ids[] = {
67b72d5b75SMichael Corcoran ACPIDEV_HID_MEMORY,
68b72d5b75SMichael Corcoran };
69b72d5b75SMichael Corcoran
70b72d5b75SMichael Corcoran static char *acpidev_memory_uid_formats[] = {
71b72d5b75SMichael Corcoran "MEM%x-%x",
72b72d5b75SMichael Corcoran };
73b72d5b75SMichael Corcoran
74b72d5b75SMichael Corcoran /* Filter rule table for memory objects. */
75b72d5b75SMichael Corcoran static acpidev_filter_rule_t acpidev_memory_filters[] = {
76b72d5b75SMichael Corcoran { /* Ignore all memory objects under the ACPI root object */
77b72d5b75SMichael Corcoran NULL,
78b72d5b75SMichael Corcoran 0,
79b72d5b75SMichael Corcoran ACPIDEV_FILTER_SKIP,
80b72d5b75SMichael Corcoran NULL,
81b72d5b75SMichael Corcoran 1,
82b72d5b75SMichael Corcoran 1,
83b72d5b75SMichael Corcoran NULL,
84b72d5b75SMichael Corcoran NULL,
85b72d5b75SMichael Corcoran },
86b72d5b75SMichael Corcoran { /* Create node and scan child for all other memory objects */
87b72d5b75SMichael Corcoran NULL,
88b72d5b75SMichael Corcoran 0,
89b72d5b75SMichael Corcoran ACPIDEV_FILTER_DEFAULT,
90b72d5b75SMichael Corcoran &acpidev_class_list_device,
91b72d5b75SMichael Corcoran 2,
92b72d5b75SMichael Corcoran INT_MAX,
93b72d5b75SMichael Corcoran NULL,
94b72d5b75SMichael Corcoran ACPIDEV_NODE_NAME_MEMORY,
95b72d5b75SMichael Corcoran }
96b72d5b75SMichael Corcoran };
97b72d5b75SMichael Corcoran
98b72d5b75SMichael Corcoran static ACPI_STATUS
acpidev_memory_probe(acpidev_walk_info_t * infop)99b72d5b75SMichael Corcoran acpidev_memory_probe(acpidev_walk_info_t *infop)
100b72d5b75SMichael Corcoran {
101*a3114836SGerry Liu ACPI_STATUS rc = AE_OK;
102b72d5b75SMichael Corcoran int flags;
103b72d5b75SMichael Corcoran
104b72d5b75SMichael Corcoran ASSERT(infop != NULL);
105b72d5b75SMichael Corcoran ASSERT(infop->awi_hdl != NULL);
106b72d5b75SMichael Corcoran ASSERT(infop->awi_info != NULL);
107b72d5b75SMichael Corcoran if (infop->awi_info->Type != ACPI_TYPE_DEVICE ||
108b72d5b75SMichael Corcoran acpidev_match_device_id(infop->awi_info,
109b72d5b75SMichael Corcoran ACPIDEV_ARRAY_PARAM(acpidev_memory_device_ids)) == 0) {
110b72d5b75SMichael Corcoran return (AE_OK);
111b72d5b75SMichael Corcoran }
112b72d5b75SMichael Corcoran
113*a3114836SGerry Liu flags = ACPIDEV_PROCESS_FLAG_SCAN;
114*a3114836SGerry Liu switch (infop->awi_op_type) {
115*a3114836SGerry Liu case ACPIDEV_OP_BOOT_PROBE:
116*a3114836SGerry Liu if (acpica_get_devcfg_feature(ACPI_DEVCFG_MEMORY)) {
117*a3114836SGerry Liu flags |= ACPIDEV_PROCESS_FLAG_CREATE;
118*a3114836SGerry Liu acpidev_dr_check(infop);
119*a3114836SGerry Liu }
120*a3114836SGerry Liu break;
121*a3114836SGerry Liu
122*a3114836SGerry Liu case ACPIDEV_OP_BOOT_REPROBE:
123*a3114836SGerry Liu break;
124*a3114836SGerry Liu
125*a3114836SGerry Liu case ACPIDEV_OP_HOTPLUG_PROBE:
126*a3114836SGerry Liu if (acpica_get_devcfg_feature(ACPI_DEVCFG_MEMORY)) {
127*a3114836SGerry Liu flags |= ACPIDEV_PROCESS_FLAG_CREATE |
128*a3114836SGerry Liu ACPIDEV_PROCESS_FLAG_SYNCSTATUS |
129*a3114836SGerry Liu ACPIDEV_PROCESS_FLAG_HOLDBRANCH;
130*a3114836SGerry Liu }
131*a3114836SGerry Liu break;
132*a3114836SGerry Liu
133*a3114836SGerry Liu default:
134*a3114836SGerry Liu ACPIDEV_DEBUG(CE_WARN, "!acpidev: unknown operation type %u "
135b72d5b75SMichael Corcoran "in acpidev_memory_probe.", infop->awi_op_type);
136b72d5b75SMichael Corcoran rc = AE_BAD_PARAMETER;
137*a3114836SGerry Liu break;
138*a3114836SGerry Liu }
139*a3114836SGerry Liu
140*a3114836SGerry Liu if (rc == AE_OK) {
141*a3114836SGerry Liu rc = acpidev_process_object(infop, flags);
142b72d5b75SMichael Corcoran }
143b72d5b75SMichael Corcoran if (ACPI_FAILURE(rc) && rc != AE_NOT_EXIST && rc != AE_ALREADY_EXISTS) {
144b72d5b75SMichael Corcoran cmn_err(CE_WARN,
145b72d5b75SMichael Corcoran "!acpidev: failed to process memory object %s.",
146b72d5b75SMichael Corcoran infop->awi_name);
147b72d5b75SMichael Corcoran } else {
148b72d5b75SMichael Corcoran rc = AE_OK;
149b72d5b75SMichael Corcoran }
150b72d5b75SMichael Corcoran
151b72d5b75SMichael Corcoran return (rc);
152b72d5b75SMichael Corcoran }
153b72d5b75SMichael Corcoran
154b72d5b75SMichael Corcoran static acpidev_filter_result_t
acpidev_memory_filter(acpidev_walk_info_t * infop,char * devname,int maxlen)155b72d5b75SMichael Corcoran acpidev_memory_filter(acpidev_walk_info_t *infop, char *devname, int maxlen)
156b72d5b75SMichael Corcoran {
157b72d5b75SMichael Corcoran acpidev_filter_result_t res;
158b72d5b75SMichael Corcoran
159b72d5b75SMichael Corcoran ASSERT(infop != NULL);
160b72d5b75SMichael Corcoran if (infop->awi_op_type == ACPIDEV_OP_BOOT_PROBE ||
161b72d5b75SMichael Corcoran infop->awi_op_type == ACPIDEV_OP_BOOT_REPROBE ||
162b72d5b75SMichael Corcoran infop->awi_op_type == ACPIDEV_OP_HOTPLUG_PROBE) {
163b72d5b75SMichael Corcoran res = acpidev_filter_device(infop, infop->awi_hdl,
164b72d5b75SMichael Corcoran ACPIDEV_ARRAY_PARAM(acpidev_memory_filters),
165b72d5b75SMichael Corcoran devname, maxlen);
166b72d5b75SMichael Corcoran } else {
167b72d5b75SMichael Corcoran res = ACPIDEV_FILTER_FAILED;
168b72d5b75SMichael Corcoran }
169b72d5b75SMichael Corcoran
170b72d5b75SMichael Corcoran return (res);
171b72d5b75SMichael Corcoran }
172b72d5b75SMichael Corcoran
173b72d5b75SMichael Corcoran static ACPI_STATUS
acpidev_memory_init(acpidev_walk_info_t * infop)174b72d5b75SMichael Corcoran acpidev_memory_init(acpidev_walk_info_t *infop)
175b72d5b75SMichael Corcoran {
176b72d5b75SMichael Corcoran char *compatible[] = {
177b72d5b75SMichael Corcoran ACPIDEV_TYPE_MEMORY,
178b72d5b75SMichael Corcoran "mem"
179b72d5b75SMichael Corcoran };
180b72d5b75SMichael Corcoran
181b72d5b75SMichael Corcoran ASSERT(infop != NULL);
182b72d5b75SMichael Corcoran ASSERT(infop->awi_hdl != NULL);
183b72d5b75SMichael Corcoran ASSERT(infop->awi_dip != NULL);
184b72d5b75SMichael Corcoran if (ACPI_FAILURE(acpidev_resource_process(infop, B_TRUE))) {
185b72d5b75SMichael Corcoran cmn_err(CE_WARN, "!acpidev: failed to process resources of "
186b72d5b75SMichael Corcoran "memory device %s.", infop->awi_name);
187b72d5b75SMichael Corcoran return (AE_ERROR);
188b72d5b75SMichael Corcoran }
189b72d5b75SMichael Corcoran
190b72d5b75SMichael Corcoran if (ACPI_FAILURE(acpidev_set_compatible(infop,
191b72d5b75SMichael Corcoran ACPIDEV_ARRAY_PARAM(compatible)))) {
192b72d5b75SMichael Corcoran return (AE_ERROR);
193b72d5b75SMichael Corcoran }
194b72d5b75SMichael Corcoran
195b72d5b75SMichael Corcoran if (ACPI_FAILURE(acpidev_set_unitaddr(infop,
196b72d5b75SMichael Corcoran ACPIDEV_ARRAY_PARAM(acpidev_memory_uid_formats), NULL))) {
197b72d5b75SMichael Corcoran return (AE_ERROR);
198b72d5b75SMichael Corcoran }
199b72d5b75SMichael Corcoran
200b72d5b75SMichael Corcoran return (AE_OK);
201b72d5b75SMichael Corcoran }
202