blob: 091415b14fbf1109e14e292c233f53f04dadf1e9 [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: evxfregn - External Interfaces, ACPI Operation Regions and
5 * Address Spaces.
6 *
Bob Mooreda6f8322018-01-04 10:06:38 -08007 * Copyright (C) 2000 - 2018, Intel Corp.
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 *
Erik Schmauss95857632018-03-14 16:13:07 -07009 *****************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -070010
Lv Zheng839e9282013-10-29 09:29:51 +080011#define EXPORT_ACPI_INTERFACES
12
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <acpi/acpi.h>
Len Browne2f7a772009-01-09 00:30:03 -050014#include "accommon.h"
15#include "acnamesp.h"
16#include "acevents.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
18#define _COMPONENT ACPI_EVENTS
Len Brown4be44fc2005-08-05 00:44:28 -040019ACPI_MODULE_NAME("evxfregn")
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
21/*******************************************************************************
22 *
23 * FUNCTION: acpi_install_address_space_handler
24 *
Bob Mooreba494be2012-07-12 09:40:10 +080025 * PARAMETERS: device - Handle for the device
Linus Torvalds1da177e2005-04-16 15:20:36 -070026 * space_id - The address space ID
Bob Mooreba494be2012-07-12 09:40:10 +080027 * handler - Address of the handler
28 * setup - Address of the setup function
29 * context - Value passed to the handler on each access
Linus Torvalds1da177e2005-04-16 15:20:36 -070030 *
31 * RETURN: Status
32 *
33 * DESCRIPTION: Install a handler for all op_regions of a given space_id.
34 *
Bob Moore39891702010-10-18 08:43:13 +080035 * NOTE: This function should only be called after acpi_enable_subsystem has
36 * been called. This is because any _REG methods associated with the Space ID
37 * are executed here, and these methods can only be safely executed after
38 * the default handlers have been installed and the hardware has been
39 * initialized (via acpi_enable_subsystem.)
40 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -070042acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040043acpi_install_address_space_handler(acpi_handle device,
44 acpi_adr_space_type space_id,
45 acpi_adr_space_handler handler,
46 acpi_adr_space_setup setup, void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -070047{
Len Brown4be44fc2005-08-05 00:44:28 -040048 struct acpi_namespace_node *node;
49 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
Bob Mooreb229cf92006-04-21 17:15:00 -040051 ACPI_FUNCTION_TRACE(acpi_install_address_space_handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
53 /* Parameter validation */
54
55 if (!device) {
Len Brown4be44fc2005-08-05 00:44:28 -040056 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 }
58
Len Brown4be44fc2005-08-05 00:44:28 -040059 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
60 if (ACPI_FAILURE(status)) {
61 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 }
63
64 /* Convert and validate the device handle */
65
Bob Mooref24b6642009-12-11 14:57:00 +080066 node = acpi_ns_validate_handle(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 if (!node) {
68 status = AE_BAD_PARAMETER;
69 goto unlock_and_exit;
70 }
71
72 /* Install the handler for all Regions for this Space ID */
73
Len Brown4be44fc2005-08-05 00:44:28 -040074 status =
75 acpi_ev_install_space_handler(node, space_id, handler, setup,
76 context);
77 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 goto unlock_and_exit;
79 }
80
Bob Mooree2066ca2011-04-13 13:22:04 +080081 /* Run all _REG methods for this address space */
82
Lv Zhengd8153462015-12-29 14:03:43 +080083 acpi_ev_execute_reg_methods(node, space_id, ACPI_REG_CONNECT);
Bob Mooree2066ca2011-04-13 13:22:04 +080084
Lv Zheng10622bf2013-10-29 09:30:02 +080085unlock_and_exit:
Len Brown4be44fc2005-08-05 00:44:28 -040086 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
87 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -070088}
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
Bob Moore83135242006-10-03 00:00:00 -040090ACPI_EXPORT_SYMBOL(acpi_install_address_space_handler)
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
92/*******************************************************************************
93 *
94 * FUNCTION: acpi_remove_address_space_handler
95 *
Bob Mooreba494be2012-07-12 09:40:10 +080096 * PARAMETERS: device - Handle for the device
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 * space_id - The address space ID
Bob Mooreba494be2012-07-12 09:40:10 +080098 * handler - Address of the handler
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 *
100 * RETURN: Status
101 *
102 * DESCRIPTION: Remove a previously installed handler.
103 *
104 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400106acpi_remove_address_space_handler(acpi_handle device,
107 acpi_adr_space_type space_id,
108 acpi_adr_space_handler handler)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109{
Len Brown4be44fc2005-08-05 00:44:28 -0400110 union acpi_operand_object *obj_desc;
111 union acpi_operand_object *handler_obj;
112 union acpi_operand_object *region_obj;
113 union acpi_operand_object **last_obj_ptr;
114 struct acpi_namespace_node *node;
115 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116
Bob Mooreb229cf92006-04-21 17:15:00 -0400117 ACPI_FUNCTION_TRACE(acpi_remove_address_space_handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118
119 /* Parameter validation */
120
121 if (!device) {
Len Brown4be44fc2005-08-05 00:44:28 -0400122 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 }
124
Len Brown4be44fc2005-08-05 00:44:28 -0400125 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
126 if (ACPI_FAILURE(status)) {
127 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 }
129
130 /* Convert and validate the device handle */
131
Bob Mooref24b6642009-12-11 14:57:00 +0800132 node = acpi_ns_validate_handle(device);
Bob Mooref6dd9222006-07-07 20:44:38 -0400133 if (!node ||
134 ((node->type != ACPI_TYPE_DEVICE) &&
135 (node->type != ACPI_TYPE_PROCESSOR) &&
136 (node->type != ACPI_TYPE_THERMAL) &&
137 (node != acpi_gbl_root_node))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 status = AE_BAD_PARAMETER;
139 goto unlock_and_exit;
140 }
141
142 /* Make sure the internal object exists */
143
Len Brown4be44fc2005-08-05 00:44:28 -0400144 obj_desc = acpi_ns_get_attached_object(node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 if (!obj_desc) {
146 status = AE_NOT_EXIST;
147 goto unlock_and_exit;
148 }
149
150 /* Find the address handler the user requested */
151
Lv Zhengaa6abd22015-12-29 14:02:08 +0800152 handler_obj = obj_desc->common_notify.handler;
153 last_obj_ptr = &obj_desc->common_notify.handler;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 while (handler_obj) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400155
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 /* We have a handler, see if user requested this one */
157
158 if (handler_obj->address_space.space_id == space_id) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400159
Bob Mooref6dd9222006-07-07 20:44:38 -0400160 /* Handler must be the same as the installed handler */
161
162 if (handler_obj->address_space.handler != handler) {
163 status = AE_BAD_PARAMETER;
164 goto unlock_and_exit;
165 }
166
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 /* Matched space_id, first dereference this in the Regions */
168
Len Brown4be44fc2005-08-05 00:44:28 -0400169 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
Bob Moored4913dc2009-03-06 10:05:18 +0800170 "Removing address handler %p(%p) for region %s "
171 "on Device %p(%p)\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400172 handler_obj, handler,
173 acpi_ut_get_region_name(space_id),
174 node, obj_desc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175
176 region_obj = handler_obj->address_space.region_list;
177
178 /* Walk the handler's region list */
179
180 while (region_obj) {
181 /*
182 * First disassociate the handler from the region.
183 *
184 * NOTE: this doesn't mean that the region goes away
185 * The region is just inaccessible as indicated to
186 * the _REG method
187 */
Len Brown4be44fc2005-08-05 00:44:28 -0400188 acpi_ev_detach_region(region_obj, TRUE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189
190 /*
191 * Walk the list: Just grab the head because the
192 * detach_region removed the previous head.
193 */
Len Brown4be44fc2005-08-05 00:44:28 -0400194 region_obj =
195 handler_obj->address_space.region_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196
197 }
198
199 /* Remove this Handler object from the list */
200
201 *last_obj_ptr = handler_obj->address_space.next;
202
203 /* Now we can delete the handler object */
204
Len Brown4be44fc2005-08-05 00:44:28 -0400205 acpi_ut_remove_reference(handler_obj);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 goto unlock_and_exit;
207 }
208
209 /* Walk the linked list of handlers */
210
211 last_obj_ptr = &handler_obj->address_space.next;
212 handler_obj = handler_obj->address_space.next;
213 }
214
215 /* The handler does not exist */
216
Len Brown4be44fc2005-08-05 00:44:28 -0400217 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
Bob Mooreb229cf92006-04-21 17:15:00 -0400218 "Unable to remove address handler %p for %s(%X), DevNode %p, obj %p\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400219 handler, acpi_ut_get_region_name(space_id), space_id,
220 node, obj_desc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221
222 status = AE_NOT_EXIST;
223
Lv Zheng10622bf2013-10-29 09:30:02 +0800224unlock_and_exit:
Len Brown4be44fc2005-08-05 00:44:28 -0400225 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
226 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228
Bob Moore83135242006-10-03 00:00:00 -0400229ACPI_EXPORT_SYMBOL(acpi_remove_address_space_handler)