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