Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
0002 /******************************************************************************
0003  *
0004  * Module Name: utdecode - Utility decoding routines (value-to-string)
0005  *
0006  * Copyright (C) 2000 - 2022, Intel Corp.
0007  *
0008  *****************************************************************************/
0009 
0010 #include <acpi/acpi.h>
0011 #include "accommon.h"
0012 #include "acnamesp.h"
0013 #include "amlcode.h"
0014 
0015 #define _COMPONENT          ACPI_UTILITIES
0016 ACPI_MODULE_NAME("utdecode")
0017 
0018 /*
0019  * Properties of the ACPI Object Types, both internal and external.
0020  * The table is indexed by values of acpi_object_type
0021  */
0022 const u8 acpi_gbl_ns_properties[ACPI_NUM_NS_TYPES] = {
0023     ACPI_NS_NORMAL,     /* 00 Any              */
0024     ACPI_NS_NORMAL,     /* 01 Number           */
0025     ACPI_NS_NORMAL,     /* 02 String           */
0026     ACPI_NS_NORMAL,     /* 03 Buffer           */
0027     ACPI_NS_NORMAL,     /* 04 Package          */
0028     ACPI_NS_NORMAL,     /* 05 field_unit       */
0029     ACPI_NS_NEWSCOPE,   /* 06 Device           */
0030     ACPI_NS_NORMAL,     /* 07 Event            */
0031     ACPI_NS_NEWSCOPE,   /* 08 Method           */
0032     ACPI_NS_NORMAL,     /* 09 Mutex            */
0033     ACPI_NS_NORMAL,     /* 10 Region           */
0034     ACPI_NS_NEWSCOPE,   /* 11 Power            */
0035     ACPI_NS_NEWSCOPE,   /* 12 Processor        */
0036     ACPI_NS_NEWSCOPE,   /* 13 Thermal          */
0037     ACPI_NS_NORMAL,     /* 14 buffer_field     */
0038     ACPI_NS_NORMAL,     /* 15 ddb_handle       */
0039     ACPI_NS_NORMAL,     /* 16 Debug Object     */
0040     ACPI_NS_NORMAL,     /* 17 def_field        */
0041     ACPI_NS_NORMAL,     /* 18 bank_field       */
0042     ACPI_NS_NORMAL,     /* 19 index_field      */
0043     ACPI_NS_NORMAL,     /* 20 Reference        */
0044     ACPI_NS_NORMAL,     /* 21 Alias            */
0045     ACPI_NS_NORMAL,     /* 22 method_alias     */
0046     ACPI_NS_NORMAL,     /* 23 Notify           */
0047     ACPI_NS_NORMAL,     /* 24 Address Handler  */
0048     ACPI_NS_NEWSCOPE | ACPI_NS_LOCAL,   /* 25 Resource Desc    */
0049     ACPI_NS_NEWSCOPE | ACPI_NS_LOCAL,   /* 26 Resource Field   */
0050     ACPI_NS_NEWSCOPE,   /* 27 Scope            */
0051     ACPI_NS_NORMAL,     /* 28 Extra            */
0052     ACPI_NS_NORMAL,     /* 29 Data             */
0053     ACPI_NS_NORMAL      /* 30 Invalid          */
0054 };
0055 
0056 /*******************************************************************************
0057  *
0058  * FUNCTION:    acpi_ut_get_region_name
0059  *
0060  * PARAMETERS:  Space ID            - ID for the region
0061  *
0062  * RETURN:      Decoded region space_id name
0063  *
0064  * DESCRIPTION: Translate a Space ID into a name string (Debug only)
0065  *
0066  ******************************************************************************/
0067 
0068 /* Region type decoding */
0069 
0070 const char *acpi_gbl_region_types[ACPI_NUM_PREDEFINED_REGIONS] = {
0071     "SystemMemory",     /* 0x00 */
0072     "SystemIO",     /* 0x01 */
0073     "PCI_Config",       /* 0x02 */
0074     "EmbeddedControl",  /* 0x03 */
0075     "SMBus",        /* 0x04 */
0076     "SystemCMOS",       /* 0x05 */
0077     "PCIBARTarget",     /* 0x06 */
0078     "IPMI",         /* 0x07 */
0079     "GeneralPurposeIo", /* 0x08 */
0080     "GenericSerialBus", /* 0x09 */
0081     "PCC",          /* 0x0A */
0082     "PlatformRtMechanism"   /* 0x0B */
0083 };
0084 
0085 const char *acpi_ut_get_region_name(u8 space_id)
0086 {
0087 
0088     if (space_id >= ACPI_USER_REGION_BEGIN) {
0089         return ("UserDefinedRegion");
0090     } else if (space_id == ACPI_ADR_SPACE_DATA_TABLE) {
0091         return ("DataTable");
0092     } else if (space_id == ACPI_ADR_SPACE_FIXED_HARDWARE) {
0093         return ("FunctionalFixedHW");
0094     } else if (space_id >= ACPI_NUM_PREDEFINED_REGIONS) {
0095         return ("InvalidSpaceId");
0096     }
0097 
0098     return (acpi_gbl_region_types[space_id]);
0099 }
0100 
0101 /*******************************************************************************
0102  *
0103  * FUNCTION:    acpi_ut_get_event_name
0104  *
0105  * PARAMETERS:  event_id            - Fixed event ID
0106  *
0107  * RETURN:      Decoded event ID name
0108  *
0109  * DESCRIPTION: Translate a Event ID into a name string (Debug only)
0110  *
0111  ******************************************************************************/
0112 
0113 /* Event type decoding */
0114 
0115 static const char *acpi_gbl_event_types[ACPI_NUM_FIXED_EVENTS] = {
0116     "PM_Timer",
0117     "GlobalLock",
0118     "PowerButton",
0119     "SleepButton",
0120     "RealTimeClock",
0121 };
0122 
0123 const char *acpi_ut_get_event_name(u32 event_id)
0124 {
0125 
0126     if (event_id > ACPI_EVENT_MAX) {
0127         return ("InvalidEventID");
0128     }
0129 
0130     return (acpi_gbl_event_types[event_id]);
0131 }
0132 
0133 /*******************************************************************************
0134  *
0135  * FUNCTION:    acpi_ut_get_type_name
0136  *
0137  * PARAMETERS:  type                - An ACPI object type
0138  *
0139  * RETURN:      Decoded ACPI object type name
0140  *
0141  * DESCRIPTION: Translate a Type ID into a name string (Debug only)
0142  *
0143  ******************************************************************************/
0144 
0145 /*
0146  * Elements of acpi_gbl_ns_type_names below must match
0147  * one-to-one with values of acpi_object_type
0148  *
0149  * The type ACPI_TYPE_ANY (Untyped) is used as a "don't care" when searching;
0150  * when stored in a table it really means that we have thus far seen no
0151  * evidence to indicate what type is actually going to be stored for this
0152  & entry.
0153  */
0154 static const char acpi_gbl_bad_type[] = "UNDEFINED";
0155 
0156 /* Printable names of the ACPI object types */
0157 
0158 static const char *acpi_gbl_ns_type_names[] = {
0159     /* 00 */ "Untyped",
0160     /* 01 */ "Integer",
0161     /* 02 */ "String",
0162     /* 03 */ "Buffer",
0163     /* 04 */ "Package",
0164     /* 05 */ "FieldUnit",
0165     /* 06 */ "Device",
0166     /* 07 */ "Event",
0167     /* 08 */ "Method",
0168     /* 09 */ "Mutex",
0169     /* 10 */ "Region",
0170     /* 11 */ "Power",
0171     /* 12 */ "Processor",
0172     /* 13 */ "Thermal",
0173     /* 14 */ "BufferField",
0174     /* 15 */ "DdbHandle",
0175     /* 16 */ "DebugObject",
0176     /* 17 */ "RegionField",
0177     /* 18 */ "BankField",
0178     /* 19 */ "IndexField",
0179     /* 20 */ "Reference",
0180     /* 21 */ "Alias",
0181     /* 22 */ "MethodAlias",
0182     /* 23 */ "Notify",
0183     /* 24 */ "AddrHandler",
0184     /* 25 */ "ResourceDesc",
0185     /* 26 */ "ResourceFld",
0186     /* 27 */ "Scope",
0187     /* 28 */ "Extra",
0188     /* 29 */ "Data",
0189     /* 30 */ "Invalid"
0190 };
0191 
0192 const char *acpi_ut_get_type_name(acpi_object_type type)
0193 {
0194 
0195     if (type > ACPI_TYPE_INVALID) {
0196         return (acpi_gbl_bad_type);
0197     }
0198 
0199     return (acpi_gbl_ns_type_names[type]);
0200 }
0201 
0202 const char *acpi_ut_get_object_type_name(union acpi_operand_object *obj_desc)
0203 {
0204     ACPI_FUNCTION_TRACE(ut_get_object_type_name);
0205 
0206     if (!obj_desc) {
0207         ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Null Object Descriptor\n"));
0208         return_STR("[NULL Object Descriptor]");
0209     }
0210 
0211     /* These descriptor types share a common area */
0212 
0213     if ((ACPI_GET_DESCRIPTOR_TYPE(obj_desc) != ACPI_DESC_TYPE_OPERAND) &&
0214         (ACPI_GET_DESCRIPTOR_TYPE(obj_desc) != ACPI_DESC_TYPE_NAMED)) {
0215         ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
0216                   "Invalid object descriptor type: 0x%2.2X [%s] (%p)\n",
0217                   ACPI_GET_DESCRIPTOR_TYPE(obj_desc),
0218                   acpi_ut_get_descriptor_name(obj_desc),
0219                   obj_desc));
0220 
0221         return_STR("Invalid object");
0222     }
0223 
0224     return_STR(acpi_ut_get_type_name(obj_desc->common.type));
0225 }
0226 
0227 /*******************************************************************************
0228  *
0229  * FUNCTION:    acpi_ut_get_node_name
0230  *
0231  * PARAMETERS:  object               - A namespace node
0232  *
0233  * RETURN:      ASCII name of the node
0234  *
0235  * DESCRIPTION: Validate the node and return the node's ACPI name.
0236  *
0237  ******************************************************************************/
0238 
0239 const char *acpi_ut_get_node_name(void *object)
0240 {
0241     struct acpi_namespace_node *node = (struct acpi_namespace_node *)object;
0242 
0243     /* Must return a string of exactly 4 characters == ACPI_NAMESEG_SIZE */
0244 
0245     if (!object) {
0246         return ("NULL");
0247     }
0248 
0249     /* Check for Root node */
0250 
0251     if ((object == ACPI_ROOT_OBJECT) || (object == acpi_gbl_root_node)) {
0252         return ("\"\\\" ");
0253     }
0254 
0255     /* Descriptor must be a namespace node */
0256 
0257     if (ACPI_GET_DESCRIPTOR_TYPE(node) != ACPI_DESC_TYPE_NAMED) {
0258         return ("####");
0259     }
0260 
0261     /*
0262      * Ensure name is valid. The name was validated/repaired when the node
0263      * was created, but make sure it has not been corrupted.
0264      */
0265     acpi_ut_repair_name(node->name.ascii);
0266 
0267     /* Return the name */
0268 
0269     return (node->name.ascii);
0270 }
0271 
0272 /*******************************************************************************
0273  *
0274  * FUNCTION:    acpi_ut_get_descriptor_name
0275  *
0276  * PARAMETERS:  object               - An ACPI object
0277  *
0278  * RETURN:      Decoded name of the descriptor type
0279  *
0280  * DESCRIPTION: Validate object and return the descriptor type
0281  *
0282  ******************************************************************************/
0283 
0284 /* Printable names of object descriptor types */
0285 
0286 static const char *acpi_gbl_desc_type_names[] = {
0287     /* 00 */ "Not a Descriptor",
0288     /* 01 */ "Cached Object",
0289     /* 02 */ "State-Generic",
0290     /* 03 */ "State-Update",
0291     /* 04 */ "State-Package",
0292     /* 05 */ "State-Control",
0293     /* 06 */ "State-RootParseScope",
0294     /* 07 */ "State-ParseScope",
0295     /* 08 */ "State-WalkScope",
0296     /* 09 */ "State-Result",
0297     /* 10 */ "State-Notify",
0298     /* 11 */ "State-Thread",
0299     /* 12 */ "Tree Walk State",
0300     /* 13 */ "Parse Tree Op",
0301     /* 14 */ "Operand Object",
0302     /* 15 */ "Namespace Node"
0303 };
0304 
0305 const char *acpi_ut_get_descriptor_name(void *object)
0306 {
0307 
0308     if (!object) {
0309         return ("NULL OBJECT");
0310     }
0311 
0312     if (ACPI_GET_DESCRIPTOR_TYPE(object) > ACPI_DESC_TYPE_MAX) {
0313         return ("Not a Descriptor");
0314     }
0315 
0316     return (acpi_gbl_desc_type_names[ACPI_GET_DESCRIPTOR_TYPE(object)]);
0317 }
0318 
0319 /*******************************************************************************
0320  *
0321  * FUNCTION:    acpi_ut_get_reference_name
0322  *
0323  * PARAMETERS:  object               - An ACPI reference object
0324  *
0325  * RETURN:      Decoded name of the type of reference
0326  *
0327  * DESCRIPTION: Decode a reference object sub-type to a string.
0328  *
0329  ******************************************************************************/
0330 
0331 /* Printable names of reference object sub-types */
0332 
0333 static const char *acpi_gbl_ref_class_names[] = {
0334     /* 00 */ "Local",
0335     /* 01 */ "Argument",
0336     /* 02 */ "RefOf",
0337     /* 03 */ "Index",
0338     /* 04 */ "DdbHandle",
0339     /* 05 */ "Named Object",
0340     /* 06 */ "Debug"
0341 };
0342 
0343 const char *acpi_ut_get_reference_name(union acpi_operand_object *object)
0344 {
0345 
0346     if (!object) {
0347         return ("NULL Object");
0348     }
0349 
0350     if (ACPI_GET_DESCRIPTOR_TYPE(object) != ACPI_DESC_TYPE_OPERAND) {
0351         return ("Not an Operand object");
0352     }
0353 
0354     if (object->common.type != ACPI_TYPE_LOCAL_REFERENCE) {
0355         return ("Not a Reference object");
0356     }
0357 
0358     if (object->reference.class > ACPI_REFCLASS_MAX) {
0359         return ("Unknown Reference class");
0360     }
0361 
0362     return (acpi_gbl_ref_class_names[object->reference.class]);
0363 }
0364 
0365 /*******************************************************************************
0366  *
0367  * FUNCTION:    acpi_ut_get_mutex_name
0368  *
0369  * PARAMETERS:  mutex_id        - The predefined ID for this mutex.
0370  *
0371  * RETURN:      Decoded name of the internal mutex
0372  *
0373  * DESCRIPTION: Translate a mutex ID into a name string (Debug only)
0374  *
0375  ******************************************************************************/
0376 
0377 /* Names for internal mutex objects, used for debug output */
0378 
0379 static const char *acpi_gbl_mutex_names[ACPI_NUM_MUTEX] = {
0380     "ACPI_MTX_Interpreter",
0381     "ACPI_MTX_Namespace",
0382     "ACPI_MTX_Tables",
0383     "ACPI_MTX_Events",
0384     "ACPI_MTX_Caches",
0385     "ACPI_MTX_Memory",
0386 };
0387 
0388 const char *acpi_ut_get_mutex_name(u32 mutex_id)
0389 {
0390 
0391     if (mutex_id > ACPI_MAX_MUTEX) {
0392         return ("Invalid Mutex ID");
0393     }
0394 
0395     return (acpi_gbl_mutex_names[mutex_id]);
0396 }
0397 
0398 #if defined(ACPI_DEBUG_OUTPUT) || defined(ACPI_DEBUGGER)
0399 
0400 /*
0401  * Strings and procedures used for debug only
0402  */
0403 
0404 /*******************************************************************************
0405  *
0406  * FUNCTION:    acpi_ut_get_notify_name
0407  *
0408  * PARAMETERS:  notify_value    - Value from the Notify() request
0409  *
0410  * RETURN:      Decoded name for the notify value
0411  *
0412  * DESCRIPTION: Translate a Notify Value to a notify namestring.
0413  *
0414  ******************************************************************************/
0415 
0416 /* Names for Notify() values, used for debug output */
0417 
0418 static const char *acpi_gbl_generic_notify[ACPI_GENERIC_NOTIFY_MAX + 1] = {
0419     /* 00 */ "Bus Check",
0420     /* 01 */ "Device Check",
0421     /* 02 */ "Device Wake",
0422     /* 03 */ "Eject Request",
0423     /* 04 */ "Device Check Light",
0424     /* 05 */ "Frequency Mismatch",
0425     /* 06 */ "Bus Mode Mismatch",
0426     /* 07 */ "Power Fault",
0427     /* 08 */ "Capabilities Check",
0428     /* 09 */ "Device PLD Check",
0429     /* 0A */ "Reserved",
0430     /* 0B */ "System Locality Update",
0431                                 /* 0C */ "Reserved (was previously Shutdown Request)",
0432                                 /* Reserved in ACPI 6.0 */
0433     /* 0D */ "System Resource Affinity Update",
0434                                 /* 0E */ "Heterogeneous Memory Attributes Update",
0435                                 /* ACPI 6.2 */
0436                         /* 0F */ "Error Disconnect Recover"
0437                         /* ACPI 6.3 */
0438 };
0439 
0440 static const char *acpi_gbl_device_notify[5] = {
0441     /* 80 */ "Status Change",
0442     /* 81 */ "Information Change",
0443     /* 82 */ "Device-Specific Change",
0444     /* 83 */ "Device-Specific Change",
0445     /* 84 */ "Reserved"
0446 };
0447 
0448 static const char *acpi_gbl_processor_notify[5] = {
0449     /* 80 */ "Performance Capability Change",
0450     /* 81 */ "C-State Change",
0451     /* 82 */ "Throttling Capability Change",
0452     /* 83 */ "Guaranteed Change",
0453     /* 84 */ "Minimum Excursion"
0454 };
0455 
0456 static const char *acpi_gbl_thermal_notify[5] = {
0457     /* 80 */ "Thermal Status Change",
0458     /* 81 */ "Thermal Trip Point Change",
0459     /* 82 */ "Thermal Device List Change",
0460     /* 83 */ "Thermal Relationship Change",
0461     /* 84 */ "Reserved"
0462 };
0463 
0464 const char *acpi_ut_get_notify_name(u32 notify_value, acpi_object_type type)
0465 {
0466 
0467     /* 00 - 0F are "common to all object types" (from ACPI Spec) */
0468 
0469     if (notify_value <= ACPI_GENERIC_NOTIFY_MAX) {
0470         return (acpi_gbl_generic_notify[notify_value]);
0471     }
0472 
0473     /* 10 - 7F are reserved */
0474 
0475     if (notify_value <= ACPI_MAX_SYS_NOTIFY) {
0476         return ("Reserved");
0477     }
0478 
0479     /* 80 - 84 are per-object-type */
0480 
0481     if (notify_value <= ACPI_SPECIFIC_NOTIFY_MAX) {
0482         switch (type) {
0483         case ACPI_TYPE_ANY:
0484         case ACPI_TYPE_DEVICE:
0485             return (acpi_gbl_device_notify[notify_value - 0x80]);
0486 
0487         case ACPI_TYPE_PROCESSOR:
0488             return (acpi_gbl_processor_notify[notify_value - 0x80]);
0489 
0490         case ACPI_TYPE_THERMAL:
0491             return (acpi_gbl_thermal_notify[notify_value - 0x80]);
0492 
0493         default:
0494             return ("Target object type does not support notifies");
0495         }
0496     }
0497 
0498     /* 84 - BF are device-specific */
0499 
0500     if (notify_value <= ACPI_MAX_DEVICE_SPECIFIC_NOTIFY) {
0501         return ("Device-Specific");
0502     }
0503 
0504     /* C0 and above are hardware-specific */
0505 
0506     return ("Hardware-Specific");
0507 }
0508 
0509 /*******************************************************************************
0510  *
0511  * FUNCTION:    acpi_ut_get_argument_type_name
0512  *
0513  * PARAMETERS:  arg_type            - an ARGP_* parser argument type
0514  *
0515  * RETURN:      Decoded ARGP_* type
0516  *
0517  * DESCRIPTION: Decode an ARGP_* parser type, as defined in the amlcode.h file,
0518  *              and used in the acopcode.h file. For example, ARGP_TERMARG.
0519  *              Used for debug only.
0520  *
0521  ******************************************************************************/
0522 
0523 static const char *acpi_gbl_argument_type[20] = {
0524     /* 00 */ "Unknown ARGP",
0525     /* 01 */ "ByteData",
0526     /* 02 */ "ByteList",
0527     /* 03 */ "CharList",
0528     /* 04 */ "DataObject",
0529     /* 05 */ "DataObjectList",
0530     /* 06 */ "DWordData",
0531     /* 07 */ "FieldList",
0532     /* 08 */ "Name",
0533     /* 09 */ "NameString",
0534     /* 0A */ "ObjectList",
0535     /* 0B */ "PackageLength",
0536     /* 0C */ "SuperName",
0537     /* 0D */ "Target",
0538     /* 0E */ "TermArg",
0539     /* 0F */ "TermList",
0540     /* 10 */ "WordData",
0541     /* 11 */ "QWordData",
0542     /* 12 */ "SimpleName",
0543     /* 13 */ "NameOrRef"
0544 };
0545 
0546 const char *acpi_ut_get_argument_type_name(u32 arg_type)
0547 {
0548 
0549     if (arg_type > ARGP_MAX) {
0550         return ("Unknown ARGP");
0551     }
0552 
0553     return (acpi_gbl_argument_type[arg_type]);
0554 }
0555 
0556 #endif
0557 
0558 /*******************************************************************************
0559  *
0560  * FUNCTION:    acpi_ut_valid_object_type
0561  *
0562  * PARAMETERS:  type            - Object type to be validated
0563  *
0564  * RETURN:      TRUE if valid object type, FALSE otherwise
0565  *
0566  * DESCRIPTION: Validate an object type
0567  *
0568  ******************************************************************************/
0569 
0570 u8 acpi_ut_valid_object_type(acpi_object_type type)
0571 {
0572 
0573     if (type > ACPI_TYPE_LOCAL_MAX) {
0574 
0575         /* Note: Assumes all TYPEs are contiguous (external/local) */
0576 
0577         return (FALSE);
0578     }
0579 
0580     return (TRUE);
0581 }