tbdata.c 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072
  1. // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
  2. /******************************************************************************
  3. *
  4. * Module Name: tbdata - Table manager data structure functions
  5. *
  6. * Copyright (C) 2000 - 2018, Intel Corp.
  7. *
  8. *****************************************************************************/
  9. #include <acpi/acpi.h>
  10. #include "accommon.h"
  11. #include "acnamesp.h"
  12. #include "actables.h"
  13. #include "acevents.h"
  14. #define _COMPONENT ACPI_TABLES
  15. ACPI_MODULE_NAME("tbdata")
  16. /* Local prototypes */
  17. static acpi_status
  18. acpi_tb_check_duplication(struct acpi_table_desc *table_desc, u32 *table_index);
  19. static u8
  20. acpi_tb_compare_tables(struct acpi_table_desc *table_desc, u32 table_index);
  21. /*******************************************************************************
  22. *
  23. * FUNCTION: acpi_tb_compare_tables
  24. *
  25. * PARAMETERS: table_desc - Table 1 descriptor to be compared
  26. * table_index - Index of table 2 to be compared
  27. *
  28. * RETURN: TRUE if both tables are identical.
  29. *
  30. * DESCRIPTION: This function compares a table with another table that has
  31. * already been installed in the root table list.
  32. *
  33. ******************************************************************************/
  34. static u8
  35. acpi_tb_compare_tables(struct acpi_table_desc *table_desc, u32 table_index)
  36. {
  37. acpi_status status = AE_OK;
  38. u8 is_identical;
  39. struct acpi_table_header *table;
  40. u32 table_length;
  41. u8 table_flags;
  42. status =
  43. acpi_tb_acquire_table(&acpi_gbl_root_table_list.tables[table_index],
  44. &table, &table_length, &table_flags);
  45. if (ACPI_FAILURE(status)) {
  46. return (FALSE);
  47. }
  48. /*
  49. * Check for a table match on the entire table length,
  50. * not just the header.
  51. */
  52. is_identical = (u8)((table_desc->length != table_length ||
  53. memcmp(table_desc->pointer, table, table_length)) ?
  54. FALSE : TRUE);
  55. /* Release the acquired table */
  56. acpi_tb_release_table(table, table_length, table_flags);
  57. return (is_identical);
  58. }
  59. /*******************************************************************************
  60. *
  61. * FUNCTION: acpi_tb_init_table_descriptor
  62. *
  63. * PARAMETERS: table_desc - Table descriptor
  64. * address - Physical address of the table
  65. * flags - Allocation flags of the table
  66. * table - Pointer to the table
  67. *
  68. * RETURN: None
  69. *
  70. * DESCRIPTION: Initialize a new table descriptor
  71. *
  72. ******************************************************************************/
  73. void
  74. acpi_tb_init_table_descriptor(struct acpi_table_desc *table_desc,
  75. acpi_physical_address address,
  76. u8 flags, struct acpi_table_header *table)
  77. {
  78. /*
  79. * Initialize the table descriptor. Set the pointer to NULL, since the
  80. * table is not fully mapped at this time.
  81. */
  82. memset(table_desc, 0, sizeof(struct acpi_table_desc));
  83. table_desc->address = address;
  84. table_desc->length = table->length;
  85. table_desc->flags = flags;
  86. ACPI_MOVE_32_TO_32(table_desc->signature.ascii, table->signature);
  87. }
  88. /*******************************************************************************
  89. *
  90. * FUNCTION: acpi_tb_acquire_table
  91. *
  92. * PARAMETERS: table_desc - Table descriptor
  93. * table_ptr - Where table is returned
  94. * table_length - Where table length is returned
  95. * table_flags - Where table allocation flags are returned
  96. *
  97. * RETURN: Status
  98. *
  99. * DESCRIPTION: Acquire an ACPI table. It can be used for tables not
  100. * maintained in the acpi_gbl_root_table_list.
  101. *
  102. ******************************************************************************/
  103. acpi_status
  104. acpi_tb_acquire_table(struct acpi_table_desc *table_desc,
  105. struct acpi_table_header **table_ptr,
  106. u32 *table_length, u8 *table_flags)
  107. {
  108. struct acpi_table_header *table = NULL;
  109. switch (table_desc->flags & ACPI_TABLE_ORIGIN_MASK) {
  110. case ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL:
  111. table =
  112. acpi_os_map_memory(table_desc->address, table_desc->length);
  113. break;
  114. case ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL:
  115. case ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL:
  116. table = ACPI_CAST_PTR(struct acpi_table_header,
  117. ACPI_PHYSADDR_TO_PTR(table_desc->
  118. address));
  119. break;
  120. default:
  121. break;
  122. }
  123. /* Table is not valid yet */
  124. if (!table) {
  125. return (AE_NO_MEMORY);
  126. }
  127. /* Fill the return values */
  128. *table_ptr = table;
  129. *table_length = table_desc->length;
  130. *table_flags = table_desc->flags;
  131. return (AE_OK);
  132. }
  133. /*******************************************************************************
  134. *
  135. * FUNCTION: acpi_tb_release_table
  136. *
  137. * PARAMETERS: table - Pointer for the table
  138. * table_length - Length for the table
  139. * table_flags - Allocation flags for the table
  140. *
  141. * RETURN: None
  142. *
  143. * DESCRIPTION: Release a table. The inverse of acpi_tb_acquire_table().
  144. *
  145. ******************************************************************************/
  146. void
  147. acpi_tb_release_table(struct acpi_table_header *table,
  148. u32 table_length, u8 table_flags)
  149. {
  150. switch (table_flags & ACPI_TABLE_ORIGIN_MASK) {
  151. case ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL:
  152. acpi_os_unmap_memory(table, table_length);
  153. break;
  154. case ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL:
  155. case ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL:
  156. default:
  157. break;
  158. }
  159. }
  160. /*******************************************************************************
  161. *
  162. * FUNCTION: acpi_tb_acquire_temp_table
  163. *
  164. * PARAMETERS: table_desc - Table descriptor to be acquired
  165. * address - Address of the table
  166. * flags - Allocation flags of the table
  167. *
  168. * RETURN: Status
  169. *
  170. * DESCRIPTION: This function validates the table header to obtain the length
  171. * of a table and fills the table descriptor to make its state as
  172. * "INSTALLED". Such a table descriptor is only used for verified
  173. * installation.
  174. *
  175. ******************************************************************************/
  176. acpi_status
  177. acpi_tb_acquire_temp_table(struct acpi_table_desc *table_desc,
  178. acpi_physical_address address, u8 flags)
  179. {
  180. struct acpi_table_header *table_header;
  181. switch (flags & ACPI_TABLE_ORIGIN_MASK) {
  182. case ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL:
  183. /* Get the length of the full table from the header */
  184. table_header =
  185. acpi_os_map_memory(address,
  186. sizeof(struct acpi_table_header));
  187. if (!table_header) {
  188. return (AE_NO_MEMORY);
  189. }
  190. acpi_tb_init_table_descriptor(table_desc, address, flags,
  191. table_header);
  192. acpi_os_unmap_memory(table_header,
  193. sizeof(struct acpi_table_header));
  194. return (AE_OK);
  195. case ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL:
  196. case ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL:
  197. table_header = ACPI_CAST_PTR(struct acpi_table_header,
  198. ACPI_PHYSADDR_TO_PTR(address));
  199. if (!table_header) {
  200. return (AE_NO_MEMORY);
  201. }
  202. acpi_tb_init_table_descriptor(table_desc, address, flags,
  203. table_header);
  204. return (AE_OK);
  205. default:
  206. break;
  207. }
  208. /* Table is not valid yet */
  209. return (AE_NO_MEMORY);
  210. }
  211. /*******************************************************************************
  212. *
  213. * FUNCTION: acpi_tb_release_temp_table
  214. *
  215. * PARAMETERS: table_desc - Table descriptor to be released
  216. *
  217. * RETURN: Status
  218. *
  219. * DESCRIPTION: The inverse of acpi_tb_acquire_temp_table().
  220. *
  221. *****************************************************************************/
  222. void acpi_tb_release_temp_table(struct acpi_table_desc *table_desc)
  223. {
  224. /*
  225. * Note that the .Address is maintained by the callers of
  226. * acpi_tb_acquire_temp_table(), thus do not invoke acpi_tb_uninstall_table()
  227. * where .Address will be freed.
  228. */
  229. acpi_tb_invalidate_table(table_desc);
  230. }
  231. /******************************************************************************
  232. *
  233. * FUNCTION: acpi_tb_validate_table
  234. *
  235. * PARAMETERS: table_desc - Table descriptor
  236. *
  237. * RETURN: Status
  238. *
  239. * DESCRIPTION: This function is called to validate the table, the returned
  240. * table descriptor is in "VALIDATED" state.
  241. *
  242. *****************************************************************************/
  243. acpi_status acpi_tb_validate_table(struct acpi_table_desc *table_desc)
  244. {
  245. acpi_status status = AE_OK;
  246. ACPI_FUNCTION_TRACE(tb_validate_table);
  247. /* Validate the table if necessary */
  248. if (!table_desc->pointer) {
  249. status = acpi_tb_acquire_table(table_desc, &table_desc->pointer,
  250. &table_desc->length,
  251. &table_desc->flags);
  252. if (!table_desc->pointer) {
  253. status = AE_NO_MEMORY;
  254. }
  255. }
  256. return_ACPI_STATUS(status);
  257. }
  258. /*******************************************************************************
  259. *
  260. * FUNCTION: acpi_tb_invalidate_table
  261. *
  262. * PARAMETERS: table_desc - Table descriptor
  263. *
  264. * RETURN: None
  265. *
  266. * DESCRIPTION: Invalidate one internal ACPI table, this is the inverse of
  267. * acpi_tb_validate_table().
  268. *
  269. ******************************************************************************/
  270. void acpi_tb_invalidate_table(struct acpi_table_desc *table_desc)
  271. {
  272. ACPI_FUNCTION_TRACE(tb_invalidate_table);
  273. /* Table must be validated */
  274. if (!table_desc->pointer) {
  275. return_VOID;
  276. }
  277. acpi_tb_release_table(table_desc->pointer, table_desc->length,
  278. table_desc->flags);
  279. table_desc->pointer = NULL;
  280. return_VOID;
  281. }
  282. /******************************************************************************
  283. *
  284. * FUNCTION: acpi_tb_validate_temp_table
  285. *
  286. * PARAMETERS: table_desc - Table descriptor
  287. *
  288. * RETURN: Status
  289. *
  290. * DESCRIPTION: This function is called to validate the table, the returned
  291. * table descriptor is in "VALIDATED" state.
  292. *
  293. *****************************************************************************/
  294. acpi_status acpi_tb_validate_temp_table(struct acpi_table_desc *table_desc)
  295. {
  296. if (!table_desc->pointer && !acpi_gbl_enable_table_validation) {
  297. /*
  298. * Only validates the header of the table.
  299. * Note that Length contains the size of the mapping after invoking
  300. * this work around, this value is required by
  301. * acpi_tb_release_temp_table().
  302. * We can do this because in acpi_init_table_descriptor(), the Length
  303. * field of the installed descriptor is filled with the actual
  304. * table length obtaining from the table header.
  305. */
  306. table_desc->length = sizeof(struct acpi_table_header);
  307. }
  308. return (acpi_tb_validate_table(table_desc));
  309. }
  310. /*******************************************************************************
  311. *
  312. * FUNCTION: acpi_tb_check_duplication
  313. *
  314. * PARAMETERS: table_desc - Table descriptor
  315. * table_index - Where the table index is returned
  316. *
  317. * RETURN: Status
  318. *
  319. * DESCRIPTION: Avoid installing duplicated tables. However table override and
  320. * user aided dynamic table load is allowed, thus comparing the
  321. * address of the table is not sufficient, and checking the entire
  322. * table content is required.
  323. *
  324. ******************************************************************************/
  325. static acpi_status
  326. acpi_tb_check_duplication(struct acpi_table_desc *table_desc, u32 *table_index)
  327. {
  328. u32 i;
  329. ACPI_FUNCTION_TRACE(tb_check_duplication);
  330. /* Check if table is already registered */
  331. for (i = 0; i < acpi_gbl_root_table_list.current_table_count; ++i) {
  332. /* Do not compare with unverified tables */
  333. if (!
  334. (acpi_gbl_root_table_list.tables[i].
  335. flags & ACPI_TABLE_IS_VERIFIED)) {
  336. continue;
  337. }
  338. /*
  339. * Check for a table match on the entire table length,
  340. * not just the header.
  341. */
  342. if (!acpi_tb_compare_tables(table_desc, i)) {
  343. continue;
  344. }
  345. /*
  346. * Note: the current mechanism does not unregister a table if it is
  347. * dynamically unloaded. The related namespace entries are deleted,
  348. * but the table remains in the root table list.
  349. *
  350. * The assumption here is that the number of different tables that
  351. * will be loaded is actually small, and there is minimal overhead
  352. * in just keeping the table in case it is needed again.
  353. *
  354. * If this assumption changes in the future (perhaps on large
  355. * machines with many table load/unload operations), tables will
  356. * need to be unregistered when they are unloaded, and slots in the
  357. * root table list should be reused when empty.
  358. */
  359. if (acpi_gbl_root_table_list.tables[i].flags &
  360. ACPI_TABLE_IS_LOADED) {
  361. /* Table is still loaded, this is an error */
  362. return_ACPI_STATUS(AE_ALREADY_EXISTS);
  363. } else {
  364. *table_index = i;
  365. return_ACPI_STATUS(AE_CTRL_TERMINATE);
  366. }
  367. }
  368. /* Indicate no duplication to the caller */
  369. return_ACPI_STATUS(AE_OK);
  370. }
  371. /******************************************************************************
  372. *
  373. * FUNCTION: acpi_tb_verify_temp_table
  374. *
  375. * PARAMETERS: table_desc - Table descriptor
  376. * signature - Table signature to verify
  377. * table_index - Where the table index is returned
  378. *
  379. * RETURN: Status
  380. *
  381. * DESCRIPTION: This function is called to validate and verify the table, the
  382. * returned table descriptor is in "VALIDATED" state.
  383. * Note that 'TableIndex' is required to be set to !NULL to
  384. * enable duplication check.
  385. *
  386. *****************************************************************************/
  387. acpi_status
  388. acpi_tb_verify_temp_table(struct acpi_table_desc *table_desc,
  389. char *signature, u32 *table_index)
  390. {
  391. acpi_status status = AE_OK;
  392. ACPI_FUNCTION_TRACE(tb_verify_temp_table);
  393. /* Validate the table */
  394. status = acpi_tb_validate_temp_table(table_desc);
  395. if (ACPI_FAILURE(status)) {
  396. return_ACPI_STATUS(AE_NO_MEMORY);
  397. }
  398. /* If a particular signature is expected (DSDT/FACS), it must match */
  399. if (signature && !ACPI_COMPARE_NAME(&table_desc->signature, signature)) {
  400. ACPI_BIOS_ERROR((AE_INFO,
  401. "Invalid signature 0x%X for ACPI table, expected [%s]",
  402. table_desc->signature.integer, signature));
  403. status = AE_BAD_SIGNATURE;
  404. goto invalidate_and_exit;
  405. }
  406. if (acpi_gbl_enable_table_validation) {
  407. /* Verify the checksum */
  408. status =
  409. acpi_tb_verify_checksum(table_desc->pointer,
  410. table_desc->length);
  411. if (ACPI_FAILURE(status)) {
  412. ACPI_EXCEPTION((AE_INFO, AE_NO_MEMORY,
  413. "%4.4s 0x%8.8X%8.8X"
  414. " Attempted table install failed",
  415. acpi_ut_valid_nameseg(table_desc->
  416. signature.
  417. ascii) ?
  418. table_desc->signature.ascii : "????",
  419. ACPI_FORMAT_UINT64(table_desc->
  420. address)));
  421. goto invalidate_and_exit;
  422. }
  423. /* Avoid duplications */
  424. if (table_index) {
  425. status =
  426. acpi_tb_check_duplication(table_desc, table_index);
  427. if (ACPI_FAILURE(status)) {
  428. if (status != AE_CTRL_TERMINATE) {
  429. ACPI_EXCEPTION((AE_INFO, status,
  430. "%4.4s 0x%8.8X%8.8X"
  431. " Table is already loaded",
  432. acpi_ut_valid_nameseg
  433. (table_desc->signature.
  434. ascii) ? table_desc->
  435. signature.
  436. ascii : "????",
  437. ACPI_FORMAT_UINT64
  438. (table_desc->address)));
  439. }
  440. goto invalidate_and_exit;
  441. }
  442. }
  443. table_desc->flags |= ACPI_TABLE_IS_VERIFIED;
  444. }
  445. return_ACPI_STATUS(status);
  446. invalidate_and_exit:
  447. acpi_tb_invalidate_table(table_desc);
  448. return_ACPI_STATUS(status);
  449. }
  450. /*******************************************************************************
  451. *
  452. * FUNCTION: acpi_tb_resize_root_table_list
  453. *
  454. * PARAMETERS: None
  455. *
  456. * RETURN: Status
  457. *
  458. * DESCRIPTION: Expand the size of global table array
  459. *
  460. ******************************************************************************/
  461. acpi_status acpi_tb_resize_root_table_list(void)
  462. {
  463. struct acpi_table_desc *tables;
  464. u32 table_count;
  465. u32 current_table_count, max_table_count;
  466. u32 i;
  467. ACPI_FUNCTION_TRACE(tb_resize_root_table_list);
  468. /* allow_resize flag is a parameter to acpi_initialize_tables */
  469. if (!(acpi_gbl_root_table_list.flags & ACPI_ROOT_ALLOW_RESIZE)) {
  470. ACPI_ERROR((AE_INFO,
  471. "Resize of Root Table Array is not allowed"));
  472. return_ACPI_STATUS(AE_SUPPORT);
  473. }
  474. /* Increase the Table Array size */
  475. if (acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) {
  476. table_count = acpi_gbl_root_table_list.max_table_count;
  477. } else {
  478. table_count = acpi_gbl_root_table_list.current_table_count;
  479. }
  480. max_table_count = table_count + ACPI_ROOT_TABLE_SIZE_INCREMENT;
  481. tables = ACPI_ALLOCATE_ZEROED(((acpi_size)max_table_count) *
  482. sizeof(struct acpi_table_desc));
  483. if (!tables) {
  484. ACPI_ERROR((AE_INFO,
  485. "Could not allocate new root table array"));
  486. return_ACPI_STATUS(AE_NO_MEMORY);
  487. }
  488. /* Copy and free the previous table array */
  489. current_table_count = 0;
  490. if (acpi_gbl_root_table_list.tables) {
  491. for (i = 0; i < table_count; i++) {
  492. if (acpi_gbl_root_table_list.tables[i].address) {
  493. memcpy(tables + current_table_count,
  494. acpi_gbl_root_table_list.tables + i,
  495. sizeof(struct acpi_table_desc));
  496. current_table_count++;
  497. }
  498. }
  499. if (acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) {
  500. ACPI_FREE(acpi_gbl_root_table_list.tables);
  501. }
  502. }
  503. acpi_gbl_root_table_list.tables = tables;
  504. acpi_gbl_root_table_list.max_table_count = max_table_count;
  505. acpi_gbl_root_table_list.current_table_count = current_table_count;
  506. acpi_gbl_root_table_list.flags |= ACPI_ROOT_ORIGIN_ALLOCATED;
  507. return_ACPI_STATUS(AE_OK);
  508. }
  509. /*******************************************************************************
  510. *
  511. * FUNCTION: acpi_tb_get_next_table_descriptor
  512. *
  513. * PARAMETERS: table_index - Where table index is returned
  514. * table_desc - Where table descriptor is returned
  515. *
  516. * RETURN: Status and table index/descriptor.
  517. *
  518. * DESCRIPTION: Allocate a new ACPI table entry to the global table list
  519. *
  520. ******************************************************************************/
  521. acpi_status
  522. acpi_tb_get_next_table_descriptor(u32 *table_index,
  523. struct acpi_table_desc **table_desc)
  524. {
  525. acpi_status status;
  526. u32 i;
  527. /* Ensure that there is room for the table in the Root Table List */
  528. if (acpi_gbl_root_table_list.current_table_count >=
  529. acpi_gbl_root_table_list.max_table_count) {
  530. status = acpi_tb_resize_root_table_list();
  531. if (ACPI_FAILURE(status)) {
  532. return (status);
  533. }
  534. }
  535. i = acpi_gbl_root_table_list.current_table_count;
  536. acpi_gbl_root_table_list.current_table_count++;
  537. if (table_index) {
  538. *table_index = i;
  539. }
  540. if (table_desc) {
  541. *table_desc = &acpi_gbl_root_table_list.tables[i];
  542. }
  543. return (AE_OK);
  544. }
  545. /*******************************************************************************
  546. *
  547. * FUNCTION: acpi_tb_terminate
  548. *
  549. * PARAMETERS: None
  550. *
  551. * RETURN: None
  552. *
  553. * DESCRIPTION: Delete all internal ACPI tables
  554. *
  555. ******************************************************************************/
  556. void acpi_tb_terminate(void)
  557. {
  558. u32 i;
  559. ACPI_FUNCTION_TRACE(tb_terminate);
  560. (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
  561. /* Delete the individual tables */
  562. for (i = 0; i < acpi_gbl_root_table_list.current_table_count; i++) {
  563. acpi_tb_uninstall_table(&acpi_gbl_root_table_list.tables[i]);
  564. }
  565. /*
  566. * Delete the root table array if allocated locally. Array cannot be
  567. * mapped, so we don't need to check for that flag.
  568. */
  569. if (acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) {
  570. ACPI_FREE(acpi_gbl_root_table_list.tables);
  571. }
  572. acpi_gbl_root_table_list.tables = NULL;
  573. acpi_gbl_root_table_list.flags = 0;
  574. acpi_gbl_root_table_list.current_table_count = 0;
  575. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "ACPI Tables freed\n"));
  576. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  577. return_VOID;
  578. }
  579. /*******************************************************************************
  580. *
  581. * FUNCTION: acpi_tb_delete_namespace_by_owner
  582. *
  583. * PARAMETERS: table_index - Table index
  584. *
  585. * RETURN: Status
  586. *
  587. * DESCRIPTION: Delete all namespace objects created when this table was loaded.
  588. *
  589. ******************************************************************************/
  590. acpi_status acpi_tb_delete_namespace_by_owner(u32 table_index)
  591. {
  592. acpi_owner_id owner_id;
  593. acpi_status status;
  594. ACPI_FUNCTION_TRACE(tb_delete_namespace_by_owner);
  595. status = acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
  596. if (ACPI_FAILURE(status)) {
  597. return_ACPI_STATUS(status);
  598. }
  599. if (table_index >= acpi_gbl_root_table_list.current_table_count) {
  600. /* The table index does not exist */
  601. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  602. return_ACPI_STATUS(AE_NOT_EXIST);
  603. }
  604. /* Get the owner ID for this table, used to delete namespace nodes */
  605. owner_id = acpi_gbl_root_table_list.tables[table_index].owner_id;
  606. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  607. /*
  608. * Need to acquire the namespace writer lock to prevent interference
  609. * with any concurrent namespace walks. The interpreter must be
  610. * released during the deletion since the acquisition of the deletion
  611. * lock may block, and also since the execution of a namespace walk
  612. * must be allowed to use the interpreter.
  613. */
  614. status = acpi_ut_acquire_write_lock(&acpi_gbl_namespace_rw_lock);
  615. if (ACPI_FAILURE(status)) {
  616. return_ACPI_STATUS(status);
  617. }
  618. acpi_ns_delete_namespace_by_owner(owner_id);
  619. acpi_ut_release_write_lock(&acpi_gbl_namespace_rw_lock);
  620. return_ACPI_STATUS(status);
  621. }
  622. /*******************************************************************************
  623. *
  624. * FUNCTION: acpi_tb_allocate_owner_id
  625. *
  626. * PARAMETERS: table_index - Table index
  627. *
  628. * RETURN: Status
  629. *
  630. * DESCRIPTION: Allocates owner_id in table_desc
  631. *
  632. ******************************************************************************/
  633. acpi_status acpi_tb_allocate_owner_id(u32 table_index)
  634. {
  635. acpi_status status = AE_BAD_PARAMETER;
  636. ACPI_FUNCTION_TRACE(tb_allocate_owner_id);
  637. (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
  638. if (table_index < acpi_gbl_root_table_list.current_table_count) {
  639. status =
  640. acpi_ut_allocate_owner_id(&
  641. (acpi_gbl_root_table_list.
  642. tables[table_index].owner_id));
  643. }
  644. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  645. return_ACPI_STATUS(status);
  646. }
  647. /*******************************************************************************
  648. *
  649. * FUNCTION: acpi_tb_release_owner_id
  650. *
  651. * PARAMETERS: table_index - Table index
  652. *
  653. * RETURN: Status
  654. *
  655. * DESCRIPTION: Releases owner_id in table_desc
  656. *
  657. ******************************************************************************/
  658. acpi_status acpi_tb_release_owner_id(u32 table_index)
  659. {
  660. acpi_status status = AE_BAD_PARAMETER;
  661. ACPI_FUNCTION_TRACE(tb_release_owner_id);
  662. (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
  663. if (table_index < acpi_gbl_root_table_list.current_table_count) {
  664. acpi_ut_release_owner_id(&
  665. (acpi_gbl_root_table_list.
  666. tables[table_index].owner_id));
  667. status = AE_OK;
  668. }
  669. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  670. return_ACPI_STATUS(status);
  671. }
  672. /*******************************************************************************
  673. *
  674. * FUNCTION: acpi_tb_get_owner_id
  675. *
  676. * PARAMETERS: table_index - Table index
  677. * owner_id - Where the table owner_id is returned
  678. *
  679. * RETURN: Status
  680. *
  681. * DESCRIPTION: returns owner_id for the ACPI table
  682. *
  683. ******************************************************************************/
  684. acpi_status acpi_tb_get_owner_id(u32 table_index, acpi_owner_id *owner_id)
  685. {
  686. acpi_status status = AE_BAD_PARAMETER;
  687. ACPI_FUNCTION_TRACE(tb_get_owner_id);
  688. (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
  689. if (table_index < acpi_gbl_root_table_list.current_table_count) {
  690. *owner_id =
  691. acpi_gbl_root_table_list.tables[table_index].owner_id;
  692. status = AE_OK;
  693. }
  694. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  695. return_ACPI_STATUS(status);
  696. }
  697. /*******************************************************************************
  698. *
  699. * FUNCTION: acpi_tb_is_table_loaded
  700. *
  701. * PARAMETERS: table_index - Index into the root table
  702. *
  703. * RETURN: Table Loaded Flag
  704. *
  705. ******************************************************************************/
  706. u8 acpi_tb_is_table_loaded(u32 table_index)
  707. {
  708. u8 is_loaded = FALSE;
  709. (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
  710. if (table_index < acpi_gbl_root_table_list.current_table_count) {
  711. is_loaded = (u8)
  712. (acpi_gbl_root_table_list.tables[table_index].flags &
  713. ACPI_TABLE_IS_LOADED);
  714. }
  715. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  716. return (is_loaded);
  717. }
  718. /*******************************************************************************
  719. *
  720. * FUNCTION: acpi_tb_set_table_loaded_flag
  721. *
  722. * PARAMETERS: table_index - Table index
  723. * is_loaded - TRUE if table is loaded, FALSE otherwise
  724. *
  725. * RETURN: None
  726. *
  727. * DESCRIPTION: Sets the table loaded flag to either TRUE or FALSE.
  728. *
  729. ******************************************************************************/
  730. void acpi_tb_set_table_loaded_flag(u32 table_index, u8 is_loaded)
  731. {
  732. (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
  733. if (table_index < acpi_gbl_root_table_list.current_table_count) {
  734. if (is_loaded) {
  735. acpi_gbl_root_table_list.tables[table_index].flags |=
  736. ACPI_TABLE_IS_LOADED;
  737. } else {
  738. acpi_gbl_root_table_list.tables[table_index].flags &=
  739. ~ACPI_TABLE_IS_LOADED;
  740. }
  741. }
  742. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  743. }
  744. /*******************************************************************************
  745. *
  746. * FUNCTION: acpi_tb_load_table
  747. *
  748. * PARAMETERS: table_index - Table index
  749. * parent_node - Where table index is returned
  750. *
  751. * RETURN: Status
  752. *
  753. * DESCRIPTION: Load an ACPI table
  754. *
  755. ******************************************************************************/
  756. acpi_status
  757. acpi_tb_load_table(u32 table_index, struct acpi_namespace_node *parent_node)
  758. {
  759. struct acpi_table_header *table;
  760. acpi_status status;
  761. acpi_owner_id owner_id;
  762. ACPI_FUNCTION_TRACE(tb_load_table);
  763. /*
  764. * Note: Now table is "INSTALLED", it must be validated before
  765. * using.
  766. */
  767. status = acpi_get_table_by_index(table_index, &table);
  768. if (ACPI_FAILURE(status)) {
  769. return_ACPI_STATUS(status);
  770. }
  771. status = acpi_ns_load_table(table_index, parent_node);
  772. /*
  773. * This case handles the legacy option that groups all module-level
  774. * code blocks together and defers execution until all of the tables
  775. * are loaded. Execute all of these blocks at this time.
  776. * Execute any module-level code that was detected during the table
  777. * load phase.
  778. *
  779. * Note: this option is deprecated and will be eliminated in the
  780. * future. Use of this option can cause problems with AML code that
  781. * depends upon in-order immediate execution of module-level code.
  782. */
  783. acpi_ns_exec_module_code_list();
  784. /*
  785. * Update GPEs for any new _Lxx/_Exx methods. Ignore errors. The host is
  786. * responsible for discovering any new wake GPEs by running _PRW methods
  787. * that may have been loaded by this table.
  788. */
  789. status = acpi_tb_get_owner_id(table_index, &owner_id);
  790. if (ACPI_SUCCESS(status)) {
  791. acpi_ev_update_gpes(owner_id);
  792. }
  793. /* Invoke table handler */
  794. acpi_tb_notify_table(ACPI_TABLE_EVENT_LOAD, table);
  795. return_ACPI_STATUS(status);
  796. }
  797. /*******************************************************************************
  798. *
  799. * FUNCTION: acpi_tb_install_and_load_table
  800. *
  801. * PARAMETERS: address - Physical address of the table
  802. * flags - Allocation flags of the table
  803. * override - Whether override should be performed
  804. * table_index - Where table index is returned
  805. *
  806. * RETURN: Status
  807. *
  808. * DESCRIPTION: Install and load an ACPI table
  809. *
  810. ******************************************************************************/
  811. acpi_status
  812. acpi_tb_install_and_load_table(acpi_physical_address address,
  813. u8 flags, u8 override, u32 *table_index)
  814. {
  815. acpi_status status;
  816. u32 i;
  817. ACPI_FUNCTION_TRACE(tb_install_and_load_table);
  818. /* Install the table and load it into the namespace */
  819. status = acpi_tb_install_standard_table(address, flags, TRUE,
  820. override, &i);
  821. if (ACPI_FAILURE(status)) {
  822. goto exit;
  823. }
  824. status = acpi_tb_load_table(i, acpi_gbl_root_node);
  825. exit:
  826. *table_index = i;
  827. return_ACPI_STATUS(status);
  828. }
  829. ACPI_EXPORT_SYMBOL(acpi_tb_install_and_load_table)
  830. /*******************************************************************************
  831. *
  832. * FUNCTION: acpi_tb_unload_table
  833. *
  834. * PARAMETERS: table_index - Table index
  835. *
  836. * RETURN: Status
  837. *
  838. * DESCRIPTION: Unload an ACPI table
  839. *
  840. ******************************************************************************/
  841. acpi_status acpi_tb_unload_table(u32 table_index)
  842. {
  843. acpi_status status = AE_OK;
  844. struct acpi_table_header *table;
  845. ACPI_FUNCTION_TRACE(tb_unload_table);
  846. /* Ensure the table is still loaded */
  847. if (!acpi_tb_is_table_loaded(table_index)) {
  848. return_ACPI_STATUS(AE_NOT_EXIST);
  849. }
  850. /* Invoke table handler */
  851. status = acpi_get_table_by_index(table_index, &table);
  852. if (ACPI_SUCCESS(status)) {
  853. acpi_tb_notify_table(ACPI_TABLE_EVENT_UNLOAD, table);
  854. }
  855. /* Delete the portion of the namespace owned by this table */
  856. status = acpi_tb_delete_namespace_by_owner(table_index);
  857. if (ACPI_FAILURE(status)) {
  858. return_ACPI_STATUS(status);
  859. }
  860. (void)acpi_tb_release_owner_id(table_index);
  861. acpi_tb_set_table_loaded_flag(table_index, FALSE);
  862. return_ACPI_STATUS(status);
  863. }
  864. ACPI_EXPORT_SYMBOL(acpi_tb_unload_table)
  865. /*******************************************************************************
  866. *
  867. * FUNCTION: acpi_tb_notify_table
  868. *
  869. * PARAMETERS: event - Table event
  870. * table - Validated table pointer
  871. *
  872. * RETURN: None
  873. *
  874. * DESCRIPTION: Notify a table event to the users.
  875. *
  876. ******************************************************************************/
  877. void acpi_tb_notify_table(u32 event, void *table)
  878. {
  879. /* Invoke table handler if present */
  880. if (acpi_gbl_table_handler) {
  881. (void)acpi_gbl_table_handler(event, table,
  882. acpi_gbl_table_handler_context);
  883. }
  884. }