blob: 89be3ccdad5383c4687d06ac1d1fe68c37116076 [file] [log] [blame]
Erik Schmauss95857632018-03-14 16:13:07 -07001// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/******************************************************************************
3 *
4 * Module Name: evrgnini- ACPI address_space (op_region) init
5 *
Bob Moore800ba7c2020-01-10 11:31:49 -08006 * Copyright (C) 2000 - 2020, Intel Corp.
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 *
Erik Schmauss95857632018-03-14 16:13:07 -07008 *****************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07009
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#include <acpi/acpi.h>
Len Browne2f7a772009-01-09 00:30:03 -050011#include "accommon.h"
12#include "acevents.h"
13#include "acnamesp.h"
Lv Zheng8633db62016-10-26 15:42:01 +080014#include "acinterp.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070015
16#define _COMPONENT ACPI_EVENTS
Len Brown4be44fc2005-08-05 00:44:28 -040017ACPI_MODULE_NAME("evrgnini")
Linus Torvalds1da177e2005-04-16 15:20:36 -070018
19/*******************************************************************************
20 *
21 * FUNCTION: acpi_ev_system_memory_region_setup
22 *
Bob Mooreba494be2012-07-12 09:40:10 +080023 * PARAMETERS: handle - Region we are interested in
24 * function - Start or stop
Linus Torvalds1da177e2005-04-16 15:20:36 -070025 * handler_context - Address space handler context
26 * region_context - Region specific context
27 *
28 * RETURN: Status
29 *
Robert Moore44f6c012005-04-18 22:49:35 -040030 * DESCRIPTION: Setup a system_memory operation region
Linus Torvalds1da177e2005-04-16 15:20:36 -070031 *
32 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -070033acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040034acpi_ev_system_memory_region_setup(acpi_handle handle,
35 u32 function,
36 void *handler_context, void **region_context)
Linus Torvalds1da177e2005-04-16 15:20:36 -070037{
Len Brown4be44fc2005-08-05 00:44:28 -040038 union acpi_operand_object *region_desc =
39 (union acpi_operand_object *)handle;
40 struct acpi_mem_space_context *local_region_context;
Rafael J. Wysockib8fcd0e2020-06-30 13:40:59 +020041 struct acpi_mem_mapping *mm;
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
Bob Mooreb229cf92006-04-21 17:15:00 -040043 ACPI_FUNCTION_TRACE(ev_system_memory_region_setup);
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
45 if (function == ACPI_REGION_DEACTIVATE) {
46 if (*region_context) {
Bob Moore793c2382006-03-31 00:00:00 -050047 local_region_context =
48 (struct acpi_mem_space_context *)*region_context;
49
Rafael J. Wysockib8fcd0e2020-06-30 13:40:59 +020050 /* Delete memory mappings if present */
Bob Moore793c2382006-03-31 00:00:00 -050051
Rafael J. Wysockib8fcd0e2020-06-30 13:40:59 +020052 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 Moore793c2382006-03-31 00:00:00 -050058 }
59 ACPI_FREE(local_region_context);
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 *region_context = NULL;
61 }
Len Brown4be44fc2005-08-05 00:44:28 -040062 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 }
64
65 /* Create a new context */
66
Len Brown4be44fc2005-08-05 00:44:28 -040067 local_region_context =
Bob Moore83135242006-10-03 00:00:00 -040068 ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_mem_space_context));
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 if (!(local_region_context)) {
Len Brown4be44fc2005-08-05 00:44:28 -040070 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 }
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 Brown4be44fc2005-08-05 00:44:28 -040079 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -070080}
81
Linus Torvalds1da177e2005-04-16 15:20:36 -070082/*******************************************************************************
83 *
84 * FUNCTION: acpi_ev_io_space_region_setup
85 *
Bob Mooreba494be2012-07-12 09:40:10 +080086 * PARAMETERS: handle - Region we are interested in
87 * function - Start or stop
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 * handler_context - Address space handler context
89 * region_context - Region specific context
90 *
91 * RETURN: Status
92 *
Robert Moore44f6c012005-04-18 22:49:35 -040093 * DESCRIPTION: Setup a IO operation region
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 *
95 ******************************************************************************/
96
97acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040098acpi_ev_io_space_region_setup(acpi_handle handle,
99 u32 function,
100 void *handler_context, void **region_context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101{
Bob Mooreb229cf92006-04-21 17:15:00 -0400102 ACPI_FUNCTION_TRACE(ev_io_space_region_setup);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103
104 if (function == ACPI_REGION_DEACTIVATE) {
105 *region_context = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400106 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 *region_context = handler_context;
108 }
109
Len Brown4be44fc2005-08-05 00:44:28 -0400110 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111}
112
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113/*******************************************************************************
114 *
115 * FUNCTION: acpi_ev_pci_config_region_setup
116 *
Bob Mooreba494be2012-07-12 09:40:10 +0800117 * PARAMETERS: handle - Region we are interested in
118 * function - Start or stop
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 * handler_context - Address space handler context
120 * region_context - Region specific context
121 *
122 * RETURN: Status
123 *
Robert Moore44f6c012005-04-18 22:49:35 -0400124 * DESCRIPTION: Setup a PCI_Config operation region
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 *
126 * MUTEX: Assumes namespace is not locked
127 *
128 ******************************************************************************/
129
130acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400131acpi_ev_pci_config_region_setup(acpi_handle handle,
132 u32 function,
133 void *handler_context, void **region_context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134{
Len Brown4be44fc2005-08-05 00:44:28 -0400135 acpi_status status = AE_OK;
Bob Moore5df7e6c2010-01-21 10:06:32 +0800136 u64 pci_value;
Len Brown4be44fc2005-08-05 00:44:28 -0400137 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 Mooreb7a69802007-02-02 19:48:21 +0300141 struct acpi_namespace_node *pci_device_node;
Len Brown4be44fc2005-08-05 00:44:28 -0400142 union acpi_operand_object *region_obj =
143 (union acpi_operand_object *)handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144
Bob Mooreb229cf92006-04-21 17:15:00 -0400145 ACPI_FUNCTION_TRACE(ev_pci_config_region_setup);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146
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 Brown4be44fc2005-08-05 00:44:28 -0400153 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 Torvalds1da177e2005-04-16 15:20:36 -0700157 }
158
159 *region_context = NULL;
160 if (function == ACPI_REGION_DEACTIVATE) {
161 if (pci_id) {
Bob Moore83135242006-10-03 00:00:00 -0400162 ACPI_FREE(pci_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 }
Len Brown4be44fc2005-08-05 00:44:28 -0400164 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 }
166
Alexey Starikovskiyc45b5c02010-05-26 11:53:07 +0800167 parent_node = region_obj->region.node->parent;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168
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 Moore52fc0b02006-10-02 00:00:00 -0400183
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 /* Start search from the parent object */
185
186 pci_root_node = parent_node;
187 while (pci_root_node != acpi_gbl_root_node) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400188
Bob Mooreb7a69802007-02-02 19:48:21 +0300189 /* Get the _HID/_CID in order to detect a root_bridge */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190
Bob Mooreb7a69802007-02-02 19:48:21 +0300191 if (acpi_ev_is_pci_root_bridge(pci_root_node)) {
192
193 /* Install a handler for this PCI root bridge */
194
Lv Zhengf5c1e1c2016-05-05 12:57:53 +0800195 status = acpi_install_address_space_handler((acpi_handle)pci_root_node, ACPI_ADR_SPACE_PCI_CONFIG, ACPI_DEFAULT_HANDLER, NULL, NULL);
Bob Mooreb7a69802007-02-02 19:48:21 +0300196 if (ACPI_FAILURE(status)) {
197 if (status == AE_SAME_HANDLER) {
198 /*
Bob Moore9f15fc62008-11-12 16:01:56 +0800199 * 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 Mooreb7a69802007-02-02 19:48:21 +0300202 */
Bob Mooreb7a69802007-02-02 19:48:21 +0300203 } else {
204 ACPI_EXCEPTION((AE_INFO, status,
Bob Moored4913dc2009-03-06 10:05:18 +0800205 "Could not install PciConfig handler "
206 "for Root Bridge %4.4s",
Bob Mooreb7a69802007-02-02 19:48:21 +0300207 acpi_ut_get_node_name
208 (pci_root_node)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 }
Bob Mooreb7a69802007-02-02 19:48:21 +0300211 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 }
213
Alexey Starikovskiyc45b5c02010-05-26 11:53:07 +0800214 pci_root_node = pci_root_node->parent;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 }
216
217 /* PCI root bridge not found, use namespace root node */
Len Brown4be44fc2005-08-05 00:44:28 -0400218 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 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 Brown4be44fc2005-08-05 00:44:28 -0400227 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 }
229
230 /* Region is still not initialized. Create a new context */
231
Bob Moore83135242006-10-03 00:00:00 -0400232 pci_id = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_pci_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 if (!pci_id) {
Len Brown4be44fc2005-08-05 00:44:28 -0400234 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 }
236
237 /*
Bob Moore9f15fc62008-11-12 16:01:56 +0800238 * For PCI_Config space access, we need the segment, bus, device and
239 * function numbers. Acquire them here.
Bob Mooreb7a69802007-02-02 19:48:21 +0300240 *
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 Torvalds1da177e2005-04-16 15:20:36 -0700243 */
Bob Mooreb7a69802007-02-02 19:48:21 +0300244 pci_device_node = region_obj->region.node;
245 while (pci_device_node && (pci_device_node->type != ACPI_TYPE_DEVICE)) {
Alexey Starikovskiyc45b5c02010-05-26 11:53:07 +0800246 pci_device_node = pci_device_node->parent;
Bob Mooreb7a69802007-02-02 19:48:21 +0300247 }
248
249 if (!pci_device_node) {
Jesper Juhle6917312007-07-19 00:48:03 +0200250 ACPI_FREE(pci_id);
Bob Mooreb7a69802007-02-02 19:48:21 +0300251 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
252 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253
254 /*
Bob Moore95abccb2010-09-15 13:22:46 +0800255 * Get the PCI device and function numbers from the _ADR object
256 * contained in the parent's scope.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 */
Bob Moored4913dc2009-03-06 10:05:18 +0800258 status = acpi_ut_evaluate_numeric_object(METHOD_NAME__ADR,
259 pci_device_node, &pci_value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260
261 /*
Bob Moore9f15fc62008-11-12 16:01:56 +0800262 * The default is zero, and since the allocation above zeroed the data,
263 * just do nothing on failure.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 */
Len Brown4be44fc2005-08-05 00:44:28 -0400265 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 Torvalds1da177e2005-04-16 15:20:36 -0700268 }
269
270 /* The PCI segment number comes from the _SEG method */
271
Bob Moored4913dc2009-03-06 10:05:18 +0800272 status = acpi_ut_evaluate_numeric_object(METHOD_NAME__SEG,
273 pci_root_node, &pci_value);
Len Brown4be44fc2005-08-05 00:44:28 -0400274 if (ACPI_SUCCESS(status)) {
275 pci_id->segment = ACPI_LOWORD(pci_value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 }
277
278 /* The PCI bus number comes from the _BBN method */
279
Bob Moored4913dc2009-03-06 10:05:18 +0800280 status = acpi_ut_evaluate_numeric_object(METHOD_NAME__BBN,
281 pci_root_node, &pci_value);
Len Brown4be44fc2005-08-05 00:44:28 -0400282 if (ACPI_SUCCESS(status)) {
283 pci_id->bus = ACPI_LOWORD(pci_value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 }
285
Bob Moore95abccb2010-09-15 13:22:46 +0800286 /* Complete/update the PCI ID for this device */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287
Bob Moore95abccb2010-09-15 13:22:46 +0800288 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 Torvalds1da177e2005-04-16 15:20:36 -0700295
296 *region_context = pci_id;
Len Brown4be44fc2005-08-05 00:44:28 -0400297 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298}
299
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300/*******************************************************************************
301 *
Bob Mooreb7a69802007-02-02 19:48:21 +0300302 * FUNCTION: acpi_ev_is_pci_root_bridge
303 *
Bob Mooreba494be2012-07-12 09:40:10 +0800304 * PARAMETERS: node - Device node being examined
Bob Mooreb7a69802007-02-02 19:48:21 +0300305 *
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 Moore8b1cafd2018-10-03 11:45:38 -0700313u8 acpi_ev_is_pci_root_bridge(struct acpi_namespace_node *node)
Bob Mooreb7a69802007-02-02 19:48:21 +0300314{
315 acpi_status status;
Lv Zheng78e25fe2012-10-31 02:25:24 +0000316 struct acpi_pnp_device_id *hid;
317 struct acpi_pnp_device_id_list *cid;
Bob Moore67a119f2008-06-10 13:42:13 +0800318 u32 i;
Bob Moore15b8dd52009-06-29 13:39:29 +0800319 u8 match;
Bob Mooreb7a69802007-02-02 19:48:21 +0300320
Bob Moore9f15fc62008-11-12 16:01:56 +0800321 /* Get the _HID and check for a PCI Root Bridge */
322
Bob Mooreb7a69802007-02-02 19:48:21 +0300323 status = acpi_ut_execute_HID(node, &hid);
324 if (ACPI_FAILURE(status)) {
325 return (FALSE);
326 }
327
Bob Moore15b8dd52009-06-29 13:39:29 +0800328 match = acpi_ut_is_pci_root_bridge(hid->string);
329 ACPI_FREE(hid);
330
331 if (match) {
Bob Mooreb7a69802007-02-02 19:48:21 +0300332 return (TRUE);
333 }
334
Bob Moore9f15fc62008-11-12 16:01:56 +0800335 /* The _HID did not match. Get the _CID and check for a PCI Root Bridge */
336
Bob Mooreb7a69802007-02-02 19:48:21 +0300337 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 Moore15b8dd52009-06-29 13:39:29 +0800345 if (acpi_ut_is_pci_root_bridge(cid->ids[i].string)) {
Bob Mooreb7a69802007-02-02 19:48:21 +0300346 ACPI_FREE(cid);
347 return (TRUE);
348 }
349 }
350
351 ACPI_FREE(cid);
352 return (FALSE);
353}
354
355/*******************************************************************************
356 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 * FUNCTION: acpi_ev_pci_bar_region_setup
358 *
Bob Mooreba494be2012-07-12 09:40:10 +0800359 * PARAMETERS: handle - Region we are interested in
360 * function - Start or stop
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 * handler_context - Address space handler context
362 * region_context - Region specific context
363 *
364 * RETURN: Status
365 *
Bob Mooreba494be2012-07-12 09:40:10 +0800366 * DESCRIPTION: Setup a pci_BAR operation region
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 *
368 * MUTEX: Assumes namespace is not locked
369 *
370 ******************************************************************************/
371
372acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400373acpi_ev_pci_bar_region_setup(acpi_handle handle,
374 u32 function,
375 void *handler_context, void **region_context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376{
Bob Mooreb229cf92006-04-21 17:15:00 -0400377 ACPI_FUNCTION_TRACE(ev_pci_bar_region_setup);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378
Len Brown4be44fc2005-08-05 00:44:28 -0400379 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380}
381
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382/*******************************************************************************
383 *
384 * FUNCTION: acpi_ev_cmos_region_setup
385 *
Bob Mooreba494be2012-07-12 09:40:10 +0800386 * PARAMETERS: handle - Region we are interested in
387 * function - Start or stop
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 * handler_context - Address space handler context
389 * region_context - Region specific context
390 *
391 * RETURN: Status
392 *
Robert Moore44f6c012005-04-18 22:49:35 -0400393 * DESCRIPTION: Setup a CMOS operation region
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 *
395 * MUTEX: Assumes namespace is not locked
396 *
397 ******************************************************************************/
398
399acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400400acpi_ev_cmos_region_setup(acpi_handle handle,
401 u32 function,
402 void *handler_context, void **region_context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403{
Bob Mooreb229cf92006-04-21 17:15:00 -0400404 ACPI_FUNCTION_TRACE(ev_cmos_region_setup);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405
Len Brown4be44fc2005-08-05 00:44:28 -0400406 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407}
408
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409/*******************************************************************************
410 *
411 * FUNCTION: acpi_ev_default_region_setup
412 *
Bob Mooreba494be2012-07-12 09:40:10 +0800413 * PARAMETERS: handle - Region we are interested in
414 * function - Start or stop
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 * handler_context - Address space handler context
416 * region_context - Region specific context
417 *
418 * RETURN: Status
419 *
Robert Moore44f6c012005-04-18 22:49:35 -0400420 * DESCRIPTION: Default region initialization
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 *
422 ******************************************************************************/
423
424acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400425acpi_ev_default_region_setup(acpi_handle handle,
426 u32 function,
427 void *handler_context, void **region_context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428{
Bob Mooreb229cf92006-04-21 17:15:00 -0400429 ACPI_FUNCTION_TRACE(ev_default_region_setup);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430
431 if (function == ACPI_REGION_DEACTIVATE) {
432 *region_context = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400433 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 *region_context = handler_context;
435 }
436
Len Brown4be44fc2005-08-05 00:44:28 -0400437 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438}
439
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440/*******************************************************************************
441 *
442 * FUNCTION: acpi_ev_initialize_region
443 *
444 * PARAMETERS: region_obj - Region we are initializing
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 *
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 Moore9f15fc62008-11-12 16:01:56 +0800454 * This also performs address space specific initialization. For
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 * example, PCI regions must have an _ADR object that contains
Bob Moore9f15fc62008-11-12 16:01:56 +0800456 * a PCI address in the scope of the definition. This address is
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 * required to perform an access to PCI config space.
458 *
Bob Moorec9e3ba22007-02-02 19:48:18 +0300459 * MUTEX: Interpreter should be unlocked, because we may run the _REG
460 * method for this region.
461 *
Lv Zheng760235c2016-11-30 15:21:12 +0800462 * 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 Torvalds1da177e2005-04-16 15:20:36 -0700474 ******************************************************************************/
475
Lv Zheng760235c2016-11-30 15:21:12 +0800476acpi_status acpi_ev_initialize_region(union acpi_operand_object *region_obj)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477{
Len Brown4be44fc2005-08-05 00:44:28 -0400478 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 Torvalds1da177e2005-04-16 15:20:36 -0700482
Lv Zheng760235c2016-11-30 15:21:12 +0800483 ACPI_FUNCTION_TRACE(ev_initialize_region);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484
485 if (!region_obj) {
Len Brown4be44fc2005-08-05 00:44:28 -0400486 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 }
488
489 if (region_obj->common.flags & AOPOBJ_OBJECT_INITIALIZED) {
Len Brown4be44fc2005-08-05 00:44:28 -0400490 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 }
492
Lv Zheng849c2572015-12-29 14:02:58 +0800493 region_obj->common.flags |= AOPOBJ_OBJECT_INITIALIZED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494
Alexey Starikovskiyc45b5c02010-05-26 11:53:07 +0800495 node = region_obj->region.node->parent;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 space_id = region_obj->region.space_id;
497
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 /*
499 * The following loop depends upon the root Node having no parent
Bob Moore7b738062015-12-29 14:01:53 +0800500 * ie: acpi_gbl_root_node->Parent being set to NULL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 */
502 while (node) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400503
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 /* Check to see if a handler exists */
505
506 handler_obj = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400507 obj_desc = acpi_ns_get_attached_object(node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 if (obj_desc) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400509
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 /* Can only be a handler if the object exists */
511
512 switch (node->type) {
513 case ACPI_TYPE_DEVICE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 case ACPI_TYPE_PROCESSOR:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 case ACPI_TYPE_THERMAL:
516
Lv Zhengaa6abd22015-12-29 14:02:08 +0800517 handler_obj = obj_desc->common_notify.handler;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 break;
519
520 default:
Chao Guan1d1ea1b72013-06-08 00:58:14 +0000521
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 /* Ignore other objects */
Chao Guan1d1ea1b72013-06-08 00:58:14 +0000523
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 break;
525 }
526
Lv Zhengf31a99ce2015-12-29 14:02:00 +0800527 handler_obj =
528 acpi_ev_find_region_handler(space_id, handler_obj);
529 if (handler_obj) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400530
Lv Zhengf31a99ce2015-12-29 14:02:00 +0800531 /* Found correct handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532
Lv Zhengf31a99ce2015-12-29 14:02:00 +0800533 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 Moore52fc0b02006-10-02 00:00:00 -0400537
Lv Zheng760235c2016-11-30 15:21:12 +0800538 (void)acpi_ev_attach_region(handler_obj,
539 region_obj, FALSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540
Lv Zhengf31a99ce2015-12-29 14:02:00 +0800541 /*
542 * Tell all users that this region is usable by
543 * running the _REG method
544 */
Lv Zheng8633db62016-10-26 15:42:01 +0800545 acpi_ex_exit_interpreter();
Lv Zheng760235c2016-11-30 15:21:12 +0800546 (void)acpi_ev_execute_reg_method(region_obj,
547 ACPI_REG_CONNECT);
Lv Zheng8633db62016-10-26 15:42:01 +0800548 acpi_ex_enter_interpreter();
Lv Zhengf31a99ce2015-12-29 14:02:00 +0800549 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 }
551 }
552
Bob Moore9f15fc62008-11-12 16:01:56 +0800553 /* This node does not have the handler we need; Pop up one level */
554
Alexey Starikovskiyc45b5c02010-05-26 11:53:07 +0800555 node = node->parent;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 }
557
Lv Zheng760235c2016-11-30 15:21:12 +0800558 /*
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 Brown4be44fc2005-08-05 00:44:28 -0400563 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
Bob Mooreb229cf92006-04-21 17:15:00 -0400564 "No handler for RegionType %s(%X) (RegionObj %p)\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400565 acpi_ut_get_region_name(space_id), space_id,
566 region_obj));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567
Lv Zheng760235c2016-11-30 15:21:12 +0800568 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569}