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