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: evxfregn - External Interfaces, ACPI Operation Regions and |
| 5 | * Address Spaces. |
| 6 | * |
Bob Moore | da6f832 | 2018-01-04 10:06:38 -0800 | [diff] [blame] | 7 | * Copyright (C) 2000 - 2018, Intel Corp. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | * |
Erik Schmauss | 9585763 | 2018-03-14 16:13:07 -0700 | [diff] [blame] | 9 | *****************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | |
Lv Zheng | 839e928 | 2013-10-29 09:29:51 +0800 | [diff] [blame] | 11 | #define EXPORT_ACPI_INTERFACES |
| 12 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <acpi/acpi.h> |
Len Brown | e2f7a77 | 2009-01-09 00:30:03 -0500 | [diff] [blame] | 14 | #include "accommon.h" |
| 15 | #include "acnamesp.h" |
| 16 | #include "acevents.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | |
| 18 | #define _COMPONENT ACPI_EVENTS |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 19 | ACPI_MODULE_NAME("evxfregn") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | |
| 21 | /******************************************************************************* |
| 22 | * |
| 23 | * FUNCTION: acpi_install_address_space_handler |
| 24 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 25 | * PARAMETERS: device - Handle for the device |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | * space_id - The address space ID |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 27 | * handler - Address of the handler |
| 28 | * setup - Address of the setup function |
| 29 | * context - Value passed to the handler on each access |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | * |
| 31 | * RETURN: Status |
| 32 | * |
| 33 | * DESCRIPTION: Install a handler for all op_regions of a given space_id. |
| 34 | * |
Bob Moore | 3989170 | 2010-10-18 08:43:13 +0800 | [diff] [blame] | 35 | * 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | ******************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 43 | acpi_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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 48 | struct acpi_namespace_node *node; |
| 49 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 51 | ACPI_FUNCTION_TRACE(acpi_install_address_space_handler); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | |
| 53 | /* Parameter validation */ |
| 54 | |
| 55 | if (!device) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 56 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | } |
| 58 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 59 | status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); |
| 60 | if (ACPI_FAILURE(status)) { |
| 61 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | /* Convert and validate the device handle */ |
| 65 | |
Bob Moore | f24b664 | 2009-12-11 14:57:00 +0800 | [diff] [blame] | 66 | node = acpi_ns_validate_handle(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | 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 Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 74 | status = |
| 75 | acpi_ev_install_space_handler(node, space_id, handler, setup, |
| 76 | context); |
| 77 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | goto unlock_and_exit; |
| 79 | } |
| 80 | |
Bob Moore | e2066ca | 2011-04-13 13:22:04 +0800 | [diff] [blame] | 81 | /* Run all _REG methods for this address space */ |
| 82 | |
Lv Zheng | d815346 | 2015-12-29 14:03:43 +0800 | [diff] [blame] | 83 | acpi_ev_execute_reg_methods(node, space_id, ACPI_REG_CONNECT); |
Bob Moore | e2066ca | 2011-04-13 13:22:04 +0800 | [diff] [blame] | 84 | |
Lv Zheng | 10622bf | 2013-10-29 09:30:02 +0800 | [diff] [blame] | 85 | unlock_and_exit: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 86 | (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); |
| 87 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 90 | ACPI_EXPORT_SYMBOL(acpi_install_address_space_handler) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | |
| 92 | /******************************************************************************* |
| 93 | * |
| 94 | * FUNCTION: acpi_remove_address_space_handler |
| 95 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 96 | * PARAMETERS: device - Handle for the device |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | * space_id - The address space ID |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 98 | * handler - Address of the handler |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | * |
| 100 | * RETURN: Status |
| 101 | * |
| 102 | * DESCRIPTION: Remove a previously installed handler. |
| 103 | * |
| 104 | ******************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 106 | acpi_remove_address_space_handler(acpi_handle device, |
| 107 | acpi_adr_space_type space_id, |
| 108 | acpi_adr_space_handler handler) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 110 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 117 | ACPI_FUNCTION_TRACE(acpi_remove_address_space_handler); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | |
| 119 | /* Parameter validation */ |
| 120 | |
| 121 | if (!device) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 122 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | } |
| 124 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 125 | status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); |
| 126 | if (ACPI_FAILURE(status)) { |
| 127 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | /* Convert and validate the device handle */ |
| 131 | |
Bob Moore | f24b664 | 2009-12-11 14:57:00 +0800 | [diff] [blame] | 132 | node = acpi_ns_validate_handle(device); |
Bob Moore | f6dd922 | 2006-07-07 20:44:38 -0400 | [diff] [blame] | 133 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | status = AE_BAD_PARAMETER; |
| 139 | goto unlock_and_exit; |
| 140 | } |
| 141 | |
| 142 | /* Make sure the internal object exists */ |
| 143 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 144 | obj_desc = acpi_ns_get_attached_object(node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | 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 Zheng | aa6abd2 | 2015-12-29 14:02:08 +0800 | [diff] [blame] | 152 | handler_obj = obj_desc->common_notify.handler; |
| 153 | last_obj_ptr = &obj_desc->common_notify.handler; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | while (handler_obj) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 155 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | /* We have a handler, see if user requested this one */ |
| 157 | |
| 158 | if (handler_obj->address_space.space_id == space_id) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 159 | |
Bob Moore | f6dd922 | 2006-07-07 20:44:38 -0400 | [diff] [blame] | 160 | /* 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | /* Matched space_id, first dereference this in the Regions */ |
| 168 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 169 | ACPI_DEBUG_PRINT((ACPI_DB_OPREGION, |
Bob Moore | d4913dc | 2009-03-06 10:05:18 +0800 | [diff] [blame] | 170 | "Removing address handler %p(%p) for region %s " |
| 171 | "on Device %p(%p)\n", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 172 | handler_obj, handler, |
| 173 | acpi_ut_get_region_name(space_id), |
| 174 | node, obj_desc)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | |
| 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 Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 188 | acpi_ev_detach_region(region_obj, TRUE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | |
| 190 | /* |
| 191 | * Walk the list: Just grab the head because the |
| 192 | * detach_region removed the previous head. |
| 193 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 194 | region_obj = |
| 195 | handler_obj->address_space.region_list; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | |
| 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 Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 205 | acpi_ut_remove_reference(handler_obj); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | 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 Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 217 | ACPI_DEBUG_PRINT((ACPI_DB_OPREGION, |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 218 | "Unable to remove address handler %p for %s(%X), DevNode %p, obj %p\n", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 219 | handler, acpi_ut_get_region_name(space_id), space_id, |
| 220 | node, obj_desc)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | |
| 222 | status = AE_NOT_EXIST; |
| 223 | |
Lv Zheng | 10622bf | 2013-10-29 09:30:02 +0800 | [diff] [blame] | 224 | unlock_and_exit: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 225 | (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); |
| 226 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 229 | ACPI_EXPORT_SYMBOL(acpi_remove_address_space_handler) |