1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45#include <acpi/acpi.h>
46#include "accommon.h"
47#include "acnamesp.h"
48#include "acevents.h"
49
50#define _COMPONENT ACPI_EVENTS
51ACPI_MODULE_NAME("evxfregn")
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68acpi_status
69acpi_install_address_space_handler(acpi_handle device,
70 acpi_adr_space_type space_id,
71 acpi_adr_space_handler handler,
72 acpi_adr_space_setup setup, void *context)
73{
74 struct acpi_namespace_node *node;
75 acpi_status status;
76
77 ACPI_FUNCTION_TRACE(acpi_install_address_space_handler);
78
79
80
81 if (!device) {
82 return_ACPI_STATUS(AE_BAD_PARAMETER);
83 }
84
85 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
86 if (ACPI_FAILURE(status)) {
87 return_ACPI_STATUS(status);
88 }
89
90
91
92 node = acpi_ns_map_handle_to_node(device);
93 if (!node) {
94 status = AE_BAD_PARAMETER;
95 goto unlock_and_exit;
96 }
97
98
99
100 status =
101 acpi_ev_install_space_handler(node, space_id, handler, setup,
102 context);
103 if (ACPI_FAILURE(status)) {
104 goto unlock_and_exit;
105 }
106
107
108
109 status = acpi_ev_execute_reg_methods(node, space_id);
110
111 unlock_and_exit:
112 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
113 return_ACPI_STATUS(status);
114}
115
116ACPI_EXPORT_SYMBOL(acpi_install_address_space_handler)
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131acpi_status
132acpi_remove_address_space_handler(acpi_handle device,
133 acpi_adr_space_type space_id,
134 acpi_adr_space_handler handler)
135{
136 union acpi_operand_object *obj_desc;
137 union acpi_operand_object *handler_obj;
138 union acpi_operand_object *region_obj;
139 union acpi_operand_object **last_obj_ptr;
140 struct acpi_namespace_node *node;
141 acpi_status status;
142
143 ACPI_FUNCTION_TRACE(acpi_remove_address_space_handler);
144
145
146
147 if (!device) {
148 return_ACPI_STATUS(AE_BAD_PARAMETER);
149 }
150
151 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
152 if (ACPI_FAILURE(status)) {
153 return_ACPI_STATUS(status);
154 }
155
156
157
158 node = acpi_ns_map_handle_to_node(device);
159 if (!node ||
160 ((node->type != ACPI_TYPE_DEVICE) &&
161 (node->type != ACPI_TYPE_PROCESSOR) &&
162 (node->type != ACPI_TYPE_THERMAL) &&
163 (node != acpi_gbl_root_node))) {
164 status = AE_BAD_PARAMETER;
165 goto unlock_and_exit;
166 }
167
168
169
170 obj_desc = acpi_ns_get_attached_object(node);
171 if (!obj_desc) {
172 status = AE_NOT_EXIST;
173 goto unlock_and_exit;
174 }
175
176
177
178 handler_obj = obj_desc->device.handler;
179 last_obj_ptr = &obj_desc->device.handler;
180 while (handler_obj) {
181
182
183
184 if (handler_obj->address_space.space_id == space_id) {
185
186
187
188 if (handler_obj->address_space.handler != handler) {
189 status = AE_BAD_PARAMETER;
190 goto unlock_and_exit;
191 }
192
193
194
195 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
196 "Removing address handler %p(%p) for region %s "
197 "on Device %p(%p)\n",
198 handler_obj, handler,
199 acpi_ut_get_region_name(space_id),
200 node, obj_desc));
201
202 region_obj = handler_obj->address_space.region_list;
203
204
205
206 while (region_obj) {
207
208
209
210
211
212
213
214 acpi_ev_detach_region(region_obj, TRUE);
215
216
217
218
219
220 region_obj =
221 handler_obj->address_space.region_list;
222
223 }
224
225
226
227 *last_obj_ptr = handler_obj->address_space.next;
228
229
230
231 acpi_ut_remove_reference(handler_obj);
232 goto unlock_and_exit;
233 }
234
235
236
237 last_obj_ptr = &handler_obj->address_space.next;
238 handler_obj = handler_obj->address_space.next;
239 }
240
241
242
243 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
244 "Unable to remove address handler %p for %s(%X), DevNode %p, obj %p\n",
245 handler, acpi_ut_get_region_name(space_id), space_id,
246 node, obj_desc));
247
248 status = AE_NOT_EXIST;
249
250 unlock_and_exit:
251 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
252 return_ACPI_STATUS(status);
253}
254
255ACPI_EXPORT_SYMBOL(acpi_remove_address_space_handler)
256