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
14ACPI_MODULE_NAME("nsobject")
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36acpi_status
37acpi_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
168void 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
190
191 node->object = NULL;
192 if (ACPI_GET_DESCRIPTOR_TYPE(obj_desc) == ACPI_DESC_TYPE_OPERAND) {
193
194
195
196 node->object = obj_desc->common.next_object;
197
198
199
200 if (node->object &&
201 (node->object->common.type != ACPI_TYPE_LOCAL_DATA)) {
202 node->object = node->object->common.next_object;
203 }
204
205
206
207
208
209 if (obj_desc->common.next_object &&
210 ((obj_desc->common.next_object)->common.type ==
211 ACPI_TYPE_LOCAL_DATA)) {
212 obj_desc->common.next_object = NULL;
213 }
214 }
215
216
217
218 node->type = ACPI_TYPE_ANY;
219
220 ACPI_DEBUG_PRINT((ACPI_DB_NAMES, "Node %p [%4.4s] Object %p\n",
221 node, acpi_ut_get_node_name(node), obj_desc));
222
223
224
225 acpi_ut_remove_reference(obj_desc);
226 return_VOID;
227}
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242union acpi_operand_object *acpi_ns_get_attached_object(struct
243 acpi_namespace_node
244 *node)
245{
246 ACPI_FUNCTION_TRACE_PTR(ns_get_attached_object, node);
247
248 if (!node) {
249 ACPI_WARNING((AE_INFO, "Null Node ptr"));
250 return_PTR(NULL);
251 }
252
253 if (!node->object ||
254 ((ACPI_GET_DESCRIPTOR_TYPE(node->object) != ACPI_DESC_TYPE_OPERAND)
255 && (ACPI_GET_DESCRIPTOR_TYPE(node->object) !=
256 ACPI_DESC_TYPE_NAMED))
257 || ((node->object)->common.type == ACPI_TYPE_LOCAL_DATA)) {
258 return_PTR(NULL);
259 }
260
261 return_PTR(node->object);
262}
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277union acpi_operand_object *acpi_ns_get_secondary_object(union
278 acpi_operand_object
279 *obj_desc)
280{
281 ACPI_FUNCTION_TRACE_PTR(ns_get_secondary_object, obj_desc);
282
283 if ((!obj_desc) ||
284 (obj_desc->common.type == ACPI_TYPE_LOCAL_DATA) ||
285 (!obj_desc->common.next_object) ||
286 ((obj_desc->common.next_object)->common.type ==
287 ACPI_TYPE_LOCAL_DATA)) {
288 return_PTR(NULL);
289 }
290
291 return_PTR(obj_desc->common.next_object);
292}
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308acpi_status
309acpi_ns_attach_data(struct acpi_namespace_node *node,
310 acpi_object_handler handler, void *data)
311{
312 union acpi_operand_object *prev_obj_desc;
313 union acpi_operand_object *obj_desc;
314 union acpi_operand_object *data_desc;
315
316
317
318 prev_obj_desc = NULL;
319 obj_desc = node->object;
320 while (obj_desc) {
321 if ((obj_desc->common.type == ACPI_TYPE_LOCAL_DATA) &&
322 (obj_desc->data.handler == handler)) {
323 return (AE_ALREADY_EXISTS);
324 }
325
326 prev_obj_desc = obj_desc;
327 obj_desc = obj_desc->common.next_object;
328 }
329
330
331
332 data_desc = acpi_ut_create_internal_object(ACPI_TYPE_LOCAL_DATA);
333 if (!data_desc) {
334 return (AE_NO_MEMORY);
335 }
336
337 data_desc->data.handler = handler;
338 data_desc->data.pointer = data;
339
340
341
342 if (prev_obj_desc) {
343 prev_obj_desc->common.next_object = data_desc;
344 } else {
345 node->object = data_desc;
346 }
347
348 return (AE_OK);
349}
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365acpi_status
366acpi_ns_detach_data(struct acpi_namespace_node *node,
367 acpi_object_handler handler)
368{
369 union acpi_operand_object *obj_desc;
370 union acpi_operand_object *prev_obj_desc;
371
372 prev_obj_desc = NULL;
373 obj_desc = node->object;
374 while (obj_desc) {
375 if ((obj_desc->common.type == ACPI_TYPE_LOCAL_DATA) &&
376 (obj_desc->data.handler == handler)) {
377 if (prev_obj_desc) {
378 prev_obj_desc->common.next_object =
379 obj_desc->common.next_object;
380 } else {
381 node->object = obj_desc->common.next_object;
382 }
383
384 acpi_ut_remove_reference(obj_desc);
385 return (AE_OK);
386 }
387
388 prev_obj_desc = obj_desc;
389 obj_desc = obj_desc->common.next_object;
390 }
391
392 return (AE_NOT_FOUND);
393}
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410acpi_status
411acpi_ns_get_attached_data(struct acpi_namespace_node *node,
412 acpi_object_handler handler, void **data)
413{
414 union acpi_operand_object *obj_desc;
415
416 obj_desc = node->object;
417 while (obj_desc) {
418 if ((obj_desc->common.type == ACPI_TYPE_LOCAL_DATA) &&
419 (obj_desc->data.handler == handler)) {
420 *data = obj_desc->data.pointer;
421 return (AE_OK);
422 }
423
424 obj_desc = obj_desc->common.next_object;
425 }
426
427 return (AE_NOT_FOUND);
428}
429