tbdata.c 31 KB

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