TianoCore EDK2 master
Loading...
Searching...
No Matches
AmlResourceDataCodeGen.c
Go to the documentation of this file.
1
15#include <AmlNodeDefines.h>
17
18#include <AmlCoreInterface.h>
19#include <AmlDefines.h>
20#include <Api/AmlApiHelper.h>
21#include <Tree/AmlNode.h>
23
46EFIAPI
48 IN AML_DATA_NODE *RdNode,
49 IN AML_OBJECT_NODE *ParentNode,
50 OUT AML_DATA_NODE **NewRdNode
51 )
52{
53 EFI_STATUS Status;
54 EFI_STATUS Status1;
55 AML_OBJECT_NODE *BufferOpNode;
56
57 if (NewRdNode != NULL) {
58 *NewRdNode = NULL;
59 }
60
61 if (ParentNode != NULL) {
62 // Check this is a NameOp node.
63 if ((!AmlNodeHasOpCode (ParentNode, AML_NAME_OP, 0))) {
64 ASSERT (0);
65 Status = EFI_INVALID_PARAMETER;
66 goto error_handler;
67 }
68
69 // Get the value which is represented as a BufferOp object node
70 // which is the 2nd fixed argument (i.e. index 1).
72 ParentNode,
74 );
75 if ((BufferOpNode == NULL) ||
76 (AmlGetNodeType ((AML_NODE_HANDLE)BufferOpNode) != EAmlNodeObject) ||
77 (!AmlNodeHasOpCode (BufferOpNode, AML_BUFFER_OP, 0)))
78 {
79 ASSERT (0);
80 Status = EFI_INVALID_PARAMETER;
81 goto error_handler;
82 }
83
84 // Add RdNode as the last element, but before the EndTag.
85 Status = AmlAppendRdNode (BufferOpNode, RdNode);
86 if (EFI_ERROR (Status)) {
87 ASSERT (0);
88 goto error_handler;
89 }
90 }
91
92 if (NewRdNode != NULL) {
93 *NewRdNode = RdNode;
94 }
95
96 return EFI_SUCCESS;
97
98error_handler:
99 Status1 = AmlDeleteTree ((AML_NODE_HEADER *)RdNode);
100 ASSERT_EFI_ERROR (Status1);
101 // Return original error.
102 return Status;
103}
104
121STATIC
122UINT8
123EFIAPI
125 IN UINT8 IsaRanges,
126 IN BOOLEAN IsDenseTranslation,
127 IN BOOLEAN IsTypeStatic
128 )
129{
130 // Only check type specific parameters.
131 if (IsaRanges > 3) {
132 ASSERT (0);
133 return MAX_UINT8;
134 }
135
136 // Construct TypeSpecificFlags and call the generic function.
137 // Cf ACPI 6.4 specification, Table 6.50:
138 // "Table 6.50: I/O Resource Flag (Resource Type = 1) Definitions"
139 return IsaRanges |
140 (IsTypeStatic ? 0 : BIT4) |
141 (IsDenseTranslation ? 0 : BIT5);
142}
143
164STATIC
165UINT8
166EFIAPI
168 IN UINT8 Cacheable,
169 IN BOOLEAN IsReadWrite,
170 IN UINT8 MemoryRangeType,
171 IN BOOLEAN IsTypeStatic
172 )
173{
174 // Only check type specific parameters.
175 if ((Cacheable > 3) ||
176 (MemoryRangeType > 3))
177 {
178 ASSERT (0);
179 return MAX_UINT8;
180 }
181
182 // Construct TypeSpecificFlags and call the generic function.
183 // Cf ACPI 6.4 specification, Table 6.49:
184 // "Memory Resource Flag (Resource Type = 0) Definitions"
185 return (IsReadWrite ? BIT0 : 0) |
186 (Cacheable << 1) |
187 (MemoryRangeType << 3) |
188 (IsTypeStatic ? 0 : BIT5);
189}
190
205STATIC
206UINT8
207EFIAPI
209 IN BOOLEAN IsPosDecode,
210 IN BOOLEAN IsMinFixed,
211 IN BOOLEAN IsMaxFixed
212 )
213{
214 return (IsPosDecode ? 0 : BIT1) |
215 (IsMinFixed ? BIT2 : 0) |
216 (IsMaxFixed ? BIT3 : 0);
217}
218
237STATIC
239EFIAPI
241 IN BOOLEAN IsMinFixed,
242 IN BOOLEAN IsMaxFixed,
243 IN UINT64 AddressGranularity,
244 IN UINT64 AddressMinimum,
245 IN UINT64 AddressMaximum,
246 IN UINT64 AddressTranslation,
247 IN UINT64 RangeLength
248 )
249{
250 if ((AddressMinimum > AddressMaximum) ||
251 (RangeLength > (AddressMaximum - AddressMinimum + 1)) ||
252 ((AddressGranularity != 0) &&
253 (((AddressGranularity + 1) & AddressGranularity) != 0)))
254 {
255 ASSERT (0);
256 return EFI_INVALID_PARAMETER;
257 }
258
259 if (RangeLength != 0) {
260 if (IsMinFixed ^ IsMaxFixed) {
261 ASSERT (0);
262 return EFI_INVALID_PARAMETER;
263 } else if (IsMinFixed &&
264 IsMaxFixed &&
265 (AddressGranularity != 0) &&
266 ((AddressMaximum - AddressMinimum + 1) != RangeLength))
267 {
268 ASSERT (0);
269 return EFI_INVALID_PARAMETER;
270 }
271 } else {
272 if (IsMinFixed && IsMaxFixed) {
273 ASSERT (0);
274 return EFI_INVALID_PARAMETER;
275 } else if (IsMinFixed &&
276 ((AddressMinimum & AddressGranularity) != 0))
277 {
278 ASSERT (0);
279 return EFI_INVALID_PARAMETER;
280 } else if (IsMaxFixed &&
281 (((AddressMaximum + 1) & AddressGranularity) != 0))
282 {
283 ASSERT (0);
284 return EFI_INVALID_PARAMETER;
285 }
286 }
287
288 return EFI_SUCCESS;
289}
290
341STATIC
343EFIAPI
345 IN UINT8 ResourceType,
346 IN BOOLEAN IsResourceConsumer,
347 IN BOOLEAN IsPosDecode,
348 IN BOOLEAN IsMinFixed,
349 IN BOOLEAN IsMaxFixed,
350 IN UINT8 TypeSpecificFlags,
351 IN UINT32 AddressGranularity,
352 IN UINT32 AddressMinimum,
353 IN UINT32 AddressMaximum,
354 IN UINT32 AddressTranslation,
355 IN UINT32 RangeLength,
356 IN UINT8 ResourceSourceIndex,
357 IN CONST CHAR8 *ResourceSource,
358 IN AML_OBJECT_NODE_HANDLE NameOpNode, OPTIONAL
359 OUT AML_DATA_NODE_HANDLE *NewRdNode OPTIONAL
360 )
361{
362 EFI_STATUS Status;
363 AML_DATA_NODE *RdNode;
365
366 // ResourceSource and ResourceSourceIndex are unused.
367 if ((TypeSpecificFlags == MAX_UINT8) ||
368 (ResourceSourceIndex != 0) ||
369 (ResourceSource != NULL) ||
370 ((NameOpNode == NULL) && (NewRdNode == NULL)))
371 {
372 ASSERT (0);
373 return EFI_INVALID_PARAMETER;
374 }
375
376 Status = CheckAddressSpaceFields (
377 IsMinFixed,
378 IsMaxFixed,
379 AddressGranularity,
380 AddressMinimum,
381 AddressMaximum,
382 AddressTranslation,
383 RangeLength
384 );
385 if (EFI_ERROR (Status)) {
386 ASSERT (0);
387 return Status;
388 }
389
390 // Header
391 RdDWord.Header.Header.Bits.Name =
392 ACPI_LARGE_DWORD_ADDRESS_SPACE_DESCRIPTOR_NAME;
393 RdDWord.Header.Header.Bits.Type = ACPI_LARGE_ITEM_FLAG;
394 RdDWord.Header.Length = sizeof (EFI_ACPI_DWORD_ADDRESS_SPACE_DESCRIPTOR) -
395 sizeof (ACPI_LARGE_RESOURCE_HEADER);
396
397 // Body
398 RdDWord.ResType = ResourceType;
399 RdDWord.GenFlag = AddressSpaceGeneralFlags (
400 IsPosDecode,
401 IsMinFixed,
402 IsMaxFixed
403 );
404 RdDWord.SpecificFlag = TypeSpecificFlags;
405 RdDWord.AddrSpaceGranularity = AddressGranularity;
406 RdDWord.AddrRangeMin = AddressMinimum;
407 RdDWord.AddrRangeMax = AddressMaximum;
408 RdDWord.AddrTranslationOffset = AddressTranslation;
409 RdDWord.AddrLen = RangeLength;
410
411 Status = AmlCreateDataNode (
413 (UINT8 *)&RdDWord,
415 &RdNode
416 );
417 if (EFI_ERROR (Status)) {
418 ASSERT (0);
419 return Status;
420 }
421
422 return LinkRdNode (RdNode, NameOpNode, NewRdNode);
423}
424
472EFIAPI
474 IN BOOLEAN IsResourceConsumer,
475 IN BOOLEAN IsMinFixed,
476 IN BOOLEAN IsMaxFixed,
477 IN BOOLEAN IsPosDecode,
478 IN UINT8 IsaRanges,
479 IN UINT32 AddressGranularity,
480 IN UINT32 AddressMinimum,
481 IN UINT32 AddressMaximum,
482 IN UINT32 AddressTranslation,
483 IN UINT32 RangeLength,
484 IN UINT8 ResourceSourceIndex,
485 IN CONST CHAR8 *ResourceSource,
486 IN BOOLEAN IsDenseTranslation,
487 IN BOOLEAN IsTypeStatic,
488 IN AML_OBJECT_NODE_HANDLE NameOpNode, OPTIONAL
489 OUT AML_DATA_NODE_HANDLE *NewRdNode OPTIONAL
490 )
491{
493 ACPI_ADDRESS_SPACE_TYPE_IO,
494 IsResourceConsumer,
495 IsPosDecode,
496 IsMinFixed,
497 IsMaxFixed,
499 IsaRanges,
500 IsDenseTranslation,
501 IsTypeStatic
502 ),
503 AddressGranularity,
504 AddressMinimum,
505 AddressMaximum,
506 AddressTranslation,
507 RangeLength,
508 ResourceSourceIndex,
509 ResourceSource,
510 NameOpNode,
511 NewRdNode
512 );
513}
514
568EFIAPI
570 IN BOOLEAN IsResourceConsumer,
571 IN BOOLEAN IsPosDecode,
572 IN BOOLEAN IsMinFixed,
573 IN BOOLEAN IsMaxFixed,
575 IN BOOLEAN IsReadWrite,
576 IN UINT32 AddressGranularity,
577 IN UINT32 AddressMinimum,
578 IN UINT32 AddressMaximum,
579 IN UINT32 AddressTranslation,
580 IN UINT32 RangeLength,
581 IN UINT8 ResourceSourceIndex,
582 IN CONST CHAR8 *ResourceSource,
583 IN AML_MEMORY_ATTRIBUTES_MTP MemoryRangeType,
584 IN BOOLEAN IsTypeStatic,
585 IN AML_OBJECT_NODE_HANDLE NameOpNode, OPTIONAL
586 OUT AML_DATA_NODE_HANDLE *NewRdNode OPTIONAL
587 )
588{
590 ACPI_ADDRESS_SPACE_TYPE_MEM,
591 IsResourceConsumer,
592 IsPosDecode,
593 IsMinFixed,
594 IsMaxFixed,
596 Cacheable,
597 IsReadWrite,
598 MemoryRangeType,
599 IsTypeStatic
600 ),
601 AddressGranularity,
602 AddressMinimum,
603 AddressMaximum,
604 AddressTranslation,
605 RangeLength,
606 ResourceSourceIndex,
607 ResourceSource,
608 NameOpNode,
609 NewRdNode
610 );
611}
612
637EFIAPI
639 BOOLEAN IsReadWrite,
640 UINT32 Address,
641 UINT32 RangeLength,
642 AML_OBJECT_NODE_HANDLE NameOpNode,
643 AML_DATA_NODE_HANDLE *NewMemNode
644 )
645{
646 EFI_STATUS Status;
647 AML_DATA_NODE *MemNode;
649
650 RangeDesc.Header.Header.Byte = ACPI_32_BIT_FIXED_MEMORY_RANGE_DESCRIPTOR;
651 RangeDesc.Header.Length = sizeof (EFI_ACPI_32_BIT_FIXED_MEMORY_RANGE_DESCRIPTOR) -
652 sizeof (ACPI_LARGE_RESOURCE_HEADER);
653 RangeDesc.Information = IsReadWrite ? BIT0 : 0;
654 RangeDesc.BaseAddress = Address;
655 RangeDesc.Length = RangeLength;
656
657 Status = AmlCreateDataNode (
659 (UINT8 *)&RangeDesc,
660 sizeof (RangeDesc),
661 &MemNode
662 );
663 if (EFI_ERROR (Status)) {
664 ASSERT (0);
665 return Status;
666 }
667
668 return LinkRdNode (MemNode, NameOpNode, NewMemNode);
669}
670
721STATIC
723EFIAPI
725 IN UINT8 ResourceType,
726 IN BOOLEAN IsResourceConsumer,
727 IN BOOLEAN IsPosDecode,
728 IN BOOLEAN IsMinFixed,
729 IN BOOLEAN IsMaxFixed,
730 IN UINT8 TypeSpecificFlags,
731 IN UINT16 AddressGranularity,
732 IN UINT16 AddressMinimum,
733 IN UINT16 AddressMaximum,
734 IN UINT16 AddressTranslation,
735 IN UINT16 RangeLength,
736 IN UINT8 ResourceSourceIndex,
737 IN CONST CHAR8 *ResourceSource,
738 IN AML_OBJECT_NODE_HANDLE NameOpNode, OPTIONAL
739 OUT AML_DATA_NODE_HANDLE *NewRdNode OPTIONAL
740 )
741{
742 EFI_STATUS Status;
743 AML_DATA_NODE *RdNode;
745
746 // ResourceSource and ResourceSourceIndex are unused.
747 if ((TypeSpecificFlags == MAX_UINT8) ||
748 (ResourceSourceIndex != 0) ||
749 (ResourceSource != NULL) ||
750 ((NameOpNode == NULL) && (NewRdNode == NULL)))
751 {
752 ASSERT (0);
753 return EFI_INVALID_PARAMETER;
754 }
755
756 Status = CheckAddressSpaceFields (
757 IsMinFixed,
758 IsMaxFixed,
759 AddressGranularity,
760 AddressMinimum,
761 AddressMaximum,
762 AddressTranslation,
763 RangeLength
764 );
765 if (EFI_ERROR (Status)) {
766 ASSERT (0);
767 return Status;
768 }
769
770 // Header
771 Rdword.Header.Header.Bits.Name =
772 ACPI_LARGE_WORD_ADDRESS_SPACE_DESCRIPTOR_NAME;
773 Rdword.Header.Header.Bits.Type = ACPI_LARGE_ITEM_FLAG;
774 Rdword.Header.Length = sizeof (EFI_ACPI_WORD_ADDRESS_SPACE_DESCRIPTOR) -
775 sizeof (ACPI_LARGE_RESOURCE_HEADER);
776
777 // Body
778 Rdword.ResType = ResourceType;
779 Rdword.GenFlag = AddressSpaceGeneralFlags (
780 IsPosDecode,
781 IsMinFixed,
782 IsMaxFixed
783 );
784 Rdword.SpecificFlag = TypeSpecificFlags;
785 Rdword.AddrSpaceGranularity = AddressGranularity;
786 Rdword.AddrRangeMin = AddressMinimum;
787 Rdword.AddrRangeMax = AddressMaximum;
788 Rdword.AddrTranslationOffset = AddressTranslation;
789 Rdword.AddrLen = RangeLength;
790
791 Status = AmlCreateDataNode (
793 (UINT8 *)&Rdword,
795 &RdNode
796 );
797 if (EFI_ERROR (Status)) {
798 ASSERT (0);
799 return Status;
800 }
801
802 return LinkRdNode (RdNode, NameOpNode, NewRdNode);
803}
804
845EFIAPI
847 IN BOOLEAN IsResourceConsumer,
848 IN BOOLEAN IsMinFixed,
849 IN BOOLEAN IsMaxFixed,
850 IN BOOLEAN IsPosDecode,
851 IN UINT16 AddressGranularity,
852 IN UINT16 AddressMinimum,
853 IN UINT16 AddressMaximum,
854 IN UINT16 AddressTranslation,
855 IN UINT16 RangeLength,
856 IN UINT8 ResourceSourceIndex,
857 IN CONST CHAR8 *ResourceSource,
858 IN AML_OBJECT_NODE_HANDLE NameOpNode, OPTIONAL
859 OUT AML_DATA_NODE_HANDLE *NewRdNode OPTIONAL
860 )
861{
862 // There is no Type Specific Flags for buses.
863 return AmlCodeGenRdWordSpace (
864 ACPI_ADDRESS_SPACE_TYPE_BUS,
865 IsResourceConsumer,
866 IsPosDecode,
867 IsMinFixed,
868 IsMaxFixed,
869 0,
870 AddressGranularity,
871 AddressMinimum,
872 AddressMaximum,
873 AddressTranslation,
874 RangeLength,
875 ResourceSourceIndex,
876 ResourceSource,
877 NameOpNode,
878 NewRdNode
879 );
880}
881
926EFIAPI
928 IN BOOLEAN IsResourceConsumer,
929 IN BOOLEAN IsMinFixed,
930 IN BOOLEAN IsMaxFixed,
931 IN BOOLEAN IsPosDecode,
932 IN UINT8 IsaRanges,
933 IN UINT16 AddressGranularity,
934 IN UINT16 AddressMinimum,
935 IN UINT16 AddressMaximum,
936 IN UINT16 AddressTranslation,
937 IN UINT16 RangeLength,
938 IN UINT8 ResourceSourceIndex,
939 IN CONST CHAR8 *ResourceSource,
940 IN BOOLEAN IsDenseTranslation,
941 IN BOOLEAN IsTypeStatic,
942 IN AML_OBJECT_NODE_HANDLE NameOpNode, OPTIONAL
943 OUT AML_DATA_NODE_HANDLE *NewRdNode OPTIONAL
944 )
945{
946 return AmlCodeGenRdWordSpace (
947 ACPI_ADDRESS_SPACE_TYPE_IO,
948 IsResourceConsumer,
949 IsPosDecode,
950 IsMinFixed,
951 IsMaxFixed,
953 IsaRanges,
954 IsDenseTranslation,
955 IsTypeStatic
956 ),
957 AddressGranularity,
958 AddressMinimum,
959 AddressMaximum,
960 AddressTranslation,
961 RangeLength,
962 ResourceSourceIndex,
963 ResourceSource,
964 NameOpNode,
965 NewRdNode
966 );
967}
968
1019STATIC
1021EFIAPI
1023 IN UINT8 ResourceType,
1024 IN BOOLEAN IsResourceConsumer,
1025 IN BOOLEAN IsPosDecode,
1026 IN BOOLEAN IsMinFixed,
1027 IN BOOLEAN IsMaxFixed,
1028 IN UINT8 TypeSpecificFlags,
1029 IN UINT64 AddressGranularity,
1030 IN UINT64 AddressMinimum,
1031 IN UINT64 AddressMaximum,
1032 IN UINT64 AddressTranslation,
1033 IN UINT64 RangeLength,
1034 IN UINT8 ResourceSourceIndex,
1035 IN CONST CHAR8 *ResourceSource,
1036 IN AML_OBJECT_NODE_HANDLE NameOpNode, OPTIONAL
1037 OUT AML_DATA_NODE_HANDLE *NewRdNode OPTIONAL
1038 )
1039{
1040 EFI_STATUS Status;
1041 AML_DATA_NODE *RdNode;
1043
1044 // ResourceSource and ResourceSourceIndex are unused.
1045 if ((TypeSpecificFlags == MAX_UINT8) ||
1046 (ResourceSourceIndex != 0) ||
1047 (ResourceSource != NULL) ||
1048 ((NameOpNode == NULL) && (NewRdNode == NULL)))
1049 {
1050 ASSERT (0);
1051 return EFI_INVALID_PARAMETER;
1052 }
1053
1054 Status = CheckAddressSpaceFields (
1055 IsMinFixed,
1056 IsMaxFixed,
1057 AddressGranularity,
1058 AddressMinimum,
1059 AddressMaximum,
1060 AddressTranslation,
1061 RangeLength
1062 );
1063 if (EFI_ERROR (Status)) {
1064 ASSERT (0);
1065 return Status;
1066 }
1067
1068 // Header
1069 RdQword.Header.Header.Bits.Name =
1070 ACPI_LARGE_QWORD_ADDRESS_SPACE_DESCRIPTOR_NAME;
1071 RdQword.Header.Header.Bits.Type = ACPI_LARGE_ITEM_FLAG;
1072 RdQword.Header.Length = sizeof (EFI_ACPI_QWORD_ADDRESS_SPACE_DESCRIPTOR) -
1073 sizeof (ACPI_LARGE_RESOURCE_HEADER);
1074
1075 // Body
1076 RdQword.ResType = ResourceType;
1077 RdQword.GenFlag = AddressSpaceGeneralFlags (
1078 IsPosDecode,
1079 IsMinFixed,
1080 IsMaxFixed
1081 );
1082 RdQword.SpecificFlag = TypeSpecificFlags;
1083 RdQword.AddrSpaceGranularity = AddressGranularity;
1084 RdQword.AddrRangeMin = AddressMinimum;
1085 RdQword.AddrRangeMax = AddressMaximum;
1086 RdQword.AddrTranslationOffset = AddressTranslation;
1087 RdQword.AddrLen = RangeLength;
1088
1089 Status = AmlCreateDataNode (
1091 (UINT8 *)&RdQword,
1093 &RdNode
1094 );
1095 if (EFI_ERROR (Status)) {
1096 ASSERT (0);
1097 return Status;
1098 }
1099
1100 return LinkRdNode (RdNode, NameOpNode, NewRdNode);
1101}
1102
1150EFIAPI
1152 IN BOOLEAN IsResourceConsumer,
1153 IN BOOLEAN IsMinFixed,
1154 IN BOOLEAN IsMaxFixed,
1155 IN BOOLEAN IsPosDecode,
1156 IN UINT8 IsaRanges,
1157 IN UINT64 AddressGranularity,
1158 IN UINT64 AddressMinimum,
1159 IN UINT64 AddressMaximum,
1160 IN UINT64 AddressTranslation,
1161 IN UINT64 RangeLength,
1162 IN UINT8 ResourceSourceIndex,
1163 IN CONST CHAR8 *ResourceSource,
1164 IN BOOLEAN IsDenseTranslation,
1165 IN BOOLEAN IsTypeStatic,
1166 IN AML_OBJECT_NODE_HANDLE NameOpNode, OPTIONAL
1167 OUT AML_DATA_NODE_HANDLE *NewRdNode OPTIONAL
1168 )
1169{
1170 return AmlCodeGenRdQWordSpace (
1171 ACPI_ADDRESS_SPACE_TYPE_IO,
1172 IsResourceConsumer,
1173 IsPosDecode,
1174 IsMinFixed,
1175 IsMaxFixed,
1177 IsaRanges,
1178 IsDenseTranslation,
1179 IsTypeStatic
1180 ),
1181 AddressGranularity,
1182 AddressMinimum,
1183 AddressMaximum,
1184 AddressTranslation,
1185 RangeLength,
1186 ResourceSourceIndex,
1187 ResourceSource,
1188 NameOpNode,
1189 NewRdNode
1190 );
1191}
1192
1246EFIAPI
1248 IN BOOLEAN IsResourceConsumer,
1249 IN BOOLEAN IsPosDecode,
1250 IN BOOLEAN IsMinFixed,
1251 IN BOOLEAN IsMaxFixed,
1252 IN AML_MEMORY_ATTRIBUTES_MEM Cacheable,
1253 IN BOOLEAN IsReadWrite,
1254 IN UINT64 AddressGranularity,
1255 IN UINT64 AddressMinimum,
1256 IN UINT64 AddressMaximum,
1257 IN UINT64 AddressTranslation,
1258 IN UINT64 RangeLength,
1259 IN UINT8 ResourceSourceIndex,
1260 IN CONST CHAR8 *ResourceSource,
1261 IN AML_MEMORY_ATTRIBUTES_MTP MemoryRangeType,
1262 IN BOOLEAN IsTypeStatic,
1263 IN AML_OBJECT_NODE_HANDLE NameOpNode, OPTIONAL
1264 OUT AML_DATA_NODE_HANDLE *NewRdNode OPTIONAL
1265 )
1266{
1267 return AmlCodeGenRdQWordSpace (
1268 ACPI_ADDRESS_SPACE_TYPE_MEM,
1269 IsResourceConsumer,
1270 IsPosDecode,
1271 IsMinFixed,
1272 IsMaxFixed,
1274 Cacheable,
1275 IsReadWrite,
1276 MemoryRangeType,
1277 IsTypeStatic
1278 ),
1279 AddressGranularity,
1280 AddressMinimum,
1281 AddressMaximum,
1282 AddressTranslation,
1283 RangeLength,
1284 ResourceSourceIndex,
1285 ResourceSource,
1286 NameOpNode,
1287 NewRdNode
1288 );
1289}
1290
1325EFIAPI
1327 IN BOOLEAN ResourceConsumer,
1328 IN BOOLEAN EdgeTriggered,
1329 IN BOOLEAN ActiveLow,
1330 IN BOOLEAN Shared,
1331 IN UINT32 *IrqList,
1332 IN UINT8 IrqCount,
1333 IN AML_OBJECT_NODE_HANDLE NameOpNode OPTIONAL,
1334 OUT AML_DATA_NODE_HANDLE *NewRdNode OPTIONAL
1335 )
1336{
1337 EFI_STATUS Status;
1338
1339 AML_DATA_NODE *RdNode;
1341 UINT32 *FirstInterrupt;
1342
1343 if ((IrqList == NULL) ||
1344 (IrqCount == 0) ||
1345 ((NameOpNode == NULL) && (NewRdNode == NULL)))
1346 {
1347 ASSERT (0);
1348 return EFI_INVALID_PARAMETER;
1349 }
1350
1351 // Header
1352 RdInterrupt.Header.Header.Bits.Name =
1353 ACPI_LARGE_EXTENDED_IRQ_DESCRIPTOR_NAME;
1354 RdInterrupt.Header.Header.Bits.Type = ACPI_LARGE_ITEM_FLAG;
1355 RdInterrupt.Header.Length = sizeof (EFI_ACPI_EXTENDED_INTERRUPT_DESCRIPTOR) -
1356 sizeof (ACPI_LARGE_RESOURCE_HEADER);
1357
1358 // Body
1359 RdInterrupt.InterruptVectorFlags = (ResourceConsumer ? BIT0 : 0) |
1360 (EdgeTriggered ? BIT1 : 0) |
1361 (ActiveLow ? BIT2 : 0) |
1362 (Shared ? BIT3 : 0);
1363 RdInterrupt.InterruptTableLength = IrqCount;
1364
1365 // Get the address of the first interrupt field.
1366 FirstInterrupt = RdInterrupt.InterruptNumber;
1367
1368 // Copy the list of interrupts.
1369 CopyMem (FirstInterrupt, IrqList, (sizeof (UINT32) * IrqCount));
1370
1371 Status = AmlCreateDataNode (
1373 (UINT8 *)&RdInterrupt,
1375 &RdNode
1376 );
1377 if (EFI_ERROR (Status)) {
1378 ASSERT (0);
1379 return Status;
1380 }
1381
1382 return LinkRdNode (RdNode, NameOpNode, NewRdNode);
1383}
1384
1423EFIAPI
1425 IN UINT8 AddressSpace,
1426 IN UINT8 BitWidth,
1427 IN UINT8 BitOffset,
1428 IN UINT64 Address,
1429 IN UINT8 AccessSize,
1430 IN AML_OBJECT_NODE_HANDLE NameOpNode OPTIONAL,
1431 OUT AML_DATA_NODE_HANDLE *NewRdNode OPTIONAL
1432 )
1433{
1434 EFI_STATUS Status;
1435 AML_DATA_NODE *RdNode;
1437
1438 // Cf. ACPI 6.4, s14.7 Referencing the PCC address space
1439 // The AccessSize represents the Subspace Id for the PCC address space.
1440 if (((AddressSpace != EFI_ACPI_6_4_PLATFORM_COMMUNICATION_CHANNEL) &&
1441 (AccessSize > EFI_ACPI_6_4_QWORD)) ||
1442 ((NameOpNode == NULL) && (NewRdNode == NULL)))
1443 {
1444 ASSERT (0);
1445 return EFI_INVALID_PARAMETER;
1446 }
1447
1448 // Header
1449 RdRegister.Header.Header.Bits.Name =
1450 ACPI_LARGE_GENERIC_REGISTER_DESCRIPTOR_NAME;
1451 RdRegister.Header.Header.Bits.Type = ACPI_LARGE_ITEM_FLAG;
1452 RdRegister.Header.Length = sizeof (EFI_ACPI_GENERIC_REGISTER_DESCRIPTOR) -
1453 sizeof (ACPI_LARGE_RESOURCE_HEADER);
1454
1455 // Body
1456 RdRegister.AddressSpaceId = AddressSpace;
1457 RdRegister.RegisterBitWidth = BitWidth;
1458 RdRegister.RegisterBitOffset = BitOffset;
1459 RdRegister.AddressSize = AccessSize;
1460 RdRegister.RegisterAddress = Address;
1461
1462 Status = AmlCreateDataNode (
1464 (UINT8 *)&RdRegister,
1466 &RdNode
1467 );
1468 if (EFI_ERROR (Status)) {
1469 ASSERT (0);
1470 return Status;
1471 }
1472
1473 return LinkRdNode (RdNode, NameOpNode, NewRdNode);
1474}
1475
1507EFIAPI
1509 IN BOOLEAN IsDecoder16,
1510 IN UINT16 AddressMinimum,
1511 IN UINT16 AddressMaximum,
1512 IN UINT8 Alignment,
1513 IN UINT8 RangeLength,
1514 IN AML_OBJECT_NODE_HANDLE NameOpNode, OPTIONAL
1515 OUT AML_DATA_NODE_HANDLE *NewRdNode OPTIONAL
1516 )
1517{
1518 EFI_STATUS Status;
1520 AML_DATA_NODE *IoNode;
1521
1522 if (AddressMinimum > AddressMaximum) {
1523 return EFI_INVALID_PARAMETER;
1524 }
1525
1526 if (Alignment != 0) {
1528 if ((AddressMinimum % Alignment) != 0) {
1529 return EFI_INVALID_PARAMETER;
1530 }
1531
1532 if ((AddressMaximum % Alignment) != 0) {
1533 return EFI_INVALID_PARAMETER;
1534 }
1535 }
1536
1537 IoDesc.Header.Byte = ACPI_IO_PORT_DESCRIPTOR;
1538 IoDesc.Information = IsDecoder16 ? BIT0 : 0;
1539
1540 IoDesc.BaseAddressMin = AddressMinimum;
1541 IoDesc.BaseAddressMax = AddressMaximum;
1542 IoDesc.Alignment = Alignment;
1543 IoDesc.Length = RangeLength;
1544
1545 Status = AmlCreateDataNode (
1547 (UINT8 *)&IoDesc,
1548 sizeof (IoDesc),
1549 &IoNode
1550 );
1551 if (EFI_ERROR (Status)) {
1552 ASSERT (0);
1553 return Status;
1554 }
1555
1556 return LinkRdNode (IoNode, NameOpNode, NewRdNode);
1557}
1558
1595EFIAPI
1597 IN UINT8 CheckSum OPTIONAL,
1598 IN AML_OBJECT_NODE *ParentNode OPTIONAL,
1599 OUT AML_DATA_NODE **NewRdNode OPTIONAL
1600 )
1601{
1602 EFI_STATUS Status;
1603 AML_DATA_NODE *RdNode;
1605 ACPI_SMALL_RESOURCE_HEADER SmallResHdr;
1606
1607 if ((ParentNode == NULL) && (NewRdNode == NULL)) {
1608 ASSERT (0);
1609 return EFI_INVALID_PARAMETER;
1610 }
1611
1612 RdNode = NULL;
1613
1614 // Header
1615 SmallResHdr.Bits.Length = sizeof (EFI_ACPI_END_TAG_DESCRIPTOR) -
1616 sizeof (ACPI_SMALL_RESOURCE_HEADER);
1617 SmallResHdr.Bits.Name = ACPI_SMALL_END_TAG_DESCRIPTOR_NAME;
1618 SmallResHdr.Bits.Type = ACPI_SMALL_ITEM_FLAG;
1619
1620 // Body
1621 EndTag.Desc = SmallResHdr.Byte;
1622 EndTag.Checksum = CheckSum;
1623
1624 Status = AmlCreateDataNode (
1626 (UINT8 *)&EndTag,
1628 &RdNode
1629 );
1630 if (EFI_ERROR (Status)) {
1631 ASSERT (0);
1632 return Status;
1633 }
1634
1635 if (NewRdNode != NULL) {
1636 *NewRdNode = RdNode;
1637 }
1638
1639 if (ParentNode != NULL) {
1640 // Check the BufferOp doesn't contain any resource data yet.
1641 // This is a hard check: do not allow to add an EndTag if the BufferNode
1642 // already has resource data elements attached. Indeed, the EndTag should
1643 // have already been added.
1644 if (AmlGetNextVariableArgument ((AML_NODE_HEADER *)ParentNode, NULL) !=
1645 NULL)
1646 {
1647 ASSERT (0);
1648 Status = EFI_INVALID_PARAMETER;
1649 goto error_handler;
1650 }
1651
1652 // Add the EndTag RdNode. Indeed, the AmlAppendRdNode function
1653 // is looking for an EndTag, which we are adding here.
1654 Status = AmlVarListAddTail (
1655 (AML_NODE_HEADER *)ParentNode,
1656 (AML_NODE_HEADER *)RdNode
1657 );
1658 if (EFI_ERROR (Status)) {
1659 ASSERT (0);
1660 goto error_handler;
1661 }
1662 }
1663
1664 return Status;
1665
1666error_handler:
1667 if (RdNode != NULL) {
1668 AmlDeleteTree ((AML_NODE_HEADER *)RdNode);
1669 }
1670
1671 return Status;
1672}
PACKED struct @101 EFI_ACPI_DWORD_ADDRESS_SPACE_DESCRIPTOR
PACKED struct @103 EFI_ACPI_EXTENDED_INTERRUPT_DESCRIPTOR
PACKED struct @100 EFI_ACPI_QWORD_ADDRESS_SPACE_DESCRIPTOR
PACKED struct @95 EFI_ACPI_IO_PORT_DESCRIPTOR
PACKED struct @99 EFI_ACPI_32_BIT_FIXED_MEMORY_RANGE_DESCRIPTOR
PACKED struct @102 EFI_ACPI_WORD_ADDRESS_SPACE_DESCRIPTOR
PACKED struct @107 EFI_ACPI_GENERIC_REGISTER_DESCRIPTOR
BOOLEAN EFIAPI AmlNodeHasOpCode(IN AML_OBJECT_NODE_HANDLE ObjectNode, IN UINT8 OpCode, IN UINT8 SubOpCode)
Definition: AmlApiHelper.c:124
EFI_STATUS EFIAPI AmlAppendRdNode(IN AML_OBJECT_NODE_HANDLE BufferOpNode, IN AML_DATA_NODE_HANDLE NewRdNode)
AML_MEMORY_ATTRIBUTES_MTP
Definition: AmlLib.h:96
AML_MEMORY_ATTRIBUTES_MEM
Definition: AmlLib.h:76
void * AML_DATA_NODE_HANDLE
Definition: AmlLib.h:59
void * AML_OBJECT_NODE_HANDLE
Definition: AmlLib.h:55
void * AML_NODE_HANDLE
Definition: AmlLib.h:47
EFI_STATUS EFIAPI AmlCreateDataNode(IN EAML_NODE_DATA_TYPE DataType, IN CONST UINT8 *Data, IN UINT32 DataSize, OUT AML_DATA_NODE **NewDataNodePtr)
Definition: AmlNode.c:275
EFI_STATUS EFIAPI AmlCodeGenEndTag(IN UINT8 CheckSum OPTIONAL, IN AML_OBJECT_NODE *ParentNode OPTIONAL, OUT AML_DATA_NODE **NewRdNode OPTIONAL)
STATIC EFI_STATUS EFIAPI AmlCodeGenRdDWordSpace(IN UINT8 ResourceType, IN BOOLEAN IsResourceConsumer, IN BOOLEAN IsPosDecode, IN BOOLEAN IsMinFixed, IN BOOLEAN IsMaxFixed, IN UINT8 TypeSpecificFlags, IN UINT32 AddressGranularity, IN UINT32 AddressMinimum, IN UINT32 AddressMaximum, IN UINT32 AddressTranslation, IN UINT32 RangeLength, IN UINT8 ResourceSourceIndex, IN CONST CHAR8 *ResourceSource, IN AML_OBJECT_NODE_HANDLE NameOpNode, OPTIONAL OUT AML_DATA_NODE_HANDLE *NewRdNode OPTIONAL)
EFI_STATUS EFIAPI AmlCodeGenRdDWordIo(IN BOOLEAN IsResourceConsumer, IN BOOLEAN IsMinFixed, IN BOOLEAN IsMaxFixed, IN BOOLEAN IsPosDecode, IN UINT8 IsaRanges, IN UINT32 AddressGranularity, IN UINT32 AddressMinimum, IN UINT32 AddressMaximum, IN UINT32 AddressTranslation, IN UINT32 RangeLength, IN UINT8 ResourceSourceIndex, IN CONST CHAR8 *ResourceSource, IN BOOLEAN IsDenseTranslation, IN BOOLEAN IsTypeStatic, IN AML_OBJECT_NODE_HANDLE NameOpNode, OPTIONAL OUT AML_DATA_NODE_HANDLE *NewRdNode OPTIONAL)
EFI_STATUS EFIAPI AmlCodeGenRdQWordIo(IN BOOLEAN IsResourceConsumer, IN BOOLEAN IsMinFixed, IN BOOLEAN IsMaxFixed, IN BOOLEAN IsPosDecode, IN UINT8 IsaRanges, IN UINT64 AddressGranularity, IN UINT64 AddressMinimum, IN UINT64 AddressMaximum, IN UINT64 AddressTranslation, IN UINT64 RangeLength, IN UINT8 ResourceSourceIndex, IN CONST CHAR8 *ResourceSource, IN BOOLEAN IsDenseTranslation, IN BOOLEAN IsTypeStatic, IN AML_OBJECT_NODE_HANDLE NameOpNode, OPTIONAL OUT AML_DATA_NODE_HANDLE *NewRdNode OPTIONAL)
STATIC EFI_STATUS EFIAPI AmlCodeGenRdWordSpace(IN UINT8 ResourceType, IN BOOLEAN IsResourceConsumer, IN BOOLEAN IsPosDecode, IN BOOLEAN IsMinFixed, IN BOOLEAN IsMaxFixed, IN UINT8 TypeSpecificFlags, IN UINT16 AddressGranularity, IN UINT16 AddressMinimum, IN UINT16 AddressMaximum, IN UINT16 AddressTranslation, IN UINT16 RangeLength, IN UINT8 ResourceSourceIndex, IN CONST CHAR8 *ResourceSource, IN AML_OBJECT_NODE_HANDLE NameOpNode, OPTIONAL OUT AML_DATA_NODE_HANDLE *NewRdNode OPTIONAL)
STATIC UINT8 EFIAPI MemoryRangeSpecificFlags(IN UINT8 Cacheable, IN BOOLEAN IsReadWrite, IN UINT8 MemoryRangeType, IN BOOLEAN IsTypeStatic)
EFI_STATUS EFIAPI AmlCodeGenRdDWordMemory(IN BOOLEAN IsResourceConsumer, IN BOOLEAN IsPosDecode, IN BOOLEAN IsMinFixed, IN BOOLEAN IsMaxFixed, IN AML_MEMORY_ATTRIBUTES_MEM Cacheable, IN BOOLEAN IsReadWrite, IN UINT32 AddressGranularity, IN UINT32 AddressMinimum, IN UINT32 AddressMaximum, IN UINT32 AddressTranslation, IN UINT32 RangeLength, IN UINT8 ResourceSourceIndex, IN CONST CHAR8 *ResourceSource, IN AML_MEMORY_ATTRIBUTES_MTP MemoryRangeType, IN BOOLEAN IsTypeStatic, IN AML_OBJECT_NODE_HANDLE NameOpNode, OPTIONAL OUT AML_DATA_NODE_HANDLE *NewRdNode OPTIONAL)
STATIC EFI_STATUS EFIAPI CheckAddressSpaceFields(IN BOOLEAN IsMinFixed, IN BOOLEAN IsMaxFixed, IN UINT64 AddressGranularity, IN UINT64 AddressMinimum, IN UINT64 AddressMaximum, IN UINT64 AddressTranslation, IN UINT64 RangeLength)
EFI_STATUS EFIAPI AmlCodeGenRdWordIo(IN BOOLEAN IsResourceConsumer, IN BOOLEAN IsMinFixed, IN BOOLEAN IsMaxFixed, IN BOOLEAN IsPosDecode, IN UINT8 IsaRanges, IN UINT16 AddressGranularity, IN UINT16 AddressMinimum, IN UINT16 AddressMaximum, IN UINT16 AddressTranslation, IN UINT16 RangeLength, IN UINT8 ResourceSourceIndex, IN CONST CHAR8 *ResourceSource, IN BOOLEAN IsDenseTranslation, IN BOOLEAN IsTypeStatic, IN AML_OBJECT_NODE_HANDLE NameOpNode, OPTIONAL OUT AML_DATA_NODE_HANDLE *NewRdNode OPTIONAL)
STATIC EFI_STATUS EFIAPI LinkRdNode(IN AML_DATA_NODE *RdNode, IN AML_OBJECT_NODE *ParentNode, OUT AML_DATA_NODE **NewRdNode)
EFI_STATUS EFIAPI AmlCodeGenRdRegister(IN UINT8 AddressSpace, IN UINT8 BitWidth, IN UINT8 BitOffset, IN UINT64 Address, IN UINT8 AccessSize, IN AML_OBJECT_NODE_HANDLE NameOpNode OPTIONAL, OUT AML_DATA_NODE_HANDLE *NewRdNode OPTIONAL)
EFI_STATUS EFIAPI AmlCodeGenRdInterrupt(IN BOOLEAN ResourceConsumer, IN BOOLEAN EdgeTriggered, IN BOOLEAN ActiveLow, IN BOOLEAN Shared, IN UINT32 *IrqList, IN UINT8 IrqCount, IN AML_OBJECT_NODE_HANDLE NameOpNode OPTIONAL, OUT AML_DATA_NODE_HANDLE *NewRdNode OPTIONAL)
STATIC UINT8 EFIAPI AddressSpaceGeneralFlags(IN BOOLEAN IsPosDecode, IN BOOLEAN IsMinFixed, IN BOOLEAN IsMaxFixed)
STATIC EFI_STATUS EFIAPI AmlCodeGenRdQWordSpace(IN UINT8 ResourceType, IN BOOLEAN IsResourceConsumer, IN BOOLEAN IsPosDecode, IN BOOLEAN IsMinFixed, IN BOOLEAN IsMaxFixed, IN UINT8 TypeSpecificFlags, IN UINT64 AddressGranularity, IN UINT64 AddressMinimum, IN UINT64 AddressMaximum, IN UINT64 AddressTranslation, IN UINT64 RangeLength, IN UINT8 ResourceSourceIndex, IN CONST CHAR8 *ResourceSource, IN AML_OBJECT_NODE_HANDLE NameOpNode, OPTIONAL OUT AML_DATA_NODE_HANDLE *NewRdNode OPTIONAL)
STATIC UINT8 EFIAPI RdIoRangeSpecificFlags(IN UINT8 IsaRanges, IN BOOLEAN IsDenseTranslation, IN BOOLEAN IsTypeStatic)
EFI_STATUS EFIAPI AmlCodeGenRdIo(IN BOOLEAN IsDecoder16, IN UINT16 AddressMinimum, IN UINT16 AddressMaximum, IN UINT8 Alignment, IN UINT8 RangeLength, IN AML_OBJECT_NODE_HANDLE NameOpNode, OPTIONAL OUT AML_DATA_NODE_HANDLE *NewRdNode OPTIONAL)
EFI_STATUS EFIAPI AmlCodeGenRdQWordMemory(IN BOOLEAN IsResourceConsumer, IN BOOLEAN IsPosDecode, IN BOOLEAN IsMinFixed, IN BOOLEAN IsMaxFixed, IN AML_MEMORY_ATTRIBUTES_MEM Cacheable, IN BOOLEAN IsReadWrite, IN UINT64 AddressGranularity, IN UINT64 AddressMinimum, IN UINT64 AddressMaximum, IN UINT64 AddressTranslation, IN UINT64 RangeLength, IN UINT8 ResourceSourceIndex, IN CONST CHAR8 *ResourceSource, IN AML_MEMORY_ATTRIBUTES_MTP MemoryRangeType, IN BOOLEAN IsTypeStatic, IN AML_OBJECT_NODE_HANDLE NameOpNode, OPTIONAL OUT AML_DATA_NODE_HANDLE *NewRdNode OPTIONAL)
EFI_STATUS EFIAPI AmlCodeGenRdMemory32Fixed(BOOLEAN IsReadWrite, UINT32 Address, UINT32 RangeLength, AML_OBJECT_NODE_HANDLE NameOpNode, AML_DATA_NODE_HANDLE *NewMemNode)
EFI_STATUS EFIAPI AmlCodeGenRdWordBusNumber(IN BOOLEAN IsResourceConsumer, IN BOOLEAN IsMinFixed, IN BOOLEAN IsMaxFixed, IN BOOLEAN IsPosDecode, IN UINT16 AddressGranularity, IN UINT16 AddressMinimum, IN UINT16 AddressMaximum, IN UINT16 AddressTranslation, IN UINT16 RangeLength, IN UINT8 ResourceSourceIndex, IN CONST CHAR8 *ResourceSource, IN AML_OBJECT_NODE_HANDLE NameOpNode, OPTIONAL OUT AML_DATA_NODE_HANDLE *NewRdNode OPTIONAL)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define STATIC
Definition: Base.h:264
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
AML_NODE_HANDLE EFIAPI AmlGetFixedArgument(IN AML_OBJECT_NODE_HANDLE ObjectNode, IN EAML_PARSE_INDEX Index)
AML_NODE_HANDLE EFIAPI AmlGetNextVariableArgument(IN AML_NODE_HANDLE Node, IN AML_NODE_HANDLE CurrVarArg)
EAML_NODE_TYPE EFIAPI AmlGetNodeType(IN AML_NODE_HANDLE Node)
EFI_STATUS EFIAPI AmlVarListAddTail(IN AML_NODE_HANDLE ParentNode, IN AML_NODE_HANDLE NewNode)
@ EAmlParseIndexTerm1
Second fixed argument index.
Definition: AmlDefines.h:66
@ EAmlNodeObject
Definition: AmlDefines.h:174
@ EAmlNodeDataTypeResourceData
Resource data element.
Definition: AmlDefines.h:44
EFI_STATUS EFIAPI AmlDeleteTree(IN AML_NODE_HANDLE Node)