This source file includes following definitions.
- ACPI_MODULE_NAME
- acpi_ns_detach_object
- acpi_ns_get_attached_object
- acpi_ns_get_secondary_object
- acpi_ns_attach_data
- acpi_ns_detach_data
- acpi_ns_get_attached_data
1
2
3
4
5
6
7
8
9 #include <acpi/acpi.h>
10 #include "accommon.h"
11 #include "acnamesp.h"
12
13 #define _COMPONENT ACPI_NAMESPACE
14 ACPI_MODULE_NAME("nsobject")
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36 acpi_status
37 acpi_ns_attach_object(struct acpi_namespace_node *node,
38 union acpi_operand_object *object, acpi_object_type type)
39 {
40 union acpi_operand_object *obj_desc;
41 union acpi_operand_object *last_obj_desc;
42 acpi_object_type object_type = ACPI_TYPE_ANY;
43
44 ACPI_FUNCTION_TRACE(ns_attach_object);
45
46
47
48
49 if (!node) {
50
51
52
53 ACPI_ERROR((AE_INFO, "Null NamedObj handle"));
54 return_ACPI_STATUS(AE_BAD_PARAMETER);
55 }
56
57 if (!object && (ACPI_TYPE_ANY != type)) {
58
59
60
61 ACPI_ERROR((AE_INFO,
62 "Null object, but type not ACPI_TYPE_ANY"));
63 return_ACPI_STATUS(AE_BAD_PARAMETER);
64 }
65
66 if (ACPI_GET_DESCRIPTOR_TYPE(node) != ACPI_DESC_TYPE_NAMED) {
67
68
69
70 ACPI_ERROR((AE_INFO, "Invalid handle %p [%s]",
71 node, acpi_ut_get_descriptor_name(node)));
72 return_ACPI_STATUS(AE_BAD_PARAMETER);
73 }
74
75
76
77 if (node->object == object) {
78 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
79 "Obj %p already installed in NameObj %p\n",
80 object, node));
81
82 return_ACPI_STATUS(AE_OK);
83 }
84
85
86
87 if (!object) {
88 obj_desc = NULL;
89 object_type = ACPI_TYPE_ANY;
90 }
91
92
93
94
95
96 else if ((ACPI_GET_DESCRIPTOR_TYPE(object) == ACPI_DESC_TYPE_NAMED) &&
97 ((struct acpi_namespace_node *)object)->object) {
98
99
100
101
102 obj_desc = ((struct acpi_namespace_node *)object)->object;
103 object_type = ((struct acpi_namespace_node *)object)->type;
104 }
105
106
107
108
109
110 else {
111 obj_desc = (union acpi_operand_object *)object;
112
113
114
115 object_type = type;
116 }
117
118 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Installing %p into Node %p [%4.4s]\n",
119 obj_desc, node, acpi_ut_get_node_name(node)));
120
121
122
123 if (node->object) {
124 acpi_ns_detach_object(node);
125 }
126
127 if (obj_desc) {
128
129
130
131
132 acpi_ut_add_reference(obj_desc);
133
134
135
136
137
138 last_obj_desc = obj_desc;
139 while (last_obj_desc->common.next_object) {
140 last_obj_desc = last_obj_desc->common.next_object;
141 }
142
143
144
145 last_obj_desc->common.next_object = node->object;
146 }
147
148 node->type = (u8) object_type;
149 node->object = obj_desc;
150
151 return_ACPI_STATUS(AE_OK);
152 }
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168 void acpi_ns_detach_object(struct acpi_namespace_node *node)
169 {
170 union acpi_operand_object *obj_desc;
171
172 ACPI_FUNCTION_TRACE(ns_detach_object);
173
174 obj_desc = node->object;
175
176 if (!obj_desc || (obj_desc->common.type == ACPI_TYPE_LOCAL_DATA)) {
177 return_VOID;
178 }
179
180 if (node->flags & ANOBJ_ALLOCATED_BUFFER) {
181
182
183
184 if (obj_desc->common.type == ACPI_TYPE_METHOD) {
185 ACPI_FREE(obj_desc->method.aml_start);
186 }
187 }
188
189 if (obj_desc->common.type == ACPI_TYPE_REGION) {
190 acpi_ut_remove_address_range(obj_desc->region.space_id, node);
191 }
192
193
194
195 node->object = NULL;
196 if (ACPI_GET_DESCRIPTOR_TYPE(obj_desc) == ACPI_DESC_TYPE_OPERAND) {
197
198
199
200 node->object = obj_desc->common.next_object;
201
202
203
204 if (node->object &&
205 (node->object->common.type != ACPI_TYPE_LOCAL_DATA)) {
206 node->object = node->object->common.next_object;
207 }
208
209
210
211
212
213 if (obj_desc->common.next_object &&
214 ((obj_desc->common.next_object)->common.type ==
215 ACPI_TYPE_LOCAL_DATA)) {
216 obj_desc->common.next_object = NULL;
217 }
218 }
219
220
221
222 node->type = ACPI_TYPE_ANY;
223
224 ACPI_DEBUG_PRINT((ACPI_DB_NAMES, "Node %p [%4.4s] Object %p\n",
225 node, acpi_ut_get_node_name(node), obj_desc));
226
227
228
229 acpi_ut_remove_reference(obj_desc);
230 return_VOID;
231 }
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246 union acpi_operand_object *acpi_ns_get_attached_object(struct
247 acpi_namespace_node
248 *node)
249 {
250 ACPI_FUNCTION_TRACE_PTR(ns_get_attached_object, node);
251
252 if (!node) {
253 ACPI_WARNING((AE_INFO, "Null Node ptr"));
254 return_PTR(NULL);
255 }
256
257 if (!node->object ||
258 ((ACPI_GET_DESCRIPTOR_TYPE(node->object) != ACPI_DESC_TYPE_OPERAND)
259 && (ACPI_GET_DESCRIPTOR_TYPE(node->object) !=
260 ACPI_DESC_TYPE_NAMED))
261 || ((node->object)->common.type == ACPI_TYPE_LOCAL_DATA)) {
262 return_PTR(NULL);
263 }
264
265 return_PTR(node->object);
266 }
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281 union acpi_operand_object *acpi_ns_get_secondary_object(union
282 acpi_operand_object
283 *obj_desc)
284 {
285 ACPI_FUNCTION_TRACE_PTR(ns_get_secondary_object, obj_desc);
286
287 if ((!obj_desc) ||
288 (obj_desc->common.type == ACPI_TYPE_LOCAL_DATA) ||
289 (!obj_desc->common.next_object) ||
290 ((obj_desc->common.next_object)->common.type ==
291 ACPI_TYPE_LOCAL_DATA)) {
292 return_PTR(NULL);
293 }
294
295 return_PTR(obj_desc->common.next_object);
296 }
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312 acpi_status
313 acpi_ns_attach_data(struct acpi_namespace_node *node,
314 acpi_object_handler handler, void *data)
315 {
316 union acpi_operand_object *prev_obj_desc;
317 union acpi_operand_object *obj_desc;
318 union acpi_operand_object *data_desc;
319
320
321
322 prev_obj_desc = NULL;
323 obj_desc = node->object;
324 while (obj_desc) {
325 if ((obj_desc->common.type == ACPI_TYPE_LOCAL_DATA) &&
326 (obj_desc->data.handler == handler)) {
327 return (AE_ALREADY_EXISTS);
328 }
329
330 prev_obj_desc = obj_desc;
331 obj_desc = obj_desc->common.next_object;
332 }
333
334
335
336 data_desc = acpi_ut_create_internal_object(ACPI_TYPE_LOCAL_DATA);
337 if (!data_desc) {
338 return (AE_NO_MEMORY);
339 }
340
341 data_desc->data.handler = handler;
342 data_desc->data.pointer = data;
343
344
345
346 if (prev_obj_desc) {
347 prev_obj_desc->common.next_object = data_desc;
348 } else {
349 node->object = data_desc;
350 }
351
352 return (AE_OK);
353 }
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369 acpi_status
370 acpi_ns_detach_data(struct acpi_namespace_node *node,
371 acpi_object_handler handler)
372 {
373 union acpi_operand_object *obj_desc;
374 union acpi_operand_object *prev_obj_desc;
375
376 prev_obj_desc = NULL;
377 obj_desc = node->object;
378 while (obj_desc) {
379 if ((obj_desc->common.type == ACPI_TYPE_LOCAL_DATA) &&
380 (obj_desc->data.handler == handler)) {
381 if (prev_obj_desc) {
382 prev_obj_desc->common.next_object =
383 obj_desc->common.next_object;
384 } else {
385 node->object = obj_desc->common.next_object;
386 }
387
388 acpi_ut_remove_reference(obj_desc);
389 return (AE_OK);
390 }
391
392 prev_obj_desc = obj_desc;
393 obj_desc = obj_desc->common.next_object;
394 }
395
396 return (AE_NOT_FOUND);
397 }
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414 acpi_status
415 acpi_ns_get_attached_data(struct acpi_namespace_node *node,
416 acpi_object_handler handler, void **data)
417 {
418 union acpi_operand_object *obj_desc;
419
420 obj_desc = node->object;
421 while (obj_desc) {
422 if ((obj_desc->common.type == ACPI_TYPE_LOCAL_DATA) &&
423 (obj_desc->data.handler == handler)) {
424 *data = obj_desc->data.pointer;
425 return (AE_OK);
426 }
427
428 obj_desc = obj_desc->common.next_object;
429 }
430
431 return (AE_NOT_FOUND);
432 }