utexcep.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*******************************************************************************
  2. *
  3. * Module Name: utexcep - Exception code support
  4. *
  5. ******************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2015, Intel Corp.
  8. * All rights reserved.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions, and the following disclaimer,
  15. * without modification.
  16. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  17. * substantially similar to the "NO WARRANTY" disclaimer below
  18. * ("Disclaimer") and any redistribution must be conditioned upon
  19. * including a substantially similar Disclaimer requirement for further
  20. * binary redistribution.
  21. * 3. Neither the names of the above-listed copyright holders nor the names
  22. * of any contributors may be used to endorse or promote products derived
  23. * from this software without specific prior written permission.
  24. *
  25. * Alternatively, this software may be distributed under the terms of the
  26. * GNU General Public License ("GPL") version 2 as published by the Free
  27. * Software Foundation.
  28. *
  29. * NO WARRANTY
  30. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  31. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  32. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  33. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  34. * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  35. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  36. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  37. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  38. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  39. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  40. * POSSIBILITY OF SUCH DAMAGES.
  41. */
  42. #define EXPORT_ACPI_INTERFACES
  43. #define ACPI_DEFINE_EXCEPTION_TABLE
  44. #include <acpi/acpi.h>
  45. #include "accommon.h"
  46. #define _COMPONENT ACPI_UTILITIES
  47. ACPI_MODULE_NAME("utexcep")
  48. /*******************************************************************************
  49. *
  50. * FUNCTION: acpi_format_exception
  51. *
  52. * PARAMETERS: status - The acpi_status code to be formatted
  53. *
  54. * RETURN: A string containing the exception text. A valid pointer is
  55. * always returned.
  56. *
  57. * DESCRIPTION: This function translates an ACPI exception into an ASCII
  58. * string. Returns "unknown status" string for invalid codes.
  59. *
  60. ******************************************************************************/
  61. const char *acpi_format_exception(acpi_status status)
  62. {
  63. const struct acpi_exception_info *exception;
  64. ACPI_FUNCTION_ENTRY();
  65. exception = acpi_ut_validate_exception(status);
  66. if (!exception) {
  67. /* Exception code was not recognized */
  68. ACPI_ERROR((AE_INFO,
  69. "Unknown exception code: 0x%8.8X", status));
  70. return ("UNKNOWN_STATUS_CODE");
  71. }
  72. return (exception->name);
  73. }
  74. ACPI_EXPORT_SYMBOL(acpi_format_exception)
  75. /*******************************************************************************
  76. *
  77. * FUNCTION: acpi_ut_validate_exception
  78. *
  79. * PARAMETERS: status - The acpi_status code to be formatted
  80. *
  81. * RETURN: A string containing the exception text. NULL if exception is
  82. * not valid.
  83. *
  84. * DESCRIPTION: This function validates and translates an ACPI exception into
  85. * an ASCII string.
  86. *
  87. ******************************************************************************/
  88. const struct acpi_exception_info *acpi_ut_validate_exception(acpi_status status)
  89. {
  90. u32 sub_status;
  91. const struct acpi_exception_info *exception = NULL;
  92. ACPI_FUNCTION_ENTRY();
  93. /*
  94. * Status is composed of two parts, a "type" and an actual code
  95. */
  96. sub_status = (status & ~AE_CODE_MASK);
  97. switch (status & AE_CODE_MASK) {
  98. case AE_CODE_ENVIRONMENTAL:
  99. if (sub_status <= AE_CODE_ENV_MAX) {
  100. exception = &acpi_gbl_exception_names_env[sub_status];
  101. }
  102. break;
  103. case AE_CODE_PROGRAMMER:
  104. if (sub_status <= AE_CODE_PGM_MAX) {
  105. exception = &acpi_gbl_exception_names_pgm[sub_status];
  106. }
  107. break;
  108. case AE_CODE_ACPI_TABLES:
  109. if (sub_status <= AE_CODE_TBL_MAX) {
  110. exception = &acpi_gbl_exception_names_tbl[sub_status];
  111. }
  112. break;
  113. case AE_CODE_AML:
  114. if (sub_status <= AE_CODE_AML_MAX) {
  115. exception = &acpi_gbl_exception_names_aml[sub_status];
  116. }
  117. break;
  118. case AE_CODE_CONTROL:
  119. if (sub_status <= AE_CODE_CTRL_MAX) {
  120. exception = &acpi_gbl_exception_names_ctrl[sub_status];
  121. }
  122. break;
  123. default:
  124. break;
  125. }
  126. if (!exception || !exception->name) {
  127. return (NULL);
  128. }
  129. return (exception);
  130. }