1 /******************************************************************************
3 * Module Name: evregion - ACPI address_space (op_region) handler dispatch
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2005, R. Byron Moore
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.
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
};
61 /* Local prototypes */
65 acpi_handle obj_handle
,
71 acpi_ev_install_handler (
72 acpi_handle obj_handle
,
78 /*******************************************************************************
80 * FUNCTION: acpi_ev_install_region_handlers
86 * DESCRIPTION: Installs the core subsystem default address space handlers.
88 ******************************************************************************/
91 acpi_ev_install_region_handlers (
97 ACPI_FUNCTION_TRACE ("ev_install_region_handlers");
100 status
= acpi_ut_acquire_mutex (ACPI_MTX_NAMESPACE
);
101 if (ACPI_FAILURE (status
)) {
102 return_ACPI_STATUS (status
);
106 * All address spaces (PCI Config, EC, SMBus) are scope dependent
107 * and registration must occur for a specific device.
109 * In the case of the system memory and IO address spaces there is currently
110 * no device associated with the address space. For these we use the root.
112 * We install the default PCI config space handler at the root so
113 * that this space is immediately available even though the we have
114 * not enumerated all the PCI Root Buses yet. This is to conform
115 * to the ACPI specification which states that the PCI config
116 * space must be always available -- even though we are nowhere
117 * near ready to find the PCI root buses at this point.
119 * NOTE: We ignore AE_ALREADY_EXISTS because this means that a handler
120 * has already been installed (via acpi_install_address_space_handler).
121 * Similar for AE_SAME_HANDLER.
123 for (i
= 0; i
< ACPI_NUM_DEFAULT_SPACES
; i
++) {
124 status
= acpi_ev_install_space_handler (acpi_gbl_root_node
,
125 acpi_gbl_default_address_spaces
[i
],
126 ACPI_DEFAULT_HANDLER
, NULL
, NULL
);
129 case AE_SAME_HANDLER
:
130 case AE_ALREADY_EXISTS
:
132 /* These exceptions are all OK */
139 goto unlock_and_exit
;
144 (void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE
);
145 return_ACPI_STATUS (status
);
149 /*******************************************************************************
151 * FUNCTION: acpi_ev_initialize_op_regions
157 * DESCRIPTION: Execute _REG methods for all Operation Regions that have
158 * an installed default region handler.
160 ******************************************************************************/
163 acpi_ev_initialize_op_regions (
170 ACPI_FUNCTION_TRACE ("ev_initialize_op_regions");
173 status
= acpi_ut_acquire_mutex (ACPI_MTX_NAMESPACE
);
174 if (ACPI_FAILURE (status
)) {
175 return_ACPI_STATUS (status
);
179 * Run the _REG methods for op_regions in each default address space
181 for (i
= 0; i
< ACPI_NUM_DEFAULT_SPACES
; i
++) {
182 /* TBD: Make sure handler is the DEFAULT handler, otherwise
183 * _REG will have already been run.
185 status
= acpi_ev_execute_reg_methods (acpi_gbl_root_node
,
186 acpi_gbl_default_address_spaces
[i
]);
189 (void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE
);
190 return_ACPI_STATUS (status
);
194 /*******************************************************************************
196 * FUNCTION: acpi_ev_execute_reg_method
198 * PARAMETERS: region_obj - Region object
199 * Function - Passed to _REG: On (1) or Off (0)
203 * DESCRIPTION: Execute _REG method for a region
205 ******************************************************************************/
208 acpi_ev_execute_reg_method (
209 union acpi_operand_object
*region_obj
,
212 struct acpi_parameter_info info
;
213 union acpi_operand_object
*params
[3];
214 union acpi_operand_object
*region_obj2
;
218 ACPI_FUNCTION_TRACE ("ev_execute_reg_method");
221 region_obj2
= acpi_ns_get_secondary_object (region_obj
);
223 return_ACPI_STATUS (AE_NOT_EXIST
);
226 if (region_obj2
->extra
.method_REG
== NULL
) {
227 return_ACPI_STATUS (AE_OK
);
231 * The _REG method has two arguments:
233 * Arg0, Integer: Operation region space ID
234 * Same value as region_obj->Region.space_id
235 * Arg1, Integer: connection status
236 * 1 for connecting the handler,
237 * 0 for disconnecting the handler
238 * Passed as a parameter
240 params
[0] = acpi_ut_create_internal_object (ACPI_TYPE_INTEGER
);
242 return_ACPI_STATUS (AE_NO_MEMORY
);
245 params
[1] = acpi_ut_create_internal_object (ACPI_TYPE_INTEGER
);
247 status
= AE_NO_MEMORY
;
251 /* Setup the parameter objects */
253 params
[0]->integer
.value
= region_obj
->region
.space_id
;
254 params
[1]->integer
.value
= function
;
257 info
.node
= region_obj2
->extra
.method_REG
;
258 info
.parameters
= params
;
259 info
.parameter_type
= ACPI_PARAM_ARGS
;
261 /* Execute the method, no return value */
263 ACPI_DEBUG_EXEC (acpi_ut_display_init_pathname (
264 ACPI_TYPE_METHOD
, info
.node
, NULL
));
265 status
= acpi_ns_evaluate_by_handle (&info
);
267 acpi_ut_remove_reference (params
[1]);
270 acpi_ut_remove_reference (params
[0]);
272 return_ACPI_STATUS (status
);
276 /*******************************************************************************
278 * FUNCTION: acpi_ev_address_space_dispatch
280 * PARAMETERS: region_obj - Internal region object
281 * Function - Read or Write operation
282 * Address - Where in the space to read or write
283 * bit_width - Field width in bits (8, 16, 32, or 64)
284 * Value - Pointer to in or out value
288 * DESCRIPTION: Dispatch an address space or operation region access to
289 * a previously installed handler.
291 ******************************************************************************/
294 acpi_ev_address_space_dispatch (
295 union acpi_operand_object
*region_obj
,
297 acpi_physical_address address
,
303 acpi_adr_space_handler handler
;
304 acpi_adr_space_setup region_setup
;
305 union acpi_operand_object
*handler_desc
;
306 union acpi_operand_object
*region_obj2
;
307 void *region_context
= NULL
;
310 ACPI_FUNCTION_TRACE ("ev_address_space_dispatch");
313 region_obj2
= acpi_ns_get_secondary_object (region_obj
);
315 return_ACPI_STATUS (AE_NOT_EXIST
);
318 /* Ensure that there is a handler associated with this region */
320 handler_desc
= region_obj
->region
.handler
;
322 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
,
323 "No handler for Region [%4.4s] (%p) [%s]\n",
324 acpi_ut_get_node_name (region_obj
->region
.node
),
325 region_obj
, acpi_ut_get_region_name (region_obj
->region
.space_id
)));
327 return_ACPI_STATUS (AE_NOT_EXIST
);
331 * It may be the case that the region has never been initialized
332 * Some types of regions require special init code
334 if (!(region_obj
->region
.flags
& AOPOBJ_SETUP_COMPLETE
)) {
336 * This region has not been initialized yet, do it
338 region_setup
= handler_desc
->address_space
.setup
;
340 /* No initialization routine, exit with error */
342 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
,
343 "No init routine for region(%p) [%s]\n",
344 region_obj
, acpi_ut_get_region_name (region_obj
->region
.space_id
)));
345 return_ACPI_STATUS (AE_NOT_EXIST
);
349 * We must exit the interpreter because the region
350 * setup will potentially execute control methods
351 * (e.g., _REG method for this region)
353 acpi_ex_exit_interpreter ();
355 status
= region_setup (region_obj
, ACPI_REGION_ACTIVATE
,
356 handler_desc
->address_space
.context
, ®ion_context
);
358 /* Re-enter the interpreter */
360 status2
= acpi_ex_enter_interpreter ();
361 if (ACPI_FAILURE (status2
)) {
362 return_ACPI_STATUS (status2
);
365 /* Check for failure of the Region Setup */
367 if (ACPI_FAILURE (status
)) {
368 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
, "Region Init: %s [%s]\n",
369 acpi_format_exception (status
),
370 acpi_ut_get_region_name (region_obj
->region
.space_id
)));
371 return_ACPI_STATUS (status
);
375 * Region initialization may have been completed by region_setup
377 if (!(region_obj
->region
.flags
& AOPOBJ_SETUP_COMPLETE
)) {
378 region_obj
->region
.flags
|= AOPOBJ_SETUP_COMPLETE
;
380 if (region_obj2
->extra
.region_context
) {
381 /* The handler for this region was already installed */
383 ACPI_MEM_FREE (region_context
);
387 * Save the returned context for use in all accesses to
388 * this particular region
390 region_obj2
->extra
.region_context
= region_context
;
395 /* We have everything we need, we can invoke the address space handler */
397 handler
= handler_desc
->address_space
.handler
;
399 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION
,
400 "Handler %p (@%p) Address %8.8X%8.8X [%s]\n",
401 ®ion_obj
->region
.handler
->address_space
, handler
,
402 ACPI_FORMAT_UINT64 (address
),
403 acpi_ut_get_region_name (region_obj
->region
.space_id
)));
405 if (!(handler_desc
->address_space
.hflags
& ACPI_ADDR_HANDLER_DEFAULT_INSTALLED
)) {
407 * For handlers other than the default (supplied) handlers, we must
408 * exit the interpreter because the handler *might* block -- we don't
409 * know what it will do, so we can't hold the lock on the intepreter.
411 acpi_ex_exit_interpreter();
414 /* Call the handler */
416 status
= handler (function
, address
, bit_width
, value
,
417 handler_desc
->address_space
.context
,
418 region_obj2
->extra
.region_context
);
420 if (ACPI_FAILURE (status
)) {
421 ACPI_REPORT_ERROR (("Handler for [%s] returned %s\n",
422 acpi_ut_get_region_name (region_obj
->region
.space_id
),
423 acpi_format_exception (status
)));
426 if (!(handler_desc
->address_space
.hflags
& ACPI_ADDR_HANDLER_DEFAULT_INSTALLED
)) {
428 * We just returned from a non-default handler, we must re-enter the
431 status2
= acpi_ex_enter_interpreter ();
432 if (ACPI_FAILURE (status2
)) {
433 return_ACPI_STATUS (status2
);
437 return_ACPI_STATUS (status
);
441 /*******************************************************************************
443 * FUNCTION: acpi_ev_detach_region
445 * PARAMETERS: region_obj - Region Object
446 * acpi_ns_is_locked - Namespace Region Already Locked?
450 * DESCRIPTION: Break the association between the handler and the region
451 * this is a two way association.
453 ******************************************************************************/
456 acpi_ev_detach_region(
457 union acpi_operand_object
*region_obj
,
458 u8 acpi_ns_is_locked
)
460 union acpi_operand_object
*handler_obj
;
461 union acpi_operand_object
*obj_desc
;
462 union acpi_operand_object
**last_obj_ptr
;
463 acpi_adr_space_setup region_setup
;
464 void **region_context
;
465 union acpi_operand_object
*region_obj2
;
469 ACPI_FUNCTION_TRACE ("ev_detach_region");
472 region_obj2
= acpi_ns_get_secondary_object (region_obj
);
476 region_context
= ®ion_obj2
->extra
.region_context
;
478 /* Get the address handler from the region object */
480 handler_obj
= region_obj
->region
.handler
;
482 /* This region has no handler, all done */
487 /* Find this region in the handler's list */
489 obj_desc
= handler_obj
->address_space
.region_list
;
490 last_obj_ptr
= &handler_obj
->address_space
.region_list
;
493 /* Is this the correct Region? */
495 if (obj_desc
== region_obj
) {
496 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION
,
497 "Removing Region %p from address handler %p\n",
498 region_obj
, handler_obj
));
500 /* This is it, remove it from the handler's list */
502 *last_obj_ptr
= obj_desc
->region
.next
;
503 obj_desc
->region
.next
= NULL
; /* Must clear field */
505 if (acpi_ns_is_locked
) {
506 status
= acpi_ut_release_mutex (ACPI_MTX_NAMESPACE
);
507 if (ACPI_FAILURE (status
)) {
512 /* Now stop region accesses by executing the _REG method */
514 status
= acpi_ev_execute_reg_method (region_obj
, 0);
515 if (ACPI_FAILURE (status
)) {
516 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
, "%s from region _REG, [%s]\n",
517 acpi_format_exception (status
),
518 acpi_ut_get_region_name (region_obj
->region
.space_id
)));
521 if (acpi_ns_is_locked
) {
522 status
= acpi_ut_acquire_mutex (ACPI_MTX_NAMESPACE
);
523 if (ACPI_FAILURE (status
)) {
528 /* Call the setup handler with the deactivate notification */
530 region_setup
= handler_obj
->address_space
.setup
;
531 status
= region_setup (region_obj
, ACPI_REGION_DEACTIVATE
,
532 handler_obj
->address_space
.context
, region_context
);
534 /* Init routine may fail, Just ignore errors */
536 if (ACPI_FAILURE (status
)) {
537 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
, "%s from region init, [%s]\n",
538 acpi_format_exception (status
),
539 acpi_ut_get_region_name (region_obj
->region
.space_id
)));
542 region_obj
->region
.flags
&= ~(AOPOBJ_SETUP_COMPLETE
);
545 * Remove handler reference in the region
547 * NOTE: this doesn't mean that the region goes away
548 * The region is just inaccessible as indicated to
551 * If the region is on the handler's list
552 * this better be the region's handler
554 region_obj
->region
.handler
= NULL
;
555 acpi_ut_remove_reference (handler_obj
);
560 /* Walk the linked list of handlers */
562 last_obj_ptr
= &obj_desc
->region
.next
;
563 obj_desc
= obj_desc
->region
.next
;
566 /* If we get here, the region was not in the handler's region list */
568 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION
,
569 "Cannot remove region %p from address handler %p\n",
570 region_obj
, handler_obj
));
576 /*******************************************************************************
578 * FUNCTION: acpi_ev_attach_region
580 * PARAMETERS: handler_obj - Handler Object
581 * region_obj - Region Object
582 * acpi_ns_is_locked - Namespace Region Already Locked?
586 * DESCRIPTION: Create the association between the handler and the region
587 * this is a two way association.
589 ******************************************************************************/
592 acpi_ev_attach_region (
593 union acpi_operand_object
*handler_obj
,
594 union acpi_operand_object
*region_obj
,
595 u8 acpi_ns_is_locked
)
598 ACPI_FUNCTION_TRACE ("ev_attach_region");
601 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION
,
602 "Adding Region [%4.4s] %p to address handler %p [%s]\n",
603 acpi_ut_get_node_name (region_obj
->region
.node
),
604 region_obj
, handler_obj
,
605 acpi_ut_get_region_name (region_obj
->region
.space_id
)));
607 /* Link this region to the front of the handler's list */
609 region_obj
->region
.next
= handler_obj
->address_space
.region_list
;
610 handler_obj
->address_space
.region_list
= region_obj
;
612 /* Install the region's handler */
614 if (region_obj
->region
.handler
) {
615 return_ACPI_STATUS (AE_ALREADY_EXISTS
);
618 region_obj
->region
.handler
= handler_obj
;
619 acpi_ut_add_reference (handler_obj
);
621 return_ACPI_STATUS (AE_OK
);
625 /*******************************************************************************
627 * FUNCTION: acpi_ev_install_handler
629 * PARAMETERS: walk_namespace callback
631 * DESCRIPTION: This routine installs an address handler into objects that are
632 * of type Region or Device.
634 * If the Object is a Device, and the device has a handler of
635 * the same type then the search is terminated in that branch.
637 * This is because the existing handler is closer in proximity
638 * to any more regions than the one we are trying to install.
640 ******************************************************************************/
643 acpi_ev_install_handler (
644 acpi_handle obj_handle
,
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
;
656 ACPI_FUNCTION_NAME ("ev_install_handler");
659 handler_obj
= (union acpi_operand_object
*) context
;
661 /* Parameter validation */
667 /* Convert and validate the device handle */
669 node
= acpi_ns_map_handle_to_node (obj_handle
);
671 return (AE_BAD_PARAMETER
);
675 * We only care about regions.and objects
676 * that are allowed to have address space handlers
678 if ((node
->type
!= ACPI_TYPE_DEVICE
) &&
679 (node
->type
!= ACPI_TYPE_REGION
) &&
680 (node
!= acpi_gbl_root_node
)) {
684 /* Check for an existing internal object */
686 obj_desc
= acpi_ns_get_attached_object (node
);
688 /* No object, just exit */
693 /* Devices are handled different than regions */
695 if (ACPI_GET_OBJECT_TYPE (obj_desc
) == 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
) {
700 /* Found a handler, is it for the same address space? */
702 if (next_handler_obj
->address_space
.space_id
== handler_obj
->address_space
.space_id
) {
703 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION
,
704 "Found handler for region [%s] in device %p(%p) handler %p\n",
705 acpi_ut_get_region_name (handler_obj
->address_space
.space_id
),
706 obj_desc
, next_handler_obj
, handler_obj
));
709 * Since the object we found it on was a device, then it
710 * means that someone has already installed a handler for
711 * the branch of the namespace from this device on. Just
712 * bail out telling the walk routine to not traverse this
713 * branch. This preserves the scoping rule for handlers.
715 return (AE_CTRL_DEPTH
);
718 /* Walk the linked list of handlers attached to this device */
720 next_handler_obj
= next_handler_obj
->address_space
.next
;
724 * As long as the device didn't have a handler for this
725 * space we don't care about it. We just ignore it and
731 /* Object is a Region */
733 if (obj_desc
->region
.space_id
!= handler_obj
->address_space
.space_id
) {
735 * This region is for a different address space
742 * Now we have a region and it is for the handler's address
745 * First disconnect region for any previous handler (if any)
747 acpi_ev_detach_region (obj_desc
, FALSE
);
749 /* Connect the region to the new handler */
751 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 (
775 struct acpi_namespace_node
*node
,
776 acpi_adr_space_type space_id
,
777 acpi_adr_space_handler handler
,
778 acpi_adr_space_setup setup
,
781 union acpi_operand_object
*obj_desc
;
782 union acpi_operand_object
*handler_obj
;
784 acpi_object_type type
;
788 ACPI_FUNCTION_TRACE ("ev_install_space_handler");
792 * This registration is valid for only the types below
793 * and the root. This is where the default handlers
796 if ((node
->type
!= ACPI_TYPE_DEVICE
) &&
797 (node
->type
!= ACPI_TYPE_PROCESSOR
) &&
798 (node
->type
!= ACPI_TYPE_THERMAL
) &&
799 (node
!= acpi_gbl_root_node
)) {
800 status
= AE_BAD_PARAMETER
;
801 goto unlock_and_exit
;
804 if (handler
== ACPI_DEFAULT_HANDLER
) {
805 flags
= ACPI_ADDR_HANDLER_DEFAULT_INSTALLED
;
808 case ACPI_ADR_SPACE_SYSTEM_MEMORY
:
809 handler
= acpi_ex_system_memory_space_handler
;
810 setup
= acpi_ev_system_memory_region_setup
;
813 case ACPI_ADR_SPACE_SYSTEM_IO
:
814 handler
= acpi_ex_system_io_space_handler
;
815 setup
= acpi_ev_io_space_region_setup
;
818 case ACPI_ADR_SPACE_PCI_CONFIG
:
819 handler
= acpi_ex_pci_config_space_handler
;
820 setup
= acpi_ev_pci_config_region_setup
;
823 case ACPI_ADR_SPACE_CMOS
:
824 handler
= acpi_ex_cmos_space_handler
;
825 setup
= acpi_ev_cmos_region_setup
;
828 case ACPI_ADR_SPACE_PCI_BAR_TARGET
:
829 handler
= acpi_ex_pci_bar_space_handler
;
830 setup
= acpi_ev_pci_bar_region_setup
;
833 case ACPI_ADR_SPACE_DATA_TABLE
:
834 handler
= acpi_ex_data_table_space_handler
;
839 status
= AE_BAD_PARAMETER
;
840 goto unlock_and_exit
;
844 /* If the caller hasn't specified a setup routine, use the default */
847 setup
= acpi_ev_default_region_setup
;
850 /* Check for an existing internal object */
852 obj_desc
= acpi_ns_get_attached_object (node
);
855 * The attached device object already exists.
856 * Make sure the handler is not already installed.
858 handler_obj
= obj_desc
->device
.handler
;
860 /* Walk the handler list for this device */
862 while (handler_obj
) {
863 /* Same space_id indicates a handler already installed */
865 if (handler_obj
->address_space
.space_id
== space_id
) {
866 if (handler_obj
->address_space
.handler
== handler
) {
868 * It is (relatively) OK to attempt to install the SAME
869 * handler twice. This can easily happen
870 * with PCI_Config space.
872 status
= AE_SAME_HANDLER
;
873 goto unlock_and_exit
;
876 /* A handler is already installed */
878 status
= AE_ALREADY_EXISTS
;
880 goto unlock_and_exit
;
883 /* Walk the linked list of handlers */
885 handler_obj
= handler_obj
->address_space
.next
;
889 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION
,
890 "Creating object on Device %p while installing handler\n", node
));
892 /* obj_desc does not exist, create one */
894 if (node
->type
== ACPI_TYPE_ANY
) {
895 type
= ACPI_TYPE_DEVICE
;
901 obj_desc
= acpi_ut_create_internal_object (type
);
903 status
= AE_NO_MEMORY
;
904 goto unlock_and_exit
;
907 /* Init new descriptor */
909 obj_desc
->common
.type
= (u8
) type
;
911 /* Attach the new object to the Node */
913 status
= acpi_ns_attach_object (node
, obj_desc
, type
);
915 /* Remove local reference to the object */
917 acpi_ut_remove_reference (obj_desc
);
919 if (ACPI_FAILURE (status
)) {
920 goto unlock_and_exit
;
924 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION
,
925 "Installing address handler for region %s(%X) on Device %4.4s %p(%p)\n",
926 acpi_ut_get_region_name (space_id
), space_id
,
927 acpi_ut_get_node_name (node
), node
, obj_desc
));
930 * Install the handler
932 * At this point there is no existing handler.
933 * Just allocate the object for the handler and link it
936 handler_obj
= acpi_ut_create_internal_object (ACPI_TYPE_LOCAL_ADDRESS_HANDLER
);
938 status
= AE_NO_MEMORY
;
939 goto unlock_and_exit
;
942 /* Init handler obj */
944 handler_obj
->address_space
.space_id
= (u8
) space_id
;
945 handler_obj
->address_space
.hflags
= flags
;
946 handler_obj
->address_space
.region_list
= NULL
;
947 handler_obj
->address_space
.node
= node
;
948 handler_obj
->address_space
.handler
= handler
;
949 handler_obj
->address_space
.context
= context
;
950 handler_obj
->address_space
.setup
= setup
;
952 /* Install at head of Device.address_space list */
954 handler_obj
->address_space
.next
= obj_desc
->device
.handler
;
957 * The Device object is the first reference on the handler_obj.
958 * Each region that uses the handler adds a reference.
960 obj_desc
->device
.handler
= handler_obj
;
963 * Walk the namespace finding all of the regions this
964 * handler will manage.
966 * Start at the device and search the branch toward
967 * the leaf nodes until either the leaf is encountered or
968 * a device is detected that has an address handler of the
971 * In either case, back up and search down the remainder
974 status
= acpi_ns_walk_namespace (ACPI_TYPE_ANY
, node
, ACPI_UINT32_MAX
,
975 ACPI_NS_WALK_UNLOCK
, acpi_ev_install_handler
,
979 return_ACPI_STATUS (status
);
983 /*******************************************************************************
985 * FUNCTION: acpi_ev_execute_reg_methods
987 * PARAMETERS: Node - Namespace node for the device
988 * space_id - The address space ID
992 * DESCRIPTION: Run all _REG methods for the input Space ID;
993 * Note: assumes namespace is locked, or system init time.
995 ******************************************************************************/
998 acpi_ev_execute_reg_methods (
999 struct acpi_namespace_node
*node
,
1000 acpi_adr_space_type space_id
)
1005 ACPI_FUNCTION_TRACE ("ev_execute_reg_methods");
1009 * Run all _REG methods for all Operation Regions for this
1010 * space ID. This is a separate walk in order to handle any
1011 * interdependencies between regions and _REG methods. (i.e. handlers
1012 * must be installed for all regions of this Space ID before we
1013 * can run any _REG methods)
1015 status
= acpi_ns_walk_namespace (ACPI_TYPE_ANY
, node
, ACPI_UINT32_MAX
,
1016 ACPI_NS_WALK_UNLOCK
, acpi_ev_reg_run
,
1019 return_ACPI_STATUS (status
);
1023 /*******************************************************************************
1025 * FUNCTION: acpi_ev_reg_run
1027 * PARAMETERS: walk_namespace callback
1029 * DESCRIPTION: Run _REg method for region objects of the requested space_iD
1031 ******************************************************************************/
1035 acpi_handle obj_handle
,
1038 void **return_value
)
1040 union acpi_operand_object
*obj_desc
;
1041 struct acpi_namespace_node
*node
;
1042 acpi_adr_space_type space_id
;
1046 space_id
= *ACPI_CAST_PTR (acpi_adr_space_type
, context
);
1048 /* Convert and validate the device handle */
1050 node
= acpi_ns_map_handle_to_node (obj_handle
);
1052 return (AE_BAD_PARAMETER
);
1056 * We only care about regions.and objects
1057 * that are allowed to have address space handlers
1059 if ((node
->type
!= ACPI_TYPE_REGION
) &&
1060 (node
!= acpi_gbl_root_node
)) {
1064 /* Check for an existing internal object */
1066 obj_desc
= acpi_ns_get_attached_object (node
);
1068 /* No object, just exit */
1073 /* Object is a Region */
1075 if (obj_desc
->region
.space_id
!= space_id
) {
1077 * This region is for a different address space
1083 status
= acpi_ev_execute_reg_method (obj_desc
, 1);