IortParser.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774
  1. /** @file
  2. IORT table parser
  3. Copyright (c) 2016 - 2020, ARM Limited. All rights reserved.
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. @par Reference(s):
  6. - IO Remapping Table, Platform Design Document, Revision D, March 2018
  7. **/
  8. #include <IndustryStandard/IoRemappingTable.h>
  9. #include <Library/PrintLib.h>
  10. #include <Library/UefiLib.h>
  11. #include "AcpiParser.h"
  12. #include "AcpiTableParser.h"
  13. #include "AcpiViewConfig.h"
  14. // Local variables
  15. STATIC ACPI_DESCRIPTION_HEADER_INFO AcpiHdrInfo;
  16. STATIC CONST UINT32 *IortNodeCount;
  17. STATIC CONST UINT32 *IortNodeOffset;
  18. STATIC CONST UINT8 *IortNodeType;
  19. STATIC CONST UINT16 *IortNodeLength;
  20. STATIC CONST UINT32 *IortIdMappingCount;
  21. STATIC CONST UINT32 *IortIdMappingOffset;
  22. STATIC CONST UINT32 *InterruptContextCount;
  23. STATIC CONST UINT32 *InterruptContextOffset;
  24. STATIC CONST UINT32 *PmuInterruptCount;
  25. STATIC CONST UINT32 *PmuInterruptOffset;
  26. STATIC CONST UINT32 *ItsCount;
  27. /**
  28. This function validates the ID Mapping array count for the ITS node.
  29. @param [in] Ptr Pointer to the start of the field data.
  30. @param [in] Context Pointer to context specific information e.g. this
  31. could be a pointer to the ACPI table header.
  32. **/
  33. STATIC
  34. VOID
  35. EFIAPI
  36. ValidateItsIdMappingCount (
  37. IN UINT8 *Ptr,
  38. IN VOID *Context
  39. )
  40. {
  41. if (*(UINT32 *)Ptr != 0) {
  42. IncrementErrorCount ();
  43. Print (L"\nERROR: IORT ID Mapping count must be zero.");
  44. }
  45. }
  46. /**
  47. This function validates the ID Mapping array count for the Performance
  48. Monitoring Counter Group (PMCG) node.
  49. @param [in] Ptr Pointer to the start of the field data.
  50. @param [in] Context Pointer to context specific information e.g. this
  51. could be a pointer to the ACPI table header.
  52. **/
  53. STATIC
  54. VOID
  55. EFIAPI
  56. ValidatePmcgIdMappingCount (
  57. IN UINT8 *Ptr,
  58. IN VOID *Context
  59. )
  60. {
  61. if (*(UINT32 *)Ptr > 1) {
  62. IncrementErrorCount ();
  63. Print (L"\nERROR: IORT ID Mapping count must not be greater than 1.");
  64. }
  65. }
  66. /**
  67. This function validates the ID Mapping array offset for the ITS node.
  68. @param [in] Ptr Pointer to the start of the field data.
  69. @param [in] Context Pointer to context specific information e.g. this
  70. could be a pointer to the ACPI table header.
  71. **/
  72. STATIC
  73. VOID
  74. EFIAPI
  75. ValidateItsIdArrayReference (
  76. IN UINT8 *Ptr,
  77. IN VOID *Context
  78. )
  79. {
  80. if (*(UINT32 *)Ptr != 0) {
  81. IncrementErrorCount ();
  82. Print (L"\nERROR: IORT ID Mapping offset must be zero.");
  83. }
  84. }
  85. /**
  86. Helper Macro for populating the IORT Node header in the ACPI_PARSER array.
  87. @param [out] ValidateIdMappingCount Optional pointer to a function for
  88. validating the ID Mapping count.
  89. @param [out] ValidateIdArrayReference Optional pointer to a function for
  90. validating the ID Array reference.
  91. **/
  92. #define PARSE_IORT_NODE_HEADER(ValidateIdMappingCount, \
  93. ValidateIdArrayReference) \
  94. { L"Type", 1, 0, L"%d", NULL, (VOID**)&IortNodeType, NULL, NULL }, \
  95. { L"Length", 2, 1, L"%d", NULL, (VOID**)&IortNodeLength, NULL, NULL }, \
  96. { L"Revision", 1, 3, L"%d", NULL, NULL, NULL, NULL }, \
  97. { L"Reserved", 4, 4, L"0x%x", NULL, NULL, NULL, NULL }, \
  98. { L"Number of ID mappings", 4, 8, L"%d", NULL, \
  99. (VOID**)&IortIdMappingCount, ValidateIdMappingCount, NULL }, \
  100. { L"Reference to ID Array", 4, 12, L"0x%x", NULL, \
  101. (VOID**)&IortIdMappingOffset, ValidateIdArrayReference, NULL }
  102. /**
  103. An ACPI_PARSER array describing the ACPI IORT Table
  104. **/
  105. STATIC CONST ACPI_PARSER IortParser[] = {
  106. PARSE_ACPI_HEADER (&AcpiHdrInfo),
  107. { L"Number of IORT Nodes", 4, 36, L"%d", NULL,
  108. (VOID **)&IortNodeCount, NULL, NULL },
  109. { L"Offset to Array of IORT Nodes",4, 40, L"0x%x", NULL,
  110. (VOID **)&IortNodeOffset, NULL, NULL },
  111. { L"Reserved", 4, 44, L"0x%x", NULL,NULL,NULL, NULL }
  112. };
  113. /**
  114. An ACPI_PARSER array describing the IORT node header structure.
  115. **/
  116. STATIC CONST ACPI_PARSER IortNodeHeaderParser[] = {
  117. PARSE_IORT_NODE_HEADER (NULL, NULL)
  118. };
  119. /**
  120. An ACPI_PARSER array describing the IORT SMMUv1/2 node.
  121. **/
  122. STATIC CONST ACPI_PARSER IortNodeSmmuV1V2Parser[] = {
  123. PARSE_IORT_NODE_HEADER (NULL, NULL),
  124. { L"Base Address", 8, 16, L"0x%lx", NULL, NULL, NULL, NULL },
  125. { L"Span", 8, 24, L"0x%lx", NULL, NULL, NULL, NULL },
  126. { L"Model", 4, 32, L"%d", NULL, NULL, NULL, NULL },
  127. { L"Flags", 4, 36, L"0x%x", NULL, NULL, NULL, NULL },
  128. { L"Reference to Global Interrupt Array",4, 40, L"0x%x", NULL, NULL, NULL,
  129. NULL },
  130. { L"Number of context interrupts", 4, 44, L"%d", NULL,
  131. (VOID **)&InterruptContextCount, NULL, NULL },
  132. { L"Reference to Context Interrupt Array",4, 48, L"0x%x", NULL,
  133. (VOID **)&InterruptContextOffset, NULL, NULL },
  134. { L"Number of PMU Interrupts", 4, 52, L"%d", NULL,
  135. (VOID **)&PmuInterruptCount, NULL, NULL },
  136. { L"Reference to PMU Interrupt Array",4, 56, L"0x%x", NULL,
  137. (VOID **)&PmuInterruptOffset, NULL, NULL },
  138. // Interrupt Array
  139. { L"SMMU_NSgIrpt", 4, 60, L"0x%x", NULL, NULL, NULL, NULL },
  140. { L"SMMU_NSgIrpt interrupt flags", 4, 64, L"0x%x", NULL, NULL, NULL, NULL },
  141. { L"SMMU_NSgCfgIrpt", 4, 68, L"0x%x", NULL, NULL, NULL, NULL },
  142. { L"SMMU_NSgCfgIrpt interrupt flags",4, 72, L"0x%x", NULL, NULL, NULL, NULL }
  143. };
  144. /**
  145. An ACPI_PARSER array describing the SMMUv1/2 Node Interrupt Array.
  146. **/
  147. STATIC CONST ACPI_PARSER InterruptArrayParser[] = {
  148. { L"Interrupt GSIV", 4, 0, L"0x%x", NULL, NULL, NULL, NULL },
  149. { L"Flags", 4, 4, L"0x%x", NULL, NULL, NULL, NULL }
  150. };
  151. /**
  152. An ACPI_PARSER array describing the IORT ID Mapping.
  153. **/
  154. STATIC CONST ACPI_PARSER IortNodeIdMappingParser[] = {
  155. { L"Input base", 4, 0, L"0x%x", NULL, NULL, NULL, NULL },
  156. { L"Number of IDs", 4, 4, L"0x%x", NULL, NULL, NULL, NULL },
  157. { L"Output base", 4, 8, L"0x%x", NULL, NULL, NULL, NULL },
  158. { L"Output reference", 4, 12, L"0x%x", NULL, NULL, NULL, NULL },
  159. { L"Flags", 4, 16, L"0x%x", NULL, NULL, NULL, NULL }
  160. };
  161. /**
  162. An ACPI_PARSER array describing the IORT SMMUv3 node.
  163. **/
  164. STATIC CONST ACPI_PARSER IortNodeSmmuV3Parser[] = {
  165. PARSE_IORT_NODE_HEADER (NULL, NULL),
  166. { L"Base Address", 8, 16, L"0x%lx", NULL, NULL, NULL, NULL },
  167. { L"Flags", 4, 24, L"0x%x", NULL, NULL, NULL, NULL },
  168. { L"Reserved", 4, 28, L"0x%x", NULL, NULL, NULL, NULL },
  169. { L"VATOS Address", 8, 32, L"0x%lx", NULL, NULL, NULL, NULL },
  170. { L"Model", 4, 40, L"%d", NULL, NULL, NULL, NULL },
  171. { L"Event", 4, 44, L"0x%x", NULL, NULL, NULL, NULL },
  172. { L"PRI", 4, 48, L"0x%x", NULL, NULL, NULL, NULL },
  173. { L"GERR", 4, 52, L"0x%x", NULL, NULL, NULL, NULL },
  174. { L"Sync", 4, 56, L"0x%x", NULL, NULL, NULL, NULL },
  175. { L"Proximity domain", 4, 60, L"0x%x", NULL, NULL, NULL, NULL },
  176. { L"Device ID mapping index", 4, 64, L"%d", NULL, NULL, NULL, NULL }
  177. };
  178. /**
  179. An ACPI_PARSER array describing the IORT ITS node.
  180. **/
  181. STATIC CONST ACPI_PARSER IortNodeItsParser[] = {
  182. PARSE_IORT_NODE_HEADER (
  183. ValidateItsIdMappingCount,
  184. ValidateItsIdArrayReference
  185. ),
  186. { L"Number of ITSs", 4,16, L"%d", NULL, (VOID **)&ItsCount, NULL }
  187. };
  188. /**
  189. An ACPI_PARSER array describing the ITS ID.
  190. **/
  191. STATIC CONST ACPI_PARSER ItsIdParser[] = {
  192. { L"GIC ITS Identifier", 4, 0, L"%d", NULL, NULL, NULL }
  193. };
  194. /**
  195. An ACPI_PARSER array describing the IORT Names Component node.
  196. **/
  197. STATIC CONST ACPI_PARSER IortNodeNamedComponentParser[] = {
  198. PARSE_IORT_NODE_HEADER (NULL, NULL),
  199. { L"Node Flags", 4, 16, L"%d", NULL, NULL, NULL, NULL },
  200. { L"Memory access properties",8, 20, L"0x%lx", NULL, NULL, NULL, NULL },
  201. { L"Device memory address size limit",1, 28, L"%d", NULL, NULL, NULL, NULL }
  202. };
  203. /**
  204. An ACPI_PARSER array describing the IORT Root Complex node.
  205. **/
  206. STATIC CONST ACPI_PARSER IortNodeRootComplexParser[] = {
  207. PARSE_IORT_NODE_HEADER (NULL, NULL),
  208. { L"Memory access properties",8, 16, L"0x%lx", NULL, NULL, NULL, NULL },
  209. { L"ATS Attribute", 4, 24, L"0x%x", NULL, NULL, NULL, NULL },
  210. { L"PCI Segment number", 4, 28, L"0x%x", NULL, NULL, NULL, NULL },
  211. { L"Memory access size limit",1, 32, L"0x%x", NULL, NULL, NULL, NULL },
  212. { L"Reserved", 3, 33, L"%x %x %x", Dump3Chars, NULL, NULL, NULL }
  213. };
  214. /**
  215. An ACPI_PARSER array describing the IORT PMCG node.
  216. **/
  217. STATIC CONST ACPI_PARSER IortNodePmcgParser[] = {
  218. PARSE_IORT_NODE_HEADER (ValidatePmcgIdMappingCount, NULL),
  219. { L"Page 0 Base Address", 8, 16, L"0x%lx", NULL, NULL, NULL, NULL },
  220. { L"Overflow interrupt GSIV", 4, 24, L"0x%x", NULL, NULL, NULL, NULL },
  221. { L"Node reference", 4, 28, L"0x%x", NULL, NULL, NULL, NULL },
  222. { L"Page 1 Base Address", 8, 32, L"0x%lx", NULL, NULL, NULL, NULL }
  223. };
  224. /**
  225. This function parses the IORT Node Id Mapping array.
  226. @param [in] Ptr Pointer to the start of the ID mapping array.
  227. @param [in] Length Length of the buffer.
  228. @param [in] MappingCount The ID Mapping count.
  229. **/
  230. STATIC
  231. VOID
  232. DumpIortNodeIdMappings (
  233. IN UINT8 *Ptr,
  234. IN UINT32 Length,
  235. IN UINT32 MappingCount
  236. )
  237. {
  238. UINT32 Index;
  239. UINT32 Offset;
  240. CHAR8 Buffer[40]; // Used for AsciiName param of ParseAcpi
  241. Index = 0;
  242. Offset = 0;
  243. while ((Index < MappingCount) &&
  244. (Offset < Length))
  245. {
  246. AsciiSPrint (
  247. Buffer,
  248. sizeof (Buffer),
  249. "ID Mapping [%d]",
  250. Index
  251. );
  252. Offset += ParseAcpi (
  253. TRUE,
  254. 4,
  255. Buffer,
  256. Ptr + Offset,
  257. Length - Offset,
  258. PARSER_PARAMS (IortNodeIdMappingParser)
  259. );
  260. Index++;
  261. }
  262. }
  263. /**
  264. This function parses the IORT SMMUv1/2 node.
  265. @param [in] Ptr Pointer to the start of the buffer.
  266. @param [in] Length Length of the buffer.
  267. @param [in] MappingCount The ID Mapping count.
  268. @param [in] MappingOffset The offset of the ID Mapping array
  269. from the start of the IORT table.
  270. **/
  271. STATIC
  272. VOID
  273. DumpIortNodeSmmuV1V2 (
  274. IN UINT8 *Ptr,
  275. IN UINT16 Length,
  276. IN UINT32 MappingCount,
  277. IN UINT32 MappingOffset
  278. )
  279. {
  280. UINT32 Index;
  281. UINT32 Offset;
  282. CHAR8 Buffer[50]; // Used for AsciiName param of ParseAcpi
  283. ParseAcpi (
  284. TRUE,
  285. 2,
  286. "SMMUv1 or SMMUv2 Node",
  287. Ptr,
  288. Length,
  289. PARSER_PARAMS (IortNodeSmmuV1V2Parser)
  290. );
  291. // Check if the values used to control the parsing logic have been
  292. // successfully read.
  293. if ((InterruptContextCount == NULL) ||
  294. (InterruptContextOffset == NULL) ||
  295. (PmuInterruptCount == NULL) ||
  296. (PmuInterruptOffset == NULL))
  297. {
  298. IncrementErrorCount ();
  299. Print (
  300. L"ERROR: Insufficient SMMUv1/2 node length. Length = %d\n",
  301. Length
  302. );
  303. return;
  304. }
  305. Offset = *InterruptContextOffset;
  306. Index = 0;
  307. while ((Index < *InterruptContextCount) &&
  308. (Offset < Length))
  309. {
  310. AsciiSPrint (
  311. Buffer,
  312. sizeof (Buffer),
  313. "Context Interrupts Array [%d]",
  314. Index
  315. );
  316. Offset += ParseAcpi (
  317. TRUE,
  318. 4,
  319. Buffer,
  320. Ptr + Offset,
  321. Length - Offset,
  322. PARSER_PARAMS (InterruptArrayParser)
  323. );
  324. Index++;
  325. }
  326. Offset = *PmuInterruptOffset;
  327. Index = 0;
  328. while ((Index < *PmuInterruptCount) &&
  329. (Offset < Length))
  330. {
  331. AsciiSPrint (
  332. Buffer,
  333. sizeof (Buffer),
  334. "PMU Interrupts Array [%d]",
  335. Index
  336. );
  337. Offset += ParseAcpi (
  338. TRUE,
  339. 4,
  340. Buffer,
  341. Ptr + Offset,
  342. Length - Offset,
  343. PARSER_PARAMS (InterruptArrayParser)
  344. );
  345. Index++;
  346. }
  347. DumpIortNodeIdMappings (
  348. Ptr + MappingOffset,
  349. Length - MappingOffset,
  350. MappingCount
  351. );
  352. }
  353. /**
  354. This function parses the IORT SMMUv3 node.
  355. @param [in] Ptr Pointer to the start of the buffer.
  356. @param [in] Length Length of the buffer.
  357. @param [in] MappingCount The ID Mapping count.
  358. @param [in] MappingOffset The offset of the ID Mapping array
  359. from the start of the IORT table.
  360. **/
  361. STATIC
  362. VOID
  363. DumpIortNodeSmmuV3 (
  364. IN UINT8 *Ptr,
  365. IN UINT16 Length,
  366. IN UINT32 MappingCount,
  367. IN UINT32 MappingOffset
  368. )
  369. {
  370. ParseAcpi (
  371. TRUE,
  372. 2,
  373. "SMMUV3 Node",
  374. Ptr,
  375. Length,
  376. PARSER_PARAMS (IortNodeSmmuV3Parser)
  377. );
  378. DumpIortNodeIdMappings (
  379. Ptr + MappingOffset,
  380. Length - MappingOffset,
  381. MappingCount
  382. );
  383. }
  384. /**
  385. This function parses the IORT ITS node.
  386. @param [in] Ptr Pointer to the start of the buffer.
  387. @param [in] Length Length of the buffer.
  388. **/
  389. STATIC
  390. VOID
  391. DumpIortNodeIts (
  392. IN UINT8 *Ptr,
  393. IN UINT16 Length
  394. )
  395. {
  396. UINT32 Offset;
  397. UINT32 Index;
  398. CHAR8 Buffer[80]; // Used for AsciiName param of ParseAcpi
  399. Offset = ParseAcpi (
  400. TRUE,
  401. 2,
  402. "ITS Node",
  403. Ptr,
  404. Length,
  405. PARSER_PARAMS (IortNodeItsParser)
  406. );
  407. // Check if the values used to control the parsing logic have been
  408. // successfully read.
  409. if (ItsCount == NULL) {
  410. IncrementErrorCount ();
  411. Print (
  412. L"ERROR: Insufficient ITS group length. Length = %d.\n",
  413. Length
  414. );
  415. return;
  416. }
  417. Index = 0;
  418. while ((Index < *ItsCount) &&
  419. (Offset < Length))
  420. {
  421. AsciiSPrint (
  422. Buffer,
  423. sizeof (Buffer),
  424. "GIC ITS Identifier Array [%d]",
  425. Index
  426. );
  427. Offset += ParseAcpi (
  428. TRUE,
  429. 4,
  430. Buffer,
  431. Ptr + Offset,
  432. Length - Offset,
  433. PARSER_PARAMS (ItsIdParser)
  434. );
  435. Index++;
  436. }
  437. // Note: ITS does not have the ID Mappings Array
  438. }
  439. /**
  440. This function parses the IORT Named Component node.
  441. @param [in] Ptr Pointer to the start of the buffer.
  442. @param [in] Length Length of the buffer.
  443. @param [in] MappingCount The ID Mapping count.
  444. @param [in] MappingOffset The offset of the ID Mapping array
  445. from the start of the IORT table.
  446. **/
  447. STATIC
  448. VOID
  449. DumpIortNodeNamedComponent (
  450. IN UINT8 *Ptr,
  451. IN UINT16 Length,
  452. IN UINT32 MappingCount,
  453. IN UINT32 MappingOffset
  454. )
  455. {
  456. UINT32 Offset;
  457. Offset = ParseAcpi (
  458. TRUE,
  459. 2,
  460. "Named Component Node",
  461. Ptr,
  462. Length,
  463. PARSER_PARAMS (IortNodeNamedComponentParser)
  464. );
  465. // Estimate the Device Name length
  466. PrintFieldName (2, L"Device Object Name");
  467. while ((*(Ptr + Offset) != 0) &&
  468. (Offset < Length))
  469. {
  470. Print (L"%c", *(Ptr + Offset));
  471. Offset++;
  472. }
  473. Print (L"\n");
  474. DumpIortNodeIdMappings (
  475. Ptr + MappingOffset,
  476. Length - MappingOffset,
  477. MappingCount
  478. );
  479. }
  480. /**
  481. This function parses the IORT Root Complex node.
  482. @param [in] Ptr Pointer to the start of the buffer.
  483. @param [in] Length Length of the buffer.
  484. @param [in] MappingCount The ID Mapping count.
  485. @param [in] MappingOffset The offset of the ID Mapping array
  486. from the start of the IORT table.
  487. **/
  488. STATIC
  489. VOID
  490. DumpIortNodeRootComplex (
  491. IN UINT8 *Ptr,
  492. IN UINT16 Length,
  493. IN UINT32 MappingCount,
  494. IN UINT32 MappingOffset
  495. )
  496. {
  497. ParseAcpi (
  498. TRUE,
  499. 2,
  500. "Root Complex Node",
  501. Ptr,
  502. Length,
  503. PARSER_PARAMS (IortNodeRootComplexParser)
  504. );
  505. DumpIortNodeIdMappings (
  506. Ptr + MappingOffset,
  507. Length - MappingOffset,
  508. MappingCount
  509. );
  510. }
  511. /**
  512. This function parses the IORT PMCG node.
  513. @param [in] Ptr Pointer to the start of the buffer.
  514. @param [in] Length Length of the buffer.
  515. @param [in] MappingCount The ID Mapping count.
  516. @param [in] MappingOffset The offset of the ID Mapping array
  517. from the start of the IORT table.
  518. **/
  519. STATIC
  520. VOID
  521. DumpIortNodePmcg (
  522. IN UINT8 *Ptr,
  523. IN UINT16 Length,
  524. IN UINT32 MappingCount,
  525. IN UINT32 MappingOffset
  526. )
  527. {
  528. ParseAcpi (
  529. TRUE,
  530. 2,
  531. "PMCG Node",
  532. Ptr,
  533. Length,
  534. PARSER_PARAMS (IortNodePmcgParser)
  535. );
  536. DumpIortNodeIdMappings (
  537. Ptr + MappingOffset,
  538. Length - MappingOffset,
  539. MappingCount
  540. );
  541. }
  542. /**
  543. This function parses the ACPI IORT table.
  544. When trace is enabled this function parses the IORT table and traces the ACPI fields.
  545. This function also parses the following nodes:
  546. - ITS Group
  547. - Named Component
  548. - Root Complex
  549. - SMMUv1/2
  550. - SMMUv3
  551. - PMCG
  552. This function also performs validation of the ACPI table fields.
  553. @param [in] Trace If TRUE, trace the ACPI fields.
  554. @param [in] Ptr Pointer to the start of the buffer.
  555. @param [in] AcpiTableLength Length of the ACPI table.
  556. @param [in] AcpiTableRevision Revision of the ACPI table.
  557. **/
  558. VOID
  559. EFIAPI
  560. ParseAcpiIort (
  561. IN BOOLEAN Trace,
  562. IN UINT8 *Ptr,
  563. IN UINT32 AcpiTableLength,
  564. IN UINT8 AcpiTableRevision
  565. )
  566. {
  567. UINT32 Offset;
  568. UINT32 Index;
  569. UINT8 *NodePtr;
  570. if (!Trace) {
  571. return;
  572. }
  573. ParseAcpi (
  574. TRUE,
  575. 0,
  576. "IORT",
  577. Ptr,
  578. AcpiTableLength,
  579. PARSER_PARAMS (IortParser)
  580. );
  581. // Check if the values used to control the parsing logic have been
  582. // successfully read.
  583. if ((IortNodeCount == NULL) ||
  584. (IortNodeOffset == NULL))
  585. {
  586. IncrementErrorCount ();
  587. Print (
  588. L"ERROR: Insufficient table length. AcpiTableLength = %d.\n",
  589. AcpiTableLength
  590. );
  591. return;
  592. }
  593. Offset = *IortNodeOffset;
  594. NodePtr = Ptr + Offset;
  595. Index = 0;
  596. // Parse the specified number of IORT nodes or the IORT table buffer length.
  597. // Whichever is minimum.
  598. while ((Index++ < *IortNodeCount) &&
  599. (Offset < AcpiTableLength))
  600. {
  601. // Parse the IORT Node Header
  602. ParseAcpi (
  603. FALSE,
  604. 0,
  605. "IORT Node Header",
  606. NodePtr,
  607. AcpiTableLength - Offset,
  608. PARSER_PARAMS (IortNodeHeaderParser)
  609. );
  610. // Check if the values used to control the parsing logic have been
  611. // successfully read.
  612. if ((IortNodeType == NULL) ||
  613. (IortNodeLength == NULL) ||
  614. (IortIdMappingCount == NULL) ||
  615. (IortIdMappingOffset == NULL))
  616. {
  617. IncrementErrorCount ();
  618. Print (
  619. L"ERROR: Insufficient remaining table buffer length to read the " \
  620. L"IORT node header. Length = %d.\n",
  621. AcpiTableLength - Offset
  622. );
  623. return;
  624. }
  625. // Validate IORT Node length
  626. if ((*IortNodeLength == 0) ||
  627. ((Offset + (*IortNodeLength)) > AcpiTableLength))
  628. {
  629. IncrementErrorCount ();
  630. Print (
  631. L"ERROR: Invalid IORT Node length. " \
  632. L"Length = %d. Offset = %d. AcpiTableLength = %d.\n",
  633. *IortNodeLength,
  634. Offset,
  635. AcpiTableLength
  636. );
  637. return;
  638. }
  639. PrintFieldName (2, L"* Node Offset *");
  640. Print (L"0x%x\n", Offset);
  641. switch (*IortNodeType) {
  642. case EFI_ACPI_IORT_TYPE_ITS_GROUP:
  643. DumpIortNodeIts (
  644. NodePtr,
  645. *IortNodeLength
  646. );
  647. break;
  648. case EFI_ACPI_IORT_TYPE_NAMED_COMP:
  649. DumpIortNodeNamedComponent (
  650. NodePtr,
  651. *IortNodeLength,
  652. *IortIdMappingCount,
  653. *IortIdMappingOffset
  654. );
  655. break;
  656. case EFI_ACPI_IORT_TYPE_ROOT_COMPLEX:
  657. DumpIortNodeRootComplex (
  658. NodePtr,
  659. *IortNodeLength,
  660. *IortIdMappingCount,
  661. *IortIdMappingOffset
  662. );
  663. break;
  664. case EFI_ACPI_IORT_TYPE_SMMUv1v2:
  665. DumpIortNodeSmmuV1V2 (
  666. NodePtr,
  667. *IortNodeLength,
  668. *IortIdMappingCount,
  669. *IortIdMappingOffset
  670. );
  671. break;
  672. case EFI_ACPI_IORT_TYPE_SMMUv3:
  673. DumpIortNodeSmmuV3 (
  674. NodePtr,
  675. *IortNodeLength,
  676. *IortIdMappingCount,
  677. *IortIdMappingOffset
  678. );
  679. break;
  680. case EFI_ACPI_IORT_TYPE_PMCG:
  681. DumpIortNodePmcg (
  682. NodePtr,
  683. *IortNodeLength,
  684. *IortIdMappingCount,
  685. *IortIdMappingOffset
  686. );
  687. break;
  688. default:
  689. IncrementErrorCount ();
  690. Print (L"ERROR: Unsupported IORT Node type = %d\n", *IortNodeType);
  691. } // switch
  692. NodePtr += (*IortNodeLength);
  693. Offset += (*IortNodeLength);
  694. } // while
  695. }