1 /******************************************************************************
3 * Module Name: evrgnini- ACPI address_space (op_region) init
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2016, 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("evrgnini")
53 /*******************************************************************************
55 * FUNCTION: acpi_ev_system_memory_region_setup
57 * PARAMETERS: handle - Region we are interested in
58 * function - Start or stop
59 * handler_context - Address space handler context
60 * region_context - Region specific context
64 * DESCRIPTION: Setup a system_memory operation region
66 ******************************************************************************/
68 acpi_ev_system_memory_region_setup(acpi_handle handle,
70 void *handler_context, void **region_context)
72 union acpi_operand_object *region_desc =
73 (union acpi_operand_object *)handle;
74 struct acpi_mem_space_context *local_region_context;
76 ACPI_FUNCTION_TRACE(ev_system_memory_region_setup);
78 if (function == ACPI_REGION_DEACTIVATE) {
79 if (*region_context) {
80 local_region_context =
81 (struct acpi_mem_space_context *)*region_context;
83 /* Delete a cached mapping if present */
85 if (local_region_context->mapped_length) {
86 acpi_os_unmap_memory(local_region_context->
87 mapped_logical_address,
88 local_region_context->
91 ACPI_FREE(local_region_context);
92 *region_context = NULL;
94 return_ACPI_STATUS(AE_OK);
97 /* Create a new context */
99 local_region_context =
100 ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_mem_space_context));
101 if (!(local_region_context)) {
102 return_ACPI_STATUS(AE_NO_MEMORY);
105 /* Save the region length and address for use in the handler */
107 local_region_context->length = region_desc->region.length;
108 local_region_context->address = region_desc->region.address;
110 *region_context = local_region_context;
111 return_ACPI_STATUS(AE_OK);
114 /*******************************************************************************
116 * FUNCTION: acpi_ev_io_space_region_setup
118 * PARAMETERS: handle - Region we are interested in
119 * function - Start or stop
120 * handler_context - Address space handler context
121 * region_context - Region specific context
125 * DESCRIPTION: Setup a IO operation region
127 ******************************************************************************/
130 acpi_ev_io_space_region_setup(acpi_handle handle,
132 void *handler_context, void **region_context)
134 ACPI_FUNCTION_TRACE(ev_io_space_region_setup);
136 if (function == ACPI_REGION_DEACTIVATE) {
137 *region_context = NULL;
139 *region_context = handler_context;
142 return_ACPI_STATUS(AE_OK);
145 /*******************************************************************************
147 * FUNCTION: acpi_ev_pci_config_region_setup
149 * PARAMETERS: handle - Region we are interested in
150 * function - Start or stop
151 * handler_context - Address space handler context
152 * region_context - Region specific context
156 * DESCRIPTION: Setup a PCI_Config operation region
158 * MUTEX: Assumes namespace is not locked
160 ******************************************************************************/
163 acpi_ev_pci_config_region_setup(acpi_handle handle,
165 void *handler_context, void **region_context)
167 acpi_status status = AE_OK;
169 struct acpi_pci_id *pci_id = *region_context;
170 union acpi_operand_object *handler_obj;
171 struct acpi_namespace_node *parent_node;
172 struct acpi_namespace_node *pci_root_node;
173 struct acpi_namespace_node *pci_device_node;
174 union acpi_operand_object *region_obj =
175 (union acpi_operand_object *)handle;
177 ACPI_FUNCTION_TRACE(ev_pci_config_region_setup);
179 handler_obj = region_obj->region.handler;
182 * No installed handler. This shouldn't happen because the dispatch
183 * routine checks before we get here, but we check again just in case.
185 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
186 "Attempting to init a region %p, with no handler\n",
188 return_ACPI_STATUS(AE_NOT_EXIST);
191 *region_context = NULL;
192 if (function == ACPI_REGION_DEACTIVATE) {
196 return_ACPI_STATUS(status);
199 parent_node = region_obj->region.node->parent;
202 * Get the _SEG and _BBN values from the device upon which the handler
205 * We need to get the _SEG and _BBN objects relative to the PCI BUS device.
206 * This is the device the handler has been registered to handle.
210 * If the address_space.Node is still pointing to the root, we need
211 * to scan upward for a PCI Root bridge and re-associate the op_region
212 * handlers with that device.
214 if (handler_obj->address_space.node == acpi_gbl_root_node) {
216 /* Start search from the parent object */
218 pci_root_node = parent_node;
219 while (pci_root_node != acpi_gbl_root_node) {
221 /* Get the _HID/_CID in order to detect a root_bridge */
223 if (acpi_ev_is_pci_root_bridge(pci_root_node)) {
225 /* Install a handler for this PCI root bridge */
227 status = acpi_install_address_space_handler((acpi_handle)pci_root_node, ACPI_ADR_SPACE_PCI_CONFIG, ACPI_DEFAULT_HANDLER, NULL, NULL);
228 if (ACPI_FAILURE(status)) {
229 if (status == AE_SAME_HANDLER) {
231 * It is OK if the handler is already installed on the
232 * root bridge. Still need to return a context object
233 * for the new PCI_Config operation region, however.
237 ACPI_EXCEPTION((AE_INFO, status,
238 "Could not install PciConfig handler "
239 "for Root Bridge %4.4s",
240 acpi_ut_get_node_name
247 pci_root_node = pci_root_node->parent;
250 /* PCI root bridge not found, use namespace root node */
252 pci_root_node = handler_obj->address_space.node;
256 * If this region is now initialized, we are done.
257 * (install_address_space_handler could have initialized it)
259 if (region_obj->region.flags & AOPOBJ_SETUP_COMPLETE) {
260 return_ACPI_STATUS(AE_OK);
263 /* Region is still not initialized. Create a new context */
265 pci_id = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_pci_id));
267 return_ACPI_STATUS(AE_NO_MEMORY);
271 * For PCI_Config space access, we need the segment, bus, device and
272 * function numbers. Acquire them here.
274 * Find the parent device object. (This allows the operation region to be
275 * within a subscope under the device, such as a control method.)
277 pci_device_node = region_obj->region.node;
278 while (pci_device_node && (pci_device_node->type != ACPI_TYPE_DEVICE)) {
279 pci_device_node = pci_device_node->parent;
282 if (!pci_device_node) {
284 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
288 * Get the PCI device and function numbers from the _ADR object
289 * contained in the parent's scope.
291 status = acpi_ut_evaluate_numeric_object(METHOD_NAME__ADR,
292 pci_device_node, &pci_value);
295 * The default is zero, and since the allocation above zeroed the data,
296 * just do nothing on failure.
298 if (ACPI_SUCCESS(status)) {
299 pci_id->device = ACPI_HIWORD(ACPI_LODWORD(pci_value));
300 pci_id->function = ACPI_LOWORD(ACPI_LODWORD(pci_value));
303 /* The PCI segment number comes from the _SEG method */
305 status = acpi_ut_evaluate_numeric_object(METHOD_NAME__SEG,
306 pci_root_node, &pci_value);
307 if (ACPI_SUCCESS(status)) {
308 pci_id->segment = ACPI_LOWORD(pci_value);
311 /* The PCI bus number comes from the _BBN method */
313 status = acpi_ut_evaluate_numeric_object(METHOD_NAME__BBN,
314 pci_root_node, &pci_value);
315 if (ACPI_SUCCESS(status)) {
316 pci_id->bus = ACPI_LOWORD(pci_value);
319 /* Complete/update the PCI ID for this device */
322 acpi_hw_derive_pci_id(pci_id, pci_root_node,
323 region_obj->region.node);
324 if (ACPI_FAILURE(status)) {
326 return_ACPI_STATUS(status);
329 *region_context = pci_id;
330 return_ACPI_STATUS(AE_OK);
333 /*******************************************************************************
335 * FUNCTION: acpi_ev_is_pci_root_bridge
337 * PARAMETERS: node - Device node being examined
339 * RETURN: TRUE if device is a PCI/PCI-Express Root Bridge
341 * DESCRIPTION: Determine if the input device represents a PCI Root Bridge by
342 * examining the _HID and _CID for the device.
344 ******************************************************************************/
346 u8 acpi_ev_is_pci_root_bridge(struct acpi_namespace_node *node)
349 struct acpi_pnp_device_id *hid;
350 struct acpi_pnp_device_id_list *cid;
354 /* Get the _HID and check for a PCI Root Bridge */
356 status = acpi_ut_execute_HID(node, &hid);
357 if (ACPI_FAILURE(status)) {
361 match = acpi_ut_is_pci_root_bridge(hid->string);
368 /* The _HID did not match. Get the _CID and check for a PCI Root Bridge */
370 status = acpi_ut_execute_CID(node, &cid);
371 if (ACPI_FAILURE(status)) {
375 /* Check all _CIDs in the returned list */
377 for (i = 0; i < cid->count; i++) {
378 if (acpi_ut_is_pci_root_bridge(cid->ids[i].string)) {
388 /*******************************************************************************
390 * FUNCTION: acpi_ev_pci_bar_region_setup
392 * PARAMETERS: handle - Region we are interested in
393 * function - Start or stop
394 * handler_context - Address space handler context
395 * region_context - Region specific context
399 * DESCRIPTION: Setup a pci_BAR operation region
401 * MUTEX: Assumes namespace is not locked
403 ******************************************************************************/
406 acpi_ev_pci_bar_region_setup(acpi_handle handle,
408 void *handler_context, void **region_context)
410 ACPI_FUNCTION_TRACE(ev_pci_bar_region_setup);
412 return_ACPI_STATUS(AE_OK);
415 /*******************************************************************************
417 * FUNCTION: acpi_ev_cmos_region_setup
419 * PARAMETERS: handle - Region we are interested in
420 * function - Start or stop
421 * handler_context - Address space handler context
422 * region_context - Region specific context
426 * DESCRIPTION: Setup a CMOS operation region
428 * MUTEX: Assumes namespace is not locked
430 ******************************************************************************/
433 acpi_ev_cmos_region_setup(acpi_handle handle,
435 void *handler_context, void **region_context)
437 ACPI_FUNCTION_TRACE(ev_cmos_region_setup);
439 return_ACPI_STATUS(AE_OK);
442 /*******************************************************************************
444 * FUNCTION: acpi_ev_default_region_setup
446 * PARAMETERS: handle - Region we are interested in
447 * function - Start or stop
448 * handler_context - Address space handler context
449 * region_context - Region specific context
453 * DESCRIPTION: Default region initialization
455 ******************************************************************************/
458 acpi_ev_default_region_setup(acpi_handle handle,
460 void *handler_context, void **region_context)
462 ACPI_FUNCTION_TRACE(ev_default_region_setup);
464 if (function == ACPI_REGION_DEACTIVATE) {
465 *region_context = NULL;
467 *region_context = handler_context;
470 return_ACPI_STATUS(AE_OK);
473 /*******************************************************************************
475 * FUNCTION: acpi_ev_initialize_region
477 * PARAMETERS: region_obj - Region we are initializing
478 * acpi_ns_locked - Is namespace locked?
482 * DESCRIPTION: Initializes the region, finds any _REG methods and saves them
483 * for execution at a later time
485 * Get the appropriate address space handler for a newly
488 * This also performs address space specific initialization. For
489 * example, PCI regions must have an _ADR object that contains
490 * a PCI address in the scope of the definition. This address is
491 * required to perform an access to PCI config space.
493 * MUTEX: Interpreter should be unlocked, because we may run the _REG
494 * method for this region.
496 ******************************************************************************/
499 acpi_ev_initialize_region(union acpi_operand_object *region_obj,
502 union acpi_operand_object *handler_obj;
503 union acpi_operand_object *obj_desc;
504 acpi_adr_space_type space_id;
505 struct acpi_namespace_node *node;
508 ACPI_FUNCTION_TRACE_U32(ev_initialize_region, acpi_ns_locked);
511 return_ACPI_STATUS(AE_BAD_PARAMETER);
514 if (region_obj->common.flags & AOPOBJ_OBJECT_INITIALIZED) {
515 return_ACPI_STATUS(AE_OK);
518 region_obj->common.flags |= AOPOBJ_OBJECT_INITIALIZED;
520 node = region_obj->region.node->parent;
521 space_id = region_obj->region.space_id;
524 * The following loop depends upon the root Node having no parent
525 * ie: acpi_gbl_root_node->Parent being set to NULL
529 /* Check to see if a handler exists */
532 obj_desc = acpi_ns_get_attached_object(node);
535 /* Can only be a handler if the object exists */
537 switch (node->type) {
538 case ACPI_TYPE_DEVICE:
539 case ACPI_TYPE_PROCESSOR:
540 case ACPI_TYPE_THERMAL:
542 handler_obj = obj_desc->common_notify.handler;
545 case ACPI_TYPE_METHOD:
547 * If we are executing module level code, the original
548 * Node's object was replaced by this Method object and we
549 * saved the handler in the method object.
551 * See acpi_ns_exec_module_code
553 if (!acpi_gbl_parse_table_as_term_list &&
555 info_flags & ACPI_METHOD_MODULE_LEVEL) {
557 obj_desc->method.dispatch.handler;
563 /* Ignore other objects */
569 acpi_ev_find_region_handler(space_id, handler_obj);
572 /* Found correct handler */
574 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
575 "Found handler %p for region %p in obj %p\n",
576 handler_obj, region_obj,
580 acpi_ev_attach_region(handler_obj,
585 * Tell all users that this region is usable by
586 * running the _REG method
588 if (acpi_ns_locked) {
590 acpi_ut_release_mutex
591 (ACPI_MTX_NAMESPACE);
592 if (ACPI_FAILURE(status)) {
593 return_ACPI_STATUS(status);
597 acpi_ex_exit_interpreter();
599 acpi_ev_execute_reg_method(region_obj,
601 acpi_ex_enter_interpreter();
603 if (acpi_ns_locked) {
605 acpi_ut_acquire_mutex
606 (ACPI_MTX_NAMESPACE);
607 if (ACPI_FAILURE(status)) {
608 return_ACPI_STATUS(status);
612 return_ACPI_STATUS(AE_OK);
616 /* This node does not have the handler we need; Pop up one level */
621 /* If we get here, there is no handler for this region */
623 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
624 "No handler for RegionType %s(%X) (RegionObj %p)\n",
625 acpi_ut_get_region_name(space_id), space_id,
628 return_ACPI_STATUS(AE_NOT_EXIST);