[PATCH] fix semaphore handling in __unregister_chrdev_region
[linux/fpc-iii.git] / drivers / acpi / events / evregion.c
blob772342708a7afb1141b60b418df238e25b01a0dd
1 /******************************************************************************
3 * Module Name: evregion - ACPI address_space (op_region) handler dispatch
5 *****************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2005, R. Byron Moore
9 * All rights reserved.
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.
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.
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.
45 #include <acpi/acpi.h>
46 #include <acpi/acevents.h>
47 #include <acpi/acnamesp.h>
48 #include <acpi/acinterp.h>
50 #define _COMPONENT ACPI_EVENTS
51 ACPI_MODULE_NAME ("evregion")
53 #define ACPI_NUM_DEFAULT_SPACES 4
55 static u8 acpi_gbl_default_address_spaces[ACPI_NUM_DEFAULT_SPACES] = {
56 ACPI_ADR_SPACE_SYSTEM_MEMORY,
57 ACPI_ADR_SPACE_SYSTEM_IO,
58 ACPI_ADR_SPACE_PCI_CONFIG,
59 ACPI_ADR_SPACE_DATA_TABLE};
62 /*******************************************************************************
64 * FUNCTION: acpi_ev_install_region_handlers
66 * PARAMETERS: None
68 * RETURN: Status
70 * DESCRIPTION: Installs the core subsystem default address space handlers.
72 ******************************************************************************/
74 acpi_status
75 acpi_ev_install_region_handlers (
76 void) {
77 acpi_status status;
78 acpi_native_uint i;
81 ACPI_FUNCTION_TRACE ("ev_install_region_handlers");
84 status = acpi_ut_acquire_mutex (ACPI_MTX_NAMESPACE);
85 if (ACPI_FAILURE (status)) {
86 return_ACPI_STATUS (status);
90 * All address spaces (PCI Config, EC, SMBus) are scope dependent
91 * and registration must occur for a specific device.
93 * In the case of the system memory and IO address spaces there is currently
94 * no device associated with the address space. For these we use the root.
96 * We install the default PCI config space handler at the root so
97 * that this space is immediately available even though the we have
98 * not enumerated all the PCI Root Buses yet. This is to conform
99 * to the ACPI specification which states that the PCI config
100 * space must be always available -- even though we are nowhere
101 * near ready to find the PCI root buses at this point.
103 * NOTE: We ignore AE_ALREADY_EXISTS because this means that a handler
104 * has already been installed (via acpi_install_address_space_handler).
105 * Similar for AE_SAME_HANDLER.
107 for (i = 0; i < ACPI_NUM_DEFAULT_SPACES; i++) {
108 status = acpi_ev_install_space_handler (acpi_gbl_root_node,
109 acpi_gbl_default_address_spaces[i],
110 ACPI_DEFAULT_HANDLER, NULL, NULL);
111 switch (status) {
112 case AE_OK:
113 case AE_SAME_HANDLER:
114 case AE_ALREADY_EXISTS:
116 /* These exceptions are all OK */
118 status = AE_OK;
119 break;
121 default:
123 goto unlock_and_exit;
127 unlock_and_exit:
128 (void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE);
129 return_ACPI_STATUS (status);
133 /*******************************************************************************
135 * FUNCTION: acpi_ev_initialize_op_regions
137 * PARAMETERS: None
139 * RETURN: Status
141 * DESCRIPTION: Execute _REG methods for all Operation Regions that have
142 * an installed default region handler.
144 ******************************************************************************/
146 acpi_status
147 acpi_ev_initialize_op_regions (
148 void)
150 acpi_status status;
151 acpi_native_uint i;
154 ACPI_FUNCTION_TRACE ("ev_initialize_op_regions");
157 status = acpi_ut_acquire_mutex (ACPI_MTX_NAMESPACE);
158 if (ACPI_FAILURE (status)) {
159 return_ACPI_STATUS (status);
163 * Run the _REG methods for op_regions in each default address space
165 for (i = 0; i < ACPI_NUM_DEFAULT_SPACES; i++) {
166 /* TBD: Make sure handler is the DEFAULT handler, otherwise
167 * _REG will have already been run.
169 status = acpi_ev_execute_reg_methods (acpi_gbl_root_node,
170 acpi_gbl_default_address_spaces[i]);
173 (void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE);
174 return_ACPI_STATUS (status);
178 /*******************************************************************************
180 * FUNCTION: acpi_ev_execute_reg_method
182 * PARAMETERS: region_obj - Object structure
183 * Function - Passed to _REG: On (1) or Off (0)
185 * RETURN: Status
187 * DESCRIPTION: Execute _REG method for a region
189 ******************************************************************************/
191 acpi_status
192 acpi_ev_execute_reg_method (
193 union acpi_operand_object *region_obj,
194 u32 function)
196 struct acpi_parameter_info info;
197 union acpi_operand_object *params[3];
198 union acpi_operand_object *region_obj2;
199 acpi_status status;
202 ACPI_FUNCTION_TRACE ("ev_execute_reg_method");
205 region_obj2 = acpi_ns_get_secondary_object (region_obj);
206 if (!region_obj2) {
207 return_ACPI_STATUS (AE_NOT_EXIST);
210 if (region_obj2->extra.method_REG == NULL) {
211 return_ACPI_STATUS (AE_OK);
215 * The _REG method has two arguments:
217 * Arg0, Integer: Operation region space ID
218 * Same value as region_obj->Region.space_id
219 * Arg1, Integer: connection status
220 * 1 for connecting the handler,
221 * 0 for disconnecting the handler
222 * Passed as a parameter
224 params[0] = acpi_ut_create_internal_object (ACPI_TYPE_INTEGER);
225 if (!params[0]) {
226 return_ACPI_STATUS (AE_NO_MEMORY);
229 params[1] = acpi_ut_create_internal_object (ACPI_TYPE_INTEGER);
230 if (!params[1]) {
231 status = AE_NO_MEMORY;
232 goto cleanup;
235 /* Setup the parameter objects */
237 params[0]->integer.value = region_obj->region.space_id;
238 params[1]->integer.value = function;
239 params[2] = NULL;
241 info.node = region_obj2->extra.method_REG;
242 info.parameters = params;
243 info.parameter_type = ACPI_PARAM_ARGS;
245 /* Execute the method, no return value */
247 ACPI_DEBUG_EXEC (acpi_ut_display_init_pathname (
248 ACPI_TYPE_METHOD, info.node, NULL));
249 status = acpi_ns_evaluate_by_handle (&info);
251 acpi_ut_remove_reference (params[1]);
253 cleanup:
254 acpi_ut_remove_reference (params[0]);
256 return_ACPI_STATUS (status);
260 /*******************************************************************************
262 * FUNCTION: acpi_ev_address_space_dispatch
264 * PARAMETERS: region_obj - Internal region object
265 * Function - Read or Write operation
266 * Address - Where in the space to read or write
267 * bit_width - Field width in bits (8, 16, 32, or 64)
268 * Value - Pointer to in or out value
270 * RETURN: Status
272 * DESCRIPTION: Dispatch an address space or operation region access to
273 * a previously installed handler.
275 ******************************************************************************/
277 acpi_status
278 acpi_ev_address_space_dispatch (
279 union acpi_operand_object *region_obj,
280 u32 function,
281 acpi_physical_address address,
282 u32 bit_width,
283 void *value)
285 acpi_status status;
286 acpi_status status2;
287 acpi_adr_space_handler handler;
288 acpi_adr_space_setup region_setup;
289 union acpi_operand_object *handler_desc;
290 union acpi_operand_object *region_obj2;
291 void *region_context = NULL;
294 ACPI_FUNCTION_TRACE ("ev_address_space_dispatch");
297 region_obj2 = acpi_ns_get_secondary_object (region_obj);
298 if (!region_obj2) {
299 return_ACPI_STATUS (AE_NOT_EXIST);
302 /* Ensure that there is a handler associated with this region */
304 handler_desc = region_obj->region.handler;
305 if (!handler_desc) {
306 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
307 "No handler for Region [%4.4s] (%p) [%s]\n",
308 acpi_ut_get_node_name (region_obj->region.node),
309 region_obj, acpi_ut_get_region_name (region_obj->region.space_id)));
311 return_ACPI_STATUS (AE_NOT_EXIST);
315 * It may be the case that the region has never been initialized
316 * Some types of regions require special init code
318 if (!(region_obj->region.flags & AOPOBJ_SETUP_COMPLETE)) {
320 * This region has not been initialized yet, do it
322 region_setup = handler_desc->address_space.setup;
323 if (!region_setup) {
324 /* No initialization routine, exit with error */
326 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "No init routine for region(%p) [%s]\n",
327 region_obj, acpi_ut_get_region_name (region_obj->region.space_id)));
328 return_ACPI_STATUS (AE_NOT_EXIST);
332 * We must exit the interpreter because the region setup will potentially
333 * execute control methods (e.g., _REG method for this region)
335 acpi_ex_exit_interpreter ();
337 status = region_setup (region_obj, ACPI_REGION_ACTIVATE,
338 handler_desc->address_space.context, &region_context);
340 /* Re-enter the interpreter */
342 status2 = acpi_ex_enter_interpreter ();
343 if (ACPI_FAILURE (status2)) {
344 return_ACPI_STATUS (status2);
347 /* Check for failure of the Region Setup */
349 if (ACPI_FAILURE (status)) {
350 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Region Init: %s [%s]\n",
351 acpi_format_exception (status),
352 acpi_ut_get_region_name (region_obj->region.space_id)));
353 return_ACPI_STATUS (status);
357 * Region initialization may have been completed by region_setup
359 if (!(region_obj->region.flags & AOPOBJ_SETUP_COMPLETE)) {
360 region_obj->region.flags |= AOPOBJ_SETUP_COMPLETE;
362 if (region_obj2->extra.region_context) {
363 /* The handler for this region was already installed */
365 ACPI_MEM_FREE (region_context);
367 else {
369 * Save the returned context for use in all accesses to
370 * this particular region
372 region_obj2->extra.region_context = region_context;
377 /* We have everything we need, we can invoke the address space handler */
379 handler = handler_desc->address_space.handler;
381 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
382 "Handler %p (@%p) Address %8.8X%8.8X [%s]\n",
383 &region_obj->region.handler->address_space, handler,
384 ACPI_FORMAT_UINT64 (address),
385 acpi_ut_get_region_name (region_obj->region.space_id)));
387 if (!(handler_desc->address_space.hflags & ACPI_ADDR_HANDLER_DEFAULT_INSTALLED)) {
389 * For handlers other than the default (supplied) handlers, we must
390 * exit the interpreter because the handler *might* block -- we don't
391 * know what it will do, so we can't hold the lock on the intepreter.
393 acpi_ex_exit_interpreter();
396 /* Call the handler */
398 status = handler (function, address, bit_width, value,
399 handler_desc->address_space.context,
400 region_obj2->extra.region_context);
402 if (ACPI_FAILURE (status)) {
403 ACPI_REPORT_ERROR (("Handler for [%s] returned %s\n",
404 acpi_ut_get_region_name (region_obj->region.space_id),
405 acpi_format_exception (status)));
408 if (!(handler_desc->address_space.hflags & ACPI_ADDR_HANDLER_DEFAULT_INSTALLED)) {
410 * We just returned from a non-default handler, we must re-enter the
411 * interpreter
413 status2 = acpi_ex_enter_interpreter ();
414 if (ACPI_FAILURE (status2)) {
415 return_ACPI_STATUS (status2);
419 return_ACPI_STATUS (status);
423 /*******************************************************************************
425 * FUNCTION: acpi_ev_detach_region
427 * PARAMETERS: region_obj - Region Object
428 * acpi_ns_is_locked - Namespace Region Already Locked?
430 * RETURN: None
432 * DESCRIPTION: Break the association between the handler and the region
433 * this is a two way association.
435 ******************************************************************************/
437 void
438 acpi_ev_detach_region(
439 union acpi_operand_object *region_obj,
440 u8 acpi_ns_is_locked)
442 union acpi_operand_object *handler_obj;
443 union acpi_operand_object *obj_desc;
444 union acpi_operand_object **last_obj_ptr;
445 acpi_adr_space_setup region_setup;
446 void **region_context;
447 union acpi_operand_object *region_obj2;
448 acpi_status status;
451 ACPI_FUNCTION_TRACE ("ev_detach_region");
454 region_obj2 = acpi_ns_get_secondary_object (region_obj);
455 if (!region_obj2) {
456 return_VOID;
458 region_context = &region_obj2->extra.region_context;
460 /* Get the address handler from the region object */
462 handler_obj = region_obj->region.handler;
463 if (!handler_obj) {
464 /* This region has no handler, all done */
466 return_VOID;
469 /* Find this region in the handler's list */
471 obj_desc = handler_obj->address_space.region_list;
472 last_obj_ptr = &handler_obj->address_space.region_list;
474 while (obj_desc) {
475 /* Is this the correct Region? */
477 if (obj_desc == region_obj) {
478 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
479 "Removing Region %p from address handler %p\n",
480 region_obj, handler_obj));
482 /* This is it, remove it from the handler's list */
484 *last_obj_ptr = obj_desc->region.next;
485 obj_desc->region.next = NULL; /* Must clear field */
487 if (acpi_ns_is_locked) {
488 status = acpi_ut_release_mutex (ACPI_MTX_NAMESPACE);
489 if (ACPI_FAILURE (status)) {
490 return_VOID;
494 /* Now stop region accesses by executing the _REG method */
496 status = acpi_ev_execute_reg_method (region_obj, 0);
497 if (ACPI_FAILURE (status)) {
498 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "%s from region _REG, [%s]\n",
499 acpi_format_exception (status),
500 acpi_ut_get_region_name (region_obj->region.space_id)));
503 if (acpi_ns_is_locked) {
504 status = acpi_ut_acquire_mutex (ACPI_MTX_NAMESPACE);
505 if (ACPI_FAILURE (status)) {
506 return_VOID;
510 /* Call the setup handler with the deactivate notification */
512 region_setup = handler_obj->address_space.setup;
513 status = region_setup (region_obj, ACPI_REGION_DEACTIVATE,
514 handler_obj->address_space.context, region_context);
516 /* Init routine may fail, Just ignore errors */
518 if (ACPI_FAILURE (status)) {
519 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "%s from region init, [%s]\n",
520 acpi_format_exception (status),
521 acpi_ut_get_region_name (region_obj->region.space_id)));
524 region_obj->region.flags &= ~(AOPOBJ_SETUP_COMPLETE);
527 * Remove handler reference in the region
529 * NOTE: this doesn't mean that the region goes away
530 * The region is just inaccessible as indicated to
531 * the _REG method
533 * If the region is on the handler's list
534 * this better be the region's handler
536 region_obj->region.handler = NULL;
537 acpi_ut_remove_reference (handler_obj);
539 return_VOID;
542 /* Walk the linked list of handlers */
544 last_obj_ptr = &obj_desc->region.next;
545 obj_desc = obj_desc->region.next;
548 /* If we get here, the region was not in the handler's region list */
550 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
551 "Cannot remove region %p from address handler %p\n",
552 region_obj, handler_obj));
554 return_VOID;
558 /*******************************************************************************
560 * FUNCTION: acpi_ev_attach_region
562 * PARAMETERS: handler_obj - Handler Object
563 * region_obj - Region Object
564 * acpi_ns_is_locked - Namespace Region Already Locked?
566 * RETURN: None
568 * DESCRIPTION: Create the association between the handler and the region
569 * this is a two way association.
571 ******************************************************************************/
573 acpi_status
574 acpi_ev_attach_region (
575 union acpi_operand_object *handler_obj,
576 union acpi_operand_object *region_obj,
577 u8 acpi_ns_is_locked)
580 ACPI_FUNCTION_TRACE ("ev_attach_region");
583 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
584 "Adding Region [%4.4s] %p to address handler %p [%s]\n",
585 acpi_ut_get_node_name (region_obj->region.node),
586 region_obj, handler_obj,
587 acpi_ut_get_region_name (region_obj->region.space_id)));
589 /* Link this region to the front of the handler's list */
591 region_obj->region.next = handler_obj->address_space.region_list;
592 handler_obj->address_space.region_list = region_obj;
594 /* Install the region's handler */
596 if (region_obj->region.handler) {
597 return_ACPI_STATUS (AE_ALREADY_EXISTS);
600 region_obj->region.handler = handler_obj;
601 acpi_ut_add_reference (handler_obj);
603 return_ACPI_STATUS (AE_OK);
607 /*******************************************************************************
609 * FUNCTION: acpi_ev_install_handler
611 * PARAMETERS: walk_namespace callback
613 * DESCRIPTION: This routine installs an address handler into objects that are
614 * of type Region or Device.
616 * If the Object is a Device, and the device has a handler of
617 * the same type then the search is terminated in that branch.
619 * This is because the existing handler is closer in proximity
620 * to any more regions than the one we are trying to install.
622 ******************************************************************************/
624 acpi_status
625 acpi_ev_install_handler (
626 acpi_handle obj_handle,
627 u32 level,
628 void *context,
629 void **return_value)
631 union acpi_operand_object *handler_obj;
632 union acpi_operand_object *next_handler_obj;
633 union acpi_operand_object *obj_desc;
634 struct acpi_namespace_node *node;
635 acpi_status status;
638 ACPI_FUNCTION_NAME ("ev_install_handler");
641 handler_obj = (union acpi_operand_object *) context;
643 /* Parameter validation */
645 if (!handler_obj) {
646 return (AE_OK);
649 /* Convert and validate the device handle */
651 node = acpi_ns_map_handle_to_node (obj_handle);
652 if (!node) {
653 return (AE_BAD_PARAMETER);
657 * We only care about regions.and objects
658 * that are allowed to have address space handlers
660 if ((node->type != ACPI_TYPE_DEVICE) &&
661 (node->type != ACPI_TYPE_REGION) &&
662 (node != acpi_gbl_root_node)) {
663 return (AE_OK);
666 /* Check for an existing internal object */
668 obj_desc = acpi_ns_get_attached_object (node);
669 if (!obj_desc) {
670 /* No object, just exit */
672 return (AE_OK);
675 /* Devices are handled different than regions */
677 if (ACPI_GET_OBJECT_TYPE (obj_desc) == ACPI_TYPE_DEVICE) {
678 /* Check if this Device already has a handler for this address space */
680 next_handler_obj = obj_desc->device.handler;
681 while (next_handler_obj) {
682 /* Found a handler, is it for the same address space? */
684 if (next_handler_obj->address_space.space_id == handler_obj->address_space.space_id) {
685 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
686 "Found handler for region [%s] in device %p(%p) handler %p\n",
687 acpi_ut_get_region_name (handler_obj->address_space.space_id),
688 obj_desc, next_handler_obj, handler_obj));
691 * Since the object we found it on was a device, then it
692 * means that someone has already installed a handler for
693 * the branch of the namespace from this device on. Just
694 * bail out telling the walk routine to not traverse this
695 * branch. This preserves the scoping rule for handlers.
697 return (AE_CTRL_DEPTH);
700 /* Walk the linked list of handlers attached to this device */
702 next_handler_obj = next_handler_obj->address_space.next;
706 * As long as the device didn't have a handler for this
707 * space we don't care about it. We just ignore it and
708 * proceed.
710 return (AE_OK);
713 /* Object is a Region */
715 if (obj_desc->region.space_id != handler_obj->address_space.space_id) {
717 * This region is for a different address space
718 * -- just ignore it
720 return (AE_OK);
724 * Now we have a region and it is for the handler's address
725 * space type.
727 * First disconnect region for any previous handler (if any)
729 acpi_ev_detach_region (obj_desc, FALSE);
731 /* Connect the region to the new handler */
733 status = acpi_ev_attach_region (handler_obj, obj_desc, FALSE);
734 return (status);
738 /*******************************************************************************
740 * FUNCTION: acpi_ev_install_space_handler
742 * PARAMETERS: Node - Namespace node for the device
743 * space_id - The address space ID
744 * Handler - Address of the handler
745 * Setup - Address of the setup function
746 * Context - Value passed to the handler on each access
748 * RETURN: Status
750 * DESCRIPTION: Install a handler for all op_regions of a given space_id.
751 * Assumes namespace is locked
753 ******************************************************************************/
755 acpi_status
756 acpi_ev_install_space_handler (
757 struct acpi_namespace_node *node,
758 acpi_adr_space_type space_id,
759 acpi_adr_space_handler handler,
760 acpi_adr_space_setup setup,
761 void *context)
763 union acpi_operand_object *obj_desc;
764 union acpi_operand_object *handler_obj;
765 acpi_status status;
766 acpi_object_type type;
767 u16 flags = 0;
770 ACPI_FUNCTION_TRACE ("ev_install_space_handler");
774 * This registration is valid for only the types below
775 * and the root. This is where the default handlers
776 * get placed.
778 if ((node->type != ACPI_TYPE_DEVICE) &&
779 (node->type != ACPI_TYPE_PROCESSOR) &&
780 (node->type != ACPI_TYPE_THERMAL) &&
781 (node != acpi_gbl_root_node)) {
782 status = AE_BAD_PARAMETER;
783 goto unlock_and_exit;
786 if (handler == ACPI_DEFAULT_HANDLER) {
787 flags = ACPI_ADDR_HANDLER_DEFAULT_INSTALLED;
789 switch (space_id) {
790 case ACPI_ADR_SPACE_SYSTEM_MEMORY:
791 handler = acpi_ex_system_memory_space_handler;
792 setup = acpi_ev_system_memory_region_setup;
793 break;
795 case ACPI_ADR_SPACE_SYSTEM_IO:
796 handler = acpi_ex_system_io_space_handler;
797 setup = acpi_ev_io_space_region_setup;
798 break;
800 case ACPI_ADR_SPACE_PCI_CONFIG:
801 handler = acpi_ex_pci_config_space_handler;
802 setup = acpi_ev_pci_config_region_setup;
803 break;
805 case ACPI_ADR_SPACE_CMOS:
806 handler = acpi_ex_cmos_space_handler;
807 setup = acpi_ev_cmos_region_setup;
808 break;
810 case ACPI_ADR_SPACE_PCI_BAR_TARGET:
811 handler = acpi_ex_pci_bar_space_handler;
812 setup = acpi_ev_pci_bar_region_setup;
813 break;
815 case ACPI_ADR_SPACE_DATA_TABLE:
816 handler = acpi_ex_data_table_space_handler;
817 setup = NULL;
818 break;
820 default:
821 status = AE_BAD_PARAMETER;
822 goto unlock_and_exit;
826 /* If the caller hasn't specified a setup routine, use the default */
828 if (!setup) {
829 setup = acpi_ev_default_region_setup;
832 /* Check for an existing internal object */
834 obj_desc = acpi_ns_get_attached_object (node);
835 if (obj_desc) {
837 * The attached device object already exists.
838 * Make sure the handler is not already installed.
840 handler_obj = obj_desc->device.handler;
842 /* Walk the handler list for this device */
844 while (handler_obj) {
845 /* Same space_id indicates a handler already installed */
847 if (handler_obj->address_space.space_id == space_id) {
848 if (handler_obj->address_space.handler == handler) {
850 * It is (relatively) OK to attempt to install the SAME
851 * handler twice. This can easily happen with PCI_Config space.
853 status = AE_SAME_HANDLER;
854 goto unlock_and_exit;
856 else {
857 /* A handler is already installed */
859 status = AE_ALREADY_EXISTS;
861 goto unlock_and_exit;
864 /* Walk the linked list of handlers */
866 handler_obj = handler_obj->address_space.next;
869 else {
870 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
871 "Creating object on Device %p while installing handler\n", node));
873 /* obj_desc does not exist, create one */
875 if (node->type == ACPI_TYPE_ANY) {
876 type = ACPI_TYPE_DEVICE;
878 else {
879 type = node->type;
882 obj_desc = acpi_ut_create_internal_object (type);
883 if (!obj_desc) {
884 status = AE_NO_MEMORY;
885 goto unlock_and_exit;
888 /* Init new descriptor */
890 obj_desc->common.type = (u8) type;
892 /* Attach the new object to the Node */
894 status = acpi_ns_attach_object (node, obj_desc, type);
896 /* Remove local reference to the object */
898 acpi_ut_remove_reference (obj_desc);
900 if (ACPI_FAILURE (status)) {
901 goto unlock_and_exit;
905 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
906 "Installing address handler for region %s(%X) on Device %4.4s %p(%p)\n",
907 acpi_ut_get_region_name (space_id), space_id,
908 acpi_ut_get_node_name (node), node, obj_desc));
911 * Install the handler
913 * At this point there is no existing handler.
914 * Just allocate the object for the handler and link it
915 * into the list.
917 handler_obj = acpi_ut_create_internal_object (ACPI_TYPE_LOCAL_ADDRESS_HANDLER);
918 if (!handler_obj) {
919 status = AE_NO_MEMORY;
920 goto unlock_and_exit;
923 /* Init handler obj */
925 handler_obj->address_space.space_id = (u8) space_id;
926 handler_obj->address_space.hflags = flags;
927 handler_obj->address_space.region_list = NULL;
928 handler_obj->address_space.node = node;
929 handler_obj->address_space.handler = handler;
930 handler_obj->address_space.context = context;
931 handler_obj->address_space.setup = setup;
933 /* Install at head of Device.address_space list */
935 handler_obj->address_space.next = obj_desc->device.handler;
938 * The Device object is the first reference on the handler_obj.
939 * Each region that uses the handler adds a reference.
941 obj_desc->device.handler = handler_obj;
944 * Walk the namespace finding all of the regions this
945 * handler will manage.
947 * Start at the device and search the branch toward
948 * the leaf nodes until either the leaf is encountered or
949 * a device is detected that has an address handler of the
950 * same type.
952 * In either case, back up and search down the remainder
953 * of the branch
955 status = acpi_ns_walk_namespace (ACPI_TYPE_ANY, node, ACPI_UINT32_MAX,
956 ACPI_NS_WALK_UNLOCK, acpi_ev_install_handler,
957 handler_obj, NULL);
959 unlock_and_exit:
960 return_ACPI_STATUS (status);
964 /*******************************************************************************
966 * FUNCTION: acpi_ev_execute_reg_methods
968 * PARAMETERS: Node - Namespace node for the device
969 * space_id - The address space ID
971 * RETURN: Status
973 * DESCRIPTION: Run all _REG methods for the input Space ID;
974 * Note: assumes namespace is locked, or system init time.
976 ******************************************************************************/
978 acpi_status
979 acpi_ev_execute_reg_methods (
980 struct acpi_namespace_node *node,
981 acpi_adr_space_type space_id)
983 acpi_status status;
986 ACPI_FUNCTION_TRACE ("ev_execute_reg_methods");
990 * Run all _REG methods for all Operation Regions for this
991 * space ID. This is a separate walk in order to handle any
992 * interdependencies between regions and _REG methods. (i.e. handlers
993 * must be installed for all regions of this Space ID before we
994 * can run any _REG methods)
996 status = acpi_ns_walk_namespace (ACPI_TYPE_ANY, node, ACPI_UINT32_MAX,
997 ACPI_NS_WALK_UNLOCK, acpi_ev_reg_run,
998 &space_id, NULL);
1000 return_ACPI_STATUS (status);
1004 /*******************************************************************************
1006 * FUNCTION: acpi_ev_reg_run
1008 * PARAMETERS: walk_namespace callback
1010 * DESCRIPTION: Run _REg method for region objects of the requested space_iD
1012 ******************************************************************************/
1014 acpi_status
1015 acpi_ev_reg_run (
1016 acpi_handle obj_handle,
1017 u32 level,
1018 void *context,
1019 void **return_value)
1021 union acpi_operand_object *obj_desc;
1022 struct acpi_namespace_node *node;
1023 acpi_adr_space_type space_id;
1024 acpi_status status;
1027 space_id = *ACPI_CAST_PTR (acpi_adr_space_type, context);
1029 /* Convert and validate the device handle */
1031 node = acpi_ns_map_handle_to_node (obj_handle);
1032 if (!node) {
1033 return (AE_BAD_PARAMETER);
1037 * We only care about regions.and objects
1038 * that are allowed to have address space handlers
1040 if ((node->type != ACPI_TYPE_REGION) &&
1041 (node != acpi_gbl_root_node)) {
1042 return (AE_OK);
1045 /* Check for an existing internal object */
1047 obj_desc = acpi_ns_get_attached_object (node);
1048 if (!obj_desc) {
1049 /* No object, just exit */
1051 return (AE_OK);
1054 /* Object is a Region */
1056 if (obj_desc->region.space_id != space_id) {
1058 * This region is for a different address space
1059 * -- just ignore it
1061 return (AE_OK);
1064 status = acpi_ev_execute_reg_method (obj_desc, 1);
1065 return (status);