]> git.proxmox.com Git - mirror_edk2.git/blame - DynamicTablesPkg/Library/Common/AmlLib/CodeGen/AmlResourceDataCodeGen.c
DynamicTablesPkg: AML Code generation for memory ranges
[mirror_edk2.git] / DynamicTablesPkg / Library / Common / AmlLib / CodeGen / AmlResourceDataCodeGen.c
CommitLineData
01ea2ad5
PG
1/** @file\r
2 AML Resource Data Code Generation.\r
3\r
691c5f77 4 Copyright (c) 2020 - 2021, Arm Limited. All rights reserved.<BR>\r
01ea2ad5
PG
5\r
6 SPDX-License-Identifier: BSD-2-Clause-Patent\r
7\r
8 @par Glossary:\r
9 - Rd or RD - Resource Data\r
10 - Rds or RDS - Resource Data Small\r
11 - Rdl or RDL - Resource Data Large\r
12**/\r
13\r
14#include <AmlNodeDefines.h>\r
15#include <CodeGen/AmlResourceDataCodeGen.h>\r
16\r
17#include <AmlCoreInterface.h>\r
18#include <AmlDefines.h>\r
19#include <Api/AmlApiHelper.h>\r
20#include <Tree/AmlNode.h>\r
21#include <ResourceData/AmlResourceData.h>\r
22\r
23/** If ParentNode is not NULL, append RdNode.\r
24 If NewRdNode is not NULL, update its value to RdNode.\r
25\r
26 @param [in] RdNode Newly created Resource Data node.\r
22873f58
PG
27 RdNode is deleted if an error occurs.\r
28 @param [in] ParentNode If not NULL, ParentNode must:\r
29 - be a NameOp node, i.e. have the AML_NAME_OP\r
30 opcode (cf "Name ()" ASL statement)\r
31 - contain a list of resource data elements\r
32 (cf "ResourceTemplate ()" ASL statement)\r
33 RdNode is then added at the end of the variable\r
34 list of resource data elements, but before the\r
35 "End Tag" Resource Data.\r
2dd7dd39
PG
36 @param [out] NewRdNode If not NULL:\r
37 - and Success, contains RdNode.\r
38 - and Error, reset to NULL.\r
01ea2ad5
PG
39\r
40 @retval EFI_SUCCESS The function completed successfully.\r
41 @retval EFI_INVALID_PARAMETER Invalid parameter.\r
42**/\r
43STATIC\r
44EFI_STATUS\r
45EFIAPI\r
46LinkRdNode (\r
731c67e1
MK
47 IN AML_DATA_NODE *RdNode,\r
48 IN AML_OBJECT_NODE *ParentNode,\r
49 OUT AML_DATA_NODE **NewRdNode\r
01ea2ad5
PG
50 )\r
51{\r
731c67e1
MK
52 EFI_STATUS Status;\r
53 EFI_STATUS Status1;\r
54 AML_OBJECT_NODE *BufferOpNode;\r
01ea2ad5
PG
55\r
56 if (NewRdNode != NULL) {\r
2dd7dd39 57 *NewRdNode = NULL;\r
01ea2ad5
PG
58 }\r
59\r
01ea2ad5 60 if (ParentNode != NULL) {\r
22873f58
PG
61 // Check this is a NameOp node.\r
62 if ((!AmlNodeHasOpCode (ParentNode, AML_NAME_OP, 0))) {\r
63 ASSERT (0);\r
64 Status = EFI_INVALID_PARAMETER;\r
65 goto error_handler;\r
66 }\r
67\r
68 // Get the value which is represented as a BufferOp object node\r
69 // which is the 2nd fixed argument (i.e. index 1).\r
70 BufferOpNode = (AML_OBJECT_NODE_HANDLE)AmlGetFixedArgument (\r
71 ParentNode,\r
72 EAmlParseIndexTerm1\r
73 );\r
74 if ((BufferOpNode == NULL) ||\r
75 (AmlGetNodeType ((AML_NODE_HANDLE)BufferOpNode) != EAmlNodeObject) ||\r
731c67e1
MK
76 (!AmlNodeHasOpCode (BufferOpNode, AML_BUFFER_OP, 0)))\r
77 {\r
22873f58
PG
78 ASSERT (0);\r
79 Status = EFI_INVALID_PARAMETER;\r
80 goto error_handler;\r
81 }\r
82\r
83 // Add RdNode as the last element, but before the EndTag.\r
84 Status = AmlAppendRdNode (BufferOpNode, RdNode);\r
01ea2ad5
PG
85 if (EFI_ERROR (Status)) {\r
86 ASSERT (0);\r
22873f58 87 goto error_handler;\r
01ea2ad5
PG
88 }\r
89 }\r
90\r
2dd7dd39
PG
91 if (NewRdNode != NULL) {\r
92 *NewRdNode = RdNode;\r
93 }\r
94\r
4fdf843c 95 return EFI_SUCCESS;\r
22873f58
PG
96\r
97error_handler:\r
731c67e1 98 Status1 = AmlDeleteTree ((AML_NODE_HEADER *)RdNode);\r
22873f58
PG
99 ASSERT_EFI_ERROR (Status1);\r
100 // Return original error.\r
101 return Status;\r
01ea2ad5
PG
102}\r
103\r
7f1861be
PG
104/** Construct the TypeSpecificFlags field for IO ranges.\r
105\r
106 See ACPI 6.4 spec, s19.6.34 for more.\r
107\r
108 @param [in] IsaRanges Possible values are:\r
109 0-Reserved\r
110 1-NonISAOnly\r
111 2-ISAOnly\r
112 3-EntireRange\r
113 See ACPI 6.4 spec, s19.6.34 for more.\r
114 @param [in] IsDenseTranslation TranslationDensity parameter.\r
115 @param [in] IsTypeStatic TranslationType parameter.\r
116\r
117 @return A type specific flags value.\r
118 MAX_UINT8 if error.\r
119**/\r
120STATIC\r
121UINT8\r
122EFIAPI\r
123RdIoRangeSpecificFlags (\r
124 IN UINT8 IsaRanges,\r
125 IN BOOLEAN IsDenseTranslation,\r
126 IN BOOLEAN IsTypeStatic\r
127 )\r
128{\r
129 // Only check type specific parameters.\r
130 if (IsaRanges > 3) {\r
131 ASSERT (0);\r
132 return MAX_UINT8;\r
133 }\r
134\r
135 // Construct TypeSpecificFlags and call the generic function.\r
136 // Cf ACPI 6.4 specification, Table 6.50:\r
137 // "Table 6.50: I/O Resource Flag (Resource Type = 1) Definitions"\r
138 return IsaRanges |\r
139 (IsTypeStatic ? 0 : BIT4) |\r
140 (IsDenseTranslation ? 0 : BIT5);\r
141}\r
142\r
143/** Construct the TypeSpecificFlags field for Memory ranges.\r
144\r
145 @param [in] Cacheable Possible values are:\r
146 0-The memory is non-cacheable\r
147 1-The memory is cacheable\r
148 2-The memory is cacheable and supports\r
149 write combining\r
150 3-The memory is cacheable and prefetchable\r
151 @param [in] IsReadWrite ReadAndWrite parameter.\r
152 @param [in] MemoryRangeType Possible values are:\r
153 0-AddressRangeMemory\r
154 1-AddressRangeReserved\r
155 2-AddressRangeACPI\r
156 3-AddressRangeNVS\r
157 See ACPI 6.4 spec, s19.6.35 for more.\r
158 @param [in] IsTypeStatic TranslationType parameter.\r
159\r
160 @return A type specific flags value.\r
161 MAX_UINT8 if error.\r
162**/\r
163STATIC\r
164UINT8\r
165EFIAPI\r
166MemoryRangeSpecificFlags (\r
167 IN UINT8 Cacheable,\r
168 IN BOOLEAN IsReadWrite,\r
169 IN UINT8 MemoryRangeType,\r
170 IN BOOLEAN IsTypeStatic\r
171 )\r
172{\r
173 // Only check type specific parameters.\r
174 if ((Cacheable > 3) ||\r
175 (MemoryRangeType > 3))\r
176 {\r
177 ASSERT (0);\r
178 return MAX_UINT8;\r
179 }\r
180\r
181 // Construct TypeSpecificFlags and call the generic function.\r
182 // Cf ACPI 6.4 specification, Table 6.49:\r
183 // "Memory Resource Flag (Resource Type = 0) Definitions"\r
184 return (IsReadWrite ? BIT0 : 0) |\r
185 (Cacheable << 1) |\r
186 (MemoryRangeType << 3) |\r
187 (IsTypeStatic ? 0 : BIT5);\r
188}\r
189\r
190/** Construct the GeneralFlags field of any Address Space Resource Descriptors.\r
191\r
192 E.g.:\r
193 ACPI 6.4 specification, s6.4.3.5.1 "QWord Address Space Descriptor"\r
194 for QWord\r
195\r
196 See ACPI 6.4 spec, s19.6.36 for more.\r
197\r
198 @param [in] IsPosDecode Decode parameter\r
199 @param [in] IsMinFixed Minimum address is fixed.\r
200 @param [in] IsMaxFixed Maximum address is fixed.\r
201\r
202 @return A type specific flags value.\r
203**/\r
204STATIC\r
205UINT8\r
206EFIAPI\r
207AddressSpaceGeneralFlags (\r
208 IN BOOLEAN IsPosDecode,\r
209 IN BOOLEAN IsMinFixed,\r
210 IN BOOLEAN IsMaxFixed\r
211 )\r
212{\r
213 return (IsPosDecode ? 0 : BIT1) |\r
214 (IsMinFixed ? BIT2 : 0) |\r
215 (IsMaxFixed ? BIT3 : 0);\r
216}\r
217\r
218/** Check Address Space Descriptor Fields.\r
219\r
220 Cf. ACPI 6.4 Table 6.44:\r
221 "Valid Combination of Address Space Descriptor Fields"\r
222\r
223 See ACPI 6.4 spec, s19.6.36 for more.\r
224\r
225 @param [in] IsMinFixed Minimum address is fixed.\r
226 @param [in] IsMaxFixed Maximum address is fixed.\r
227 @param [in] AddressGranularity Address granularity.\r
228 @param [in] AddressMinimum Minimum address.\r
229 @param [in] AddressMaximum Maximum address.\r
230 @param [in] AddressTranslation Address translation.\r
231 @param [in] RangeLength Range length.\r
232\r
233 @retval EFI_SUCCESS The function completed successfully.\r
234 @retval EFI_INVALID_PARAMETER Invalid parameter.\r
235**/\r
236STATIC\r
237EFI_STATUS\r
238EFIAPI\r
239CheckAddressSpaceFields (\r
240 IN BOOLEAN IsMinFixed,\r
241 IN BOOLEAN IsMaxFixed,\r
242 IN UINT64 AddressGranularity,\r
243 IN UINT64 AddressMinimum,\r
244 IN UINT64 AddressMaximum,\r
245 IN UINT64 AddressTranslation,\r
246 IN UINT64 RangeLength\r
247 )\r
248{\r
249 if ((AddressMinimum > AddressMaximum) ||\r
250 (RangeLength > (AddressMaximum - AddressMinimum + 1)) ||\r
251 ((AddressGranularity != 0) &&\r
252 (((AddressGranularity + 1) & AddressGranularity) != 0)))\r
253 {\r
254 ASSERT (0);\r
255 return EFI_INVALID_PARAMETER;\r
256 }\r
257\r
258 if (RangeLength != 0) {\r
259 if (IsMinFixed ^ IsMaxFixed) {\r
260 ASSERT (0);\r
261 return EFI_INVALID_PARAMETER;\r
262 } else if (IsMinFixed &&\r
263 IsMaxFixed &&\r
264 (AddressGranularity != 0) &&\r
265 ((AddressMaximum - AddressMinimum + 1) != RangeLength))\r
266 {\r
267 ASSERT (0);\r
268 return EFI_INVALID_PARAMETER;\r
269 }\r
270 } else {\r
271 if (IsMinFixed && IsMaxFixed) {\r
272 ASSERT (0);\r
273 return EFI_INVALID_PARAMETER;\r
274 } else if (IsMinFixed &&\r
275 ((AddressMinimum & AddressGranularity) != 0))\r
276 {\r
277 ASSERT (0);\r
278 return EFI_INVALID_PARAMETER;\r
279 } else if (IsMaxFixed &&\r
280 (((AddressMaximum + 1) & AddressGranularity) != 0))\r
281 {\r
282 ASSERT (0);\r
283 return EFI_INVALID_PARAMETER;\r
284 }\r
285 }\r
286\r
287 return EFI_SUCCESS;\r
288}\r
289\r
290/** Code generation for the "DWordSpace ()" ASL function.\r
291\r
292 The Resource Data effectively created is a DWord Address Space Resource\r
293 Data. Cf ACPI 6.4:\r
294 - s6.4.3.5.2 "DWord Address Space Descriptor".\r
295 - s19.6.36 "DWordSpace".\r
296\r
297 The created resource data node can be:\r
298 - appended to the list of resource data elements of the NameOpNode.\r
299 In such case NameOpNode must be defined by a the "Name ()" ASL statement\r
300 and initially contain a "ResourceTemplate ()".\r
301 - returned through the NewRdNode parameter.\r
302\r
303 See ACPI 6.4 spec, s19.6.36 for more.\r
304\r
305 @param [in] ResourceType Resource type.\r
306 Possible values are:\r
307 0: Memory range\r
308 1: I/O range\r
309 2: Bus number range\r
310 3-191: Reserved\r
311 192-255: Hardware Vendor Defined\r
312 See ACPI 6.4 spec, s6.4.3.5.2 for more.\r
313 @param [in] IsResourceConsumer ResourceUsage parameter.\r
314 @param [in] IsPosDecode Decode parameter\r
315 @param [in] IsMinFixed Minimum address is fixed.\r
316 @param [in] IsMaxFixed Maximum address is fixed.\r
317 @param [in] TypeSpecificFlags Type specific flags.\r
318 See ACPI 6.4 spec, s6.4.3.5.5\r
319 "Resource Type Specific Flags".\r
320 @param [in] AddressGranularity Address granularity.\r
321 @param [in] AddressMinimum Minimum address.\r
322 @param [in] AddressMaximum Maximum address.\r
323 @param [in] AddressTranslation Address translation.\r
324 @param [in] RangeLength Range length.\r
325 @param [in] ResourceSourceIndex Resource Source index.\r
326 Unused. Must be 0.\r
327 @param [in] ResourceSource Resource Source.\r
328 Unused. Must be NULL.\r
329 @param [in] NameOpNode NameOp object node defining a named object.\r
330 If provided, append the new resource data\r
331 node to the list of resource data elements\r
332 of this node.\r
333 @param [out] NewRdNode If provided and success,\r
334 contain the created node.\r
335\r
336 @retval EFI_SUCCESS The function completed successfully.\r
337 @retval EFI_INVALID_PARAMETER Invalid parameter.\r
338 @retval EFI_OUT_OF_RESOURCES Could not allocate memory.\r
339**/\r
340STATIC\r
341EFI_STATUS\r
342EFIAPI\r
343AmlCodeGenRdDWordSpace (\r
344 IN UINT8 ResourceType,\r
345 IN BOOLEAN IsResourceConsumer,\r
346 IN BOOLEAN IsPosDecode,\r
347 IN BOOLEAN IsMinFixed,\r
348 IN BOOLEAN IsMaxFixed,\r
349 IN UINT8 TypeSpecificFlags,\r
350 IN UINT32 AddressGranularity,\r
351 IN UINT32 AddressMinimum,\r
352 IN UINT32 AddressMaximum,\r
353 IN UINT32 AddressTranslation,\r
354 IN UINT32 RangeLength,\r
355 IN UINT8 ResourceSourceIndex,\r
356 IN CONST CHAR8 *ResourceSource,\r
357 IN AML_OBJECT_NODE_HANDLE NameOpNode, OPTIONAL\r
358 OUT AML_DATA_NODE_HANDLE *NewRdNode OPTIONAL\r
359 )\r
360{\r
361 EFI_STATUS Status;\r
362 AML_DATA_NODE *RdNode;\r
363 EFI_ACPI_DWORD_ADDRESS_SPACE_DESCRIPTOR RdDWord;\r
364\r
365 // ResourceSource and ResourceSourceIndex are unused.\r
366 if ((TypeSpecificFlags == MAX_UINT8) ||\r
367 (ResourceSourceIndex != 0) ||\r
368 (ResourceSource != NULL) ||\r
369 ((NameOpNode == NULL) && (NewRdNode == NULL)))\r
370 {\r
371 ASSERT (0);\r
372 return EFI_INVALID_PARAMETER;\r
373 }\r
374\r
375 Status = CheckAddressSpaceFields (\r
376 IsMinFixed,\r
377 IsMaxFixed,\r
378 AddressGranularity,\r
379 AddressMinimum,\r
380 AddressMaximum,\r
381 AddressTranslation,\r
382 RangeLength\r
383 );\r
384 if (EFI_ERROR (Status)) {\r
385 ASSERT (0);\r
386 return Status;\r
387 }\r
388\r
389 // Header\r
390 RdDWord.Header.Header.Bits.Name =\r
391 ACPI_LARGE_DWORD_ADDRESS_SPACE_DESCRIPTOR_NAME;\r
392 RdDWord.Header.Header.Bits.Type = ACPI_LARGE_ITEM_FLAG;\r
393 RdDWord.Header.Length = sizeof (EFI_ACPI_DWORD_ADDRESS_SPACE_DESCRIPTOR) -\r
394 sizeof (ACPI_LARGE_RESOURCE_HEADER);\r
395\r
396 // Body\r
397 RdDWord.ResType = ResourceType;\r
398 RdDWord.GenFlag = AddressSpaceGeneralFlags (\r
399 IsPosDecode,\r
400 IsMinFixed,\r
401 IsMaxFixed\r
402 );\r
403 RdDWord.SpecificFlag = TypeSpecificFlags;\r
404 RdDWord.AddrSpaceGranularity = AddressGranularity;\r
405 RdDWord.AddrRangeMin = AddressMinimum;\r
406 RdDWord.AddrRangeMax = AddressMaximum;\r
407 RdDWord.AddrTranslationOffset = AddressTranslation;\r
408 RdDWord.AddrLen = RangeLength;\r
409\r
410 Status = AmlCreateDataNode (\r
411 EAmlNodeDataTypeResourceData,\r
412 (UINT8 *)&RdDWord,\r
413 sizeof (EFI_ACPI_DWORD_ADDRESS_SPACE_DESCRIPTOR),\r
414 &RdNode\r
415 );\r
416 if (EFI_ERROR (Status)) {\r
417 ASSERT (0);\r
418 return Status;\r
419 }\r
420\r
421 return LinkRdNode (RdNode, NameOpNode, NewRdNode);\r
422}\r
423\r
424/** Code generation for the "DWordIO ()" ASL function.\r
425\r
426 The Resource Data effectively created is a DWord Address Space Resource\r
427 Data. Cf ACPI 6.4:\r
428 - s6.4.3.5.2 "DWord Address Space Descriptor".\r
429 - s19.6.34 "DWordIO".\r
430\r
431 The created resource data node can be:\r
432 - appended to the list of resource data elements of the NameOpNode.\r
433 In such case NameOpNode must be defined by a the "Name ()" ASL statement\r
434 and initially contain a "ResourceTemplate ()".\r
435 - returned through the NewRdNode parameter.\r
436\r
437 See ACPI 6.4 spec, s19.6.34 for more.\r
438\r
439 @param [in] IsResourceConsumer ResourceUsage parameter.\r
440 @param [in] IsMinFixed Minimum address is fixed.\r
441 @param [in] IsMaxFixed Maximum address is fixed.\r
442 @param [in] IsPosDecode Decode parameter\r
443 @param [in] IsaRanges Possible values are:\r
444 0-Reserved\r
445 1-NonISAOnly\r
446 2-ISAOnly\r
447 3-EntireRange\r
448 @param [in] AddressGranularity Address granularity.\r
449 @param [in] AddressMinimum Minimum address.\r
450 @param [in] AddressMaximum Maximum address.\r
451 @param [in] AddressTranslation Address translation.\r
452 @param [in] RangeLength Range length.\r
453 @param [in] ResourceSourceIndex Resource Source index.\r
454 Unused. Must be 0.\r
455 @param [in] ResourceSource Resource Source.\r
456 Unused. Must be NULL.\r
457 @param [in] IsDenseTranslation TranslationDensity parameter.\r
458 @param [in] IsTypeStatic TranslationType parameter.\r
459 @param [in] NameOpNode NameOp object node defining a named object.\r
460 If provided, append the new resource data\r
461 node to the list of resource data elements\r
462 of this node.\r
463 @param [out] NewRdNode If provided and success,\r
464 contain the created node.\r
465\r
466 @retval EFI_SUCCESS The function completed successfully.\r
467 @retval EFI_INVALID_PARAMETER Invalid parameter.\r
468 @retval EFI_OUT_OF_RESOURCES Could not allocate memory.\r
469**/\r
470EFI_STATUS\r
471EFIAPI\r
472AmlCodeGenRdDWordIo (\r
473 IN BOOLEAN IsResourceConsumer,\r
474 IN BOOLEAN IsMinFixed,\r
475 IN BOOLEAN IsMaxFixed,\r
476 IN BOOLEAN IsPosDecode,\r
477 IN UINT8 IsaRanges,\r
478 IN UINT32 AddressGranularity,\r
479 IN UINT32 AddressMinimum,\r
480 IN UINT32 AddressMaximum,\r
481 IN UINT32 AddressTranslation,\r
482 IN UINT32 RangeLength,\r
483 IN UINT8 ResourceSourceIndex,\r
484 IN CONST CHAR8 *ResourceSource,\r
485 IN BOOLEAN IsDenseTranslation,\r
486 IN BOOLEAN IsTypeStatic,\r
487 IN AML_OBJECT_NODE_HANDLE NameOpNode, OPTIONAL\r
488 OUT AML_DATA_NODE_HANDLE *NewRdNode OPTIONAL\r
489 )\r
490{\r
491 return AmlCodeGenRdDWordSpace (\r
492 ACPI_ADDRESS_SPACE_TYPE_IO,\r
493 IsResourceConsumer,\r
494 IsPosDecode,\r
495 IsMinFixed,\r
496 IsMaxFixed,\r
497 RdIoRangeSpecificFlags (\r
498 IsaRanges,\r
499 IsDenseTranslation,\r
500 IsTypeStatic\r
501 ),\r
502 AddressGranularity,\r
503 AddressMinimum,\r
504 AddressMaximum,\r
505 AddressTranslation,\r
506 RangeLength,\r
507 ResourceSourceIndex,\r
508 ResourceSource,\r
509 NameOpNode,\r
510 NewRdNode\r
511 );\r
512}\r
513\r
514/** Code generation for the "DWordMemory ()" ASL function.\r
515\r
516 The Resource Data effectively created is a DWord Address Space Resource\r
517 Data. Cf ACPI 6.4:\r
518 - s6.4.3.5.2 "DWord Address Space Descriptor".\r
519 - s19.6.35 "DWordMemory".\r
520\r
521 The created resource data node can be:\r
522 - appended to the list of resource data elements of the NameOpNode.\r
523 In such case NameOpNode must be defined by a the "Name ()" ASL statement\r
524 and initially contain a "ResourceTemplate ()".\r
525 - returned through the NewRdNode parameter.\r
526\r
527 See ACPI 6.4 spec, s19.6.35 for more.\r
528\r
529 @param [in] IsResourceConsumer ResourceUsage parameter.\r
530 @param [in] IsPosDecode Decode parameter\r
531 @param [in] IsMinFixed Minimum address is fixed.\r
532 @param [in] IsMaxFixed Maximum address is fixed.\r
533 @param [in] Cacheable Possible values are:\r
534 0-The memory is non-cacheable\r
535 1-The memory is cacheable\r
536 2-The memory is cacheable and supports\r
537 write combining\r
538 3-The memory is cacheable and prefetchable\r
539 @param [in] IsReadWrite ReadAndWrite parameter.\r
540 @param [in] AddressGranularity Address granularity.\r
541 @param [in] AddressMinimum Minimum address.\r
542 @param [in] AddressMaximum Maximum address.\r
543 @param [in] AddressTranslation Address translation.\r
544 @param [in] RangeLength Range length.\r
545 @param [in] ResourceSourceIndex Resource Source index.\r
546 Unused. Must be 0.\r
547 @param [in] ResourceSource Resource Source.\r
548 Unused. Must be NULL.\r
549 @param [in] MemoryRangeType Possible values are:\r
550 0-AddressRangeMemory\r
551 1-AddressRangeReserved\r
552 2-AddressRangeACPI\r
553 3-AddressRangeNVS\r
554 @param [in] IsTypeStatic TranslationType parameter.\r
555 @param [in] NameOpNode NameOp object node defining a named object.\r
556 If provided, append the new resource data\r
557 node to the list of resource data elements\r
558 of this node.\r
559 @param [out] NewRdNode If provided and success,\r
560 contain the created node.\r
561\r
562 @retval EFI_SUCCESS The function completed successfully.\r
563 @retval EFI_INVALID_PARAMETER Invalid parameter.\r
564 @retval EFI_OUT_OF_RESOURCES Could not allocate memory.\r
565**/\r
566EFI_STATUS\r
567EFIAPI\r
568AmlCodeGenRdDWordMemory (\r
569 IN BOOLEAN IsResourceConsumer,\r
570 IN BOOLEAN IsPosDecode,\r
571 IN BOOLEAN IsMinFixed,\r
572 IN BOOLEAN IsMaxFixed,\r
573 IN UINT8 Cacheable,\r
574 IN BOOLEAN IsReadWrite,\r
575 IN UINT32 AddressGranularity,\r
576 IN UINT32 AddressMinimum,\r
577 IN UINT32 AddressMaximum,\r
578 IN UINT32 AddressTranslation,\r
579 IN UINT32 RangeLength,\r
580 IN UINT8 ResourceSourceIndex,\r
581 IN CONST CHAR8 *ResourceSource,\r
582 IN UINT8 MemoryRangeType,\r
583 IN BOOLEAN IsTypeStatic,\r
584 IN AML_OBJECT_NODE_HANDLE NameOpNode, OPTIONAL\r
585 OUT AML_DATA_NODE_HANDLE *NewRdNode OPTIONAL\r
586 )\r
587{\r
588 return AmlCodeGenRdDWordSpace (\r
589 ACPI_ADDRESS_SPACE_TYPE_MEM,\r
590 IsResourceConsumer,\r
591 IsPosDecode,\r
592 IsMinFixed,\r
593 IsMaxFixed,\r
594 MemoryRangeSpecificFlags (\r
595 Cacheable,\r
596 IsReadWrite,\r
597 MemoryRangeType,\r
598 IsTypeStatic\r
599 ),\r
600 AddressGranularity,\r
601 AddressMinimum,\r
602 AddressMaximum,\r
603 AddressTranslation,\r
604 RangeLength,\r
605 ResourceSourceIndex,\r
606 ResourceSource,\r
607 NameOpNode,\r
608 NewRdNode\r
609 );\r
610}\r
611\r
612/** Code generation for the "WordSpace ()" ASL function.\r
613\r
614 The Resource Data effectively created is a Word Address Space Resource\r
615 Data. Cf ACPI 6.4:\r
616 - s6.4.3.5.3 "Word Address Space Descriptor".\r
617 - s19.6.151 "WordSpace".\r
618\r
619 The created resource data node can be:\r
620 - appended to the list of resource data elements of the NameOpNode.\r
621 In such case NameOpNode must be defined by a the "Name ()" ASL statement\r
622 and initially contain a "ResourceTemplate ()".\r
623 - returned through the NewRdNode parameter.\r
624\r
625 See ACPI 6.4 spec, s19.6.151 for more.\r
626\r
627 @param [in] ResourceType Resource type.\r
628 Possible values are:\r
629 0: Memory range\r
630 1: I/O range\r
631 2: Bus number range\r
632 3-191: Reserved\r
633 192-255: Hardware Vendor Defined\r
634 See ACPI 6.4 spec, s6.4.3.5.3 for more.\r
635 @param [in] IsResourceConsumer ResourceUsage parameter.\r
636 @param [in] IsPosDecode Decode parameter\r
637 @param [in] IsMinFixed Minimum address is fixed.\r
638 @param [in] IsMaxFixed Maximum address is fixed.\r
639 @param [in] TypeSpecificFlags Type specific flags.\r
640 See ACPI 6.4 spec, s6.4.3.5.5\r
641 "Resource Type Specific Flags".\r
642 @param [in] AddressGranularity Address granularity.\r
643 @param [in] AddressMinimum Minimum address.\r
644 @param [in] AddressMaximum Maximum address.\r
645 @param [in] AddressTranslation Address translation.\r
646 @param [in] RangeLength Range length.\r
647 @param [in] ResourceSourceIndex Resource Source index.\r
648 Unused. Must be 0.\r
649 @param [in] ResourceSource Resource Source.\r
650 Unused. Must be NULL.\r
651 @param [in] NameOpNode NameOp object node defining a named object.\r
652 If provided, append the new resource data\r
653 node to the list of resource data elements\r
654 of this node.\r
655 @param [out] NewRdNode If provided and success,\r
656 contain the created node.\r
657\r
658 @retval EFI_SUCCESS The function completed successfully.\r
659 @retval EFI_INVALID_PARAMETER Invalid parameter.\r
660 @retval EFI_OUT_OF_RESOURCES Could not allocate memory.\r
661**/\r
662STATIC\r
663EFI_STATUS\r
664EFIAPI\r
665AmlCodeGenRdWordSpace (\r
666 IN UINT8 ResourceType,\r
667 IN BOOLEAN IsResourceConsumer,\r
668 IN BOOLEAN IsPosDecode,\r
669 IN BOOLEAN IsMinFixed,\r
670 IN BOOLEAN IsMaxFixed,\r
671 IN UINT8 TypeSpecificFlags,\r
672 IN UINT16 AddressGranularity,\r
673 IN UINT16 AddressMinimum,\r
674 IN UINT16 AddressMaximum,\r
675 IN UINT16 AddressTranslation,\r
676 IN UINT16 RangeLength,\r
677 IN UINT8 ResourceSourceIndex,\r
678 IN CONST CHAR8 *ResourceSource,\r
679 IN AML_OBJECT_NODE_HANDLE NameOpNode, OPTIONAL\r
680 OUT AML_DATA_NODE_HANDLE *NewRdNode OPTIONAL\r
681 )\r
682{\r
683 EFI_STATUS Status;\r
684 AML_DATA_NODE *RdNode;\r
685 EFI_ACPI_WORD_ADDRESS_SPACE_DESCRIPTOR Rdword;\r
686\r
687 // ResourceSource and ResourceSourceIndex are unused.\r
688 if ((TypeSpecificFlags == MAX_UINT8) ||\r
689 (ResourceSourceIndex != 0) ||\r
690 (ResourceSource != NULL) ||\r
691 ((NameOpNode == NULL) && (NewRdNode == NULL)))\r
692 {\r
693 ASSERT (0);\r
694 return EFI_INVALID_PARAMETER;\r
695 }\r
696\r
697 Status = CheckAddressSpaceFields (\r
698 IsMinFixed,\r
699 IsMaxFixed,\r
700 AddressGranularity,\r
701 AddressMinimum,\r
702 AddressMaximum,\r
703 AddressTranslation,\r
704 RangeLength\r
705 );\r
706 if (EFI_ERROR (Status)) {\r
707 ASSERT (0);\r
708 return Status;\r
709 }\r
710\r
711 // Header\r
712 Rdword.Header.Header.Bits.Name =\r
713 ACPI_LARGE_WORD_ADDRESS_SPACE_DESCRIPTOR_NAME;\r
714 Rdword.Header.Header.Bits.Type = ACPI_LARGE_ITEM_FLAG;\r
715 Rdword.Header.Length = sizeof (EFI_ACPI_WORD_ADDRESS_SPACE_DESCRIPTOR) -\r
716 sizeof (ACPI_LARGE_RESOURCE_HEADER);\r
717\r
718 // Body\r
719 Rdword.ResType = ResourceType;\r
720 Rdword.GenFlag = AddressSpaceGeneralFlags (\r
721 IsPosDecode,\r
722 IsMinFixed,\r
723 IsMaxFixed\r
724 );\r
725 Rdword.SpecificFlag = TypeSpecificFlags;\r
726 Rdword.AddrSpaceGranularity = AddressGranularity;\r
727 Rdword.AddrRangeMin = AddressMinimum;\r
728 Rdword.AddrRangeMax = AddressMaximum;\r
729 Rdword.AddrTranslationOffset = AddressTranslation;\r
730 Rdword.AddrLen = RangeLength;\r
731\r
732 Status = AmlCreateDataNode (\r
733 EAmlNodeDataTypeResourceData,\r
734 (UINT8 *)&Rdword,\r
735 sizeof (EFI_ACPI_WORD_ADDRESS_SPACE_DESCRIPTOR),\r
736 &RdNode\r
737 );\r
738 if (EFI_ERROR (Status)) {\r
739 ASSERT (0);\r
740 return Status;\r
741 }\r
742\r
743 return LinkRdNode (RdNode, NameOpNode, NewRdNode);\r
744}\r
745\r
746/** Code generation for the "WordBusNumber ()" ASL function.\r
747\r
748 The Resource Data effectively created is a Word Address Space Resource\r
749 Data. Cf ACPI 6.4:\r
750 - s6.4.3.5.3 "Word Address Space Descriptor".\r
751 - s19.6.149 "WordBusNumber".\r
752\r
753 The created resource data node can be:\r
754 - appended to the list of resource data elements of the NameOpNode.\r
755 In such case NameOpNode must be defined by a the "Name ()" ASL statement\r
756 and initially contain a "ResourceTemplate ()".\r
757 - returned through the NewRdNode parameter.\r
758\r
759 See ACPI 6.4 spec, s19.6.149 for more.\r
760\r
761 @param [in] IsResourceConsumer ResourceUsage parameter.\r
762 @param [in] IsMinFixed Minimum address is fixed.\r
763 @param [in] IsMaxFixed Maximum address is fixed.\r
764 @param [in] IsPosDecode Decode parameter\r
765 @param [in] AddressGranularity Address granularity.\r
766 @param [in] AddressMinimum Minimum address.\r
767 @param [in] AddressMaximum Maximum address.\r
768 @param [in] AddressTranslation Address translation.\r
769 @param [in] RangeLength Range length.\r
770 @param [in] ResourceSourceIndex Resource Source index.\r
771 Unused. Must be 0.\r
772 @param [in] ResourceSource Resource Source.\r
773 Unused. Must be NULL.\r
774 @param [in] NameOpNode NameOp object node defining a named object.\r
775 If provided, append the new resource data\r
776 node to the list of resource data elements\r
777 of this node.\r
778 @param [out] NewRdNode If provided and success,\r
779 contain the created node.\r
780\r
781 @retval EFI_SUCCESS The function completed successfully.\r
782 @retval EFI_INVALID_PARAMETER Invalid parameter.\r
783 @retval EFI_OUT_OF_RESOURCES Could not allocate memory.\r
784**/\r
785EFI_STATUS\r
786EFIAPI\r
787AmlCodeGenRdWordBusNumber (\r
788 IN BOOLEAN IsResourceConsumer,\r
789 IN BOOLEAN IsMinFixed,\r
790 IN BOOLEAN IsMaxFixed,\r
791 IN BOOLEAN IsPosDecode,\r
792 IN UINT32 AddressGranularity,\r
793 IN UINT32 AddressMinimum,\r
794 IN UINT32 AddressMaximum,\r
795 IN UINT32 AddressTranslation,\r
796 IN UINT32 RangeLength,\r
797 IN UINT8 ResourceSourceIndex,\r
798 IN CONST CHAR8 *ResourceSource,\r
799 IN AML_OBJECT_NODE_HANDLE NameOpNode, OPTIONAL\r
800 OUT AML_DATA_NODE_HANDLE *NewRdNode OPTIONAL\r
801 )\r
802{\r
803 // There is no Type Specific Flags for buses.\r
804 return AmlCodeGenRdWordSpace (\r
805 ACPI_ADDRESS_SPACE_TYPE_BUS,\r
806 IsResourceConsumer,\r
807 IsPosDecode,\r
808 IsMinFixed,\r
809 IsMaxFixed,\r
810 0,\r
811 AddressGranularity,\r
812 AddressMinimum,\r
813 AddressMaximum,\r
814 AddressTranslation,\r
815 RangeLength,\r
816 ResourceSourceIndex,\r
817 ResourceSource,\r
818 NameOpNode,\r
819 NewRdNode\r
820 );\r
821}\r
822\r
823/** Code generation for the "QWordSpace ()" ASL function.\r
824\r
825 The Resource Data effectively created is a QWord Address Space Resource\r
826 Data. Cf ACPI 6.4:\r
827 - s6.4.3.5.1 "QWord Address Space Descriptor".\r
828 - s19.6.111 "QWordSpace".\r
829\r
830 The created resource data node can be:\r
831 - appended to the list of resource data elements of the NameOpNode.\r
832 In such case NameOpNode must be defined by a the "Name ()" ASL statement\r
833 and initially contain a "ResourceTemplate ()".\r
834 - returned through the NewRdNode parameter.\r
835\r
836 See ACPI 6.4 spec, s19.6.111 for more.\r
837\r
838 @param [in] ResourceType Resource type.\r
839 Possible values are:\r
840 0: Memory range\r
841 1: I/O range\r
842 2: Bus number range\r
843 3-191: Reserved\r
844 192-255: Hardware Vendor Defined\r
845 See ACPI 6.4 spec, s6.4.3.5.1 for more.\r
846 @param [in] IsResourceConsumer ResourceUsage parameter.\r
847 @param [in] IsPosDecode Decode parameter\r
848 @param [in] IsMinFixed Minimum address is fixed.\r
849 @param [in] IsMaxFixed Maximum address is fixed.\r
850 @param [in] TypeSpecificFlags Type specific flags.\r
851 See ACPI 6.4 spec, s6.4.3.5.5\r
852 "Resource Type Specific Flags".\r
853 @param [in] AddressGranularity Address granularity.\r
854 @param [in] AddressMinimum Minimum address.\r
855 @param [in] AddressMaximum Maximum address.\r
856 @param [in] AddressTranslation Address translation.\r
857 @param [in] RangeLength Range length.\r
858 @param [in] ResourceSourceIndex Resource Source index.\r
859 Unused. Must be 0.\r
860 @param [in] ResourceSource Resource Source.\r
861 Unused. Must be NULL.\r
862 @param [in] NameOpNode NameOp object node defining a named object.\r
863 If provided, append the new resource data\r
864 node to the list of resource data elements\r
865 of this node.\r
866 @param [out] NewRdNode If provided and success,\r
867 contain the created node.\r
868\r
869 @retval EFI_SUCCESS The function completed successfully.\r
870 @retval EFI_INVALID_PARAMETER Invalid parameter.\r
871 @retval EFI_OUT_OF_RESOURCES Could not allocate memory.\r
872**/\r
873STATIC\r
874EFI_STATUS\r
875EFIAPI\r
876AmlCodeGenRdQWordSpace (\r
877 IN UINT8 ResourceType,\r
878 IN BOOLEAN IsResourceConsumer,\r
879 IN BOOLEAN IsPosDecode,\r
880 IN BOOLEAN IsMinFixed,\r
881 IN BOOLEAN IsMaxFixed,\r
882 IN UINT8 TypeSpecificFlags,\r
883 IN UINT64 AddressGranularity,\r
884 IN UINT64 AddressMinimum,\r
885 IN UINT64 AddressMaximum,\r
886 IN UINT64 AddressTranslation,\r
887 IN UINT64 RangeLength,\r
888 IN UINT8 ResourceSourceIndex,\r
889 IN CONST CHAR8 *ResourceSource,\r
890 IN AML_OBJECT_NODE_HANDLE NameOpNode, OPTIONAL\r
891 OUT AML_DATA_NODE_HANDLE *NewRdNode OPTIONAL\r
892 )\r
893{\r
894 EFI_STATUS Status;\r
895 AML_DATA_NODE *RdNode;\r
896 EFI_ACPI_QWORD_ADDRESS_SPACE_DESCRIPTOR RdQword;\r
897\r
898 // ResourceSource and ResourceSourceIndex are unused.\r
899 if ((TypeSpecificFlags == MAX_UINT8) ||\r
900 (ResourceSourceIndex != 0) ||\r
901 (ResourceSource != NULL) ||\r
902 ((NameOpNode == NULL) && (NewRdNode == NULL)))\r
903 {\r
904 ASSERT (0);\r
905 return EFI_INVALID_PARAMETER;\r
906 }\r
907\r
908 Status = CheckAddressSpaceFields (\r
909 IsMinFixed,\r
910 IsMaxFixed,\r
911 AddressGranularity,\r
912 AddressMinimum,\r
913 AddressMaximum,\r
914 AddressTranslation,\r
915 RangeLength\r
916 );\r
917 if (EFI_ERROR (Status)) {\r
918 ASSERT (0);\r
919 return Status;\r
920 }\r
921\r
922 // Header\r
923 RdQword.Header.Header.Bits.Name =\r
924 ACPI_LARGE_QWORD_ADDRESS_SPACE_DESCRIPTOR_NAME;\r
925 RdQword.Header.Header.Bits.Type = ACPI_LARGE_ITEM_FLAG;\r
926 RdQword.Header.Length = sizeof (EFI_ACPI_QWORD_ADDRESS_SPACE_DESCRIPTOR) -\r
927 sizeof (ACPI_LARGE_RESOURCE_HEADER);\r
928\r
929 // Body\r
930 RdQword.ResType = ResourceType;\r
931 RdQword.GenFlag = AddressSpaceGeneralFlags (\r
932 IsPosDecode,\r
933 IsMinFixed,\r
934 IsMaxFixed\r
935 );\r
936 RdQword.SpecificFlag = TypeSpecificFlags;\r
937 RdQword.AddrSpaceGranularity = AddressGranularity;\r
938 RdQword.AddrRangeMin = AddressMinimum;\r
939 RdQword.AddrRangeMax = AddressMaximum;\r
940 RdQword.AddrTranslationOffset = AddressTranslation;\r
941 RdQword.AddrLen = RangeLength;\r
942\r
943 Status = AmlCreateDataNode (\r
944 EAmlNodeDataTypeResourceData,\r
945 (UINT8 *)&RdQword,\r
946 sizeof (EFI_ACPI_QWORD_ADDRESS_SPACE_DESCRIPTOR),\r
947 &RdNode\r
948 );\r
949 if (EFI_ERROR (Status)) {\r
950 ASSERT (0);\r
951 return Status;\r
952 }\r
953\r
954 return LinkRdNode (RdNode, NameOpNode, NewRdNode);\r
955}\r
956\r
957/** Code generation for the "QWordMemory ()" ASL function.\r
958\r
959 The Resource Data effectively created is a QWord Address Space Resource\r
960 Data. Cf ACPI 6.4:\r
961 - s6.4.3.5.1 "QWord Address Space Descriptor".\r
962 - s19.6.110 "QWordMemory".\r
963\r
964 The created resource data node can be:\r
965 - appended to the list of resource data elements of the NameOpNode.\r
966 In such case NameOpNode must be defined by a the "Name ()" ASL statement\r
967 and initially contain a "ResourceTemplate ()".\r
968 - returned through the NewRdNode parameter.\r
969\r
970 See ACPI 6.4 spec, s19.6.110 for more.\r
971\r
972 @param [in] IsResourceConsumer ResourceUsage parameter.\r
973 @param [in] IsPosDecode Decode parameter.\r
974 @param [in] IsMinFixed Minimum address is fixed.\r
975 @param [in] IsMaxFixed Maximum address is fixed.\r
976 @param [in] Cacheable Possible values are:\r
977 0-The memory is non-cacheable\r
978 1-The memory is cacheable\r
979 2-The memory is cacheable and supports\r
980 write combining\r
981 3-The memory is cacheable and prefetchable\r
982 @param [in] IsReadWrite ReadAndWrite parameter.\r
983 @param [in] AddressGranularity Address granularity.\r
984 @param [in] AddressMinimum Minimum address.\r
985 @param [in] AddressMaximum Maximum address.\r
986 @param [in] AddressTranslation Address translation.\r
987 @param [in] RangeLength Range length.\r
988 @param [in] ResourceSourceIndex Resource Source index.\r
989 Unused. Must be 0.\r
990 @param [in] ResourceSource Resource Source.\r
991 Unused. Must be NULL.\r
992 @param [in] MemoryRangeType Possible values are:\r
993 0-AddressRangeMemory\r
994 1-AddressRangeReserved\r
995 2-AddressRangeACPI\r
996 3-AddressRangeNVS\r
997 @param [in] IsTypeStatic TranslationType parameter.\r
998 @param [in] NameOpNode NameOp object node defining a named object.\r
999 If provided, append the new resource data\r
1000 node to the list of resource data elements\r
1001 of this node.\r
1002 @param [out] NewRdNode If provided and success,\r
1003 contain the created node.\r
1004\r
1005 @retval EFI_SUCCESS The function completed successfully.\r
1006 @retval EFI_INVALID_PARAMETER Invalid parameter.\r
1007 @retval EFI_OUT_OF_RESOURCES Could not allocate memory.\r
1008**/\r
1009EFI_STATUS\r
1010EFIAPI\r
1011AmlCodeGenRdQWordMemory (\r
1012 IN BOOLEAN IsResourceConsumer,\r
1013 IN BOOLEAN IsPosDecode,\r
1014 IN BOOLEAN IsMinFixed,\r
1015 IN BOOLEAN IsMaxFixed,\r
1016 IN UINT8 Cacheable,\r
1017 IN BOOLEAN IsReadWrite,\r
1018 IN UINT64 AddressGranularity,\r
1019 IN UINT64 AddressMinimum,\r
1020 IN UINT64 AddressMaximum,\r
1021 IN UINT64 AddressTranslation,\r
1022 IN UINT64 RangeLength,\r
1023 IN UINT8 ResourceSourceIndex,\r
1024 IN CONST CHAR8 *ResourceSource,\r
1025 IN UINT8 MemoryRangeType,\r
1026 IN BOOLEAN IsTypeStatic,\r
1027 IN AML_OBJECT_NODE_HANDLE NameOpNode, OPTIONAL\r
1028 OUT AML_DATA_NODE_HANDLE *NewRdNode OPTIONAL\r
1029 )\r
1030{\r
1031 return AmlCodeGenRdQWordSpace (\r
1032 ACPI_ADDRESS_SPACE_TYPE_MEM,\r
1033 IsResourceConsumer,\r
1034 IsPosDecode,\r
1035 IsMinFixed,\r
1036 IsMaxFixed,\r
1037 MemoryRangeSpecificFlags (\r
1038 Cacheable,\r
1039 IsReadWrite,\r
1040 MemoryRangeType,\r
1041 IsTypeStatic\r
1042 ),\r
1043 AddressGranularity,\r
1044 AddressMinimum,\r
1045 AddressMaximum,\r
1046 AddressTranslation,\r
1047 RangeLength,\r
1048 ResourceSourceIndex,\r
1049 ResourceSource,\r
1050 NameOpNode,\r
1051 NewRdNode\r
1052 );\r
1053}\r
1054\r
01ea2ad5
PG
1055/** Code generation for the "Interrupt ()" ASL function.\r
1056\r
01ea2ad5 1057 The Resource Data effectively created is an Extended Interrupt Resource\r
22873f58
PG
1058 Data. Cf ACPI 6.4:\r
1059 - s6.4.3.6 "Extended Interrupt Descriptor"\r
1060 - s19.6.64 "Interrupt (Interrupt Resource Descriptor Macro)"\r
01ea2ad5 1061\r
22873f58
PG
1062 The created resource data node can be:\r
1063 - appended to the list of resource data elements of the NameOpNode.\r
1064 In such case NameOpNode must be defined by a the "Name ()" ASL statement\r
1065 and initially contain a "ResourceTemplate ()".\r
1066 - returned through the NewRdNode parameter.\r
01ea2ad5 1067\r
22873f58
PG
1068 @param [in] ResourceConsumer The device consumes the specified interrupt\r
1069 or produces it for use by a child device.\r
1070 @param [in] EdgeTriggered The interrupt is edge triggered or\r
1071 level triggered.\r
1072 @param [in] ActiveLow The interrupt is active-high or active-low.\r
1073 @param [in] Shared The interrupt can be shared with other\r
1074 devices or not (Exclusive).\r
1075 @param [in] IrqList Interrupt list. Must be non-NULL.\r
1076 @param [in] IrqCount Interrupt count. Must be non-zero.\r
1077 @param [in] NameOpNode NameOp object node defining a named object.\r
1078 If provided, append the new resource data node\r
1079 to the list of resource data elements of this\r
1080 node.\r
1081 @param [out] NewRdNode If provided and success,\r
1082 contain the created node.\r
01ea2ad5
PG
1083\r
1084 @retval EFI_SUCCESS The function completed successfully.\r
1085 @retval EFI_INVALID_PARAMETER Invalid parameter.\r
1086 @retval EFI_OUT_OF_RESOURCES Could not allocate memory.\r
1087**/\r
1088EFI_STATUS\r
1089EFIAPI\r
22873f58
PG
1090AmlCodeGenRdInterrupt (\r
1091 IN BOOLEAN ResourceConsumer,\r
1092 IN BOOLEAN EdgeTriggered,\r
1093 IN BOOLEAN ActiveLow,\r
1094 IN BOOLEAN Shared,\r
1095 IN UINT32 *IrqList,\r
1096 IN UINT8 IrqCount,\r
fe2d8189 1097 IN AML_OBJECT_NODE_HANDLE NameOpNode OPTIONAL,\r
22873f58 1098 OUT AML_DATA_NODE_HANDLE *NewRdNode OPTIONAL\r
01ea2ad5
PG
1099 )\r
1100{\r
731c67e1 1101 EFI_STATUS Status;\r
01ea2ad5 1102\r
731c67e1
MK
1103 AML_DATA_NODE *RdNode;\r
1104 EFI_ACPI_EXTENDED_INTERRUPT_DESCRIPTOR RdInterrupt;\r
1105 UINT32 *FirstInterrupt;\r
01ea2ad5
PG
1106\r
1107 if ((IrqList == NULL) ||\r
1108 (IrqCount == 0) ||\r
731c67e1
MK
1109 ((NameOpNode == NULL) && (NewRdNode == NULL)))\r
1110 {\r
01ea2ad5
PG
1111 ASSERT (0);\r
1112 return EFI_INVALID_PARAMETER;\r
1113 }\r
1114\r
22873f58 1115 // Header\r
01ea2ad5
PG
1116 RdInterrupt.Header.Header.Bits.Name =\r
1117 ACPI_LARGE_EXTENDED_IRQ_DESCRIPTOR_NAME;\r
1118 RdInterrupt.Header.Header.Bits.Type = ACPI_LARGE_ITEM_FLAG;\r
731c67e1
MK
1119 RdInterrupt.Header.Length = sizeof (EFI_ACPI_EXTENDED_INTERRUPT_DESCRIPTOR) -\r
1120 sizeof (ACPI_LARGE_RESOURCE_HEADER);\r
22873f58
PG
1121\r
1122 // Body\r
01ea2ad5
PG
1123 RdInterrupt.InterruptVectorFlags = (ResourceConsumer ? BIT0 : 0) |\r
1124 (EdgeTriggered ? BIT1 : 0) |\r
1125 (ActiveLow ? BIT2 : 0) |\r
1126 (Shared ? BIT3 : 0);\r
1127 RdInterrupt.InterruptTableLength = IrqCount;\r
1128\r
1129 // Get the address of the first interrupt field.\r
1130 FirstInterrupt = RdInterrupt.InterruptNumber;\r
1131\r
1132 // Copy the list of interrupts.\r
1133 CopyMem (FirstInterrupt, IrqList, (sizeof (UINT32) * IrqCount));\r
1134\r
1135 Status = AmlCreateDataNode (\r
1136 EAmlNodeDataTypeResourceData,\r
731c67e1 1137 (UINT8 *)&RdInterrupt,\r
01ea2ad5
PG
1138 sizeof (EFI_ACPI_EXTENDED_INTERRUPT_DESCRIPTOR),\r
1139 &RdNode\r
1140 );\r
1141 if (EFI_ERROR (Status)) {\r
1142 ASSERT (0);\r
1143 return Status;\r
1144 }\r
1145\r
22873f58 1146 return LinkRdNode (RdNode, NameOpNode, NewRdNode);\r
01ea2ad5 1147}\r
691c5f77 1148\r
f995f867
PG
1149/** Code generation for the "Register ()" ASL function.\r
1150\r
1151 The Resource Data effectively created is a Generic Register Descriptor.\r
1152 Data. Cf ACPI 6.4:\r
1153 - s6.4.3.7 "Generic Register Descriptor".\r
1154 - s19.6.114 "Register".\r
1155\r
1156 The created resource data node can be:\r
1157 - appended to the list of resource data elements of the NameOpNode.\r
1158 In such case NameOpNode must be defined by a the "Name ()" ASL statement\r
1159 and initially contain a "ResourceTemplate ()".\r
1160 - returned through the NewRdNode parameter.\r
1161\r
1162 @param [in] AddressSpace Address space where the register exists.\r
1163 Can be one of I/O space, System Memory, etc.\r
1164 @param [in] BitWidth Number of bits in the register.\r
1165 @param [in] BitOffset Offset in bits from the start of the register\r
1166 indicated by the Address.\r
1167 @param [in] Address Register address.\r
1168 @param [in] AccessSize Size of data values used when accessing the\r
1169 address space. Can be one of:\r
1170 0 - Undefined, legacy (EFI_ACPI_6_4_UNDEFINED)\r
1171 1 - Byte access (EFI_ACPI_6_4_BYTE)\r
1172 2 - Word access (EFI_ACPI_6_4_WORD)\r
1173 3 - DWord access (EFI_ACPI_6_4_DWORD)\r
1174 4 - QWord access (EFI_ACPI_6_4_QWORD)\r
1175 @param [in] NameOpNode NameOp object node defining a named object.\r
1176 If provided, append the new resource data node\r
1177 to the list of resource data elements of this\r
1178 node.\r
1179 @param [out] NewRdNode If provided and success,\r
1180 contain the created node.\r
1181\r
1182 @retval EFI_SUCCESS The function completed successfully.\r
1183 @retval EFI_INVALID_PARAMETER Invalid parameter.\r
1184 @retval EFI_OUT_OF_RESOURCES Could not allocate memory.\r
1185**/\r
1186EFI_STATUS\r
1187EFIAPI\r
1188AmlCodeGenRdRegister (\r
1189 IN UINT8 AddressSpace,\r
1190 IN UINT8 BitWidth,\r
1191 IN UINT8 BitOffset,\r
1192 IN UINT64 Address,\r
1193 IN UINT8 AccessSize,\r
fe2d8189 1194 IN AML_OBJECT_NODE_HANDLE NameOpNode OPTIONAL,\r
f995f867
PG
1195 OUT AML_DATA_NODE_HANDLE *NewRdNode OPTIONAL\r
1196 )\r
1197{\r
731c67e1
MK
1198 EFI_STATUS Status;\r
1199 AML_DATA_NODE *RdNode;\r
1200 EFI_ACPI_GENERIC_REGISTER_DESCRIPTOR RdRegister;\r
f995f867
PG
1201\r
1202 if ((AccessSize > EFI_ACPI_6_4_QWORD) ||\r
731c67e1
MK
1203 ((NameOpNode == NULL) && (NewRdNode == NULL)))\r
1204 {\r
f995f867
PG
1205 ASSERT (0);\r
1206 return EFI_INVALID_PARAMETER;\r
1207 }\r
1208\r
1209 // Header\r
1210 RdRegister.Header.Header.Bits.Name =\r
1211 ACPI_LARGE_GENERIC_REGISTER_DESCRIPTOR_NAME;\r
1212 RdRegister.Header.Header.Bits.Type = ACPI_LARGE_ITEM_FLAG;\r
731c67e1
MK
1213 RdRegister.Header.Length = sizeof (EFI_ACPI_GENERIC_REGISTER_DESCRIPTOR) -\r
1214 sizeof (ACPI_LARGE_RESOURCE_HEADER);\r
f995f867
PG
1215\r
1216 // Body\r
731c67e1
MK
1217 RdRegister.AddressSpaceId = AddressSpace;\r
1218 RdRegister.RegisterBitWidth = BitWidth;\r
f995f867 1219 RdRegister.RegisterBitOffset = BitOffset;\r
731c67e1
MK
1220 RdRegister.AddressSize = AccessSize;\r
1221 RdRegister.RegisterAddress = Address;\r
f995f867
PG
1222\r
1223 Status = AmlCreateDataNode (\r
1224 EAmlNodeDataTypeResourceData,\r
731c67e1 1225 (UINT8 *)&RdRegister,\r
f995f867
PG
1226 sizeof (EFI_ACPI_GENERIC_REGISTER_DESCRIPTOR),\r
1227 &RdNode\r
1228 );\r
1229 if (EFI_ERROR (Status)) {\r
1230 ASSERT (0);\r
1231 return Status;\r
1232 }\r
1233\r
1234 return LinkRdNode (RdNode, NameOpNode, NewRdNode);\r
1235}\r
1236\r
9454d1eb
PG
1237/** Code generation for the EndTag resource data.\r
1238\r
1239 The EndTag resource data is automatically generated by the ASL compiler\r
1240 at the end of a list of resource data elements. Thus, it doesn't have\r
1241 a corresponding ASL function.\r
1242\r
1243 This function allocates memory to create a data node. It is the caller's\r
1244 responsibility to either:\r
1245 - attach this node to an AML tree;\r
1246 - delete this node.\r
1247\r
1248 ACPI 6.4, s6.4.2.9 "End Tag":\r
1249 "This checksum is generated such that adding it to the sum of all the data\r
1250 bytes will produce a zero sum."\r
1251 "If the checksum field is zero, the resource data is treated as if the\r
1252 checksum operation succeeded. Configuration proceeds normally."\r
1253\r
1254 To avoid re-computing checksums, if a new resource data elements is\r
1255 added/removed/modified in a list of resource data elements, the AmlLib\r
1256 resets the checksum to 0.\r
1257\r
1258 @param [in] CheckSum CheckSum to store in the EndTag.\r
1259 To ignore/avoid computing the checksum,\r
1260 give 0.\r
1261 @param [in] ParentNode If not NULL, add the generated node\r
1262 to the end of the variable list of\r
1263 argument of the ParentNode.\r
1264 The ParentNode must not initially contain\r
1265 an EndTag resource data element.\r
1266 @param [out] NewRdNode If success, contains the generated node.\r
1267\r
1268 @retval EFI_SUCCESS The function completed successfully.\r
1269 @retval EFI_INVALID_PARAMETER Invalid parameter.\r
1270 @retval EFI_OUT_OF_RESOURCES Could not allocate memory.\r
1271**/\r
1272EFI_STATUS\r
1273EFIAPI\r
1274AmlCodeGenEndTag (\r
731c67e1
MK
1275 IN UINT8 CheckSum OPTIONAL,\r
1276 IN AML_OBJECT_NODE *ParentNode OPTIONAL,\r
1277 OUT AML_DATA_NODE **NewRdNode OPTIONAL\r
9454d1eb
PG
1278 )\r
1279{\r
731c67e1
MK
1280 EFI_STATUS Status;\r
1281 AML_DATA_NODE *RdNode;\r
1282 EFI_ACPI_END_TAG_DESCRIPTOR EndTag;\r
1283 ACPI_SMALL_RESOURCE_HEADER SmallResHdr;\r
9454d1eb
PG
1284\r
1285 if ((ParentNode == NULL) && (NewRdNode == NULL)) {\r
1286 ASSERT (0);\r
1287 return EFI_INVALID_PARAMETER;\r
1288 }\r
1289\r
1290 RdNode = NULL;\r
1291\r
1292 // Header\r
1293 SmallResHdr.Bits.Length = sizeof (EFI_ACPI_END_TAG_DESCRIPTOR) -\r
731c67e1 1294 sizeof (ACPI_SMALL_RESOURCE_HEADER);\r
9454d1eb
PG
1295 SmallResHdr.Bits.Name = ACPI_SMALL_END_TAG_DESCRIPTOR_NAME;\r
1296 SmallResHdr.Bits.Type = ACPI_SMALL_ITEM_FLAG;\r
1297\r
1298 // Body\r
731c67e1 1299 EndTag.Desc = SmallResHdr.Byte;\r
9454d1eb
PG
1300 EndTag.Checksum = CheckSum;\r
1301\r
1302 Status = AmlCreateDataNode (\r
1303 EAmlNodeDataTypeResourceData,\r
731c67e1 1304 (UINT8 *)&EndTag,\r
9454d1eb
PG
1305 sizeof (EFI_ACPI_END_TAG_DESCRIPTOR),\r
1306 &RdNode\r
1307 );\r
1308 if (EFI_ERROR (Status)) {\r
1309 ASSERT (0);\r
1310 return Status;\r
1311 }\r
1312\r
1313 if (NewRdNode != NULL) {\r
1314 *NewRdNode = RdNode;\r
1315 }\r
1316\r
1317 if (ParentNode != NULL) {\r
1318 // Check the BufferOp doesn't contain any resource data yet.\r
1319 // This is a hard check: do not allow to add an EndTag if the BufferNode\r
1320 // already has resource data elements attached. Indeed, the EndTag should\r
1321 // have already been added.\r
731c67e1
MK
1322 if (AmlGetNextVariableArgument ((AML_NODE_HEADER *)ParentNode, NULL) !=\r
1323 NULL)\r
1324 {\r
9454d1eb
PG
1325 ASSERT (0);\r
1326 Status = EFI_INVALID_PARAMETER;\r
1327 goto error_handler;\r
1328 }\r
1329\r
1330 // Add the EndTag RdNode. Indeed, the AmlAppendRdNode function\r
1331 // is looking for an EndTag, which we are adding here.\r
1332 Status = AmlVarListAddTail (\r
731c67e1
MK
1333 (AML_NODE_HEADER *)ParentNode,\r
1334 (AML_NODE_HEADER *)RdNode\r
9454d1eb
PG
1335 );\r
1336 if (EFI_ERROR (Status)) {\r
1337 ASSERT (0);\r
1338 goto error_handler;\r
1339 }\r
1340 }\r
1341\r
1342 return Status;\r
1343\r
1344error_handler:\r
1345 if (RdNode != NULL) {\r
731c67e1 1346 AmlDeleteTree ((AML_NODE_HEADER *)RdNode);\r
9454d1eb 1347 }\r
731c67e1 1348\r
9454d1eb
PG
1349 return Status;\r
1350}\r
1351\r
691c5f77
PG
1352// DEPRECATED APIS\r
1353#ifndef DISABLE_NEW_DEPRECATED_INTERFACES\r
1354\r
1355/** DEPRECATED API\r
1356\r
1357 Add an Interrupt Resource Data node.\r
1358\r
1359 This function creates a Resource Data element corresponding to the\r
1360 "Interrupt ()" ASL function, stores it in an AML Data Node.\r
1361\r
1362 It then adds it after the input CurrRdNode in the list of resource data\r
1363 element.\r
1364\r
1365 The Resource Data effectively created is an Extended Interrupt Resource\r
1366 Data. See ACPI 6.3 specification, s6.4.3.6 "Extended Interrupt Descriptor"\r
1367 for more information about Extended Interrupt Resource Data.\r
1368\r
1369 The Extended Interrupt contains one single interrupt.\r
1370\r
1371 This function allocates memory to create a data node. It is the caller's\r
1372 responsibility to either:\r
1373 - attach this node to an AML tree;\r
1374 - delete this node.\r
1375\r
1376 Note: The _CRS node must be defined using the ASL Name () function.\r
1377 e.g. Name (_CRS, ResourceTemplate () {\r
1378 ...\r
1379 }\r
1380\r
1381 @ingroup UserApis\r
1382\r
1383 @param [in] NameOpCrsNode NameOp object node defining a "_CRS" object.\r
1384 Must have an OpCode=AML_NAME_OP, SubOpCode=0.\r
1385 NameOp object nodes are defined in ASL\r
1386 using the "Name ()" function.\r
1387 @param [in] ResourceConsumer The device consumes the specified interrupt\r
1388 or produces it for use by a child device.\r
1389 @param [in] EdgeTriggered The interrupt is edge triggered or\r
1390 level triggered.\r
1391 @param [in] ActiveLow The interrupt is active-high or active-low.\r
1392 @param [in] Shared The interrupt can be shared with other\r
1393 devices or not (Exclusive).\r
1394 @param [in] IrqList Interrupt list. Must be non-NULL.\r
1395 @param [in] IrqCount Interrupt count. Must be non-zero.\r
1396\r
1397\r
1398 @retval EFI_SUCCESS The function completed successfully.\r
1399 @retval EFI_INVALID_PARAMETER Invalid parameter.\r
1400 @retval EFI_OUT_OF_RESOURCES Could not allocate memory.\r
1401**/\r
1402EFI_STATUS\r
1403EFIAPI\r
1404AmlCodeGenCrsAddRdInterrupt (\r
1405 IN AML_OBJECT_NODE_HANDLE NameOpCrsNode,\r
1406 IN BOOLEAN ResourceConsumer,\r
1407 IN BOOLEAN EdgeTriggered,\r
1408 IN BOOLEAN ActiveLow,\r
1409 IN BOOLEAN Shared,\r
731c67e1 1410 IN UINT32 *IrqList,\r
691c5f77
PG
1411 IN UINT8 IrqCount\r
1412 )\r
1413{\r
22873f58 1414 return AmlCodeGenRdInterrupt (\r
691c5f77
PG
1415 ResourceConsumer,\r
1416 EdgeTriggered,\r
1417 ActiveLow,\r
1418 Shared,\r
1419 IrqList,\r
22873f58
PG
1420 IrqCount,\r
1421 NameOpCrsNode,\r
1422 NULL\r
691c5f77
PG
1423 );\r
1424}\r
1425\r
1426#endif // DISABLE_NEW_DEPRECATED_INTERFACES\r