0001
0002
0003
0004
0005
0006
0007
0008 #include <acpi/acpi.h>
0009 #include "accommon.h"
0010 #include "acdebug.h"
0011
0012 #define _COMPONENT ACPI_CA_DEBUGGER
0013 ACPI_MODULE_NAME("dbconvert")
0014
0015 #define DB_DEFAULT_PKG_ELEMENTS 33
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028 acpi_status acpi_db_hex_char_to_value(int hex_char, u8 *return_value)
0029 {
0030 u8 value;
0031
0032
0033
0034 if (!isxdigit(hex_char)) {
0035 return (AE_BAD_HEX_CONSTANT);
0036 }
0037
0038 if (hex_char <= 0x39) {
0039 value = (u8)(hex_char - 0x30);
0040 } else {
0041 value = (u8)(toupper(hex_char) - 0x37);
0042 }
0043
0044 *return_value = value;
0045 return (AE_OK);
0046 }
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062 static acpi_status acpi_db_hex_byte_to_binary(char *hex_byte, u8 *return_value)
0063 {
0064 u8 local0;
0065 u8 local1;
0066 acpi_status status;
0067
0068
0069
0070 status = acpi_db_hex_char_to_value(hex_byte[0], &local0);
0071 if (ACPI_FAILURE(status)) {
0072 return (status);
0073 }
0074
0075
0076
0077 status = acpi_db_hex_char_to_value(hex_byte[1], &local1);
0078 if (ACPI_FAILURE(status)) {
0079 return (status);
0080 }
0081
0082 *return_value = (u8)((local0 << 4) | local1);
0083 return (AE_OK);
0084 }
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100 static acpi_status
0101 acpi_db_convert_to_buffer(char *string, union acpi_object *object)
0102 {
0103 u32 i;
0104 u32 j;
0105 u32 length;
0106 u8 *buffer;
0107 acpi_status status;
0108
0109
0110
0111 acpi_ut_remove_whitespace(&string);
0112
0113
0114
0115 for (i = 0, length = 0; string[i];) {
0116 i += 2;
0117 length++;
0118
0119 while (string[i] && ((string[i] == ',') || (string[i] == ' '))) {
0120 i++;
0121 }
0122 }
0123
0124 buffer = ACPI_ALLOCATE(length);
0125 if (!buffer) {
0126 return (AE_NO_MEMORY);
0127 }
0128
0129
0130
0131 for (i = 0, j = 0; string[i];) {
0132 status = acpi_db_hex_byte_to_binary(&string[i], &buffer[j]);
0133 if (ACPI_FAILURE(status)) {
0134 ACPI_FREE(buffer);
0135 return (status);
0136 }
0137
0138 j++;
0139 i += 2;
0140 while (string[i] && ((string[i] == ',') || (string[i] == ' '))) {
0141 i++;
0142 }
0143 }
0144
0145 object->type = ACPI_TYPE_BUFFER;
0146 object->buffer.pointer = buffer;
0147 object->buffer.length = length;
0148 return (AE_OK);
0149 }
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165 acpi_status acpi_db_convert_to_package(char *string, union acpi_object *object)
0166 {
0167 char *this;
0168 char *next;
0169 u32 i;
0170 acpi_object_type type;
0171 union acpi_object *elements;
0172 acpi_status status;
0173
0174 elements =
0175 ACPI_ALLOCATE_ZEROED(DB_DEFAULT_PKG_ELEMENTS *
0176 sizeof(union acpi_object));
0177
0178 this = string;
0179 for (i = 0; i < (DB_DEFAULT_PKG_ELEMENTS - 1); i++) {
0180 this = acpi_db_get_next_token(this, &next, &type);
0181 if (!this) {
0182 break;
0183 }
0184
0185
0186
0187 status = acpi_db_convert_to_object(type, this, &elements[i]);
0188 if (ACPI_FAILURE(status)) {
0189 acpi_db_delete_objects(i + 1, elements);
0190 ACPI_FREE(elements);
0191 return (status);
0192 }
0193
0194 this = next;
0195 }
0196
0197 object->type = ACPI_TYPE_PACKAGE;
0198 object->package.count = i;
0199 object->package.elements = elements;
0200 return (AE_OK);
0201 }
0202
0203
0204
0205
0206
0207
0208
0209
0210
0211
0212
0213
0214
0215
0216
0217
0218
0219
0220
0221 acpi_status
0222 acpi_db_convert_to_object(acpi_object_type type,
0223 char *string, union acpi_object *object)
0224 {
0225 acpi_status status = AE_OK;
0226
0227 switch (type) {
0228 case ACPI_TYPE_STRING:
0229
0230 object->type = ACPI_TYPE_STRING;
0231 object->string.pointer = string;
0232 object->string.length = (u32)strlen(string);
0233 break;
0234
0235 case ACPI_TYPE_BUFFER:
0236
0237 status = acpi_db_convert_to_buffer(string, object);
0238 break;
0239
0240 case ACPI_TYPE_PACKAGE:
0241
0242 status = acpi_db_convert_to_package(string, object);
0243 break;
0244
0245 default:
0246
0247 object->type = ACPI_TYPE_INTEGER;
0248 status = acpi_ut_strtoul64(string, &object->integer.value);
0249 break;
0250 }
0251
0252 return (status);
0253 }
0254
0255
0256
0257
0258
0259
0260
0261
0262
0263
0264
0265
0266
0267 u8 *acpi_db_encode_pld_buffer(struct acpi_pld_info *pld_info)
0268 {
0269 u32 *buffer;
0270 u32 dword;
0271
0272 buffer = ACPI_ALLOCATE_ZEROED(ACPI_PLD_BUFFER_SIZE);
0273 if (!buffer) {
0274 return (NULL);
0275 }
0276
0277
0278
0279 dword = 0;
0280 ACPI_PLD_SET_REVISION(&dword, pld_info->revision);
0281 ACPI_PLD_SET_IGNORE_COLOR(&dword, pld_info->ignore_color);
0282 ACPI_PLD_SET_RED(&dword, pld_info->red);
0283 ACPI_PLD_SET_GREEN(&dword, pld_info->green);
0284 ACPI_PLD_SET_BLUE(&dword, pld_info->blue);
0285 ACPI_MOVE_32_TO_32(&buffer[0], &dword);
0286
0287
0288
0289 dword = 0;
0290 ACPI_PLD_SET_WIDTH(&dword, pld_info->width);
0291 ACPI_PLD_SET_HEIGHT(&dword, pld_info->height);
0292 ACPI_MOVE_32_TO_32(&buffer[1], &dword);
0293
0294
0295
0296 dword = 0;
0297 ACPI_PLD_SET_USER_VISIBLE(&dword, pld_info->user_visible);
0298 ACPI_PLD_SET_DOCK(&dword, pld_info->dock);
0299 ACPI_PLD_SET_LID(&dword, pld_info->lid);
0300 ACPI_PLD_SET_PANEL(&dword, pld_info->panel);
0301 ACPI_PLD_SET_VERTICAL(&dword, pld_info->vertical_position);
0302 ACPI_PLD_SET_HORIZONTAL(&dword, pld_info->horizontal_position);
0303 ACPI_PLD_SET_SHAPE(&dword, pld_info->shape);
0304 ACPI_PLD_SET_ORIENTATION(&dword, pld_info->group_orientation);
0305 ACPI_PLD_SET_TOKEN(&dword, pld_info->group_token);
0306 ACPI_PLD_SET_POSITION(&dword, pld_info->group_position);
0307 ACPI_PLD_SET_BAY(&dword, pld_info->bay);
0308 ACPI_MOVE_32_TO_32(&buffer[2], &dword);
0309
0310
0311
0312 dword = 0;
0313 ACPI_PLD_SET_EJECTABLE(&dword, pld_info->ejectable);
0314 ACPI_PLD_SET_OSPM_EJECT(&dword, pld_info->ospm_eject_required);
0315 ACPI_PLD_SET_CABINET(&dword, pld_info->cabinet_number);
0316 ACPI_PLD_SET_CARD_CAGE(&dword, pld_info->card_cage_number);
0317 ACPI_PLD_SET_REFERENCE(&dword, pld_info->reference);
0318 ACPI_PLD_SET_ROTATION(&dword, pld_info->rotation);
0319 ACPI_PLD_SET_ORDER(&dword, pld_info->order);
0320 ACPI_MOVE_32_TO_32(&buffer[3], &dword);
0321
0322 if (pld_info->revision >= 2) {
0323
0324
0325
0326 dword = 0;
0327 ACPI_PLD_SET_VERT_OFFSET(&dword, pld_info->vertical_offset);
0328 ACPI_PLD_SET_HORIZ_OFFSET(&dword, pld_info->horizontal_offset);
0329 ACPI_MOVE_32_TO_32(&buffer[4], &dword);
0330 }
0331
0332 return (ACPI_CAST_PTR(u8, buffer));
0333 }
0334
0335
0336
0337
0338
0339
0340
0341
0342
0343
0344
0345
0346
0347 #define ACPI_PLD_OUTPUT "%20s : %-6X\n"
0348
0349 void acpi_db_dump_pld_buffer(union acpi_object *obj_desc)
0350 {
0351 union acpi_object *buffer_desc;
0352 struct acpi_pld_info *pld_info;
0353 u8 *new_buffer;
0354 acpi_status status;
0355
0356
0357
0358 if (obj_desc->type != ACPI_TYPE_PACKAGE) {
0359 return;
0360 }
0361
0362 buffer_desc = &obj_desc->package.elements[0];
0363 if (buffer_desc->type != ACPI_TYPE_BUFFER) {
0364 return;
0365 }
0366
0367
0368
0369 status = acpi_decode_pld_buffer(buffer_desc->buffer.pointer,
0370 buffer_desc->buffer.length, &pld_info);
0371 if (ACPI_FAILURE(status)) {
0372 return;
0373 }
0374
0375
0376
0377 new_buffer = acpi_db_encode_pld_buffer(pld_info);
0378 if (!new_buffer) {
0379 goto exit;
0380 }
0381
0382
0383
0384 if (memcmp(new_buffer, buffer_desc->buffer.pointer,
0385 buffer_desc->buffer.length)) {
0386 acpi_os_printf
0387 ("Converted _PLD buffer does not compare. New:\n");
0388
0389 acpi_ut_dump_buffer(new_buffer,
0390 buffer_desc->buffer.length, DB_BYTE_DISPLAY,
0391 0);
0392 }
0393
0394
0395
0396 acpi_os_printf(ACPI_PLD_OUTPUT, "PLD_Revision", pld_info->revision);
0397 acpi_os_printf(ACPI_PLD_OUTPUT, "PLD_IgnoreColor",
0398 pld_info->ignore_color);
0399 acpi_os_printf(ACPI_PLD_OUTPUT, "PLD_Red", pld_info->red);
0400 acpi_os_printf(ACPI_PLD_OUTPUT, "PLD_Green", pld_info->green);
0401 acpi_os_printf(ACPI_PLD_OUTPUT, "PLD_Blue", pld_info->blue);
0402
0403
0404
0405 acpi_os_printf(ACPI_PLD_OUTPUT, "PLD_Width", pld_info->width);
0406 acpi_os_printf(ACPI_PLD_OUTPUT, "PLD_Height", pld_info->height);
0407
0408
0409
0410 acpi_os_printf(ACPI_PLD_OUTPUT, "PLD_UserVisible",
0411 pld_info->user_visible);
0412 acpi_os_printf(ACPI_PLD_OUTPUT, "PLD_Dock", pld_info->dock);
0413 acpi_os_printf(ACPI_PLD_OUTPUT, "PLD_Lid", pld_info->lid);
0414 acpi_os_printf(ACPI_PLD_OUTPUT, "PLD_Panel", pld_info->panel);
0415 acpi_os_printf(ACPI_PLD_OUTPUT, "PLD_VerticalPosition",
0416 pld_info->vertical_position);
0417 acpi_os_printf(ACPI_PLD_OUTPUT, "PLD_HorizontalPosition",
0418 pld_info->horizontal_position);
0419 acpi_os_printf(ACPI_PLD_OUTPUT, "PLD_Shape", pld_info->shape);
0420 acpi_os_printf(ACPI_PLD_OUTPUT, "PLD_GroupOrientation",
0421 pld_info->group_orientation);
0422 acpi_os_printf(ACPI_PLD_OUTPUT, "PLD_GroupToken",
0423 pld_info->group_token);
0424 acpi_os_printf(ACPI_PLD_OUTPUT, "PLD_GroupPosition",
0425 pld_info->group_position);
0426 acpi_os_printf(ACPI_PLD_OUTPUT, "PLD_Bay", pld_info->bay);
0427
0428
0429
0430 acpi_os_printf(ACPI_PLD_OUTPUT, "PLD_Ejectable", pld_info->ejectable);
0431 acpi_os_printf(ACPI_PLD_OUTPUT, "PLD_EjectRequired",
0432 pld_info->ospm_eject_required);
0433 acpi_os_printf(ACPI_PLD_OUTPUT, "PLD_CabinetNumber",
0434 pld_info->cabinet_number);
0435 acpi_os_printf(ACPI_PLD_OUTPUT, "PLD_CardCageNumber",
0436 pld_info->card_cage_number);
0437 acpi_os_printf(ACPI_PLD_OUTPUT, "PLD_Reference", pld_info->reference);
0438 acpi_os_printf(ACPI_PLD_OUTPUT, "PLD_Rotation", pld_info->rotation);
0439 acpi_os_printf(ACPI_PLD_OUTPUT, "PLD_Order", pld_info->order);
0440
0441
0442
0443 if (buffer_desc->buffer.length > 16) {
0444 acpi_os_printf(ACPI_PLD_OUTPUT, "PLD_VerticalOffset",
0445 pld_info->vertical_offset);
0446 acpi_os_printf(ACPI_PLD_OUTPUT, "PLD_HorizontalOffset",
0447 pld_info->horizontal_offset);
0448 }
0449
0450 ACPI_FREE(new_buffer);
0451 exit:
0452 ACPI_FREE(pld_info);
0453 }