Erik Schmauss | 9585763 | 2018-03-14 16:13:07 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /****************************************************************************** |
| 3 | * |
| 4 | * Module Name: evrgnini- ACPI address_space (op_region) init |
| 5 | * |
Bob Moore | 800ba7c | 2020-01-10 11:31:49 -0800 | [diff] [blame] | 6 | * Copyright (C) 2000 - 2020, Intel Corp. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * |
Erik Schmauss | 9585763 | 2018-03-14 16:13:07 -0700 | [diff] [blame] | 8 | *****************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include <acpi/acpi.h> |
Len Brown | e2f7a77 | 2009-01-09 00:30:03 -0500 | [diff] [blame] | 11 | #include "accommon.h" |
| 12 | #include "acevents.h" |
| 13 | #include "acnamesp.h" |
Lv Zheng | 8633db6 | 2016-10-26 15:42:01 +0800 | [diff] [blame] | 14 | #include "acinterp.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | |
| 16 | #define _COMPONENT ACPI_EVENTS |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 17 | ACPI_MODULE_NAME("evrgnini") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | |
| 19 | /******************************************************************************* |
| 20 | * |
| 21 | * FUNCTION: acpi_ev_system_memory_region_setup |
| 22 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 23 | * PARAMETERS: handle - Region we are interested in |
| 24 | * function - Start or stop |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | * handler_context - Address space handler context |
| 26 | * region_context - Region specific context |
| 27 | * |
| 28 | * RETURN: Status |
| 29 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 30 | * DESCRIPTION: Setup a system_memory operation region |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | * |
| 32 | ******************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 34 | acpi_ev_system_memory_region_setup(acpi_handle handle, |
| 35 | u32 function, |
| 36 | void *handler_context, void **region_context) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 38 | union acpi_operand_object *region_desc = |
| 39 | (union acpi_operand_object *)handle; |
| 40 | struct acpi_mem_space_context *local_region_context; |
Rafael J. Wysocki | b8fcd0e | 2020-06-30 13:40:59 +0200 | [diff] [blame] | 41 | struct acpi_mem_mapping *mm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 43 | ACPI_FUNCTION_TRACE(ev_system_memory_region_setup); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | |
| 45 | if (function == ACPI_REGION_DEACTIVATE) { |
| 46 | if (*region_context) { |
Bob Moore | 793c238 | 2006-03-31 00:00:00 -0500 | [diff] [blame] | 47 | local_region_context = |
| 48 | (struct acpi_mem_space_context *)*region_context; |
| 49 | |
Rafael J. Wysocki | b8fcd0e | 2020-06-30 13:40:59 +0200 | [diff] [blame] | 50 | /* Delete memory mappings if present */ |
Bob Moore | 793c238 | 2006-03-31 00:00:00 -0500 | [diff] [blame] | 51 | |
Rafael J. Wysocki | b8fcd0e | 2020-06-30 13:40:59 +0200 | [diff] [blame] | 52 | while (local_region_context->first_mm) { |
| 53 | mm = local_region_context->first_mm; |
| 54 | local_region_context->first_mm = mm->next_mm; |
| 55 | acpi_os_unmap_memory(mm->logical_address, |
| 56 | mm->length); |
| 57 | ACPI_FREE(mm); |
Bob Moore | 793c238 | 2006-03-31 00:00:00 -0500 | [diff] [blame] | 58 | } |
| 59 | ACPI_FREE(local_region_context); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | *region_context = NULL; |
| 61 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 62 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | /* Create a new context */ |
| 66 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 67 | local_region_context = |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 68 | ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_mem_space_context)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | if (!(local_region_context)) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 70 | return_ACPI_STATUS(AE_NO_MEMORY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | /* Save the region length and address for use in the handler */ |
| 74 | |
| 75 | local_region_context->length = region_desc->region.length; |
| 76 | local_region_context->address = region_desc->region.address; |
| 77 | |
| 78 | *region_context = local_region_context; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 79 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | } |
| 81 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | /******************************************************************************* |
| 83 | * |
| 84 | * FUNCTION: acpi_ev_io_space_region_setup |
| 85 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 86 | * PARAMETERS: handle - Region we are interested in |
| 87 | * function - Start or stop |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | * handler_context - Address space handler context |
| 89 | * region_context - Region specific context |
| 90 | * |
| 91 | * RETURN: Status |
| 92 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 93 | * DESCRIPTION: Setup a IO operation region |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | * |
| 95 | ******************************************************************************/ |
| 96 | |
| 97 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 98 | acpi_ev_io_space_region_setup(acpi_handle handle, |
| 99 | u32 function, |
| 100 | void *handler_context, void **region_context) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | { |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 102 | ACPI_FUNCTION_TRACE(ev_io_space_region_setup); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | |
| 104 | if (function == ACPI_REGION_DEACTIVATE) { |
| 105 | *region_context = NULL; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 106 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | *region_context = handler_context; |
| 108 | } |
| 109 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 110 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | } |
| 112 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | /******************************************************************************* |
| 114 | * |
| 115 | * FUNCTION: acpi_ev_pci_config_region_setup |
| 116 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 117 | * PARAMETERS: handle - Region we are interested in |
| 118 | * function - Start or stop |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | * handler_context - Address space handler context |
| 120 | * region_context - Region specific context |
| 121 | * |
| 122 | * RETURN: Status |
| 123 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 124 | * DESCRIPTION: Setup a PCI_Config operation region |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | * |
| 126 | * MUTEX: Assumes namespace is not locked |
| 127 | * |
| 128 | ******************************************************************************/ |
| 129 | |
| 130 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 131 | acpi_ev_pci_config_region_setup(acpi_handle handle, |
| 132 | u32 function, |
| 133 | void *handler_context, void **region_context) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 135 | acpi_status status = AE_OK; |
Bob Moore | 5df7e6c | 2010-01-21 10:06:32 +0800 | [diff] [blame] | 136 | u64 pci_value; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 137 | struct acpi_pci_id *pci_id = *region_context; |
| 138 | union acpi_operand_object *handler_obj; |
| 139 | struct acpi_namespace_node *parent_node; |
| 140 | struct acpi_namespace_node *pci_root_node; |
Bob Moore | b7a6980 | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 141 | struct acpi_namespace_node *pci_device_node; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 142 | union acpi_operand_object *region_obj = |
| 143 | (union acpi_operand_object *)handle; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 145 | ACPI_FUNCTION_TRACE(ev_pci_config_region_setup); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | |
| 147 | handler_obj = region_obj->region.handler; |
| 148 | if (!handler_obj) { |
| 149 | /* |
| 150 | * No installed handler. This shouldn't happen because the dispatch |
| 151 | * routine checks before we get here, but we check again just in case. |
| 152 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 153 | ACPI_DEBUG_PRINT((ACPI_DB_OPREGION, |
| 154 | "Attempting to init a region %p, with no handler\n", |
| 155 | region_obj)); |
| 156 | return_ACPI_STATUS(AE_NOT_EXIST); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | *region_context = NULL; |
| 160 | if (function == ACPI_REGION_DEACTIVATE) { |
| 161 | if (pci_id) { |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 162 | ACPI_FREE(pci_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 164 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | } |
| 166 | |
Alexey Starikovskiy | c45b5c0 | 2010-05-26 11:53:07 +0800 | [diff] [blame] | 167 | parent_node = region_obj->region.node->parent; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | |
| 169 | /* |
| 170 | * Get the _SEG and _BBN values from the device upon which the handler |
| 171 | * is installed. |
| 172 | * |
| 173 | * We need to get the _SEG and _BBN objects relative to the PCI BUS device. |
| 174 | * This is the device the handler has been registered to handle. |
| 175 | */ |
| 176 | |
| 177 | /* |
| 178 | * If the address_space.Node is still pointing to the root, we need |
| 179 | * to scan upward for a PCI Root bridge and re-associate the op_region |
| 180 | * handlers with that device. |
| 181 | */ |
| 182 | if (handler_obj->address_space.node == acpi_gbl_root_node) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 183 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | /* Start search from the parent object */ |
| 185 | |
| 186 | pci_root_node = parent_node; |
| 187 | while (pci_root_node != acpi_gbl_root_node) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 188 | |
Bob Moore | b7a6980 | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 189 | /* Get the _HID/_CID in order to detect a root_bridge */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | |
Bob Moore | b7a6980 | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 191 | if (acpi_ev_is_pci_root_bridge(pci_root_node)) { |
| 192 | |
| 193 | /* Install a handler for this PCI root bridge */ |
| 194 | |
Lv Zheng | f5c1e1c | 2016-05-05 12:57:53 +0800 | [diff] [blame] | 195 | status = acpi_install_address_space_handler((acpi_handle)pci_root_node, ACPI_ADR_SPACE_PCI_CONFIG, ACPI_DEFAULT_HANDLER, NULL, NULL); |
Bob Moore | b7a6980 | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 196 | if (ACPI_FAILURE(status)) { |
| 197 | if (status == AE_SAME_HANDLER) { |
| 198 | /* |
Bob Moore | 9f15fc6 | 2008-11-12 16:01:56 +0800 | [diff] [blame] | 199 | * It is OK if the handler is already installed on the |
| 200 | * root bridge. Still need to return a context object |
| 201 | * for the new PCI_Config operation region, however. |
Bob Moore | b7a6980 | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 202 | */ |
Bob Moore | b7a6980 | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 203 | } else { |
| 204 | ACPI_EXCEPTION((AE_INFO, status, |
Bob Moore | d4913dc | 2009-03-06 10:05:18 +0800 | [diff] [blame] | 205 | "Could not install PciConfig handler " |
| 206 | "for Root Bridge %4.4s", |
Bob Moore | b7a6980 | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 207 | acpi_ut_get_node_name |
| 208 | (pci_root_node))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | } |
Bob Moore | b7a6980 | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 211 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | } |
| 213 | |
Alexey Starikovskiy | c45b5c0 | 2010-05-26 11:53:07 +0800 | [diff] [blame] | 214 | pci_root_node = pci_root_node->parent; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | /* PCI root bridge not found, use namespace root node */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 218 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | pci_root_node = handler_obj->address_space.node; |
| 220 | } |
| 221 | |
| 222 | /* |
| 223 | * If this region is now initialized, we are done. |
| 224 | * (install_address_space_handler could have initialized it) |
| 225 | */ |
| 226 | if (region_obj->region.flags & AOPOBJ_SETUP_COMPLETE) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 227 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | /* Region is still not initialized. Create a new context */ |
| 231 | |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 232 | pci_id = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_pci_id)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | if (!pci_id) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 234 | return_ACPI_STATUS(AE_NO_MEMORY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | /* |
Bob Moore | 9f15fc6 | 2008-11-12 16:01:56 +0800 | [diff] [blame] | 238 | * For PCI_Config space access, we need the segment, bus, device and |
| 239 | * function numbers. Acquire them here. |
Bob Moore | b7a6980 | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 240 | * |
| 241 | * Find the parent device object. (This allows the operation region to be |
| 242 | * within a subscope under the device, such as a control method.) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | */ |
Bob Moore | b7a6980 | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 244 | pci_device_node = region_obj->region.node; |
| 245 | while (pci_device_node && (pci_device_node->type != ACPI_TYPE_DEVICE)) { |
Alexey Starikovskiy | c45b5c0 | 2010-05-26 11:53:07 +0800 | [diff] [blame] | 246 | pci_device_node = pci_device_node->parent; |
Bob Moore | b7a6980 | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | if (!pci_device_node) { |
Jesper Juhl | e691731 | 2007-07-19 00:48:03 +0200 | [diff] [blame] | 250 | ACPI_FREE(pci_id); |
Bob Moore | b7a6980 | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 251 | return_ACPI_STATUS(AE_AML_OPERAND_TYPE); |
| 252 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | |
| 254 | /* |
Bob Moore | 95abccb | 2010-09-15 13:22:46 +0800 | [diff] [blame] | 255 | * Get the PCI device and function numbers from the _ADR object |
| 256 | * contained in the parent's scope. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | */ |
Bob Moore | d4913dc | 2009-03-06 10:05:18 +0800 | [diff] [blame] | 258 | status = acpi_ut_evaluate_numeric_object(METHOD_NAME__ADR, |
| 259 | pci_device_node, &pci_value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | |
| 261 | /* |
Bob Moore | 9f15fc6 | 2008-11-12 16:01:56 +0800 | [diff] [blame] | 262 | * The default is zero, and since the allocation above zeroed the data, |
| 263 | * just do nothing on failure. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 265 | if (ACPI_SUCCESS(status)) { |
| 266 | pci_id->device = ACPI_HIWORD(ACPI_LODWORD(pci_value)); |
| 267 | pci_id->function = ACPI_LOWORD(ACPI_LODWORD(pci_value)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | /* The PCI segment number comes from the _SEG method */ |
| 271 | |
Bob Moore | d4913dc | 2009-03-06 10:05:18 +0800 | [diff] [blame] | 272 | status = acpi_ut_evaluate_numeric_object(METHOD_NAME__SEG, |
| 273 | pci_root_node, &pci_value); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 274 | if (ACPI_SUCCESS(status)) { |
| 275 | pci_id->segment = ACPI_LOWORD(pci_value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | /* The PCI bus number comes from the _BBN method */ |
| 279 | |
Bob Moore | d4913dc | 2009-03-06 10:05:18 +0800 | [diff] [blame] | 280 | status = acpi_ut_evaluate_numeric_object(METHOD_NAME__BBN, |
| 281 | pci_root_node, &pci_value); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 282 | if (ACPI_SUCCESS(status)) { |
| 283 | pci_id->bus = ACPI_LOWORD(pci_value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | } |
| 285 | |
Bob Moore | 95abccb | 2010-09-15 13:22:46 +0800 | [diff] [blame] | 286 | /* Complete/update the PCI ID for this device */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | |
Bob Moore | 95abccb | 2010-09-15 13:22:46 +0800 | [diff] [blame] | 288 | status = |
| 289 | acpi_hw_derive_pci_id(pci_id, pci_root_node, |
| 290 | region_obj->region.node); |
| 291 | if (ACPI_FAILURE(status)) { |
| 292 | ACPI_FREE(pci_id); |
| 293 | return_ACPI_STATUS(status); |
| 294 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | |
| 296 | *region_context = pci_id; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 297 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | } |
| 299 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | /******************************************************************************* |
| 301 | * |
Bob Moore | b7a6980 | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 302 | * FUNCTION: acpi_ev_is_pci_root_bridge |
| 303 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 304 | * PARAMETERS: node - Device node being examined |
Bob Moore | b7a6980 | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 305 | * |
| 306 | * RETURN: TRUE if device is a PCI/PCI-Express Root Bridge |
| 307 | * |
| 308 | * DESCRIPTION: Determine if the input device represents a PCI Root Bridge by |
| 309 | * examining the _HID and _CID for the device. |
| 310 | * |
| 311 | ******************************************************************************/ |
| 312 | |
Bob Moore | 8b1cafd | 2018-10-03 11:45:38 -0700 | [diff] [blame] | 313 | u8 acpi_ev_is_pci_root_bridge(struct acpi_namespace_node *node) |
Bob Moore | b7a6980 | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 314 | { |
| 315 | acpi_status status; |
Lv Zheng | 78e25fe | 2012-10-31 02:25:24 +0000 | [diff] [blame] | 316 | struct acpi_pnp_device_id *hid; |
| 317 | struct acpi_pnp_device_id_list *cid; |
Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 318 | u32 i; |
Bob Moore | 15b8dd5 | 2009-06-29 13:39:29 +0800 | [diff] [blame] | 319 | u8 match; |
Bob Moore | b7a6980 | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 320 | |
Bob Moore | 9f15fc6 | 2008-11-12 16:01:56 +0800 | [diff] [blame] | 321 | /* Get the _HID and check for a PCI Root Bridge */ |
| 322 | |
Bob Moore | b7a6980 | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 323 | status = acpi_ut_execute_HID(node, &hid); |
| 324 | if (ACPI_FAILURE(status)) { |
| 325 | return (FALSE); |
| 326 | } |
| 327 | |
Bob Moore | 15b8dd5 | 2009-06-29 13:39:29 +0800 | [diff] [blame] | 328 | match = acpi_ut_is_pci_root_bridge(hid->string); |
| 329 | ACPI_FREE(hid); |
| 330 | |
| 331 | if (match) { |
Bob Moore | b7a6980 | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 332 | return (TRUE); |
| 333 | } |
| 334 | |
Bob Moore | 9f15fc6 | 2008-11-12 16:01:56 +0800 | [diff] [blame] | 335 | /* The _HID did not match. Get the _CID and check for a PCI Root Bridge */ |
| 336 | |
Bob Moore | b7a6980 | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 337 | status = acpi_ut_execute_CID(node, &cid); |
| 338 | if (ACPI_FAILURE(status)) { |
| 339 | return (FALSE); |
| 340 | } |
| 341 | |
| 342 | /* Check all _CIDs in the returned list */ |
| 343 | |
| 344 | for (i = 0; i < cid->count; i++) { |
Bob Moore | 15b8dd5 | 2009-06-29 13:39:29 +0800 | [diff] [blame] | 345 | if (acpi_ut_is_pci_root_bridge(cid->ids[i].string)) { |
Bob Moore | b7a6980 | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 346 | ACPI_FREE(cid); |
| 347 | return (TRUE); |
| 348 | } |
| 349 | } |
| 350 | |
| 351 | ACPI_FREE(cid); |
| 352 | return (FALSE); |
| 353 | } |
| 354 | |
| 355 | /******************************************************************************* |
| 356 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | * FUNCTION: acpi_ev_pci_bar_region_setup |
| 358 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 359 | * PARAMETERS: handle - Region we are interested in |
| 360 | * function - Start or stop |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | * handler_context - Address space handler context |
| 362 | * region_context - Region specific context |
| 363 | * |
| 364 | * RETURN: Status |
| 365 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 366 | * DESCRIPTION: Setup a pci_BAR operation region |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | * |
| 368 | * MUTEX: Assumes namespace is not locked |
| 369 | * |
| 370 | ******************************************************************************/ |
| 371 | |
| 372 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 373 | acpi_ev_pci_bar_region_setup(acpi_handle handle, |
| 374 | u32 function, |
| 375 | void *handler_context, void **region_context) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | { |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 377 | ACPI_FUNCTION_TRACE(ev_pci_bar_region_setup); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 379 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | } |
| 381 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | /******************************************************************************* |
| 383 | * |
| 384 | * FUNCTION: acpi_ev_cmos_region_setup |
| 385 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 386 | * PARAMETERS: handle - Region we are interested in |
| 387 | * function - Start or stop |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | * handler_context - Address space handler context |
| 389 | * region_context - Region specific context |
| 390 | * |
| 391 | * RETURN: Status |
| 392 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 393 | * DESCRIPTION: Setup a CMOS operation region |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | * |
| 395 | * MUTEX: Assumes namespace is not locked |
| 396 | * |
| 397 | ******************************************************************************/ |
| 398 | |
| 399 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 400 | acpi_ev_cmos_region_setup(acpi_handle handle, |
| 401 | u32 function, |
| 402 | void *handler_context, void **region_context) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | { |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 404 | ACPI_FUNCTION_TRACE(ev_cmos_region_setup); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 406 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | } |
| 408 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | /******************************************************************************* |
| 410 | * |
| 411 | * FUNCTION: acpi_ev_default_region_setup |
| 412 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 413 | * PARAMETERS: handle - Region we are interested in |
| 414 | * function - Start or stop |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | * handler_context - Address space handler context |
| 416 | * region_context - Region specific context |
| 417 | * |
| 418 | * RETURN: Status |
| 419 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 420 | * DESCRIPTION: Default region initialization |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | * |
| 422 | ******************************************************************************/ |
| 423 | |
| 424 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 425 | acpi_ev_default_region_setup(acpi_handle handle, |
| 426 | u32 function, |
| 427 | void *handler_context, void **region_context) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | { |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 429 | ACPI_FUNCTION_TRACE(ev_default_region_setup); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | |
| 431 | if (function == ACPI_REGION_DEACTIVATE) { |
| 432 | *region_context = NULL; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 433 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | *region_context = handler_context; |
| 435 | } |
| 436 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 437 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | } |
| 439 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | /******************************************************************************* |
| 441 | * |
| 442 | * FUNCTION: acpi_ev_initialize_region |
| 443 | * |
| 444 | * PARAMETERS: region_obj - Region we are initializing |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | * |
| 446 | * RETURN: Status |
| 447 | * |
| 448 | * DESCRIPTION: Initializes the region, finds any _REG methods and saves them |
| 449 | * for execution at a later time |
| 450 | * |
| 451 | * Get the appropriate address space handler for a newly |
| 452 | * created region. |
| 453 | * |
Bob Moore | 9f15fc6 | 2008-11-12 16:01:56 +0800 | [diff] [blame] | 454 | * This also performs address space specific initialization. For |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | * example, PCI regions must have an _ADR object that contains |
Bob Moore | 9f15fc6 | 2008-11-12 16:01:56 +0800 | [diff] [blame] | 456 | * a PCI address in the scope of the definition. This address is |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | * required to perform an access to PCI config space. |
| 458 | * |
Bob Moore | c9e3ba2 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 459 | * MUTEX: Interpreter should be unlocked, because we may run the _REG |
| 460 | * method for this region. |
| 461 | * |
Lv Zheng | 760235c | 2016-11-30 15:21:12 +0800 | [diff] [blame] | 462 | * NOTE: Possible incompliance: |
| 463 | * There is a behavior conflict in automatic _REG execution: |
| 464 | * 1. When the interpreter is evaluating a method, we can only |
| 465 | * automatically run _REG for the following case: |
| 466 | * operation_region (OPR1, 0x80, 0x1000010, 0x4) |
| 467 | * 2. When the interpreter is loading a table, we can also |
| 468 | * automatically run _REG for the following case: |
| 469 | * operation_region (OPR1, 0x80, 0x1000010, 0x4) |
| 470 | * Though this may not be compliant to the de-facto standard, the |
| 471 | * logic is kept in order not to trigger regressions. And keeping |
| 472 | * this logic should be taken care by the caller of this function. |
| 473 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | ******************************************************************************/ |
| 475 | |
Lv Zheng | 760235c | 2016-11-30 15:21:12 +0800 | [diff] [blame] | 476 | acpi_status acpi_ev_initialize_region(union acpi_operand_object *region_obj) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 478 | union acpi_operand_object *handler_obj; |
| 479 | union acpi_operand_object *obj_desc; |
| 480 | acpi_adr_space_type space_id; |
| 481 | struct acpi_namespace_node *node; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | |
Lv Zheng | 760235c | 2016-11-30 15:21:12 +0800 | [diff] [blame] | 483 | ACPI_FUNCTION_TRACE(ev_initialize_region); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | |
| 485 | if (!region_obj) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 486 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | } |
| 488 | |
| 489 | if (region_obj->common.flags & AOPOBJ_OBJECT_INITIALIZED) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 490 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | } |
| 492 | |
Lv Zheng | 849c257 | 2015-12-29 14:02:58 +0800 | [diff] [blame] | 493 | region_obj->common.flags |= AOPOBJ_OBJECT_INITIALIZED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | |
Alexey Starikovskiy | c45b5c0 | 2010-05-26 11:53:07 +0800 | [diff] [blame] | 495 | node = region_obj->region.node->parent; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | space_id = region_obj->region.space_id; |
| 497 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | /* |
| 499 | * The following loop depends upon the root Node having no parent |
Bob Moore | 7b73806 | 2015-12-29 14:01:53 +0800 | [diff] [blame] | 500 | * ie: acpi_gbl_root_node->Parent being set to NULL |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | */ |
| 502 | while (node) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 503 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | /* Check to see if a handler exists */ |
| 505 | |
| 506 | handler_obj = NULL; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 507 | obj_desc = acpi_ns_get_attached_object(node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | if (obj_desc) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 509 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | /* Can only be a handler if the object exists */ |
| 511 | |
| 512 | switch (node->type) { |
| 513 | case ACPI_TYPE_DEVICE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | case ACPI_TYPE_PROCESSOR: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | case ACPI_TYPE_THERMAL: |
| 516 | |
Lv Zheng | aa6abd2 | 2015-12-29 14:02:08 +0800 | [diff] [blame] | 517 | handler_obj = obj_desc->common_notify.handler; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | break; |
| 519 | |
| 520 | default: |
Chao Guan | 1d1ea1b7 | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 521 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | /* Ignore other objects */ |
Chao Guan | 1d1ea1b7 | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 523 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | break; |
| 525 | } |
| 526 | |
Lv Zheng | f31a99ce | 2015-12-29 14:02:00 +0800 | [diff] [blame] | 527 | handler_obj = |
| 528 | acpi_ev_find_region_handler(space_id, handler_obj); |
| 529 | if (handler_obj) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 530 | |
Lv Zheng | f31a99ce | 2015-12-29 14:02:00 +0800 | [diff] [blame] | 531 | /* Found correct handler */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | |
Lv Zheng | f31a99ce | 2015-12-29 14:02:00 +0800 | [diff] [blame] | 533 | ACPI_DEBUG_PRINT((ACPI_DB_OPREGION, |
| 534 | "Found handler %p for region %p in obj %p\n", |
| 535 | handler_obj, region_obj, |
| 536 | obj_desc)); |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 537 | |
Lv Zheng | 760235c | 2016-11-30 15:21:12 +0800 | [diff] [blame] | 538 | (void)acpi_ev_attach_region(handler_obj, |
| 539 | region_obj, FALSE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | |
Lv Zheng | f31a99ce | 2015-12-29 14:02:00 +0800 | [diff] [blame] | 541 | /* |
| 542 | * Tell all users that this region is usable by |
| 543 | * running the _REG method |
| 544 | */ |
Lv Zheng | 8633db6 | 2016-10-26 15:42:01 +0800 | [diff] [blame] | 545 | acpi_ex_exit_interpreter(); |
Lv Zheng | 760235c | 2016-11-30 15:21:12 +0800 | [diff] [blame] | 546 | (void)acpi_ev_execute_reg_method(region_obj, |
| 547 | ACPI_REG_CONNECT); |
Lv Zheng | 8633db6 | 2016-10-26 15:42:01 +0800 | [diff] [blame] | 548 | acpi_ex_enter_interpreter(); |
Lv Zheng | f31a99ce | 2015-12-29 14:02:00 +0800 | [diff] [blame] | 549 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | } |
| 551 | } |
| 552 | |
Bob Moore | 9f15fc6 | 2008-11-12 16:01:56 +0800 | [diff] [blame] | 553 | /* This node does not have the handler we need; Pop up one level */ |
| 554 | |
Alexey Starikovskiy | c45b5c0 | 2010-05-26 11:53:07 +0800 | [diff] [blame] | 555 | node = node->parent; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | } |
| 557 | |
Lv Zheng | 760235c | 2016-11-30 15:21:12 +0800 | [diff] [blame] | 558 | /* |
| 559 | * If we get here, there is no handler for this region. This is not |
| 560 | * fatal because many regions get created before a handler is installed |
| 561 | * for said region. |
| 562 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 563 | ACPI_DEBUG_PRINT((ACPI_DB_OPREGION, |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 564 | "No handler for RegionType %s(%X) (RegionObj %p)\n", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 565 | acpi_ut_get_region_name(space_id), space_id, |
| 566 | region_obj)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | |
Lv Zheng | 760235c | 2016-11-30 15:21:12 +0800 | [diff] [blame] | 568 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | } |