tbdata.c 30 KB

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