1 /*******************************************************************************
3 * Module Name: dbconvert - debugger miscellaneous conversion routines
5 ******************************************************************************/
8 * Copyright (C) 2000 - 2015, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
44 #include <acpi/acpi.h>
48 #define _COMPONENT ACPI_CA_DEBUGGER
49 ACPI_MODULE_NAME("dbconvert")
51 #define DB_DEFAULT_PKG_ELEMENTS 33
52 /*******************************************************************************
54 * FUNCTION: acpi_db_hex_char_to_value
56 * PARAMETERS: hex_char - Ascii Hex digit, 0-9|a-f|A-F
57 * return_value - Where the converted value is returned
61 * DESCRIPTION: Convert a single hex character to a 4-bit number (0-16).
63 ******************************************************************************/
64 acpi_status
acpi_db_hex_char_to_value(int hex_char
, u8
*return_value
)
68 /* Digit must be ascii [0-9a-fA-F] */
70 if (!isxdigit(hex_char
)) {
71 return (AE_BAD_HEX_CONSTANT
);
74 if (hex_char
<= 0x39) {
75 value
= (u8
)(hex_char
- 0x30);
77 value
= (u8
)(toupper(hex_char
) - 0x37);
80 *return_value
= value
;
84 /*******************************************************************************
86 * FUNCTION: acpi_db_hex_byte_to_binary
88 * PARAMETERS: hex_byte - Double hex digit (0x00 - 0xFF) in format:
89 * hi_byte then lo_byte.
90 * return_value - Where the converted value is returned
94 * DESCRIPTION: Convert two hex characters to an 8 bit number (0 - 255).
96 ******************************************************************************/
98 static acpi_status
acpi_db_hex_byte_to_binary(char *hex_byte
, u8
*return_value
)
106 status
= acpi_db_hex_char_to_value(hex_byte
[0], &local0
);
107 if (ACPI_FAILURE(status
)) {
113 status
= acpi_db_hex_char_to_value(hex_byte
[1], &local1
);
114 if (ACPI_FAILURE(status
)) {
118 *return_value
= (u8
)((local0
<< 4) | local1
);
122 /*******************************************************************************
124 * FUNCTION: acpi_db_convert_to_buffer
126 * PARAMETERS: string - Input string to be converted
127 * object - Where the buffer object is returned
131 * DESCRIPTION: Convert a string to a buffer object. String is treated a list
132 * of buffer elements, each separated by a space or comma.
134 ******************************************************************************/
137 acpi_db_convert_to_buffer(char *string
, union acpi_object
*object
)
145 /* Generate the final buffer length */
147 for (i
= 0, length
= 0; string
[i
];) {
151 while (string
[i
] && ((string
[i
] == ',') || (string
[i
] == ' '))) {
156 buffer
= ACPI_ALLOCATE(length
);
158 return (AE_NO_MEMORY
);
161 /* Convert the command line bytes to the buffer */
163 for (i
= 0, j
= 0; string
[i
];) {
164 status
= acpi_db_hex_byte_to_binary(&string
[i
], &buffer
[j
]);
165 if (ACPI_FAILURE(status
)) {
172 while (string
[i
] && ((string
[i
] == ',') || (string
[i
] == ' '))) {
177 object
->type
= ACPI_TYPE_BUFFER
;
178 object
->buffer
.pointer
= buffer
;
179 object
->buffer
.length
= length
;
183 /*******************************************************************************
185 * FUNCTION: acpi_db_convert_to_package
187 * PARAMETERS: string - Input string to be converted
188 * object - Where the package object is returned
192 * DESCRIPTION: Convert a string to a package object. Handles nested packages
193 * via recursion with acpi_db_convert_to_object.
195 ******************************************************************************/
197 acpi_status
acpi_db_convert_to_package(char *string
, union acpi_object
* object
)
202 acpi_object_type type
;
203 union acpi_object
*elements
;
207 ACPI_ALLOCATE_ZEROED(DB_DEFAULT_PKG_ELEMENTS
*
208 sizeof(union acpi_object
));
211 for (i
= 0; i
< (DB_DEFAULT_PKG_ELEMENTS
- 1); i
++) {
212 this = acpi_db_get_next_token(this, &next
, &type
);
217 /* Recursive call to convert each package element */
219 status
= acpi_db_convert_to_object(type
, this, &elements
[i
]);
220 if (ACPI_FAILURE(status
)) {
221 acpi_db_delete_objects(i
+ 1, elements
);
229 object
->type
= ACPI_TYPE_PACKAGE
;
230 object
->package
.count
= i
;
231 object
->package
.elements
= elements
;
235 /*******************************************************************************
237 * FUNCTION: acpi_db_convert_to_object
239 * PARAMETERS: type - Object type as determined by parser
240 * string - Input string to be converted
241 * object - Where the new object is returned
245 * DESCRIPTION: Convert a typed and tokenized string to an union acpi_object. Typing:
246 * 1) String objects were surrounded by quotes.
247 * 2) Buffer objects were surrounded by parentheses.
248 * 3) Package objects were surrounded by brackets "[]".
249 * 4) All standalone tokens are treated as integers.
251 ******************************************************************************/
254 acpi_db_convert_to_object(acpi_object_type type
,
255 char *string
, union acpi_object
* object
)
257 acpi_status status
= AE_OK
;
260 case ACPI_TYPE_STRING
:
262 object
->type
= ACPI_TYPE_STRING
;
263 object
->string
.pointer
= string
;
264 object
->string
.length
= (u32
)strlen(string
);
267 case ACPI_TYPE_BUFFER
:
269 status
= acpi_db_convert_to_buffer(string
, object
);
272 case ACPI_TYPE_PACKAGE
:
274 status
= acpi_db_convert_to_package(string
, object
);
279 object
->type
= ACPI_TYPE_INTEGER
;
280 status
= acpi_ut_strtoul64(string
, 16, &object
->integer
.value
);
287 /*******************************************************************************
289 * FUNCTION: acpi_db_encode_pld_buffer
291 * PARAMETERS: pld_info - _PLD buffer struct (Using local struct)
293 * RETURN: Encode _PLD buffer suitable for return value from _PLD
295 * DESCRIPTION: Bit-packs a _PLD buffer struct. Used to test the _PLD macros
297 ******************************************************************************/
299 u8
*acpi_db_encode_pld_buffer(struct acpi_pld_info
*pld_info
)
304 buffer
= ACPI_ALLOCATE_ZEROED(ACPI_PLD_BUFFER_SIZE
);
312 ACPI_PLD_SET_REVISION(&dword
, pld_info
->revision
);
313 ACPI_PLD_SET_IGNORE_COLOR(&dword
, pld_info
->ignore_color
);
314 ACPI_PLD_SET_RED(&dword
, pld_info
->red
);
315 ACPI_PLD_SET_GREEN(&dword
, pld_info
->green
);
316 ACPI_PLD_SET_BLUE(&dword
, pld_info
->blue
);
317 ACPI_MOVE_32_TO_32(&buffer
[0], &dword
);
322 ACPI_PLD_SET_WIDTH(&dword
, pld_info
->width
);
323 ACPI_PLD_SET_HEIGHT(&dword
, pld_info
->height
);
324 ACPI_MOVE_32_TO_32(&buffer
[1], &dword
);
329 ACPI_PLD_SET_USER_VISIBLE(&dword
, pld_info
->user_visible
);
330 ACPI_PLD_SET_DOCK(&dword
, pld_info
->dock
);
331 ACPI_PLD_SET_LID(&dword
, pld_info
->lid
);
332 ACPI_PLD_SET_PANEL(&dword
, pld_info
->panel
);
333 ACPI_PLD_SET_VERTICAL(&dword
, pld_info
->vertical_position
);
334 ACPI_PLD_SET_HORIZONTAL(&dword
, pld_info
->horizontal_position
);
335 ACPI_PLD_SET_SHAPE(&dword
, pld_info
->shape
);
336 ACPI_PLD_SET_ORIENTATION(&dword
, pld_info
->group_orientation
);
337 ACPI_PLD_SET_TOKEN(&dword
, pld_info
->group_token
);
338 ACPI_PLD_SET_POSITION(&dword
, pld_info
->group_position
);
339 ACPI_PLD_SET_BAY(&dword
, pld_info
->bay
);
340 ACPI_MOVE_32_TO_32(&buffer
[2], &dword
);
345 ACPI_PLD_SET_EJECTABLE(&dword
, pld_info
->ejectable
);
346 ACPI_PLD_SET_OSPM_EJECT(&dword
, pld_info
->ospm_eject_required
);
347 ACPI_PLD_SET_CABINET(&dword
, pld_info
->cabinet_number
);
348 ACPI_PLD_SET_CARD_CAGE(&dword
, pld_info
->card_cage_number
);
349 ACPI_PLD_SET_REFERENCE(&dword
, pld_info
->reference
);
350 ACPI_PLD_SET_ROTATION(&dword
, pld_info
->rotation
);
351 ACPI_PLD_SET_ORDER(&dword
, pld_info
->order
);
352 ACPI_MOVE_32_TO_32(&buffer
[3], &dword
);
354 if (pld_info
->revision
>= 2) {
359 ACPI_PLD_SET_VERT_OFFSET(&dword
, pld_info
->vertical_offset
);
360 ACPI_PLD_SET_HORIZ_OFFSET(&dword
, pld_info
->horizontal_offset
);
361 ACPI_MOVE_32_TO_32(&buffer
[4], &dword
);
364 return (ACPI_CAST_PTR(u8
, buffer
));
367 /*******************************************************************************
369 * FUNCTION: acpi_db_dump_pld_buffer
371 * PARAMETERS: obj_desc - Object returned from _PLD method
375 * DESCRIPTION: Dumps formatted contents of a _PLD return buffer.
377 ******************************************************************************/
379 #define ACPI_PLD_OUTPUT "%20s : %-6X\n"
381 void acpi_db_dump_pld_buffer(union acpi_object
*obj_desc
)
383 union acpi_object
*buffer_desc
;
384 struct acpi_pld_info
*pld_info
;
388 /* Object must be of type Package with at least one Buffer element */
390 if (obj_desc
->type
!= ACPI_TYPE_PACKAGE
) {
394 buffer_desc
= &obj_desc
->package
.elements
[0];
395 if (buffer_desc
->type
!= ACPI_TYPE_BUFFER
) {
399 /* Convert _PLD buffer to local _PLD struct */
401 status
= acpi_decode_pld_buffer(buffer_desc
->buffer
.pointer
,
402 buffer_desc
->buffer
.length
, &pld_info
);
403 if (ACPI_FAILURE(status
)) {
407 /* Encode local _PLD struct back to a _PLD buffer */
409 new_buffer
= acpi_db_encode_pld_buffer(pld_info
);
414 /* The two bit-packed buffers should match */
416 if (memcmp(new_buffer
, buffer_desc
->buffer
.pointer
,
417 buffer_desc
->buffer
.length
)) {
419 ("Converted _PLD buffer does not compare. New:\n");
421 acpi_ut_dump_buffer(new_buffer
,
422 buffer_desc
->buffer
.length
, DB_BYTE_DISPLAY
,
426 /* First 32-bit dword */
428 acpi_os_printf(ACPI_PLD_OUTPUT
, "PLD_Revision", pld_info
->revision
);
429 acpi_os_printf(ACPI_PLD_OUTPUT
, "PLD_IgnoreColor",
430 pld_info
->ignore_color
);
431 acpi_os_printf(ACPI_PLD_OUTPUT
, "PLD_Red", pld_info
->red
);
432 acpi_os_printf(ACPI_PLD_OUTPUT
, "PLD_Green", pld_info
->green
);
433 acpi_os_printf(ACPI_PLD_OUTPUT
, "PLD_Blue", pld_info
->blue
);
435 /* Second 32-bit dword */
437 acpi_os_printf(ACPI_PLD_OUTPUT
, "PLD_Width", pld_info
->width
);
438 acpi_os_printf(ACPI_PLD_OUTPUT
, "PLD_Height", pld_info
->height
);
440 /* Third 32-bit dword */
442 acpi_os_printf(ACPI_PLD_OUTPUT
, "PLD_UserVisible",
443 pld_info
->user_visible
);
444 acpi_os_printf(ACPI_PLD_OUTPUT
, "PLD_Dock", pld_info
->dock
);
445 acpi_os_printf(ACPI_PLD_OUTPUT
, "PLD_Lid", pld_info
->lid
);
446 acpi_os_printf(ACPI_PLD_OUTPUT
, "PLD_Panel", pld_info
->panel
);
447 acpi_os_printf(ACPI_PLD_OUTPUT
, "PLD_VerticalPosition",
448 pld_info
->vertical_position
);
449 acpi_os_printf(ACPI_PLD_OUTPUT
, "PLD_HorizontalPosition",
450 pld_info
->horizontal_position
);
451 acpi_os_printf(ACPI_PLD_OUTPUT
, "PLD_Shape", pld_info
->shape
);
452 acpi_os_printf(ACPI_PLD_OUTPUT
, "PLD_GroupOrientation",
453 pld_info
->group_orientation
);
454 acpi_os_printf(ACPI_PLD_OUTPUT
, "PLD_GroupToken",
455 pld_info
->group_token
);
456 acpi_os_printf(ACPI_PLD_OUTPUT
, "PLD_GroupPosition",
457 pld_info
->group_position
);
458 acpi_os_printf(ACPI_PLD_OUTPUT
, "PLD_Bay", pld_info
->bay
);
460 /* Fourth 32-bit dword */
462 acpi_os_printf(ACPI_PLD_OUTPUT
, "PLD_Ejectable", pld_info
->ejectable
);
463 acpi_os_printf(ACPI_PLD_OUTPUT
, "PLD_EjectRequired",
464 pld_info
->ospm_eject_required
);
465 acpi_os_printf(ACPI_PLD_OUTPUT
, "PLD_CabinetNumber",
466 pld_info
->cabinet_number
);
467 acpi_os_printf(ACPI_PLD_OUTPUT
, "PLD_CardCageNumber",
468 pld_info
->card_cage_number
);
469 acpi_os_printf(ACPI_PLD_OUTPUT
, "PLD_Reference", pld_info
->reference
);
470 acpi_os_printf(ACPI_PLD_OUTPUT
, "PLD_Rotation", pld_info
->rotation
);
471 acpi_os_printf(ACPI_PLD_OUTPUT
, "PLD_Order", pld_info
->order
);
473 /* Fifth 32-bit dword */
475 if (buffer_desc
->buffer
.length
> 16) {
476 acpi_os_printf(ACPI_PLD_OUTPUT
, "PLD_VerticalOffset",
477 pld_info
->vertical_offset
);
478 acpi_os_printf(ACPI_PLD_OUTPUT
, "PLD_HorizontalOffset",
479 pld_info
->horizontal_offset
);
483 ACPI_FREE(new_buffer
);