1 /****************************************************************************** 2 * 3 * Module Name: ahmain - Main module for the acpi help utility 4 * 5 *****************************************************************************/ 6 7 /* 8 * Copyright (C) 2000 - 2014, Intel Corp. 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 44 #include "acpihelp.h" 45 46 47 /* Local prototypes */ 48 49 static void 50 AhDisplayUsage ( 51 void); 52 53 #define AH_UTILITY_NAME "ACPI Help Utility" 54 #define AH_SUPPORTED_OPTIONS "aehikmopsv" 55 56 57 /****************************************************************************** 58 * 59 * FUNCTION: AhDisplayUsage 60 * 61 * DESCRIPTION: Usage message 62 * 63 ******************************************************************************/ 64 65 static void 66 AhDisplayUsage ( 67 void) 68 { 69 70 ACPI_USAGE_HEADER ("acpihelp <options> [Name/Prefix | HexValue]"); 71 ACPI_OPTION ("-h", "Display help"); 72 ACPI_OPTION ("-v", "Display version information"); 73 74 printf ("\nAML (ACPI Machine Language) Names and Encodings:\n"); 75 ACPI_OPTION ("-a [Name/Prefix]", "Find/Display both ASL operator and AML opcode name(s)"); 76 ACPI_OPTION ("-m [Name/Prefix]", "Find/Display AML opcode name(s)"); 77 78 printf ("\nASL (ACPI Source Language) Names and Symbols:\n"); 79 ACPI_OPTION ("-k [Name/Prefix]", "Find/Display ASL non-operator keyword(s)"); 80 ACPI_OPTION ("-p [Name/Prefix]", "Find/Display ASL predefined method name(s)"); 81 ACPI_OPTION ("-s [Name/Prefix]", "Find/Display ASL operator name(s)"); 82 83 printf ("\nOther ACPI Names:\n"); 84 ACPI_OPTION ("-i [Name/Prefix]", "Find/Display ACPI/PNP Hardware ID(s)"); 85 86 printf ("\nACPI Values:\n"); 87 ACPI_OPTION ("-e [HexValue]", "Decode ACPICA exception code"); 88 ACPI_OPTION ("-o [HexValue]", "Decode hex AML opcode"); 89 90 printf ("\nName/Prefix or HexValue not specified means \"Display All\"\n"); 91 printf ("\nDefault search with valid Name/Prefix and no options:\n"); 92 printf (" Find ASL/AML operator names - if NamePrefix does not start with underscore\n"); 93 printf (" Find ASL predefined method names - if NamePrefix starts with underscore\n"); 94 } 95 96 97 /****************************************************************************** 98 * 99 * FUNCTION: main 100 * 101 * DESCRIPTION: C main function for AcpiHelp utility. 102 * 103 ******************************************************************************/ 104 105 int ACPI_SYSTEM_XFACE 106 main ( 107 int argc, 108 char *argv[]) 109 { 110 char *Name; 111 UINT32 DecodeType; 112 int j; 113 114 115 ACPI_DEBUG_INITIALIZE (); /* For debug version only */ 116 printf (ACPI_COMMON_SIGNON (AH_UTILITY_NAME)); 117 DecodeType = AH_DECODE_DEFAULT; 118 119 if (argc < 2) 120 { 121 AhDisplayUsage (); 122 return (0); 123 } 124 125 /* Command line options */ 126 127 while ((j = AcpiGetopt (argc, argv, AH_SUPPORTED_OPTIONS)) != EOF) switch (j) 128 { 129 case 'a': 130 131 DecodeType = AH_DECODE_ASL_AML; 132 break; 133 134 case 'e': 135 136 DecodeType = AH_DECODE_EXCEPTION; 137 break; 138 139 case 'i': 140 141 DecodeType = AH_DISPLAY_DEVICE_IDS; 142 break; 143 144 case 'k': 145 146 DecodeType = AH_DECODE_ASL_KEYWORD; 147 break; 148 149 case 'm': 150 151 DecodeType = AH_DECODE_AML; 152 break; 153 154 case 'o': 155 156 DecodeType = AH_DECODE_AML_OPCODE; 157 break; 158 159 case 'p': 160 161 DecodeType = AH_DECODE_PREDEFINED_NAME; 162 break; 163 164 case 's': 165 166 DecodeType = AH_DECODE_ASL; 167 break; 168 169 case 'v': /* -v: (Version): signon already emitted, just exit */ 170 171 return (0); 172 173 case 'h': 174 default: 175 176 AhDisplayUsage (); 177 return (-1); 178 } 179 180 /* Missing (null) name means "display all" */ 181 182 Name = argv[AcpiGbl_Optind]; 183 184 switch (DecodeType) 185 { 186 case AH_DECODE_ASL_AML: 187 188 AhFindAslAndAmlOperators (Name); 189 break; 190 191 case AH_DECODE_AML: 192 193 AhFindAmlOpcode (Name); 194 break; 195 196 case AH_DECODE_AML_OPCODE: 197 198 AhDecodeAmlOpcode (Name); 199 break; 200 201 case AH_DECODE_PREDEFINED_NAME: 202 203 AhFindPredefinedNames (Name); 204 break; 205 206 case AH_DECODE_ASL: 207 208 AhFindAslOperators (Name); 209 break; 210 211 case AH_DECODE_ASL_KEYWORD: 212 213 AhFindAslKeywords (Name); 214 break; 215 216 case AH_DISPLAY_DEVICE_IDS: 217 218 AhDisplayDeviceIds (Name); 219 break; 220 221 case AH_DECODE_EXCEPTION: 222 223 AhDecodeException (Name); 224 break; 225 226 default: 227 228 if (!Name) 229 { 230 AhFindAslOperators (Name); 231 break; 232 } 233 234 if (*Name == '_') 235 { 236 AhFindPredefinedNames (Name); 237 } 238 else 239 { 240 AhFindAslAndAmlOperators (Name); 241 } 242 break; 243 } 244 245 return (0); 246 } 247 248 249 /******************************************************************************* 250 * 251 * FUNCTION: AhStrupr (strupr) 252 * 253 * PARAMETERS: SrcString - The source string to convert 254 * 255 * RETURN: None 256 * 257 * DESCRIPTION: Convert string to uppercase 258 * 259 * NOTE: This is not a POSIX function, so it appears here, not in utclib.c 260 * 261 ******************************************************************************/ 262 263 void 264 AhStrupr ( 265 char *SrcString) 266 { 267 char *String; 268 269 270 if (!SrcString) 271 { 272 return; 273 } 274 275 /* Walk entire string, uppercasing the letters */ 276 277 for (String = SrcString; *String; String++) 278 { 279 *String = (char) toupper ((int) *String); 280 } 281 282 return; 283 } 284