1
2
3
4
5
6
7
8
9
10#include <acpi/acpi.h>
11#include "accommon.h"
12#include "acparser.h"
13#include "amlcode.h"
14#include "acdispat.h"
15#include "acnamesp.h"
16#include "acinterp.h"
17
18#define _COMPONENT ACPI_DISPATCHER
19ACPI_MODULE_NAME("dsobject")
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35acpi_status
36acpi_ds_build_internal_object(struct acpi_walk_state *walk_state,
37 union acpi_parse_object *op,
38 union acpi_operand_object **obj_desc_ptr)
39{
40 union acpi_operand_object *obj_desc;
41 acpi_status status;
42
43 ACPI_FUNCTION_TRACE(ds_build_internal_object);
44
45 *obj_desc_ptr = NULL;
46 if (op->common.aml_opcode == AML_INT_NAMEPATH_OP) {
47
48
49
50
51
52 if (!op->common.node) {
53
54
55
56 if ((op->common.parent->common.aml_opcode ==
57 AML_PACKAGE_OP)
58 || (op->common.parent->common.aml_opcode ==
59 AML_VARIABLE_PACKAGE_OP)) {
60
61
62
63
64
65
66 goto create_new_object;
67 } else {
68 status = acpi_ns_lookup(walk_state->scope_info,
69 op->common.value.string,
70 ACPI_TYPE_ANY,
71 ACPI_IMODE_EXECUTE,
72 ACPI_NS_SEARCH_PARENT |
73 ACPI_NS_DONT_OPEN_SCOPE,
74 NULL,
75 ACPI_CAST_INDIRECT_PTR
76 (struct
77 acpi_namespace_node,
78 &(op->common.node)));
79 if (ACPI_FAILURE(status)) {
80 ACPI_ERROR_NAMESPACE(walk_state->
81 scope_info,
82 op->common.value.
83 string, status);
84 return_ACPI_STATUS(status);
85 }
86 }
87 }
88 }
89
90create_new_object:
91
92
93
94 obj_desc = acpi_ut_create_internal_object((acpi_ps_get_opcode_info
95 (op->common.aml_opcode))->
96 object_type);
97 if (!obj_desc) {
98 return_ACPI_STATUS(AE_NO_MEMORY);
99 }
100
101 status =
102 acpi_ds_init_object_from_op(walk_state, op, op->common.aml_opcode,
103 &obj_desc);
104 if (ACPI_FAILURE(status)) {
105 acpi_ut_remove_reference(obj_desc);
106 return_ACPI_STATUS(status);
107 }
108
109
110
111
112
113 if ((op->common.parent->common.aml_opcode == AML_PACKAGE_OP) ||
114 (op->common.parent->common.aml_opcode == AML_VARIABLE_PACKAGE_OP)) {
115 obj_desc->reference.resolved = TRUE;
116
117 if ((op->common.aml_opcode == AML_INT_NAMEPATH_OP) &&
118 !obj_desc->reference.node) {
119
120
121
122
123 obj_desc->reference.node =
124 walk_state->scope_info->scope.node;
125 obj_desc->reference.aml = op->common.aml;
126 obj_desc->reference.resolved = FALSE;
127 }
128 }
129
130 *obj_desc_ptr = obj_desc;
131 return_ACPI_STATUS(status);
132}
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150acpi_status
151acpi_ds_build_internal_buffer_obj(struct acpi_walk_state *walk_state,
152 union acpi_parse_object *op,
153 u32 buffer_length,
154 union acpi_operand_object **obj_desc_ptr)
155{
156 union acpi_parse_object *arg;
157 union acpi_operand_object *obj_desc;
158 union acpi_parse_object *byte_list;
159 u32 byte_list_length = 0;
160
161 ACPI_FUNCTION_TRACE(ds_build_internal_buffer_obj);
162
163
164
165
166
167
168 obj_desc = *obj_desc_ptr;
169 if (!obj_desc) {
170
171
172
173 obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_BUFFER);
174 *obj_desc_ptr = obj_desc;
175 if (!obj_desc) {
176 return_ACPI_STATUS(AE_NO_MEMORY);
177 }
178 }
179
180
181
182
183
184
185 arg = op->common.value.arg;
186
187 byte_list = arg->named.next;
188 if (byte_list) {
189 if (byte_list->common.aml_opcode != AML_INT_BYTELIST_OP) {
190 ACPI_ERROR((AE_INFO,
191 "Expecting bytelist, found AML opcode 0x%X in op %p",
192 byte_list->common.aml_opcode, byte_list));
193
194 acpi_ut_remove_reference(obj_desc);
195 return (AE_TYPE);
196 }
197
198 byte_list_length = (u32) byte_list->common.value.integer;
199 }
200
201
202
203
204
205
206 obj_desc->buffer.length = buffer_length;
207 if (byte_list_length > buffer_length) {
208 obj_desc->buffer.length = byte_list_length;
209 }
210
211
212
213 if (obj_desc->buffer.length == 0) {
214 obj_desc->buffer.pointer = NULL;
215 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
216 "Buffer defined with zero length in AML, creating\n"));
217 } else {
218 obj_desc->buffer.pointer =
219 ACPI_ALLOCATE_ZEROED(obj_desc->buffer.length);
220 if (!obj_desc->buffer.pointer) {
221 acpi_ut_delete_object_desc(obj_desc);
222 return_ACPI_STATUS(AE_NO_MEMORY);
223 }
224
225
226
227 if (byte_list) {
228 memcpy(obj_desc->buffer.pointer, byte_list->named.data,
229 byte_list_length);
230 }
231 }
232
233 obj_desc->buffer.flags |= AOPOBJ_DATA_VALID;
234 op->common.node = ACPI_CAST_PTR(struct acpi_namespace_node, obj_desc);
235 return_ACPI_STATUS(AE_OK);
236}
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252acpi_status
253acpi_ds_create_node(struct acpi_walk_state *walk_state,
254 struct acpi_namespace_node *node,
255 union acpi_parse_object *op)
256{
257 acpi_status status;
258 union acpi_operand_object *obj_desc;
259
260 ACPI_FUNCTION_TRACE_PTR(ds_create_node, op);
261
262
263
264
265
266
267 if (acpi_ns_get_attached_object(node)) {
268 return_ACPI_STATUS(AE_OK);
269 }
270
271 if (!op->common.value.arg) {
272
273
274
275 return_ACPI_STATUS(AE_OK);
276 }
277
278
279
280 status =
281 acpi_ds_build_internal_object(walk_state, op->common.value.arg,
282 &obj_desc);
283 if (ACPI_FAILURE(status)) {
284 return_ACPI_STATUS(status);
285 }
286
287
288
289 node->type = obj_desc->common.type;
290
291
292
293 status = acpi_ns_attach_object(node, obj_desc, node->type);
294
295
296
297 acpi_ut_remove_reference(obj_desc);
298 return_ACPI_STATUS(status);
299}
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318acpi_status
319acpi_ds_init_object_from_op(struct acpi_walk_state *walk_state,
320 union acpi_parse_object *op,
321 u16 opcode,
322 union acpi_operand_object **ret_obj_desc)
323{
324 const struct acpi_opcode_info *op_info;
325 union acpi_operand_object *obj_desc;
326 acpi_status status = AE_OK;
327
328 ACPI_FUNCTION_TRACE(ds_init_object_from_op);
329
330 obj_desc = *ret_obj_desc;
331 op_info = acpi_ps_get_opcode_info(opcode);
332 if (op_info->class == AML_CLASS_UNKNOWN) {
333
334
335
336 return_ACPI_STATUS(AE_TYPE);
337 }
338
339
340
341 switch (obj_desc->common.type) {
342 case ACPI_TYPE_BUFFER:
343
344
345
346 obj_desc->buffer.node =
347 ACPI_CAST_PTR(struct acpi_namespace_node,
348 walk_state->operands[0]);
349 obj_desc->buffer.aml_start = op->named.data;
350 obj_desc->buffer.aml_length = op->named.length;
351 break;
352
353 case ACPI_TYPE_PACKAGE:
354
355
356
357
358
359
360
361 obj_desc->package.node =
362 ACPI_CAST_PTR(struct acpi_namespace_node,
363 walk_state->operands[0]);
364
365 if (!op->named.data) {
366 return_ACPI_STATUS(AE_OK);
367 }
368
369 obj_desc->package.aml_start = op->named.data;
370 obj_desc->package.aml_length = op->named.length;
371 break;
372
373 case ACPI_TYPE_INTEGER:
374
375 switch (op_info->type) {
376 case AML_TYPE_CONSTANT:
377
378
379
380
381
382
383
384
385 obj_desc->common.flags = AOPOBJ_AML_CONSTANT;
386
387 switch (opcode) {
388 case AML_ZERO_OP:
389
390 obj_desc->integer.value = 0;
391 break;
392
393 case AML_ONE_OP:
394
395 obj_desc->integer.value = 1;
396 break;
397
398 case AML_ONES_OP:
399
400 obj_desc->integer.value = ACPI_UINT64_MAX;
401
402
403
404 (void)acpi_ex_truncate_for32bit_table(obj_desc);
405 break;
406
407 case AML_REVISION_OP:
408
409 obj_desc->integer.value = ACPI_CA_VERSION;
410 break;
411
412 default:
413
414 ACPI_ERROR((AE_INFO,
415 "Unknown constant opcode 0x%X",
416 opcode));
417 status = AE_AML_OPERAND_TYPE;
418 break;
419 }
420 break;
421
422 case AML_TYPE_LITERAL:
423
424 obj_desc->integer.value = op->common.value.integer;
425
426 if (acpi_ex_truncate_for32bit_table(obj_desc)) {
427
428
429
430 ACPI_WARNING((AE_INFO,
431 "Truncated 64-bit constant found in 32-bit table: %8.8X%8.8X => %8.8X",
432 ACPI_FORMAT_UINT64(op->common.
433 value.integer),
434 (u32)obj_desc->integer.value));
435 }
436 break;
437
438 default:
439
440 ACPI_ERROR((AE_INFO, "Unknown Integer type 0x%X",
441 op_info->type));
442 status = AE_AML_OPERAND_TYPE;
443 break;
444 }
445 break;
446
447 case ACPI_TYPE_STRING:
448
449 obj_desc->string.pointer = op->common.value.string;
450 obj_desc->string.length = (u32)strlen(op->common.value.string);
451
452
453
454
455
456 obj_desc->common.flags |= AOPOBJ_STATIC_POINTER;
457 break;
458
459 case ACPI_TYPE_METHOD:
460 break;
461
462 case ACPI_TYPE_LOCAL_REFERENCE:
463
464 switch (op_info->type) {
465 case AML_TYPE_LOCAL_VARIABLE:
466
467
468
469 obj_desc->reference.value =
470 ((u32)opcode) - AML_FIRST_LOCAL_OP;
471 obj_desc->reference.class = ACPI_REFCLASS_LOCAL;
472
473 status =
474 acpi_ds_method_data_get_node(ACPI_REFCLASS_LOCAL,
475 obj_desc->reference.
476 value, walk_state,
477 ACPI_CAST_INDIRECT_PTR
478 (struct
479 acpi_namespace_node,
480 &obj_desc->reference.
481 object));
482 break;
483
484 case AML_TYPE_METHOD_ARGUMENT:
485
486
487
488 obj_desc->reference.value =
489 ((u32)opcode) - AML_FIRST_ARG_OP;
490 obj_desc->reference.class = ACPI_REFCLASS_ARG;
491
492 status = acpi_ds_method_data_get_node(ACPI_REFCLASS_ARG,
493 obj_desc->
494 reference.value,
495 walk_state,
496 ACPI_CAST_INDIRECT_PTR
497 (struct
498 acpi_namespace_node,
499 &obj_desc->
500 reference.
501 object));
502 break;
503
504 default:
505
506 switch (op->common.aml_opcode) {
507 case AML_INT_NAMEPATH_OP:
508
509
510
511 obj_desc->reference.node = op->common.node;
512 obj_desc->reference.class = ACPI_REFCLASS_NAME;
513 if (op->common.node) {
514 obj_desc->reference.object =
515 op->common.node->object;
516 }
517 break;
518
519 case AML_DEBUG_OP:
520
521 obj_desc->reference.class = ACPI_REFCLASS_DEBUG;
522 break;
523
524 default:
525
526 ACPI_ERROR((AE_INFO,
527 "Unimplemented reference type for AML opcode: 0x%4.4X",
528 opcode));
529 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
530 }
531 break;
532 }
533 break;
534
535 default:
536
537 ACPI_ERROR((AE_INFO, "Unimplemented data type: 0x%X",
538 obj_desc->common.type));
539
540 status = AE_AML_OPERAND_TYPE;
541 break;
542 }
543
544 return_ACPI_STATUS(status);
545}
546