AmlResourceDataCodeGen.c 52 KB

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