]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiSdt.h
MdeModulePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdeModulePkg / Universal / Acpi / AcpiTableDxe / AcpiSdt.h
1 /** @file
2 ACPI Sdt Protocol Driver
3
4 Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved. <BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #ifndef _ACPI_SDT_H_
10 #define _ACPI_SDT_H_
11
12 //
13 // Privacy data structure
14 //
15
16 //
17 // ACPI Notify Linked List Signature.
18 //
19 #define EFI_ACPI_NOTIFY_LIST_SIGNATURE SIGNATURE_32 ('E', 'A', 'N', 'L')
20
21 //
22 // ACPI Notify List Entry definition.
23 //
24 // Signature must be set to EFI_ACPI_NOTIFY_LIST_SIGNATURE
25 // Link is the linked list data.
26 // Notification is the callback function.
27 //
28 typedef struct {
29 UINT32 Signature;
30 LIST_ENTRY Link;
31 EFI_ACPI_NOTIFICATION_FN Notification;
32 } EFI_ACPI_NOTIFY_LIST;
33
34 //
35 // Containment record for ACPI Notify linked list.
36 //
37 #define EFI_ACPI_NOTIFY_LIST_FROM_LINK(_link) CR (_link, EFI_ACPI_NOTIFY_LIST, Link, EFI_ACPI_NOTIFY_LIST_SIGNATURE)
38
39 typedef struct _AML_BYTE_ENCODING AML_BYTE_ENCODING;
40 typedef struct _EFI_AML_NODE_LIST EFI_AML_NODE_LIST;
41
42 //
43 // AML Node Linked List Signature.
44 //
45 #define EFI_AML_NODE_LIST_SIGNATURE SIGNATURE_32 ('E', 'A', 'M', 'L')
46
47 //
48 // AML Node Linked List Entry definition.
49 //
50 // Signature must be set to EFI_AML_NODE_LIST_SIGNATURE
51 // Link is the linked list data.
52 // Name is the ACPI node name.
53 // This is listed for PATH finding.
54 // Buffer is the ACPI node buffer pointer, the first/second bytes are opcode.
55 // This buffer should not be freed.
56 // Size is the total size of this ACPI node buffer.
57 // Children is the children linked list of this node.
58 //
59 #define AML_NAME_SEG_SIZE 4
60
61 struct _EFI_AML_NODE_LIST {
62 UINT32 Signature;
63 UINT8 Name[AML_NAME_SEG_SIZE];
64 UINT8 *Buffer;
65 UINTN Size;
66 LIST_ENTRY Link;
67 LIST_ENTRY Children;
68 EFI_AML_NODE_LIST *Parent;
69 AML_BYTE_ENCODING *AmlByteEncoding;
70 };
71
72 //
73 // Containment record for AML Node linked list.
74 //
75 #define EFI_AML_NODE_LIST_FROM_LINK(_link) CR (_link, EFI_AML_NODE_LIST, Link, EFI_AML_NODE_LIST_SIGNATURE)
76
77 //
78 // AML Handle Signature.
79 //
80 #define EFI_AML_HANDLE_SIGNATURE SIGNATURE_32 ('E', 'A', 'H', 'S')
81 #define EFI_AML_ROOT_HANDLE_SIGNATURE SIGNATURE_32 ('E', 'A', 'R', 'H')
82
83 //
84 // AML Handle Entry definition.
85 //
86 // Signature must be set to EFI_AML_HANDLE_SIGNATURE or EFI_AML_ROOT_HANDLE_SIGNATURE
87 // Buffer is the ACPI node buffer pointer, the first/second bytes are opcode.
88 // This buffer should not be freed.
89 // Size is the total size of this ACPI node buffer.
90 //
91 typedef struct {
92 UINT32 Signature;
93 UINT8 *Buffer;
94 UINTN Size;
95 AML_BYTE_ENCODING *AmlByteEncoding;
96 BOOLEAN Modified;
97 } EFI_AML_HANDLE;
98
99 typedef UINT32 AML_OP_PARSE_INDEX;
100
101 #define AML_OP_PARSE_INDEX_GET_OPCODE 0
102 #define AML_OP_PARSE_INDEX_GET_TERM1 1
103 #define AML_OP_PARSE_INDEX_GET_TERM2 2
104 #define AML_OP_PARSE_INDEX_GET_TERM3 3
105 #define AML_OP_PARSE_INDEX_GET_TERM4 4
106 #define AML_OP_PARSE_INDEX_GET_TERM5 5
107 #define AML_OP_PARSE_INDEX_GET_TERM6 6
108 #define AML_OP_PARSE_INDEX_GET_SIZE (AML_OP_PARSE_INDEX)-1
109
110 typedef UINT32 AML_OP_PARSE_FORMAT;
111 #define AML_NONE 0
112 #define AML_OPCODE 1
113 #define AML_UINT8 2
114 #define AML_UINT16 3
115 #define AML_UINT32 4
116 #define AML_UINT64 5
117 #define AML_NAME 6
118 #define AML_STRING 7
119 #define AML_OBJECT 8
120
121 typedef UINT32 AML_OP_ATTRIBUTE;
122 #define AML_HAS_PKG_LENGTH 0x1 // It is ACPI attribute - if OpCode has PkgLength
123 #define AML_IS_NAME_CHAR 0x2 // It is ACPI attribute - if this is NameChar
124 #define AML_HAS_CHILD_OBJ 0x4 // it is ACPI attribute - if OpCode has Child Object.
125 #define AML_IN_NAMESPACE 0x10000 // It is UEFI SDT attribute - if OpCode will be in NameSpace
126 // NOTE; Not all OBJECT will be in NameSpace
127 // For example, BankField | CreateBitField | CreateByteField | CreateDWordField |
128 // CreateField | CreateQWordField | CreateWordField | Field | IndexField.
129
130 struct _AML_BYTE_ENCODING {
131 UINT8 OpCode;
132 UINT8 SubOpCode;
133 AML_OP_PARSE_INDEX MaxIndex;
134 AML_OP_PARSE_FORMAT Format[6];
135 AML_OP_ATTRIBUTE Attribute;
136 };
137
138 //
139 // AcpiSdt protocol declaration
140 //
141
142 /**
143 Returns a requested ACPI table.
144
145 The GetAcpiTable() function returns a pointer to a buffer containing the ACPI table associated
146 with the Index that was input. The following structures are not considered elements in the list of
147 ACPI tables:
148 - Root System Description Pointer (RSD_PTR)
149 - Root System Description Table (RSDT)
150 - Extended System Description Table (XSDT)
151 Version is updated with a bit map containing all the versions of ACPI of which the table is a
152 member. For tables installed via the EFI_ACPI_TABLE_PROTOCOL.InstallAcpiTable() interface,
153 the function returns the value of EFI_ACPI_STD_PROTOCOL.AcpiVersion.
154
155 @param[in] Index The zero-based index of the table to retrieve.
156 @param[out] Table Pointer for returning the table buffer.
157 @param[out] Version On return, updated with the ACPI versions to which this table belongs. Type
158 EFI_ACPI_TABLE_VERSION is defined in "Related Definitions" in the
159 EFI_ACPI_SDT_PROTOCOL.
160 @param[out] TableKey On return, points to the table key for the specified ACPI system definition table.
161 This is identical to the table key used in the EFI_ACPI_TABLE_PROTOCOL.
162 The TableKey can be passed to EFI_ACPI_TABLE_PROTOCOL.UninstallAcpiTable()
163 to uninstall the table.
164
165 @retval EFI_SUCCESS The function completed successfully.
166 @retval EFI_NOT_FOUND The requested index is too large and a table was not found.
167 **/
168 EFI_STATUS
169 EFIAPI
170 GetAcpiTable2 (
171 IN UINTN Index,
172 OUT EFI_ACPI_SDT_HEADER **Table,
173 OUT EFI_ACPI_TABLE_VERSION *Version,
174 OUT UINTN *TableKey
175 );
176
177 /**
178 Register or unregister a callback when an ACPI table is installed.
179
180 This function registers or unregisters a function which will be called whenever a new ACPI table is
181 installed.
182
183 @param[in] Register If TRUE, then the specified function will be registered. If FALSE, then the specified
184 function will be unregistered.
185 @param[in] Notification Points to the callback function to be registered or unregistered.
186
187 @retval EFI_SUCCESS Callback successfully registered or unregistered.
188 @retval EFI_INVALID_PARAMETER Notification is NULL
189 @retval EFI_INVALID_PARAMETER Register is FALSE and Notification does not match a known registration function.
190 **/
191 EFI_STATUS
192 EFIAPI
193 RegisterNotify (
194 IN BOOLEAN Register,
195 IN EFI_ACPI_NOTIFICATION_FN Notification
196 );
197
198 /**
199 Create a handle for the first ACPI opcode in an ACPI system description table.
200
201 @param[in] TableKey The table key for the ACPI table, as returned by GetTable().
202 @param[out] Handle On return, points to the newly created ACPI handle.
203
204 @retval EFI_SUCCESS Handle created successfully.
205 @retval EFI_NOT_FOUND TableKey does not refer to a valid ACPI table.
206 **/
207 EFI_STATUS
208 EFIAPI
209 OpenSdt (
210 IN UINTN TableKey,
211 OUT EFI_ACPI_HANDLE *Handle
212 );
213
214 /**
215 Create a handle from an ACPI opcode
216
217 @param[in] Buffer Points to the ACPI opcode.
218 @param[out] Handle Upon return, holds the handle.
219
220 @retval EFI_SUCCESS Success
221 @retval EFI_INVALID_PARAMETER Buffer is NULL or Handle is NULL or Buffer points to an
222 invalid opcode.
223
224 **/
225 EFI_STATUS
226 EFIAPI
227 Open (
228 IN VOID *Buffer,
229 OUT EFI_ACPI_HANDLE *Handle
230 );
231
232 /**
233 Close an ACPI handle.
234
235 @param[in] Handle Returns the handle.
236
237 @retval EFI_SUCCESS Success
238 @retval EFI_INVALID_PARAMETER Handle is NULL or does not refer to a valid ACPI object.
239 **/
240 EFI_STATUS
241 EFIAPI
242 Close (
243 IN EFI_ACPI_HANDLE Handle
244 );
245
246 /**
247 Retrieve information about an ACPI object.
248
249 @param[in] Handle ACPI object handle.
250 @param[in] Index Index of the data to retrieve from the object. In general, indexes read from left-to-right
251 in the ACPI encoding, with index 0 always being the ACPI opcode.
252 @param[out] DataType Points to the returned data type or EFI_ACPI_DATA_TYPE_NONE if no data exists
253 for the specified index.
254 @param[out] Data Upon return, points to the pointer to the data.
255 @param[out] DataSize Upon return, points to the size of Data.
256
257 @retval EFI_SUCCESS Success.
258 @retval EFI_INVALID_PARAMETER Handle is NULL or does not refer to a valid ACPI object.
259 **/
260 EFI_STATUS
261 EFIAPI
262 GetOption (
263 IN EFI_ACPI_HANDLE Handle,
264 IN UINTN Index,
265 OUT EFI_ACPI_DATA_TYPE *DataType,
266 OUT CONST VOID **Data,
267 OUT UINTN *DataSize
268 );
269
270 /**
271 Change information about an ACPI object.
272
273 @param[in] Handle ACPI object handle.
274 @param[in] Index Index of the data to retrieve from the object. In general, indexes read from left-to-right
275 in the ACPI encoding, with index 0 always being the ACPI opcode.
276 @param[in] Data Points to the data.
277 @param[in] DataSize The size of the Data.
278
279 @retval EFI_SUCCESS Success
280 @retval EFI_INVALID_PARAMETER Handle is NULL or does not refer to a valid ACPI object.
281 @retval EFI_BAD_BUFFER_SIZE Data cannot be accommodated in the space occupied by
282 the option.
283
284 **/
285 EFI_STATUS
286 EFIAPI
287 SetOption (
288 IN EFI_ACPI_HANDLE Handle,
289 IN UINTN Index,
290 IN CONST VOID *Data,
291 IN UINTN DataSize
292 );
293
294 /**
295 Return the child ACPI objects.
296
297 @param[in] ParentHandle Parent handle.
298 @param[in, out] Handle On entry, points to the previously returned handle or NULL to start with the first
299 handle. On return, points to the next returned ACPI handle or NULL if there are no
300 child objects.
301
302 @retval EFI_SUCCESS Success
303 @retval EFI_INVALID_PARAMETER ParentHandle is NULL or does not refer to a valid ACPI object.
304 **/
305 EFI_STATUS
306 EFIAPI
307 GetChild (
308 IN EFI_ACPI_HANDLE ParentHandle,
309 IN OUT EFI_ACPI_HANDLE *Handle
310 );
311
312 /**
313 Returns the handle of the ACPI object representing the specified ACPI path
314
315 @param[in] HandleIn Points to the handle of the object representing the starting point for the path search.
316 @param[in] AcpiPath Points to the ACPI path, which conforms to the ACPI encoded path format.
317 @param[out] HandleOut On return, points to the ACPI object which represents AcpiPath, relative to
318 HandleIn.
319
320 @retval EFI_SUCCESS Success
321 @retval EFI_INVALID_PARAMETER HandleIn is NULL or does not refer to a valid ACPI object.
322 **/
323 EFI_STATUS
324 EFIAPI
325 FindPath (
326 IN EFI_ACPI_HANDLE HandleIn,
327 IN VOID *AcpiPath,
328 OUT EFI_ACPI_HANDLE *HandleOut
329 );
330
331 //
332 // ACPI SDT function
333 //
334
335 /**
336 Create a handle from an ACPI opcode
337
338 @param[in] Buffer Points to the ACPI opcode.
339 @param[in] BufferSize Max buffer size.
340 @param[out] Handle Upon return, holds the handle.
341
342 @retval EFI_SUCCESS Success
343 @retval EFI_INVALID_PARAMETER Buffer is NULL or Handle is NULL or Buffer points to an
344 invalid opcode.
345
346 **/
347 EFI_STATUS
348 SdtOpenEx (
349 IN VOID *Buffer,
350 IN UINTN BufferSize,
351 OUT EFI_ACPI_HANDLE *Handle
352 );
353
354 //
355 // AML support function
356 //
357
358 /**
359 Get AML NameString size.
360
361 @param[in] Buffer AML NameString.
362 @param[out] BufferSize AML NameString size
363
364 @retval EFI_SUCCESS Success.
365 @retval EFI_INVALID_PARAMETER Buffer does not refer to a valid AML NameString.
366 **/
367 EFI_STATUS
368 AmlGetNameStringSize (
369 IN UINT8 *Buffer,
370 OUT UINTN *BufferSize
371 );
372
373 /**
374 This function retuns package length from the buffer.
375
376 @param[in] Buffer AML buffer
377 @param[out] PkgLength The total length of package.
378
379 @return The byte data count to present the package length.
380 **/
381 UINTN
382 AmlGetPkgLength (
383 IN UINT8 *Buffer,
384 OUT UINTN *PkgLength
385 );
386
387 /**
388 This function returns AcpiDataType according to AmlType.
389
390 @param[in] AmlType AML Type.
391
392 @return AcpiDataType
393 **/
394 EFI_ACPI_DATA_TYPE
395 AmlTypeToAcpiType (
396 IN AML_OP_PARSE_FORMAT AmlType
397 );
398
399 /**
400 This function returns AmlByteEncoding according to OpCode Byte.
401
402 @param[in] OpByteBuffer OpCode byte buffer.
403
404 @return AmlByteEncoding
405 **/
406 AML_BYTE_ENCODING *
407 AmlSearchByOpByte (
408 IN UINT8 *OpByteBuffer
409 );
410
411 /**
412 Return object size.
413
414 @param[in] AmlByteEncoding AML Byte Encoding.
415 @param[in] Buffer AML object buffer.
416 @param[in] MaxBufferSize AML object buffer MAX size. The parser can not parse any data exceed this region.
417
418 @return Size of the object.
419 **/
420 UINTN
421 AmlGetObjectSize (
422 IN AML_BYTE_ENCODING *AmlByteEncoding,
423 IN UINT8 *Buffer,
424 IN UINTN MaxBufferSize
425 );
426
427 /**
428 Return object name.
429
430 @param[in] AmlHandle AML handle.
431
432 @return Name of the object.
433 **/
434 CHAR8 *
435 AmlGetObjectName (
436 IN EFI_AML_HANDLE *AmlHandle
437 );
438
439 /**
440 Retrieve information according to AmlHandle
441
442 @param[in] AmlHandle AML handle.
443 @param[in] Index Index of the data to retrieve from the object. In general, indexes read from left-to-right
444 in the ACPI encoding, with index 0 always being the ACPI opcode.
445 @param[out] DataType Points to the returned data type or EFI_ACPI_DATA_TYPE_NONE if no data exists
446 for the specified index.
447 @param[out] Data Upon return, points to the pointer to the data.
448 @param[out] DataSize Upon return, points to the size of Data.
449
450 @retval EFI_SUCCESS Success.
451 @retval EFI_INVALID_PARAMETER AmlHandle does not refer to a valid ACPI object.
452 **/
453 EFI_STATUS
454 AmlParseOptionHandleCommon (
455 IN EFI_AML_HANDLE *AmlHandle,
456 IN AML_OP_PARSE_INDEX Index,
457 OUT EFI_ACPI_DATA_TYPE *DataType,
458 OUT VOID **Data,
459 OUT UINTN *DataSize
460 );
461
462 /**
463 Return offset of last option.
464
465 @param[in] AmlHandle AML Handle.
466 @param[out] Buffer Upon return, points to the offset after last option.
467
468 @retval EFI_SUCCESS Success.
469 @retval EFI_INVALID_PARAMETER AmlHandle does not refer to a valid ACPI object.
470 **/
471 EFI_STATUS
472 AmlGetOffsetAfterLastOption (
473 IN EFI_AML_HANDLE *AmlHandle,
474 OUT UINT8 **Buffer
475 );
476
477 /**
478 Return the child ACPI objects from Root Handle.
479
480 @param[in] AmlParentHandle Parent handle. It is Root Handle.
481 @param[in] AmlHandle The previously returned handle or NULL to start with the first handle.
482 @param[out] Buffer On return, points to the next returned ACPI handle or NULL if there are no
483 child objects.
484
485 @retval EFI_SUCCESS Success
486 @retval EFI_INVALID_PARAMETER ParentHandle is NULL or does not refer to a valid ACPI object.
487 **/
488 EFI_STATUS
489 AmlGetChildFromRoot (
490 IN EFI_AML_HANDLE *AmlParentHandle,
491 IN EFI_AML_HANDLE *AmlHandle,
492 OUT VOID **Buffer
493 );
494
495 /**
496 Return the child ACPI objects from Non-Root Handle.
497
498 @param[in] AmlParentHandle Parent handle. It is Non-Root Handle.
499 @param[in] AmlHandle The previously returned handle or NULL to start with the first handle.
500 @param[out] Buffer On return, points to the next returned ACPI handle or NULL if there are no
501 child objects.
502
503 @retval EFI_SUCCESS Success
504 @retval EFI_INVALID_PARAMETER ParentHandle is NULL or does not refer to a valid ACPI object.
505 **/
506 EFI_STATUS
507 AmlGetChildFromNonRoot (
508 IN EFI_AML_HANDLE *AmlParentHandle,
509 IN EFI_AML_HANDLE *AmlHandle,
510 OUT VOID **Buffer
511 );
512
513 /**
514 Return AML name according to ASL name.
515 The caller need free the AmlName returned.
516
517 @param[in] AslPath ASL name.
518
519 @return AmlName
520 **/
521 UINT8 *
522 AmlNameFromAslName (
523 IN UINT8 *AslPath
524 );
525
526 /**
527 Returns the handle of the ACPI object representing the specified ACPI AML path
528
529 @param[in] AmlHandle Points to the handle of the object representing the starting point for the path search.
530 @param[in] AmlPath Points to the ACPI AML path.
531 @param[out] Buffer On return, points to the ACPI object which represents AcpiPath, relative to
532 HandleIn.
533 @param[in] FromRoot TRUE means to find AML path from \ (Root) Node.
534 FALSE means to find AML path from this Node (The HandleIn).
535
536 @retval EFI_SUCCESS Success
537 @retval EFI_INVALID_PARAMETER HandleIn does not refer to a valid ACPI object.
538 **/
539 EFI_STATUS
540 AmlFindPath (
541 IN EFI_AML_HANDLE *AmlHandle,
542 IN UINT8 *AmlPath,
543 OUT VOID **Buffer,
544 IN BOOLEAN FromRoot
545 );
546
547 /**
548 Print AML NameString.
549
550 @param[in] Buffer AML NameString.
551 **/
552 VOID
553 AmlPrintNameString (
554 IN UINT8 *Buffer
555 );
556
557 /**
558 Print AML NameSeg.
559
560 @param[in] Buffer AML NameSeg.
561 **/
562 VOID
563 AmlPrintNameSeg (
564 IN UINT8 *Buffer
565 );
566
567 /**
568 Check if it is AML Root name
569
570 @param[in] Buffer AML path.
571
572 @retval TRUE AML path is root.
573 @retval FALSE AML path is not root.
574 **/
575 BOOLEAN
576 AmlIsRootPath (
577 IN UINT8 *Buffer
578 );
579
580 #endif