1 | /* $Id: acpi-ast.cpp 108059 2025-02-04 13:35:41Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IPRT - Advanced Configuration and Power Interface (ACPI) AST handling.
|
---|
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 |
|
---|
38 | /*********************************************************************************************************************************
|
---|
39 | * Header Files *
|
---|
40 | *********************************************************************************************************************************/
|
---|
41 | #define LOG_GROUP RTLOGGROUP_ACPI
|
---|
42 | #include <iprt/assert.h>
|
---|
43 | #include <iprt/errcore.h>
|
---|
44 | #include <iprt/list.h>
|
---|
45 | #include <iprt/mem.h>
|
---|
46 |
|
---|
47 | #include <iprt/formats/acpi-aml.h>
|
---|
48 |
|
---|
49 | #include "internal/acpi.h"
|
---|
50 |
|
---|
51 |
|
---|
52 | /*********************************************************************************************************************************
|
---|
53 | * Defined Constants And Macros *
|
---|
54 | *********************************************************************************************************************************/
|
---|
55 |
|
---|
56 |
|
---|
57 | /*********************************************************************************************************************************
|
---|
58 | * Structures and Typedefs *
|
---|
59 | *********************************************************************************************************************************/
|
---|
60 |
|
---|
61 |
|
---|
62 | /*********************************************************************************************************************************
|
---|
63 | * Global Variables *
|
---|
64 | *********************************************************************************************************************************/
|
---|
65 |
|
---|
66 |
|
---|
67 | /*********************************************************************************************************************************
|
---|
68 | * Internal Functions *
|
---|
69 | *********************************************************************************************************************************/
|
---|
70 |
|
---|
71 | DECLHIDDEN(PRTACPIASTNODE) rtAcpiAstNodeAlloc(RTACPIASTNODEOP enmOp, uint32_t fFlags, uint8_t cArgs)
|
---|
72 | {
|
---|
73 | PRTACPIASTNODE pAstNd = (PRTACPIASTNODE)RTMemAllocZ(RT_UOFFSETOF_DYN(RTACPIASTNODE, aArgs[cArgs]));
|
---|
74 | if (pAstNd)
|
---|
75 | {
|
---|
76 | pAstNd->enmOp = enmOp;
|
---|
77 | pAstNd->fFlags = fFlags;
|
---|
78 | pAstNd->cArgs = cArgs;
|
---|
79 | RTListInit(&pAstNd->LstScopeNodes);
|
---|
80 | }
|
---|
81 |
|
---|
82 | return pAstNd;
|
---|
83 | }
|
---|
84 |
|
---|
85 |
|
---|
86 | DECLHIDDEN(void) rtAcpiAstNodeFree(PRTACPIASTNODE pAstNd)
|
---|
87 | {
|
---|
88 | /** @todo */
|
---|
89 | RTMemFree(pAstNd);
|
---|
90 | }
|
---|
91 |
|
---|
92 |
|
---|
93 | static int rtAcpiAstDumpAstList(PCRTLISTANCHOR pLst, RTACPITBL hAcpiTbl)
|
---|
94 | {
|
---|
95 | PCRTACPIASTNODE pIt;
|
---|
96 | RTListForEach(pLst, pIt, RTACPIASTNODE, NdAst)
|
---|
97 | {
|
---|
98 | int rc = rtAcpiAstDumpToTbl(pIt, hAcpiTbl);
|
---|
99 | if (RT_FAILURE(rc))
|
---|
100 | return rc;
|
---|
101 | }
|
---|
102 |
|
---|
103 | return VINF_SUCCESS;
|
---|
104 | }
|
---|
105 |
|
---|
106 |
|
---|
107 | DECLHIDDEN(int) rtAcpiAstDumpToTbl(PCRTACPIASTNODE pAstNd, RTACPITBL hAcpiTbl)
|
---|
108 | {
|
---|
109 | int rc;
|
---|
110 |
|
---|
111 | switch (pAstNd->enmOp)
|
---|
112 | {
|
---|
113 | case kAcpiAstNodeOp_Scope:
|
---|
114 | {
|
---|
115 | AssertBreakStmt( pAstNd->cArgs == 1
|
---|
116 | && pAstNd->aArgs[0].enmType == kAcpiAstArgType_NameString,
|
---|
117 | rc = VERR_INTERNAL_ERROR);
|
---|
118 | rc = RTAcpiTblScopeStart(hAcpiTbl, pAstNd->aArgs[0].u.pszNameString);
|
---|
119 | if (RT_SUCCESS(rc))
|
---|
120 | {
|
---|
121 | /* Walk all the other AST nodes. */
|
---|
122 | rc = rtAcpiAstDumpAstList(&pAstNd->LstScopeNodes, hAcpiTbl);
|
---|
123 | if (RT_SUCCESS(rc))
|
---|
124 | rc = RTAcpiTblScopeFinalize(hAcpiTbl);
|
---|
125 | }
|
---|
126 | break;
|
---|
127 | }
|
---|
128 | case kAcpiAstNodeOp_Processor:
|
---|
129 | {
|
---|
130 | AssertBreakStmt( pAstNd->cArgs == 4
|
---|
131 | && pAstNd->aArgs[0].enmType == kAcpiAstArgType_NameString
|
---|
132 | && pAstNd->aArgs[1].enmType == kAcpiAstArgType_U8
|
---|
133 | && pAstNd->aArgs[2].enmType == kAcpiAstArgType_U32
|
---|
134 | && pAstNd->aArgs[3].enmType == kAcpiAstArgType_U8,
|
---|
135 | rc = VERR_INTERNAL_ERROR);
|
---|
136 | rc = RTAcpiTblProcessorStart(hAcpiTbl,
|
---|
137 | pAstNd->aArgs[0].u.pszNameString,
|
---|
138 | pAstNd->aArgs[1].u.u8,
|
---|
139 | pAstNd->aArgs[2].u.u32,
|
---|
140 | pAstNd->aArgs[3].u.u8);
|
---|
141 | if (RT_SUCCESS(rc))
|
---|
142 | {
|
---|
143 | /* Walk all the other AST nodes. */
|
---|
144 | rc = rtAcpiAstDumpAstList(&pAstNd->LstScopeNodes, hAcpiTbl);
|
---|
145 | if (RT_SUCCESS(rc))
|
---|
146 | rc = RTAcpiTblProcessorFinalize(hAcpiTbl);
|
---|
147 | }
|
---|
148 | break;
|
---|
149 | }
|
---|
150 | case kAcpiAstNodeOp_External:
|
---|
151 | {
|
---|
152 | AssertBreakStmt( pAstNd->cArgs == 3
|
---|
153 | && pAstNd->aArgs[0].enmType == kAcpiAstArgType_NameString
|
---|
154 | && pAstNd->aArgs[1].enmType == kAcpiAstArgType_ObjType
|
---|
155 | && pAstNd->aArgs[2].enmType == kAcpiAstArgType_U8,
|
---|
156 | rc = VERR_INTERNAL_ERROR);
|
---|
157 | rc = RTAcpiTblExternalAppend(hAcpiTbl, pAstNd->aArgs[0].u.pszNameString, pAstNd->aArgs[1].u.enmObjType, pAstNd->aArgs[2].u.u8);
|
---|
158 | }
|
---|
159 | case kAcpiAstNodeOp_Method:
|
---|
160 | {
|
---|
161 | AssertBreakStmt( pAstNd->cArgs == 4
|
---|
162 | && pAstNd->aArgs[0].enmType == kAcpiAstArgType_NameString
|
---|
163 | && pAstNd->aArgs[1].enmType == kAcpiAstArgType_U8
|
---|
164 | && pAstNd->aArgs[2].enmType == kAcpiAstArgType_Bool
|
---|
165 | && pAstNd->aArgs[3].enmType == kAcpiAstArgType_U8,
|
---|
166 | rc = VERR_INTERNAL_ERROR);
|
---|
167 | rc = RTAcpiTblMethodStart(hAcpiTbl, pAstNd->aArgs[0].u.pszNameString,
|
---|
168 | pAstNd->aArgs[1].u.u8,
|
---|
169 | pAstNd->aArgs[1].u.f ? RTACPI_METHOD_F_SERIALIZED : RTACPI_METHOD_F_NOT_SERIALIZED,
|
---|
170 | pAstNd->aArgs[1].u.u8);
|
---|
171 | if (RT_SUCCESS(rc))
|
---|
172 | {
|
---|
173 | /* Walk all the other AST nodes. */
|
---|
174 | rc = rtAcpiAstDumpAstList(&pAstNd->LstScopeNodes, hAcpiTbl);
|
---|
175 | if (RT_SUCCESS(rc))
|
---|
176 | rc = RTAcpiTblMethodFinalize(hAcpiTbl);
|
---|
177 | }
|
---|
178 | }
|
---|
179 | default:
|
---|
180 | AssertFailedStmt(rc = VERR_NOT_IMPLEMENTED);
|
---|
181 | }
|
---|
182 |
|
---|
183 | return rc;
|
---|
184 | }
|
---|