sh_eth: fix EESIPR values for SH77{34|63}
[linux/fpc-iii.git] / drivers / acpi / acpica / dbconvert.c
blob147ce8894f76f85a28f28744a24b94194bc611e8
1 /*******************************************************************************
3 * Module Name: dbconvert - debugger miscellaneous conversion routines
5 ******************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2016, Intel Corp.
9 * All rights reserved.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
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.
30 * NO WARRANTY
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>
45 #include "accommon.h"
46 #include "acdebug.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
59 * RETURN: Status
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)
66 u8 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);
76 } else {
77 value = (u8)(toupper(hex_char) - 0x37);
80 *return_value = value;
81 return (AE_OK);
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
92 * RETURN: Status
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)
100 u8 local0;
101 u8 local1;
102 acpi_status status;
104 /* High byte */
106 status = acpi_db_hex_char_to_value(hex_byte[0], &local0);
107 if (ACPI_FAILURE(status)) {
108 return (status);
111 /* Low byte */
113 status = acpi_db_hex_char_to_value(hex_byte[1], &local1);
114 if (ACPI_FAILURE(status)) {
115 return (status);
118 *return_value = (u8)((local0 << 4) | local1);
119 return (AE_OK);
122 /*******************************************************************************
124 * FUNCTION: acpi_db_convert_to_buffer
126 * PARAMETERS: string - Input string to be converted
127 * object - Where the buffer object is returned
129 * RETURN: Status
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 ******************************************************************************/
136 static acpi_status
137 acpi_db_convert_to_buffer(char *string, union acpi_object *object)
139 u32 i;
140 u32 j;
141 u32 length;
142 u8 *buffer;
143 acpi_status status;
145 /* Generate the final buffer length */
147 for (i = 0, length = 0; string[i];) {
148 i += 2;
149 length++;
151 while (string[i] && ((string[i] == ',') || (string[i] == ' '))) {
152 i++;
156 buffer = ACPI_ALLOCATE(length);
157 if (!buffer) {
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)) {
166 ACPI_FREE(buffer);
167 return (status);
170 j++;
171 i += 2;
172 while (string[i] && ((string[i] == ',') || (string[i] == ' '))) {
173 i++;
177 object->type = ACPI_TYPE_BUFFER;
178 object->buffer.pointer = buffer;
179 object->buffer.length = length;
180 return (AE_OK);
183 /*******************************************************************************
185 * FUNCTION: acpi_db_convert_to_package
187 * PARAMETERS: string - Input string to be converted
188 * object - Where the package object is returned
190 * RETURN: Status
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)
199 char *this;
200 char *next;
201 u32 i;
202 acpi_object_type type;
203 union acpi_object *elements;
204 acpi_status status;
206 elements =
207 ACPI_ALLOCATE_ZEROED(DB_DEFAULT_PKG_ELEMENTS *
208 sizeof(union acpi_object));
210 this = string;
211 for (i = 0; i < (DB_DEFAULT_PKG_ELEMENTS - 1); i++) {
212 this = acpi_db_get_next_token(this, &next, &type);
213 if (!this) {
214 break;
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);
222 ACPI_FREE(elements);
223 return (status);
226 this = next;
229 object->type = ACPI_TYPE_PACKAGE;
230 object->package.count = i;
231 object->package.elements = elements;
232 return (AE_OK);
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
243 * RETURN: Status
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 ******************************************************************************/
253 acpi_status
254 acpi_db_convert_to_object(acpi_object_type type,
255 char *string, union acpi_object *object)
257 acpi_status status = AE_OK;
259 switch (type) {
260 case ACPI_TYPE_STRING:
262 object->type = ACPI_TYPE_STRING;
263 object->string.pointer = string;
264 object->string.length = (u32)strlen(string);
265 break;
267 case ACPI_TYPE_BUFFER:
269 status = acpi_db_convert_to_buffer(string, object);
270 break;
272 case ACPI_TYPE_PACKAGE:
274 status = acpi_db_convert_to_package(string, object);
275 break;
277 default:
279 object->type = ACPI_TYPE_INTEGER;
280 status = acpi_ut_strtoul64(string,
281 (acpi_gbl_integer_byte_width |
282 ACPI_STRTOUL_BASE16),
283 &object->integer.value);
284 break;
287 return (status);
290 /*******************************************************************************
292 * FUNCTION: acpi_db_encode_pld_buffer
294 * PARAMETERS: pld_info - _PLD buffer struct (Using local struct)
296 * RETURN: Encode _PLD buffer suitable for return value from _PLD
298 * DESCRIPTION: Bit-packs a _PLD buffer struct. Used to test the _PLD macros
300 ******************************************************************************/
302 u8 *acpi_db_encode_pld_buffer(struct acpi_pld_info *pld_info)
304 u32 *buffer;
305 u32 dword;
307 buffer = ACPI_ALLOCATE_ZEROED(ACPI_PLD_BUFFER_SIZE);
308 if (!buffer) {
309 return (NULL);
312 /* First 32 bits */
314 dword = 0;
315 ACPI_PLD_SET_REVISION(&dword, pld_info->revision);
316 ACPI_PLD_SET_IGNORE_COLOR(&dword, pld_info->ignore_color);
317 ACPI_PLD_SET_RED(&dword, pld_info->red);
318 ACPI_PLD_SET_GREEN(&dword, pld_info->green);
319 ACPI_PLD_SET_BLUE(&dword, pld_info->blue);
320 ACPI_MOVE_32_TO_32(&buffer[0], &dword);
322 /* Second 32 bits */
324 dword = 0;
325 ACPI_PLD_SET_WIDTH(&dword, pld_info->width);
326 ACPI_PLD_SET_HEIGHT(&dword, pld_info->height);
327 ACPI_MOVE_32_TO_32(&buffer[1], &dword);
329 /* Third 32 bits */
331 dword = 0;
332 ACPI_PLD_SET_USER_VISIBLE(&dword, pld_info->user_visible);
333 ACPI_PLD_SET_DOCK(&dword, pld_info->dock);
334 ACPI_PLD_SET_LID(&dword, pld_info->lid);
335 ACPI_PLD_SET_PANEL(&dword, pld_info->panel);
336 ACPI_PLD_SET_VERTICAL(&dword, pld_info->vertical_position);
337 ACPI_PLD_SET_HORIZONTAL(&dword, pld_info->horizontal_position);
338 ACPI_PLD_SET_SHAPE(&dword, pld_info->shape);
339 ACPI_PLD_SET_ORIENTATION(&dword, pld_info->group_orientation);
340 ACPI_PLD_SET_TOKEN(&dword, pld_info->group_token);
341 ACPI_PLD_SET_POSITION(&dword, pld_info->group_position);
342 ACPI_PLD_SET_BAY(&dword, pld_info->bay);
343 ACPI_MOVE_32_TO_32(&buffer[2], &dword);
345 /* Fourth 32 bits */
347 dword = 0;
348 ACPI_PLD_SET_EJECTABLE(&dword, pld_info->ejectable);
349 ACPI_PLD_SET_OSPM_EJECT(&dword, pld_info->ospm_eject_required);
350 ACPI_PLD_SET_CABINET(&dword, pld_info->cabinet_number);
351 ACPI_PLD_SET_CARD_CAGE(&dword, pld_info->card_cage_number);
352 ACPI_PLD_SET_REFERENCE(&dword, pld_info->reference);
353 ACPI_PLD_SET_ROTATION(&dword, pld_info->rotation);
354 ACPI_PLD_SET_ORDER(&dword, pld_info->order);
355 ACPI_MOVE_32_TO_32(&buffer[3], &dword);
357 if (pld_info->revision >= 2) {
359 /* Fifth 32 bits */
361 dword = 0;
362 ACPI_PLD_SET_VERT_OFFSET(&dword, pld_info->vertical_offset);
363 ACPI_PLD_SET_HORIZ_OFFSET(&dword, pld_info->horizontal_offset);
364 ACPI_MOVE_32_TO_32(&buffer[4], &dword);
367 return (ACPI_CAST_PTR(u8, buffer));
370 /*******************************************************************************
372 * FUNCTION: acpi_db_dump_pld_buffer
374 * PARAMETERS: obj_desc - Object returned from _PLD method
376 * RETURN: None.
378 * DESCRIPTION: Dumps formatted contents of a _PLD return buffer.
380 ******************************************************************************/
382 #define ACPI_PLD_OUTPUT "%20s : %-6X\n"
384 void acpi_db_dump_pld_buffer(union acpi_object *obj_desc)
386 union acpi_object *buffer_desc;
387 struct acpi_pld_info *pld_info;
388 u8 *new_buffer;
389 acpi_status status;
391 /* Object must be of type Package with at least one Buffer element */
393 if (obj_desc->type != ACPI_TYPE_PACKAGE) {
394 return;
397 buffer_desc = &obj_desc->package.elements[0];
398 if (buffer_desc->type != ACPI_TYPE_BUFFER) {
399 return;
402 /* Convert _PLD buffer to local _PLD struct */
404 status = acpi_decode_pld_buffer(buffer_desc->buffer.pointer,
405 buffer_desc->buffer.length, &pld_info);
406 if (ACPI_FAILURE(status)) {
407 return;
410 /* Encode local _PLD struct back to a _PLD buffer */
412 new_buffer = acpi_db_encode_pld_buffer(pld_info);
413 if (!new_buffer) {
414 goto exit;
417 /* The two bit-packed buffers should match */
419 if (memcmp(new_buffer, buffer_desc->buffer.pointer,
420 buffer_desc->buffer.length)) {
421 acpi_os_printf
422 ("Converted _PLD buffer does not compare. New:\n");
424 acpi_ut_dump_buffer(new_buffer,
425 buffer_desc->buffer.length, DB_BYTE_DISPLAY,
429 /* First 32-bit dword */
431 acpi_os_printf(ACPI_PLD_OUTPUT, "PLD_Revision", pld_info->revision);
432 acpi_os_printf(ACPI_PLD_OUTPUT, "PLD_IgnoreColor",
433 pld_info->ignore_color);
434 acpi_os_printf(ACPI_PLD_OUTPUT, "PLD_Red", pld_info->red);
435 acpi_os_printf(ACPI_PLD_OUTPUT, "PLD_Green", pld_info->green);
436 acpi_os_printf(ACPI_PLD_OUTPUT, "PLD_Blue", pld_info->blue);
438 /* Second 32-bit dword */
440 acpi_os_printf(ACPI_PLD_OUTPUT, "PLD_Width", pld_info->width);
441 acpi_os_printf(ACPI_PLD_OUTPUT, "PLD_Height", pld_info->height);
443 /* Third 32-bit dword */
445 acpi_os_printf(ACPI_PLD_OUTPUT, "PLD_UserVisible",
446 pld_info->user_visible);
447 acpi_os_printf(ACPI_PLD_OUTPUT, "PLD_Dock", pld_info->dock);
448 acpi_os_printf(ACPI_PLD_OUTPUT, "PLD_Lid", pld_info->lid);
449 acpi_os_printf(ACPI_PLD_OUTPUT, "PLD_Panel", pld_info->panel);
450 acpi_os_printf(ACPI_PLD_OUTPUT, "PLD_VerticalPosition",
451 pld_info->vertical_position);
452 acpi_os_printf(ACPI_PLD_OUTPUT, "PLD_HorizontalPosition",
453 pld_info->horizontal_position);
454 acpi_os_printf(ACPI_PLD_OUTPUT, "PLD_Shape", pld_info->shape);
455 acpi_os_printf(ACPI_PLD_OUTPUT, "PLD_GroupOrientation",
456 pld_info->group_orientation);
457 acpi_os_printf(ACPI_PLD_OUTPUT, "PLD_GroupToken",
458 pld_info->group_token);
459 acpi_os_printf(ACPI_PLD_OUTPUT, "PLD_GroupPosition",
460 pld_info->group_position);
461 acpi_os_printf(ACPI_PLD_OUTPUT, "PLD_Bay", pld_info->bay);
463 /* Fourth 32-bit dword */
465 acpi_os_printf(ACPI_PLD_OUTPUT, "PLD_Ejectable", pld_info->ejectable);
466 acpi_os_printf(ACPI_PLD_OUTPUT, "PLD_EjectRequired",
467 pld_info->ospm_eject_required);
468 acpi_os_printf(ACPI_PLD_OUTPUT, "PLD_CabinetNumber",
469 pld_info->cabinet_number);
470 acpi_os_printf(ACPI_PLD_OUTPUT, "PLD_CardCageNumber",
471 pld_info->card_cage_number);
472 acpi_os_printf(ACPI_PLD_OUTPUT, "PLD_Reference", pld_info->reference);
473 acpi_os_printf(ACPI_PLD_OUTPUT, "PLD_Rotation", pld_info->rotation);
474 acpi_os_printf(ACPI_PLD_OUTPUT, "PLD_Order", pld_info->order);
476 /* Fifth 32-bit dword */
478 if (buffer_desc->buffer.length > 16) {
479 acpi_os_printf(ACPI_PLD_OUTPUT, "PLD_VerticalOffset",
480 pld_info->vertical_offset);
481 acpi_os_printf(ACPI_PLD_OUTPUT, "PLD_HorizontalOffset",
482 pld_info->horizontal_offset);
485 ACPI_FREE(new_buffer);
486 exit:
487 ACPI_FREE(pld_info);