1
2
3
4
5
6
7
8
9
10
11#include <acpi/acpi.h>
12#include "accommon.h"
13#include "acnamesp.h"
14#include "acinterp.h"
15#include "acpredef.h"
16#include "amlresrc.h"
17
18#define _COMPONENT ACPI_NAMESPACE
19ACPI_MODULE_NAME("nsconvert")
20
21
22
23
24
25
26
27
28
29
30
31
32
33acpi_status
34acpi_ns_convert_to_integer(union acpi_operand_object *original_object,
35 union acpi_operand_object **return_object)
36{
37 union acpi_operand_object *new_object;
38 acpi_status status;
39 u64 value = 0;
40 u32 i;
41
42 switch (original_object->common.type) {
43 case ACPI_TYPE_STRING:
44
45
46
47 status =
48 acpi_ut_strtoul64(original_object->string.pointer, &value);
49 if (ACPI_FAILURE(status)) {
50 return (status);
51 }
52 break;
53
54 case ACPI_TYPE_BUFFER:
55
56
57
58 if (original_object->buffer.length > 8) {
59 return (AE_AML_OPERAND_TYPE);
60 }
61
62
63
64 for (i = 0; i < original_object->buffer.length; i++) {
65 value |= ((u64)
66 original_object->buffer.pointer[i] << (i *
67 8));
68 }
69 break;
70
71 default:
72
73 return (AE_AML_OPERAND_TYPE);
74 }
75
76 new_object = acpi_ut_create_integer_object(value);
77 if (!new_object) {
78 return (AE_NO_MEMORY);
79 }
80
81 *return_object = new_object;
82 return (AE_OK);
83}
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98acpi_status
99acpi_ns_convert_to_string(union acpi_operand_object *original_object,
100 union acpi_operand_object **return_object)
101{
102 union acpi_operand_object *new_object;
103 acpi_size length;
104 acpi_status status;
105
106 switch (original_object->common.type) {
107 case ACPI_TYPE_INTEGER:
108
109
110
111
112
113 if (original_object->integer.value == 0) {
114
115
116
117 new_object = acpi_ut_create_string_object(0);
118 if (!new_object) {
119 return (AE_NO_MEMORY);
120 }
121 } else {
122 status = acpi_ex_convert_to_string(original_object,
123 &new_object,
124 ACPI_IMPLICIT_CONVERT_HEX);
125 if (ACPI_FAILURE(status)) {
126 return (status);
127 }
128 }
129 break;
130
131 case ACPI_TYPE_BUFFER:
132
133
134
135
136
137
138 length = 0;
139 while ((length < original_object->buffer.length) &&
140 (original_object->buffer.pointer[length])) {
141 length++;
142 }
143
144
145
146 new_object = acpi_ut_create_string_object(length);
147 if (!new_object) {
148 return (AE_NO_MEMORY);
149 }
150
151
152
153
154
155 memcpy(new_object->string.pointer,
156 original_object->buffer.pointer, length);
157 break;
158
159 default:
160
161 return (AE_AML_OPERAND_TYPE);
162 }
163
164 *return_object = new_object;
165 return (AE_OK);
166}
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181acpi_status
182acpi_ns_convert_to_buffer(union acpi_operand_object *original_object,
183 union acpi_operand_object **return_object)
184{
185 union acpi_operand_object *new_object;
186 acpi_status status;
187 union acpi_operand_object **elements;
188 u32 *dword_buffer;
189 u32 count;
190 u32 i;
191
192 switch (original_object->common.type) {
193 case ACPI_TYPE_INTEGER:
194
195
196
197
198
199
200
201 status =
202 acpi_ex_convert_to_buffer(original_object, &new_object);
203 if (ACPI_FAILURE(status)) {
204 return (status);
205 }
206 break;
207
208 case ACPI_TYPE_STRING:
209
210
211
212 new_object = acpi_ut_create_buffer_object
213 (original_object->string.length);
214 if (!new_object) {
215 return (AE_NO_MEMORY);
216 }
217
218 memcpy(new_object->buffer.pointer,
219 original_object->string.pointer,
220 original_object->string.length);
221 break;
222
223 case ACPI_TYPE_PACKAGE:
224
225
226
227
228
229
230
231
232 elements = original_object->package.elements;
233 count = original_object->package.count;
234
235 for (i = 0; i < count; i++) {
236 if ((!*elements) ||
237 ((*elements)->common.type != ACPI_TYPE_INTEGER)) {
238 return (AE_AML_OPERAND_TYPE);
239 }
240 elements++;
241 }
242
243
244
245 new_object = acpi_ut_create_buffer_object(ACPI_MUL_4(count));
246 if (!new_object) {
247 return (AE_NO_MEMORY);
248 }
249
250
251
252 elements = original_object->package.elements;
253 dword_buffer = ACPI_CAST_PTR(u32, new_object->buffer.pointer);
254
255 for (i = 0; i < count; i++) {
256 *dword_buffer = (u32)(*elements)->integer.value;
257 dword_buffer++;
258 elements++;
259 }
260 break;
261
262 default:
263
264 return (AE_AML_OPERAND_TYPE);
265 }
266
267 *return_object = new_object;
268 return (AE_OK);
269}
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285acpi_status
286acpi_ns_convert_to_unicode(struct acpi_namespace_node *scope,
287 union acpi_operand_object *original_object,
288 union acpi_operand_object **return_object)
289{
290 union acpi_operand_object *new_object;
291 char *ascii_string;
292 u16 *unicode_buffer;
293 u32 unicode_length;
294 u32 i;
295
296 if (!original_object) {
297 return (AE_OK);
298 }
299
300
301
302 if (original_object->common.type == ACPI_TYPE_BUFFER) {
303 if (original_object->buffer.length < 2) {
304 return (AE_AML_OPERAND_VALUE);
305 }
306
307 *return_object = NULL;
308 return (AE_OK);
309 }
310
311
312
313
314
315 ascii_string = original_object->string.pointer;
316 unicode_length = (original_object->string.length * 2) + 2;
317
318
319
320 new_object = acpi_ut_create_buffer_object(unicode_length);
321 if (!new_object) {
322 return (AE_NO_MEMORY);
323 }
324
325 unicode_buffer = ACPI_CAST_PTR(u16, new_object->buffer.pointer);
326
327
328
329 for (i = 0; i < original_object->string.length; i++) {
330 unicode_buffer[i] = (u16)ascii_string[i];
331 }
332
333 *return_object = new_object;
334 return (AE_OK);
335}
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352acpi_status
353acpi_ns_convert_to_resource(struct acpi_namespace_node *scope,
354 union acpi_operand_object *original_object,
355 union acpi_operand_object **return_object)
356{
357 union acpi_operand_object *new_object;
358 u8 *buffer;
359
360
361
362
363
364
365
366
367
368
369 if (original_object) {
370 switch (original_object->common.type) {
371 case ACPI_TYPE_INTEGER:
372
373
374
375 if (original_object->integer.value) {
376 return (AE_AML_OPERAND_TYPE);
377 }
378 break;
379
380 case ACPI_TYPE_BUFFER:
381
382 if (original_object->buffer.length) {
383
384
385
386 *return_object = NULL;
387 return (AE_OK);
388 }
389 break;
390
391 case ACPI_TYPE_STRING:
392 default:
393
394 return (AE_AML_OPERAND_TYPE);
395 }
396 }
397
398
399
400 new_object = acpi_ut_create_buffer_object(2);
401 if (!new_object) {
402 return (AE_NO_MEMORY);
403 }
404
405 buffer = ACPI_CAST_PTR(u8, new_object->buffer.pointer);
406
407
408
409 buffer[0] = (ACPI_RESOURCE_NAME_END_TAG | ASL_RDESC_END_TAG_SIZE);
410 buffer[1] = 0x00;
411
412 *return_object = new_object;
413 return (AE_OK);
414}
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431acpi_status
432acpi_ns_convert_to_reference(struct acpi_namespace_node *scope,
433 union acpi_operand_object *original_object,
434 union acpi_operand_object **return_object)
435{
436 union acpi_operand_object *new_object = NULL;
437 acpi_status status;
438 struct acpi_namespace_node *node;
439 union acpi_generic_state scope_info;
440 char *name;
441
442 ACPI_FUNCTION_NAME(ns_convert_to_reference);
443
444
445
446 status =
447 acpi_ns_internalize_name(original_object->string.pointer, &name);
448 if (ACPI_FAILURE(status)) {
449 return_ACPI_STATUS(status);
450 }
451
452
453
454 scope_info.scope.node =
455 ACPI_CAST_PTR(struct acpi_namespace_node, scope);
456 status =
457 acpi_ns_lookup(&scope_info, name, ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
458 ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE,
459 NULL, &node);
460 if (ACPI_FAILURE(status)) {
461
462
463
464 ACPI_ERROR_NAMESPACE(&scope_info,
465 original_object->string.pointer, status);
466 goto error_exit;
467 }
468
469
470
471 new_object = acpi_ut_create_internal_object(ACPI_TYPE_LOCAL_REFERENCE);
472 if (!new_object) {
473 status = AE_NO_MEMORY;
474 goto error_exit;
475 }
476 new_object->reference.node = node;
477 new_object->reference.object = node->object;
478 new_object->reference.class = ACPI_REFCLASS_NAME;
479
480
481
482
483
484 acpi_ut_add_reference(node->object);
485
486error_exit:
487 ACPI_FREE(name);
488 *return_object = new_object;
489 return (status);
490}
491