]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /****************************************************************************** |
2 | * | |
42f8fb75 | 3 | * Module Name: evregion - Operation Region support |
1da177e4 LT |
4 | * |
5 | *****************************************************************************/ | |
6 | ||
7 | /* | |
7735ca0e | 8 | * Copyright (C) 2000 - 2017, Intel Corp. |
1da177e4 LT |
9 | * All rights reserved. |
10 | * | |
11 | * Redistribution and use in source and binary forms, with or without | |
12 | * modification, are permitted provided that the following conditions | |
13 | * are met: | |
14 | * 1. Redistributions of source code must retain the above copyright | |
15 | * notice, this list of conditions, and the following disclaimer, | |
16 | * without modification. | |
17 | * 2. Redistributions in binary form must reproduce at minimum a disclaimer | |
18 | * substantially similar to the "NO WARRANTY" disclaimer below | |
19 | * ("Disclaimer") and any redistribution must be conditioned upon | |
20 | * including a substantially similar Disclaimer requirement for further | |
21 | * binary redistribution. | |
22 | * 3. Neither the names of the above-listed copyright holders nor the names | |
23 | * of any contributors may be used to endorse or promote products derived | |
24 | * from this software without specific prior written permission. | |
25 | * | |
26 | * Alternatively, this software may be distributed under the terms of the | |
27 | * GNU General Public License ("GPL") version 2 as published by the Free | |
28 | * Software Foundation. | |
29 | * | |
30 | * NO WARRANTY | |
31 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
32 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
33 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR | |
34 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
35 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
36 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
37 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
38 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | |
39 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | |
40 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
41 | * POSSIBILITY OF SUCH DAMAGES. | |
42 | */ | |
43 | ||
1da177e4 | 44 | #include <acpi/acpi.h> |
e2f7a777 LB |
45 | #include "accommon.h" |
46 | #include "acevents.h" | |
47 | #include "acnamesp.h" | |
48 | #include "acinterp.h" | |
1da177e4 LT |
49 | |
50 | #define _COMPONENT ACPI_EVENTS | |
4be44fcd | 51 | ACPI_MODULE_NAME("evregion") |
1da177e4 | 52 | |
42f8fb75 BM |
53 | extern u8 acpi_gbl_default_address_spaces[]; |
54 | ||
44f6c012 | 55 | /* Local prototypes */ |
74d3ec77 | 56 | |
8f4f5e78 ZR |
57 | static void |
58 | acpi_ev_orphan_ec_reg_method(struct acpi_namespace_node *ec_device_node); | |
e2066ca1 | 59 | |
44f6c012 | 60 | static acpi_status |
4be44fcd LB |
61 | acpi_ev_reg_run(acpi_handle obj_handle, |
62 | u32 level, void *context, void **return_value); | |
44f6c012 | 63 | |
1da177e4 LT |
64 | /******************************************************************************* |
65 | * | |
66 | * FUNCTION: acpi_ev_initialize_op_regions | |
67 | * | |
68 | * PARAMETERS: None | |
69 | * | |
70 | * RETURN: Status | |
71 | * | |
72 | * DESCRIPTION: Execute _REG methods for all Operation Regions that have | |
73 | * an installed default region handler. | |
74 | * | |
75 | ******************************************************************************/ | |
76 | ||
4be44fcd | 77 | acpi_status acpi_ev_initialize_op_regions(void) |
1da177e4 | 78 | { |
4be44fcd | 79 | acpi_status status; |
67a119f9 | 80 | u32 i; |
1da177e4 | 81 | |
b229cf92 | 82 | ACPI_FUNCTION_TRACE(ev_initialize_op_regions); |
1da177e4 | 83 | |
4be44fcd LB |
84 | status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); |
85 | if (ACPI_FAILURE(status)) { | |
86 | return_ACPI_STATUS(status); | |
1da177e4 LT |
87 | } |
88 | ||
9f15fc66 | 89 | /* Run the _REG methods for op_regions in each default address space */ |
52fc0b02 | 90 | |
9f15fc66 BM |
91 | for (i = 0; i < ACPI_NUM_DEFAULT_SPACES; i++) { |
92 | /* | |
74d3ec77 LM |
93 | * Make sure the installed handler is the DEFAULT handler. If not the |
94 | * default, the _REG methods will have already been run (when the | |
95 | * handler was installed) | |
1da177e4 | 96 | */ |
74d3ec77 LM |
97 | if (acpi_ev_has_default_handler(acpi_gbl_root_node, |
98 | acpi_gbl_default_address_spaces | |
99 | [i])) { | |
d815346f LZ |
100 | acpi_ev_execute_reg_methods(acpi_gbl_root_node, |
101 | acpi_gbl_default_address_spaces | |
102 | [i], ACPI_REG_CONNECT); | |
74d3ec77 | 103 | } |
1da177e4 LT |
104 | } |
105 | ||
4be44fcd LB |
106 | (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); |
107 | return_ACPI_STATUS(status); | |
1da177e4 LT |
108 | } |
109 | ||
1da177e4 LT |
110 | /******************************************************************************* |
111 | * | |
112 | * FUNCTION: acpi_ev_address_space_dispatch | |
113 | * | |
114 | * PARAMETERS: region_obj - Internal region object | |
9ce81784 | 115 | * field_obj - Corresponding field. Can be NULL. |
ba494bee | 116 | * function - Read or Write operation |
f5407af3 | 117 | * region_offset - Where in the region to read or write |
1da177e4 | 118 | * bit_width - Field width in bits (8, 16, 32, or 64) |
ba494bee | 119 | * value - Pointer to in or out value, must be |
5df7e6cb | 120 | * a full 64-bit integer |
1da177e4 LT |
121 | * |
122 | * RETURN: Status | |
123 | * | |
124 | * DESCRIPTION: Dispatch an address space or operation region access to | |
125 | * a previously installed handler. | |
126 | * | |
7b738064 BM |
127 | * NOTE: During early initialization, we always install the default region |
128 | * handlers for Memory, I/O and PCI_Config. This ensures that these operation | |
129 | * region address spaces are always available as per the ACPI specification. | |
130 | * This is especially needed in order to support the execution of | |
131 | * module-level AML code during loading of the ACPI tables. | |
132 | * | |
1da177e4 LT |
133 | ******************************************************************************/ |
134 | ||
135 | acpi_status | |
4be44fcd | 136 | acpi_ev_address_space_dispatch(union acpi_operand_object *region_obj, |
9ce81784 | 137 | union acpi_operand_object *field_obj, |
4be44fcd | 138 | u32 function, |
5df7e6cb | 139 | u32 region_offset, u32 bit_width, u64 *value) |
1da177e4 | 140 | { |
4be44fcd | 141 | acpi_status status; |
4be44fcd LB |
142 | acpi_adr_space_handler handler; |
143 | acpi_adr_space_setup region_setup; | |
144 | union acpi_operand_object *handler_desc; | |
145 | union acpi_operand_object *region_obj2; | |
146 | void *region_context = NULL; | |
9ce81784 | 147 | struct acpi_connection_info *context; |
75ec6e55 | 148 | acpi_physical_address address; |
1da177e4 | 149 | |
b229cf92 | 150 | ACPI_FUNCTION_TRACE(ev_address_space_dispatch); |
1da177e4 | 151 | |
4be44fcd | 152 | region_obj2 = acpi_ns_get_secondary_object(region_obj); |
1da177e4 | 153 | if (!region_obj2) { |
4be44fcd | 154 | return_ACPI_STATUS(AE_NOT_EXIST); |
1da177e4 LT |
155 | } |
156 | ||
157 | /* Ensure that there is a handler associated with this region */ | |
158 | ||
159 | handler_desc = region_obj->region.handler; | |
160 | if (!handler_desc) { | |
b8e4d893 BM |
161 | ACPI_ERROR((AE_INFO, |
162 | "No handler for Region [%4.4s] (%p) [%s]", | |
163 | acpi_ut_get_node_name(region_obj->region.node), | |
164 | region_obj, | |
165 | acpi_ut_get_region_name(region_obj->region. | |
166 | space_id))); | |
4be44fcd LB |
167 | |
168 | return_ACPI_STATUS(AE_NOT_EXIST); | |
1da177e4 LT |
169 | } |
170 | ||
9ce81784 BM |
171 | context = handler_desc->address_space.context; |
172 | ||
1da177e4 | 173 | /* |
9f15fc66 | 174 | * It may be the case that the region has never been initialized. |
1da177e4 LT |
175 | * Some types of regions require special init code |
176 | */ | |
177 | if (!(region_obj->region.flags & AOPOBJ_SETUP_COMPLETE)) { | |
9f15fc66 BM |
178 | |
179 | /* This region has not been initialized yet, do it */ | |
180 | ||
1da177e4 LT |
181 | region_setup = handler_desc->address_space.setup; |
182 | if (!region_setup) { | |
52fc0b02 | 183 | |
1da177e4 LT |
184 | /* No initialization routine, exit with error */ |
185 | ||
b8e4d893 BM |
186 | ACPI_ERROR((AE_INFO, |
187 | "No init routine for region(%p) [%s]", | |
188 | region_obj, | |
189 | acpi_ut_get_region_name(region_obj->region. | |
190 | space_id))); | |
4be44fcd | 191 | return_ACPI_STATUS(AE_NOT_EXIST); |
1da177e4 LT |
192 | } |
193 | ||
194 | /* | |
9f15fc66 BM |
195 | * We must exit the interpreter because the region setup will |
196 | * potentially execute control methods (for example, the _REG method | |
197 | * for this region) | |
1da177e4 | 198 | */ |
014d433f | 199 | acpi_ex_exit_interpreter(); |
1da177e4 | 200 | |
4be44fcd | 201 | status = region_setup(region_obj, ACPI_REGION_ACTIVATE, |
9ce81784 | 202 | context, ®ion_context); |
1da177e4 LT |
203 | |
204 | /* Re-enter the interpreter */ | |
205 | ||
014d433f | 206 | acpi_ex_enter_interpreter(); |
1da177e4 LT |
207 | |
208 | /* Check for failure of the Region Setup */ | |
209 | ||
4be44fcd | 210 | if (ACPI_FAILURE(status)) { |
b8e4d893 BM |
211 | ACPI_EXCEPTION((AE_INFO, status, |
212 | "During region initialization: [%s]", | |
213 | acpi_ut_get_region_name(region_obj-> | |
214 | region. | |
215 | space_id))); | |
4be44fcd | 216 | return_ACPI_STATUS(status); |
1da177e4 LT |
217 | } |
218 | ||
9f15fc66 BM |
219 | /* Region initialization may have been completed by region_setup */ |
220 | ||
1da177e4 LT |
221 | if (!(region_obj->region.flags & AOPOBJ_SETUP_COMPLETE)) { |
222 | region_obj->region.flags |= AOPOBJ_SETUP_COMPLETE; | |
223 | ||
d2e7d079 DB |
224 | /* |
225 | * Save the returned context for use in all accesses to | |
226 | * the handler for this particular region | |
227 | */ | |
228 | if (!(region_obj2->extra.region_context)) { | |
4be44fcd LB |
229 | region_obj2->extra.region_context = |
230 | region_context; | |
1da177e4 LT |
231 | } |
232 | } | |
233 | } | |
234 | ||
235 | /* We have everything we need, we can invoke the address space handler */ | |
236 | ||
237 | handler = handler_desc->address_space.handler; | |
75ec6e55 | 238 | address = (region_obj->region.address + region_offset); |
1da177e4 | 239 | |
9ce81784 BM |
240 | /* |
241 | * Special handling for generic_serial_bus and general_purpose_io: | |
242 | * There are three extra parameters that must be passed to the | |
243 | * handler via the context: | |
75ec6e55 BM |
244 | * 1) Connection buffer, a resource template from Connection() op |
245 | * 2) Length of the above buffer | |
246 | * 3) Actual access length from the access_as() op | |
247 | * | |
248 | * In addition, for general_purpose_io, the Address and bit_width fields | |
249 | * are defined as follows: | |
250 | * 1) Address is the pin number index of the field (bit offset from | |
251 | * the previous Connection) | |
252 | * 2) bit_width is the actual bit length of the field (number of pins) | |
9ce81784 | 253 | */ |
75ec6e55 BM |
254 | if ((region_obj->region.space_id == ACPI_ADR_SPACE_GSBUS) && |
255 | context && field_obj) { | |
256 | ||
257 | /* Get the Connection (resource_template) buffer */ | |
258 | ||
259 | context->connection = field_obj->field.resource_buffer; | |
260 | context->length = field_obj->field.resource_length; | |
261 | context->access_length = field_obj->field.access_length; | |
262 | } | |
263 | if ((region_obj->region.space_id == ACPI_ADR_SPACE_GPIO) && | |
9ce81784 BM |
264 | context && field_obj) { |
265 | ||
266 | /* Get the Connection (resource_template) buffer */ | |
267 | ||
268 | context->connection = field_obj->field.resource_buffer; | |
269 | context->length = field_obj->field.resource_length; | |
270 | context->access_length = field_obj->field.access_length; | |
75ec6e55 BM |
271 | address = field_obj->field.pin_number_index; |
272 | bit_width = field_obj->field.bit_length; | |
9ce81784 BM |
273 | } |
274 | ||
75ec6e55 BM |
275 | ACPI_DEBUG_PRINT((ACPI_DB_OPREGION, |
276 | "Handler %p (@%p) Address %8.8X%8.8X [%s]\n", | |
277 | ®ion_obj->region.handler->address_space, handler, | |
1d0a0b2f | 278 | ACPI_FORMAT_UINT64(address), |
75ec6e55 BM |
279 | acpi_ut_get_region_name(region_obj->region. |
280 | space_id))); | |
281 | ||
61686124 BM |
282 | if (!(handler_desc->address_space.handler_flags & |
283 | ACPI_ADDR_HANDLER_DEFAULT_INSTALLED)) { | |
1da177e4 LT |
284 | /* |
285 | * For handlers other than the default (supplied) handlers, we must | |
286 | * exit the interpreter because the handler *might* block -- we don't | |
287 | * know what it will do, so we can't hold the lock on the intepreter. | |
288 | */ | |
014d433f | 289 | acpi_ex_exit_interpreter(); |
1da177e4 LT |
290 | } |
291 | ||
292 | /* Call the handler */ | |
293 | ||
75ec6e55 | 294 | status = handler(function, address, bit_width, value, context, |
1da177e4 LT |
295 | region_obj2->extra.region_context); |
296 | ||
4be44fcd | 297 | if (ACPI_FAILURE(status)) { |
b8e4d893 BM |
298 | ACPI_EXCEPTION((AE_INFO, status, "Returned by Handler for [%s]", |
299 | acpi_ut_get_region_name(region_obj->region. | |
300 | space_id))); | |
53ae81e1 BM |
301 | |
302 | /* | |
303 | * Special case for an EC timeout. These are seen so frequently | |
304 | * that an additional error message is helpful | |
305 | */ | |
306 | if ((region_obj->region.space_id == ACPI_ADR_SPACE_EC) && | |
307 | (status == AE_TIME)) { | |
308 | ACPI_ERROR((AE_INFO, | |
309 | "Timeout from EC hardware or EC device driver")); | |
310 | } | |
1da177e4 LT |
311 | } |
312 | ||
61686124 BM |
313 | if (!(handler_desc->address_space.handler_flags & |
314 | ACPI_ADDR_HANDLER_DEFAULT_INSTALLED)) { | |
1da177e4 LT |
315 | /* |
316 | * We just returned from a non-default handler, we must re-enter the | |
317 | * interpreter | |
318 | */ | |
014d433f | 319 | acpi_ex_enter_interpreter(); |
1da177e4 LT |
320 | } |
321 | ||
4be44fcd | 322 | return_ACPI_STATUS(status); |
1da177e4 LT |
323 | } |
324 | ||
1da177e4 LT |
325 | /******************************************************************************* |
326 | * | |
327 | * FUNCTION: acpi_ev_detach_region | |
328 | * | |
329 | * PARAMETERS: region_obj - Region Object | |
330 | * acpi_ns_is_locked - Namespace Region Already Locked? | |
331 | * | |
332 | * RETURN: None | |
333 | * | |
334 | * DESCRIPTION: Break the association between the handler and the region | |
335 | * this is a two way association. | |
336 | * | |
337 | ******************************************************************************/ | |
338 | ||
339 | void | |
4be44fcd LB |
340 | acpi_ev_detach_region(union acpi_operand_object *region_obj, |
341 | u8 acpi_ns_is_locked) | |
1da177e4 | 342 | { |
4be44fcd LB |
343 | union acpi_operand_object *handler_obj; |
344 | union acpi_operand_object *obj_desc; | |
f953529f | 345 | union acpi_operand_object *start_desc; |
4be44fcd LB |
346 | union acpi_operand_object **last_obj_ptr; |
347 | acpi_adr_space_setup region_setup; | |
348 | void **region_context; | |
349 | union acpi_operand_object *region_obj2; | |
350 | acpi_status status; | |
1da177e4 | 351 | |
b229cf92 | 352 | ACPI_FUNCTION_TRACE(ev_detach_region); |
1da177e4 | 353 | |
4be44fcd | 354 | region_obj2 = acpi_ns_get_secondary_object(region_obj); |
1da177e4 LT |
355 | if (!region_obj2) { |
356 | return_VOID; | |
357 | } | |
358 | region_context = ®ion_obj2->extra.region_context; | |
359 | ||
360 | /* Get the address handler from the region object */ | |
361 | ||
362 | handler_obj = region_obj->region.handler; | |
363 | if (!handler_obj) { | |
52fc0b02 | 364 | |
1da177e4 LT |
365 | /* This region has no handler, all done */ |
366 | ||
367 | return_VOID; | |
368 | } | |
369 | ||
370 | /* Find this region in the handler's list */ | |
371 | ||
372 | obj_desc = handler_obj->address_space.region_list; | |
f953529f | 373 | start_desc = obj_desc; |
1da177e4 LT |
374 | last_obj_ptr = &handler_obj->address_space.region_list; |
375 | ||
376 | while (obj_desc) { | |
52fc0b02 | 377 | |
1da177e4 LT |
378 | /* Is this the correct Region? */ |
379 | ||
380 | if (obj_desc == region_obj) { | |
4be44fcd LB |
381 | ACPI_DEBUG_PRINT((ACPI_DB_OPREGION, |
382 | "Removing Region %p from address handler %p\n", | |
383 | region_obj, handler_obj)); | |
1da177e4 LT |
384 | |
385 | /* This is it, remove it from the handler's list */ | |
386 | ||
387 | *last_obj_ptr = obj_desc->region.next; | |
4be44fcd | 388 | obj_desc->region.next = NULL; /* Must clear field */ |
1da177e4 LT |
389 | |
390 | if (acpi_ns_is_locked) { | |
4be44fcd LB |
391 | status = |
392 | acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); | |
393 | if (ACPI_FAILURE(status)) { | |
1da177e4 LT |
394 | return_VOID; |
395 | } | |
396 | } | |
397 | ||
398 | /* Now stop region accesses by executing the _REG method */ | |
399 | ||
e2066ca1 BM |
400 | status = |
401 | acpi_ev_execute_reg_method(region_obj, | |
402 | ACPI_REG_DISCONNECT); | |
4be44fcd | 403 | if (ACPI_FAILURE(status)) { |
b8e4d893 BM |
404 | ACPI_EXCEPTION((AE_INFO, status, |
405 | "from region _REG, [%s]", | |
406 | acpi_ut_get_region_name | |
407 | (region_obj->region.space_id))); | |
1da177e4 LT |
408 | } |
409 | ||
410 | if (acpi_ns_is_locked) { | |
4be44fcd LB |
411 | status = |
412 | acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); | |
413 | if (ACPI_FAILURE(status)) { | |
1da177e4 LT |
414 | return_VOID; |
415 | } | |
416 | } | |
417 | ||
f6dd9221 | 418 | /* |
9f15fc66 BM |
419 | * If the region has been activated, call the setup handler with |
420 | * the deactivate notification | |
f6dd9221 BM |
421 | */ |
422 | if (region_obj->region.flags & AOPOBJ_SETUP_COMPLETE) { | |
423 | region_setup = handler_obj->address_space.setup; | |
424 | status = | |
425 | region_setup(region_obj, | |
426 | ACPI_REGION_DEACTIVATE, | |
427 | handler_obj->address_space. | |
428 | context, region_context); | |
1da177e4 | 429 | |
d2e7d079 DB |
430 | /* |
431 | * region_context should have been released by the deactivate | |
432 | * operation. We don't need access to it anymore here. | |
433 | */ | |
434 | if (region_context) { | |
435 | *region_context = NULL; | |
436 | } | |
437 | ||
f6dd9221 | 438 | /* Init routine may fail, Just ignore errors */ |
1da177e4 | 439 | |
f6dd9221 BM |
440 | if (ACPI_FAILURE(status)) { |
441 | ACPI_EXCEPTION((AE_INFO, status, | |
442 | "from region handler - deactivate, [%s]", | |
443 | acpi_ut_get_region_name | |
444 | (region_obj->region. | |
445 | space_id))); | |
446 | } | |
1da177e4 | 447 | |
f6dd9221 BM |
448 | region_obj->region.flags &= |
449 | ~(AOPOBJ_SETUP_COMPLETE); | |
1da177e4 LT |
450 | } |
451 | ||
1da177e4 LT |
452 | /* |
453 | * Remove handler reference in the region | |
454 | * | |
f6dd9221 BM |
455 | * NOTE: this doesn't mean that the region goes away, the region |
456 | * is just inaccessible as indicated to the _REG method | |
1da177e4 | 457 | * |
f6dd9221 BM |
458 | * If the region is on the handler's list, this must be the |
459 | * region's handler | |
1da177e4 LT |
460 | */ |
461 | region_obj->region.handler = NULL; | |
4be44fcd | 462 | acpi_ut_remove_reference(handler_obj); |
1da177e4 LT |
463 | |
464 | return_VOID; | |
465 | } | |
466 | ||
467 | /* Walk the linked list of handlers */ | |
468 | ||
469 | last_obj_ptr = &obj_desc->region.next; | |
470 | obj_desc = obj_desc->region.next; | |
f953529f BM |
471 | |
472 | /* Prevent infinite loop if list is corrupted */ | |
473 | ||
474 | if (obj_desc == start_desc) { | |
475 | ACPI_ERROR((AE_INFO, | |
476 | "Circular handler list in region object %p", | |
477 | region_obj)); | |
478 | return_VOID; | |
479 | } | |
1da177e4 LT |
480 | } |
481 | ||
482 | /* If we get here, the region was not in the handler's region list */ | |
483 | ||
4be44fcd LB |
484 | ACPI_DEBUG_PRINT((ACPI_DB_OPREGION, |
485 | "Cannot remove region %p from address handler %p\n", | |
486 | region_obj, handler_obj)); | |
1da177e4 LT |
487 | |
488 | return_VOID; | |
489 | } | |
490 | ||
1da177e4 LT |
491 | /******************************************************************************* |
492 | * | |
493 | * FUNCTION: acpi_ev_attach_region | |
494 | * | |
495 | * PARAMETERS: handler_obj - Handler Object | |
496 | * region_obj - Region Object | |
497 | * acpi_ns_is_locked - Namespace Region Already Locked? | |
498 | * | |
499 | * RETURN: None | |
500 | * | |
501 | * DESCRIPTION: Create the association between the handler and the region | |
502 | * this is a two way association. | |
503 | * | |
504 | ******************************************************************************/ | |
505 | ||
506 | acpi_status | |
4be44fcd LB |
507 | acpi_ev_attach_region(union acpi_operand_object *handler_obj, |
508 | union acpi_operand_object *region_obj, | |
509 | u8 acpi_ns_is_locked) | |
1da177e4 LT |
510 | { |
511 | ||
b229cf92 | 512 | ACPI_FUNCTION_TRACE(ev_attach_region); |
1da177e4 | 513 | |
1d65d9a7 LZ |
514 | /* Install the region's handler */ |
515 | ||
516 | if (region_obj->region.handler) { | |
517 | return_ACPI_STATUS(AE_ALREADY_EXISTS); | |
518 | } | |
519 | ||
4be44fcd LB |
520 | ACPI_DEBUG_PRINT((ACPI_DB_OPREGION, |
521 | "Adding Region [%4.4s] %p to address handler %p [%s]\n", | |
522 | acpi_ut_get_node_name(region_obj->region.node), | |
523 | region_obj, handler_obj, | |
524 | acpi_ut_get_region_name(region_obj->region. | |
525 | space_id))); | |
1da177e4 LT |
526 | |
527 | /* Link this region to the front of the handler's list */ | |
528 | ||
529 | region_obj->region.next = handler_obj->address_space.region_list; | |
530 | handler_obj->address_space.region_list = region_obj; | |
1da177e4 | 531 | region_obj->region.handler = handler_obj; |
4be44fcd | 532 | acpi_ut_add_reference(handler_obj); |
1da177e4 | 533 | |
4be44fcd | 534 | return_ACPI_STATUS(AE_OK); |
1da177e4 LT |
535 | } |
536 | ||
849c2571 LZ |
537 | /******************************************************************************* |
538 | * | |
d1461a1b | 539 | * FUNCTION: acpi_ev_execute_reg_method |
849c2571 LZ |
540 | * |
541 | * PARAMETERS: region_obj - Region object | |
d1461a1b | 542 | * function - Passed to _REG: On (1) or Off (0) |
849c2571 LZ |
543 | * |
544 | * RETURN: Status | |
545 | * | |
d1461a1b | 546 | * DESCRIPTION: Execute _REG method for a region |
849c2571 LZ |
547 | * |
548 | ******************************************************************************/ | |
549 | ||
d1461a1b LZ |
550 | acpi_status |
551 | acpi_ev_execute_reg_method(union acpi_operand_object *region_obj, u32 function) | |
849c2571 | 552 | { |
d1461a1b LZ |
553 | struct acpi_evaluate_info *info; |
554 | union acpi_operand_object *args[3]; | |
555 | union acpi_operand_object *region_obj2; | |
0dfaaa3d BM |
556 | const acpi_name *reg_name_ptr = |
557 | ACPI_CAST_PTR(acpi_name, METHOD_NAME__REG); | |
849c2571 LZ |
558 | struct acpi_namespace_node *method_node; |
559 | struct acpi_namespace_node *node; | |
849c2571 LZ |
560 | acpi_status status; |
561 | ||
d1461a1b LZ |
562 | ACPI_FUNCTION_TRACE(ev_execute_reg_method); |
563 | ||
564 | if (!acpi_gbl_namespace_initialized || | |
565 | region_obj->region.handler == NULL) { | |
566 | return_ACPI_STATUS(AE_OK); | |
567 | } | |
849c2571 LZ |
568 | |
569 | region_obj2 = acpi_ns_get_secondary_object(region_obj); | |
570 | if (!region_obj2) { | |
d1461a1b | 571 | return_ACPI_STATUS(AE_NOT_EXIST); |
849c2571 LZ |
572 | } |
573 | ||
d1461a1b LZ |
574 | /* |
575 | * Find any "_REG" method associated with this region definition. | |
576 | * The method should always be updated as this function may be | |
577 | * invoked after a namespace change. | |
578 | */ | |
849c2571 | 579 | node = region_obj->region.node->parent; |
849c2571 LZ |
580 | status = |
581 | acpi_ns_search_one_scope(*reg_name_ptr, node, ACPI_TYPE_METHOD, | |
582 | &method_node); | |
583 | if (ACPI_SUCCESS(status)) { | |
584 | /* | |
d1461a1b LZ |
585 | * The _REG method is optional and there can be only one per |
586 | * region definition. This will be executed when the handler is | |
587 | * attached or removed. | |
849c2571 LZ |
588 | */ |
589 | region_obj2->extra.method_REG = method_node; | |
590 | } | |
d1461a1b | 591 | if (region_obj2->extra.method_REG == NULL) { |
efaed9be LZ |
592 | return_ACPI_STATUS(AE_OK); |
593 | } | |
594 | ||
595 | /* _REG(DISCONNECT) should be paired with _REG(CONNECT) */ | |
596 | ||
597 | if ((function == ACPI_REG_CONNECT && | |
598 | region_obj->common.flags & AOPOBJ_REG_CONNECTED) || | |
599 | (function == ACPI_REG_DISCONNECT && | |
600 | !(region_obj->common.flags & AOPOBJ_REG_CONNECTED))) { | |
42f8fb75 | 601 | return_ACPI_STATUS(AE_OK); |
1da177e4 LT |
602 | } |
603 | ||
42f8fb75 | 604 | /* Allocate and initialize the evaluation information block */ |
1da177e4 | 605 | |
42f8fb75 BM |
606 | info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info)); |
607 | if (!info) { | |
608 | return_ACPI_STATUS(AE_NO_MEMORY); | |
1da177e4 LT |
609 | } |
610 | ||
42f8fb75 | 611 | info->prefix_node = region_obj2->extra.method_REG; |
29a241cc | 612 | info->relative_pathname = NULL; |
42f8fb75 BM |
613 | info->parameters = args; |
614 | info->flags = ACPI_IGNORE_RETURN_VALUE; | |
1da177e4 LT |
615 | |
616 | /* | |
42f8fb75 BM |
617 | * The _REG method has two arguments: |
618 | * | |
619 | * arg0 - Integer: | |
620 | * Operation region space ID Same value as region_obj->Region.space_id | |
1da177e4 | 621 | * |
42f8fb75 BM |
622 | * arg1 - Integer: |
623 | * connection status 1 for connecting the handler, 0 for disconnecting | |
624 | * the handler (Passed as a parameter) | |
1da177e4 | 625 | */ |
42f8fb75 BM |
626 | args[0] = |
627 | acpi_ut_create_integer_object((u64)region_obj->region.space_id); | |
628 | if (!args[0]) { | |
1da177e4 | 629 | status = AE_NO_MEMORY; |
42f8fb75 | 630 | goto cleanup1; |
1da177e4 LT |
631 | } |
632 | ||
42f8fb75 BM |
633 | args[1] = acpi_ut_create_integer_object((u64)function); |
634 | if (!args[1]) { | |
635 | status = AE_NO_MEMORY; | |
636 | goto cleanup2; | |
637 | } | |
1da177e4 | 638 | |
42f8fb75 | 639 | args[2] = NULL; /* Terminate list */ |
1da177e4 | 640 | |
42f8fb75 | 641 | /* Execute the method, no return value */ |
1da177e4 | 642 | |
42f8fb75 BM |
643 | ACPI_DEBUG_EXEC(acpi_ut_display_init_pathname |
644 | (ACPI_TYPE_METHOD, info->prefix_node, NULL)); | |
1da177e4 | 645 | |
42f8fb75 BM |
646 | status = acpi_ns_evaluate(info); |
647 | acpi_ut_remove_reference(args[1]); | |
1da177e4 | 648 | |
efaed9be LZ |
649 | if (ACPI_FAILURE(status)) { |
650 | goto cleanup2; | |
651 | } | |
652 | ||
653 | if (function == ACPI_REG_CONNECT) { | |
654 | region_obj->common.flags |= AOPOBJ_REG_CONNECTED; | |
655 | } else { | |
656 | region_obj->common.flags &= ~AOPOBJ_REG_CONNECTED; | |
657 | } | |
658 | ||
10622bf8 | 659 | cleanup2: |
42f8fb75 | 660 | acpi_ut_remove_reference(args[0]); |
1da177e4 | 661 | |
10622bf8 | 662 | cleanup1: |
42f8fb75 | 663 | ACPI_FREE(info); |
4be44fcd | 664 | return_ACPI_STATUS(status); |
1da177e4 LT |
665 | } |
666 | ||
1da177e4 LT |
667 | /******************************************************************************* |
668 | * | |
669 | * FUNCTION: acpi_ev_execute_reg_methods | |
670 | * | |
ba494bee | 671 | * PARAMETERS: node - Namespace node for the device |
1da177e4 | 672 | * space_id - The address space ID |
d815346f | 673 | * function - Passed to _REG: On (1) or Off (0) |
1da177e4 | 674 | * |
d815346f | 675 | * RETURN: None |
1da177e4 LT |
676 | * |
677 | * DESCRIPTION: Run all _REG methods for the input Space ID; | |
678 | * Note: assumes namespace is locked, or system init time. | |
679 | * | |
680 | ******************************************************************************/ | |
681 | ||
d815346f | 682 | void |
4be44fcd | 683 | acpi_ev_execute_reg_methods(struct acpi_namespace_node *node, |
d815346f | 684 | acpi_adr_space_type space_id, u32 function) |
1da177e4 | 685 | { |
25823e78 | 686 | struct acpi_reg_walk_info info; |
1da177e4 | 687 | |
b229cf92 | 688 | ACPI_FUNCTION_TRACE(ev_execute_reg_methods); |
1da177e4 | 689 | |
25823e78 | 690 | info.space_id = space_id; |
d815346f | 691 | info.function = function; |
25823e78 BM |
692 | info.reg_run_count = 0; |
693 | ||
694 | ACPI_DEBUG_PRINT_RAW((ACPI_DB_NAMES, | |
695 | " Running _REG methods for SpaceId %s\n", | |
696 | acpi_ut_get_region_name(info.space_id))); | |
697 | ||
1da177e4 | 698 | /* |
9f15fc66 BM |
699 | * Run all _REG methods for all Operation Regions for this space ID. This |
700 | * is a separate walk in order to handle any interdependencies between | |
701 | * regions and _REG methods. (i.e. handlers must be installed for all | |
702 | * regions of this Space ID before we can run any _REG methods) | |
1da177e4 | 703 | */ |
d815346f LZ |
704 | (void)acpi_ns_walk_namespace(ACPI_TYPE_ANY, node, ACPI_UINT32_MAX, |
705 | ACPI_NS_WALK_UNLOCK, acpi_ev_reg_run, NULL, | |
706 | &info, NULL); | |
1da177e4 | 707 | |
e2066ca1 BM |
708 | /* Special case for EC: handle "orphan" _REG methods with no region */ |
709 | ||
710 | if (space_id == ACPI_ADR_SPACE_EC) { | |
8f4f5e78 | 711 | acpi_ev_orphan_ec_reg_method(node); |
e2066ca1 BM |
712 | } |
713 | ||
25823e78 BM |
714 | ACPI_DEBUG_PRINT_RAW((ACPI_DB_NAMES, |
715 | " Executed %u _REG methods for SpaceId %s\n", | |
716 | info.reg_run_count, | |
717 | acpi_ut_get_region_name(info.space_id))); | |
718 | ||
d815346f | 719 | return_VOID; |
1da177e4 LT |
720 | } |
721 | ||
1da177e4 LT |
722 | /******************************************************************************* |
723 | * | |
724 | * FUNCTION: acpi_ev_reg_run | |
725 | * | |
726 | * PARAMETERS: walk_namespace callback | |
727 | * | |
ba494bee | 728 | * DESCRIPTION: Run _REG method for region objects of the requested spaceID |
1da177e4 LT |
729 | * |
730 | ******************************************************************************/ | |
731 | ||
44f6c012 | 732 | static acpi_status |
4be44fcd LB |
733 | acpi_ev_reg_run(acpi_handle obj_handle, |
734 | u32 level, void *context, void **return_value) | |
1da177e4 | 735 | { |
4be44fcd LB |
736 | union acpi_operand_object *obj_desc; |
737 | struct acpi_namespace_node *node; | |
4be44fcd | 738 | acpi_status status; |
25823e78 | 739 | struct acpi_reg_walk_info *info; |
1da177e4 | 740 | |
25823e78 | 741 | info = ACPI_CAST_PTR(struct acpi_reg_walk_info, context); |
1da177e4 LT |
742 | |
743 | /* Convert and validate the device handle */ | |
744 | ||
f24b664d | 745 | node = acpi_ns_validate_handle(obj_handle); |
1da177e4 LT |
746 | if (!node) { |
747 | return (AE_BAD_PARAMETER); | |
748 | } | |
749 | ||
750 | /* | |
9f15fc66 BM |
751 | * We only care about regions.and objects that are allowed to have address |
752 | * space handlers | |
1da177e4 | 753 | */ |
4be44fcd | 754 | if ((node->type != ACPI_TYPE_REGION) && (node != acpi_gbl_root_node)) { |
1da177e4 LT |
755 | return (AE_OK); |
756 | } | |
757 | ||
758 | /* Check for an existing internal object */ | |
759 | ||
4be44fcd | 760 | obj_desc = acpi_ns_get_attached_object(node); |
1da177e4 | 761 | if (!obj_desc) { |
52fc0b02 | 762 | |
1da177e4 LT |
763 | /* No object, just exit */ |
764 | ||
765 | return (AE_OK); | |
766 | } | |
767 | ||
768 | /* Object is a Region */ | |
769 | ||
25823e78 | 770 | if (obj_desc->region.space_id != info->space_id) { |
9f15fc66 BM |
771 | |
772 | /* This region is for a different address space, just ignore it */ | |
773 | ||
1da177e4 LT |
774 | return (AE_OK); |
775 | } | |
776 | ||
25823e78 | 777 | info->reg_run_count++; |
d815346f | 778 | status = acpi_ev_execute_reg_method(obj_desc, info->function); |
1da177e4 LT |
779 | return (status); |
780 | } | |
e2066ca1 BM |
781 | |
782 | /******************************************************************************* | |
783 | * | |
784 | * FUNCTION: acpi_ev_orphan_ec_reg_method | |
785 | * | |
8f4f5e78 | 786 | * PARAMETERS: ec_device_node - Namespace node for an EC device |
e2066ca1 BM |
787 | * |
788 | * RETURN: None | |
789 | * | |
790 | * DESCRIPTION: Execute an "orphan" _REG method that appears under the EC | |
791 | * device. This is a _REG method that has no corresponding region | |
792 | * within the EC device scope. The orphan _REG method appears to | |
793 | * have been enabled by the description of the ECDT in the ACPI | |
794 | * specification: "The availability of the region space can be | |
795 | * detected by providing a _REG method object underneath the | |
796 | * Embedded Controller device." | |
797 | * | |
8f4f5e78 ZR |
798 | * To quickly access the EC device, we use the ec_device_node used |
799 | * during EC handler installation. Otherwise, we would need to | |
800 | * perform a time consuming namespace walk, executing _HID | |
801 | * methods to find the EC device. | |
802 | * | |
803 | * MUTEX: Assumes the namespace is locked | |
e2066ca1 BM |
804 | * |
805 | ******************************************************************************/ | |
806 | ||
8f4f5e78 ZR |
807 | static void |
808 | acpi_ev_orphan_ec_reg_method(struct acpi_namespace_node *ec_device_node) | |
e2066ca1 | 809 | { |
8f4f5e78 ZR |
810 | acpi_handle reg_method; |
811 | struct acpi_namespace_node *next_node; | |
e2066ca1 BM |
812 | acpi_status status; |
813 | struct acpi_object_list args; | |
814 | union acpi_object objects[2]; | |
e2066ca1 BM |
815 | |
816 | ACPI_FUNCTION_TRACE(ev_orphan_ec_reg_method); | |
817 | ||
8f4f5e78 | 818 | if (!ec_device_node) { |
e2066ca1 BM |
819 | return_VOID; |
820 | } | |
821 | ||
822 | /* Namespace is currently locked, must release */ | |
823 | ||
824 | (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); | |
825 | ||
e2066ca1 BM |
826 | /* Get a handle to a _REG method immediately under the EC device */ |
827 | ||
8f4f5e78 | 828 | status = acpi_get_handle(ec_device_node, METHOD_NAME__REG, ®_method); |
e2066ca1 | 829 | if (ACPI_FAILURE(status)) { |
8f4f5e78 | 830 | goto exit; /* There is no _REG method present */ |
e2066ca1 BM |
831 | } |
832 | ||
833 | /* | |
834 | * Execute the _REG method only if there is no Operation Region in | |
835 | * this scope with the Embedded Controller space ID. Otherwise, it | |
836 | * will already have been executed. Note, this allows for Regions | |
837 | * with other space IDs to be present; but the code below will then | |
8f4f5e78 | 838 | * execute the _REG method with the embedded_control space_ID argument. |
e2066ca1 BM |
839 | */ |
840 | next_node = acpi_ns_get_next_node(ec_device_node, NULL); | |
841 | while (next_node) { | |
842 | if ((next_node->type == ACPI_TYPE_REGION) && | |
843 | (next_node->object) && | |
844 | (next_node->object->region.space_id == ACPI_ADR_SPACE_EC)) { | |
8f4f5e78 | 845 | goto exit; /* Do not execute the _REG */ |
e2066ca1 | 846 | } |
8f4f5e78 | 847 | |
e2066ca1 BM |
848 | next_node = acpi_ns_get_next_node(ec_device_node, next_node); |
849 | } | |
850 | ||
8f4f5e78 | 851 | /* Evaluate the _REG(embedded_control,Connect) method */ |
e2066ca1 BM |
852 | |
853 | args.count = 2; | |
854 | args.pointer = objects; | |
855 | objects[0].type = ACPI_TYPE_INTEGER; | |
856 | objects[0].integer.value = ACPI_ADR_SPACE_EC; | |
857 | objects[1].type = ACPI_TYPE_INTEGER; | |
858 | objects[1].integer.value = ACPI_REG_CONNECT; | |
859 | ||
860 | status = acpi_evaluate_object(reg_method, NULL, &args, NULL); | |
861 | ||
10622bf8 | 862 | exit: |
e2066ca1 BM |
863 | /* We ignore all errors from above, don't care */ |
864 | ||
865 | status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); | |
866 | return_VOID; | |
867 | } |