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