1 /******************************************************************************
3 * Module Name: evregion - ACPI address_space (op_region) handler dispatch
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2008, 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_reg_run(acpi_handle obj_handle,
56 u32 level, void *context, void **return_value);
59 acpi_ev_install_handler(acpi_handle obj_handle,
60 u32 level, void *context, void **return_value);
62 /* These are the address spaces that will get default handlers */
64 #define ACPI_NUM_DEFAULT_SPACES 4
66 static u8 acpi_gbl_default_address_spaces[ACPI_NUM_DEFAULT_SPACES] = {
67 ACPI_ADR_SPACE_SYSTEM_MEMORY,
68 ACPI_ADR_SPACE_SYSTEM_IO,
69 ACPI_ADR_SPACE_PCI_CONFIG,
70 ACPI_ADR_SPACE_DATA_TABLE
73 /*******************************************************************************
75 * FUNCTION: acpi_ev_install_region_handlers
81 * DESCRIPTION: Installs the core subsystem default address space handlers.
83 ******************************************************************************/
85 acpi_status acpi_ev_install_region_handlers(void)
90 ACPI_FUNCTION_TRACE(ev_install_region_handlers);
92 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
93 if (ACPI_FAILURE(status)) {
94 return_ACPI_STATUS(status);
98 * All address spaces (PCI Config, EC, SMBus) are scope dependent and
99 * registration must occur for a specific device.
101 * In the case of the system memory and IO address spaces there is
102 * currently no device associated with the address space. For these we
105 * We install the default PCI config space handler at the root so that
106 * this space is immediately available even though the we have not
107 * enumerated all the PCI Root Buses yet. This is to conform to the ACPI
108 * specification which states that the PCI config space must be always
109 * available -- even though we are nowhere near ready to find the PCI root
110 * buses at this point.
112 * NOTE: We ignore AE_ALREADY_EXISTS because this means that a handler
113 * has already been installed (via acpi_install_address_space_handler).
114 * Similar for AE_SAME_HANDLER.
116 for (i = 0; i < ACPI_NUM_DEFAULT_SPACES; i++) {
117 status = acpi_ev_install_space_handler(acpi_gbl_root_node,
118 acpi_gbl_default_address_spaces
120 ACPI_DEFAULT_HANDLER,
124 case AE_SAME_HANDLER:
125 case AE_ALREADY_EXISTS:
127 /* These exceptions are all OK */
134 goto unlock_and_exit;
139 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
140 return_ACPI_STATUS(status);
143 /*******************************************************************************
145 * FUNCTION: acpi_ev_initialize_op_regions
151 * DESCRIPTION: Execute _REG methods for all Operation Regions that have
152 * an installed default region handler.
154 ******************************************************************************/
156 acpi_status acpi_ev_initialize_op_regions(void)
161 ACPI_FUNCTION_TRACE(ev_initialize_op_regions);
163 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
164 if (ACPI_FAILURE(status)) {
165 return_ACPI_STATUS(status);
168 /* Run the _REG methods for op_regions in each default address space */
170 for (i = 0; i < ACPI_NUM_DEFAULT_SPACES; i++) {
172 * TBD: Make sure handler is the DEFAULT handler, otherwise
173 * _REG will have already been run.
175 status = acpi_ev_execute_reg_methods(acpi_gbl_root_node,
176 acpi_gbl_default_address_spaces
180 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
181 return_ACPI_STATUS(status);
184 /*******************************************************************************
186 * FUNCTION: acpi_ev_execute_reg_method
188 * PARAMETERS: region_obj - Region object
189 * Function - Passed to _REG: On (1) or Off (0)
193 * DESCRIPTION: Execute _REG method for a region
195 ******************************************************************************/
198 acpi_ev_execute_reg_method(union acpi_operand_object *region_obj, u32 function)
200 struct acpi_evaluate_info *info;
201 union acpi_operand_object *args[3];
202 union acpi_operand_object *region_obj2;
205 ACPI_FUNCTION_TRACE(ev_execute_reg_method);
207 region_obj2 = acpi_ns_get_secondary_object(region_obj);
209 return_ACPI_STATUS(AE_NOT_EXIST);
212 if (region_obj2->extra.method_REG == NULL) {
213 return_ACPI_STATUS(AE_OK);
216 /* Allocate and initialize the evaluation information block */
218 info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info));
220 return_ACPI_STATUS(AE_NO_MEMORY);
223 info->prefix_node = region_obj2->extra.method_REG;
224 info->pathname = NULL;
225 info->parameters = args;
226 info->flags = ACPI_IGNORE_RETURN_VALUE;
229 * The _REG method has two arguments:
232 * Operation region space ID Same value as region_obj->Region.space_id
235 * connection status 1 for connecting the handler, 0 for disconnecting
236 * the handler (Passed as a parameter)
238 args[0] = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER);
240 status = AE_NO_MEMORY;
244 args[1] = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER);
246 status = AE_NO_MEMORY;
250 /* Setup the parameter objects */
252 args[0]->integer.value = region_obj->region.space_id;
253 args[1]->integer.value = function;
256 /* Execute the method, no return value */
258 ACPI_DEBUG_EXEC(acpi_ut_display_init_pathname
259 (ACPI_TYPE_METHOD, info->prefix_node, NULL));
261 status = acpi_ns_evaluate(info);
262 acpi_ut_remove_reference(args[1]);
265 acpi_ut_remove_reference(args[0]);
269 return_ACPI_STATUS(status);
272 /*******************************************************************************
274 * FUNCTION: acpi_ev_address_space_dispatch
276 * PARAMETERS: region_obj - Internal region object
277 * Function - Read or Write operation
278 * Address - Where in the space to read or write
279 * bit_width - Field width in bits (8, 16, 32, or 64)
280 * Value - Pointer to in or out value, must be
281 * full 64-bit acpi_integer
285 * DESCRIPTION: Dispatch an address space or operation region access to
286 * a previously installed handler.
288 ******************************************************************************/
291 acpi_ev_address_space_dispatch(union acpi_operand_object *region_obj,
293 acpi_physical_address address,
294 u32 bit_width, acpi_integer * value)
297 acpi_adr_space_handler handler;
298 acpi_adr_space_setup region_setup;
299 union acpi_operand_object *handler_desc;
300 union acpi_operand_object *region_obj2;
301 void *region_context = NULL;
303 ACPI_FUNCTION_TRACE(ev_address_space_dispatch);
305 region_obj2 = acpi_ns_get_secondary_object(region_obj);
307 return_ACPI_STATUS(AE_NOT_EXIST);
310 /* Ensure that there is a handler associated with this region */
312 handler_desc = region_obj->region.handler;
315 "No handler for Region [%4.4s] (%p) [%s]",
316 acpi_ut_get_node_name(region_obj->region.node),
318 acpi_ut_get_region_name(region_obj->region.
321 return_ACPI_STATUS(AE_NOT_EXIST);
325 * It may be the case that the region has never been initialized.
326 * Some types of regions require special init code
328 if (!(region_obj->region.flags & AOPOBJ_SETUP_COMPLETE)) {
330 /* This region has not been initialized yet, do it */
332 region_setup = handler_desc->address_space.setup;
335 /* No initialization routine, exit with error */
338 "No init routine for region(%p) [%s]",
340 acpi_ut_get_region_name(region_obj->region.
342 return_ACPI_STATUS(AE_NOT_EXIST);
346 * We must exit the interpreter because the region setup will
347 * potentially execute control methods (for example, the _REG method
350 acpi_ex_exit_interpreter();
352 status = region_setup(region_obj, ACPI_REGION_ACTIVATE,
353 handler_desc->address_space.context,
356 /* Re-enter the interpreter */
358 acpi_ex_enter_interpreter();
360 /* Check for failure of the Region Setup */
362 if (ACPI_FAILURE(status)) {
363 ACPI_EXCEPTION((AE_INFO, status,
364 "During region initialization: [%s]",
365 acpi_ut_get_region_name(region_obj->
368 return_ACPI_STATUS(status);
371 /* Region initialization may have been completed by region_setup */
373 if (!(region_obj->region.flags & AOPOBJ_SETUP_COMPLETE)) {
374 region_obj->region.flags |= AOPOBJ_SETUP_COMPLETE;
376 if (region_obj2->extra.region_context) {
378 /* The handler for this region was already installed */
380 ACPI_FREE(region_context);
383 * Save the returned context for use in all accesses to
384 * this particular region
386 region_obj2->extra.region_context =
392 /* We have everything we need, we can invoke the address space handler */
394 handler = handler_desc->address_space.handler;
396 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
397 "Handler %p (@%p) Address %8.8X%8.8X [%s]\n",
398 ®ion_obj->region.handler->address_space, handler,
399 ACPI_FORMAT_NATIVE_UINT(address),
400 acpi_ut_get_region_name(region_obj->region.
403 if (!(handler_desc->address_space.handler_flags &
404 ACPI_ADDR_HANDLER_DEFAULT_INSTALLED)) {
406 * For handlers other than the default (supplied) handlers, we must
407 * exit the interpreter because the handler *might* block -- we don't
408 * know what it will do, so we can't hold the lock on the intepreter.
410 acpi_ex_exit_interpreter();
413 /* Call the handler */
415 status = handler(function, address, bit_width, value,
416 handler_desc->address_space.context,
417 region_obj2->extra.region_context);
419 if (ACPI_FAILURE(status)) {
420 ACPI_EXCEPTION((AE_INFO, status, "Returned by Handler for [%s]",
421 acpi_ut_get_region_name(region_obj->region.
425 if (!(handler_desc->address_space.handler_flags &
426 ACPI_ADDR_HANDLER_DEFAULT_INSTALLED)) {
428 * We just returned from a non-default handler, we must re-enter the
431 acpi_ex_enter_interpreter();
434 return_ACPI_STATUS(status);
437 /*******************************************************************************
439 * FUNCTION: acpi_ev_detach_region
441 * PARAMETERS: region_obj - Region Object
442 * acpi_ns_is_locked - Namespace Region Already Locked?
446 * DESCRIPTION: Break the association between the handler and the region
447 * this is a two way association.
449 ******************************************************************************/
452 acpi_ev_detach_region(union acpi_operand_object *region_obj,
453 u8 acpi_ns_is_locked)
455 union acpi_operand_object *handler_obj;
456 union acpi_operand_object *obj_desc;
457 union acpi_operand_object **last_obj_ptr;
458 acpi_adr_space_setup region_setup;
459 void **region_context;
460 union acpi_operand_object *region_obj2;
463 ACPI_FUNCTION_TRACE(ev_detach_region);
465 region_obj2 = acpi_ns_get_secondary_object(region_obj);
469 region_context = ®ion_obj2->extra.region_context;
471 /* Get the address handler from the region object */
473 handler_obj = region_obj->region.handler;
476 /* This region has no handler, all done */
481 /* Find this region in the handler's list */
483 obj_desc = handler_obj->address_space.region_list;
484 last_obj_ptr = &handler_obj->address_space.region_list;
488 /* Is this the correct Region? */
490 if (obj_desc == region_obj) {
491 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
492 "Removing Region %p from address handler %p\n",
493 region_obj, handler_obj));
495 /* This is it, remove it from the handler's list */
497 *last_obj_ptr = obj_desc->region.next;
498 obj_desc->region.next = NULL; /* Must clear field */
500 if (acpi_ns_is_locked) {
502 acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
503 if (ACPI_FAILURE(status)) {
508 /* Now stop region accesses by executing the _REG method */
510 status = acpi_ev_execute_reg_method(region_obj, 0);
511 if (ACPI_FAILURE(status)) {
512 ACPI_EXCEPTION((AE_INFO, status,
513 "from region _REG, [%s]",
514 acpi_ut_get_region_name
515 (region_obj->region.space_id)));
518 if (acpi_ns_is_locked) {
520 acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
521 if (ACPI_FAILURE(status)) {
527 * If the region has been activated, call the setup handler with
528 * the deactivate notification
530 if (region_obj->region.flags & AOPOBJ_SETUP_COMPLETE) {
531 region_setup = handler_obj->address_space.setup;
533 region_setup(region_obj,
534 ACPI_REGION_DEACTIVATE,
535 handler_obj->address_space.
536 context, region_context);
538 /* Init routine may fail, Just ignore errors */
540 if (ACPI_FAILURE(status)) {
541 ACPI_EXCEPTION((AE_INFO, status,
542 "from region handler - deactivate, [%s]",
543 acpi_ut_get_region_name
548 region_obj->region.flags &=
549 ~(AOPOBJ_SETUP_COMPLETE);
553 * Remove handler reference in the region
555 * NOTE: this doesn't mean that the region goes away, the region
556 * is just inaccessible as indicated to the _REG method
558 * If the region is on the handler's list, this must be the
561 region_obj->region.handler = NULL;
562 acpi_ut_remove_reference(handler_obj);
567 /* Walk the linked list of handlers */
569 last_obj_ptr = &obj_desc->region.next;
570 obj_desc = obj_desc->region.next;
573 /* If we get here, the region was not in the handler's region list */
575 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
576 "Cannot remove region %p from address handler %p\n",
577 region_obj, handler_obj));
582 /*******************************************************************************
584 * FUNCTION: acpi_ev_attach_region
586 * PARAMETERS: handler_obj - Handler Object
587 * region_obj - Region Object
588 * acpi_ns_is_locked - Namespace Region Already Locked?
592 * DESCRIPTION: Create the association between the handler and the region
593 * this is a two way association.
595 ******************************************************************************/
598 acpi_ev_attach_region(union acpi_operand_object *handler_obj,
599 union acpi_operand_object *region_obj,
600 u8 acpi_ns_is_locked)
603 ACPI_FUNCTION_TRACE(ev_attach_region);
605 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
606 "Adding Region [%4.4s] %p to address handler %p [%s]\n",
607 acpi_ut_get_node_name(region_obj->region.node),
608 region_obj, handler_obj,
609 acpi_ut_get_region_name(region_obj->region.
612 /* Link this region to the front of the handler's list */
614 region_obj->region.next = handler_obj->address_space.region_list;
615 handler_obj->address_space.region_list = region_obj;
617 /* Install the region's handler */
619 if (region_obj->region.handler) {
620 return_ACPI_STATUS(AE_ALREADY_EXISTS);
623 region_obj->region.handler = handler_obj;
624 acpi_ut_add_reference(handler_obj);
626 return_ACPI_STATUS(AE_OK);
629 /*******************************************************************************
631 * FUNCTION: acpi_ev_install_handler
633 * PARAMETERS: walk_namespace callback
635 * DESCRIPTION: This routine installs an address handler into objects that are
636 * of type Region or Device.
638 * If the Object is a Device, and the device has a handler of
639 * the same type then the search is terminated in that branch.
641 * This is because the existing handler is closer in proximity
642 * to any more regions than the one we are trying to install.
644 ******************************************************************************/
647 acpi_ev_install_handler(acpi_handle obj_handle,
648 u32 level, void *context, void **return_value)
650 union acpi_operand_object *handler_obj;
651 union acpi_operand_object *next_handler_obj;
652 union acpi_operand_object *obj_desc;
653 struct acpi_namespace_node *node;
656 ACPI_FUNCTION_NAME(ev_install_handler);
658 handler_obj = (union acpi_operand_object *)context;
660 /* Parameter validation */
666 /* Convert and validate the device handle */
668 node = acpi_ns_map_handle_to_node(obj_handle);
670 return (AE_BAD_PARAMETER);
674 * We only care about regions and objects that are allowed to have
675 * address space handlers
677 if ((node->type != ACPI_TYPE_DEVICE) &&
678 (node->type != ACPI_TYPE_REGION) && (node != acpi_gbl_root_node)) {
682 /* Check for an existing internal object */
684 obj_desc = acpi_ns_get_attached_object(node);
687 /* No object, just exit */
692 /* Devices are handled different than regions */
694 if (obj_desc->common.type == ACPI_TYPE_DEVICE) {
696 /* Check if this Device already has a handler for this address space */
698 next_handler_obj = obj_desc->device.handler;
699 while (next_handler_obj) {
701 /* Found a handler, is it for the same address space? */
703 if (next_handler_obj->address_space.space_id ==
704 handler_obj->address_space.space_id) {
705 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
706 "Found handler for region [%s] in device %p(%p) "
708 acpi_ut_get_region_name
709 (handler_obj->address_space.
715 * Since the object we found it on was a device, then it
716 * means that someone has already installed a handler for
717 * the branch of the namespace from this device on. Just
718 * bail out telling the walk routine to not traverse this
719 * branch. This preserves the scoping rule for handlers.
721 return (AE_CTRL_DEPTH);
724 /* Walk the linked list of handlers attached to this device */
726 next_handler_obj = next_handler_obj->address_space.next;
730 * As long as the device didn't have a handler for this space we
731 * don't care about it. We just ignore it and proceed.
736 /* Object is a Region */
738 if (obj_desc->region.space_id != handler_obj->address_space.space_id) {
740 /* This region is for a different address space, just ignore it */
746 * Now we have a region and it is for the handler's address space type.
748 * First disconnect region for any previous handler (if any)
750 acpi_ev_detach_region(obj_desc, FALSE);
752 /* Connect the region to the new handler */
754 status = acpi_ev_attach_region(handler_obj, obj_desc, FALSE);
758 /*******************************************************************************
760 * FUNCTION: acpi_ev_install_space_handler
762 * PARAMETERS: Node - Namespace node for the device
763 * space_id - The address space ID
764 * Handler - Address of the handler
765 * Setup - Address of the setup function
766 * Context - Value passed to the handler on each access
770 * DESCRIPTION: Install a handler for all op_regions of a given space_id.
771 * Assumes namespace is locked
773 ******************************************************************************/
776 acpi_ev_install_space_handler(struct acpi_namespace_node * node,
777 acpi_adr_space_type space_id,
778 acpi_adr_space_handler handler,
779 acpi_adr_space_setup setup, void *context)
781 union acpi_operand_object *obj_desc;
782 union acpi_operand_object *handler_obj;
784 acpi_object_type type;
787 ACPI_FUNCTION_TRACE(ev_install_space_handler);
790 * This registration is valid for only the types below and the root. This
791 * is where the default handlers get placed.
793 if ((node->type != ACPI_TYPE_DEVICE) &&
794 (node->type != ACPI_TYPE_PROCESSOR) &&
795 (node->type != ACPI_TYPE_THERMAL) && (node != acpi_gbl_root_node)) {
796 status = AE_BAD_PARAMETER;
797 goto unlock_and_exit;
800 if (handler == ACPI_DEFAULT_HANDLER) {
801 flags = ACPI_ADDR_HANDLER_DEFAULT_INSTALLED;
804 case ACPI_ADR_SPACE_SYSTEM_MEMORY:
805 handler = acpi_ex_system_memory_space_handler;
806 setup = acpi_ev_system_memory_region_setup;
809 case ACPI_ADR_SPACE_SYSTEM_IO:
810 handler = acpi_ex_system_io_space_handler;
811 setup = acpi_ev_io_space_region_setup;
814 case ACPI_ADR_SPACE_PCI_CONFIG:
815 handler = acpi_ex_pci_config_space_handler;
816 setup = acpi_ev_pci_config_region_setup;
819 case ACPI_ADR_SPACE_CMOS:
820 handler = acpi_ex_cmos_space_handler;
821 setup = acpi_ev_cmos_region_setup;
824 case ACPI_ADR_SPACE_PCI_BAR_TARGET:
825 handler = acpi_ex_pci_bar_space_handler;
826 setup = acpi_ev_pci_bar_region_setup;
829 case ACPI_ADR_SPACE_DATA_TABLE:
830 handler = acpi_ex_data_table_space_handler;
835 status = AE_BAD_PARAMETER;
836 goto unlock_and_exit;
840 /* If the caller hasn't specified a setup routine, use the default */
843 setup = acpi_ev_default_region_setup;
846 /* Check for an existing internal object */
848 obj_desc = acpi_ns_get_attached_object(node);
851 * The attached device object already exists. Make sure the handler
852 * is not already installed.
854 handler_obj = obj_desc->device.handler;
856 /* Walk the handler list for this device */
858 while (handler_obj) {
860 /* Same space_id indicates a handler already installed */
862 if (handler_obj->address_space.space_id == space_id) {
863 if (handler_obj->address_space.handler ==
866 * It is (relatively) OK to attempt to install the SAME
867 * handler twice. This can easily happen with the
870 status = AE_SAME_HANDLER;
871 goto unlock_and_exit;
873 /* A handler is already installed */
875 status = AE_ALREADY_EXISTS;
877 goto unlock_and_exit;
880 /* Walk the linked list of handlers */
882 handler_obj = handler_obj->address_space.next;
885 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
886 "Creating object on Device %p while installing handler\n",
889 /* obj_desc does not exist, create one */
891 if (node->type == ACPI_TYPE_ANY) {
892 type = ACPI_TYPE_DEVICE;
897 obj_desc = acpi_ut_create_internal_object(type);
899 status = AE_NO_MEMORY;
900 goto unlock_and_exit;
903 /* Init new descriptor */
905 obj_desc->common.type = (u8) type;
907 /* Attach the new object to the Node */
909 status = acpi_ns_attach_object(node, obj_desc, type);
911 /* Remove local reference to the object */
913 acpi_ut_remove_reference(obj_desc);
915 if (ACPI_FAILURE(status)) {
916 goto unlock_and_exit;
920 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
921 "Installing address handler for region %s(%X) on Device %4.4s %p(%p)\n",
922 acpi_ut_get_region_name(space_id), space_id,
923 acpi_ut_get_node_name(node), node, obj_desc));
926 * Install the handler
928 * At this point there is no existing handler. Just allocate the object
929 * for the handler and link it into the list.
932 acpi_ut_create_internal_object(ACPI_TYPE_LOCAL_ADDRESS_HANDLER);
934 status = AE_NO_MEMORY;
935 goto unlock_and_exit;
938 /* Init handler obj */
940 handler_obj->address_space.space_id = (u8) space_id;
941 handler_obj->address_space.handler_flags = flags;
942 handler_obj->address_space.region_list = NULL;
943 handler_obj->address_space.node = node;
944 handler_obj->address_space.handler = handler;
945 handler_obj->address_space.context = context;
946 handler_obj->address_space.setup = setup;
948 /* Install at head of Device.address_space list */
950 handler_obj->address_space.next = obj_desc->device.handler;
953 * The Device object is the first reference on the handler_obj.
954 * Each region that uses the handler adds a reference.
956 obj_desc->device.handler = handler_obj;
959 * Walk the namespace finding all of the regions this
960 * handler will manage.
962 * Start at the device and search the branch toward
963 * the leaf nodes until either the leaf is encountered or
964 * a device is detected that has an address handler of the
967 * In either case, back up and search down the remainder
970 status = acpi_ns_walk_namespace(ACPI_TYPE_ANY, node, ACPI_UINT32_MAX,
972 acpi_ev_install_handler, handler_obj,
976 return_ACPI_STATUS(status);
979 /*******************************************************************************
981 * FUNCTION: acpi_ev_execute_reg_methods
983 * PARAMETERS: Node - Namespace node for the device
984 * space_id - The address space ID
988 * DESCRIPTION: Run all _REG methods for the input Space ID;
989 * Note: assumes namespace is locked, or system init time.
991 ******************************************************************************/
994 acpi_ev_execute_reg_methods(struct acpi_namespace_node *node,
995 acpi_adr_space_type space_id)
999 ACPI_FUNCTION_TRACE(ev_execute_reg_methods);
1002 * Run all _REG methods for all Operation Regions for this space ID. This
1003 * is a separate walk in order to handle any interdependencies between
1004 * regions and _REG methods. (i.e. handlers must be installed for all
1005 * regions of this Space ID before we can run any _REG methods)
1007 status = acpi_ns_walk_namespace(ACPI_TYPE_ANY, node, ACPI_UINT32_MAX,
1008 ACPI_NS_WALK_UNLOCK, acpi_ev_reg_run,
1011 return_ACPI_STATUS(status);
1014 /*******************************************************************************
1016 * FUNCTION: acpi_ev_reg_run
1018 * PARAMETERS: walk_namespace callback
1020 * DESCRIPTION: Run _REG method for region objects of the requested space_iD
1022 ******************************************************************************/
1025 acpi_ev_reg_run(acpi_handle obj_handle,
1026 u32 level, void *context, void **return_value)
1028 union acpi_operand_object *obj_desc;
1029 struct acpi_namespace_node *node;
1030 acpi_adr_space_type space_id;
1033 space_id = *ACPI_CAST_PTR(acpi_adr_space_type, context);
1035 /* Convert and validate the device handle */
1037 node = acpi_ns_map_handle_to_node(obj_handle);
1039 return (AE_BAD_PARAMETER);
1043 * We only care about regions.and objects that are allowed to have address
1046 if ((node->type != ACPI_TYPE_REGION) && (node != acpi_gbl_root_node)) {
1050 /* Check for an existing internal object */
1052 obj_desc = acpi_ns_get_attached_object(node);
1055 /* No object, just exit */
1060 /* Object is a Region */
1062 if (obj_desc->region.space_id != space_id) {
1064 /* This region is for a different address space, just ignore it */
1069 status = acpi_ev_execute_reg_method(obj_desc, 1);