1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499
|
/** @file
ACPI Table Protocol Implementation
Copyright (c) 2006 - 2025, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2016, Linaro Ltd. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
//
// Includes
//
#include "AcpiTable.h"
//
// The maximum number of tables that pre-allocated.
//
UINTN mEfiAcpiMaxNumTables = EFI_ACPI_MAX_NUM_TABLES;
//
// Allocation strategy to use for AllocatePages ().
// Runtime value depends on PcdExposedAcpiTableVersions.
//
STATIC EFI_ALLOCATE_TYPE mAcpiTableAllocType;
/**
This function adds an ACPI table to the table list. It will detect FACS and
allocate the correct type of memory and properly align the table.
@param AcpiTableInstance Instance of the protocol.
@param Table Table to add.
@param Checksum Does the table require checksumming.
@param Version The version of the list to add the table to.
@param IsFromHob True, if add Apci Table from Hob List.
@param Handle Pointer for returning the handle.
@return EFI_SUCCESS The function completed successfully.
@return EFI_OUT_OF_RESOURCES Could not allocate a required resource.
@return EFI_ABORTED The table is a duplicate of a table that is required
to be unique.
**/
EFI_STATUS
AddTableToList (
IN EFI_ACPI_TABLE_INSTANCE *AcpiTableInstance,
IN VOID *Table,
IN BOOLEAN Checksum,
IN EFI_ACPI_TABLE_VERSION Version,
IN BOOLEAN IsFromHob,
OUT UINTN *Handle
);
/**
This function finds and removes the table specified by the handle.
@param AcpiTableInstance Instance of the protocol.
@param Version Bitmask of which versions to remove.
@param Handle Table to remove.
@return EFI_SUCCESS The function completed successfully.
@return EFI_ABORTED An error occurred.
@return EFI_NOT_FOUND Handle not found in table list.
**/
EFI_STATUS
RemoveTableFromList (
IN EFI_ACPI_TABLE_INSTANCE *AcpiTableInstance,
IN EFI_ACPI_TABLE_VERSION Version,
IN UINTN Handle
);
/**
This function calculates and updates an UINT8 checksum.
@param Buffer Pointer to buffer to checksum
@param Size Number of bytes to checksum
@param ChecksumOffset Offset to place the checksum result in
@return EFI_SUCCESS The function completed successfully.
**/
EFI_STATUS
AcpiPlatformChecksum (
IN VOID *Buffer,
IN UINTN Size,
IN UINTN ChecksumOffset
);
/**
Checksum all versions of the common tables, RSDP, RSDT, XSDT.
@param AcpiTableInstance Protocol instance private data.
@return EFI_SUCCESS The function completed successfully.
**/
EFI_STATUS
ChecksumCommonTables (
IN OUT EFI_ACPI_TABLE_INSTANCE *AcpiTableInstance
);
//
// Protocol function implementations.
//
/**
This function publishes the specified versions of the ACPI tables by
installing EFI configuration table entries for them. Any combination of
table versions can be published.
@param AcpiTableInstance Instance of the protocol.
@param Version Version(s) to publish.
@return EFI_SUCCESS The function completed successfully.
@return EFI_ABORTED The function could not complete successfully.
**/
EFI_STATUS
EFIAPI
PublishTables (
IN EFI_ACPI_TABLE_INSTANCE *AcpiTableInstance,
IN EFI_ACPI_TABLE_VERSION Version
)
{
EFI_STATUS Status;
UINT32 *CurrentRsdtEntry;
VOID *CurrentXsdtEntry;
UINT64 Buffer64;
//
// Reorder tables as some operating systems don't seem to find the
// FADT correctly if it is not in the first few entries
//
//
// Add FADT as the first entry
//
if ((Version & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
CurrentRsdtEntry = (UINT32 *)((UINT8 *)AcpiTableInstance->Rsdt1 + sizeof (EFI_ACPI_DESCRIPTION_HEADER));
*CurrentRsdtEntry = (UINT32)(UINTN)AcpiTableInstance->Fadt1;
CurrentRsdtEntry = (UINT32 *)((UINT8 *)AcpiTableInstance->Rsdt3 + sizeof (EFI_ACPI_DESCRIPTION_HEADER));
*CurrentRsdtEntry = (UINT32)(UINTN)AcpiTableInstance->Fadt3;
}
if ((Version & ACPI_TABLE_VERSION_GTE_2_0) != 0) {
CurrentXsdtEntry = (VOID *)((UINT8 *)AcpiTableInstance->Xsdt + sizeof (EFI_ACPI_DESCRIPTION_HEADER));
//
// Add entry to XSDT, XSDT expects 64 bit pointers, but
// the table pointers in XSDT are not aligned on 8 byte boundary.
//
Buffer64 = (UINT64)(UINTN)AcpiTableInstance->Fadt3;
CopyMem (
CurrentXsdtEntry,
&Buffer64,
sizeof (UINT64)
);
}
//
// Do checksum again because Dsdt/Xsdt is updated.
//
ChecksumCommonTables (AcpiTableInstance);
//
// Add the RSD_PTR to the system table and store that we have installed the
// tables.
//
if ((Version & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
Status = gBS->InstallConfigurationTable (&gEfiAcpi10TableGuid, AcpiTableInstance->Rsdp1);
if (EFI_ERROR (Status)) {
return EFI_ABORTED;
}
}
if ((Version & ACPI_TABLE_VERSION_GTE_2_0) != 0) {
Status = gBS->InstallConfigurationTable (&gEfiAcpiTableGuid, AcpiTableInstance->Rsdp3);
if (EFI_ERROR (Status)) {
return EFI_ABORTED;
}
}
return EFI_SUCCESS;
}
/**
Installs an ACPI table into the RSDT/XSDT.
Note that the ACPI table should be checksumed before installing it.
Otherwise it will assert.
@param This Protocol instance pointer.
@param AcpiTableBuffer A pointer to a buffer containing the ACPI table to be installed.
@param AcpiTableBufferSize Specifies the size, in bytes, of the AcpiTableBuffer buffer.
@param TableKey Reurns a key to refer to the ACPI table.
@return EFI_SUCCESS The table was successfully inserted.
@return EFI_INVALID_PARAMETER Either AcpiTableBuffer is NULL, TableKey is NULL, or AcpiTableBufferSize
and the size field embedded in the ACPI table pointed to by AcpiTableBuffer
are not in sync.
@return EFI_OUT_OF_RESOURCES Insufficient resources exist to complete the request.
@retval EFI_ACCESS_DENIED The table signature matches a table already
present in the system and platform policy
does not allow duplicate tables of this type.
**/
EFI_STATUS
EFIAPI
InstallAcpiTable (
IN EFI_ACPI_TABLE_PROTOCOL *This,
IN VOID *AcpiTableBuffer,
IN UINTN AcpiTableBufferSize,
OUT UINTN *TableKey
)
{
EFI_ACPI_TABLE_INSTANCE *AcpiTableInstance;
EFI_STATUS Status;
VOID *AcpiTableBufferConst;
EFI_ACPI_TABLE_VERSION Version;
//
// Check for invalid input parameters
//
if ( (AcpiTableBuffer == NULL) || (TableKey == NULL)
|| (((EFI_ACPI_DESCRIPTION_HEADER *)AcpiTableBuffer)->Length != AcpiTableBufferSize))
{
return EFI_INVALID_PARAMETER;
}
Version = PcdGet32 (PcdAcpiExposedTableVersions);
//
// Get the instance of the ACPI table protocol
//
AcpiTableInstance = EFI_ACPI_TABLE_INSTANCE_FROM_THIS (This);
//
// Install the ACPI table
//
AcpiTableBufferConst = AllocateCopyPool (AcpiTableBufferSize, AcpiTableBuffer);
*TableKey = 0;
Status = AddTableToList (
AcpiTableInstance,
AcpiTableBufferConst,
TRUE,
Version,
FALSE,
TableKey
);
if (!EFI_ERROR (Status)) {
Status = PublishTables (
AcpiTableInstance,
Version
);
}
FreePool (AcpiTableBufferConst);
//
// Add a new table successfully, notify registed callback
//
if (FeaturePcdGet (PcdInstallAcpiSdtProtocol)) {
if (!EFI_ERROR (Status)) {
SdtNotifyAcpiList (
AcpiTableInstance,
Version,
*TableKey
);
}
}
return Status;
}
/**
Removes an ACPI table from the RSDT/XSDT.
@param This Protocol instance pointer.
@param TableKey Specifies the table to uninstall. The key was returned from InstallAcpiTable().
@return EFI_SUCCESS The table was successfully uninstalled.
@return EFI_NOT_FOUND TableKey does not refer to a valid key for a table entry.
**/
EFI_STATUS
EFIAPI
UninstallAcpiTable (
IN EFI_ACPI_TABLE_PROTOCOL *This,
IN UINTN TableKey
)
{
EFI_ACPI_TABLE_INSTANCE *AcpiTableInstance;
EFI_STATUS Status;
EFI_ACPI_TABLE_VERSION Version;
//
// Get the instance of the ACPI table protocol
//
AcpiTableInstance = EFI_ACPI_TABLE_INSTANCE_FROM_THIS (This);
Version = PcdGet32 (PcdAcpiExposedTableVersions);
//
// Uninstall the ACPI table
//
Status = RemoveTableFromList (
AcpiTableInstance,
Version,
TableKey
);
if (!EFI_ERROR (Status)) {
Status = PublishTables (
AcpiTableInstance,
Version
);
}
if (EFI_ERROR (Status)) {
return EFI_NOT_FOUND;
} else {
return EFI_SUCCESS;
}
}
/**
If the number of APCI tables exceeds the preallocated max table number, enlarge the table buffer.
@param AcpiTableInstance ACPI table protocol instance data structure.
@return EFI_SUCCESS reallocate the table beffer successfully.
@return EFI_OUT_OF_RESOURCES Unable to allocate required resources.
**/
EFI_STATUS
ReallocateAcpiTableBuffer (
IN EFI_ACPI_TABLE_INSTANCE *AcpiTableInstance
)
{
UINTN NewMaxTableNumber;
UINTN TotalSize;
UINT8 *Pointer;
EFI_PHYSICAL_ADDRESS PageAddress;
EFI_ACPI_TABLE_INSTANCE TempPrivateData;
EFI_STATUS Status;
UINT64 CurrentData;
EFI_MEMORY_TYPE AcpiAllocateMemoryType;
CopyMem (&TempPrivateData, AcpiTableInstance, sizeof (EFI_ACPI_TABLE_INSTANCE));
//
// Enlarge the max table number from mEfiAcpiMaxNumTables to mEfiAcpiMaxNumTables + EFI_ACPI_MAX_NUM_TABLES
//
NewMaxTableNumber = mEfiAcpiMaxNumTables + EFI_ACPI_MAX_NUM_TABLES;
//
// Create RSDT, XSDT structures and allocate buffers.
//
TotalSize = sizeof (EFI_ACPI_DESCRIPTION_HEADER) + // for ACPI 2.0/3.0 XSDT
NewMaxTableNumber * sizeof (UINT64);
if ((PcdGet32 (PcdAcpiExposedTableVersions) & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
TotalSize += sizeof (EFI_ACPI_DESCRIPTION_HEADER) + // for ACPI 1.0 RSDT
NewMaxTableNumber * sizeof (UINT32) +
sizeof (EFI_ACPI_DESCRIPTION_HEADER) + // for ACPI 2.0/3.0 RSDT
NewMaxTableNumber * sizeof (UINT32);
}
if (PcdGetBool (PcdNoACPIReclaimMemory)) {
AcpiAllocateMemoryType = EfiACPIMemoryNVS;
} else {
AcpiAllocateMemoryType = EfiACPIReclaimMemory;
}
if (mAcpiTableAllocType != AllocateAnyPages) {
//
// Allocate memory in the lower 32 bit of address range for
// compatibility with ACPI 1.0 OS.
//
// This is done because ACPI 1.0 pointers are 32 bit values.
// ACPI 2.0 OS and all 64 bit OS must use the 64 bit ACPI table addresses.
// There is no architectural reason these should be below 4GB, it is purely
// for convenience of implementation that we force memory below 4GB.
//
PageAddress = 0xFFFFFFFF;
Status = gBS->AllocatePages (
mAcpiTableAllocType,
AcpiAllocateMemoryType,
EFI_SIZE_TO_PAGES (TotalSize),
&PageAddress
);
} else {
Status = gBS->AllocatePool (
AcpiAllocateMemoryType,
TotalSize,
(VOID **)&Pointer
);
}
if (EFI_ERROR (Status)) {
return EFI_OUT_OF_RESOURCES;
}
if (mAcpiTableAllocType != AllocateAnyPages) {
Pointer = (UINT8 *)(UINTN)PageAddress;
}
ZeroMem (Pointer, TotalSize);
AcpiTableInstance->Rsdt1 = (EFI_ACPI_DESCRIPTION_HEADER *)Pointer;
if ((PcdGet32 (PcdAcpiExposedTableVersions) & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
Pointer += (sizeof (EFI_ACPI_DESCRIPTION_HEADER) + NewMaxTableNumber * sizeof (UINT32));
AcpiTableInstance->Rsdt3 = (EFI_ACPI_DESCRIPTION_HEADER *)Pointer;
Pointer += (sizeof (EFI_ACPI_DESCRIPTION_HEADER) + NewMaxTableNumber * sizeof (UINT32));
}
AcpiTableInstance->Xsdt = (EFI_ACPI_DESCRIPTION_HEADER *)Pointer;
//
// Update RSDP to point to the new Rsdt and Xsdt address.
//
if ((PcdGet32 (PcdAcpiExposedTableVersions) & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
AcpiTableInstance->Rsdp1->RsdtAddress = (UINT32)(UINTN)AcpiTableInstance->Rsdt1;
AcpiTableInstance->Rsdp3->RsdtAddress = (UINT32)(UINTN)AcpiTableInstance->Rsdt3;
}
CurrentData = (UINT64)(UINTN)AcpiTableInstance->Xsdt;
CopyMem (&AcpiTableInstance->Rsdp3->XsdtAddress, &CurrentData, sizeof (UINT64));
//
// copy the original Rsdt1, Rsdt3 and Xsdt structure to new buffer
//
if ((PcdGet32 (PcdAcpiExposedTableVersions) & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
CopyMem (AcpiTableInstance->Rsdt1, TempPrivateData.Rsdt1, (sizeof (EFI_ACPI_DESCRIPTION_HEADER) + mEfiAcpiMaxNumTables * sizeof (UINT32)));
CopyMem (AcpiTableInstance->Rsdt3, TempPrivateData.Rsdt3, (sizeof (EFI_ACPI_DESCRIPTION_HEADER) + mEfiAcpiMaxNumTables * sizeof (UINT32)));
}
CopyMem (AcpiTableInstance->Xsdt, TempPrivateData.Xsdt, (sizeof (EFI_ACPI_DESCRIPTION_HEADER) + mEfiAcpiMaxNumTables * sizeof (UINT64)));
if (mAcpiTableAllocType != AllocateAnyPages) {
//
// Calculate orignal ACPI table buffer size
//
TotalSize = sizeof (EFI_ACPI_DESCRIPTION_HEADER) + // for ACPI 2.0/3.0 XSDT
mEfiAcpiMaxNumTables * sizeof (UINT64);
if ((PcdGet32 (PcdAcpiExposedTableVersions) & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
TotalSize += sizeof (EFI_ACPI_DESCRIPTION_HEADER) + // for ACPI 1.0 RSDT
mEfiAcpiMaxNumTables * sizeof (UINT32) +
sizeof (EFI_ACPI_DESCRIPTION_HEADER) + // for ACPI 2.0/3.0 RSDT
mEfiAcpiMaxNumTables * sizeof (UINT32);
}
gBS->FreePages (
(EFI_PHYSICAL_ADDRESS)(UINTN)TempPrivateData.Rsdt1,
EFI_SIZE_TO_PAGES (TotalSize)
);
} else {
gBS->FreePool (TempPrivateData.Rsdt1);
}
//
// Update the Max ACPI table number
//
mEfiAcpiMaxNumTables = NewMaxTableNumber;
return EFI_SUCCESS;
}
/**
Free the memory associated with the provided EFI_ACPI_TABLE_LIST instance.
@param TableEntry EFI_ACPI_TABLE_LIST instance pointer
**/
STATIC
VOID
FreeTableMemory (
EFI_ACPI_TABLE_LIST *TableEntry
)
{
if (TableEntry->PoolAllocation) {
gBS->FreePool (TableEntry->Table);
} else {
gBS->FreePages (
(EFI_PHYSICAL_ADDRESS)(UINTN)TableEntry->Table,
EFI_SIZE_TO_PAGES (TableEntry->TableSize)
);
}
}
/**
This function adds an ACPI table to the table list. It will detect FACS and
allocate the correct type of memory and properly align the table.
@param AcpiTableInstance Instance of the protocol.
@param Table Table to add.
@param Checksum Does the table require checksumming.
@param Version The version of the list to add the table to.
@param IsFromHob True, if add Apci Table from Hob List.
@param Handle Pointer for returning the handle.
@return EFI_SUCCESS The function completed successfully.
@return EFI_OUT_OF_RESOURCES Could not allocate a required resource.
@retval EFI_ACCESS_DENIED The table signature matches a table already
present in the system and platform policy
does not allow duplicate tables of this type.
**/
EFI_STATUS
AddTableToList (
IN EFI_ACPI_TABLE_INSTANCE *AcpiTableInstance,
IN VOID *Table,
IN BOOLEAN Checksum,
IN EFI_ACPI_TABLE_VERSION Version,
IN BOOLEAN IsFromHob,
OUT UINTN *Handle
)
{
EFI_STATUS Status;
EFI_ACPI_TABLE_LIST *CurrentTableList;
UINT32 CurrentTableSignature;
UINT32 CurrentTableSize;
UINT32 *CurrentRsdtEntry;
VOID *CurrentXsdtEntry;
EFI_PHYSICAL_ADDRESS AllocPhysAddress;
UINT64 Buffer64;
BOOLEAN AddToRsdt;
EFI_MEMORY_TYPE AcpiAllocateMemoryType;
//
// Check for invalid input parameters
//
ASSERT (AcpiTableInstance);
ASSERT (Table);
ASSERT (Handle);
//
// Init locals
//
AddToRsdt = TRUE;
//
// Create a new list entry
//
CurrentTableList = AllocatePool (sizeof (EFI_ACPI_TABLE_LIST));
ASSERT (CurrentTableList);
//
// Determine table type and size
//
CurrentTableSignature = ((EFI_ACPI_COMMON_HEADER *)Table)->Signature;
CurrentTableSize = ((EFI_ACPI_COMMON_HEADER *)Table)->Length;
//
// Allocate a buffer for the table. All tables are allocated in the lower 32 bits of address space
// for backwards compatibility with ACPI 1.0 OS.
//
// This is done because ACPI 1.0 pointers are 32 bit values.
// ACPI 2.0 OS and all 64 bit OS must use the 64 bit ACPI table addresses.
// There is no architectural reason these should be below 4GB, it is purely
// for convenience of implementation that we force memory below 4GB.
//
AllocPhysAddress = 0xFFFFFFFF;
CurrentTableList->TableSize = CurrentTableSize;
CurrentTableList->PoolAllocation = FALSE;
if (PcdGetBool (PcdNoACPIReclaimMemory)) {
AcpiAllocateMemoryType = EfiACPIMemoryNVS;
} else {
AcpiAllocateMemoryType = EfiACPIReclaimMemory;
}
//
// Allocation memory type depends on the type of the table
//
if ((CurrentTableSignature == EFI_ACPI_2_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE) ||
(CurrentTableSignature == EFI_ACPI_4_0_UEFI_ACPI_DATA_TABLE_SIGNATURE))
{
//
// Allocate memory for the FACS. This structure must be aligned
// on a 64 byte boundary and must be ACPI NVS memory.
// Using AllocatePages should ensure that it is always aligned.
// Do not change signature for new ACPI version because they are same.
//
// UEFI table also need to be in ACPI NVS memory, because some data field
// could be updated by OS present agent. For example, BufferPtrAddress in
// SMM communication ACPI table.
//
ASSERT ((EFI_PAGE_SIZE % 64) == 0);
if (IsFromHob) {
AllocPhysAddress = (UINTN)Table;
Status = EFI_SUCCESS;
} else {
Status = gBS->AllocatePages (
AllocateMaxAddress,
EfiACPIMemoryNVS,
EFI_SIZE_TO_PAGES (CurrentTableList->TableSize),
&AllocPhysAddress
);
}
} else if (mAcpiTableAllocType == AllocateAnyPages) {
//
// If there is no allocation limit, there is also no need to use page
// based allocations for ACPI tables, which may be wasteful on platforms
// such as AArch64 that allocate multiples of 64 KB
//
Status = gBS->AllocatePool (
AcpiAllocateMemoryType,
CurrentTableList->TableSize,
(VOID **)&CurrentTableList->Table
);
CurrentTableList->PoolAllocation = TRUE;
} else {
//
// All other tables are ACPI reclaim memory, no alignment requirements.
//
Status = gBS->AllocatePages (
mAcpiTableAllocType,
AcpiAllocateMemoryType,
EFI_SIZE_TO_PAGES (CurrentTableList->TableSize),
&AllocPhysAddress
);
CurrentTableList->Table = (EFI_ACPI_COMMON_HEADER *)(UINTN)AllocPhysAddress;
}
//
// Check return value from memory alloc.
//
if (EFI_ERROR (Status)) {
gBS->FreePool (CurrentTableList);
return EFI_OUT_OF_RESOURCES;
}
if (!CurrentTableList->PoolAllocation) {
CurrentTableList->Table = (EFI_ACPI_COMMON_HEADER *)(UINTN)AllocPhysAddress;
}
//
// Initialize the table contents
//
CurrentTableList->Signature = EFI_ACPI_TABLE_LIST_SIGNATURE;
CopyMem (CurrentTableList->Table, Table, CurrentTableSize);
CurrentTableList->Handle = AcpiTableInstance->CurrentHandle++;
*Handle = CurrentTableList->Handle;
CurrentTableList->Version = Version;
//
// Update internal pointers if this is a required table. If it is a required
// table and a table of that type already exists, return an error.
//
// Calculate the checksum if the table is not FACS.
//
switch (CurrentTableSignature) {
case EFI_ACPI_1_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE:
//
// We don't add the FADT in the standard way because some
// OS expect the FADT to be early in the table list.
// So we always add it as the first element in the list.
//
AddToRsdt = FALSE;
//
// Check that the table has not been previously added.
//
if ((((Version & EFI_ACPI_TABLE_VERSION_1_0B) != 0) && (AcpiTableInstance->Fadt1 != NULL)) ||
(((Version & ACPI_TABLE_VERSION_GTE_2_0) != 0) && (AcpiTableInstance->Fadt3 != NULL))
)
{
FreeTableMemory (CurrentTableList);
gBS->FreePool (CurrentTableList);
return EFI_ACCESS_DENIED;
}
//
// Add the table to the appropriate table version
//
if ((Version & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
//
// Save a pointer to the table
//
AcpiTableInstance->Fadt1 = (EFI_ACPI_1_0_FIXED_ACPI_DESCRIPTION_TABLE *)CurrentTableList->Table;
//
// Update pointers in FADT. If tables don't exist this will put NULL pointers there.
//
AcpiTableInstance->Fadt1->FirmwareCtrl = (UINT32)(UINTN)AcpiTableInstance->Facs1;
AcpiTableInstance->Fadt1->Dsdt = (UINT32)(UINTN)AcpiTableInstance->Dsdt1;
//
// RSDP OEM information is updated to match the FADT OEM information
//
CopyMem (
&AcpiTableInstance->Rsdp1->OemId,
&AcpiTableInstance->Fadt1->Header.OemId,
6
);
//
// RSDT OEM information is updated to match the FADT OEM information.
//
CopyMem (
&AcpiTableInstance->Rsdt1->OemId,
&AcpiTableInstance->Fadt1->Header.OemId,
6
);
CopyMem (
&AcpiTableInstance->Rsdt1->OemTableId,
&AcpiTableInstance->Fadt1->Header.OemTableId,
sizeof (UINT64)
);
AcpiTableInstance->Rsdt1->OemRevision = AcpiTableInstance->Fadt1->Header.OemRevision;
}
if ((Version & ACPI_TABLE_VERSION_GTE_2_0) != 0) {
//
// Save a pointer to the table
//
AcpiTableInstance->Fadt3 = (EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE *)CurrentTableList->Table;
//
// Update pointers in FADT. If tables don't exist this will put NULL pointers there.
// Note: If the FIRMWARE_CTRL is non-zero, then X_FIRMWARE_CTRL must be zero, and
// vice-versa.
//
if ((UINT64)(UINTN)AcpiTableInstance->Facs3 < BASE_4GB) {
AcpiTableInstance->Fadt3->FirmwareCtrl = (UINT32)(UINTN)AcpiTableInstance->Facs3;
ZeroMem (&AcpiTableInstance->Fadt3->XFirmwareCtrl, sizeof (UINT64));
} else {
Buffer64 = (UINT64)(UINTN)AcpiTableInstance->Facs3;
CopyMem (
&AcpiTableInstance->Fadt3->XFirmwareCtrl,
&Buffer64,
sizeof (UINT64)
);
AcpiTableInstance->Fadt3->FirmwareCtrl = 0;
}
if ((UINT64)(UINTN)AcpiTableInstance->Dsdt3 < BASE_4GB) {
AcpiTableInstance->Fadt3->Dsdt = (UINT32)(UINTN)AcpiTableInstance->Dsdt3;
//
// Comment block "the caller installs the tables in "DSDT, FADT" order"
// The below comments are also in "the caller installs the tables in "FADT, DSDT" order" comment block.
//
// The ACPI specification, up to and including revision 5.1 Errata A,
// allows the DSDT and X_DSDT fields to be both set in the FADT.
// (Obviously, this only makes sense if the DSDT address is representable in 4 bytes.)
// Starting with 5.1 Errata B, specifically for Mantis 1393 <https://mantis.uefi.org/mantis/view.php?id=1393>,
// the spec requires at most one of DSDT and X_DSDT fields to be set to a nonzero value,
// but strangely an exception is 6.0 that has no this requirement.
//
// Here we do not make the DSDT and X_DSDT fields mutual exclusion conditionally
// by checking FADT revision, but always set both DSDT and X_DSDT fields in the FADT
// to have better compatibility as some OS may have assumption to only consume X_DSDT
// field even the DSDT address is < 4G.
//
Buffer64 = AcpiTableInstance->Fadt3->Dsdt;
} else {
AcpiTableInstance->Fadt3->Dsdt = 0;
Buffer64 = (UINT64)(UINTN)AcpiTableInstance->Dsdt3;
}
CopyMem (&AcpiTableInstance->Fadt3->XDsdt, &Buffer64, sizeof (UINT64));
//
// RSDP OEM information is updated to match the FADT OEM information
//
CopyMem (
&AcpiTableInstance->Rsdp3->OemId,
&AcpiTableInstance->Fadt3->Header.OemId,
6
);
if ((PcdGet32 (PcdAcpiExposedTableVersions) & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
//
// RSDT OEM information is updated to match FADT OEM information.
//
CopyMem (
&AcpiTableInstance->Rsdt3->OemId,
&AcpiTableInstance->Fadt3->Header.OemId,
6
);
CopyMem (
&AcpiTableInstance->Rsdt3->OemTableId,
&AcpiTableInstance->Fadt3->Header.OemTableId,
sizeof (UINT64)
);
AcpiTableInstance->Rsdt3->OemRevision = AcpiTableInstance->Fadt3->Header.OemRevision;
}
//
// XSDT OEM information is updated to match FADT OEM information.
//
CopyMem (
&AcpiTableInstance->Xsdt->OemId,
&AcpiTableInstance->Fadt3->Header.OemId,
6
);
CopyMem (
&AcpiTableInstance->Xsdt->OemTableId,
&AcpiTableInstance->Fadt3->Header.OemTableId,
sizeof (UINT64)
);
AcpiTableInstance->Xsdt->OemRevision = AcpiTableInstance->Fadt3->Header.OemRevision;
}
//
// Checksum the table
//
if (Checksum) {
AcpiPlatformChecksum (
CurrentTableList->Table,
CurrentTableList->Table->Length,
OFFSET_OF (
EFI_ACPI_DESCRIPTION_HEADER,
Checksum
)
);
}
break;
case EFI_ACPI_1_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE:
//
// Check that the table has not been previously added.
//
if ((((Version & EFI_ACPI_TABLE_VERSION_1_0B) != 0) && (AcpiTableInstance->Facs1 != NULL)) ||
(((Version & ACPI_TABLE_VERSION_GTE_2_0) != 0) && (AcpiTableInstance->Facs3 != NULL))
)
{
FreeTableMemory (CurrentTableList);
gBS->FreePool (CurrentTableList);
return EFI_ACCESS_DENIED;
}
//
// FACS is referenced by FADT and is not part of RSDT
//
AddToRsdt = FALSE;
//
// Add the table to the appropriate table version
//
if ((Version & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
//
// Save a pointer to the table
//
AcpiTableInstance->Facs1 = (EFI_ACPI_1_0_FIRMWARE_ACPI_CONTROL_STRUCTURE *)CurrentTableList->Table;
//
// If FADT already exists, update table pointers.
//
if (AcpiTableInstance->Fadt1 != NULL) {
AcpiTableInstance->Fadt1->FirmwareCtrl = (UINT32)(UINTN)AcpiTableInstance->Facs1;
//
// Checksum FADT table
//
AcpiPlatformChecksum (
AcpiTableInstance->Fadt1,
AcpiTableInstance->Fadt1->Header.Length,
OFFSET_OF (
EFI_ACPI_DESCRIPTION_HEADER,
Checksum
)
);
}
}
if ((Version & ACPI_TABLE_VERSION_GTE_2_0) != 0) {
//
// Save a pointer to the table
//
AcpiTableInstance->Facs3 = (EFI_ACPI_3_0_FIRMWARE_ACPI_CONTROL_STRUCTURE *)CurrentTableList->Table;
//
// If FADT already exists, update table pointers.
//
if (AcpiTableInstance->Fadt3 != NULL) {
//
// Note: If the FIRMWARE_CTRL is non-zero, then X_FIRMWARE_CTRL must be zero, and
// vice-versa.
//
if ((UINT64)(UINTN)AcpiTableInstance->Facs3 < BASE_4GB) {
AcpiTableInstance->Fadt3->FirmwareCtrl = (UINT32)(UINTN)AcpiTableInstance->Facs3;
ZeroMem (&AcpiTableInstance->Fadt3->XFirmwareCtrl, sizeof (UINT64));
} else {
Buffer64 = (UINT64)(UINTN)AcpiTableInstance->Facs3;
CopyMem (
&AcpiTableInstance->Fadt3->XFirmwareCtrl,
&Buffer64,
sizeof (UINT64)
);
AcpiTableInstance->Fadt3->FirmwareCtrl = 0;
}
//
// Checksum FADT table
//
AcpiPlatformChecksum (
AcpiTableInstance->Fadt3,
AcpiTableInstance->Fadt3->Header.Length,
OFFSET_OF (
EFI_ACPI_DESCRIPTION_HEADER,
Checksum
)
);
}
}
break;
case EFI_ACPI_1_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE:
//
// Check that the table has not been previously added.
//
if ((((Version & EFI_ACPI_TABLE_VERSION_1_0B) != 0) && (AcpiTableInstance->Dsdt1 != NULL)) ||
(((Version & ACPI_TABLE_VERSION_GTE_2_0) != 0) && (AcpiTableInstance->Dsdt3 != NULL))
)
{
FreeTableMemory (CurrentTableList);
gBS->FreePool (CurrentTableList);
return EFI_ACCESS_DENIED;
}
//
// DSDT is referenced by FADT and is not part of RSDT
//
AddToRsdt = FALSE;
//
// Add the table to the appropriate table version
//
if ((Version & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
//
// Save a pointer to the table
//
AcpiTableInstance->Dsdt1 = (EFI_ACPI_DESCRIPTION_HEADER *)CurrentTableList->Table;
//
// If FADT already exists, update table pointers.
//
if (AcpiTableInstance->Fadt1 != NULL) {
AcpiTableInstance->Fadt1->Dsdt = (UINT32)(UINTN)AcpiTableInstance->Dsdt1;
//
// Checksum FADT table
//
AcpiPlatformChecksum (
AcpiTableInstance->Fadt1,
AcpiTableInstance->Fadt1->Header.Length,
OFFSET_OF (
EFI_ACPI_DESCRIPTION_HEADER,
Checksum
)
);
}
}
if ((Version & ACPI_TABLE_VERSION_GTE_2_0) != 0) {
//
// Save a pointer to the table
//
AcpiTableInstance->Dsdt3 = (EFI_ACPI_DESCRIPTION_HEADER *)CurrentTableList->Table;
//
// If FADT already exists, update table pointers.
//
if (AcpiTableInstance->Fadt3 != NULL) {
if ((UINT64)(UINTN)AcpiTableInstance->Dsdt3 < BASE_4GB) {
AcpiTableInstance->Fadt3->Dsdt = (UINT32)(UINTN)AcpiTableInstance->Dsdt3;
//
// Comment block "the caller installs the tables in "FADT, DSDT" order"
// The below comments are also in "the caller installs the tables in "DSDT, FADT" order" comment block.
//
// The ACPI specification, up to and including revision 5.1 Errata A,
// allows the DSDT and X_DSDT fields to be both set in the FADT.
// (Obviously, this only makes sense if the DSDT address is representable in 4 bytes.)
// Starting with 5.1 Errata B, specifically for Mantis 1393 <https://mantis.uefi.org/mantis/view.php?id=1393>,
// the spec requires at most one of DSDT and X_DSDT fields to be set to a nonzero value,
// but strangely an exception is 6.0 that has no this requirement.
//
// Here we do not make the DSDT and X_DSDT fields mutual exclusion conditionally
// by checking FADT revision, but always set both DSDT and X_DSDT fields in the FADT
// to have better compatibility as some OS may have assumption to only consume X_DSDT
// field even the DSDT address is < 4G.
//
Buffer64 = AcpiTableInstance->Fadt3->Dsdt;
} else {
AcpiTableInstance->Fadt3->Dsdt = 0;
Buffer64 = (UINT64)(UINTN)AcpiTableInstance->Dsdt3;
}
CopyMem (&AcpiTableInstance->Fadt3->XDsdt, &Buffer64, sizeof (UINT64));
//
// Checksum FADT table
//
AcpiPlatformChecksum (
AcpiTableInstance->Fadt3,
AcpiTableInstance->Fadt3->Header.Length,
OFFSET_OF (
EFI_ACPI_DESCRIPTION_HEADER,
Checksum
)
);
}
}
//
// Checksum the table
//
if (Checksum) {
AcpiPlatformChecksum (
CurrentTableList->Table,
CurrentTableList->Table->Length,
OFFSET_OF (
EFI_ACPI_DESCRIPTION_HEADER,
Checksum
)
);
}
break;
default:
//
// Checksum the table
//
if (Checksum) {
AcpiPlatformChecksum (
CurrentTableList->Table,
CurrentTableList->Table->Length,
OFFSET_OF (
EFI_ACPI_DESCRIPTION_HEADER,
Checksum
)
);
}
break;
}
//
// Add the table to the current list of tables
//
InsertTailList (&AcpiTableInstance->TableList, &CurrentTableList->Link);
//
// Add the table to RSDT and/or XSDT table entry lists.
//
//
// Add to ACPI 1.0b table tree
//
if ((Version & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
if (AddToRsdt) {
//
// If the table number exceed the gEfiAcpiMaxNumTables, enlarge the table buffer
//
if (AcpiTableInstance->NumberOfTableEntries1 >= mEfiAcpiMaxNumTables) {
Status = ReallocateAcpiTableBuffer (AcpiTableInstance);
ASSERT_EFI_ERROR (Status);
}
CurrentRsdtEntry = (UINT32 *)
(
(UINT8 *)AcpiTableInstance->Rsdt1 +
sizeof (EFI_ACPI_DESCRIPTION_HEADER) +
AcpiTableInstance->NumberOfTableEntries1 *
sizeof (UINT32)
);
//
// Add entry to the RSDT unless its the FACS or DSDT
//
*CurrentRsdtEntry = (UINT32)(UINTN)CurrentTableList->Table;
//
// Update RSDT length
//
AcpiTableInstance->Rsdt1->Length = AcpiTableInstance->Rsdt1->Length + sizeof (UINT32);
AcpiTableInstance->NumberOfTableEntries1++;
}
}
//
// Add to ACPI 2.0/3.0 table tree
//
if ((Version & ACPI_TABLE_VERSION_GTE_2_0) != 0) {
if (AddToRsdt) {
//
// If the table number exceed the gEfiAcpiMaxNumTables, enlarge the table buffer
//
if (AcpiTableInstance->NumberOfTableEntries3 >= mEfiAcpiMaxNumTables) {
Status = ReallocateAcpiTableBuffer (AcpiTableInstance);
ASSERT_EFI_ERROR (Status);
}
if ((PcdGet32 (PcdAcpiExposedTableVersions) & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
//
// At this time, it is assumed that RSDT and XSDT maintain parallel lists of tables.
// If it becomes necessary to maintain separate table lists, changes will be required.
//
CurrentRsdtEntry = (UINT32 *)
(
(UINT8 *)AcpiTableInstance->Rsdt3 +
sizeof (EFI_ACPI_DESCRIPTION_HEADER) +
AcpiTableInstance->NumberOfTableEntries3 *
sizeof (UINT32)
);
//
// Add entry to the RSDT
//
*CurrentRsdtEntry = (UINT32)(UINTN)CurrentTableList->Table;
//
// Update RSDT length
//
AcpiTableInstance->Rsdt3->Length = AcpiTableInstance->Rsdt3->Length + sizeof (UINT32);
}
//
// This pointer must not be directly dereferenced as the XSDT entries may not
// be 64 bit aligned resulting in a possible fault. Use CopyMem to update.
//
CurrentXsdtEntry = (VOID *)
(
(UINT8 *)AcpiTableInstance->Xsdt +
sizeof (EFI_ACPI_DESCRIPTION_HEADER) +
AcpiTableInstance->NumberOfTableEntries3 *
sizeof (UINT64)
);
//
// Add entry to XSDT, XSDT expects 64 bit pointers, but
// the table pointers in XSDT are not aligned on 8 byte boundary.
//
Buffer64 = (UINT64)(UINTN)CurrentTableList->Table;
CopyMem (
CurrentXsdtEntry,
&Buffer64,
sizeof (UINT64)
);
//
// Update length
//
AcpiTableInstance->Xsdt->Length = AcpiTableInstance->Xsdt->Length + sizeof (UINT64);
AcpiTableInstance->NumberOfTableEntries3++;
}
}
ChecksumCommonTables (AcpiTableInstance);
return EFI_SUCCESS;
}
/**
This function finds the table specified by the handle and returns a pointer to it.
If the handle is not found, EFI_NOT_FOUND is returned and the contents of Table are
undefined.
@param Handle Table to find.
@param TableList Table list to search
@param Table Pointer to table found.
@return EFI_SUCCESS The function completed successfully.
@return EFI_NOT_FOUND No table found matching the handle specified.
**/
EFI_STATUS
FindTableByHandle (
IN UINTN Handle,
IN LIST_ENTRY *TableList,
OUT EFI_ACPI_TABLE_LIST **Table
)
{
LIST_ENTRY *CurrentLink;
EFI_ACPI_TABLE_LIST *CurrentTable;
//
// Check for invalid input parameters
//
ASSERT (Table);
//
// Find the table
//
CurrentLink = TableList->ForwardLink;
while (CurrentLink != TableList) {
CurrentTable = EFI_ACPI_TABLE_LIST_FROM_LINK (CurrentLink);
if (CurrentTable->Handle == Handle) {
//
// Found handle, so return this table.
//
*Table = CurrentTable;
return EFI_SUCCESS;
}
CurrentLink = CurrentLink->ForwardLink;
}
//
// Table not found
//
return EFI_NOT_FOUND;
}
/**
This function removes a basic table from the RSDT and/or XSDT.
For Acpi 1.0 tables, pass in the Rsdt.
For Acpi 2.0 tables, pass in both Rsdt and Xsdt.
@param Table Pointer to table found.
@param NumberOfTableEntries Current number of table entries in the RSDT/XSDT
@param Rsdt Pointer to the RSDT to remove from
@param Xsdt Pointer to the Xsdt to remove from
@return EFI_SUCCESS The function completed successfully.
@return EFI_INVALID_PARAMETER The table was not found in both Rsdt and Xsdt.
**/
EFI_STATUS
RemoveTableFromRsdt (
IN OUT EFI_ACPI_TABLE_LIST *Table,
IN OUT UINTN *NumberOfTableEntries,
IN OUT EFI_ACPI_DESCRIPTION_HEADER *Rsdt OPTIONAL,
IN OUT EFI_ACPI_DESCRIPTION_HEADER *Xsdt OPTIONAL
)
{
UINT32 *CurrentRsdtEntry;
VOID *CurrentXsdtEntry;
UINT64 CurrentTablePointer64;
UINTN Index;
//
// Check for invalid input parameters
//
ASSERT (Table);
ASSERT (NumberOfTableEntries);
ASSERT (Rsdt || Xsdt);
//
// Find the table entry in the RSDT and XSDT
//
for (Index = 0; Index < *NumberOfTableEntries; Index++) {
//
// At this time, it is assumed that RSDT and XSDT maintain parallel lists of tables.
// If it becomes necessary to maintain separate table lists, changes will be required.
//
if (Rsdt != NULL) {
CurrentRsdtEntry = (UINT32 *)((UINT8 *)Rsdt + sizeof (EFI_ACPI_DESCRIPTION_HEADER) + Index * sizeof (UINT32));
} else {
CurrentRsdtEntry = NULL;
}
if (Xsdt != NULL) {
//
// This pointer must not be directly dereferenced as the XSDT entries may not
// be 64 bit aligned resulting in a possible fault. Use CopyMem to update.
//
CurrentXsdtEntry = (VOID *)((UINT8 *)Xsdt + sizeof (EFI_ACPI_DESCRIPTION_HEADER) + Index * sizeof (UINT64));
//
// Read the entry value out of the XSDT
//
CopyMem (&CurrentTablePointer64, CurrentXsdtEntry, sizeof (UINT64));
} else {
//
// Initialize to NULL
//
CurrentXsdtEntry = 0;
CurrentTablePointer64 = 0;
}
//
// Check if we have found the corresponding entry in both RSDT and XSDT
//
if (((Rsdt == NULL) || (*CurrentRsdtEntry == (UINT32)(UINTN)Table->Table)) &&
((Xsdt == NULL) || (CurrentTablePointer64 == (UINT64)(UINTN)Table->Table))
)
{
//
// Found entry, so copy all following entries and shrink table
//
if (Rsdt != NULL) {
CopyMem (CurrentRsdtEntry, CurrentRsdtEntry + 1, (*NumberOfTableEntries - Index - 1) * sizeof (UINT32));
ZeroMem ((UINT8 *)Rsdt + sizeof (EFI_ACPI_DESCRIPTION_HEADER) + ((*NumberOfTableEntries - 1) * sizeof (UINT32)), sizeof (UINT32));
Rsdt->Length = Rsdt->Length - sizeof (UINT32);
}
if (Xsdt != NULL) {
CopyMem (CurrentXsdtEntry, ((UINT64 *)CurrentXsdtEntry) + 1, (*NumberOfTableEntries - Index - 1) * sizeof (UINT64));
ZeroMem ((UINT8 *)Xsdt + sizeof (EFI_ACPI_DESCRIPTION_HEADER) + ((*NumberOfTableEntries - 1) * sizeof (UINT64)), sizeof (UINT64));
Xsdt->Length = Xsdt->Length - sizeof (UINT64);
}
break;
} else if (Index + 1 == *NumberOfTableEntries) {
//
// At the last entry, and table not found
//
return EFI_INVALID_PARAMETER;
}
}
//
// Checksum the tables
//
if (Rsdt != NULL) {
AcpiPlatformChecksum (
Rsdt,
Rsdt->Length,
OFFSET_OF (
EFI_ACPI_DESCRIPTION_HEADER,
Checksum
)
);
}
if (Xsdt != NULL) {
AcpiPlatformChecksum (
Xsdt,
Xsdt->Length,
OFFSET_OF (
EFI_ACPI_DESCRIPTION_HEADER,
Checksum
)
);
}
//
// Decrement the number of tables
//
(*NumberOfTableEntries)--;
return EFI_SUCCESS;
}
/**
This function removes a table and frees any associated memory.
@param AcpiTableInstance Instance of the protocol.
@param Version Version(s) to delete.
@param Table Pointer to table found.
@return EFI_SUCCESS The function completed successfully.
**/
EFI_STATUS
DeleteTable (
IN EFI_ACPI_TABLE_INSTANCE *AcpiTableInstance,
IN EFI_ACPI_TABLE_VERSION Version,
IN OUT EFI_ACPI_TABLE_LIST *Table
)
{
UINT32 CurrentTableSignature;
BOOLEAN RemoveFromRsdt;
//
// Check for invalid input parameters
//
ASSERT (AcpiTableInstance);
ASSERT (Table);
//
// Init locals
//
RemoveFromRsdt = TRUE;
//
// Check for Table->Table
//
ASSERT (Table->Table != NULL);
CurrentTableSignature = ((EFI_ACPI_COMMON_HEADER *)Table->Table)->Signature;
//
// Basic tasks to accomplish delete are:
// Determine removal requirements (in RSDT/XSDT or not)
// Remove entry from RSDT/XSDT
// Remove any table references to the table
// If no one is using the table
// Free the table (removing pointers from private data and tables)
// Remove from list
// Free list structure
//
//
// Determine if this table is in the RSDT or XSDT
//
if ((CurrentTableSignature == EFI_ACPI_1_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE) ||
(CurrentTableSignature == EFI_ACPI_2_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE) ||
(CurrentTableSignature == EFI_ACPI_3_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE)
)
{
RemoveFromRsdt = FALSE;
}
//
// We don't remove the FADT in the standard way because some
// OS expect the FADT to be early in the table list.
// So we always put it as the first element in the list.
//
if (CurrentTableSignature == EFI_ACPI_1_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE) {
RemoveFromRsdt = FALSE;
}
//
// Remove the table from RSDT and XSDT
//
if (Table->Table != NULL) {
//
// This is a basic table, remove it from any lists and the Rsdt and/or Xsdt
//
if (Version & EFI_ACPI_TABLE_VERSION_NONE & Table->Version) {
//
// Remove this version from the table
//
Table->Version = Table->Version &~EFI_ACPI_TABLE_VERSION_NONE;
}
if (Version & EFI_ACPI_TABLE_VERSION_1_0B & Table->Version) {
//
// Remove this version from the table
//
Table->Version = Table->Version &~EFI_ACPI_TABLE_VERSION_1_0B;
//
// Remove from Rsdt. We don't care about the return value because it is
// acceptable for the table to not exist in Rsdt.
// We didn't add some tables so we don't remove them.
//
if (RemoveFromRsdt) {
RemoveTableFromRsdt (
Table,
&AcpiTableInstance->NumberOfTableEntries1,
AcpiTableInstance->Rsdt1,
NULL
);
}
}
if (Version & ACPI_TABLE_VERSION_GTE_2_0 & Table->Version) {
//
// Remove this version from the table
//
Table->Version = Table->Version &~(Version & ACPI_TABLE_VERSION_GTE_2_0);
//
// Remove from Rsdt and Xsdt. We don't care about the return value
// because it is acceptable for the table to not exist in Rsdt/Xsdt.
// We didn't add some tables so we don't remove them.
//
if (RemoveFromRsdt) {
RemoveTableFromRsdt (
Table,
&AcpiTableInstance->NumberOfTableEntries3,
AcpiTableInstance->Rsdt3,
AcpiTableInstance->Xsdt
);
}
}
//
// Free the table, clean up any dependent tables and our private data pointers.
//
switch (Table->Table->Signature) {
case EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE:
if ((Version & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
AcpiTableInstance->Fadt1 = NULL;
}
if ((Version & ACPI_TABLE_VERSION_GTE_2_0) != 0) {
AcpiTableInstance->Fadt3 = NULL;
}
break;
case EFI_ACPI_3_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE:
if ((Version & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
AcpiTableInstance->Facs1 = NULL;
//
// Update FADT table pointers
//
if (AcpiTableInstance->Fadt1 != NULL) {
AcpiTableInstance->Fadt1->FirmwareCtrl = 0;
//
// Checksum table
//
AcpiPlatformChecksum (
AcpiTableInstance->Fadt1,
AcpiTableInstance->Fadt1->Header.Length,
OFFSET_OF (
EFI_ACPI_DESCRIPTION_HEADER,
Checksum
)
);
}
}
if ((Version & ACPI_TABLE_VERSION_GTE_2_0) != 0) {
AcpiTableInstance->Facs3 = NULL;
//
// Update FADT table pointers
//
if (AcpiTableInstance->Fadt3 != NULL) {
AcpiTableInstance->Fadt3->FirmwareCtrl = 0;
ZeroMem (&AcpiTableInstance->Fadt3->XFirmwareCtrl, sizeof (UINT64));
//
// Checksum table
//
AcpiPlatformChecksum (
AcpiTableInstance->Fadt3,
AcpiTableInstance->Fadt3->Header.Length,
OFFSET_OF (
EFI_ACPI_DESCRIPTION_HEADER,
Checksum
)
);
}
}
break;
case EFI_ACPI_3_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE:
if ((Version & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
AcpiTableInstance->Dsdt1 = NULL;
//
// Update FADT table pointers
//
if (AcpiTableInstance->Fadt1 != NULL) {
AcpiTableInstance->Fadt1->Dsdt = 0;
//
// Checksum table
//
AcpiPlatformChecksum (
AcpiTableInstance->Fadt1,
AcpiTableInstance->Fadt1->Header.Length,
OFFSET_OF (
EFI_ACPI_DESCRIPTION_HEADER,
Checksum
)
);
}
}
if ((Version & ACPI_TABLE_VERSION_GTE_2_0) != 0) {
AcpiTableInstance->Dsdt3 = NULL;
//
// Update FADT table pointers
//
if (AcpiTableInstance->Fadt3 != NULL) {
AcpiTableInstance->Fadt3->Dsdt = 0;
ZeroMem (&AcpiTableInstance->Fadt3->XDsdt, sizeof (UINT64));
//
// Checksum table
//
AcpiPlatformChecksum (
AcpiTableInstance->Fadt3,
AcpiTableInstance->Fadt3->Header.Length,
OFFSET_OF (
EFI_ACPI_DESCRIPTION_HEADER,
Checksum
)
);
}
}
break;
default:
//
// Do nothing
//
break;
}
}
//
// If no version is using this table anymore, remove and free list entry.
//
if (Table->Version == 0) {
//
// Free the Table
//
FreeTableMemory (Table);
RemoveEntryList (&(Table->Link));
gBS->FreePool (Table);
}
//
// Done
//
return EFI_SUCCESS;
}
/**
This function finds and removes the table specified by the handle.
@param AcpiTableInstance Instance of the protocol.
@param Version Bitmask of which versions to remove.
@param Handle Table to remove.
@return EFI_SUCCESS The function completed successfully.
@return EFI_ABORTED An error occurred.
@return EFI_NOT_FOUND Handle not found in table list.
**/
EFI_STATUS
RemoveTableFromList (
IN EFI_ACPI_TABLE_INSTANCE *AcpiTableInstance,
IN EFI_ACPI_TABLE_VERSION Version,
IN UINTN Handle
)
{
EFI_ACPI_TABLE_LIST *Table;
EFI_STATUS Status;
Table = (EFI_ACPI_TABLE_LIST *)NULL;
//
// Check for invalid input parameters
//
ASSERT (AcpiTableInstance);
//
// Find the table
//
Status = FindTableByHandle (
Handle,
&AcpiTableInstance->TableList,
&Table
);
if (EFI_ERROR (Status)) {
return EFI_NOT_FOUND;
}
//
// Remove the table
//
Status = DeleteTable (AcpiTableInstance, Version, Table);
if (EFI_ERROR (Status)) {
return EFI_ABORTED;
}
//
// Completed successfully
//
return EFI_SUCCESS;
}
/**
This function calculates and updates an UINT8 checksum.
@param Buffer Pointer to buffer to checksum
@param Size Number of bytes to checksum
@param ChecksumOffset Offset to place the checksum result in
@return EFI_SUCCESS The function completed successfully.
**/
EFI_STATUS
AcpiPlatformChecksum (
IN VOID *Buffer,
IN UINTN Size,
IN UINTN ChecksumOffset
)
{
UINT8 Sum;
UINT8 *Ptr;
Sum = 0;
//
// Initialize pointer
//
Ptr = Buffer;
//
// set checksum to 0 first
//
Ptr[ChecksumOffset] = 0;
//
// add all content of buffer
//
while ((Size--) != 0) {
Sum = (UINT8)(Sum + (*Ptr++));
}
//
// set checksum
//
Ptr = Buffer;
Ptr[ChecksumOffset] = (UINT8)(0xff - Sum + 1);
return EFI_SUCCESS;
}
/**
Checksum all versions of the common tables, RSDP, RSDT, XSDT.
@param AcpiTableInstance Protocol instance private data.
@return EFI_SUCCESS The function completed successfully.
**/
EFI_STATUS
ChecksumCommonTables (
IN OUT EFI_ACPI_TABLE_INSTANCE *AcpiTableInstance
)
{
//
// RSDP ACPI 1.0 checksum for 1.0 table. This is only the first 20 bytes of the structure
//
if ((PcdGet32 (PcdAcpiExposedTableVersions) & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
AcpiPlatformChecksum (
AcpiTableInstance->Rsdp1,
sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER),
OFFSET_OF (
EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER,
Checksum
)
);
}
//
// RSDP ACPI 1.0 checksum for 2.0/3.0 table. This is only the first 20 bytes of the structure
//
AcpiPlatformChecksum (
AcpiTableInstance->Rsdp3,
sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER),
OFFSET_OF (
EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER,
Checksum
)
);
//
// RSDP ACPI 2.0/3.0 checksum, this is the entire table
//
AcpiPlatformChecksum (
AcpiTableInstance->Rsdp3,
sizeof (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER),
OFFSET_OF (
EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER,
ExtendedChecksum
)
);
if ((PcdGet32 (PcdAcpiExposedTableVersions) & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
//
// RSDT checksums
//
AcpiPlatformChecksum (
AcpiTableInstance->Rsdt1,
AcpiTableInstance->Rsdt1->Length,
OFFSET_OF (
EFI_ACPI_DESCRIPTION_HEADER,
Checksum
)
);
AcpiPlatformChecksum (
AcpiTableInstance->Rsdt3,
AcpiTableInstance->Rsdt3->Length,
OFFSET_OF (
EFI_ACPI_DESCRIPTION_HEADER,
Checksum
)
);
}
//
// XSDT checksum
//
AcpiPlatformChecksum (
AcpiTableInstance->Xsdt,
AcpiTableInstance->Xsdt->Length,
OFFSET_OF (
EFI_ACPI_DESCRIPTION_HEADER,
Checksum
)
);
return EFI_SUCCESS;
}
/**
This function will find gUniversalPayloadAcpiTableGuid Guid Hob, and install Acpi table from it.
@param AcpiTableInstance Protocol instance private data.
@return EFI_SUCCESS The function completed successfully.
@return EFI_NOT_FOUND The function doesn't find the gEfiAcpiTableGuid Guid Hob.
@return EFI_ABORTED The function could not complete successfully.
**/
EFI_STATUS
InstallAcpiTableFromHob (
EFI_ACPI_TABLE_INSTANCE *AcpiTableInstance
)
{
EFI_HOB_GUID_TYPE *GuidHob;
EFI_ACPI_TABLE_VERSION Version;
EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER *Rsdp;
EFI_ACPI_DESCRIPTION_HEADER *Rsdt;
EFI_ACPI_DESCRIPTION_HEADER *ChildTable;
UINT64 ChildTableAddress;
UINTN Count;
UINTN Index;
UINTN TableKey;
EFI_STATUS Status;
UINTN EntrySize;
UNIVERSAL_PAYLOAD_ACPI_TABLE *AcpiTableAdress;
VOID *TableToInstall;
EFI_ACPI_SDT_HEADER *Table;
UNIVERSAL_PAYLOAD_GENERIC_HEADER *GenericHeader;
TableKey = 0;
Version = PcdGet32 (PcdAcpiExposedTableVersions);
Status = EFI_SUCCESS;
//
// HOB only contains the ACPI table in 2.0+ format.
//
GuidHob = GetFirstGuidHob (&gUniversalPayloadAcpiTableGuid);
if (GuidHob == NULL) {
return EFI_NOT_FOUND;
}
GenericHeader = (UNIVERSAL_PAYLOAD_GENERIC_HEADER *)GET_GUID_HOB_DATA (GuidHob);
if ((sizeof (UNIVERSAL_PAYLOAD_GENERIC_HEADER) > GET_GUID_HOB_DATA_SIZE (GuidHob)) || (GenericHeader->Length > GET_GUID_HOB_DATA_SIZE (GuidHob))) {
return EFI_NOT_FOUND;
}
if (GenericHeader->Revision == UNIVERSAL_PAYLOAD_ACPI_TABLE_REVISION) {
//
// UNIVERSAL_PAYLOAD_ACPI_TABLE structure is used when Revision equals to UNIVERSAL_PAYLOAD_ACPI_TABLE_REVISION
//
AcpiTableAdress = (UNIVERSAL_PAYLOAD_ACPI_TABLE *)GET_GUID_HOB_DATA (GuidHob);
if (AcpiTableAdress->Header.Length < UNIVERSAL_PAYLOAD_SIZEOF_THROUGH_FIELD (UNIVERSAL_PAYLOAD_ACPI_TABLE, Rsdp)) {
//
// Retrun if can't find the ACPI Info Hob with enough length
//
return EFI_NOT_FOUND;
}
Rsdp = (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER *)(UINTN)(AcpiTableAdress->Rsdp);
//
// An ACPI-compatible OS must use the XSDT if present.
// It shouldn't happen that XsdtAddress points beyond 4G range in 32-bit environment.
//
ASSERT ((UINTN)Rsdp->XsdtAddress == Rsdp->XsdtAddress);
EntrySize = sizeof (UINT64);
Rsdt = (EFI_ACPI_DESCRIPTION_HEADER *)(UINTN)Rsdp->XsdtAddress;
if (Rsdt == NULL) {
//
// XsdtAddress is zero, then we use Rsdt which has 32 bit entry
//
Rsdt = (EFI_ACPI_DESCRIPTION_HEADER *)(UINTN)Rsdp->RsdtAddress;
EntrySize = sizeof (UINT32);
}
if (Rsdt->Length <= sizeof (EFI_ACPI_DESCRIPTION_HEADER)) {
return EFI_ABORTED;
}
Count = (Rsdt->Length - sizeof (EFI_ACPI_DESCRIPTION_HEADER)) / EntrySize;
for (Index = 0; Index < Count; Index++) {
ChildTableAddress = 0;
CopyMem (&ChildTableAddress, (UINT8 *)(Rsdt + 1) + EntrySize * Index, EntrySize);
//
// If the address is of UINT64 while this module runs at 32 bits,
// make sure the upper bits are all-zeros.
//
ASSERT (ChildTableAddress == (UINTN)ChildTableAddress);
if (ChildTableAddress != (UINTN)ChildTableAddress) {
Status = EFI_ABORTED;
break;
}
ChildTable = (EFI_ACPI_DESCRIPTION_HEADER *)(UINTN)ChildTableAddress;
Status = AddTableToList (AcpiTableInstance, ChildTable, TRUE, Version, TRUE, &TableKey);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "InstallAcpiTableFromHob: Fail to add ACPI table at 0x%p\n", ChildTable));
ASSERT_EFI_ERROR (Status);
break;
}
if (ChildTable->Signature == EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE) {
//
// Add the FACS and DSDT tables if it is not NULL.
//
if (((EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE *)ChildTable)->FirmwareCtrl != 0) {
TableToInstall = (VOID *)(UINTN)((EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE *)ChildTable)->FirmwareCtrl;
Status = AddTableToList (AcpiTableInstance, TableToInstall, TRUE, Version, TRUE, &TableKey);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "InstallAcpiTableFromHob: Fail to add ACPI table FACS\n"));
ASSERT_EFI_ERROR (Status);
break;
}
}
//
// First check if xDSDT is available, as that is preferred as per
// ACPI Spec 6.5+ Table 5-9 X_DSDT definition
//
if (((EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE *)ChildTable)->XDsdt != 0) {
TableToInstall = (VOID *)(UINTN)((EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE *)ChildTable)->XDsdt;
} else if (((EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE *)ChildTable)->Dsdt != 0) {
TableToInstall = (VOID *)(UINTN)((EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE *)ChildTable)->Dsdt;
} else {
DEBUG ((DEBUG_ERROR, "DSDT table not found\n"));
continue;
}
Status = AddTableToList (AcpiTableInstance, TableToInstall, TRUE, Version, TRUE, &TableKey);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "InstallAcpiTableFromHob: Fail to add ACPI table DSDT\n"));
ASSERT_EFI_ERROR (Status);
break;
}
}
}
} else {
return EFI_NOT_FOUND;
}
if (EFI_ERROR (Status)) {
//
// Error happens when trying to add ACPI table to the list.
// Remove all of them from list because at this time, no other tables except from HOB are in the list
//
while (SdtGetAcpiTable (AcpiTableInstance, 0, &Table, &Version, &TableKey) == EFI_SUCCESS) {
RemoveTableFromList (AcpiTableInstance, Version, TableKey);
}
} else {
Status = PublishTables (AcpiTableInstance, Version);
}
ASSERT_EFI_ERROR (Status);
return Status;
}
/**
This function is updating the instance with RSDP and RSDT, these are steps in the constructor that will be skipped if this HOB is available.
@param AcpiTableInstance Protocol instance private data.
@param GuidHob GUID HOB header.
@return EFI_SUCCESS The function completed successfully.
@return EFI_NOT_FOUND The function doesn't find the Rsdp from AcpiSiliconHob.
@return EFI_ABORTED The function could not complete successfully.
**/
EFI_STATUS
InstallAcpiTableFromAcpiSiliconHob (
IN OUT EFI_ACPI_TABLE_INSTANCE *AcpiTableInstance,
IN EFI_HOB_GUID_TYPE *GuidHob
)
{
ACPI_SILICON_HOB *AcpiSiliconHob;
EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER *SiAcpiHobRsdp;
EFI_ACPI_DESCRIPTION_HEADER *SiCommonAcpiTable;
EFI_STATUS Status;
UINTN NumOfTblEntries;
EFI_ACPI_TABLE_VERSION Version;
UINT64 SocTablePtr;
EFI_ACPI_DESCRIPTION_HEADER *SocEntryTable;
UINTN Index;
UINTN TableKey;
VOID *NeedToInstallTable;
UINT8 *Buffer;
EFI_PHYSICAL_ADDRESS PageAddress;
UINTN TotalSocTablesize;
UINT8 *Pointer;
EFI_MEMORY_TYPE AcpiAllocateMemoryType;
DEBUG ((DEBUG_INFO, "InstallAcpiTableFromAcpiSiliconHob - Start\n"));
//
// Initial variable.
//
SiAcpiHobRsdp = NULL;
SiCommonAcpiTable = NULL;
AcpiSiliconHob = GET_GUID_HOB_DATA (GuidHob);
Status = EFI_SUCCESS;
Version = PcdGet32 (PcdAcpiExposedTableVersions);
TableKey = 0;
if (PcdGetBool (PcdNoACPIReclaimMemory)) {
AcpiAllocateMemoryType = EfiACPIMemoryNVS;
} else {
AcpiAllocateMemoryType = EfiACPIReclaimMemory;
}
//
// Got RSDP table from ACPI Silicon Hob.
//
SiAcpiHobRsdp = (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER *)(UINTN)(AcpiSiliconHob->Rsdp);
if (SiAcpiHobRsdp == NULL) {
DEBUG ((DEBUG_ERROR, "InstallAcpiTableFromAcpiSiliconHob: Fail to locate RSDP Acpi table!!\n"));
return EFI_NOT_FOUND;
}
DEBUG ((DEBUG_INFO, "Silicon ACPI RSDP address : 0x%016lx\n", SiAcpiHobRsdp));
AcpiTableInstance->Rsdp3 = SiAcpiHobRsdp;
//
// Got XSDT address from RSDP table.
//
Buffer = (UINT8 *)(UINTN)(SiAcpiHobRsdp->XsdtAddress);
SiCommonAcpiTable = (EFI_ACPI_DESCRIPTION_HEADER *)Buffer;
DEBUG ((DEBUG_INFO, "Silicon ACPI XSDT address : 0x%016lx\n", SiCommonAcpiTable));
if (SiCommonAcpiTable->Length <= sizeof (EFI_ACPI_DESCRIPTION_HEADER)) {
DEBUG ((DEBUG_ERROR, "XSDT length is incorrect\n"));
return EFI_ABORTED;
}
//
// Calcaue 64bit Acpi table number.
//
NumOfTblEntries = (SiCommonAcpiTable->Length - sizeof (EFI_ACPI_DESCRIPTION_HEADER)) / sizeof (UINT64);
DEBUG ((DEBUG_INFO, "64bit NumOfTblEntries : 0x%x\n", NumOfTblEntries));
//
// Reserved the ACPI reclaim memory for XSDT.
//
TotalSocTablesize = sizeof (EFI_ACPI_DESCRIPTION_HEADER) + (mEfiAcpiMaxNumTables * sizeof (UINT64));
if (mAcpiTableAllocType != AllocateAnyPages) {
//
// Allocate memory in the lower 32 bit of address range for
// compatibility with ACPI 1.0 OS.
//
// This is done because ACPI 1.0 pointers are 32 bit values.
// ACPI 2.0 OS and all 64 bit OS must use the 64 bit ACPI table addresses.
// There is no architectural reason these should be below 4GB, it is purely
// for convenience of implementation that we force memory below 4GB.
//
PageAddress = 0xFFFFFFFF;
Status = gBS->AllocatePages (
mAcpiTableAllocType,
AcpiAllocateMemoryType,
EFI_SIZE_TO_PAGES (TotalSocTablesize),
&PageAddress
);
} else {
Status = gBS->AllocatePool (
AcpiAllocateMemoryType,
TotalSocTablesize,
(VOID **)&Pointer
);
}
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "Fail to allocate EfiACPIReclaimMemory for XSDT. Status : %r\n", Status));
return EFI_OUT_OF_RESOURCES;
}
if (mAcpiTableAllocType != AllocateAnyPages) {
Pointer = (UINT8 *)(UINTN)PageAddress;
}
ZeroMem (Pointer, TotalSocTablesize);
AcpiTableInstance->Xsdt = (EFI_ACPI_DESCRIPTION_HEADER *)(UINTN)Pointer;
//
// Initial XSDT table content.
//
AcpiTableInstance->Xsdt->Signature = SiCommonAcpiTable->Signature;
//
// Always reserve first one for FADT table.
//
AcpiTableInstance->Xsdt->Length = sizeof (EFI_ACPI_DESCRIPTION_HEADER) + sizeof (UINT64);
AcpiTableInstance->Xsdt->Revision = SiCommonAcpiTable->Revision;
CopyMem (
&AcpiTableInstance->Xsdt->OemId,
SiCommonAcpiTable->OemId,
sizeof (AcpiTableInstance->Xsdt->OemId)
);
CopyMem (
&AcpiTableInstance->Xsdt->OemTableId,
&SiCommonAcpiTable->OemTableId,
sizeof (UINT64)
);
AcpiTableInstance->Xsdt->OemRevision = SiCommonAcpiTable->OemRevision;
AcpiTableInstance->Xsdt->CreatorId = SiCommonAcpiTable->CreatorId;
AcpiTableInstance->Xsdt->CreatorRevision = SiCommonAcpiTable->CreatorRevision;
AcpiTableInstance->NumberOfTableEntries3 = 1;
//
// Extract ACPI table from AcpiSiliconHob XSDT.
//
for (Index = 0; Index < NumOfTblEntries; Index++) {
CopyMem (&SocTablePtr, (((UINT8 *)(SiCommonAcpiTable + 1)) + ((sizeof (UINT64)) * Index)), sizeof (UINT64));
SocEntryTable = (EFI_ACPI_DESCRIPTION_HEADER *)(UINTN)SocTablePtr;
//
// Display table information.
//
DEBUG ((DEBUG_INFO, "[%x] Table address : 0x%016lx\n", Index, SocTablePtr));
Buffer = (UINT8 *)&SocEntryTable->Signature;
DEBUG ((DEBUG_INFO, "Table signature = %c%c%c%c\n", Buffer[0], Buffer[1], Buffer[2], Buffer[3]));
DEBUG ((DEBUG_INFO, "Table Length : 0x%x\n", SocEntryTable->Length));
Buffer = (UINT8 *)&SocEntryTable->OemId;
DEBUG (
(DEBUG_INFO, "Table OemId = %c%c%c%c%c%c\n",
Buffer[0],
Buffer[1],
Buffer[2],
Buffer[3],
Buffer[4],
Buffer[5]
)
);
Buffer = (UINT8 *)&SocEntryTable->OemTableId;
DEBUG (
(DEBUG_INFO, "Table OemTableId = %c%c%c%c%c%c%c%c\n",
Buffer[0],
Buffer[1],
Buffer[2],
Buffer[3],
Buffer[4],
Buffer[5],
Buffer[6],
Buffer[7]
)
);
DEBUG ((DEBUG_INFO, "\n"));
//
// Add ACPI table in the DXE AcpiTableInstance.
//
Status = AddTableToList (AcpiTableInstance, SocEntryTable, TRUE, Version, TRUE, &TableKey);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "InstallAcpiTableFromAcpiSiliconHob: Fail to add ACPI table at 0x%p\n", SocEntryTable));
ASSERT_EFI_ERROR (Status);
break;
} else {
Status = PublishTables (AcpiTableInstance, Version);
if (!EFI_ERROR (Status)) {
//
// Add a new table successfully, notify registed callback
//
if (FeaturePcdGet (PcdInstallAcpiSdtProtocol)) {
SdtNotifyAcpiList (AcpiTableInstance, Version, TableKey);
}
}
}
if (SocEntryTable->Signature == EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE) {
//
// According ACPI spec, if XDsdt field contains a nonzero value which can be used by the OSPM, then the Dsdt field must be ignored by the OSPM.
//
if (((EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE *)SocEntryTable)->XDsdt != 0) {
NeedToInstallTable = (VOID *)(UINTN)((EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE *)SocEntryTable)->XDsdt;
} else if (((EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE *)SocEntryTable)->Dsdt != 0) {
NeedToInstallTable = (VOID *)(UINTN)((EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE *)SocEntryTable)->Dsdt;
}
//
// if signature can not be found from the XDsdt / Dsdt field then skip it.
//
if (((EFI_ACPI_DESCRIPTION_HEADER *)NeedToInstallTable)->Signature == EFI_ACPI_3_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE) {
Status = AddTableToList (AcpiTableInstance, NeedToInstallTable, TRUE, Version, TRUE, &TableKey);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "Fail to add DSDT in the DXE Table list!\n"));
ASSERT_EFI_ERROR (Status);
break;
} else {
Status = PublishTables (AcpiTableInstance, Version);
if (!EFI_ERROR (Status)) {
//
// Add a new table successfully, notify registed callback
//
if (FeaturePcdGet (PcdInstallAcpiSdtProtocol)) {
SdtNotifyAcpiList (AcpiTableInstance, Version, TableKey);
}
}
DEBUG ((DEBUG_INFO, "Installed DSDT in the DXE Table list!\n"));
}
} else {
DEBUG ((DEBUG_ERROR, "The DSDT content is not correct, then skip it!\n"));
}
//
// According ACPI spec, if XFirmwareCtrl field contains a nonzero value which can be used by the OSPM, then the FirmwareCtrl field must be ignored by the OSPM.
//
if (((EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE *)SocEntryTable)->XFirmwareCtrl != 0) {
NeedToInstallTable = (VOID *)(UINTN)((EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE *)SocEntryTable)->XFirmwareCtrl;
} else if (((EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE *)SocEntryTable)->FirmwareCtrl != 0) {
NeedToInstallTable = (VOID *)(UINTN)((EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE *)SocEntryTable)->FirmwareCtrl;
}
if (((EFI_ACPI_DESCRIPTION_HEADER *)NeedToInstallTable)->Signature == EFI_ACPI_3_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE) {
Status = AddTableToList (AcpiTableInstance, NeedToInstallTable, TRUE, Version, TRUE, &TableKey);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "Fail to add FACS in the DXE Table list!\n"));
ASSERT_EFI_ERROR (Status);
break;
} else {
Status = PublishTables (AcpiTableInstance, Version);
if (!EFI_ERROR (Status)) {
//
// Add a new table successfully, notify registed callback
//
if (FeaturePcdGet (PcdInstallAcpiSdtProtocol)) {
SdtNotifyAcpiList (AcpiTableInstance, Version, TableKey);
}
}
DEBUG ((DEBUG_INFO, "Installed FACS in the DXE Table list!\n"));
}
} else {
DEBUG ((DEBUG_ERROR, "The FACS content is not correct, then skip it!\n"));
}
}
}
DEBUG ((DEBUG_INFO, "InstallAcpiTableFromAcpiSiliconHob - End\n"));
return Status;
}
/**
Constructor for the ACPI table protocol. Initializes instance
data.
@param AcpiTableInstance Instance to construct
@return EFI_SUCCESS Instance initialized.
@return EFI_OUT_OF_RESOURCES Unable to allocate required resources.
**/
EFI_STATUS
AcpiTableAcpiTableConstructor (
EFI_ACPI_TABLE_INSTANCE *AcpiTableInstance
)
{
EFI_STATUS Status;
UINT64 CurrentData;
UINTN TotalSize;
UINTN RsdpTableSize;
UINT8 *Pointer;
EFI_PHYSICAL_ADDRESS PageAddress;
EFI_MEMORY_TYPE AcpiAllocateMemoryType;
EFI_HOB_GUID_TYPE *GuidHob;
//
// Check for invalid input parameters
//
ASSERT (AcpiTableInstance);
//
// If ACPI v1.0b is among the ACPI versions we aim to support, we have to
// ensure that all memory allocations are below 4 GB.
//
if ((PcdGet32 (PcdAcpiExposedTableVersions) & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
mAcpiTableAllocType = AllocateMaxAddress;
} else {
mAcpiTableAllocType = AllocateAnyPages;
}
InitializeListHead (&AcpiTableInstance->TableList);
AcpiTableInstance->CurrentHandle = 1;
AcpiTableInstance->AcpiTableProtocol.InstallAcpiTable = InstallAcpiTable;
AcpiTableInstance->AcpiTableProtocol.UninstallAcpiTable = UninstallAcpiTable;
if (FeaturePcdGet (PcdInstallAcpiSdtProtocol)) {
SdtAcpiTableAcpiSdtConstructor (AcpiTableInstance);
}
//
// Check Silicon ACPI Hob.
//
GuidHob = GetFirstGuidHob (&gAcpiTableHobGuid);
if (GuidHob != NULL) {
Status = InstallAcpiTableFromAcpiSiliconHob (AcpiTableInstance, GuidHob);
if (Status == EFI_SUCCESS) {
DEBUG ((DEBUG_INFO, "Installed ACPI Table from AcpiSiliconHob.\n"));
return EFI_SUCCESS;
} else {
DEBUG ((DEBUG_ERROR, "Fail to Installed ACPI Table from AcpiSiliconHob!!\n"));
ASSERT (Status != EFI_SUCCESS);
}
} else {
DEBUG ((DEBUG_INFO, "Fail to locate AcpiSiliconHob!!\n"));
}
//
// Create RSDP table
//
RsdpTableSize = sizeof (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER);
if ((PcdGet32 (PcdAcpiExposedTableVersions) & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
RsdpTableSize += sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER);
}
if (PcdGetBool (PcdNoACPIReclaimMemory)) {
AcpiAllocateMemoryType = EfiACPIMemoryNVS;
} else {
AcpiAllocateMemoryType = EfiACPIReclaimMemory;
}
if (mAcpiTableAllocType != AllocateAnyPages) {
PageAddress = 0xFFFFFFFF;
Status = gBS->AllocatePages (
mAcpiTableAllocType,
AcpiAllocateMemoryType,
EFI_SIZE_TO_PAGES (RsdpTableSize),
&PageAddress
);
} else {
Status = gBS->AllocatePool (
AcpiAllocateMemoryType,
RsdpTableSize,
(VOID **)&Pointer
);
}
if (EFI_ERROR (Status)) {
return EFI_OUT_OF_RESOURCES;
}
if (mAcpiTableAllocType != AllocateAnyPages) {
Pointer = (UINT8 *)(UINTN)PageAddress;
}
ZeroMem (Pointer, RsdpTableSize);
AcpiTableInstance->Rsdp1 = (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER *)Pointer;
if ((PcdGet32 (PcdAcpiExposedTableVersions) & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
Pointer += sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER);
}
AcpiTableInstance->Rsdp3 = (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER *)Pointer;
//
// Create RSDT, XSDT structures
//
TotalSize = sizeof (EFI_ACPI_DESCRIPTION_HEADER) + // for ACPI 2.0/3.0 XSDT
mEfiAcpiMaxNumTables * sizeof (UINT64);
if ((PcdGet32 (PcdAcpiExposedTableVersions) & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
TotalSize += sizeof (EFI_ACPI_DESCRIPTION_HEADER) + // for ACPI 1.0 RSDT
mEfiAcpiMaxNumTables * sizeof (UINT32) +
sizeof (EFI_ACPI_DESCRIPTION_HEADER) + // for ACPI 2.0/3.0 RSDT
mEfiAcpiMaxNumTables * sizeof (UINT32);
}
if (mAcpiTableAllocType != AllocateAnyPages) {
//
// Allocate memory in the lower 32 bit of address range for
// compatibility with ACPI 1.0 OS.
//
// This is done because ACPI 1.0 pointers are 32 bit values.
// ACPI 2.0 OS and all 64 bit OS must use the 64 bit ACPI table addresses.
// There is no architectural reason these should be below 4GB, it is purely
// for convenience of implementation that we force memory below 4GB.
//
PageAddress = 0xFFFFFFFF;
Status = gBS->AllocatePages (
mAcpiTableAllocType,
AcpiAllocateMemoryType,
EFI_SIZE_TO_PAGES (TotalSize),
&PageAddress
);
} else {
Status = gBS->AllocatePool (
AcpiAllocateMemoryType,
TotalSize,
(VOID **)&Pointer
);
}
if (EFI_ERROR (Status)) {
if (mAcpiTableAllocType != AllocateAnyPages) {
gBS->FreePages (
(EFI_PHYSICAL_ADDRESS)(UINTN)AcpiTableInstance->Rsdp1,
EFI_SIZE_TO_PAGES (RsdpTableSize)
);
} else {
gBS->FreePool (AcpiTableInstance->Rsdp1);
}
return EFI_OUT_OF_RESOURCES;
}
if (mAcpiTableAllocType != AllocateAnyPages) {
Pointer = (UINT8 *)(UINTN)PageAddress;
}
ZeroMem (Pointer, TotalSize);
AcpiTableInstance->Rsdt1 = (EFI_ACPI_DESCRIPTION_HEADER *)Pointer;
if ((PcdGet32 (PcdAcpiExposedTableVersions) & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
Pointer += (sizeof (EFI_ACPI_DESCRIPTION_HEADER) + EFI_ACPI_MAX_NUM_TABLES * sizeof (UINT32));
AcpiTableInstance->Rsdt3 = (EFI_ACPI_DESCRIPTION_HEADER *)Pointer;
Pointer += (sizeof (EFI_ACPI_DESCRIPTION_HEADER) + EFI_ACPI_MAX_NUM_TABLES * sizeof (UINT32));
}
AcpiTableInstance->Xsdt = (EFI_ACPI_DESCRIPTION_HEADER *)Pointer;
//
// Initialize RSDP
//
if ((PcdGet32 (PcdAcpiExposedTableVersions) & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
CurrentData = EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER_SIGNATURE;
CopyMem (&AcpiTableInstance->Rsdp1->Signature, &CurrentData, sizeof (UINT64));
CopyMem (AcpiTableInstance->Rsdp1->OemId, PcdGetPtr (PcdAcpiDefaultOemId), sizeof (AcpiTableInstance->Rsdp1->OemId));
AcpiTableInstance->Rsdp1->Reserved = EFI_ACPI_RESERVED_BYTE;
AcpiTableInstance->Rsdp1->RsdtAddress = (UINT32)(UINTN)AcpiTableInstance->Rsdt1;
}
CurrentData = EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER_SIGNATURE;
CopyMem (&AcpiTableInstance->Rsdp3->Signature, &CurrentData, sizeof (UINT64));
CopyMem (AcpiTableInstance->Rsdp3->OemId, PcdGetPtr (PcdAcpiDefaultOemId), sizeof (AcpiTableInstance->Rsdp3->OemId));
AcpiTableInstance->Rsdp3->Revision = EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER_REVISION;
AcpiTableInstance->Rsdp3->Length = sizeof (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER);
if ((PcdGet32 (PcdAcpiExposedTableVersions) & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
AcpiTableInstance->Rsdp3->RsdtAddress = (UINT32)(UINTN)AcpiTableInstance->Rsdt3;
}
CurrentData = (UINT64)(UINTN)AcpiTableInstance->Xsdt;
CopyMem (&AcpiTableInstance->Rsdp3->XsdtAddress, &CurrentData, sizeof (UINT64));
SetMem (AcpiTableInstance->Rsdp3->Reserved, 3, EFI_ACPI_RESERVED_BYTE);
if ((PcdGet32 (PcdAcpiExposedTableVersions) & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
//
// Initialize Rsdt
//
// Note that we "reserve" one entry for the FADT so it can always be
// at the beginning of the list of tables. Some OS don't seem
// to find it correctly if it is too far down the list.
//
AcpiTableInstance->Rsdt1->Signature = EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_TABLE_SIGNATURE;
AcpiTableInstance->Rsdt1->Length = sizeof (EFI_ACPI_DESCRIPTION_HEADER);
AcpiTableInstance->Rsdt1->Revision = EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_TABLE_REVISION;
CopyMem (AcpiTableInstance->Rsdt1->OemId, PcdGetPtr (PcdAcpiDefaultOemId), sizeof (AcpiTableInstance->Rsdt1->OemId));
CurrentData = PcdGet64 (PcdAcpiDefaultOemTableId);
CopyMem (&AcpiTableInstance->Rsdt1->OemTableId, &CurrentData, sizeof (UINT64));
AcpiTableInstance->Rsdt1->OemRevision = PcdGet32 (PcdAcpiDefaultOemRevision);
AcpiTableInstance->Rsdt1->CreatorId = PcdGet32 (PcdAcpiDefaultCreatorId);
AcpiTableInstance->Rsdt1->CreatorRevision = PcdGet32 (PcdAcpiDefaultCreatorRevision);
//
// We always reserve first one for FADT
//
AcpiTableInstance->NumberOfTableEntries1 = 1;
AcpiTableInstance->Rsdt1->Length = AcpiTableInstance->Rsdt1->Length + sizeof (UINT32);
AcpiTableInstance->Rsdt3->Signature = EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_TABLE_SIGNATURE;
AcpiTableInstance->Rsdt3->Length = sizeof (EFI_ACPI_DESCRIPTION_HEADER);
AcpiTableInstance->Rsdt3->Revision = EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_TABLE_REVISION;
CopyMem (AcpiTableInstance->Rsdt3->OemId, PcdGetPtr (PcdAcpiDefaultOemId), sizeof (AcpiTableInstance->Rsdt3->OemId));
CurrentData = PcdGet64 (PcdAcpiDefaultOemTableId);
CopyMem (&AcpiTableInstance->Rsdt3->OemTableId, &CurrentData, sizeof (UINT64));
AcpiTableInstance->Rsdt3->OemRevision = PcdGet32 (PcdAcpiDefaultOemRevision);
AcpiTableInstance->Rsdt3->CreatorId = PcdGet32 (PcdAcpiDefaultCreatorId);
AcpiTableInstance->Rsdt3->CreatorRevision = PcdGet32 (PcdAcpiDefaultCreatorRevision);
//
// We always reserve first one for FADT
//
AcpiTableInstance->Rsdt3->Length = AcpiTableInstance->Rsdt3->Length + sizeof (UINT32);
}
AcpiTableInstance->NumberOfTableEntries3 = 1;
//
// Initialize Xsdt
//
AcpiTableInstance->Xsdt->Signature = EFI_ACPI_3_0_EXTENDED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE;
AcpiTableInstance->Xsdt->Length = sizeof (EFI_ACPI_DESCRIPTION_HEADER);
AcpiTableInstance->Xsdt->Revision = EFI_ACPI_3_0_EXTENDED_SYSTEM_DESCRIPTION_TABLE_REVISION;
CopyMem (AcpiTableInstance->Xsdt->OemId, PcdGetPtr (PcdAcpiDefaultOemId), sizeof (AcpiTableInstance->Xsdt->OemId));
CurrentData = PcdGet64 (PcdAcpiDefaultOemTableId);
CopyMem (&AcpiTableInstance->Xsdt->OemTableId, &CurrentData, sizeof (UINT64));
AcpiTableInstance->Xsdt->OemRevision = PcdGet32 (PcdAcpiDefaultOemRevision);
AcpiTableInstance->Xsdt->CreatorId = PcdGet32 (PcdAcpiDefaultCreatorId);
AcpiTableInstance->Xsdt->CreatorRevision = PcdGet32 (PcdAcpiDefaultCreatorRevision);
//
// We always reserve first one for FADT
//
AcpiTableInstance->Xsdt->Length = AcpiTableInstance->Xsdt->Length + sizeof (UINT64);
ChecksumCommonTables (AcpiTableInstance);
InstallAcpiTableFromHob (AcpiTableInstance);
//
// Completed successfully
//
return EFI_SUCCESS;
}
|