aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/acpi/acpica
diff options
context:
space:
mode:
authorBob Moore <robert.moore@intel.com>2013-03-08 04:23:16 -0500
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2013-03-11 19:45:05 -0400
commit76a6225bf0b64572251a8c27d33e84afac6af713 (patch)
tree96d9869aa27375efa6f7fb0210a926f6070dba54 /drivers/acpi/acpica
parentd5a36100f62fa6db5541344e08b361b34e9114c5 (diff)
ACPICA: Split object conversion functions to a new file
New file, nsconvert.c, for return object conversion functions. Created in preparation for new conversion functions forthcoming. Signed-off-by: Bob Moore <robert.moore@intel.com> Signed-off-by: Lv Zheng <lv.zheng@intel.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Diffstat (limited to 'drivers/acpi/acpica')
-rw-r--r--drivers/acpi/acpica/Makefile1
-rw-r--r--drivers/acpi/acpica/acnamesp.h15
-rw-r--r--drivers/acpi/acpica/nsconvert.c302
-rw-r--r--drivers/acpi/acpica/nsrepair.c262
4 files changed, 318 insertions, 262 deletions
diff --git a/drivers/acpi/acpica/Makefile b/drivers/acpi/acpica/Makefile
index a1b9bf5085a2..5a542c8db942 100644
--- a/drivers/acpi/acpica/Makefile
+++ b/drivers/acpi/acpica/Makefile
@@ -83,6 +83,7 @@ acpi-$(ACPI_FUTURE_USAGE) += hwtimer.o
83acpi-y += \ 83acpi-y += \
84 nsaccess.o \ 84 nsaccess.o \
85 nsalloc.o \ 85 nsalloc.o \
86 nsconvert.o \
86 nsdump.o \ 87 nsdump.o \
87 nseval.o \ 88 nseval.o \
88 nsinit.o \ 89 nsinit.o \
diff --git a/drivers/acpi/acpica/acnamesp.h b/drivers/acpi/acpica/acnamesp.h
index dec6e9ec2e0c..7156bc75ebe0 100644
--- a/drivers/acpi/acpica/acnamesp.h
+++ b/drivers/acpi/acpica/acnamesp.h
@@ -167,6 +167,21 @@ void acpi_ns_delete_children(struct acpi_namespace_node *parent);
167int acpi_ns_compare_names(char *name1, char *name2); 167int acpi_ns_compare_names(char *name1, char *name2);
168 168
169/* 169/*
170 * nsconvert - Dynamic object conversion routines
171 */
172acpi_status
173acpi_ns_convert_to_integer(union acpi_operand_object *original_object,
174 union acpi_operand_object **return_object);
175
176acpi_status
177acpi_ns_convert_to_string(union acpi_operand_object *original_object,
178 union acpi_operand_object **return_object);
179
180acpi_status
181acpi_ns_convert_to_buffer(union acpi_operand_object *original_object,
182 union acpi_operand_object **return_object);
183
184/*
170 * nsdump - Namespace dump/print utilities 185 * nsdump - Namespace dump/print utilities
171 */ 186 */
172#ifdef ACPI_FUTURE_USAGE 187#ifdef ACPI_FUTURE_USAGE
diff --git a/drivers/acpi/acpica/nsconvert.c b/drivers/acpi/acpica/nsconvert.c
new file mode 100644
index 000000000000..fcb7dfb494cd
--- /dev/null
+++ b/drivers/acpi/acpica/nsconvert.c
@@ -0,0 +1,302 @@
1/******************************************************************************
2 *
3 * Module Name: nsconvert - Object conversions for objects returned by
4 * predefined methods
5 *
6 *****************************************************************************/
7
8/*
9 * Copyright (C) 2000 - 2013, Intel Corp.
10 * All rights reserved.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions, and the following disclaimer,
17 * without modification.
18 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 * substantially similar to the "NO WARRANTY" disclaimer below
20 * ("Disclaimer") and any redistribution must be conditioned upon
21 * including a substantially similar Disclaimer requirement for further
22 * binary redistribution.
23 * 3. Neither the names of the above-listed copyright holders nor the names
24 * of any contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
26 *
27 * Alternatively, this software may be distributed under the terms of the
28 * GNU General Public License ("GPL") version 2 as published by the Free
29 * Software Foundation.
30 *
31 * NO WARRANTY
32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 * POSSIBILITY OF SUCH DAMAGES.
43 */
44
45#include <acpi/acpi.h>
46#include "accommon.h"
47#include "acnamesp.h"
48#include "acinterp.h"
49#include "acpredef.h"
50#include "amlresrc.h"
51
52#define _COMPONENT ACPI_NAMESPACE
53ACPI_MODULE_NAME("nsconvert")
54
55/*******************************************************************************
56 *
57 * FUNCTION: acpi_ns_convert_to_integer
58 *
59 * PARAMETERS: original_object - Object to be converted
60 * return_object - Where the new converted object is returned
61 *
62 * RETURN: Status. AE_OK if conversion was successful.
63 *
64 * DESCRIPTION: Attempt to convert a String/Buffer object to an Integer.
65 *
66 ******************************************************************************/
67acpi_status
68acpi_ns_convert_to_integer(union acpi_operand_object *original_object,
69 union acpi_operand_object **return_object)
70{
71 union acpi_operand_object *new_object;
72 acpi_status status;
73 u64 value = 0;
74 u32 i;
75
76 switch (original_object->common.type) {
77 case ACPI_TYPE_STRING:
78
79 /* String-to-Integer conversion */
80
81 status = acpi_ut_strtoul64(original_object->string.pointer,
82 ACPI_ANY_BASE, &value);
83 if (ACPI_FAILURE(status)) {
84 return (status);
85 }
86 break;
87
88 case ACPI_TYPE_BUFFER:
89
90 /* Buffer-to-Integer conversion. Max buffer size is 64 bits. */
91
92 if (original_object->buffer.length > 8) {
93 return (AE_AML_OPERAND_TYPE);
94 }
95
96 /* Extract each buffer byte to create the integer */
97
98 for (i = 0; i < original_object->buffer.length; i++) {
99 value |=
100 ((u64)original_object->buffer.
101 pointer[i] << (i * 8));
102 }
103 break;
104
105 default:
106 return (AE_AML_OPERAND_TYPE);
107 }
108
109 new_object = acpi_ut_create_integer_object(value);
110 if (!new_object) {
111 return (AE_NO_MEMORY);
112 }
113
114 *return_object = new_object;
115 return (AE_OK);
116}
117
118/*******************************************************************************
119 *
120 * FUNCTION: acpi_ns_convert_to_string
121 *
122 * PARAMETERS: original_object - Object to be converted
123 * return_object - Where the new converted object is returned
124 *
125 * RETURN: Status. AE_OK if conversion was successful.
126 *
127 * DESCRIPTION: Attempt to convert a Integer/Buffer object to a String.
128 *
129 ******************************************************************************/
130
131acpi_status
132acpi_ns_convert_to_string(union acpi_operand_object *original_object,
133 union acpi_operand_object **return_object)
134{
135 union acpi_operand_object *new_object;
136 acpi_size length;
137 acpi_status status;
138
139 switch (original_object->common.type) {
140 case ACPI_TYPE_INTEGER:
141 /*
142 * Integer-to-String conversion. Commonly, convert
143 * an integer of value 0 to a NULL string. The last element of
144 * _BIF and _BIX packages occasionally need this fix.
145 */
146 if (original_object->integer.value == 0) {
147
148 /* Allocate a new NULL string object */
149
150 new_object = acpi_ut_create_string_object(0);
151 if (!new_object) {
152 return (AE_NO_MEMORY);
153 }
154 } else {
155 status =
156 acpi_ex_convert_to_string(original_object,
157 &new_object,
158 ACPI_IMPLICIT_CONVERT_HEX);
159 if (ACPI_FAILURE(status)) {
160 return (status);
161 }
162 }
163 break;
164
165 case ACPI_TYPE_BUFFER:
166 /*
167 * Buffer-to-String conversion. Use a to_string
168 * conversion, no transform performed on the buffer data. The best
169 * example of this is the _BIF method, where the string data from
170 * the battery is often (incorrectly) returned as buffer object(s).
171 */
172 length = 0;
173 while ((length < original_object->buffer.length) &&
174 (original_object->buffer.pointer[length])) {
175 length++;
176 }
177
178 /* Allocate a new string object */
179
180 new_object = acpi_ut_create_string_object(length);
181 if (!new_object) {
182 return (AE_NO_MEMORY);
183 }
184
185 /*
186 * Copy the raw buffer data with no transform. String is already NULL
187 * terminated at Length+1.
188 */
189 ACPI_MEMCPY(new_object->string.pointer,
190 original_object->buffer.pointer, length);
191 break;
192
193 default:
194 return (AE_AML_OPERAND_TYPE);
195 }
196
197 *return_object = new_object;
198 return (AE_OK);
199}
200
201/*******************************************************************************
202 *
203 * FUNCTION: acpi_ns_convert_to_buffer
204 *
205 * PARAMETERS: original_object - Object to be converted
206 * return_object - Where the new converted object is returned
207 *
208 * RETURN: Status. AE_OK if conversion was successful.
209 *
210 * DESCRIPTION: Attempt to convert a Integer/String/Package object to a Buffer.
211 *
212 ******************************************************************************/
213
214acpi_status
215acpi_ns_convert_to_buffer(union acpi_operand_object *original_object,
216 union acpi_operand_object **return_object)
217{
218 union acpi_operand_object *new_object;
219 acpi_status status;
220 union acpi_operand_object **elements;
221 u32 *dword_buffer;
222 u32 count;
223 u32 i;
224
225 switch (original_object->common.type) {
226 case ACPI_TYPE_INTEGER:
227 /*
228 * Integer-to-Buffer conversion.
229 * Convert the Integer to a packed-byte buffer. _MAT and other
230 * objects need this sometimes, if a read has been performed on a
231 * Field object that is less than or equal to the global integer
232 * size (32 or 64 bits).
233 */
234 status =
235 acpi_ex_convert_to_buffer(original_object, &new_object);
236 if (ACPI_FAILURE(status)) {
237 return (status);
238 }
239 break;
240
241 case ACPI_TYPE_STRING:
242
243 /* String-to-Buffer conversion. Simple data copy */
244
245 new_object =
246 acpi_ut_create_buffer_object(original_object->string.
247 length);
248 if (!new_object) {
249 return (AE_NO_MEMORY);
250 }
251
252 ACPI_MEMCPY(new_object->buffer.pointer,
253 original_object->string.pointer,
254 original_object->string.length);
255 break;
256
257 case ACPI_TYPE_PACKAGE:
258 /*
259 * This case is often seen for predefined names that must return a
260 * Buffer object with multiple DWORD integers within. For example,
261 * _FDE and _GTM. The Package can be converted to a Buffer.
262 */
263
264 /* All elements of the Package must be integers */
265
266 elements = original_object->package.elements;
267 count = original_object->package.count;
268
269 for (i = 0; i < count; i++) {
270 if ((!*elements) ||
271 ((*elements)->common.type != ACPI_TYPE_INTEGER)) {
272 return (AE_AML_OPERAND_TYPE);
273 }
274 elements++;
275 }
276
277 /* Create the new buffer object to replace the Package */
278
279 new_object = acpi_ut_create_buffer_object(ACPI_MUL_4(count));
280 if (!new_object) {
281 return (AE_NO_MEMORY);
282 }
283
284 /* Copy the package elements (integers) to the buffer as DWORDs */
285
286 elements = original_object->package.elements;
287 dword_buffer = ACPI_CAST_PTR(u32, new_object->buffer.pointer);
288
289 for (i = 0; i < count; i++) {
290 *dword_buffer = (u32)(*elements)->integer.value;
291 dword_buffer++;
292 elements++;
293 }
294 break;
295
296 default:
297 return (AE_AML_OPERAND_TYPE);
298 }
299
300 *return_object = new_object;
301 return (AE_OK);
302}
diff --git a/drivers/acpi/acpica/nsrepair.c b/drivers/acpi/acpica/nsrepair.c
index f9c9fd45cd1f..c5e828f4ed0b 100644
--- a/drivers/acpi/acpica/nsrepair.c
+++ b/drivers/acpi/acpica/nsrepair.c
@@ -84,18 +84,6 @@ ACPI_MODULE_NAME("nsrepair")
84 * 84 *
85 ******************************************************************************/ 85 ******************************************************************************/
86/* Local prototypes */ 86/* Local prototypes */
87static acpi_status
88acpi_ns_convert_to_integer(union acpi_operand_object *original_object,
89 union acpi_operand_object **return_object);
90
91static acpi_status
92acpi_ns_convert_to_string(union acpi_operand_object *original_object,
93 union acpi_operand_object **return_object);
94
95static acpi_status
96acpi_ns_convert_to_buffer(union acpi_operand_object *original_object,
97 union acpi_operand_object **return_object);
98
99static const struct acpi_simple_repair_info *acpi_ns_match_simple_repair(struct 87static const struct acpi_simple_repair_info *acpi_ns_match_simple_repair(struct
100 acpi_namespace_node 88 acpi_namespace_node
101 *node, 89 *node,
@@ -344,256 +332,6 @@ static const struct acpi_simple_repair_info *acpi_ns_match_simple_repair(struct
344 332
345/******************************************************************************* 333/*******************************************************************************
346 * 334 *
347 * FUNCTION: acpi_ns_convert_to_integer
348 *
349 * PARAMETERS: original_object - Object to be converted
350 * return_object - Where the new converted object is returned
351 *
352 * RETURN: Status. AE_OK if conversion was successful.
353 *
354 * DESCRIPTION: Attempt to convert a String/Buffer object to an Integer.
355 *
356 ******************************************************************************/
357
358static acpi_status
359acpi_ns_convert_to_integer(union acpi_operand_object *original_object,
360 union acpi_operand_object **return_object)
361{
362 union acpi_operand_object *new_object;
363 acpi_status status;
364 u64 value = 0;
365 u32 i;
366
367 switch (original_object->common.type) {
368 case ACPI_TYPE_STRING:
369
370 /* String-to-Integer conversion */
371
372 status = acpi_ut_strtoul64(original_object->string.pointer,
373 ACPI_ANY_BASE, &value);
374 if (ACPI_FAILURE(status)) {
375 return (status);
376 }
377 break;
378
379 case ACPI_TYPE_BUFFER:
380
381 /* Buffer-to-Integer conversion. Max buffer size is 64 bits. */
382
383 if (original_object->buffer.length > 8) {
384 return (AE_AML_OPERAND_TYPE);
385 }
386
387 /* Extract each buffer byte to create the integer */
388
389 for (i = 0; i < original_object->buffer.length; i++) {
390 value |=
391 ((u64) original_object->buffer.
392 pointer[i] << (i * 8));
393 }
394 break;
395
396 default:
397 return (AE_AML_OPERAND_TYPE);
398 }
399
400 new_object = acpi_ut_create_integer_object(value);
401 if (!new_object) {
402 return (AE_NO_MEMORY);
403 }
404
405 *return_object = new_object;
406 return (AE_OK);
407}
408
409/*******************************************************************************
410 *
411 * FUNCTION: acpi_ns_convert_to_string
412 *
413 * PARAMETERS: original_object - Object to be converted
414 * return_object - Where the new converted object is returned
415 *
416 * RETURN: Status. AE_OK if conversion was successful.
417 *
418 * DESCRIPTION: Attempt to convert a Integer/Buffer object to a String.
419 *
420 ******************************************************************************/
421
422static acpi_status
423acpi_ns_convert_to_string(union acpi_operand_object *original_object,
424 union acpi_operand_object **return_object)
425{
426 union acpi_operand_object *new_object;
427 acpi_size length;
428 acpi_status status;
429
430 switch (original_object->common.type) {
431 case ACPI_TYPE_INTEGER:
432 /*
433 * Integer-to-String conversion. Commonly, convert
434 * an integer of value 0 to a NULL string. The last element of
435 * _BIF and _BIX packages occasionally need this fix.
436 */
437 if (original_object->integer.value == 0) {
438
439 /* Allocate a new NULL string object */
440
441 new_object = acpi_ut_create_string_object(0);
442 if (!new_object) {
443 return (AE_NO_MEMORY);
444 }
445 } else {
446 status =
447 acpi_ex_convert_to_string(original_object,
448 &new_object,
449 ACPI_IMPLICIT_CONVERT_HEX);
450 if (ACPI_FAILURE(status)) {
451 return (status);
452 }
453 }
454 break;
455
456 case ACPI_TYPE_BUFFER:
457 /*
458 * Buffer-to-String conversion. Use a to_string
459 * conversion, no transform performed on the buffer data. The best
460 * example of this is the _BIF method, where the string data from
461 * the battery is often (incorrectly) returned as buffer object(s).
462 */
463 length = 0;
464 while ((length < original_object->buffer.length) &&
465 (original_object->buffer.pointer[length])) {
466 length++;
467 }
468
469 /* Allocate a new string object */
470
471 new_object = acpi_ut_create_string_object(length);
472 if (!new_object) {
473 return (AE_NO_MEMORY);
474 }
475
476 /*
477 * Copy the raw buffer data with no transform. String is already NULL
478 * terminated at Length+1.
479 */
480 ACPI_MEMCPY(new_object->string.pointer,
481 original_object->buffer.pointer, length);
482 break;
483
484 default:
485 return (AE_AML_OPERAND_TYPE);
486 }
487
488 *return_object = new_object;
489 return (AE_OK);
490}
491
492/*******************************************************************************
493 *
494 * FUNCTION: acpi_ns_convert_to_buffer
495 *
496 * PARAMETERS: original_object - Object to be converted
497 * return_object - Where the new converted object is returned
498 *
499 * RETURN: Status. AE_OK if conversion was successful.
500 *
501 * DESCRIPTION: Attempt to convert a Integer/String/Package object to a Buffer.
502 *
503 ******************************************************************************/
504
505static acpi_status
506acpi_ns_convert_to_buffer(union acpi_operand_object *original_object,
507 union acpi_operand_object **return_object)
508{
509 union acpi_operand_object *new_object;
510 acpi_status status;
511 union acpi_operand_object **elements;
512 u32 *dword_buffer;
513 u32 count;
514 u32 i;
515
516 switch (original_object->common.type) {
517 case ACPI_TYPE_INTEGER:
518 /*
519 * Integer-to-Buffer conversion.
520 * Convert the Integer to a packed-byte buffer. _MAT and other
521 * objects need this sometimes, if a read has been performed on a
522 * Field object that is less than or equal to the global integer
523 * size (32 or 64 bits).
524 */
525 status =
526 acpi_ex_convert_to_buffer(original_object, &new_object);
527 if (ACPI_FAILURE(status)) {
528 return (status);
529 }
530 break;
531
532 case ACPI_TYPE_STRING:
533
534 /* String-to-Buffer conversion. Simple data copy */
535
536 new_object =
537 acpi_ut_create_buffer_object(original_object->string.
538 length);
539 if (!new_object) {
540 return (AE_NO_MEMORY);
541 }
542
543 ACPI_MEMCPY(new_object->buffer.pointer,
544 original_object->string.pointer,
545 original_object->string.length);
546 break;
547
548 case ACPI_TYPE_PACKAGE:
549 /*
550 * This case is often seen for predefined names that must return a
551 * Buffer object with multiple DWORD integers within. For example,
552 * _FDE and _GTM. The Package can be converted to a Buffer.
553 */
554
555 /* All elements of the Package must be integers */
556
557 elements = original_object->package.elements;
558 count = original_object->package.count;
559
560 for (i = 0; i < count; i++) {
561 if ((!*elements) ||
562 ((*elements)->common.type != ACPI_TYPE_INTEGER)) {
563 return (AE_AML_OPERAND_TYPE);
564 }
565 elements++;
566 }
567
568 /* Create the new buffer object to replace the Package */
569
570 new_object = acpi_ut_create_buffer_object(ACPI_MUL_4(count));
571 if (!new_object) {
572 return (AE_NO_MEMORY);
573 }
574
575 /* Copy the package elements (integers) to the buffer as DWORDs */
576
577 elements = original_object->package.elements;
578 dword_buffer = ACPI_CAST_PTR(u32, new_object->buffer.pointer);
579
580 for (i = 0; i < count; i++) {
581 *dword_buffer = (u32) (*elements)->integer.value;
582 dword_buffer++;
583 elements++;
584 }
585 break;
586
587 default:
588 return (AE_AML_OPERAND_TYPE);
589 }
590
591 *return_object = new_object;
592 return (AE_OK);
593}
594
595/*******************************************************************************
596 *
597 * FUNCTION: acpi_ns_repair_null_element 335 * FUNCTION: acpi_ns_repair_null_element
598 * 336 *
599 * PARAMETERS: data - Pointer to validation data structure 337 * PARAMETERS: data - Pointer to validation data structure