1*4882a593Smuzhiyun // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
2*4882a593Smuzhiyun /******************************************************************************
3*4882a593Smuzhiyun *
4*4882a593Smuzhiyun * Module Name: psopinfo - AML opcode information functions and dispatch tables
5*4882a593Smuzhiyun *
6*4882a593Smuzhiyun * Copyright (C) 2000 - 2020, Intel Corp.
7*4882a593Smuzhiyun *
8*4882a593Smuzhiyun *****************************************************************************/
9*4882a593Smuzhiyun
10*4882a593Smuzhiyun #include <acpi/acpi.h>
11*4882a593Smuzhiyun #include "accommon.h"
12*4882a593Smuzhiyun #include "acparser.h"
13*4882a593Smuzhiyun #include "acopcode.h"
14*4882a593Smuzhiyun #include "amlcode.h"
15*4882a593Smuzhiyun
16*4882a593Smuzhiyun #define _COMPONENT ACPI_PARSER
17*4882a593Smuzhiyun ACPI_MODULE_NAME("psopinfo")
18*4882a593Smuzhiyun
19*4882a593Smuzhiyun static const u8 acpi_gbl_argument_count[] =
20*4882a593Smuzhiyun { 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 6 };
21*4882a593Smuzhiyun
22*4882a593Smuzhiyun /*******************************************************************************
23*4882a593Smuzhiyun *
24*4882a593Smuzhiyun * FUNCTION: acpi_ps_get_opcode_info
25*4882a593Smuzhiyun *
26*4882a593Smuzhiyun * PARAMETERS: opcode - The AML opcode
27*4882a593Smuzhiyun *
28*4882a593Smuzhiyun * RETURN: A pointer to the info about the opcode.
29*4882a593Smuzhiyun *
30*4882a593Smuzhiyun * DESCRIPTION: Find AML opcode description based on the opcode.
31*4882a593Smuzhiyun * NOTE: This procedure must ALWAYS return a valid pointer!
32*4882a593Smuzhiyun *
33*4882a593Smuzhiyun ******************************************************************************/
34*4882a593Smuzhiyun
acpi_ps_get_opcode_info(u16 opcode)35*4882a593Smuzhiyun const struct acpi_opcode_info *acpi_ps_get_opcode_info(u16 opcode)
36*4882a593Smuzhiyun {
37*4882a593Smuzhiyun #ifdef ACPI_DEBUG_OUTPUT
38*4882a593Smuzhiyun const char *opcode_name = "Unknown AML opcode";
39*4882a593Smuzhiyun #endif
40*4882a593Smuzhiyun
41*4882a593Smuzhiyun ACPI_FUNCTION_NAME(ps_get_opcode_info);
42*4882a593Smuzhiyun
43*4882a593Smuzhiyun /*
44*4882a593Smuzhiyun * Detect normal 8-bit opcode or extended 16-bit opcode
45*4882a593Smuzhiyun */
46*4882a593Smuzhiyun if (!(opcode & 0xFF00)) {
47*4882a593Smuzhiyun
48*4882a593Smuzhiyun /* Simple (8-bit) opcode: 0-255, can't index beyond table */
49*4882a593Smuzhiyun
50*4882a593Smuzhiyun return (&acpi_gbl_aml_op_info
51*4882a593Smuzhiyun [acpi_gbl_short_op_index[(u8)opcode]]);
52*4882a593Smuzhiyun }
53*4882a593Smuzhiyun
54*4882a593Smuzhiyun if (((opcode & 0xFF00) == AML_EXTENDED_OPCODE) &&
55*4882a593Smuzhiyun (((u8)opcode) <= MAX_EXTENDED_OPCODE)) {
56*4882a593Smuzhiyun
57*4882a593Smuzhiyun /* Valid extended (16-bit) opcode */
58*4882a593Smuzhiyun
59*4882a593Smuzhiyun return (&acpi_gbl_aml_op_info
60*4882a593Smuzhiyun [acpi_gbl_long_op_index[(u8)opcode]]);
61*4882a593Smuzhiyun }
62*4882a593Smuzhiyun #if defined ACPI_ASL_COMPILER && defined ACPI_DEBUG_OUTPUT
63*4882a593Smuzhiyun #include "asldefine.h"
64*4882a593Smuzhiyun
65*4882a593Smuzhiyun switch (opcode) {
66*4882a593Smuzhiyun case AML_RAW_DATA_BYTE:
67*4882a593Smuzhiyun opcode_name = "-Raw Data Byte-";
68*4882a593Smuzhiyun break;
69*4882a593Smuzhiyun
70*4882a593Smuzhiyun case AML_RAW_DATA_WORD:
71*4882a593Smuzhiyun opcode_name = "-Raw Data Word-";
72*4882a593Smuzhiyun break;
73*4882a593Smuzhiyun
74*4882a593Smuzhiyun case AML_RAW_DATA_DWORD:
75*4882a593Smuzhiyun opcode_name = "-Raw Data Dword-";
76*4882a593Smuzhiyun break;
77*4882a593Smuzhiyun
78*4882a593Smuzhiyun case AML_RAW_DATA_QWORD:
79*4882a593Smuzhiyun opcode_name = "-Raw Data Qword-";
80*4882a593Smuzhiyun break;
81*4882a593Smuzhiyun
82*4882a593Smuzhiyun case AML_RAW_DATA_BUFFER:
83*4882a593Smuzhiyun opcode_name = "-Raw Data Buffer-";
84*4882a593Smuzhiyun break;
85*4882a593Smuzhiyun
86*4882a593Smuzhiyun case AML_RAW_DATA_CHAIN:
87*4882a593Smuzhiyun opcode_name = "-Raw Data Buffer Chain-";
88*4882a593Smuzhiyun break;
89*4882a593Smuzhiyun
90*4882a593Smuzhiyun case AML_PACKAGE_LENGTH:
91*4882a593Smuzhiyun opcode_name = "-Package Length-";
92*4882a593Smuzhiyun break;
93*4882a593Smuzhiyun
94*4882a593Smuzhiyun case AML_UNASSIGNED_OPCODE:
95*4882a593Smuzhiyun opcode_name = "-Unassigned Opcode-";
96*4882a593Smuzhiyun break;
97*4882a593Smuzhiyun
98*4882a593Smuzhiyun case AML_DEFAULT_ARG_OP:
99*4882a593Smuzhiyun opcode_name = "-Default Arg-";
100*4882a593Smuzhiyun break;
101*4882a593Smuzhiyun
102*4882a593Smuzhiyun default:
103*4882a593Smuzhiyun break;
104*4882a593Smuzhiyun }
105*4882a593Smuzhiyun #endif
106*4882a593Smuzhiyun
107*4882a593Smuzhiyun /* Unknown AML opcode */
108*4882a593Smuzhiyun
109*4882a593Smuzhiyun ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "%s [%4.4X]\n", opcode_name, opcode));
110*4882a593Smuzhiyun
111*4882a593Smuzhiyun return (&acpi_gbl_aml_op_info[_UNK]);
112*4882a593Smuzhiyun }
113*4882a593Smuzhiyun
114*4882a593Smuzhiyun /*******************************************************************************
115*4882a593Smuzhiyun *
116*4882a593Smuzhiyun * FUNCTION: acpi_ps_get_opcode_name
117*4882a593Smuzhiyun *
118*4882a593Smuzhiyun * PARAMETERS: opcode - The AML opcode
119*4882a593Smuzhiyun *
120*4882a593Smuzhiyun * RETURN: A pointer to the name of the opcode (ASCII String)
121*4882a593Smuzhiyun * Note: Never returns NULL.
122*4882a593Smuzhiyun *
123*4882a593Smuzhiyun * DESCRIPTION: Translate an opcode into a human-readable string
124*4882a593Smuzhiyun *
125*4882a593Smuzhiyun ******************************************************************************/
126*4882a593Smuzhiyun
acpi_ps_get_opcode_name(u16 opcode)127*4882a593Smuzhiyun const char *acpi_ps_get_opcode_name(u16 opcode)
128*4882a593Smuzhiyun {
129*4882a593Smuzhiyun #if defined(ACPI_DISASSEMBLER) || defined (ACPI_DEBUG_OUTPUT)
130*4882a593Smuzhiyun
131*4882a593Smuzhiyun const struct acpi_opcode_info *op;
132*4882a593Smuzhiyun
133*4882a593Smuzhiyun op = acpi_ps_get_opcode_info(opcode);
134*4882a593Smuzhiyun
135*4882a593Smuzhiyun /* Always guaranteed to return a valid pointer */
136*4882a593Smuzhiyun
137*4882a593Smuzhiyun return (op->name);
138*4882a593Smuzhiyun
139*4882a593Smuzhiyun #else
140*4882a593Smuzhiyun return ("OpcodeName unavailable");
141*4882a593Smuzhiyun
142*4882a593Smuzhiyun #endif
143*4882a593Smuzhiyun }
144*4882a593Smuzhiyun
145*4882a593Smuzhiyun /*******************************************************************************
146*4882a593Smuzhiyun *
147*4882a593Smuzhiyun * FUNCTION: acpi_ps_get_argument_count
148*4882a593Smuzhiyun *
149*4882a593Smuzhiyun * PARAMETERS: op_type - Type associated with the AML opcode
150*4882a593Smuzhiyun *
151*4882a593Smuzhiyun * RETURN: Argument count
152*4882a593Smuzhiyun *
153*4882a593Smuzhiyun * DESCRIPTION: Obtain the number of expected arguments for an AML opcode
154*4882a593Smuzhiyun *
155*4882a593Smuzhiyun ******************************************************************************/
156*4882a593Smuzhiyun
acpi_ps_get_argument_count(u32 op_type)157*4882a593Smuzhiyun u8 acpi_ps_get_argument_count(u32 op_type)
158*4882a593Smuzhiyun {
159*4882a593Smuzhiyun
160*4882a593Smuzhiyun if (op_type <= AML_TYPE_EXEC_6A_0T_1R) {
161*4882a593Smuzhiyun return (acpi_gbl_argument_count[op_type]);
162*4882a593Smuzhiyun }
163*4882a593Smuzhiyun
164*4882a593Smuzhiyun return (0);
165*4882a593Smuzhiyun }
166*4882a593Smuzhiyun
167*4882a593Smuzhiyun /*
168*4882a593Smuzhiyun * This table is directly indexed by the opcodes It returns
169*4882a593Smuzhiyun * an index into the opcode table (acpi_gbl_aml_op_info)
170*4882a593Smuzhiyun */
171*4882a593Smuzhiyun const u8 acpi_gbl_short_op_index[256] = {
172*4882a593Smuzhiyun /* 0 1 2 3 4 5 6 7 */
173*4882a593Smuzhiyun /* 8 9 A B C D E F */
174*4882a593Smuzhiyun /* 0x00 */ 0x00, 0x01, _UNK, _UNK, _UNK, _UNK, 0x02, _UNK,
175*4882a593Smuzhiyun /* 0x08 */ 0x03, _UNK, 0x04, 0x05, 0x06, 0x07, 0x6E, _UNK,
176*4882a593Smuzhiyun /* 0x10 */ 0x08, 0x09, 0x0a, 0x6F, 0x0b, 0x81, _UNK, _UNK,
177*4882a593Smuzhiyun /* 0x18 */ _UNK, _UNK, _UNK, _UNK, _UNK, _UNK, _UNK, _UNK,
178*4882a593Smuzhiyun /* 0x20 */ _UNK, _UNK, _UNK, _UNK, _UNK, _UNK, _UNK, _UNK,
179*4882a593Smuzhiyun /* 0x28 */ _UNK, _UNK, _UNK, _UNK, _UNK, 0x63, _PFX, _PFX,
180*4882a593Smuzhiyun /* 0x30 */ 0x67, 0x66, 0x68, 0x65, 0x69, 0x64, 0x6A, 0x7D,
181*4882a593Smuzhiyun /* 0x38 */ 0x7F, 0x80, _UNK, _UNK, _UNK, _UNK, _UNK, _UNK,
182*4882a593Smuzhiyun /* 0x40 */ _UNK, _ASC, _ASC, _ASC, _ASC, _ASC, _ASC, _ASC,
183*4882a593Smuzhiyun /* 0x48 */ _ASC, _ASC, _ASC, _ASC, _ASC, _ASC, _ASC, _ASC,
184*4882a593Smuzhiyun /* 0x50 */ _ASC, _ASC, _ASC, _ASC, _ASC, _ASC, _ASC, _ASC,
185*4882a593Smuzhiyun /* 0x58 */ _ASC, _ASC, _ASC, _UNK, _PFX, _UNK, _PFX, _ASC,
186*4882a593Smuzhiyun /* 0x60 */ 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13,
187*4882a593Smuzhiyun /* 0x68 */ 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, _UNK,
188*4882a593Smuzhiyun /* 0x70 */ 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22,
189*4882a593Smuzhiyun /* 0x78 */ 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a,
190*4882a593Smuzhiyun /* 0x80 */ 0x2b, 0x2c, 0x2d, 0x2e, 0x70, 0x71, 0x2f, 0x30,
191*4882a593Smuzhiyun /* 0x88 */ 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x72,
192*4882a593Smuzhiyun /* 0x90 */ 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x73, 0x74,
193*4882a593Smuzhiyun /* 0x98 */ 0x75, 0x76, _UNK, _UNK, 0x77, 0x78, 0x79, 0x7A,
194*4882a593Smuzhiyun /* 0xA0 */ 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x60, 0x61,
195*4882a593Smuzhiyun /* 0xA8 */ 0x62, 0x82, _UNK, _UNK, _UNK, _UNK, _UNK, _UNK,
196*4882a593Smuzhiyun /* 0xB0 */ _UNK, _UNK, _UNK, _UNK, _UNK, _UNK, _UNK, _UNK,
197*4882a593Smuzhiyun /* 0xB8 */ _UNK, _UNK, _UNK, _UNK, _UNK, _UNK, _UNK, _UNK,
198*4882a593Smuzhiyun /* 0xC0 */ _UNK, _UNK, _UNK, _UNK, _UNK, _UNK, _UNK, _UNK,
199*4882a593Smuzhiyun /* 0xC8 */ _UNK, _UNK, _UNK, _UNK, 0x44, _UNK, _UNK, _UNK,
200*4882a593Smuzhiyun /* 0xD0 */ _UNK, _UNK, _UNK, _UNK, _UNK, _UNK, _UNK, _UNK,
201*4882a593Smuzhiyun /* 0xD8 */ _UNK, _UNK, _UNK, _UNK, _UNK, _UNK, _UNK, _UNK,
202*4882a593Smuzhiyun /* 0xE0 */ _UNK, _UNK, _UNK, _UNK, _UNK, _UNK, _UNK, _UNK,
203*4882a593Smuzhiyun /* 0xE8 */ _UNK, _UNK, _UNK, _UNK, _UNK, _UNK, _UNK, _UNK,
204*4882a593Smuzhiyun /* 0xF0 */ _UNK, _UNK, _UNK, _UNK, _UNK, _UNK, _UNK, _UNK,
205*4882a593Smuzhiyun /* 0xF8 */ _UNK, _UNK, _UNK, _UNK, _UNK, _UNK, _UNK, 0x45,
206*4882a593Smuzhiyun };
207*4882a593Smuzhiyun
208*4882a593Smuzhiyun /*
209*4882a593Smuzhiyun * This table is indexed by the second opcode of the extended opcode
210*4882a593Smuzhiyun * pair. It returns an index into the opcode table (acpi_gbl_aml_op_info)
211*4882a593Smuzhiyun */
212*4882a593Smuzhiyun const u8 acpi_gbl_long_op_index[NUM_EXTENDED_OPCODE] = {
213*4882a593Smuzhiyun /* 0 1 2 3 4 5 6 7 */
214*4882a593Smuzhiyun /* 8 9 A B C D E F */
215*4882a593Smuzhiyun /* 0x00 */ _UNK, 0x46, 0x47, _UNK, _UNK, _UNK, _UNK, _UNK,
216*4882a593Smuzhiyun /* 0x08 */ _UNK, _UNK, _UNK, _UNK, _UNK, _UNK, _UNK, _UNK,
217*4882a593Smuzhiyun /* 0x10 */ _UNK, _UNK, 0x48, 0x49, _UNK, _UNK, _UNK, _UNK,
218*4882a593Smuzhiyun /* 0x18 */ _UNK, _UNK, _UNK, _UNK, _UNK, _UNK, _UNK, 0x7B,
219*4882a593Smuzhiyun /* 0x20 */ 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51,
220*4882a593Smuzhiyun /* 0x28 */ 0x52, 0x53, 0x54, _UNK, _UNK, _UNK, _UNK, _UNK,
221*4882a593Smuzhiyun /* 0x30 */ 0x55, 0x56, 0x57, 0x7e, _UNK, _UNK, _UNK, _UNK,
222*4882a593Smuzhiyun /* 0x38 */ _UNK, _UNK, _UNK, _UNK, _UNK, _UNK, _UNK, _UNK,
223*4882a593Smuzhiyun /* 0x40 */ _UNK, _UNK, _UNK, _UNK, _UNK, _UNK, _UNK, _UNK,
224*4882a593Smuzhiyun /* 0x48 */ _UNK, _UNK, _UNK, _UNK, _UNK, _UNK, _UNK, _UNK,
225*4882a593Smuzhiyun /* 0x50 */ _UNK, _UNK, _UNK, _UNK, _UNK, _UNK, _UNK, _UNK,
226*4882a593Smuzhiyun /* 0x58 */ _UNK, _UNK, _UNK, _UNK, _UNK, _UNK, _UNK, _UNK,
227*4882a593Smuzhiyun /* 0x60 */ _UNK, _UNK, _UNK, _UNK, _UNK, _UNK, _UNK, _UNK,
228*4882a593Smuzhiyun /* 0x68 */ _UNK, _UNK, _UNK, _UNK, _UNK, _UNK, _UNK, _UNK,
229*4882a593Smuzhiyun /* 0x70 */ _UNK, _UNK, _UNK, _UNK, _UNK, _UNK, _UNK, _UNK,
230*4882a593Smuzhiyun /* 0x78 */ _UNK, _UNK, _UNK, _UNK, _UNK, _UNK, _UNK, _UNK,
231*4882a593Smuzhiyun /* 0x80 */ 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
232*4882a593Smuzhiyun /* 0x88 */ 0x7C,
233*4882a593Smuzhiyun };
234