utexcep.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
  2. /*******************************************************************************
  3. *
  4. * Module Name: utexcep - Exception code support
  5. *
  6. ******************************************************************************/
  7. #define EXPORT_ACPI_INTERFACES
  8. #define ACPI_DEFINE_EXCEPTION_TABLE
  9. #include <acpi/acpi.h>
  10. #include "accommon.h"
  11. #define _COMPONENT ACPI_UTILITIES
  12. ACPI_MODULE_NAME("utexcep")
  13. /*******************************************************************************
  14. *
  15. * FUNCTION: acpi_format_exception
  16. *
  17. * PARAMETERS: status - The acpi_status code to be formatted
  18. *
  19. * RETURN: A string containing the exception text. A valid pointer is
  20. * always returned.
  21. *
  22. * DESCRIPTION: This function translates an ACPI exception into an ASCII
  23. * string. Returns "unknown status" string for invalid codes.
  24. *
  25. ******************************************************************************/
  26. const char *acpi_format_exception(acpi_status status)
  27. {
  28. const struct acpi_exception_info *exception;
  29. ACPI_FUNCTION_ENTRY();
  30. exception = acpi_ut_validate_exception(status);
  31. if (!exception) {
  32. /* Exception code was not recognized */
  33. ACPI_ERROR((AE_INFO,
  34. "Unknown exception code: 0x%8.8X", status));
  35. return ("UNKNOWN_STATUS_CODE");
  36. }
  37. return (exception->name);
  38. }
  39. ACPI_EXPORT_SYMBOL(acpi_format_exception)
  40. /*******************************************************************************
  41. *
  42. * FUNCTION: acpi_ut_validate_exception
  43. *
  44. * PARAMETERS: status - The acpi_status code to be formatted
  45. *
  46. * RETURN: A string containing the exception text. NULL if exception is
  47. * not valid.
  48. *
  49. * DESCRIPTION: This function validates and translates an ACPI exception into
  50. * an ASCII string.
  51. *
  52. ******************************************************************************/
  53. const struct acpi_exception_info *acpi_ut_validate_exception(acpi_status status)
  54. {
  55. u32 sub_status;
  56. const struct acpi_exception_info *exception = NULL;
  57. ACPI_FUNCTION_ENTRY();
  58. /*
  59. * Status is composed of two parts, a "type" and an actual code
  60. */
  61. sub_status = (status & ~AE_CODE_MASK);
  62. switch (status & AE_CODE_MASK) {
  63. case AE_CODE_ENVIRONMENTAL:
  64. if (sub_status <= AE_CODE_ENV_MAX) {
  65. exception = &acpi_gbl_exception_names_env[sub_status];
  66. }
  67. break;
  68. case AE_CODE_PROGRAMMER:
  69. if (sub_status <= AE_CODE_PGM_MAX) {
  70. exception = &acpi_gbl_exception_names_pgm[sub_status];
  71. }
  72. break;
  73. case AE_CODE_ACPI_TABLES:
  74. if (sub_status <= AE_CODE_TBL_MAX) {
  75. exception = &acpi_gbl_exception_names_tbl[sub_status];
  76. }
  77. break;
  78. case AE_CODE_AML:
  79. if (sub_status <= AE_CODE_AML_MAX) {
  80. exception = &acpi_gbl_exception_names_aml[sub_status];
  81. }
  82. break;
  83. case AE_CODE_CONTROL:
  84. if (sub_status <= AE_CODE_CTRL_MAX) {
  85. exception = &acpi_gbl_exception_names_ctrl[sub_status];
  86. }
  87. break;
  88. default:
  89. break;
  90. }
  91. if (!exception || !exception->name) {
  92. return (NULL);
  93. }
  94. return (exception);
  95. }