]> git.proxmox.com Git - mirror_edk2.git/blob - DynamicTablesPkg/Library/Common/AmlLib/AmlEncoding/Aml.c
d829b1869846863c83dceca884b3ff663906996e
[mirror_edk2.git] / DynamicTablesPkg / Library / Common / AmlLib / AmlEncoding / Aml.c
1 /** @file
2 AML grammar definitions.
3
4 Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved. <BR>
5 Copyright (c) 2019 - 2021, Arm Limited. All rights reserved.<BR>
6
7 SPDX-License-Identifier: BSD-2-Clause-Patent
8 **/
9
10 #include <AmlEncoding/Aml.h>
11
12 /** AML grammar encoding table.
13
14 The ASL language is a description language, used to define abstract
15 objects, like devices, thermal zones, etc. and their place in a hierarchical
16 tree. The following table stores the AML grammar definition. It can be used
17 to parse an AML bytestream. Each line corresponds to the definition of an
18 opcode and what is expected to be found with this opcode.
19 See table 20-440 in the ACPI 6.3 specification s20.3, and the AML
20 grammar definitions in s20.2.
21
22 - OpCode/SubOpCode:
23 An OpCode/SubOpCode couple allows to identify an object type.
24 The OpCode and SubOpCode are one byte each. The SubOpCode is
25 used when the Opcode value is 0x5B (extended OpCode). Otherwise
26 the SubOpcode is set to 0. If the SubOpCode is 0 in the table
27 below, there is no SubOpCode in the AML bytestream, only the
28 OpCode is used to identify the object.
29
30 - Fixed arguments:
31 The fixed arguments follow the OpCode and SubOpCode. Their number
32 and type can be found in the table below. There can be at the most
33 6 fixed arguments for an object.
34 Fixed arguments's type allow to know what is expected in the AML bytestream.
35 Knowing the size of the incoming element, AML bytes can be packed and parsed
36 accordingly. These types can be found in the same table 20-440 in the
37 ACPI 6.3, s20.3 specification.
38 E.g.: An AML object, a UINT8, a NULL terminated string, etc.
39
40 -Attributes:
41 The attribute field gives additional information on each object. This can
42 be the presence of a variable list of arguments, the presence of a PkgLen,
43 etc.
44
45 In summary, an AML object is described as:
46 OpCode [SubOpcode] [PkgLen] [FixedArgs] [VarArgs]
47
48 OpCode {1 byte}
49 [SubOpCode] {1 byte.
50 Only relevant if the OpCode value is
51 0x5B (extended OpCode prefix).
52 Otherwise 0. Most objects don't have one.}
53 [PkgLen] {Size of the object.
54 It has a special encoding, cf. ACPI 6.3
55 specification, s20.2.4 "Package Length
56 Encoding".
57 Most objects don't have one.}
58 [FixedArgs[0..X]] {Fixed list of arguments.
59 (where X <= 5) Can be other objects or data (a byte,
60 a string, etc.). They belong to the
61 current AML object.
62 The number of fixed arguments varies according
63 to the object, but it is fixed for each kind of
64 object.}
65 [VarArgs] {Variable list of arguments.
66 They also belong to the current object and can
67 be objects or data.
68 Most objects don't have one.}
69 [ByteList] {This is a sub-type of a variable list of
70 arguments. It can only be found in buffer
71 objects.
72 A ByteList is either a list of bytes or
73 a list of resource data elements. Resource
74 data elements have specific opcodes.}
75 [FieldList] {This is a sub-type of a variable list of
76 arguments. It can only be found in Fields,
77 IndexFields and BankFields.
78 A FieldList is made of FieldElements.
79 FieldElements have specific opcodes.}
80 */
81 GLOBAL_REMOVE_IF_UNREFERENCED
82 STATIC
83 CONST
84 AML_BYTE_ENCODING mAmlByteEncoding[] = {
85 // Comment Str OpCode SubOpCode MaxIndex NameIndex 0 1 2 3 4 5 Attribute
86 /* 0x00 */ {AML_OPCODE_DEF ("ZeroOp", AML_ZERO_OP), 0, 0, 0, {EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, 0},
87 /* 0x01 */ {AML_OPCODE_DEF ("OneOp", AML_ONE_OP), 0, 0, 0, {EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, 0},
88 /* 0x06 */ {AML_OPCODE_DEF ("AliasOp", AML_ALIAS_OP), 0, 2, 1, {EAmlName, EAmlName, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, AML_IN_NAMESPACE},
89 /* 0x08 */ {AML_OPCODE_DEF ("NameOp", AML_NAME_OP), 0, 2, 0, {EAmlName, EAmlObject, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, AML_IN_NAMESPACE},
90 /* 0x0A */ {AML_OPCODE_DEF ("BytePrefix", AML_BYTE_PREFIX), 0, 1, 0, {EAmlUInt8, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, 0},
91 /* 0x0B */ {AML_OPCODE_DEF ("WordPrefix", AML_WORD_PREFIX), 0, 1, 0, {EAmlUInt16, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, 0},
92 /* 0x0C */ {AML_OPCODE_DEF ("DWordPrefix", AML_DWORD_PREFIX), 0, 1, 0, {EAmlUInt32, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, 0},
93 /* 0x0D */ {AML_OPCODE_DEF ("StringPrefix", AML_STRING_PREFIX), 0, 1, 0, {EAmlString, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, 0},
94 /* 0x0E */ {AML_OPCODE_DEF ("QWordPrefix", AML_QWORD_PREFIX), 0, 1, 0, {EAmlUInt64, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, 0},
95 /* 0x10 */ {AML_OPCODE_DEF ("ScopeOp", AML_SCOPE_OP), 0, 1, 0, {EAmlName, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, AML_HAS_PKG_LENGTH | AML_HAS_CHILD_OBJ | AML_IN_NAMESPACE},
96 /* 0x11 */ {AML_OPCODE_DEF ("BufferOp", AML_BUFFER_OP), 0, 1, 0, {EAmlObject, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, AML_HAS_PKG_LENGTH | AML_HAS_BYTE_LIST},
97 /* 0x12 */ {AML_OPCODE_DEF ("PackageOp", AML_PACKAGE_OP), 0, 1, 0, {EAmlUInt8, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, AML_HAS_PKG_LENGTH | AML_HAS_CHILD_OBJ},
98 /* 0x13 */ {AML_OPCODE_DEF ("VarPackageOp", AML_VAR_PACKAGE_OP), 0, 1, 0, {EAmlObject, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, AML_HAS_PKG_LENGTH | AML_HAS_CHILD_OBJ},
99 /* 0x14 */ {AML_OPCODE_DEF ("MethodOp", AML_METHOD_OP), 0, 2, 0, {EAmlName, EAmlUInt8, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, AML_HAS_PKG_LENGTH | AML_HAS_CHILD_OBJ | AML_IN_NAMESPACE},
100 /* 0x15 */ {AML_OPCODE_DEF ("ExternalOp", AML_EXTERNAL_OP), 0, 3, 0, {EAmlName, EAmlUInt8, EAmlUInt8, EAmlNone, EAmlNone, EAmlNone}, AML_IN_NAMESPACE},
101 /* 0x2E */ {AML_OPCODE_DEF ("DualNamePrefix", AML_DUAL_NAME_PREFIX), 0, 0, 0, {EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, AML_IS_NAME_CHAR},
102 /* 0x2F */ {AML_OPCODE_DEF ("MultiNamePrefix", AML_MULTI_NAME_PREFIX), 0, 0, 0, {EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, AML_IS_NAME_CHAR},
103 /* 0x41 */ {AML_OPCODE_DEF ("NameChar_A", 'A'), 0, 0, 0, {EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, AML_IS_NAME_CHAR},
104 /* 0x42 */ {AML_OPCODE_DEF ("NameChar_B", 'B'), 0, 0, 0, {EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, AML_IS_NAME_CHAR},
105 /* 0x43 */ {AML_OPCODE_DEF ("NameChar_C", 'C'), 0, 0, 0, {EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, AML_IS_NAME_CHAR},
106 /* 0x44 */ {AML_OPCODE_DEF ("NameChar_D", 'D'), 0, 0, 0, {EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, AML_IS_NAME_CHAR},
107 /* 0x45 */ {AML_OPCODE_DEF ("NameChar_E", 'E'), 0, 0, 0, {EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, AML_IS_NAME_CHAR},
108 /* 0x46 */ {AML_OPCODE_DEF ("NameChar_F", 'F'), 0, 0, 0, {EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, AML_IS_NAME_CHAR},
109 /* 0x47 */ {AML_OPCODE_DEF ("NameChar_G", 'G'), 0, 0, 0, {EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, AML_IS_NAME_CHAR},
110 /* 0x48 */ {AML_OPCODE_DEF ("NameChar_H", 'H'), 0, 0, 0, {EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, AML_IS_NAME_CHAR},
111 /* 0x49 */ {AML_OPCODE_DEF ("NameChar_I", 'I'), 0, 0, 0, {EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, AML_IS_NAME_CHAR},
112 /* 0x4A */ {AML_OPCODE_DEF ("NameChar_J", 'J'), 0, 0, 0, {EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, AML_IS_NAME_CHAR},
113 /* 0x4B */ {AML_OPCODE_DEF ("NameChar_K", 'K'), 0, 0, 0, {EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, AML_IS_NAME_CHAR},
114 /* 0x4C */ {AML_OPCODE_DEF ("NameChar_L", 'L'), 0, 0, 0, {EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, AML_IS_NAME_CHAR},
115 /* 0x4D */ {AML_OPCODE_DEF ("NameChar_M", 'M'), 0, 0, 0, {EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, AML_IS_NAME_CHAR},
116 /* 0x4E */ {AML_OPCODE_DEF ("NameChar_N", 'N'), 0, 0, 0, {EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, AML_IS_NAME_CHAR},
117 /* 0x4F */ {AML_OPCODE_DEF ("NameChar_O", 'O'), 0, 0, 0, {EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, AML_IS_NAME_CHAR},
118 /* 0x50 */ {AML_OPCODE_DEF ("NameChar_P", 'P'), 0, 0, 0, {EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, AML_IS_NAME_CHAR},
119 /* 0x51 */ {AML_OPCODE_DEF ("NameChar_Q", 'Q'), 0, 0, 0, {EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, AML_IS_NAME_CHAR},
120 /* 0x52 */ {AML_OPCODE_DEF ("NameChar_R", 'R'), 0, 0, 0, {EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, AML_IS_NAME_CHAR},
121 /* 0x53 */ {AML_OPCODE_DEF ("NameChar_S", 'S'), 0, 0, 0, {EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, AML_IS_NAME_CHAR},
122 /* 0x54 */ {AML_OPCODE_DEF ("NameChar_T", 'T'), 0, 0, 0, {EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, AML_IS_NAME_CHAR},
123 /* 0x55 */ {AML_OPCODE_DEF ("NameChar_U", 'U'), 0, 0, 0, {EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, AML_IS_NAME_CHAR},
124 /* 0x56 */ {AML_OPCODE_DEF ("NameChar_V", 'V'), 0, 0, 0, {EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, AML_IS_NAME_CHAR},
125 /* 0x57 */ {AML_OPCODE_DEF ("NameChar_W", 'W'), 0, 0, 0, {EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, AML_IS_NAME_CHAR},
126 /* 0x58 */ {AML_OPCODE_DEF ("NameChar_X", 'X'), 0, 0, 0, {EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, AML_IS_NAME_CHAR},
127 /* 0x59 */ {AML_OPCODE_DEF ("NameChar_Y", 'Y'), 0, 0, 0, {EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, AML_IS_NAME_CHAR},
128 /* 0x5A */ {AML_OPCODE_DEF ("NameChar_Z", 'Z'), 0, 0, 0, {EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, AML_IS_NAME_CHAR},
129 /* 0x5B 0x01 */ {AML_OPCODE_DEF ("MutexOp", AML_EXT_OP), AML_EXT_MUTEX_OP, 2, 0, {EAmlName, EAmlUInt8, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, AML_IN_NAMESPACE},
130 /* 0x5B 0x02 */ {AML_OPCODE_DEF ("EventOp", AML_EXT_OP), AML_EXT_EVENT_OP, 1, 0, {EAmlName, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, AML_IN_NAMESPACE},
131 /* 0x5B 0x12 */ {AML_OPCODE_DEF ("CondRefOfOp", AML_EXT_OP), AML_EXT_COND_REF_OF_OP, 2, 0, {EAmlObject, EAmlObject, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, 0},
132 /* 0x5B 0x13 */ {AML_OPCODE_DEF ("CreateFieldOp", AML_EXT_OP), AML_EXT_CREATE_FIELD_OP,4, 3, {EAmlObject, EAmlObject, EAmlObject, EAmlName, EAmlNone, EAmlNone}, AML_IN_NAMESPACE},
133 /* 0x5B 0x1F */ {AML_OPCODE_DEF ("LoadTableOp", AML_EXT_OP), AML_EXT_LOAD_TABLE_OP, 6, 0, {EAmlObject, EAmlObject, EAmlObject, EAmlObject, EAmlObject, EAmlObject}, 0},
134 /* 0x5B 0x20 */ {AML_OPCODE_DEF ("LoadOp", AML_EXT_OP), AML_EXT_LOAD_OP, 2, 0, {EAmlName, EAmlObject, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, 0},
135 /* 0x5B 0x21 */ {AML_OPCODE_DEF ("StallOp", AML_EXT_OP), AML_EXT_STALL_OP, 1, 0, {EAmlObject, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, 0},
136 /* 0x5B 0x22 */ {AML_OPCODE_DEF ("SleepOp", AML_EXT_OP), AML_EXT_SLEEP_OP, 1, 0, {EAmlObject, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, 0},
137 /* 0x5B 0x23 */ {AML_OPCODE_DEF ("AcquireOp", AML_EXT_OP), AML_EXT_ACQUIRE_OP, 2, 0, {EAmlObject, EAmlUInt16, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, 0},
138 /* 0x5B 0x24 */ {AML_OPCODE_DEF ("SignalOp", AML_EXT_OP), AML_EXT_SIGNAL_OP, 1, 0, {EAmlObject, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, 0},
139 /* 0x5B 0x25 */ {AML_OPCODE_DEF ("WaitOp", AML_EXT_OP), AML_EXT_WAIT_OP, 2, 0, {EAmlObject, EAmlObject, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, 0},
140 /* 0x5B 0x26 */ {AML_OPCODE_DEF ("ResetOp", AML_EXT_OP), AML_EXT_RESET_OP, 1, 0, {EAmlObject, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, 0},
141 /* 0x5B 0x27 */ {AML_OPCODE_DEF ("ReleaseOp", AML_EXT_OP), AML_EXT_RELEASE_OP, 1, 0, {EAmlObject, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, 0},
142 /* 0x5B 0x28 */ {AML_OPCODE_DEF ("FromBCDOp", AML_EXT_OP), AML_EXT_FROM_BCD_OP, 2, 0, {EAmlObject, EAmlObject, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, 0},
143 /* 0x5B 0x29 */ {AML_OPCODE_DEF ("ToBCDOp", AML_EXT_OP), AML_EXT_TO_BCD_OP, 2, 0, {EAmlObject, EAmlObject, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, 0},
144 /* 0x5B 0x2A */ {AML_OPCODE_DEF ("UnloadOp", AML_EXT_OP), AML_EXT_UNLOAD_OP, 1, 0, {EAmlObject, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, 0},
145 /* 0x5B 0x30 */ {AML_OPCODE_DEF ("RevisionOp", AML_EXT_OP), AML_EXT_REVISION_OP, 0, 0, {EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, 0},
146 /* 0x5B 0x31 */ {AML_OPCODE_DEF ("DebugOp", AML_EXT_OP), AML_EXT_DEBUG_OP, 0, 0, {EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, 0},
147 /* 0x5B 0x32 */ {AML_OPCODE_DEF ("FatalOp", AML_EXT_OP), AML_EXT_FATAL_OP, 3, 0, {EAmlUInt8, EAmlUInt32, EAmlObject, EAmlNone, EAmlNone, EAmlNone}, 0},
148 /* 0x5B 0x33 */ {AML_OPCODE_DEF ("TimerOp", AML_EXT_OP), AML_EXT_TIMER_OP, 0, 0, {EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, 0},
149 /* 0x5B 0x80 */ {AML_OPCODE_DEF ("OpRegionOp", AML_EXT_OP), AML_EXT_REGION_OP, 4, 0, {EAmlName, EAmlUInt8, EAmlObject, EAmlObject, EAmlNone, EAmlNone}, AML_IN_NAMESPACE},
150 /* 0x5B 0x81 */ {AML_OPCODE_DEF ("FieldOp", AML_EXT_OP), AML_EXT_FIELD_OP, 2, 0, {EAmlName, EAmlUInt8, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, AML_HAS_PKG_LENGTH | AML_HAS_FIELD_LIST},
151 /* 0x5B 0x82 */ {AML_OPCODE_DEF ("DeviceOp", AML_EXT_OP), AML_EXT_DEVICE_OP, 1, 0, {EAmlName, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, AML_HAS_PKG_LENGTH | AML_HAS_CHILD_OBJ | AML_IN_NAMESPACE},
152 /* 0x5B 0x83 */ {AML_OPCODE_DEF ("ProcessorOp", AML_EXT_OP), AML_EXT_PROCESSOR_OP, 4, 0, {EAmlName, EAmlUInt8, EAmlUInt32, EAmlUInt8, EAmlNone, EAmlNone}, AML_HAS_PKG_LENGTH | AML_HAS_CHILD_OBJ | AML_IN_NAMESPACE},
153 /* 0x5B 0x84 */ {AML_OPCODE_DEF ("PowerResOp", AML_EXT_OP), AML_EXT_POWER_RES_OP, 3, 0, {EAmlName, EAmlUInt8, EAmlUInt16, EAmlNone, EAmlNone, EAmlNone}, AML_HAS_PKG_LENGTH | AML_HAS_CHILD_OBJ | AML_IN_NAMESPACE},
154 /* 0x5B 0x85 */ {AML_OPCODE_DEF ("ThermalZoneOp", AML_EXT_OP), AML_EXT_THERMAL_ZONE_OP,1, 0, {EAmlName, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, AML_HAS_PKG_LENGTH | AML_HAS_CHILD_OBJ | AML_IN_NAMESPACE},
155 /* 0x5B 0x86 */ {AML_OPCODE_DEF ("IndexFieldOp", AML_EXT_OP), AML_EXT_INDEX_FIELD_OP, 3, 0, {EAmlName, EAmlName, EAmlUInt8, EAmlNone, EAmlNone, EAmlNone}, AML_HAS_PKG_LENGTH | AML_HAS_FIELD_LIST},
156 /* 0x5B 0x87 */ {AML_OPCODE_DEF ("BankFieldOp", AML_EXT_OP), AML_EXT_BANK_FIELD_OP, 4, 0, {EAmlName, EAmlName, EAmlObject, EAmlUInt8, EAmlNone, EAmlNone}, AML_HAS_PKG_LENGTH | AML_HAS_FIELD_LIST},
157 /* 0x5B 0x88 */ {AML_OPCODE_DEF ("DataRegionOp", AML_EXT_OP), AML_EXT_DATA_REGION_OP, 4, 0, {EAmlName, EAmlObject, EAmlObject, EAmlObject, EAmlNone, EAmlNone}, AML_IN_NAMESPACE},
158 /* 0x5C */ {AML_OPCODE_DEF ("RootChar", AML_ROOT_CHAR), 0, 0, 0, {EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, AML_IS_NAME_CHAR},
159 /* 0x5E */ {AML_OPCODE_DEF ("ParentPrefixChar", AML_PARENT_PREFIX_CHAR), 0, 0, 0, {EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, AML_IS_NAME_CHAR},
160 /* 0x5F */ {AML_OPCODE_DEF ("NameChar", '_'), 0, 0, 0, {EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, AML_IS_NAME_CHAR},
161 /* 0x60 */ {AML_OPCODE_DEF ("Local0Op", AML_LOCAL0), 0, 0, 0, {EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, 0},
162 /* 0x61 */ {AML_OPCODE_DEF ("Local1Op", AML_LOCAL1), 0, 0, 0, {EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, 0},
163 /* 0x62 */ {AML_OPCODE_DEF ("Local2Op", AML_LOCAL2), 0, 0, 0, {EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, 0},
164 /* 0x63 */ {AML_OPCODE_DEF ("Local3Op", AML_LOCAL3), 0, 0, 0, {EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, 0},
165 /* 0x64 */ {AML_OPCODE_DEF ("Local4Op", AML_LOCAL4), 0, 0, 0, {EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, 0},
166 /* 0x65 */ {AML_OPCODE_DEF ("Local5Op", AML_LOCAL5), 0, 0, 0, {EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, 0},
167 /* 0x66 */ {AML_OPCODE_DEF ("Local6Op", AML_LOCAL6), 0, 0, 0, {EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, 0},
168 /* 0x67 */ {AML_OPCODE_DEF ("Local7Op", AML_LOCAL7), 0, 0, 0, {EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, 0},
169 /* 0x68 */ {AML_OPCODE_DEF ("Arg0Op", AML_ARG0), 0, 0, 0, {EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, 0},
170 /* 0x69 */ {AML_OPCODE_DEF ("Arg1Op", AML_ARG1), 0, 0, 0, {EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, 0},
171 /* 0x6A */ {AML_OPCODE_DEF ("Arg2Op", AML_ARG2), 0, 0, 0, {EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, 0},
172 /* 0x6B */ {AML_OPCODE_DEF ("Arg3Op", AML_ARG3), 0, 0, 0, {EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, 0},
173 /* 0x6C */ {AML_OPCODE_DEF ("Arg4Op", AML_ARG4), 0, 0, 0, {EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, 0},
174 /* 0x6D */ {AML_OPCODE_DEF ("Arg5Op", AML_ARG5), 0, 0, 0, {EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, 0},
175 /* 0x6E */ {AML_OPCODE_DEF ("Arg6Op", AML_ARG6), 0, 0, 0, {EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, 0},
176 /* 0x70 */ {AML_OPCODE_DEF ("StoreOp", AML_STORE_OP), 0, 2, 0, {EAmlObject, EAmlObject, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, 0},
177 /* 0x71 */ {AML_OPCODE_DEF ("RefOfOp", AML_REF_OF_OP), 0, 1, 0, {EAmlObject, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, 0},
178 /* 0x72 */ {AML_OPCODE_DEF ("AddOp", AML_ADD_OP), 0, 3, 0, {EAmlObject, EAmlObject, EAmlObject, EAmlNone, EAmlNone, EAmlNone}, 0},
179 /* 0x73 */ {AML_OPCODE_DEF ("ConcatOp", AML_CONCAT_OP), 0, 3, 0, {EAmlObject, EAmlObject, EAmlObject, EAmlNone, EAmlNone, EAmlNone}, 0},
180 /* 0x74 */ {AML_OPCODE_DEF ("SubtractOp", AML_SUBTRACT_OP), 0, 3, 0, {EAmlObject, EAmlObject, EAmlObject, EAmlNone, EAmlNone, EAmlNone}, 0},
181 /* 0x75 */ {AML_OPCODE_DEF ("IncrementOp", AML_INCREMENT_OP), 0, 1, 0, {EAmlObject, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, 0},
182 /* 0x76 */ {AML_OPCODE_DEF ("DecrementOp", AML_DECREMENT_OP), 0, 1, 0, {EAmlObject, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, 0},
183 /* 0x77 */ {AML_OPCODE_DEF ("MultiplyOp", AML_MULTIPLY_OP), 0, 3, 0, {EAmlObject, EAmlObject, EAmlObject, EAmlNone, EAmlNone, EAmlNone}, 0},
184 /* 0x78 */ {AML_OPCODE_DEF ("DivideOp", AML_DIVIDE_OP), 0, 4, 0, {EAmlObject, EAmlObject, EAmlObject, EAmlObject, EAmlNone, EAmlNone}, 0},
185 /* 0x79 */ {AML_OPCODE_DEF ("ShiftLeftOp", AML_SHIFT_LEFT_OP), 0, 3, 0, {EAmlObject, EAmlObject, EAmlObject, EAmlNone, EAmlNone, EAmlNone}, 0},
186 /* 0x7A */ {AML_OPCODE_DEF ("ShiftRightOp", AML_SHIFT_RIGHT_OP), 0, 3, 0, {EAmlObject, EAmlObject, EAmlObject, EAmlNone, EAmlNone, EAmlNone}, 0},
187 /* 0x7B */ {AML_OPCODE_DEF ("AndOp", AML_AND_OP), 0, 3, 0, {EAmlObject, EAmlObject, EAmlObject, EAmlNone, EAmlNone, EAmlNone}, 0},
188 /* 0x7C */ {AML_OPCODE_DEF ("NAndOp", AML_NAND_OP), 0, 3, 0, {EAmlObject, EAmlObject, EAmlObject, EAmlNone, EAmlNone, EAmlNone}, 0},
189 /* 0x7D */ {AML_OPCODE_DEF ("OrOp", AML_OR_OP), 0, 3, 0, {EAmlObject, EAmlObject, EAmlObject, EAmlNone, EAmlNone, EAmlNone}, 0},
190 /* 0x7E */ {AML_OPCODE_DEF ("NorOp", AML_NOR_OP), 0, 3, 0, {EAmlObject, EAmlObject, EAmlObject, EAmlNone, EAmlNone, EAmlNone}, 0},
191 /* 0x7F */ {AML_OPCODE_DEF ("XOrOp", AML_XOR_OP), 0, 3, 0, {EAmlObject, EAmlObject, EAmlObject, EAmlNone, EAmlNone, EAmlNone}, 0},
192 /* 0x80 */ {AML_OPCODE_DEF ("NotOp", AML_NOT_OP), 0, 2, 0, {EAmlObject, EAmlObject, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, 0},
193 /* 0x81 */ {AML_OPCODE_DEF ("FindSetLeftBitOp", AML_FIND_SET_LEFT_BIT_OP), 0, 2, 0, {EAmlObject, EAmlObject, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, 0},
194 /* 0x82 */ {AML_OPCODE_DEF ("FindSetRightBitOp", AML_FIND_SET_RIGHT_BIT_OP),0, 2, 0, {EAmlObject, EAmlObject, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, 0},
195 /* 0x83 */ {AML_OPCODE_DEF ("DerefOfOp", AML_DEREF_OF_OP), 0, 1, 0, {EAmlObject, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, 0},
196 /* 0x84 */ {AML_OPCODE_DEF ("ConcatResOp", AML_CONCAT_RES_OP), 0, 3, 0, {EAmlObject, EAmlObject, EAmlObject, EAmlNone, EAmlNone, EAmlNone}, 0},
197 /* 0x85 */ {AML_OPCODE_DEF ("ModOp", AML_MOD_OP), 0, 3, 0, {EAmlObject, EAmlObject, EAmlObject, EAmlNone, EAmlNone, EAmlNone}, 0},
198 /* 0x86 */ {AML_OPCODE_DEF ("NotifyOp", AML_NOTIFY_OP), 0, 2, 0, {EAmlObject, EAmlObject, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, 0},
199 /* 0x87 */ {AML_OPCODE_DEF ("SizeOfOp", AML_SIZE_OF_OP), 0, 1, 0, {EAmlObject, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, 0},
200 /* 0x88 */ {AML_OPCODE_DEF ("IndexOp", AML_INDEX_OP), 0, 3, 0, {EAmlObject, EAmlObject, EAmlObject, EAmlNone, EAmlNone, EAmlNone}, 0},
201 /* 0x89 */ {AML_OPCODE_DEF ("MatchOp", AML_MATCH_OP), 0, 6, 0, {EAmlObject, EAmlUInt8, EAmlObject, EAmlUInt8, EAmlObject, EAmlObject}, 0},
202 /* 0x8A */ {AML_OPCODE_DEF ("CreateDWordFieldOp", AML_CREATE_DWORD_FIELD_OP),0, 3, 2, {EAmlObject, EAmlObject, EAmlName, EAmlNone, EAmlNone, EAmlNone}, AML_IN_NAMESPACE},
203 /* 0x8B */ {AML_OPCODE_DEF ("CreateWordFieldOp", AML_CREATE_WORD_FIELD_OP), 0, 3, 2, {EAmlObject, EAmlObject, EAmlName, EAmlNone, EAmlNone, EAmlNone}, AML_IN_NAMESPACE},
204 /* 0x8C */ {AML_OPCODE_DEF ("CreateByteFieldOp", AML_CREATE_BYTE_FIELD_OP), 0, 3, 2, {EAmlObject, EAmlObject, EAmlName, EAmlNone, EAmlNone, EAmlNone}, AML_IN_NAMESPACE},
205 /* 0x8D */ {AML_OPCODE_DEF ("CreateBitFieldOp", AML_CREATE_BIT_FIELD_OP), 0, 3, 2, {EAmlObject, EAmlObject, EAmlName, EAmlNone, EAmlNone, EAmlNone}, AML_IN_NAMESPACE},
206 /* 0x8E */ {AML_OPCODE_DEF ("ObjectTypeOp", AML_OBJECT_TYPE_OP), 0, 1, 0, {EAmlObject, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, 0},
207 /* 0x8F */ {AML_OPCODE_DEF ("CreateQWordFieldOp", AML_CREATE_QWORD_FIELD_OP),0, 3, 2, {EAmlObject, EAmlObject, EAmlName, EAmlNone, EAmlNone, EAmlNone}, AML_IN_NAMESPACE},
208 /* 0x90 */ {AML_OPCODE_DEF ("LAndOp", AML_LAND_OP), 0, 2, 0, {EAmlObject, EAmlObject, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, 0},
209 /* 0x91 */ {AML_OPCODE_DEF ("LOrOp", AML_LOR_OP), 0, 2, 0, {EAmlObject, EAmlObject, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, 0},
210 /* 0x92 */ {AML_OPCODE_DEF ("LNotOp", AML_LNOT_OP), 0, 1, 0, {EAmlObject, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, 0},
211 /* 0x93 */ {AML_OPCODE_DEF ("LEqualOp", AML_LEQUAL_OP), 0, 2, 0, {EAmlObject, EAmlObject, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, 0},
212 /* 0x94 */ {AML_OPCODE_DEF ("LGreaterOp", AML_LGREATER_OP), 0, 2, 0, {EAmlObject, EAmlObject, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, 0},
213 /* 0x95 */ {AML_OPCODE_DEF ("LLessOp", AML_LLESS_OP), 0, 2, 0, {EAmlObject, EAmlObject, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, 0},
214 /* 0x96 */ {AML_OPCODE_DEF ("ToBufferOp", AML_TO_BUFFER_OP), 0, 2, 0, {EAmlObject, EAmlObject, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, 0},
215 /* 0x97 */ {AML_OPCODE_DEF ("ToDecimalStringOp", AML_TO_DEC_STRING_OP), 0, 2, 0, {EAmlObject, EAmlObject, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, 0},
216 /* 0x98 */ {AML_OPCODE_DEF ("ToHexStringOp", AML_TO_HEX_STRING_OP), 0, 2, 0, {EAmlObject, EAmlObject, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, 0},
217 /* 0x99 */ {AML_OPCODE_DEF ("ToIntegerOp", AML_TO_INTEGER_OP), 0, 2, 0, {EAmlObject, EAmlObject, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, 0},
218 /* 0x9C */ {AML_OPCODE_DEF ("ToStringOp", AML_TO_STRING_OP), 0, 3, 0, {EAmlObject, EAmlObject, EAmlObject, EAmlNone, EAmlNone, EAmlNone}, 0},
219 /* 0x9D */ {AML_OPCODE_DEF ("CopyObjectOp", AML_COPY_OBJECT_OP), 0, 2, 0, {EAmlObject, EAmlObject, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, 0},
220 /* 0x9E */ {AML_OPCODE_DEF ("MidOp", AML_MID_OP), 0, 3, 0, {EAmlObject, EAmlObject, EAmlObject, EAmlNone, EAmlNone, EAmlNone}, 0},
221 /* 0x9F */ {AML_OPCODE_DEF ("ContinueOp", AML_CONTINUE_OP), 0, 0, 0, {EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, 0},
222 /* 0xA0 */ {AML_OPCODE_DEF ("IfOp", AML_IF_OP), 0, 1, 0, {EAmlObject, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, AML_HAS_PKG_LENGTH | AML_HAS_CHILD_OBJ},
223 /* 0xA1 */ {AML_OPCODE_DEF ("ElseOp", AML_ELSE_OP), 0, 0, 0, {EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, AML_HAS_PKG_LENGTH | AML_HAS_CHILD_OBJ},
224 /* 0xA2 */ {AML_OPCODE_DEF ("WhileOp", AML_WHILE_OP), 0, 1, 0, {EAmlObject, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, AML_HAS_PKG_LENGTH | AML_HAS_CHILD_OBJ},
225 /* 0xA3 */ {AML_OPCODE_DEF ("NoopOp", AML_NOOP_OP), 0, 0, 0, {EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, 0},
226 /* 0xA4 */ {AML_OPCODE_DEF ("ReturnOp", AML_RETURN_OP), 0, 1, 0, {EAmlObject, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, 0},
227 /* 0xA5 */ {AML_OPCODE_DEF ("BreakOp", AML_BREAK_OP), 0, 0, 0, {EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, 0},
228 /* 0xCC */ {AML_OPCODE_DEF ("BreakPointOp", AML_BREAK_POINT_OP), 0, 0, 0, {EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, 0},
229 /* 0xD0 */ {AML_OPCODE_DEF ("MethodInvocOp", AML_METHOD_INVOC_OP), 0, 2, 0, {EAmlName, EAmlUInt8, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, AML_IS_PSEUDO_OPCODE | AML_HAS_CHILD_OBJ},
230 /* 0xFF */ {AML_OPCODE_DEF ("OnesOp", AML_ONES_OP), 0, 0, 0, {EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, 0},
231 };
232
233 /** AML grammar encoding for field elements.
234
235 Some AML objects are expecting a FieldList. They are referred in this library
236 as field nodes. These objects have the following opcodes:
237 - FieldOp;
238 - IndexFieldOp;
239 - BankFieldOp.
240 In the AML grammar encoding table, they have the AML_HAS_FIELD_LIST
241 attribute.
242
243 A field list is made of field elements.
244 According to the ACPI 6.3 specification, s20.2.5.2 "Named Objects Encoding",
245 field elements can be:
246 - NamedField := NameSeg PkgLength;
247 - ReservedField := 0x00 PkgLength;
248 - AccessField := 0x01 AccessType AccessAttrib;
249 - ConnectField := <0x02 NameString> | <0x02 BufferData>;
250 - ExtendedAccessField := 0x03 AccessType ExtendedAccessAttrib AccessLength.
251
252 A small set of opcodes describes field elements. They are referred in this
253 library as field opcodes.
254 The NamedField field element doesn't have a field opcode. A pseudo
255 OpCode/SubOpCode couple has been created for it.
256
257 Field elements:
258 - don't have a SubOpCode;
259 - have at most 3 fixed arguments (6 for object opcodes,
260 8 for method invocations);
261 - don't have variable list of arguments;
262 - are not part of the AML namespace, except NamedField field elements.
263 */
264 GLOBAL_REMOVE_IF_UNREFERENCED
265 STATIC
266 CONST
267 AML_BYTE_ENCODING mAmlFieldEncoding[] = {
268 // Comment Str OpCode SubOpCode MaxIndex NameIndex 0 1 2 3 4 5 Attribute
269 /* 0x00 */ {AML_OPCODE_DEF ("FieldReservedOp", AML_FIELD_RESERVED_OP), 0, 0, 0, {EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, AML_IS_FIELD_ELEMENT | AML_HAS_PKG_LENGTH},
270 /* 0x01 */ {AML_OPCODE_DEF ("FieldAccessOp", AML_FIELD_ACCESS_OP), 0, 2, 0, {EAmlUInt8, EAmlUInt8, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, AML_IS_FIELD_ELEMENT},
271 /* 0x02 */ {AML_OPCODE_DEF ("FieldConnectionOp", AML_FIELD_CONNECTION_OP), 0, 1, 0, {EAmlObject, EAmlNone, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, AML_IS_FIELD_ELEMENT},
272 /* 0x03 */ {AML_OPCODE_DEF ("FieldExtAccessOp", AML_FIELD_EXT_ACCESS_OP), 0, 3, 0, {EAmlUInt8, EAmlUInt8, EAmlUInt8, EAmlNone, EAmlNone, EAmlNone}, AML_IS_FIELD_ELEMENT},
273 /* 0x04 */ {AML_OPCODE_DEF ("FieldNamed", AML_FIELD_NAMED_OP), 0, 2, 0, {EAmlName, EAmlFieldPkgLen, EAmlNone, EAmlNone, EAmlNone, EAmlNone}, AML_IS_FIELD_ELEMENT | AML_IS_PSEUDO_OPCODE | AML_IN_NAMESPACE}
274 };
275
276 /** Get the AML_BYTE_ENCODING entry in the AML encoding table.
277
278 Note: For Pseudo OpCodes this function returns NULL.
279
280 @param [in] Buffer Pointer to an OpCode/SubOpCode couple.
281 If *Buffer = 0x5b (extended OpCode),
282 Buffer must be at least two bytes long.
283
284 @return The corresponding AML_BYTE_ENCODING entry.
285 NULL if not found.
286 **/
287 CONST
288 AML_BYTE_ENCODING *
289 EFIAPI
290 AmlGetByteEncoding (
291 IN CONST UINT8 * Buffer
292 )
293 {
294 UINT8 OpCode;
295 UINT8 SubOpCode;
296 UINT32 Index;
297
298 if (Buffer == NULL) {
299 ASSERT (0);
300 return NULL;
301 }
302
303 // Get OpCode and SubOpCode.
304 OpCode = Buffer[0];
305 if (OpCode == AML_EXT_OP) {
306 SubOpCode = Buffer[1];
307 } else {
308 SubOpCode = 0;
309 }
310
311 // Search the table.
312 for (Index = 0;
313 Index < (sizeof (mAmlByteEncoding) / sizeof (mAmlByteEncoding[0]));
314 Index++) {
315 if ((mAmlByteEncoding[Index].OpCode == OpCode) &&
316 (mAmlByteEncoding[Index].SubOpCode == SubOpCode)) {
317 if ((mAmlByteEncoding[Index].Attribute & AML_IS_PSEUDO_OPCODE) ==
318 AML_IS_PSEUDO_OPCODE) {
319 // A pseudo OpCode cannot be parsed as it is internal to this library.
320 // The MethodInvocation encoding can be detected by NameSpace lookup.
321 ASSERT (0);
322 return NULL;
323 }
324 return &mAmlByteEncoding[Index];
325 }
326 }
327
328 return NULL;
329 }
330
331 /** Get the AML_BYTE_ENCODING entry in the AML encoding table
332 by providing an OpCode/SubOpCode couple.
333
334 @param [in] OpCode OpCode.
335 @param [in] SubOpCode SubOpCode.
336
337 @return The corresponding AML_BYTE_ENCODING entry.
338 NULL if not found.
339 **/
340 CONST
341 AML_BYTE_ENCODING *
342 EFIAPI
343 AmlGetByteEncodingByOpCode (
344 IN UINT8 OpCode,
345 IN UINT8 SubOpCode
346 )
347 {
348 UINT32 Index;
349
350 // Search the table.
351 for (Index = 0;
352 Index < (sizeof (mAmlByteEncoding) / sizeof (mAmlByteEncoding[0]));
353 Index++) {
354 if ((mAmlByteEncoding[Index].OpCode == OpCode) &&
355 (mAmlByteEncoding[Index].SubOpCode == SubOpCode)) {
356 return &mAmlByteEncoding[Index];
357 }
358 }
359 return NULL;
360 }
361
362 /** Get the AML_BYTE_ENCODING entry in the field encoding table.
363
364 Note: For Pseudo OpCodes this function returns NULL.
365
366 @param [in] Buffer Pointer to a field OpCode.
367 No SubOpCode is expected.
368
369 @return The corresponding AML_BYTE_ENCODING entry
370 in the field encoding table.
371 NULL if not found.
372 **/
373 CONST
374 AML_BYTE_ENCODING *
375 EFIAPI
376 AmlGetFieldEncoding (
377 IN CONST UINT8 * Buffer
378 )
379 {
380 UINT8 OpCode;
381 UINT32 Index;
382
383 if (Buffer == NULL) {
384 ASSERT (0);
385 return NULL;
386 }
387
388 // Get OpCode.
389 OpCode = *Buffer;
390
391 // Search in the table.
392 for (Index = 0;
393 Index < (sizeof (mAmlFieldEncoding) / sizeof (mAmlFieldEncoding[0]));
394 Index++) {
395 if (mAmlFieldEncoding[Index].OpCode == OpCode) {
396 if ((mAmlFieldEncoding[Index].Attribute & AML_IS_PSEUDO_OPCODE) ==
397 AML_IS_PSEUDO_OPCODE) {
398 // A pseudo OpCode cannot be parsed as it is internal to this library.
399 // The NamedField encoding can be detected because it begins with a
400 // char.
401 ASSERT (0);
402 return NULL;
403 }
404 return &mAmlFieldEncoding[Index];
405 }
406 }
407
408 return NULL;
409 }
410
411 /** Get the AML_BYTE_ENCODING entry in the field encoding table
412 by providing an OpCode/SubOpCode couple.
413
414 @param [in] OpCode OpCode.
415 @param [in] SubOpCode SubOpCode.
416
417 @return The corresponding AML_BYTE_ENCODING entry
418 in the field encoding table.
419 NULL if not found.
420 **/
421 CONST
422 AML_BYTE_ENCODING *
423 EFIAPI
424 AmlGetFieldEncodingByOpCode (
425 IN UINT8 OpCode,
426 IN UINT8 SubOpCode
427 )
428 {
429 UINT32 Index;
430
431 // Search the table.
432 for (Index = 0;
433 Index < (sizeof (mAmlFieldEncoding) / sizeof (mAmlFieldEncoding[0]));
434 Index++) {
435 if ((mAmlFieldEncoding[Index].OpCode == OpCode) &&
436 (mAmlFieldEncoding[Index].SubOpCode == SubOpCode)) {
437 return &mAmlFieldEncoding[Index];
438 }
439 }
440 return NULL;
441 }
442
443 // Enable this function for debug.
444 #if !defined (MDEPKG_NDEBUG)
445 /** Look for an OpCode/SubOpCode couple in the AML grammar,
446 and return a corresponding string.
447
448 @param [in] OpCode The OpCode.
449 @param [in] SubOpCode The SubOpCode.
450
451 @return A string describing the OpCode/SubOpCode couple.
452 NULL if not found.
453 **/
454 CONST
455 CHAR8 *
456 AmlGetOpCodeStr (
457 IN UINT8 OpCode,
458 IN UINT8 SubOpCode
459 )
460 {
461 EAML_PARSE_INDEX Index;
462
463 // Search the table.
464 for (Index = 0;
465 Index < (sizeof (mAmlByteEncoding) / sizeof (mAmlByteEncoding[0]));
466 Index++) {
467 if ((mAmlByteEncoding[Index].OpCode == OpCode) &&
468 (mAmlByteEncoding[Index].SubOpCode == SubOpCode)) {
469 return mAmlByteEncoding[Index].Str;
470 }
471 }
472
473 ASSERT (0);
474 return NULL;
475 }
476
477 /** Look for an OpCode/SubOpCode couple in the AML field element grammar,
478 and return a corresponding string.
479
480 @param [in] OpCode The OpCode.
481 @param [in] SubOpCode The SubOpCode. Must be zero.
482
483 @return A string describing the OpCode/SubOpCode couple.
484 NULL if not found.
485 **/
486 CONST
487 CHAR8 *
488 AmlGetFieldOpCodeStr (
489 IN UINT8 OpCode,
490 IN UINT8 SubOpCode
491 )
492 {
493 EAML_PARSE_INDEX Index;
494
495 if (SubOpCode != 0) {
496 ASSERT (0);
497 return NULL;
498 }
499
500 // Search the table.
501 for (Index = 0;
502 Index < (sizeof (mAmlFieldEncoding) / sizeof (mAmlFieldEncoding[0]));
503 Index++) {
504 if ((mAmlFieldEncoding[Index].OpCode == OpCode)) {
505 return mAmlFieldEncoding[Index].Str;
506 }
507 }
508
509 ASSERT (0);
510 return NULL;
511 }
512 #endif // MDEPKG_NDEBUG
513
514 /** Check whether the OpCode/SubOpcode couple is a valid entry
515 in the AML grammar encoding table.
516
517 @param [in] OpCode OpCode to check.
518 @param [in] SubOpCode SubOpCode to check.
519
520 @retval TRUE The OpCode/SubOpCode couple is valid.
521 @retval FALSE Otherwise.
522 **/
523 BOOLEAN
524 EFIAPI
525 AmlIsOpCodeValid (
526 IN UINT8 OpCode,
527 IN UINT8 SubOpCode
528 )
529 {
530 EAML_PARSE_INDEX Index;
531
532 // Search the table.
533 for (Index = 0;
534 Index < (sizeof (mAmlByteEncoding) / sizeof (mAmlByteEncoding[0]));
535 Index++) {
536 if ((mAmlByteEncoding[Index].OpCode == OpCode) &&
537 (mAmlByteEncoding[Index].SubOpCode == SubOpCode)) {
538 return TRUE;
539 }
540 }
541 return FALSE;
542 }
543
544 /** AML_PARSE_FORMAT to EAML_NODE_DATA_TYPE translation table.
545
546 AML_PARSE_FORMAT describes an internal set of values identifying the types
547 that can be found while parsing an AML bytestream.
548 EAML_NODE_DATA_TYPE describes an external set of values allowing to identify
549 what type of data can be found in data nodes.
550 */
551 GLOBAL_REMOVE_IF_UNREFERENCED
552 STATIC
553 CONST
554 EAML_NODE_DATA_TYPE mAmlTypeToNodeDataType[] = {
555 EAmlNodeDataTypeNone, // EAmlNone
556 EAmlNodeDataTypeUInt, // EAmlUInt8
557 EAmlNodeDataTypeUInt, // EAmlUInt16
558 EAmlNodeDataTypeUInt, // EAmlUInt32
559 EAmlNodeDataTypeUInt, // EAmlUInt64
560 EAmlNodeDataTypeReserved5, // EAmlObject
561 EAmlNodeDataTypeNameString, // EAmlName
562 EAmlNodeDataTypeString, // EAmlString
563 EAmlNodeDataTypeFieldPkgLen // EAmlFieldPkgLen
564 };
565
566 /** Convert an AML_PARSE_FORMAT to its corresponding EAML_NODE_DATA_TYPE.
567
568 @param [in] AmlType Input AML Type.
569
570 @return The corresponding EAML_NODE_DATA_TYPE.
571 EAmlNodeDataTypeNone if not found.
572 **/
573 EAML_NODE_DATA_TYPE
574 EFIAPI
575 AmlTypeToNodeDataType (
576 IN AML_PARSE_FORMAT AmlType
577 )
578 {
579 if (AmlType >=
580 (sizeof (mAmlTypeToNodeDataType) / sizeof (mAmlTypeToNodeDataType[0]))) {
581 ASSERT (0);
582 return EAmlNodeDataTypeNone;
583 }
584
585 return mAmlTypeToNodeDataType[AmlType];
586 }
587
588 /** Get the package length from the buffer.
589
590 @param [in] Buffer AML buffer.
591 @param [out] PkgLength The interpreted PkgLen value.
592 Length cannot exceed 2^28.
593
594 @return The number of bytes to represent the package length.
595 0 if an issue occurred.
596 **/
597 UINT32
598 EFIAPI
599 AmlGetPkgLength (
600 IN CONST UINT8 * Buffer,
601 OUT UINT32 * PkgLength
602 )
603 {
604 UINT8 LeadByte;
605 UINT8 ByteCount;
606 UINT32 RealLength;
607 UINT32 Offset;
608
609 if ((Buffer == NULL) ||
610 (PkgLength == NULL)) {
611 ASSERT (0);
612 return 0;
613 }
614
615 /* From ACPI 6.3 specification, s20.2.4 "Package Length Encoding":
616
617 PkgLength := PkgLeadByte |
618 <PkgLeadByte ByteData> |
619 <PkgLeadByte ByteData ByteData> |
620 <PkgLeadByte ByteData ByteData ByteData>
621
622 PkgLeadByte := <bit 7-6: ByteData count that follows (0-3)>
623 <bit 5-4: Only used if PkgLength < 63>
624 <bit 3-0: Least significant package length nibble>
625
626 Note:
627 The high 2 bits of the first byte reveal how many
628 follow bytes are in the PkgLength. If the
629 PkgLength has only one byte, bit 0 through 5 are
630 used to encode the package length (in other
631 words, values 0-63). If the package length value
632 is more than 63, more than one byte must be
633 used for the encoding in which case bit 4 and 5 of
634 the PkgLeadByte are reserved and must be zero.
635 If the multiple bytes encoding is used, bits 0-3 of
636 the PkgLeadByte become the least significant 4
637 bits of the resulting package length value. The next
638 ByteData will become the next least
639 significant 8 bits of the resulting value and so on,
640 up to 3 ByteData bytes. Thus, the maximum
641 package length is 2**28.
642 */
643
644 LeadByte = *Buffer;
645 ByteCount = (LeadByte >> 6) & 0x03U;
646 Offset = ByteCount + 1U;
647 RealLength = 0;
648
649 // Switch on the number of bytes used to store the PkgLen.
650 switch (ByteCount) {
651 case 0:
652 {
653 RealLength = LeadByte;
654 break;
655 }
656 case 1:
657 {
658 RealLength = *(Buffer + 1);
659 RealLength = (RealLength << 4) | (LeadByte & 0xF);
660 break;
661 }
662 case 2:
663 {
664 RealLength = *(Buffer + 1);
665 RealLength |= ((UINT32)(*(Buffer + 2))) << 8;
666 RealLength = (RealLength << 4) | (LeadByte & 0xF);
667 break;
668 }
669 case 3:
670 {
671 RealLength = *(Buffer + 1);
672 RealLength |= ((UINT32)(*(Buffer + 2))) << 8;
673 RealLength |= ((UINT32)(*(Buffer + 3))) << 16;
674 RealLength = (RealLength << 4) | (LeadByte & 0xF);
675 break;
676 }
677 default:
678 {
679 ASSERT (0);
680 Offset = 0;
681 break;
682 }
683 } // switch
684
685 *PkgLength = RealLength;
686
687 return Offset;
688 }
689
690 /** Convert the Length to the AML PkgLen encoding,
691 then and write it in the Buffer.
692
693 @param [in] Length Length to convert.
694 Length cannot exceed 2^28.
695 @param [out] Buffer Write the result in this Buffer.
696
697 @return The number of bytes used to write the Length.
698 **/
699 UINT8
700 EFIAPI
701 AmlSetPkgLength (
702 IN UINT32 Length,
703 OUT UINT8 * Buffer
704 )
705 {
706 UINT8 LeadByte;
707 UINT8 Offset;
708 UINT8 CurrentOffset;
709 UINT8 CurrentShift;
710 UINT32 ComputedLength;
711
712 if (Buffer == NULL) {
713 ASSERT (0);
714 return 0;
715 }
716
717 LeadByte = 0;
718 Offset = 0;
719
720 if ((Length < (1 << 6))) {
721 // Length < 2^6, only need one byte to encode it.
722 LeadByte = (UINT8)Length;
723
724 } else {
725 // Need more than one byte to encode it.
726 // Test Length to find how many bytes are needed.
727
728 if (Length >= (1 << 28)) {
729 // Length >= 2^28, should not be possible.
730 ASSERT (0);
731 return 0;
732
733 } else if (Length >= (1 << 20)) {
734 // Length >= 2^20
735 Offset = 3;
736
737 } else if (Length >= (1 << 12)) {
738 // Length >= 2^12
739 Offset = 2;
740
741 } else if (Length >= (1 << 6)) {
742 // Length >= 2^6
743 Offset = 1;
744
745 } else {
746 // Should not be possible.
747 ASSERT (0);
748 return 0;
749 }
750
751 // Set the LeadByte.
752 LeadByte = (UINT8)(Offset << 6);
753 LeadByte = (UINT8)(LeadByte | (Length & 0xF));
754 }
755
756 // Write to the Buffer.
757 *Buffer = LeadByte;
758 CurrentOffset = 1;
759 while (CurrentOffset < (Offset + 1)) {
760 CurrentShift = (UINT8)((CurrentOffset - 1) * 8);
761 ComputedLength = Length & (UINT32)(0x00000FF0 << CurrentShift);
762 ComputedLength = (ComputedLength) >> (4 + CurrentShift);
763 LeadByte = (UINT8)(ComputedLength & 0xFF);
764 *(Buffer + CurrentOffset) = LeadByte;
765 CurrentOffset++;
766 }
767
768 return ++Offset;
769 }
770
771 /** Compute the number of bytes required to write a package length.
772
773 @param [in] Length The length to convert in the AML package length
774 encoding style.
775 Length cannot exceed 2^28.
776
777 @return The number of bytes required to write the Length.
778 **/
779 UINT8
780 EFIAPI
781 AmlComputePkgLengthWidth (
782 IN UINT32 Length
783 )
784 {
785 // Length >= 2^28, should not be possible.
786 if (Length >= (1 << 28)) {
787 ASSERT (0);
788 return 0;
789
790 } else if (Length >= (1 << 20)) {
791 // Length >= 2^20
792 return 4;
793
794 } else if (Length >= (1 << 12)) {
795 // Length >= 2^12
796 return 3;
797
798 } else if (Length >= (1 << 6)) {
799 // Length >= 2^6
800 return 2;
801 }
802
803 // Length < 2^6
804 return 1;
805 }
806
807 /** Given a length, compute the value of a PkgLen.
808
809 In AML, some object have a PkgLen, telling the size of the AML object.
810 It can be encoded in 1 to 4 bytes. The bytes used to encode the PkgLen is
811 itself counted in the PkgLen value.
812 This means that if an AML object sees its size increment/decrement,
813 the number of bytes used to encode the PkgLen value can itself
814 increment/decrement.
815
816 For instance, the AML encoding of a DeviceOp is:
817 DefDevice := DeviceOp PkgLength NameString TermList
818 If:
819 - sizeof (NameString) = 4 (the name is "DEV0" for instance);
820 - sizeof (TermList) = (2^6-6)
821 then the PkgLen is encoded on 1 byte. Indeed, its value is:
822 sizeof (PkgLen) + sizeof (NameString) + sizeof (TermList) =
823 sizeof (PkgLen) + 4 + (2^6-6)
824 So:
825 PkgLen = sizeof (PkgLen) + (2^6-2)
826
827 The input arguments Length and PkgLen represent, for the DefDevice:
828 DefDevice := DeviceOp PkgLength NameString TermList
829 |------Length-----|
830 |--------*PgkLength---------|
831
832 @param [in] Length The length to encode as a PkgLen.
833 Length cannot exceed 2^28 - 4 (4 bytes for the
834 PkgLen encoding).
835 The size of the PkgLen encoding bytes should not be
836 counted in this length value.
837 @param [out] PkgLen If success, contains the value of the PkgLen,
838 ready to encode in the PkgLen format.
839 This value takes into account the size of PkgLen
840 encoding.
841
842 @retval EFI_SUCCESS The function completed successfully.
843 @retval EFI_INVALID_PARAMETER Invalid parameter.
844 **/
845 EFI_STATUS
846 EFIAPI
847 AmlComputePkgLength (
848 IN UINT32 Length,
849 OUT UINT32 * PkgLen
850 )
851 {
852 UINT32 PkgLenWidth;
853 UINT32 ReComputedPkgLenWidth;
854
855 if (PkgLen == NULL) {
856 ASSERT (0);
857 return EFI_INVALID_PARAMETER;
858 }
859
860 // Compute the PkgLenWidth.
861 PkgLenWidth = AmlComputePkgLengthWidth (Length);
862 if (PkgLenWidth == 0) {
863 ASSERT (0);
864 return EFI_INVALID_PARAMETER;
865 }
866
867 // Add it to the Length.
868 Length += PkgLenWidth;
869
870 // Check that adding the PkgLenWidth didn't trigger a domino effect,
871 // increasing the encoding width of the PkgLen again.
872 // The PkgLen is encoded in at most 4 bytes. It is possible to increase
873 // the PkgLen width if its encoding is less than 3 bytes.
874 ReComputedPkgLenWidth = AmlComputePkgLengthWidth (Length);
875 if (ReComputedPkgLenWidth != PkgLenWidth) {
876 if ((ReComputedPkgLenWidth != 0) &&
877 (ReComputedPkgLenWidth < 4)) {
878 // No need to recompute the PkgLen since a new threshold cannot
879 // be reached by incrementing the value by one.
880 Length += 1;
881 } else {
882 ASSERT (0);
883 return EFI_INVALID_PARAMETER;
884 }
885 }
886
887 *PkgLen = Length;
888
889 return EFI_SUCCESS;
890 }