1 | /* $Id: acpi.h 108087 2025-02-05 18:38:43Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IPRT - Internal RTAcpi header.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2025 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.virtualbox.org.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or
|
---|
13 | * modify it under the terms of the GNU General Public License
|
---|
14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
15 | * License.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful, but
|
---|
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | * General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | *
|
---|
25 | * The contents of this file may alternatively be used under the terms
|
---|
26 | * of the Common Development and Distribution License Version 1.0
|
---|
27 | * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
---|
28 | * in the VirtualBox distribution, in which case the provisions of the
|
---|
29 | * CDDL are applicable instead of those of the GPL.
|
---|
30 | *
|
---|
31 | * You may elect to license modified versions of this file under the
|
---|
32 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
33 | *
|
---|
34 | * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
35 | */
|
---|
36 |
|
---|
37 | #ifndef IPRT_INCLUDED_INTERNAL_acpi_h
|
---|
38 | #define IPRT_INCLUDED_INTERNAL_acpi_h
|
---|
39 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
40 | # pragma once
|
---|
41 | #endif
|
---|
42 |
|
---|
43 | #include <iprt/acpi.h>
|
---|
44 | #include <iprt/list.h>
|
---|
45 |
|
---|
46 | RT_C_DECLS_BEGIN
|
---|
47 |
|
---|
48 | /** Pointer to an ACPI AST node. */
|
---|
49 | typedef struct RTACPIASTNODE *PRTACPIASTNODE;
|
---|
50 | /** Pointer to a const ACPI AST node. */
|
---|
51 | typedef const struct RTACPIASTNODE *PCRTACPIASTNODE;
|
---|
52 |
|
---|
53 | /**
|
---|
54 | * AST node argument type.
|
---|
55 | */
|
---|
56 | typedef enum RTACPIASTARGTYPE
|
---|
57 | {
|
---|
58 | kAcpiAstArgType_Invalid = 0,
|
---|
59 | kAcpiAstArgType_AstNode,
|
---|
60 | kAcpiAstArgType_NameString,
|
---|
61 | kAcpiAstArgType_Bool,
|
---|
62 | kAcpiAstArgType_U8,
|
---|
63 | kAcpiAstArgType_U16,
|
---|
64 | kAcpiAstArgType_U32,
|
---|
65 | kAcpiAstArgType_U64,
|
---|
66 | kAcpiAstArgType_ObjType,
|
---|
67 | kAcpiAstArgType_RegionSpace,
|
---|
68 | kAcpiAstArgType_FieldAcc,
|
---|
69 | kAcpiAstArgType_FieldUpdate,
|
---|
70 | kAcpiAstArgType_32Bit_Hack = 0x7fffffff
|
---|
71 | } RTACPIASTARGTYPE;
|
---|
72 |
|
---|
73 |
|
---|
74 | /**
|
---|
75 | * An AST node argument
|
---|
76 | */
|
---|
77 | typedef struct RTACPIASTARG
|
---|
78 | {
|
---|
79 | /** Argument type. */
|
---|
80 | RTACPIASTARGTYPE enmType;
|
---|
81 | /** Type dependent data. */
|
---|
82 | union
|
---|
83 | {
|
---|
84 | uintptr_t uPtrInternal;
|
---|
85 | PRTACPIASTNODE pAstNd;
|
---|
86 | const char *pszNameString;
|
---|
87 | bool f;
|
---|
88 | uint8_t u8;
|
---|
89 | uint16_t u16;
|
---|
90 | uint32_t u32;
|
---|
91 | uint64_t u64;
|
---|
92 | RTACPIOBJTYPE enmObjType;
|
---|
93 | RTACPIOPREGIONSPACE enmRegionSpace;
|
---|
94 | RTACPIFIELDACC enmFieldAcc;
|
---|
95 | RTACPIFIELDUPDATE enmFieldUpdate;
|
---|
96 | } u;
|
---|
97 | } RTACPIASTARG;
|
---|
98 | /** Pointer to an AST node argument. */
|
---|
99 | typedef RTACPIASTARG *PRTACPIASTARG;
|
---|
100 | /** Pointer to a const AST node argument. */
|
---|
101 | typedef const RTACPIASTARG *PCRTACPIASTARG;
|
---|
102 |
|
---|
103 |
|
---|
104 | /**
|
---|
105 | * The ACPI AST node op.
|
---|
106 | */
|
---|
107 | typedef enum RTACPIASTNODEOP
|
---|
108 | {
|
---|
109 | kAcpiAstNodeOp_Invalid = 0,
|
---|
110 | kAcpiAstNodeOp_Identifier,
|
---|
111 | kAcpiAstNodeOp_StringLiteral,
|
---|
112 | kAcpiAstNodeOp_Number,
|
---|
113 | kAcpiAstNodeOp_Scope,
|
---|
114 | kAcpiAstNodeOp_Processor,
|
---|
115 | kAcpiAstNodeOp_External,
|
---|
116 | kAcpiAstNodeOp_Method,
|
---|
117 | kAcpiAstNodeOp_Device,
|
---|
118 | kAcpiAstNodeOp_If,
|
---|
119 | kAcpiAstNodeOp_Else,
|
---|
120 | kAcpiAstNodeOp_LAnd,
|
---|
121 | kAcpiAstNodeOp_LEqual,
|
---|
122 | kAcpiAstNodeOp_LGreater,
|
---|
123 | kAcpiAstNodeOp_LGreaterEqual,
|
---|
124 | kAcpiAstNodeOp_LLess,
|
---|
125 | kAcpiAstNodeOp_LLessEqual,
|
---|
126 | kAcpiAstNodeOp_LNot,
|
---|
127 | kAcpiAstNodeOp_LNotEqual,
|
---|
128 | kAcpiAstNodeOp_Zero,
|
---|
129 | kAcpiAstNodeOp_One,
|
---|
130 | kAcpiAstNodeOp_Ones,
|
---|
131 | kAcpiAstNodeOp_Return,
|
---|
132 | kAcpiAstNodeOp_Unicode,
|
---|
133 | kAcpiAstNodeOp_OperationRegion,
|
---|
134 | kAcpiAstNodeOp_Field,
|
---|
135 | kAcpiAstNodeOp_Name,
|
---|
136 | kAcpiAstNodeOp_ResourceTemplate,
|
---|
137 | kAcpiAstNodeOp_Arg0,
|
---|
138 | kAcpiAstNodeOp_Arg1,
|
---|
139 | kAcpiAstNodeOp_Arg2,
|
---|
140 | kAcpiAstNodeOp_Arg3,
|
---|
141 | kAcpiAstNodeOp_Arg4,
|
---|
142 | kAcpiAstNodeOp_Arg5,
|
---|
143 | kAcpiAstNodeOp_Arg6,
|
---|
144 | kAcpiAstNodeOp_Local0,
|
---|
145 | kAcpiAstNodeOp_Local1,
|
---|
146 | kAcpiAstNodeOp_Local2,
|
---|
147 | kAcpiAstNodeOp_Local3,
|
---|
148 | kAcpiAstNodeOp_Local4,
|
---|
149 | kAcpiAstNodeOp_Local5,
|
---|
150 | kAcpiAstNodeOp_Local6,
|
---|
151 | kAcpiAstNodeOp_Local7,
|
---|
152 | kAcpiAstNodeOp_Package,
|
---|
153 | kAcpiAstNodeOp_Buffer,
|
---|
154 | kAcpiAstNodeOp_ToUuid,
|
---|
155 | kAcpiAstNodeOp_DerefOf,
|
---|
156 | kAcpiAstNodeOp_Index,
|
---|
157 | kAcpiAstNodeOp_Store,
|
---|
158 | kAcpiAstNodeOp_Break,
|
---|
159 | kAcpiAstNodeOp_Continue,
|
---|
160 | kAcpiAstNodeOp_Add,
|
---|
161 | kAcpiAstNodeOp_Subtract,
|
---|
162 | kAcpiAstNodeOp_And,
|
---|
163 | kAcpiAstNodeOp_Nand,
|
---|
164 | kAcpiAstNodeOp_Or,
|
---|
165 | kAcpiAstNodeOp_Xor,
|
---|
166 | kAcpiAstNodeOp_Not,
|
---|
167 | kAcpiAstNodeOp_32Bit_Hack = 0x7fffffff
|
---|
168 | } RTACPIASTNODEOP;
|
---|
169 |
|
---|
170 |
|
---|
171 | /**
|
---|
172 | * The core ACPI AST node.
|
---|
173 | */
|
---|
174 | typedef struct RTACPIASTNODE
|
---|
175 | {
|
---|
176 | /** List node. */
|
---|
177 | RTLISTNODE NdAst;
|
---|
178 | /** The AML op defining the node. */
|
---|
179 | RTACPIASTNODEOP enmOp;
|
---|
180 | /** Some additional flags. */
|
---|
181 | uint32_t fFlags;
|
---|
182 | /** Operation dependent data. */
|
---|
183 | union
|
---|
184 | {
|
---|
185 | /** List of other AST nodes for the opened scope if indicated by the AST flags (RTACPIASTNODE). */
|
---|
186 | RTLISTANCHOR LstScopeNodes;
|
---|
187 | /** Pointer to the identifier if an identifier node. */
|
---|
188 | const char *pszIde;
|
---|
189 | /** Pointer to the string literal if a string literal node. */
|
---|
190 | const char *pszStrLit;
|
---|
191 | /** A number */
|
---|
192 | uint64_t u64;
|
---|
193 | struct
|
---|
194 | {
|
---|
195 | /** Pointer to the field unit list - freed with RTMemFree() when the node is freed. */
|
---|
196 | PRTACPIFIELDENTRY paFields;
|
---|
197 | /** Number of field entries. */
|
---|
198 | uint32_t cFields;
|
---|
199 | } Fields;
|
---|
200 | /** The resource template. */
|
---|
201 | RTACPIRES hAcpiRes;
|
---|
202 | };
|
---|
203 | /** Number of "arguments" for the opcode following (for example Scope(), Method(), If(), etc., i.e. anything requiring () after the keyword ). */
|
---|
204 | uint8_t cArgs;
|
---|
205 | /** Padding */
|
---|
206 | uint8_t abRsvd[2];
|
---|
207 | /** The AST node arguments - variable in size. */
|
---|
208 | RTACPIASTARG aArgs[1];
|
---|
209 | } RTACPIASTNODE;
|
---|
210 |
|
---|
211 | /** Default flags. */
|
---|
212 | #define RTACPI_AST_NODE_F_DEFAULT 0
|
---|
213 | /** The AST node opens a new scope. */
|
---|
214 | #define RTACPI_AST_NODE_F_NEW_SCOPE RT_BIT_32(0)
|
---|
215 |
|
---|
216 |
|
---|
217 | /**
|
---|
218 | * Allocates a new ACPI AST node initialized with the given properties.
|
---|
219 | *
|
---|
220 | * @returns Pointer to the new ACPI AST node or NULL if out of memory.
|
---|
221 | * @param enmOp The operation of the AST node.
|
---|
222 | * @param fFlags Flags for this node.
|
---|
223 | * @param cArgs Number of arguments to allocate.
|
---|
224 | */
|
---|
225 | DECLHIDDEN(PRTACPIASTNODE) rtAcpiAstNodeAlloc(RTACPIASTNODEOP enmOp, uint32_t fFlags, uint8_t cArgs);
|
---|
226 |
|
---|
227 |
|
---|
228 | /**
|
---|
229 | * Frees the given AST node and all children nodes linked to this one.
|
---|
230 | *
|
---|
231 | * @param pAstNd The AST node to free.
|
---|
232 | */
|
---|
233 | DECLHIDDEN(void) rtAcpiAstNodeFree(PRTACPIASTNODE pAstNd);
|
---|
234 |
|
---|
235 |
|
---|
236 | /**
|
---|
237 | * Does a few transformations on the given AST node and its children where required.
|
---|
238 | *
|
---|
239 | * @returns IPRT status.
|
---|
240 | * @param pAstNd The AST node to transform.
|
---|
241 | * @param pErrInfo Some additional error information on failure.
|
---|
242 | *
|
---|
243 | * @note This currently only implements merging if ... else ... nodes but can be extended to
|
---|
244 | * also do some optimizations and proper checking.
|
---|
245 | */
|
---|
246 | DECLHIDDEN(int) rtAcpiAstNodeTransform(PRTACPIASTNODE pAstNd, PRTERRINFO pErrInfo);
|
---|
247 |
|
---|
248 |
|
---|
249 | /**
|
---|
250 | * Dumps the given AST node and everything it references to the given ACPI table.
|
---|
251 | *
|
---|
252 | * @returns IPRT status code.
|
---|
253 | * @param pAstNd The AST node to dump.
|
---|
254 | * @param hAcpiTbl The ACPI table to dump to.
|
---|
255 | */
|
---|
256 | DECLHIDDEN(int) rtAcpiAstDumpToTbl(PCRTACPIASTNODE pAstNd, RTACPITBL hAcpiTbl);
|
---|
257 |
|
---|
258 |
|
---|
259 | /**
|
---|
260 | * Worker for decompiling AML bytecode to the ASL source language.
|
---|
261 | *
|
---|
262 | * @returns IPRT status code.
|
---|
263 | * @param hVfsIosOut The VFS I/O stream handle to output the result to.
|
---|
264 | * @param hVfsIosIn The VFS I/O stream handle to read the ACPI table from.
|
---|
265 | * @param pErrInfo Where to return additional error information.
|
---|
266 | */
|
---|
267 | DECLHIDDEN(int) rtAcpiTblConvertFromAmlToAsl(RTVFSIOSTREAM hVfsIosOut, RTVFSIOSTREAM hVfsIosIn, PRTERRINFO pErrInfo);
|
---|
268 |
|
---|
269 |
|
---|
270 | /**
|
---|
271 | * Worker for compiling ASL to the AML bytecode.
|
---|
272 | *
|
---|
273 | * @returns IPRT status code.
|
---|
274 | * @param hVfsIosOut The VFS I/O stream handle to output the result to.
|
---|
275 | * @param hVfsIosIn The VFS I/O stream handle to read the ACPI table from.
|
---|
276 | * @param pErrInfo Where to return additional error information.
|
---|
277 | */
|
---|
278 | DECLHIDDEN(int) rtAcpiTblConvertFromAslToAml(RTVFSIOSTREAM hVfsIosOut, RTVFSIOSTREAM hVfsIosIn, PRTERRINFO pErrInfo);
|
---|
279 |
|
---|
280 |
|
---|
281 | RT_C_DECLS_END
|
---|
282 |
|
---|
283 | #endif /* !IPRT_INCLUDED_INTERNAL_acpi_h */
|
---|
284 |
|
---|