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.
50 #define _COMPONENT ACPI_CA_DEBUGGER
51 ACPI_MODULE_NAME ("dbconvert")
54 #define DB_DEFAULT_PKG_ELEMENTS 33
57 /*******************************************************************************
59 * FUNCTION: AcpiDbHexCharToValue
61 * PARAMETERS: HexChar - Ascii Hex digit, 0-9|a-f|A-F
62 * ReturnValue - Where the converted value is returned
66 * DESCRIPTION: Convert a single hex character to a 4-bit number (0-16).
68 ******************************************************************************/
71 AcpiDbHexCharToValue (
78 /* Digit must be ascii [0-9a-fA-F] */
80 if (!ACPI_IS_XDIGIT (HexChar))
82 return (AE_BAD_HEX_CONSTANT);
87 Value = (UINT8) (HexChar - 0x30);
91 Value = (UINT8) (ACPI_TOUPPER (HexChar) - 0x37);
99 /*******************************************************************************
101 * FUNCTION: AcpiDbHexByteToBinary
103 * PARAMETERS: HexByte - Double hex digit (0x00 - 0xFF) in format:
104 * HiByte then LoByte.
105 * ReturnValue - Where the converted value is returned
109 * DESCRIPTION: Convert two hex characters to an 8 bit number (0 - 255).
111 ******************************************************************************/
114 AcpiDbHexByteToBinary (
125 Status = AcpiDbHexCharToValue (HexByte[0], &Local0);
126 if (ACPI_FAILURE (Status))
133 Status = AcpiDbHexCharToValue (HexByte[1], &Local1);
134 if (ACPI_FAILURE (Status))
139 *ReturnValue = (UINT8) ((Local0 << 4) | Local1);
144 /*******************************************************************************
146 * FUNCTION: AcpiDbConvertToBuffer
148 * PARAMETERS: String - Input string to be converted
149 * Object - Where the buffer object is returned
153 * DESCRIPTION: Convert a string to a buffer object. String is treated a list
154 * of buffer elements, each separated by a space or comma.
156 ******************************************************************************/
159 AcpiDbConvertToBuffer (
170 /* Generate the final buffer length */
172 for (i = 0, Length = 0; String[i];)
178 ((String[i] == ',') || (String[i] == ' ')))
184 Buffer = ACPI_ALLOCATE (Length);
187 return (AE_NO_MEMORY);
190 /* Convert the command line bytes to the buffer */
192 for (i = 0, j = 0; String[i];)
194 Status = AcpiDbHexByteToBinary (&String[i], &Buffer[j]);
195 if (ACPI_FAILURE (Status))
204 ((String[i] == ',') || (String[i] == ' ')))
210 Object->Type = ACPI_TYPE_BUFFER;
211 Object->Buffer.Pointer = Buffer;
212 Object->Buffer.Length = Length;
217 /*******************************************************************************
219 * FUNCTION: AcpiDbConvertToPackage
221 * PARAMETERS: String - Input string to be converted
222 * Object - Where the package object is returned
226 * DESCRIPTION: Convert a string to a package object. Handles nested packages
227 * via recursion with AcpiDbConvertToObject.
229 ******************************************************************************/
232 AcpiDbConvertToPackage (
239 ACPI_OBJECT_TYPE Type;
240 ACPI_OBJECT *Elements;
244 Elements = ACPI_ALLOCATE_ZEROED (
245 DB_DEFAULT_PKG_ELEMENTS * sizeof (ACPI_OBJECT));
248 for (i = 0; i < (DB_DEFAULT_PKG_ELEMENTS - 1); i++)
250 This = AcpiDbGetNextToken (This, &Next, &Type);
256 /* Recursive call to convert each package element */
258 Status = AcpiDbConvertToObject (Type, This, &Elements[i]);
259 if (ACPI_FAILURE (Status))
261 AcpiDbDeleteObjects (i + 1, Elements);
262 ACPI_FREE (Elements);
269 Object->Type = ACPI_TYPE_PACKAGE;
270 Object->Package.Count = i;
271 Object->Package.Elements = Elements;
276 /*******************************************************************************
278 * FUNCTION: AcpiDbConvertToObject
280 * PARAMETERS: Type - Object type as determined by parser
281 * String - Input string to be converted
282 * Object - Where the new object is returned
286 * DESCRIPTION: Convert a typed and tokenized string to an ACPI_OBJECT. Typing:
287 * 1) String objects were surrounded by quotes.
288 * 2) Buffer objects were surrounded by parentheses.
289 * 3) Package objects were surrounded by brackets "[]".
290 * 4) All standalone tokens are treated as integers.
292 ******************************************************************************/
295 AcpiDbConvertToObject (
296 ACPI_OBJECT_TYPE Type,
300 ACPI_STATUS Status = AE_OK;
305 case ACPI_TYPE_STRING:
307 Object->Type = ACPI_TYPE_STRING;
308 Object->String.Pointer = String;
309 Object->String.Length = (UINT32) ACPI_STRLEN (String);
312 case ACPI_TYPE_BUFFER:
314 Status = AcpiDbConvertToBuffer (String, Object);
317 case ACPI_TYPE_PACKAGE:
319 Status = AcpiDbConvertToPackage (String, Object);
324 Object->Type = ACPI_TYPE_INTEGER;
325 Status = AcpiUtStrtoul64 (String, 16, &Object->Integer.Value);
333 /*******************************************************************************
335 * FUNCTION: AcpiDbEncodePldBuffer
337 * PARAMETERS: PldInfo - _PLD buffer struct (Using local struct)
339 * RETURN: Encode _PLD buffer suitable for return value from _PLD
341 * DESCRIPTION: Bit-packs a _PLD buffer struct. Used to test the _PLD macros
343 ******************************************************************************/
346 AcpiDbEncodePldBuffer (
347 ACPI_PLD_INFO *PldInfo)
353 Buffer = ACPI_ALLOCATE_ZEROED (ACPI_PLD_BUFFER_SIZE);
362 ACPI_PLD_SET_REVISION (&Dword, PldInfo->Revision);
363 ACPI_PLD_SET_IGNORE_COLOR (&Dword, PldInfo->IgnoreColor);
364 ACPI_PLD_SET_RED (&Dword, PldInfo->Red);
365 ACPI_PLD_SET_GREEN (&Dword, PldInfo->Green);
366 ACPI_PLD_SET_BLUE (&Dword, PldInfo->Blue);
367 ACPI_MOVE_32_TO_32 (&Buffer[0], &Dword);
372 ACPI_PLD_SET_WIDTH (&Dword, PldInfo->Width);
373 ACPI_PLD_SET_HEIGHT (&Dword, PldInfo->Height);
374 ACPI_MOVE_32_TO_32 (&Buffer[1], &Dword);
379 ACPI_PLD_SET_USER_VISIBLE (&Dword, PldInfo->UserVisible);
380 ACPI_PLD_SET_DOCK (&Dword, PldInfo->Dock);
381 ACPI_PLD_SET_LID (&Dword, PldInfo->Lid);
382 ACPI_PLD_SET_PANEL (&Dword, PldInfo->Panel);
383 ACPI_PLD_SET_VERTICAL (&Dword, PldInfo->VerticalPosition);
384 ACPI_PLD_SET_HORIZONTAL (&Dword, PldInfo->HorizontalPosition);
385 ACPI_PLD_SET_SHAPE (&Dword, PldInfo->Shape);
386 ACPI_PLD_SET_ORIENTATION (&Dword, PldInfo->GroupOrientation);
387 ACPI_PLD_SET_TOKEN (&Dword, PldInfo->GroupToken);
388 ACPI_PLD_SET_POSITION (&Dword, PldInfo->GroupPosition);
389 ACPI_PLD_SET_BAY (&Dword, PldInfo->Bay);
390 ACPI_MOVE_32_TO_32 (&Buffer[2], &Dword);
395 ACPI_PLD_SET_EJECTABLE (&Dword, PldInfo->Ejectable);
396 ACPI_PLD_SET_OSPM_EJECT (&Dword, PldInfo->OspmEjectRequired);
397 ACPI_PLD_SET_CABINET (&Dword, PldInfo->CabinetNumber);
398 ACPI_PLD_SET_CARD_CAGE (&Dword, PldInfo->CardCageNumber);
399 ACPI_PLD_SET_REFERENCE (&Dword, PldInfo->Reference);
400 ACPI_PLD_SET_ROTATION (&Dword, PldInfo->Rotation);
401 ACPI_PLD_SET_ORDER (&Dword, PldInfo->Order);
402 ACPI_MOVE_32_TO_32 (&Buffer[3], &Dword);
404 if (PldInfo->Revision >= 2)
409 ACPI_PLD_SET_VERT_OFFSET (&Dword, PldInfo->VerticalOffset);
410 ACPI_PLD_SET_HORIZ_OFFSET (&Dword, PldInfo->HorizontalOffset);
411 ACPI_MOVE_32_TO_32 (&Buffer[4], &Dword);
414 return (ACPI_CAST_PTR (UINT8, Buffer));
418 /*******************************************************************************
420 * FUNCTION: AcpiDbDumpPldBuffer
422 * PARAMETERS: ObjDesc - Object returned from _PLD method
426 * DESCRIPTION: Dumps formatted contents of a _PLD return buffer.
428 ******************************************************************************/
430 #define ACPI_PLD_OUTPUT "%20s : %-6X\n"
433 AcpiDbDumpPldBuffer (
434 ACPI_OBJECT *ObjDesc)
436 ACPI_OBJECT *BufferDesc;
437 ACPI_PLD_INFO *PldInfo;
442 /* Object must be of type Package with at least one Buffer element */
444 if (ObjDesc->Type != ACPI_TYPE_PACKAGE)
449 BufferDesc = &ObjDesc->Package.Elements[0];
450 if (BufferDesc->Type != ACPI_TYPE_BUFFER)
455 /* Convert _PLD buffer to local _PLD struct */
457 Status = AcpiDecodePldBuffer (BufferDesc->Buffer.Pointer,
458 BufferDesc->Buffer.Length, &PldInfo);
459 if (ACPI_FAILURE (Status))
464 /* Encode local _PLD struct back to a _PLD buffer */
466 NewBuffer = AcpiDbEncodePldBuffer (PldInfo);
472 /* The two bit-packed buffers should match */
474 if (ACPI_MEMCMP (NewBuffer, BufferDesc->Buffer.Pointer,
475 BufferDesc->Buffer.Length))
477 AcpiOsPrintf ("Converted _PLD buffer does not compare. New:\n");
479 AcpiUtDumpBuffer (NewBuffer,
480 BufferDesc->Buffer.Length, DB_BYTE_DISPLAY, 0);
483 /* First 32-bit dword */
485 AcpiOsPrintf (ACPI_PLD_OUTPUT, "PLD_Revision", PldInfo->Revision);
486 AcpiOsPrintf (ACPI_PLD_OUTPUT, "PLD_IgnoreColor", PldInfo->IgnoreColor);
487 AcpiOsPrintf (ACPI_PLD_OUTPUT, "PLD_Red", PldInfo->Red);
488 AcpiOsPrintf (ACPI_PLD_OUTPUT, "PLD_Green", PldInfo->Green);
489 AcpiOsPrintf (ACPI_PLD_OUTPUT, "PLD_Blue", PldInfo->Blue);
491 /* Second 32-bit dword */
493 AcpiOsPrintf (ACPI_PLD_OUTPUT, "PLD_Width", PldInfo->Width);
494 AcpiOsPrintf (ACPI_PLD_OUTPUT, "PLD_Height", PldInfo->Height);
496 /* Third 32-bit dword */
498 AcpiOsPrintf (ACPI_PLD_OUTPUT, "PLD_UserVisible", PldInfo->UserVisible);
499 AcpiOsPrintf (ACPI_PLD_OUTPUT, "PLD_Dock", PldInfo->Dock);
500 AcpiOsPrintf (ACPI_PLD_OUTPUT, "PLD_Lid", PldInfo->Lid);
501 AcpiOsPrintf (ACPI_PLD_OUTPUT, "PLD_Panel", PldInfo->Panel);
502 AcpiOsPrintf (ACPI_PLD_OUTPUT, "PLD_VerticalPosition", PldInfo->VerticalPosition);
503 AcpiOsPrintf (ACPI_PLD_OUTPUT, "PLD_HorizontalPosition", PldInfo->HorizontalPosition);
504 AcpiOsPrintf (ACPI_PLD_OUTPUT, "PLD_Shape", PldInfo->Shape);
505 AcpiOsPrintf (ACPI_PLD_OUTPUT, "PLD_GroupOrientation", PldInfo->GroupOrientation);
506 AcpiOsPrintf (ACPI_PLD_OUTPUT, "PLD_GroupToken", PldInfo->GroupToken);
507 AcpiOsPrintf (ACPI_PLD_OUTPUT, "PLD_GroupPosition", PldInfo->GroupPosition);
508 AcpiOsPrintf (ACPI_PLD_OUTPUT, "PLD_Bay", PldInfo->Bay);
510 /* Fourth 32-bit dword */
512 AcpiOsPrintf (ACPI_PLD_OUTPUT, "PLD_Ejectable", PldInfo->Ejectable);
513 AcpiOsPrintf (ACPI_PLD_OUTPUT, "PLD_EjectRequired", PldInfo->OspmEjectRequired);
514 AcpiOsPrintf (ACPI_PLD_OUTPUT, "PLD_CabinetNumber", PldInfo->CabinetNumber);
515 AcpiOsPrintf (ACPI_PLD_OUTPUT, "PLD_CardCageNumber", PldInfo->CardCageNumber);
516 AcpiOsPrintf (ACPI_PLD_OUTPUT, "PLD_Reference", PldInfo->Reference);
517 AcpiOsPrintf (ACPI_PLD_OUTPUT, "PLD_Rotation", PldInfo->Rotation);
518 AcpiOsPrintf (ACPI_PLD_OUTPUT, "PLD_Order", PldInfo->Order);
520 /* Fifth 32-bit dword */
522 if (BufferDesc->Buffer.Length > 16)
524 AcpiOsPrintf (ACPI_PLD_OUTPUT, "PLD_VerticalOffset", PldInfo->VerticalOffset);
525 AcpiOsPrintf (ACPI_PLD_OUTPUT, "PLD_HorizontalOffset", PldInfo->HorizontalOffset);
529 ACPI_FREE (NewBuffer);
532 #endif /* ACPI_DEBUGGER */