VirtualBox

source: vbox/trunk/include/iprt/acpi.h@ 108029

Last change on this file since 108029 was 108029, checked in by vboxsync, 3 weeks ago

Runtime/RTAcpi: Some more work on the ASL -> AML compiler, can process our vbox-standard.dsl now, bugref:10733

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 34.3 KB
Line 
1/** @file
2 * IPRT - Advanced Configuration and Power Interface (ACPI) Table generation API.
3 */
4
5/*
6 * Copyright (C) 2024 Oracle and/or its affiliates.
7 *
8 * This file is part of VirtualBox base platform packages, as
9 * available from https://www.virtualbox.org.
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation, in version 3 of the
14 * License.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, see <https://www.gnu.org/licenses>.
23 *
24 * The contents of this file may alternatively be used under the terms
25 * of the Common Development and Distribution License Version 1.0
26 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
27 * in the VirtualBox distribution, in which case the provisions of the
28 * CDDL are applicable instead of those of the GPL.
29 *
30 * You may elect to license modified versions of this file under the
31 * terms and conditions of either the GPL or the CDDL or both.
32 *
33 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
34 */
35
36#ifndef IPRT_INCLUDED_acpi_h
37#define IPRT_INCLUDED_acpi_h
38#ifndef RT_WITHOUT_PRAGMA_ONCE
39# pragma once
40#endif
41
42#include <iprt/cdefs.h>
43#include <iprt/types.h>
44#include <iprt/vfs.h>
45
46#include <iprt/formats/acpi-tables.h>
47
48
49RT_C_DECLS_BEGIN
50
51/** @defgroup grp_rt_acpi RTAcpi - Advanced Configuration and Power Interface (ACPI) Table generation API.
52 * @ingroup grp_rt
53 * @{
54 */
55
56#ifdef IN_RING3
57
58/**
59 * ACPI table type.
60 */
61typedef enum RTACPITBLTYPE
62{
63 /** The invalid output type. */
64 RTACPITBLTYPE_INVALID = 0,
65 /** Type is an UTF-8 ASL source. */
66 RTACPITBLTYPE_ASL,
67 /** Type is the AML bytecode. */
68 RTACPITBLTYPE_AML,
69 /** Usual 32-bit hack. */
70 RTACPITBLTYPE_32BIT_HACK = 0x7fffffff
71} RTACPITBLTYPE;
72
73
74/**
75 * Regenerates the ACPI checksum for the given data.
76 *
77 * @returns The checksum for the given data.
78 * @param pvData The data to check sum.
79 * @param cbData Number of bytes to check sum.
80 */
81RTDECL(uint8_t) RTAcpiChecksumGenerate(const void *pvData, size_t cbData);
82
83
84/**
85 * Generates and writes the table header checksum for the given ACPI table.
86 *
87 * @param pTbl Pointer to the ACPI table to set the checksum for.
88 * @param cbTbl Size of the table in bytes, including the ACPI table header.
89 */
90RTDECL(void) RTAcpiTblHdrChecksumGenerate(PACPITBLHDR pTbl, size_t cbTbl);
91
92
93/**
94 * Creates an ACPI table from the given VFS file.
95 *
96 * @returns IPRT status code.
97 * @param phAcpiTbl Where to store the ACPI table handle on success.
98 * @param hVfsIos The VFS I/O stream handle to read the ACPI table from.
99 * @param enmInType The input type of the ACPI table.
100 * @param pErrInfo Where to return additional error information.
101 */
102RTDECL(int) RTAcpiTblCreateFromVfsIoStrm(PRTACPITBL phAcpiTbl, RTVFSIOSTREAM hVfsIos, RTACPITBLTYPE enmInType, PRTERRINFO pErrInfo);
103
104
105/**
106 * Converts a given ACPI table input stream to the given output type.
107 *
108 * @returns IPRT status code.
109 * @param hVfsIosOut The VFS I/O stream handle to output the result to.
110 * @param enmOutType The output type.
111 * @param hVfsIosIn The VFS I/O stream handle to read the ACPI table from.
112 * @param enmInType The input type of the ACPI table.
113 * @param pErrInfo Where to return additional error information.
114 */
115RTDECL(int) RTAcpiTblConvertFromVfsIoStrm(RTVFSIOSTREAM hVfsIosOut, RTACPITBLTYPE enmOutType,
116 RTVFSIOSTREAM hVfsIosIn, RTACPITBLTYPE enmInType, PRTERRINFO pErrInfo);
117
118
119/**
120 * Creates an ACPI table from the given filename.
121 *
122 * @returns IPRT status code.
123 * @param phAcpiTbl Where to store the ACPI table handle on success.
124 * @param pszFilename The filename to read the ACPI table from.
125 * @param enmInType The input type of the ACPI table.
126 * @param pErrInfo Where to return additional error information.
127 */
128RTDECL(int) RTAcpiTblCreateFromFile(PRTACPITBL phAcpiTbl, const char *pszFilename, RTACPITBLTYPE enmInType, PRTERRINFO pErrInfo);
129
130
131/**
132 * Creates a new empty ACPI table.
133 *
134 * @returns IPRT status code.
135 * @param phAcpiTbl Where to store the ACPI table handle on success.
136 * @param u32TblSig The signature of the table to use.
137 * @param bRevision The revision of the table.
138 * @param pszOemId The OEM supplied string identifiying the OEM, maximum of 6 characters.
139 * @param pszOemTblId The OEM supplied string identifiying the OEM table, maximum of 8 characters.
140 * @param u32OemRevision The OEM supplied revision number.
141 * @param pszCreatorId Vendor ID of the utility that created the table, maximum of 4 characters.
142 * @param u32CreatorRevision Revision of the utility that created the table.
143 */
144RTDECL(int) RTAcpiTblCreate(PRTACPITBL phAcpiTbl, uint32_t u32TblSig, uint8_t bRevision, const char *pszOemId,
145 const char *pszOemTblId, uint32_t u32OemRevision, const char *pszCreatorId,
146 uint32_t u32CreatorRevision);
147
148
149/**
150 * Destroys the given ACPI table, freeing all resources.
151 *
152 * @param hAcpiTbl The ACPI table handle to destroy.
153 */
154RTDECL(void) RTAcpiTblDestroy(RTACPITBL hAcpiTbl);
155
156
157/**
158 * Finalizes the given ACPI table, setting the header and generating checksums.
159 *
160 * @returns IPRT status code.
161 * @param hAcpiTbl The ACPI table handle to finalize.
162 *
163 * @note Nothing can be added to the table after this was called.
164 */
165RTDECL(int) RTAcpiTblFinalize(RTACPITBL hAcpiTbl);
166
167
168/**
169 * Returns the size of the given ACPI table.
170 *
171 * @returns Size of the given ACPI table in bytes, 0 on error.
172 * @param hAcpiTbl The ACPI table handle.
173 *
174 * @note This can only be called after RTAcpiTblFinalize() was called successfully.
175 */
176RTDECL(uint32_t) RTAcpiTblGetSize(RTACPITBL hAcpiTbl);
177
178
179/**
180 * Dumps the given ACPI table to the given VFS I/O stream.
181 *
182 * @returns IPRT status code.
183 * @param hAcpiTbl The ACPI table handle.
184 * @param enmOutType The output type.
185 * @param hVfsIos The VFS I/O stream handle to dump the table to.
186 */
187RTDECL(int) RTAcpiTblDumpToVfsIoStrm(RTACPITBL hAcpiTbl, RTACPITBLTYPE enmOutType, RTVFSIOSTREAM hVfsIos);
188
189
190/**
191 * Dumps the given ACPI table to the given file.
192 *
193 * @returns IPRT status code.
194 * @param hAcpiTbl The ACPI table handle.
195 * @param enmOutType The output type.
196 * @param pszFilename The file path to dump the table to.
197 */
198RTDECL(int) RTAcpiTblDumpToFile(RTACPITBL hAcpiTbl, RTACPITBLTYPE enmOutType, const char *pszFilename);
199
200
201/**
202 * Starts a new DefScope object.
203 *
204 * @returns IPRT status code.
205 * @param hAcpiTbl The ACPI table handle.
206 * @param pszName Name of the scope, can have a root (\) specifier optionally.
207 */
208RTDECL(int) RTAcpiTblScopeStart(RTACPITBL hAcpiTbl, const char *pszName);
209
210
211/**
212 * Finalizes the current scope object, nothing can be added to the scope afterwards.
213 *
214 * @returns IPRT status code.
215 * @param hAcpiTbl The ACPI table handle.
216 */
217RTDECL(int) RTAcpiTblScopeFinalize(RTACPITBL hAcpiTbl);
218
219
220/**
221 * Starts a new DefPackage object.
222 *
223 * @returns IPRT status code.
224 * @param hAcpiTbl The ACPI table handle.
225 * @param cElements Number of element which will be inside the package,
226 * only supports up to 255 elements, use DefVarPackage if more is required.
227 */
228RTDECL(int) RTAcpiTblPackageStart(RTACPITBL hAcpiTbl, uint8_t cElements);
229
230
231/**
232 * Finalizes the current DefPackage object, and return to the enclosing object's scope.
233 *
234 * @returns IPRT status code.
235 * @param hAcpiTbl The ACPI table handle.
236 */
237RTDECL(int) RTAcpiTblPackageFinalize(RTACPITBL hAcpiTbl);
238
239
240/**
241 * Starts a new device object for the given ACPI table in the current scope.
242 *
243 * @returns IPRT status code.
244 * @param hAcpiTbl The ACPI table handle.
245 * @param pszName Name of the device object, must be <= 4 characters long.
246 */
247RTDECL(int) RTAcpiTblDeviceStart(RTACPITBL hAcpiTbl, const char *pszName);
248
249
250/**
251 * Starts a new device object for the given ACPI table in the current scope.
252 *
253 * @returns IPRT status code.
254 * @param hAcpiTbl The ACPI table handle.
255 * @param pszNameFmt The name of the device as a format string.
256 * @param ... The format arguments.
257 */
258RTDECL(int) RTAcpiTblDeviceStartF(RTACPITBL hAcpiTbl, const char *pszNameFmt, ...) RT_IPRT_FORMAT_ATTR(2, 3);
259
260
261/**
262 * Starts a new device object for the given ACPI table in the current scope.
263 *
264 * @returns IPRT status code.
265 * @param hAcpiTbl The ACPI table handle.
266 * @param pszNameFmt The name of the device as a format string.
267 * @param va The format arguments.
268 */
269RTDECL(int) RTAcpiTblDeviceStartV(RTACPITBL hAcpiTbl, const char *pszNameFmt, va_list va) RT_IPRT_FORMAT_ATTR(2, 0);
270
271
272/**
273 * Finalizes the current scope object, nothing can be added to the scope afterwards.
274 *
275 * @returns IPRT status code.
276 * @param hAcpiTbl The ACPI table handle.
277 */
278RTDECL(int) RTAcpiTblDeviceFinalize(RTACPITBL hAcpiTbl);
279
280
281/**
282 * Starts a new processor object for the given ACPI table in the current scope.
283 *
284 * @returns IPRT status code.
285 * @param hAcpiTbl The ACPI table handle.
286 * @param pszName Name of the device object, must be <= 4 characters long.
287 * @param bProcId The processor ID.
288 * @param u32PBlkAddr Address of the processor register block.
289 * @param cbPBlk Size of the processor register block in bytes.
290 */
291RTDECL(int) RTAcpiTblProcessorStart(RTACPITBL hAcpiTbl, const char *pszName, uint8_t bProcId, uint32_t u32PBlkAddr,
292 uint8_t cbPBlk);
293
294
295/**
296 * Starts a new processor object for the given ACPI table in the current scope.
297 *
298 * @returns IPRT status code.
299 * @param hAcpiTbl The ACPI table handle.
300 * @param bProcId The processor ID.
301 * @param u32PBlkAddr Address of the processor register block.
302 * @param cbPBlk Size of the processor register block in bytes.
303 * @param pszNameFmt The name of the device as a format string.
304 * @param ... The format arguments.
305 */
306RTDECL(int) RTAcpiTblProcessorStartF(RTACPITBL hAcpiTbl, uint8_t bProcId, uint32_t u32PBlkAddr, uint8_t cbPBlk,
307 const char *pszNameFmt, ...) RT_IPRT_FORMAT_ATTR(5, 6);
308
309
310/**
311 * Starts a new processor object for the given ACPI table in the current scope.
312 *
313 * @returns IPRT status code.
314 * @param hAcpiTbl The ACPI table handle.
315 * @param bProcId The processor ID.
316 * @param u32PBlkAddr Address of the processor register block.
317 * @param cbPBlk Size of the processor register block in bytes.
318 * @param pszNameFmt The name of the device as a format string.
319 * @param va The format arguments.
320 */
321RTDECL(int) RTAcpiTblProcessorStartV(RTACPITBL hAcpiTbl, uint8_t bProcId, uint32_t u32PBlkAddr, uint8_t cbPBlk,
322 const char *pszNameFmt, va_list va) RT_IPRT_FORMAT_ATTR(5, 0);
323
324
325/**
326 * Finalizes the current scope object, nothing can be added to the scope afterwards.
327 *
328 * @returns IPRT status code.
329 * @param hAcpiTbl The ACPI table handle.
330 */
331RTDECL(int) RTAcpiTblProcessorFinalize(RTACPITBL hAcpiTbl);
332
333
334/**
335 * Starts a new method object for the given ACPI table in the current scope.
336 *
337 * @returns IPRT status code.
338 * @param hAcpiTbl The ACPI table handle.
339 * @param pszName The method name.
340 * @param fFlags AML method flags, see RTACPI_METHOD_F_XXX.
341 * @param cArgs Number of arguments this method takes.
342 * @param uSyncLvl The sync level.
343 */
344RTDECL(int) RTAcpiTblMethodStart(RTACPITBL hAcpiTbl, const char *pszName, uint8_t cArgs, uint32_t fFlags, uint8_t uSyncLvl);
345
346
347/** ACPI method is not serialized. */
348#define RTACPI_METHOD_F_NOT_SERIALIZED 0
349/** ACPI method call needs to be serialized in the ACPI interpreter. */
350#define RTACPI_METHOD_F_SERIALIZED RT_BIT_32(0)
351
352
353/**
354 * Finalizes the current method object, nothing can be added to the method afterwards.
355 *
356 * @returns IPRT status code.
357 * @param hAcpiTbl The ACPI table handle.
358 */
359RTDECL(int) RTAcpiTblMethodFinalize(RTACPITBL hAcpiTbl);
360
361
362/**
363 * Appends a new DefName object (only the NameOp NameString part, DataRefObject is left for the caller
364 * to append).
365 *
366 * @returns IPRT status code.
367 * @param hAcpiTbl The ACPI table handle.
368 * @param pszName The name to append.
369 */
370RTDECL(int) RTAcpiTblNameAppend(RTACPITBL hAcpiTbl, const char *pszName);
371
372
373/**
374 * Appends a new NullName object.
375 *
376 * @returns IPRT status code.
377 * @param hAcpiTbl The ACPI table handle.
378 */
379RTDECL(int) RTAcpiTblNullNameAppend(RTACPITBL hAcpiTbl);
380
381
382/**
383 * Appends a new NameString object.
384 *
385 * @returns IPRT status code.
386 * @param hAcpiTbl The ACPI table handle.
387 * @param pszName The name to append.
388 */
389RTDECL(int) RTAcpiTblNameStringAppend(RTACPITBL hAcpiTbl, const char *pszName);
390
391
392/**
393 * Appends a new String object.
394 *
395 * @returns IPRT status code.
396 * @param hAcpiTbl The ACPI table handle.
397 * @param psz The string to append.
398 */
399RTDECL(int) RTAcpiTblStringAppend(RTACPITBL hAcpiTbl, const char *psz);
400
401
402/**
403 * Appends a new integer object (depending on the value ZeroOp, OneOp,
404 * BytePrefix, WordPrefix, DWordPrefix or QWordPrefix is used).
405 *
406 * @returns IPRT status code.
407 * @param hAcpiTbl The ACPI table handle.
408 * @param u64 The 64-bit value to append.
409 */
410RTDECL(int) RTAcpiTblIntegerAppend(RTACPITBL hAcpiTbl, uint64_t u64);
411
412
413/**
414 * Appends a new DefBuffer object under the current scope.
415 *
416 * @returns IPRT status code.
417 * @param hAcpiTbl The ACPI table handle.
418 * @param pvBuf The buffer data.
419 * @param cbBuf Size of the buffer in bytes.
420 */
421RTDECL(int) RTAcpiTblBufferAppend(RTACPITBL hAcpiTbl, const void *pvBuf, size_t cbBuf);
422
423
424/**
425 * Appends the given resource as a DefBuffer under the current scope.
426 *
427 * @returns IPRT status code.
428 * @param hAcpiTbl The ACPI table handle.
429 * @param hAcpiRes The ACPI resource handle.
430 */
431RTDECL(int) RTAcpiTblResourceAppend(RTACPITBL hAcpiTbl, RTACPIRES hAcpiRes);
432
433
434/**
435 * List of statements.
436 */
437typedef enum RTACPISTMT
438{
439 /** Invalid statement. */
440 kAcpiStmt_Invalid = 0,
441 /** Return statement. */
442 kAcpiStmt_Return,
443 /** Breakpoint statement. */
444 kAcpiStmt_Breakpoint,
445 /** No operation statement. */
446 kAcpiStmt_Nop,
447 /** Break statement. */
448 kAcpiStmt_Break,
449 /** Continue statement. */
450 kAcpiStmt_Continue,
451 /** Add(Operand, Operand, Target) statement. */
452 kAcpiStmt_Add,
453 /** Subtract(Operand, Operand, Target) statement. */
454 kAcpiStmt_Subtract,
455 /** And(Operand, Operand, Target) statement. */
456 kAcpiStmt_And,
457 /** Nand(Operand, Operand, Target) statement. */
458 kAcpiStmt_Nand,
459 /** Or(Operand, Operand, Target) statement. */
460 kAcpiStmt_Or,
461 /** Xor(Operand, Operand, Target) statement. */
462 kAcpiStmt_Xor,
463 /** Not(Operand, Target) statement. */
464 kAcpiStmt_Not,
465 /** Store(TermArg, Supername) statement. */
466 kAcpiStmt_Store,
467 /** Index(BuffPkgStrObj, IndexValue, Target) statement. */
468 kAcpiStmt_Index,
469 /** DerefOf(ObjReference) statement. */
470 kAcpiStmt_DerefOf
471} RTACPISTMT;
472
473
474/**
475 * Appends the given simple statement to the given ACPI table in the current scope.
476 *
477 * @returns IPRT status code.
478 * @param hAcpiTbl The ACPI table handle.
479 * @param enmStmt The statement to add.
480 */
481RTDECL(int) RTAcpiTblStmtSimpleAppend(RTACPITBL hAcpiTbl, RTACPISTMT enmStmt);
482
483
484/**
485 * Starts a new If statement operation.
486 *
487 * @returns IPRT status code.
488 * @param hAcpiTbl The ACPI table handle.
489 */
490RTDECL(int) RTAcpiTblIfStart(RTACPITBL hAcpiTbl);
491
492
493/**
494 * Finalizes the current If statement operation.
495 *
496 * @returns IPRT status code.
497 * @param hAcpiTbl The ACPI table handle.
498 */
499RTDECL(int) RTAcpiTblIfFinalize(RTACPITBL hAcpiTbl);
500
501
502/**
503 * Starts a new Else operation (only valid if currently inside an If oepration).
504 *
505 * @returns IPRT status code.
506 * @param hAcpiTbl The ACPI table handle.
507 */
508RTDECL(int) RTAcpiTblElseStart(RTACPITBL hAcpiTbl);
509
510
511/**
512 * Finalizes the current Else statement operation.
513 *
514 * @returns IPRT status code.
515 * @param hAcpiTbl The ACPI table handle.
516 */
517RTDECL(int) RTAcpiTblElseFinalize(RTACPITBL hAcpiTbl);
518
519
520/**
521 * List of binary operations.
522 */
523typedef enum RTACPIBINARYOP
524{
525 /** Invalid binary operation. */
526 kAcpiBinaryOp_Invalid = 0,
527 /** LAnd(Operand, Operand). */
528 kAcpiBinaryOp_LAnd,
529 /** LEqual(Operand, Operand). */
530 kAcpiBinaryOp_LEqual,
531 /** LGreater(Operand, Operand). */
532 kAcpiBinaryOp_LGreater,
533 /** LGreaterEqual(Operand, Operand). */
534 kAcpiBinaryOp_LGreaterEqual,
535 /** LLess(Operand, Operand). */
536 kAcpiBinaryOp_LLess,
537 /** LLessEqual(Operand, Operand). */
538 kAcpiBinaryOp_LLessEqual,
539 /** LNotEqual(Operand, Operand). */
540 kAcpiBinaryOp_LNotEqual
541} RTACPIBINARYOP;
542
543
544/**
545 * Appends the given binary operand.
546 *
547 * @returns IPRT status code.
548 * @param hAcpiTbl The ACPI table handle.
549 * @param enmBinaryOp The binary operation to append.
550 */
551RTDECL(int) RTAcpiTblBinaryOpAppend(RTACPITBL hAcpiTbl, RTACPIBINARYOP enmBinaryOp);
552
553
554/**
555 * Appends the given Arg<idArg> operand.
556 *
557 * @returns IPRT status code.
558 * @param hAcpiTbl The ACPI table handle.
559 * @param idArg The argument ID to append [0..6].
560 */
561RTDECL(int) RTAcpiTblArgOpAppend(RTACPITBL hAcpiTbl, uint8_t idArg);
562
563
564/**
565 * Appends the given Local<idLocal> operand.
566 *
567 * @returns IPRT status code.
568 * @param hAcpiTbl The ACPI table handle.
569 * @param idLocal The local ID to append [0..7].
570 */
571RTDECL(int) RTAcpiTblLocalOpAppend(RTACPITBL hAcpiTbl, uint8_t idLocal);
572
573
574/**
575 * Appends the given UUID as a buffer object.
576 *
577 * @returns IPRT status code.
578 * @param hAcpiTbl The ACPI table handle.
579 * @param pUuid The UUID to append.
580 */
581RTDECL(int) RTAcpiTblUuidAppend(RTACPITBL hAcpiTbl, PCRTUUID pUuid);
582
583
584/**
585 * Appends the given UUID string as a UUID buffer object.
586 *
587 * @returns IPRT status code.
588 * @param hAcpiTbl The ACPI table handle.
589 * @param pszUuid The UUID string to append as a buffer.
590 */
591RTDECL(int) RTAcpiTblUuidAppendFromStr(RTACPITBL hAcpiTbl, const char *pszUuid);
592
593
594/**
595 * Known operation region space types.
596 */
597typedef enum RTACPIOPREGIONSPACE
598{
599 /** Invalid region space type. */
600 kAcpiOperationRegionSpace_Invalid = 0,
601 /** Region is in system memory space. */
602 kAcpiOperationRegionSpace_SystemMemory,
603 /** Region is in system I/O space. */
604 kAcpiOperationRegionSpace_SystemIo,
605 /** Region is in PCI config space. */
606 kAcpiOperationRegionSpace_PciConfig,
607 /** Region is in embedded control space. */
608 kAcpiOperationRegionSpace_EmbeddedControl,
609 /** Region is in SMBUS space. */
610 kAcpiOperationRegionSpace_SmBus,
611 /** Region is in system CMOS space. */
612 kAcpiOperationRegionSpace_SystemCmos,
613 /** Region is a PCI bar target. */
614 kAcpiOperationRegionSpace_PciBarTarget,
615 /** Region is in IPMI space. */
616 kAcpiOperationRegionSpace_Ipmi,
617 /** Region is in GPIO space. */
618 kAcpiOperationRegionSpace_Gpio,
619 /** Region is in generic serial bus space. */
620 kAcpiOperationRegionSpace_GenericSerialBus,
621 /** Region is in platform communications channel (PCC) space. */
622 kAcpiOperationRegionSpace_Pcc,
623 /** 32bit hack. */
624 kAcpiOperationRegionSpace_32bit_Hack = 0x7fffffff
625} RTACPIOPREGIONSPACE;
626
627
628/**
629 * Appends a new OperationRegion() to the given ACPI table - extended version.
630 *
631 * @returns IPRT status code.
632 * @param hAcpiTbl The ACPI table handle.
633 * @param pszName The name of the operation region.
634 * @param enmSpace The operation region space type.
635 *
636 * @note This doesn't encode the region offset and size arguments but leaves it up to the caller
637 * to be able to encode complex stuff.
638 */
639RTDECL(int) RTAcpiTblOpRegionAppendEx(RTACPITBL hAcpiTbl, const char *pszName, RTACPIOPREGIONSPACE enmSpace);
640
641
642/**
643 * Appends a new OperationRegion() to the given ACPI table.
644 *
645 * @returns IPRT status code.
646 * @param hAcpiTbl The ACPI table handle.
647 * @param pszName The name of the operation region.
648 * @param enmSpace The operation region space type.
649 * @param offRegion Offset of the region.
650 * @param cbRegion Size of the region in bytes.
651 */
652RTDECL(int) RTAcpiTblOpRegionAppend(RTACPITBL hAcpiTbl, const char *pszName, RTACPIOPREGIONSPACE enmSpace,
653 uint64_t offRegion, uint64_t cbRegion);
654
655
656/**
657 * Field access type.
658 */
659typedef enum RTACPIFIELDACC
660{
661 /** Invalid access type. */
662 kAcpiFieldAcc_Invalid = 0,
663 /** Any access width is okay. */
664 kAcpiFieldAcc_Any,
665 /** Byte (8-bit) access. */
666 kAcpiFieldAcc_Byte,
667 /** Word (16-bit) access. */
668 kAcpiFieldAcc_Word,
669 /** Double word (32-bit) access. */
670 kAcpiFieldAcc_DWord,
671 /** Quad word (64-bit) access. */
672 kAcpiFieldAcc_QWord,
673 /** Buffer like access. */
674 kAcpiFieldAcc_Buffer
675} RTACPIFIELDACC;
676
677
678/**
679 * Field update rule.
680 */
681typedef enum RTACPIFIELDUPDATE
682{
683 /** Invalid upadte rule. */
684 kAcpiFieldUpdate_Invalid = 0,
685 /** Preserve content not being accessed. */
686 kAcpiFieldUpdate_Preserve,
687 /** Write as ones. */
688 kAcpiFieldUpdate_WriteAsOnes,
689 /** Write as zeroes. */
690 kAcpiFieldUpdate_WriteAsZeroes
691} RTACPIFIELDUPDATE;
692
693
694/**
695 * Field entry.
696 */
697typedef struct RTACPIFIELDENTRY
698{
699 /** The field name. */
700 const char *pszName;
701 /** Number of bits of the field. */
702 uint64_t cBits;
703} RTACPIFIELDENTRY;
704/** Pointer to a field entry. */
705typedef RTACPIFIELDENTRY *PRTACPIFIELDENTRY;
706/** Pointer to a const field entry. */
707typedef const RTACPIFIELDENTRY *PCRTACPIFIELDENTRY;
708
709
710/**
711 * Appends a new field descriptor to the given ACPI table.
712 *
713 * @returns IPRT status code.
714 * @param hAcpiTbl The ACPI table handle.
715 * @param pszNameRef The region/buffer the field describes.
716 * @param enmAcc The access type,
717 * @param fLock Flag whether access must happen under a lock.
718 * @param enmUpdate The update rule.
719 * @param paFields Pointer to the field descriptors.
720 * @param cFields Number of entries in the array.
721 */
722RTDECL(int) RTAcpiTblFieldAppend(RTACPITBL hAcpiTbl, const char *pszNameRef, RTACPIFIELDACC enmAcc,
723 bool fLock, RTACPIFIELDUPDATE enmUpdate, PCRTACPIFIELDENTRY paFields,
724 uint32_t cFields);
725
726
727
728/** @name ACPI resource builder related API.
729 * @{ */
730
731/**
732 * Creates a new empty resource template.
733 *
734 * @returns IPRT status code.
735 * @param phAcpiRes Where to store the handle to the ACPI resource on success.
736 */
737RTDECL(int) RTAcpiResourceCreate(PRTACPIRES phAcpiRes);
738
739
740/**
741 * Destroys the given ACPI resource, freeing all allocated resources.
742 *
743 * @param hAcpiRes The ACPI resource handle to destroy.
744 */
745RTDECL(void) RTAcpiResourceDestroy(RTACPIRES hAcpiRes);
746
747
748/**
749 * Resets the given ACPI resource handle to create a new empty template.
750 *
751 * @param hAcpiRes The ACPI resource handle.
752 */
753RTDECL(void) RTAcpiResourceReset(RTACPIRES hAcpiRes);
754
755
756/**
757 * Seals the given ACPI resource against further changes and adds any
758 * missing data required to complete the resource buffer.
759 *
760 * @returns IPRT status code.
761 * @param hAcpiRes The ACPI resource handle.
762 *
763 * @note After a call to this method completed successfully it is not possible
764 * to add new resources until RTAcpiResourceReset() was called.
765 */
766RTDECL(int) RTAcpiResourceSeal(RTACPIRES hAcpiRes);
767
768
769/**
770 * Queries the pointer to the buffer holding the encoded data.
771 *
772 * @returns IPRT status code.
773 * @param hAcpiRes The ACPI resource handle.
774 * @param ppvRes Where to store the pointer to the buffer holding the encoded resource template on success.
775 * @param pcbRes Where to store the size of the encoded data in bytes on success.
776 *
777 * @note The ACPI resource must be successfully sealed with RTAcpiResourceSeal() for this function to succeed.
778 * Also the buffer pointer will only be valid until a call to any other RTAcpiResource* method.
779 */
780RTDECL(int) RTAcpiResourceQueryBuffer(RTACPIRES hAcpiRes, const void **ppvRes, size_t *pcbRes);
781
782
783/**
784 * Adds a fixed memory range with the given start address and size to the given ACPI resource.
785 *
786 * @returns IPRT status code.
787 * @param hAcpiRes The ACPI resource handle.
788 * @param u32AddrBase The base address to encode.
789 * @param cbRange The range length in bytes to encode.
790 * @param fRw Flag whether this address range is read-write or read-only.
791 */
792RTDECL(int) RTAcpiResourceAdd32BitFixedMemoryRange(RTACPIRES hAcpiRes, uint32_t u32AddrBase, uint32_t cbRange,
793 bool fRw);
794
795
796/**
797 * Adds an extended interrupt descriptor with the given configuration to the given ACPI resource.
798 *
799 * @returns IPRT status code.
800 * @param hAcpiRes The ACPI resource handle.
801 * @param fConsumer Flag whether the entity this resource is assigned to consumes the interrupt (true) or produces it (false).
802 * @param fEdgeTriggered Flag whether the interrupt is edged (true) or level (false) triggered.
803 * @param fActiveLow Flag whether the interrupt polarity is active low (true) or active high (false).
804 * @param fShared Flag whether the interrupt is shared between different entities (true) or exclusive to the assigned entity (false).
805 * @param fWakeCapable Flag whether the interrupt can wake the system (true) or not (false).
806 * @param cIntrs Number of interrupts following.
807 * @param pau32Intrs Pointer to the array of interrupt numbers.
808 */
809RTDECL(int) RTAcpiResourceAddExtendedInterrupt(RTACPIRES hAcpiRes, bool fConsumer, bool fEdgeTriggered, bool fActiveLow, bool fShared,
810 bool fWakeCapable, uint8_t cIntrs, uint32_t *pau32Intrs);
811
812
813/** @name Generic address space flags.
814 * @{ */
815#define RTACPI_RESOURCE_ADDR_RANGE_F_DECODE_TYPE_SUB RT_BIT_32(0)
816#define RTACPI_RESOURCE_ADDR_RANGE_F_DECODE_TYPE_POS 0
817
818#define RTACPI_RESOURCE_ADDR_RANGE_F_MIN_ADDR_FIXED RT_BIT_32(1)
819#define RTACPI_RESOURCE_ADDR_RANGE_F_MIN_ADDR_CHANGEABLE 0
820
821#define RTACPI_RESOURCE_ADDR_RANGE_F_MAX_ADDR_FIXED RT_BIT_32(2)
822#define RTACPI_RESOURCE_ADDR_RANGE_F_MAX_ADDR_CHANGEABLE 0
823
824#define RTACPI_RESOURCE_ADDR_RANGE_F_VALID_MASK UINT32_C(0x00000007)
825/** @} */
826
827/**
828 * Memory range cacheability
829 */
830typedef enum RTACPIRESMEMRANGECACHEABILITY
831{
832 /** Usual invalid value. */
833 kAcpiResMemRangeCacheability_Invalid = 0,
834 /** Memory range is non cacheable (like MMIO, etc.). */
835 kAcpiResMemRangeCacheability_NonCacheable,
836 /** Memory is cacheable. */
837 kAcpiResMemRangeCacheability_Cacheable,
838 /** Memory is cacheable and supports write comining. */
839 kAcpiResMemRangeCacheability_CacheableWriteCombining,
840 /** Memory is cacheable and supports prefetching. */
841 kAcpiResMemRangeCacheability_CacheablePrefetchable,
842 /** 32-bit blow up hack. */
843 kAcpiResMemRangeCacheability_32BitHack = 0x7fffffff
844} RTACPIRESMEMRANGECACHEABILITY;
845
846
847/**
848 * Memory attribute.
849 */
850typedef enum RTACPIRESMEMRANGETYPE
851{
852 /** Invalid memory range type. */
853 kAcpiResMemType_Invalid = 0,
854 /** Memory range is actual memory. */
855 kAcpiResMemType_Memory,
856 /** Memory range is reserved. */
857 kAcpiResMemType_Reserved,
858 /** Memory range is reserved to ACPI. */
859 kAcpiResMemType_Acpi,
860 /** Memory range is no volatile storage. */
861 kAcpiResMemType_Nvs,
862 /** 32-bit blow up hack. */
863 kAcpiResMemType_32BitHack = 0x7fffffff
864} RTACPIRESMEMRANGETYPE;
865
866
867/**
868 * Adds a quad word (64-bit) memory range to the given ACPI resource.
869 *
870 * @returns IPRT status code.
871 * @param hAcpiRes The ACPI resource handle.
872 * @param enmCacheability The cacheability of the memory range.
873 * @param enmType Memory range type.
874 * @param fRw Flag whether the memory range is read/write (true) or readonly (false).
875 * @param fAddrSpace Additional address space flags (combination of RTACPI_RESOURCE_ADDR_RANGE_F_XXX).
876 * @param u64AddrMin The start address of the memory range.
877 * @param u64AddrMax Last valid address of the range.
878 * @param u64OffTrans Translation offset being applied to the address (for a PCIe bridge or IOMMU for example).
879 * @param u64Granularity The access granularity of the range in bytes.
880 * @param u64Length Length of the memory range in bytes.
881 */
882RTDECL(int) RTAcpiResourceAddQWordMemoryRange(RTACPIRES hAcpiRes, RTACPIRESMEMRANGECACHEABILITY enmCacheability,
883 RTACPIRESMEMRANGETYPE enmType, bool fRw, uint32_t fAddrSpace,
884 uint64_t u64AddrMin, uint64_t u64AddrMax, uint64_t u64OffTrans,
885 uint64_t u64Granularity, uint64_t u64Length);
886
887
888/**
889 * Adds a double word (32-bit) memory range to the given ACPI resource.
890 *
891 * @returns IPRT status code.
892 * @param hAcpiRes The ACPI resource handle.
893 * @param enmCacheability The cacheability of the memory range.
894 * @param enmType Memory range type.
895 * @param fRw Flag whether the memory range is read/write (true) or readonly (false).
896 * @param fAddrSpace Additional address space flags (combination of RTACPI_RESOURCE_ADDR_RANGE_F_XXX).
897 * @param u32AddrMin The start address of the memory range.
898 * @param u32AddrMax Last valid address of the range.
899 * @param u32OffTrans Translation offset being applied to the address (for a PCIe bridge or IOMMU for example).
900 * @param u32Granularity The access granularity of the range in bytes.
901 * @param u32Length Length of the memory range in bytes.
902 */
903RTDECL(int) RTAcpiResourceAddDWordMemoryRange(RTACPIRES hAcpiRes, RTACPIRESMEMRANGECACHEABILITY enmCacheability,
904 RTACPIRESMEMRANGETYPE enmType, bool fRw, uint32_t fAddrSpace,
905 uint32_t u32AddrMin, uint32_t u32AddrMax, uint32_t u32OffTrans,
906 uint32_t u32Granularity, uint32_t u32Length);
907
908
909/**
910 * I/O range coverage.
911 */
912typedef enum RTACPIRESIORANGE
913{
914 /** Invalid range. */
915 kAcpiResIoRange_Invalid = 0,
916 /** Range covers only non ISA I/O ports. */
917 kAcpiResIoRange_NonIsaOnly,
918 /** Range covers only ISA I/O ports. */
919 kAcpiResIoRange_IsaOnly,
920 /** Range covers the whole I/O port range. */
921 kAcpiResIoRange_Whole,
922 /** 32-bit blow up hack. */
923 kAcpiResIoRange_32BitHack = 0x7fffffff
924} RTACPIRESIORANGE;
925
926
927/**
928 * I/O range type.
929 */
930typedef enum RTACPIRESIORANGETYPE
931{
932 /** Invalid value. */
933 kAcpiResIoRangeType_Invalid = 0,
934 /** Resource is I/O on the primary and secondary side of the bridge. */
935 kAcpiResIoRangeType_Static,
936 /** Resource is memory on the primary and I/O on the secondary side of the bridge,
937 * primary side memory address for a given I/O port is calculated with
938 * address = (((Port & 0xfffc) << 10) || (Port & 0xfff)) + AddrMin. */
939 kAcpiResIoRangeType_Translation_Sparse,
940 /** Resource is memory on the primary and I/O on the secondary side of the bridge,
941 * primary side memory address for a given I/O port is calculated with
942 * address = AddrMin + Port. */
943 kAcpiResIoRangeType_Translation_Dense,
944 /** 32-bit blowup hack. */
945 kAcpiResIoRangeType_32BitHack = 0x7fffffff
946} RTACPIRESIORANGETYPE;
947
948
949/**
950 * Adds a quad word (64-bit) I/O range to the given ACPI resource.
951 *
952 * @returns IPRT status code.
953 * @param hAcpiRes The ACPI resource handle.
954 * @param enmIoType The I/O range type.
955 * @param enmIoRange The I/O range coverage.
956 * @param fAddrSpace Additional address space flags (combination of RTACPI_RESOURCE_ADDR_RANGE_F_XXX).
957 * @param u64AddrMin The start address of the memory range.
958 * @param u64AddrMax Last valid address of the range.
959 * @param u64OffTrans Translation offset being applied to the address (for a PCIe bridge or IOMMU for example).
960 * @param u64Granularity The access granularity of the range in bytes.
961 * @param u64Length Length of the memory range in bytes.
962 */
963RTDECL(int) RTAcpiResourceAddQWordIoRange(RTACPIRES hAcpiRes, RTACPIRESIORANGETYPE enmIoType, RTACPIRESIORANGE enmIoRange,
964 uint32_t fAddrSpace, uint64_t u64AddrMin, uint64_t u64AddrMax, uint64_t u64OffTrans,
965 uint64_t u64Granularity, uint64_t u64Length);
966
967
968/**
969 * Adds a word (16-bit) bus number to the given ACPI resource.
970 *
971 * @returns IPRT status code.
972 * @param hAcpiRes The ACPI resource handle.
973 * @param fAddrSpace Additional address space flags (combination of RTACPI_RESOURCE_ADDR_RANGE_F_XXX).
974 * @param u16BusMin Starting bus number.
975 * @param u16BusMax Last valid bus number.
976 * @param u16OffTrans Translation offset being applied to the bus number.
977 * @param u16Granularity The access granularity of the bus number.
978 * @param u16Length Length of the bus range.
979 */
980RTDECL(int) RTAcpiResourceAddWordBusNumber(RTACPIRES hAcpiRes, uint32_t fAddrSpace, uint16_t u16BusMin, uint16_t u16BusMax,
981 uint16_t u16OffTrans, uint16_t u16Granularity, uint16_t u16Length);
982
983/** @} */
984
985#endif /* IN_RING3 */
986
987/** @} */
988
989RT_C_DECLS_END
990
991#endif /* !IPRT_INCLUDED_acpi_h */
992
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette