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>
45 #include <acpi/acevents.h>
46 #include <acpi/acnamesp.h>
47 #include <acpi/acinterp.h>
49 #define _COMPONENT ACPI_EVENTS
50 ACPI_MODULE_NAME("evregion")
52 /* Local prototypes */
54 acpi_ev_reg_run(acpi_handle obj_handle
,
55 u32 level
, void *context
, void **return_value
);
58 acpi_ev_install_handler(acpi_handle obj_handle
,
59 u32 level
, void *context
, void **return_value
);
61 /* These are the address spaces that will get default handlers */
63 #define ACPI_NUM_DEFAULT_SPACES 4
65 static u8 acpi_gbl_default_address_spaces
[ACPI_NUM_DEFAULT_SPACES
] = {
66 ACPI_ADR_SPACE_SYSTEM_MEMORY
,
67 ACPI_ADR_SPACE_SYSTEM_IO
,
68 ACPI_ADR_SPACE_PCI_CONFIG
,
69 ACPI_ADR_SPACE_DATA_TABLE
72 /*******************************************************************************
74 * FUNCTION: acpi_ev_install_region_handlers
80 * DESCRIPTION: Installs the core subsystem default address space handlers.
82 ******************************************************************************/
84 acpi_status
acpi_ev_install_region_handlers(void)
89 ACPI_FUNCTION_TRACE(ev_install_region_handlers
);
91 status
= acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE
);
92 if (ACPI_FAILURE(status
)) {
93 return_ACPI_STATUS(status
);
97 * All address spaces (PCI Config, EC, SMBus) are scope dependent and
98 * registration must occur for a specific device.
100 * In the case of the system memory and IO address spaces there is
101 * currently no device associated with the address space. For these we
104 * We install the default PCI config space handler at the root so that
105 * this space is immediately available even though the we have not
106 * enumerated all the PCI Root Buses yet. This is to conform to the ACPI
107 * specification which states that the PCI config space must be always
108 * available -- even though we are nowhere near ready to find the PCI root
109 * buses at this point.
111 * NOTE: We ignore AE_ALREADY_EXISTS because this means that a handler
112 * has already been installed (via acpi_install_address_space_handler).
113 * Similar for AE_SAME_HANDLER.
115 for (i
= 0; i
< ACPI_NUM_DEFAULT_SPACES
; i
++) {
116 status
= acpi_ev_install_space_handler(acpi_gbl_root_node
,
117 acpi_gbl_default_address_spaces
119 ACPI_DEFAULT_HANDLER
,
123 case AE_SAME_HANDLER
:
124 case AE_ALREADY_EXISTS
:
126 /* These exceptions are all OK */
133 goto unlock_and_exit
;
138 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE
);
139 return_ACPI_STATUS(status
);
142 /*******************************************************************************
144 * FUNCTION: acpi_ev_initialize_op_regions
150 * DESCRIPTION: Execute _REG methods for all Operation Regions that have
151 * an installed default region handler.
153 ******************************************************************************/
155 acpi_status
acpi_ev_initialize_op_regions(void)
160 ACPI_FUNCTION_TRACE(ev_initialize_op_regions
);
162 status
= acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE
);
163 if (ACPI_FAILURE(status
)) {
164 return_ACPI_STATUS(status
);
167 /* Run the _REG methods for op_regions in each default address space */
169 for (i
= 0; i
< ACPI_NUM_DEFAULT_SPACES
; i
++) {
171 * TBD: Make sure handler is the DEFAULT handler, otherwise
172 * _REG will have already been run.
174 status
= acpi_ev_execute_reg_methods(acpi_gbl_root_node
,
175 acpi_gbl_default_address_spaces
179 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE
);
180 return_ACPI_STATUS(status
);
183 /*******************************************************************************
185 * FUNCTION: acpi_ev_execute_reg_method
187 * PARAMETERS: region_obj - Region object
188 * Function - Passed to _REG: On (1) or Off (0)
192 * DESCRIPTION: Execute _REG method for a region
194 ******************************************************************************/
197 acpi_ev_execute_reg_method(union acpi_operand_object
*region_obj
, u32 function
)
199 struct acpi_evaluate_info
*info
;
200 union acpi_operand_object
*args
[3];
201 union acpi_operand_object
*region_obj2
;
204 ACPI_FUNCTION_TRACE(ev_execute_reg_method
);
206 region_obj2
= acpi_ns_get_secondary_object(region_obj
);
208 return_ACPI_STATUS(AE_NOT_EXIST
);
211 if (region_obj2
->extra
.method_REG
== NULL
) {
212 return_ACPI_STATUS(AE_OK
);
215 /* Allocate and initialize the evaluation information block */
217 info
= ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info
));
219 return_ACPI_STATUS(AE_NO_MEMORY
);
222 info
->prefix_node
= region_obj2
->extra
.method_REG
;
223 info
->pathname
= NULL
;
224 info
->parameters
= args
;
225 info
->flags
= ACPI_IGNORE_RETURN_VALUE
;
228 * The _REG method has two arguments:
231 * Operation region space ID Same value as region_obj->Region.space_id
234 * connection status 1 for connecting the handler, 0 for disconnecting
235 * the handler (Passed as a parameter)
237 args
[0] = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER
);
239 status
= AE_NO_MEMORY
;
243 args
[1] = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER
);
245 status
= AE_NO_MEMORY
;
249 /* Setup the parameter objects */
251 args
[0]->integer
.value
= region_obj
->region
.space_id
;
252 args
[1]->integer
.value
= function
;
255 /* Execute the method, no return value */
257 ACPI_DEBUG_EXEC(acpi_ut_display_init_pathname
258 (ACPI_TYPE_METHOD
, info
->prefix_node
, NULL
));
260 status
= acpi_ns_evaluate(info
);
261 acpi_ut_remove_reference(args
[1]);
264 acpi_ut_remove_reference(args
[0]);
268 return_ACPI_STATUS(status
);
271 /*******************************************************************************
273 * FUNCTION: acpi_ev_address_space_dispatch
275 * PARAMETERS: region_obj - Internal region object
276 * Function - Read or Write operation
277 * Address - Where in the space to read or write
278 * bit_width - Field width in bits (8, 16, 32, or 64)
279 * Value - Pointer to in or out value, must be
280 * full 64-bit acpi_integer
284 * DESCRIPTION: Dispatch an address space or operation region access to
285 * a previously installed handler.
287 ******************************************************************************/
290 acpi_ev_address_space_dispatch(union acpi_operand_object
*region_obj
,
292 acpi_physical_address address
,
293 u32 bit_width
, acpi_integer
* value
)
296 acpi_adr_space_handler handler
;
297 acpi_adr_space_setup region_setup
;
298 union acpi_operand_object
*handler_desc
;
299 union acpi_operand_object
*region_obj2
;
300 void *region_context
= NULL
;
302 ACPI_FUNCTION_TRACE(ev_address_space_dispatch
);
304 region_obj2
= acpi_ns_get_secondary_object(region_obj
);
306 return_ACPI_STATUS(AE_NOT_EXIST
);
309 /* Ensure that there is a handler associated with this region */
311 handler_desc
= region_obj
->region
.handler
;
314 "No handler for Region [%4.4s] (%p) [%s]",
315 acpi_ut_get_node_name(region_obj
->region
.node
),
317 acpi_ut_get_region_name(region_obj
->region
.
320 return_ACPI_STATUS(AE_NOT_EXIST
);
324 * It may be the case that the region has never been initialized.
325 * Some types of regions require special init code
327 if (!(region_obj
->region
.flags
& AOPOBJ_SETUP_COMPLETE
)) {
329 /* This region has not been initialized yet, do it */
331 region_setup
= handler_desc
->address_space
.setup
;
334 /* No initialization routine, exit with error */
337 "No init routine for region(%p) [%s]",
339 acpi_ut_get_region_name(region_obj
->region
.
341 return_ACPI_STATUS(AE_NOT_EXIST
);
345 * We must exit the interpreter because the region setup will
346 * potentially execute control methods (for example, the _REG method
349 acpi_ex_exit_interpreter();
351 status
= region_setup(region_obj
, ACPI_REGION_ACTIVATE
,
352 handler_desc
->address_space
.context
,
355 /* Re-enter the interpreter */
357 acpi_ex_enter_interpreter();
359 /* Check for failure of the Region Setup */
361 if (ACPI_FAILURE(status
)) {
362 ACPI_EXCEPTION((AE_INFO
, status
,
363 "During region initialization: [%s]",
364 acpi_ut_get_region_name(region_obj
->
367 return_ACPI_STATUS(status
);
370 /* Region initialization may have been completed by region_setup */
372 if (!(region_obj
->region
.flags
& AOPOBJ_SETUP_COMPLETE
)) {
373 region_obj
->region
.flags
|= AOPOBJ_SETUP_COMPLETE
;
375 if (region_obj2
->extra
.region_context
) {
377 /* The handler for this region was already installed */
379 ACPI_FREE(region_context
);
382 * Save the returned context for use in all accesses to
383 * this particular region
385 region_obj2
->extra
.region_context
=
391 /* We have everything we need, we can invoke the address space handler */
393 handler
= handler_desc
->address_space
.handler
;
395 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION
,
396 "Handler %p (@%p) Address %8.8X%8.8X [%s]\n",
397 ®ion_obj
->region
.handler
->address_space
, handler
,
398 ACPI_FORMAT_NATIVE_UINT(address
),
399 acpi_ut_get_region_name(region_obj
->region
.
402 if (!(handler_desc
->address_space
.handler_flags
&
403 ACPI_ADDR_HANDLER_DEFAULT_INSTALLED
)) {
405 * For handlers other than the default (supplied) handlers, we must
406 * exit the interpreter because the handler *might* block -- we don't
407 * know what it will do, so we can't hold the lock on the intepreter.
409 acpi_ex_exit_interpreter();
412 /* Call the handler */
414 status
= handler(function
, address
, bit_width
, value
,
415 handler_desc
->address_space
.context
,
416 region_obj2
->extra
.region_context
);
418 if (ACPI_FAILURE(status
)) {
419 ACPI_EXCEPTION((AE_INFO
, status
, "Returned by Handler for [%s]",
420 acpi_ut_get_region_name(region_obj
->region
.
424 if (!(handler_desc
->address_space
.handler_flags
&
425 ACPI_ADDR_HANDLER_DEFAULT_INSTALLED
)) {
427 * We just returned from a non-default handler, we must re-enter the
430 acpi_ex_enter_interpreter();
433 return_ACPI_STATUS(status
);
436 /*******************************************************************************
438 * FUNCTION: acpi_ev_detach_region
440 * PARAMETERS: region_obj - Region Object
441 * acpi_ns_is_locked - Namespace Region Already Locked?
445 * DESCRIPTION: Break the association between the handler and the region
446 * this is a two way association.
448 ******************************************************************************/
451 acpi_ev_detach_region(union acpi_operand_object
*region_obj
,
452 u8 acpi_ns_is_locked
)
454 union acpi_operand_object
*handler_obj
;
455 union acpi_operand_object
*obj_desc
;
456 union acpi_operand_object
**last_obj_ptr
;
457 acpi_adr_space_setup region_setup
;
458 void **region_context
;
459 union acpi_operand_object
*region_obj2
;
462 ACPI_FUNCTION_TRACE(ev_detach_region
);
464 region_obj2
= acpi_ns_get_secondary_object(region_obj
);
468 region_context
= ®ion_obj2
->extra
.region_context
;
470 /* Get the address handler from the region object */
472 handler_obj
= region_obj
->region
.handler
;
475 /* This region has no handler, all done */
480 /* Find this region in the handler's list */
482 obj_desc
= handler_obj
->address_space
.region_list
;
483 last_obj_ptr
= &handler_obj
->address_space
.region_list
;
487 /* Is this the correct Region? */
489 if (obj_desc
== region_obj
) {
490 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION
,
491 "Removing Region %p from address handler %p\n",
492 region_obj
, handler_obj
));
494 /* This is it, remove it from the handler's list */
496 *last_obj_ptr
= obj_desc
->region
.next
;
497 obj_desc
->region
.next
= NULL
; /* Must clear field */
499 if (acpi_ns_is_locked
) {
501 acpi_ut_release_mutex(ACPI_MTX_NAMESPACE
);
502 if (ACPI_FAILURE(status
)) {
507 /* Now stop region accesses by executing the _REG method */
509 status
= acpi_ev_execute_reg_method(region_obj
, 0);
510 if (ACPI_FAILURE(status
)) {
511 ACPI_EXCEPTION((AE_INFO
, status
,
512 "from region _REG, [%s]",
513 acpi_ut_get_region_name
514 (region_obj
->region
.space_id
)));
517 if (acpi_ns_is_locked
) {
519 acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE
);
520 if (ACPI_FAILURE(status
)) {
526 * If the region has been activated, call the setup handler with
527 * the deactivate notification
529 if (region_obj
->region
.flags
& AOPOBJ_SETUP_COMPLETE
) {
530 region_setup
= handler_obj
->address_space
.setup
;
532 region_setup(region_obj
,
533 ACPI_REGION_DEACTIVATE
,
534 handler_obj
->address_space
.
535 context
, region_context
);
537 /* Init routine may fail, Just ignore errors */
539 if (ACPI_FAILURE(status
)) {
540 ACPI_EXCEPTION((AE_INFO
, status
,
541 "from region handler - deactivate, [%s]",
542 acpi_ut_get_region_name
547 region_obj
->region
.flags
&=
548 ~(AOPOBJ_SETUP_COMPLETE
);
552 * Remove handler reference in the region
554 * NOTE: this doesn't mean that the region goes away, the region
555 * is just inaccessible as indicated to the _REG method
557 * If the region is on the handler's list, this must be the
560 region_obj
->region
.handler
= NULL
;
561 acpi_ut_remove_reference(handler_obj
);
566 /* Walk the linked list of handlers */
568 last_obj_ptr
= &obj_desc
->region
.next
;
569 obj_desc
= obj_desc
->region
.next
;
572 /* If we get here, the region was not in the handler's region list */
574 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION
,
575 "Cannot remove region %p from address handler %p\n",
576 region_obj
, handler_obj
));
581 /*******************************************************************************
583 * FUNCTION: acpi_ev_attach_region
585 * PARAMETERS: handler_obj - Handler Object
586 * region_obj - Region Object
587 * acpi_ns_is_locked - Namespace Region Already Locked?
591 * DESCRIPTION: Create the association between the handler and the region
592 * this is a two way association.
594 ******************************************************************************/
597 acpi_ev_attach_region(union acpi_operand_object
*handler_obj
,
598 union acpi_operand_object
*region_obj
,
599 u8 acpi_ns_is_locked
)
602 ACPI_FUNCTION_TRACE(ev_attach_region
);
604 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION
,
605 "Adding Region [%4.4s] %p to address handler %p [%s]\n",
606 acpi_ut_get_node_name(region_obj
->region
.node
),
607 region_obj
, handler_obj
,
608 acpi_ut_get_region_name(region_obj
->region
.
611 /* Link this region to the front of the handler's list */
613 region_obj
->region
.next
= handler_obj
->address_space
.region_list
;
614 handler_obj
->address_space
.region_list
= region_obj
;
616 /* Install the region's handler */
618 if (region_obj
->region
.handler
) {
619 return_ACPI_STATUS(AE_ALREADY_EXISTS
);
622 region_obj
->region
.handler
= handler_obj
;
623 acpi_ut_add_reference(handler_obj
);
625 return_ACPI_STATUS(AE_OK
);
628 /*******************************************************************************
630 * FUNCTION: acpi_ev_install_handler
632 * PARAMETERS: walk_namespace callback
634 * DESCRIPTION: This routine installs an address handler into objects that are
635 * of type Region or Device.
637 * If the Object is a Device, and the device has a handler of
638 * the same type then the search is terminated in that branch.
640 * This is because the existing handler is closer in proximity
641 * to any more regions than the one we are trying to install.
643 ******************************************************************************/
646 acpi_ev_install_handler(acpi_handle obj_handle
,
647 u32 level
, void *context
, void **return_value
)
649 union acpi_operand_object
*handler_obj
;
650 union acpi_operand_object
*next_handler_obj
;
651 union acpi_operand_object
*obj_desc
;
652 struct acpi_namespace_node
*node
;
655 ACPI_FUNCTION_NAME(ev_install_handler
);
657 handler_obj
= (union acpi_operand_object
*)context
;
659 /* Parameter validation */
665 /* Convert and validate the device handle */
667 node
= acpi_ns_map_handle_to_node(obj_handle
);
669 return (AE_BAD_PARAMETER
);
673 * We only care about regions and objects that are allowed to have
674 * address space handlers
676 if ((node
->type
!= ACPI_TYPE_DEVICE
) &&
677 (node
->type
!= ACPI_TYPE_REGION
) && (node
!= acpi_gbl_root_node
)) {
681 /* Check for an existing internal object */
683 obj_desc
= acpi_ns_get_attached_object(node
);
686 /* No object, just exit */
691 /* Devices are handled different than regions */
693 if (ACPI_GET_OBJECT_TYPE(obj_desc
) == ACPI_TYPE_DEVICE
) {
695 /* Check if this Device already has a handler for this address space */
697 next_handler_obj
= obj_desc
->device
.handler
;
698 while (next_handler_obj
) {
700 /* Found a handler, is it for the same address space? */
702 if (next_handler_obj
->address_space
.space_id
==
703 handler_obj
->address_space
.space_id
) {
704 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION
,
705 "Found handler for region [%s] in device %p(%p) handler %p\n",
706 acpi_ut_get_region_name
707 (handler_obj
->address_space
.
713 * Since the object we found it on was a device, then it
714 * means that someone has already installed a handler for
715 * the branch of the namespace from this device on. Just
716 * bail out telling the walk routine to not traverse this
717 * branch. This preserves the scoping rule for handlers.
719 return (AE_CTRL_DEPTH
);
722 /* Walk the linked list of handlers attached to this device */
724 next_handler_obj
= next_handler_obj
->address_space
.next
;
728 * As long as the device didn't have a handler for this space we
729 * don't care about it. We just ignore it and proceed.
734 /* Object is a Region */
736 if (obj_desc
->region
.space_id
!= handler_obj
->address_space
.space_id
) {
738 /* This region is for a different address space, just ignore it */
744 * Now we have a region and it is for the handler's address space type.
746 * First disconnect region for any previous handler (if any)
748 acpi_ev_detach_region(obj_desc
, FALSE
);
750 /* Connect the region to the new handler */
752 status
= acpi_ev_attach_region(handler_obj
, obj_desc
, FALSE
);
756 /*******************************************************************************
758 * FUNCTION: acpi_ev_install_space_handler
760 * PARAMETERS: Node - Namespace node for the device
761 * space_id - The address space ID
762 * Handler - Address of the handler
763 * Setup - Address of the setup function
764 * Context - Value passed to the handler on each access
768 * DESCRIPTION: Install a handler for all op_regions of a given space_id.
769 * Assumes namespace is locked
771 ******************************************************************************/
774 acpi_ev_install_space_handler(struct acpi_namespace_node
* node
,
775 acpi_adr_space_type space_id
,
776 acpi_adr_space_handler handler
,
777 acpi_adr_space_setup setup
, void *context
)
779 union acpi_operand_object
*obj_desc
;
780 union acpi_operand_object
*handler_obj
;
782 acpi_object_type type
;
785 ACPI_FUNCTION_TRACE(ev_install_space_handler
);
788 * This registration is valid for only the types below and the root. This
789 * is where the default handlers get placed.
791 if ((node
->type
!= ACPI_TYPE_DEVICE
) &&
792 (node
->type
!= ACPI_TYPE_PROCESSOR
) &&
793 (node
->type
!= ACPI_TYPE_THERMAL
) && (node
!= acpi_gbl_root_node
)) {
794 status
= AE_BAD_PARAMETER
;
795 goto unlock_and_exit
;
798 if (handler
== ACPI_DEFAULT_HANDLER
) {
799 flags
= ACPI_ADDR_HANDLER_DEFAULT_INSTALLED
;
802 case ACPI_ADR_SPACE_SYSTEM_MEMORY
:
803 handler
= acpi_ex_system_memory_space_handler
;
804 setup
= acpi_ev_system_memory_region_setup
;
807 case ACPI_ADR_SPACE_SYSTEM_IO
:
808 handler
= acpi_ex_system_io_space_handler
;
809 setup
= acpi_ev_io_space_region_setup
;
812 case ACPI_ADR_SPACE_PCI_CONFIG
:
813 handler
= acpi_ex_pci_config_space_handler
;
814 setup
= acpi_ev_pci_config_region_setup
;
817 case ACPI_ADR_SPACE_CMOS
:
818 handler
= acpi_ex_cmos_space_handler
;
819 setup
= acpi_ev_cmos_region_setup
;
822 case ACPI_ADR_SPACE_PCI_BAR_TARGET
:
823 handler
= acpi_ex_pci_bar_space_handler
;
824 setup
= acpi_ev_pci_bar_region_setup
;
827 case ACPI_ADR_SPACE_DATA_TABLE
:
828 handler
= acpi_ex_data_table_space_handler
;
833 status
= AE_BAD_PARAMETER
;
834 goto unlock_and_exit
;
838 /* If the caller hasn't specified a setup routine, use the default */
841 setup
= acpi_ev_default_region_setup
;
844 /* Check for an existing internal object */
846 obj_desc
= acpi_ns_get_attached_object(node
);
849 * The attached device object already exists. Make sure the handler
850 * is not already installed.
852 handler_obj
= obj_desc
->device
.handler
;
854 /* Walk the handler list for this device */
856 while (handler_obj
) {
858 /* Same space_id indicates a handler already installed */
860 if (handler_obj
->address_space
.space_id
== space_id
) {
861 if (handler_obj
->address_space
.handler
==
864 * It is (relatively) OK to attempt to install the SAME
865 * handler twice. This can easily happen with the
868 status
= AE_SAME_HANDLER
;
869 goto unlock_and_exit
;
871 /* A handler is already installed */
873 status
= AE_ALREADY_EXISTS
;
875 goto unlock_and_exit
;
878 /* Walk the linked list of handlers */
880 handler_obj
= handler_obj
->address_space
.next
;
883 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION
,
884 "Creating object on Device %p while installing handler\n",
887 /* obj_desc does not exist, create one */
889 if (node
->type
== ACPI_TYPE_ANY
) {
890 type
= ACPI_TYPE_DEVICE
;
895 obj_desc
= acpi_ut_create_internal_object(type
);
897 status
= AE_NO_MEMORY
;
898 goto unlock_and_exit
;
901 /* Init new descriptor */
903 obj_desc
->common
.type
= (u8
) type
;
905 /* Attach the new object to the Node */
907 status
= acpi_ns_attach_object(node
, obj_desc
, type
);
909 /* Remove local reference to the object */
911 acpi_ut_remove_reference(obj_desc
);
913 if (ACPI_FAILURE(status
)) {
914 goto unlock_and_exit
;
918 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION
,
919 "Installing address handler for region %s(%X) on Device %4.4s %p(%p)\n",
920 acpi_ut_get_region_name(space_id
), space_id
,
921 acpi_ut_get_node_name(node
), node
, obj_desc
));
924 * Install the handler
926 * At this point there is no existing handler. Just allocate the object
927 * for the handler and link it into the list.
930 acpi_ut_create_internal_object(ACPI_TYPE_LOCAL_ADDRESS_HANDLER
);
932 status
= AE_NO_MEMORY
;
933 goto unlock_and_exit
;
936 /* Init handler obj */
938 handler_obj
->address_space
.space_id
= (u8
) space_id
;
939 handler_obj
->address_space
.handler_flags
= flags
;
940 handler_obj
->address_space
.region_list
= NULL
;
941 handler_obj
->address_space
.node
= node
;
942 handler_obj
->address_space
.handler
= handler
;
943 handler_obj
->address_space
.context
= context
;
944 handler_obj
->address_space
.setup
= setup
;
946 /* Install at head of Device.address_space list */
948 handler_obj
->address_space
.next
= obj_desc
->device
.handler
;
951 * The Device object is the first reference on the handler_obj.
952 * Each region that uses the handler adds a reference.
954 obj_desc
->device
.handler
= handler_obj
;
957 * Walk the namespace finding all of the regions this
958 * handler will manage.
960 * Start at the device and search the branch toward
961 * the leaf nodes until either the leaf is encountered or
962 * a device is detected that has an address handler of the
965 * In either case, back up and search down the remainder
968 status
= acpi_ns_walk_namespace(ACPI_TYPE_ANY
, node
, ACPI_UINT32_MAX
,
970 acpi_ev_install_handler
, handler_obj
,
974 return_ACPI_STATUS(status
);
977 /*******************************************************************************
979 * FUNCTION: acpi_ev_execute_reg_methods
981 * PARAMETERS: Node - Namespace node for the device
982 * space_id - The address space ID
986 * DESCRIPTION: Run all _REG methods for the input Space ID;
987 * Note: assumes namespace is locked, or system init time.
989 ******************************************************************************/
992 acpi_ev_execute_reg_methods(struct acpi_namespace_node
*node
,
993 acpi_adr_space_type space_id
)
997 ACPI_FUNCTION_TRACE(ev_execute_reg_methods
);
1000 * Run all _REG methods for all Operation Regions for this space ID. This
1001 * is a separate walk in order to handle any interdependencies between
1002 * regions and _REG methods. (i.e. handlers must be installed for all
1003 * regions of this Space ID before we can run any _REG methods)
1005 status
= acpi_ns_walk_namespace(ACPI_TYPE_ANY
, node
, ACPI_UINT32_MAX
,
1006 ACPI_NS_WALK_UNLOCK
, acpi_ev_reg_run
,
1009 return_ACPI_STATUS(status
);
1012 /*******************************************************************************
1014 * FUNCTION: acpi_ev_reg_run
1016 * PARAMETERS: walk_namespace callback
1018 * DESCRIPTION: Run _REG method for region objects of the requested space_iD
1020 ******************************************************************************/
1023 acpi_ev_reg_run(acpi_handle obj_handle
,
1024 u32 level
, void *context
, void **return_value
)
1026 union acpi_operand_object
*obj_desc
;
1027 struct acpi_namespace_node
*node
;
1028 acpi_adr_space_type space_id
;
1031 space_id
= *ACPI_CAST_PTR(acpi_adr_space_type
, context
);
1033 /* Convert and validate the device handle */
1035 node
= acpi_ns_map_handle_to_node(obj_handle
);
1037 return (AE_BAD_PARAMETER
);
1041 * We only care about regions.and objects that are allowed to have address
1044 if ((node
->type
!= ACPI_TYPE_REGION
) && (node
!= acpi_gbl_root_node
)) {
1048 /* Check for an existing internal object */
1050 obj_desc
= acpi_ns_get_attached_object(node
);
1053 /* No object, just exit */
1058 /* Object is a Region */
1060 if (obj_desc
->region
.space_id
!= space_id
) {
1062 /* This region is for a different address space, just ignore it */
1067 status
= acpi_ev_execute_reg_method(obj_desc
, 1);