Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
0002 /*******************************************************************************
0003  *
0004  * Module Name: utexcep - Exception code support
0005  *
0006  ******************************************************************************/
0007 
0008 #define EXPORT_ACPI_INTERFACES
0009 
0010 #define ACPI_DEFINE_EXCEPTION_TABLE
0011 #include <acpi/acpi.h>
0012 #include "accommon.h"
0013 
0014 #define _COMPONENT          ACPI_UTILITIES
0015 ACPI_MODULE_NAME("utexcep")
0016 
0017 /*******************************************************************************
0018  *
0019  * FUNCTION:    acpi_format_exception
0020  *
0021  * PARAMETERS:  status              - The acpi_status code to be formatted
0022  *
0023  * RETURN:      A string containing the exception text. A valid pointer is
0024  *              always returned.
0025  *
0026  * DESCRIPTION: This function translates an ACPI exception into an ASCII
0027  *              string. Returns "unknown status" string for invalid codes.
0028  *
0029  ******************************************************************************/
0030 const char *acpi_format_exception(acpi_status status)
0031 {
0032     const struct acpi_exception_info *exception;
0033 
0034     ACPI_FUNCTION_ENTRY();
0035 
0036     exception = acpi_ut_validate_exception(status);
0037     if (!exception) {
0038 
0039         /* Exception code was not recognized */
0040 
0041         ACPI_ERROR((AE_INFO,
0042                 "Unknown exception code: 0x%8.8X", status));
0043 
0044         return ("UNKNOWN_STATUS_CODE");
0045     }
0046 
0047     return (exception->name);
0048 }
0049 
0050 ACPI_EXPORT_SYMBOL(acpi_format_exception)
0051 
0052 /*******************************************************************************
0053  *
0054  * FUNCTION:    acpi_ut_validate_exception
0055  *
0056  * PARAMETERS:  status              - The acpi_status code to be formatted
0057  *
0058  * RETURN:      A string containing the exception text. NULL if exception is
0059  *              not valid.
0060  *
0061  * DESCRIPTION: This function validates and translates an ACPI exception into
0062  *              an ASCII string.
0063  *
0064  ******************************************************************************/
0065 const struct acpi_exception_info *acpi_ut_validate_exception(acpi_status status)
0066 {
0067     u32 sub_status;
0068     const struct acpi_exception_info *exception = NULL;
0069 
0070     ACPI_FUNCTION_ENTRY();
0071 
0072     /*
0073      * Status is composed of two parts, a "type" and an actual code
0074      */
0075     sub_status = (status & ~AE_CODE_MASK);
0076 
0077     switch (status & AE_CODE_MASK) {
0078     case AE_CODE_ENVIRONMENTAL:
0079 
0080         if (sub_status <= AE_CODE_ENV_MAX) {
0081             exception = &acpi_gbl_exception_names_env[sub_status];
0082         }
0083         break;
0084 
0085     case AE_CODE_PROGRAMMER:
0086 
0087         if (sub_status <= AE_CODE_PGM_MAX) {
0088             exception = &acpi_gbl_exception_names_pgm[sub_status];
0089         }
0090         break;
0091 
0092     case AE_CODE_ACPI_TABLES:
0093 
0094         if (sub_status <= AE_CODE_TBL_MAX) {
0095             exception = &acpi_gbl_exception_names_tbl[sub_status];
0096         }
0097         break;
0098 
0099     case AE_CODE_AML:
0100 
0101         if (sub_status <= AE_CODE_AML_MAX) {
0102             exception = &acpi_gbl_exception_names_aml[sub_status];
0103         }
0104         break;
0105 
0106     case AE_CODE_CONTROL:
0107 
0108         if (sub_status <= AE_CODE_CTRL_MAX) {
0109             exception = &acpi_gbl_exception_names_ctrl[sub_status];
0110         }
0111         break;
0112 
0113     default:
0114 
0115         break;
0116     }
0117 
0118     if (!exception || !exception->name) {
0119         return (NULL);
0120     }
0121 
0122     return (exception);
0123 }