1 /******************************************************************************
3 * Module Name: evregion - ACPI address_space (op_region) handler dispatch
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2011, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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.
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.
44 #include <acpi/acpi.h>
50 #define _COMPONENT ACPI_EVENTS
51 ACPI_MODULE_NAME("evregion")
53 /* Local prototypes */
55 acpi_ev_has_default_handler(struct acpi_namespace_node *node,
56 acpi_adr_space_type space_id);
59 acpi_ev_reg_run(acpi_handle obj_handle,
60 u32 level, void *context, void **return_value);
63 acpi_ev_install_handler(acpi_handle obj_handle,
64 u32 level, void *context, void **return_value);
66 /* These are the address spaces that will get default handlers */
68 #define ACPI_NUM_DEFAULT_SPACES 4
70 static u8 acpi_gbl_default_address_spaces[ACPI_NUM_DEFAULT_SPACES] = {
71 ACPI_ADR_SPACE_SYSTEM_MEMORY,
72 ACPI_ADR_SPACE_SYSTEM_IO,
73 ACPI_ADR_SPACE_PCI_CONFIG,
74 ACPI_ADR_SPACE_DATA_TABLE
77 /*******************************************************************************
79 * FUNCTION: acpi_ev_install_region_handlers
85 * DESCRIPTION: Installs the core subsystem default address space handlers.
87 ******************************************************************************/
89 acpi_status acpi_ev_install_region_handlers(void)
94 ACPI_FUNCTION_TRACE(ev_install_region_handlers);
96 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
97 if (ACPI_FAILURE(status)) {
98 return_ACPI_STATUS(status);
102 * All address spaces (PCI Config, EC, SMBus) are scope dependent and
103 * registration must occur for a specific device.
105 * In the case of the system memory and IO address spaces there is
106 * currently no device associated with the address space. For these we
109 * We install the default PCI config space handler at the root so that
110 * this space is immediately available even though the we have not
111 * enumerated all the PCI Root Buses yet. This is to conform to the ACPI
112 * specification which states that the PCI config space must be always
113 * available -- even though we are nowhere near ready to find the PCI root
114 * buses at this point.
116 * NOTE: We ignore AE_ALREADY_EXISTS because this means that a handler
117 * has already been installed (via acpi_install_address_space_handler).
118 * Similar for AE_SAME_HANDLER.
120 for (i = 0; i < ACPI_NUM_DEFAULT_SPACES; i++) {
121 status = acpi_ev_install_space_handler(acpi_gbl_root_node,
122 acpi_gbl_default_address_spaces
124 ACPI_DEFAULT_HANDLER,
128 case AE_SAME_HANDLER:
129 case AE_ALREADY_EXISTS:
131 /* These exceptions are all OK */
138 goto unlock_and_exit;
143 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
144 return_ACPI_STATUS(status);
147 /*******************************************************************************
149 * FUNCTION: acpi_ev_has_default_handler
151 * PARAMETERS: Node - Namespace node for the device
152 * space_id - The address space ID
154 * RETURN: TRUE if default handler is installed, FALSE otherwise
156 * DESCRIPTION: Check if the default handler is installed for the requested
159 ******************************************************************************/
162 acpi_ev_has_default_handler(struct acpi_namespace_node *node,
163 acpi_adr_space_type space_id)
165 union acpi_operand_object *obj_desc;
166 union acpi_operand_object *handler_obj;
168 /* Must have an existing internal object */
170 obj_desc = acpi_ns_get_attached_object(node);
172 handler_obj = obj_desc->device.handler;
174 /* Walk the linked list of handlers for this object */
176 while (handler_obj) {
177 if (handler_obj->address_space.space_id == space_id) {
178 if (handler_obj->address_space.handler_flags &
179 ACPI_ADDR_HANDLER_DEFAULT_INSTALLED) {
184 handler_obj = handler_obj->address_space.next;
191 /*******************************************************************************
193 * FUNCTION: acpi_ev_initialize_op_regions
199 * DESCRIPTION: Execute _REG methods for all Operation Regions that have
200 * an installed default region handler.
202 ******************************************************************************/
204 acpi_status acpi_ev_initialize_op_regions(void)
209 ACPI_FUNCTION_TRACE(ev_initialize_op_regions);
211 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
212 if (ACPI_FAILURE(status)) {
213 return_ACPI_STATUS(status);
216 /* Run the _REG methods for op_regions in each default address space */
218 for (i = 0; i < ACPI_NUM_DEFAULT_SPACES; i++) {
220 * Make sure the installed handler is the DEFAULT handler. If not the
221 * default, the _REG methods will have already been run (when the
222 * handler was installed)
224 if (acpi_ev_has_default_handler(acpi_gbl_root_node,
225 acpi_gbl_default_address_spaces
228 acpi_ev_execute_reg_methods(acpi_gbl_root_node,
229 acpi_gbl_default_address_spaces
234 acpi_gbl_reg_methods_executed = TRUE;
236 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
237 return_ACPI_STATUS(status);
240 /*******************************************************************************
242 * FUNCTION: acpi_ev_execute_reg_method
244 * PARAMETERS: region_obj - Region object
245 * Function - Passed to _REG: On (1) or Off (0)
249 * DESCRIPTION: Execute _REG method for a region
251 ******************************************************************************/
254 acpi_ev_execute_reg_method(union acpi_operand_object *region_obj, u32 function)
256 struct acpi_evaluate_info *info;
257 union acpi_operand_object *args[3];
258 union acpi_operand_object *region_obj2;
261 ACPI_FUNCTION_TRACE(ev_execute_reg_method);
263 region_obj2 = acpi_ns_get_secondary_object(region_obj);
265 return_ACPI_STATUS(AE_NOT_EXIST);
268 if (region_obj2->extra.method_REG == NULL) {
269 return_ACPI_STATUS(AE_OK);
272 /* Allocate and initialize the evaluation information block */
274 info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info));
276 return_ACPI_STATUS(AE_NO_MEMORY);
279 info->prefix_node = region_obj2->extra.method_REG;
280 info->pathname = NULL;
281 info->parameters = args;
282 info->flags = ACPI_IGNORE_RETURN_VALUE;
285 * The _REG method has two arguments:
288 * Operation region space ID Same value as region_obj->Region.space_id
291 * connection status 1 for connecting the handler, 0 for disconnecting
292 * the handler (Passed as a parameter)
295 acpi_ut_create_integer_object((u64) region_obj->region.space_id);
297 status = AE_NO_MEMORY;
301 args[1] = acpi_ut_create_integer_object((u64) function);
303 status = AE_NO_MEMORY;
307 args[2] = NULL; /* Terminate list */
309 /* Execute the method, no return value */
311 ACPI_DEBUG_EXEC(acpi_ut_display_init_pathname
312 (ACPI_TYPE_METHOD, info->prefix_node, NULL));
314 status = acpi_ns_evaluate(info);
315 acpi_ut_remove_reference(args[1]);
318 acpi_ut_remove_reference(args[0]);
322 return_ACPI_STATUS(status);
325 /*******************************************************************************
327 * FUNCTION: acpi_ev_address_space_dispatch
329 * PARAMETERS: region_obj - Internal region object
330 * Function - Read or Write operation
331 * region_offset - Where in the region to read or write
332 * bit_width - Field width in bits (8, 16, 32, or 64)
333 * Value - Pointer to in or out value, must be
334 * a full 64-bit integer
338 * DESCRIPTION: Dispatch an address space or operation region access to
339 * a previously installed handler.
341 ******************************************************************************/
344 acpi_ev_address_space_dispatch(union acpi_operand_object *region_obj,
346 u32 region_offset, u32 bit_width, u64 *value)
349 acpi_adr_space_handler handler;
350 acpi_adr_space_setup region_setup;
351 union acpi_operand_object *handler_desc;
352 union acpi_operand_object *region_obj2;
353 void *region_context = NULL;
355 ACPI_FUNCTION_TRACE(ev_address_space_dispatch);
357 region_obj2 = acpi_ns_get_secondary_object(region_obj);
359 return_ACPI_STATUS(AE_NOT_EXIST);
362 /* Ensure that there is a handler associated with this region */
364 handler_desc = region_obj->region.handler;
367 "No handler for Region [%4.4s] (%p) [%s]",
368 acpi_ut_get_node_name(region_obj->region.node),
370 acpi_ut_get_region_name(region_obj->region.
373 return_ACPI_STATUS(AE_NOT_EXIST);
377 * It may be the case that the region has never been initialized.
378 * Some types of regions require special init code
380 if (!(region_obj->region.flags & AOPOBJ_SETUP_COMPLETE)) {
382 /* This region has not been initialized yet, do it */
384 region_setup = handler_desc->address_space.setup;
387 /* No initialization routine, exit with error */
390 "No init routine for region(%p) [%s]",
392 acpi_ut_get_region_name(region_obj->region.
394 return_ACPI_STATUS(AE_NOT_EXIST);
398 * We must exit the interpreter because the region setup will
399 * potentially execute control methods (for example, the _REG method
402 acpi_ex_exit_interpreter();
404 status = region_setup(region_obj, ACPI_REGION_ACTIVATE,
405 handler_desc->address_space.context,
408 /* Re-enter the interpreter */
410 acpi_ex_enter_interpreter();
412 /* Check for failure of the Region Setup */
414 if (ACPI_FAILURE(status)) {
415 ACPI_EXCEPTION((AE_INFO, status,
416 "During region initialization: [%s]",
417 acpi_ut_get_region_name(region_obj->
420 return_ACPI_STATUS(status);
423 /* Region initialization may have been completed by region_setup */
425 if (!(region_obj->region.flags & AOPOBJ_SETUP_COMPLETE)) {
426 region_obj->region.flags |= AOPOBJ_SETUP_COMPLETE;
428 if (region_obj2->extra.region_context) {
430 /* The handler for this region was already installed */
432 ACPI_FREE(region_context);
435 * Save the returned context for use in all accesses to
436 * this particular region
438 region_obj2->extra.region_context =
444 /* We have everything we need, we can invoke the address space handler */
446 handler = handler_desc->address_space.handler;
448 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
449 "Handler %p (@%p) Address %8.8X%8.8X [%s]\n",
450 ®ion_obj->region.handler->address_space, handler,
451 ACPI_FORMAT_NATIVE_UINT(region_obj->region.address +
453 acpi_ut_get_region_name(region_obj->region.
456 if (!(handler_desc->address_space.handler_flags &
457 ACPI_ADDR_HANDLER_DEFAULT_INSTALLED)) {
459 * For handlers other than the default (supplied) handlers, we must
460 * exit the interpreter because the handler *might* block -- we don't
461 * know what it will do, so we can't hold the lock on the intepreter.
463 acpi_ex_exit_interpreter();
466 /* Call the handler */
468 status = handler(function,
469 (region_obj->region.address + region_offset),
470 bit_width, value, handler_desc->address_space.context,
471 region_obj2->extra.region_context);
473 if (ACPI_FAILURE(status)) {
474 ACPI_EXCEPTION((AE_INFO, status, "Returned by Handler for [%s]",
475 acpi_ut_get_region_name(region_obj->region.
479 if (!(handler_desc->address_space.handler_flags &
480 ACPI_ADDR_HANDLER_DEFAULT_INSTALLED)) {
482 * We just returned from a non-default handler, we must re-enter the
485 acpi_ex_enter_interpreter();
488 return_ACPI_STATUS(status);
491 /*******************************************************************************
493 * FUNCTION: acpi_ev_detach_region
495 * PARAMETERS: region_obj - Region Object
496 * acpi_ns_is_locked - Namespace Region Already Locked?
500 * DESCRIPTION: Break the association between the handler and the region
501 * this is a two way association.
503 ******************************************************************************/
506 acpi_ev_detach_region(union acpi_operand_object *region_obj,
507 u8 acpi_ns_is_locked)
509 union acpi_operand_object *handler_obj;
510 union acpi_operand_object *obj_desc;
511 union acpi_operand_object **last_obj_ptr;
512 acpi_adr_space_setup region_setup;
513 void **region_context;
514 union acpi_operand_object *region_obj2;
517 ACPI_FUNCTION_TRACE(ev_detach_region);
519 region_obj2 = acpi_ns_get_secondary_object(region_obj);
523 region_context = ®ion_obj2->extra.region_context;
525 /* Get the address handler from the region object */
527 handler_obj = region_obj->region.handler;
530 /* This region has no handler, all done */
535 /* Find this region in the handler's list */
537 obj_desc = handler_obj->address_space.region_list;
538 last_obj_ptr = &handler_obj->address_space.region_list;
542 /* Is this the correct Region? */
544 if (obj_desc == region_obj) {
545 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
546 "Removing Region %p from address handler %p\n",
547 region_obj, handler_obj));
549 /* This is it, remove it from the handler's list */
551 *last_obj_ptr = obj_desc->region.next;
552 obj_desc->region.next = NULL; /* Must clear field */
554 if (acpi_ns_is_locked) {
556 acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
557 if (ACPI_FAILURE(status)) {
562 /* Now stop region accesses by executing the _REG method */
564 status = acpi_ev_execute_reg_method(region_obj, 0);
565 if (ACPI_FAILURE(status)) {
566 ACPI_EXCEPTION((AE_INFO, status,
567 "from region _REG, [%s]",
568 acpi_ut_get_region_name
569 (region_obj->region.space_id)));
572 if (acpi_ns_is_locked) {
574 acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
575 if (ACPI_FAILURE(status)) {
581 * If the region has been activated, call the setup handler with
582 * the deactivate notification
584 if (region_obj->region.flags & AOPOBJ_SETUP_COMPLETE) {
585 region_setup = handler_obj->address_space.setup;
587 region_setup(region_obj,
588 ACPI_REGION_DEACTIVATE,
589 handler_obj->address_space.
590 context, region_context);
592 /* Init routine may fail, Just ignore errors */
594 if (ACPI_FAILURE(status)) {
595 ACPI_EXCEPTION((AE_INFO, status,
596 "from region handler - deactivate, [%s]",
597 acpi_ut_get_region_name
602 region_obj->region.flags &=
603 ~(AOPOBJ_SETUP_COMPLETE);
607 * Remove handler reference in the region
609 * NOTE: this doesn't mean that the region goes away, the region
610 * is just inaccessible as indicated to the _REG method
612 * If the region is on the handler's list, this must be the
615 region_obj->region.handler = NULL;
616 acpi_ut_remove_reference(handler_obj);
621 /* Walk the linked list of handlers */
623 last_obj_ptr = &obj_desc->region.next;
624 obj_desc = obj_desc->region.next;
627 /* If we get here, the region was not in the handler's region list */
629 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
630 "Cannot remove region %p from address handler %p\n",
631 region_obj, handler_obj));
636 /*******************************************************************************
638 * FUNCTION: acpi_ev_attach_region
640 * PARAMETERS: handler_obj - Handler Object
641 * region_obj - Region Object
642 * acpi_ns_is_locked - Namespace Region Already Locked?
646 * DESCRIPTION: Create the association between the handler and the region
647 * this is a two way association.
649 ******************************************************************************/
652 acpi_ev_attach_region(union acpi_operand_object *handler_obj,
653 union acpi_operand_object *region_obj,
654 u8 acpi_ns_is_locked)
657 ACPI_FUNCTION_TRACE(ev_attach_region);
659 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
660 "Adding Region [%4.4s] %p to address handler %p [%s]\n",
661 acpi_ut_get_node_name(region_obj->region.node),
662 region_obj, handler_obj,
663 acpi_ut_get_region_name(region_obj->region.
666 /* Link this region to the front of the handler's list */
668 region_obj->region.next = handler_obj->address_space.region_list;
669 handler_obj->address_space.region_list = region_obj;
671 /* Install the region's handler */
673 if (region_obj->region.handler) {
674 return_ACPI_STATUS(AE_ALREADY_EXISTS);
677 region_obj->region.handler = handler_obj;
678 acpi_ut_add_reference(handler_obj);
680 return_ACPI_STATUS(AE_OK);
683 /*******************************************************************************
685 * FUNCTION: acpi_ev_install_handler
687 * PARAMETERS: walk_namespace callback
689 * DESCRIPTION: This routine installs an address handler into objects that are
690 * of type Region or Device.
692 * If the Object is a Device, and the device has a handler of
693 * the same type then the search is terminated in that branch.
695 * This is because the existing handler is closer in proximity
696 * to any more regions than the one we are trying to install.
698 ******************************************************************************/
701 acpi_ev_install_handler(acpi_handle obj_handle,
702 u32 level, void *context, void **return_value)
704 union acpi_operand_object *handler_obj;
705 union acpi_operand_object *next_handler_obj;
706 union acpi_operand_object *obj_desc;
707 struct acpi_namespace_node *node;
710 ACPI_FUNCTION_NAME(ev_install_handler);
712 handler_obj = (union acpi_operand_object *)context;
714 /* Parameter validation */
720 /* Convert and validate the device handle */
722 node = acpi_ns_validate_handle(obj_handle);
724 return (AE_BAD_PARAMETER);
728 * We only care about regions and objects that are allowed to have
729 * address space handlers
731 if ((node->type != ACPI_TYPE_DEVICE) &&
732 (node->type != ACPI_TYPE_REGION) && (node != acpi_gbl_root_node)) {
736 /* Check for an existing internal object */
738 obj_desc = acpi_ns_get_attached_object(node);
741 /* No object, just exit */
746 /* Devices are handled different than regions */
748 if (obj_desc->common.type == ACPI_TYPE_DEVICE) {
750 /* Check if this Device already has a handler for this address space */
752 next_handler_obj = obj_desc->device.handler;
753 while (next_handler_obj) {
755 /* Found a handler, is it for the same address space? */
757 if (next_handler_obj->address_space.space_id ==
758 handler_obj->address_space.space_id) {
759 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
760 "Found handler for region [%s] in device %p(%p) "
762 acpi_ut_get_region_name
763 (handler_obj->address_space.
769 * Since the object we found it on was a device, then it
770 * means that someone has already installed a handler for
771 * the branch of the namespace from this device on. Just
772 * bail out telling the walk routine to not traverse this
773 * branch. This preserves the scoping rule for handlers.
775 return (AE_CTRL_DEPTH);
778 /* Walk the linked list of handlers attached to this device */
780 next_handler_obj = next_handler_obj->address_space.next;
784 * As long as the device didn't have a handler for this space we
785 * don't care about it. We just ignore it and proceed.
790 /* Object is a Region */
792 if (obj_desc->region.space_id != handler_obj->address_space.space_id) {
794 /* This region is for a different address space, just ignore it */
800 * Now we have a region and it is for the handler's address space type.
802 * First disconnect region for any previous handler (if any)
804 acpi_ev_detach_region(obj_desc, FALSE);
806 /* Connect the region to the new handler */
808 status = acpi_ev_attach_region(handler_obj, obj_desc, FALSE);
812 /*******************************************************************************
814 * FUNCTION: acpi_ev_install_space_handler
816 * PARAMETERS: Node - Namespace node for the device
817 * space_id - The address space ID
818 * Handler - Address of the handler
819 * Setup - Address of the setup function
820 * Context - Value passed to the handler on each access
824 * DESCRIPTION: Install a handler for all op_regions of a given space_id.
825 * Assumes namespace is locked
827 ******************************************************************************/
830 acpi_ev_install_space_handler(struct acpi_namespace_node * node,
831 acpi_adr_space_type space_id,
832 acpi_adr_space_handler handler,
833 acpi_adr_space_setup setup, void *context)
835 union acpi_operand_object *obj_desc;
836 union acpi_operand_object *handler_obj;
838 acpi_object_type type;
841 ACPI_FUNCTION_TRACE(ev_install_space_handler);
844 * This registration is valid for only the types below and the root. This
845 * is where the default handlers get placed.
847 if ((node->type != ACPI_TYPE_DEVICE) &&
848 (node->type != ACPI_TYPE_PROCESSOR) &&
849 (node->type != ACPI_TYPE_THERMAL) && (node != acpi_gbl_root_node)) {
850 status = AE_BAD_PARAMETER;
851 goto unlock_and_exit;
854 if (handler == ACPI_DEFAULT_HANDLER) {
855 flags = ACPI_ADDR_HANDLER_DEFAULT_INSTALLED;
858 case ACPI_ADR_SPACE_SYSTEM_MEMORY:
859 handler = acpi_ex_system_memory_space_handler;
860 setup = acpi_ev_system_memory_region_setup;
863 case ACPI_ADR_SPACE_SYSTEM_IO:
864 handler = acpi_ex_system_io_space_handler;
865 setup = acpi_ev_io_space_region_setup;
868 case ACPI_ADR_SPACE_PCI_CONFIG:
869 handler = acpi_ex_pci_config_space_handler;
870 setup = acpi_ev_pci_config_region_setup;
873 case ACPI_ADR_SPACE_CMOS:
874 handler = acpi_ex_cmos_space_handler;
875 setup = acpi_ev_cmos_region_setup;
878 case ACPI_ADR_SPACE_PCI_BAR_TARGET:
879 handler = acpi_ex_pci_bar_space_handler;
880 setup = acpi_ev_pci_bar_region_setup;
883 case ACPI_ADR_SPACE_DATA_TABLE:
884 handler = acpi_ex_data_table_space_handler;
889 status = AE_BAD_PARAMETER;
890 goto unlock_and_exit;
894 /* If the caller hasn't specified a setup routine, use the default */
897 setup = acpi_ev_default_region_setup;
900 /* Check for an existing internal object */
902 obj_desc = acpi_ns_get_attached_object(node);
905 * The attached device object already exists. Make sure the handler
906 * is not already installed.
908 handler_obj = obj_desc->device.handler;
910 /* Walk the handler list for this device */
912 while (handler_obj) {
914 /* Same space_id indicates a handler already installed */
916 if (handler_obj->address_space.space_id == space_id) {
917 if (handler_obj->address_space.handler ==
920 * It is (relatively) OK to attempt to install the SAME
921 * handler twice. This can easily happen with the
924 status = AE_SAME_HANDLER;
925 goto unlock_and_exit;
927 /* A handler is already installed */
929 status = AE_ALREADY_EXISTS;
931 goto unlock_and_exit;
934 /* Walk the linked list of handlers */
936 handler_obj = handler_obj->address_space.next;
939 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
940 "Creating object on Device %p while installing handler\n",
943 /* obj_desc does not exist, create one */
945 if (node->type == ACPI_TYPE_ANY) {
946 type = ACPI_TYPE_DEVICE;
951 obj_desc = acpi_ut_create_internal_object(type);
953 status = AE_NO_MEMORY;
954 goto unlock_and_exit;
957 /* Init new descriptor */
959 obj_desc->common.type = (u8) type;
961 /* Attach the new object to the Node */
963 status = acpi_ns_attach_object(node, obj_desc, type);
965 /* Remove local reference to the object */
967 acpi_ut_remove_reference(obj_desc);
969 if (ACPI_FAILURE(status)) {
970 goto unlock_and_exit;
974 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
975 "Installing address handler for region %s(%X) on Device %4.4s %p(%p)\n",
976 acpi_ut_get_region_name(space_id), space_id,
977 acpi_ut_get_node_name(node), node, obj_desc));
980 * Install the handler
982 * At this point there is no existing handler. Just allocate the object
983 * for the handler and link it into the list.
986 acpi_ut_create_internal_object(ACPI_TYPE_LOCAL_ADDRESS_HANDLER);
988 status = AE_NO_MEMORY;
989 goto unlock_and_exit;
992 /* Init handler obj */
994 handler_obj->address_space.space_id = (u8) space_id;
995 handler_obj->address_space.handler_flags = flags;
996 handler_obj->address_space.region_list = NULL;
997 handler_obj->address_space.node = node;
998 handler_obj->address_space.handler = handler;
999 handler_obj->address_space.context = context;
1000 handler_obj->address_space.setup = setup;
1002 /* Install at head of Device.address_space list */
1004 handler_obj->address_space.next = obj_desc->device.handler;
1007 * The Device object is the first reference on the handler_obj.
1008 * Each region that uses the handler adds a reference.
1010 obj_desc->device.handler = handler_obj;
1013 * Walk the namespace finding all of the regions this
1014 * handler will manage.
1016 * Start at the device and search the branch toward
1017 * the leaf nodes until either the leaf is encountered or
1018 * a device is detected that has an address handler of the
1021 * In either case, back up and search down the remainder
1024 status = acpi_ns_walk_namespace(ACPI_TYPE_ANY, node, ACPI_UINT32_MAX,
1025 ACPI_NS_WALK_UNLOCK,
1026 acpi_ev_install_handler, NULL,
1030 return_ACPI_STATUS(status);
1033 /*******************************************************************************
1035 * FUNCTION: acpi_ev_execute_reg_methods
1037 * PARAMETERS: Node - Namespace node for the device
1038 * space_id - The address space ID
1042 * DESCRIPTION: Run all _REG methods for the input Space ID;
1043 * Note: assumes namespace is locked, or system init time.
1045 ******************************************************************************/
1048 acpi_ev_execute_reg_methods(struct acpi_namespace_node *node,
1049 acpi_adr_space_type space_id)
1053 ACPI_FUNCTION_TRACE(ev_execute_reg_methods);
1056 * Run all _REG methods for all Operation Regions for this space ID. This
1057 * is a separate walk in order to handle any interdependencies between
1058 * regions and _REG methods. (i.e. handlers must be installed for all
1059 * regions of this Space ID before we can run any _REG methods)
1061 status = acpi_ns_walk_namespace(ACPI_TYPE_ANY, node, ACPI_UINT32_MAX,
1062 ACPI_NS_WALK_UNLOCK, acpi_ev_reg_run,
1063 NULL, &space_id, NULL);
1065 return_ACPI_STATUS(status);
1068 /*******************************************************************************
1070 * FUNCTION: acpi_ev_reg_run
1072 * PARAMETERS: walk_namespace callback
1074 * DESCRIPTION: Run _REG method for region objects of the requested space_iD
1076 ******************************************************************************/
1079 acpi_ev_reg_run(acpi_handle obj_handle,
1080 u32 level, void *context, void **return_value)
1082 union acpi_operand_object *obj_desc;
1083 struct acpi_namespace_node *node;
1084 acpi_adr_space_type space_id;
1087 space_id = *ACPI_CAST_PTR(acpi_adr_space_type, context);
1089 /* Convert and validate the device handle */
1091 node = acpi_ns_validate_handle(obj_handle);
1093 return (AE_BAD_PARAMETER);
1097 * We only care about regions.and objects that are allowed to have address
1100 if ((node->type != ACPI_TYPE_REGION) && (node != acpi_gbl_root_node)) {
1104 /* Check for an existing internal object */
1106 obj_desc = acpi_ns_get_attached_object(node);
1109 /* No object, just exit */
1114 /* Object is a Region */
1116 if (obj_desc->region.space_id != space_id) {
1118 /* This region is for a different address space, just ignore it */
1123 status = acpi_ev_execute_reg_method(obj_desc, 1);