tbdata.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909
  1. /******************************************************************************
  2. *
  3. * Module Name: tbdata - Table manager data structure functions
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2016, 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. /*******************************************************************************
  50. *
  51. * FUNCTION: acpi_tb_init_table_descriptor
  52. *
  53. * PARAMETERS: table_desc - Table descriptor
  54. * address - Physical address of the table
  55. * flags - Allocation flags of the table
  56. * table - Pointer to the table
  57. *
  58. * RETURN: None
  59. *
  60. * DESCRIPTION: Initialize a new table descriptor
  61. *
  62. ******************************************************************************/
  63. void
  64. acpi_tb_init_table_descriptor(struct acpi_table_desc *table_desc,
  65. acpi_physical_address address,
  66. u8 flags, struct acpi_table_header *table)
  67. {
  68. /*
  69. * Initialize the table descriptor. Set the pointer to NULL, since the
  70. * table is not fully mapped at this time.
  71. */
  72. memset(table_desc, 0, sizeof(struct acpi_table_desc));
  73. table_desc->address = address;
  74. table_desc->length = table->length;
  75. table_desc->flags = flags;
  76. ACPI_MOVE_32_TO_32(table_desc->signature.ascii, table->signature);
  77. }
  78. /*******************************************************************************
  79. *
  80. * FUNCTION: acpi_tb_acquire_table
  81. *
  82. * PARAMETERS: table_desc - Table descriptor
  83. * table_ptr - Where table is returned
  84. * table_length - Where table length is returned
  85. * table_flags - Where table allocation flags are returned
  86. *
  87. * RETURN: Status
  88. *
  89. * DESCRIPTION: Acquire an ACPI table. It can be used for tables not
  90. * maintained in the acpi_gbl_root_table_list.
  91. *
  92. ******************************************************************************/
  93. acpi_status
  94. acpi_tb_acquire_table(struct acpi_table_desc *table_desc,
  95. struct acpi_table_header **table_ptr,
  96. u32 *table_length, u8 *table_flags)
  97. {
  98. struct acpi_table_header *table = NULL;
  99. switch (table_desc->flags & ACPI_TABLE_ORIGIN_MASK) {
  100. case ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL:
  101. table =
  102. acpi_os_map_memory(table_desc->address, table_desc->length);
  103. break;
  104. case ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL:
  105. case ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL:
  106. table = ACPI_CAST_PTR(struct acpi_table_header,
  107. ACPI_PHYSADDR_TO_PTR(table_desc->
  108. address));
  109. break;
  110. default:
  111. break;
  112. }
  113. /* Table is not valid yet */
  114. if (!table) {
  115. return (AE_NO_MEMORY);
  116. }
  117. /* Fill the return values */
  118. *table_ptr = table;
  119. *table_length = table_desc->length;
  120. *table_flags = table_desc->flags;
  121. return (AE_OK);
  122. }
  123. /*******************************************************************************
  124. *
  125. * FUNCTION: acpi_tb_release_table
  126. *
  127. * PARAMETERS: table - Pointer for the table
  128. * table_length - Length for the table
  129. * table_flags - Allocation flags for the table
  130. *
  131. * RETURN: None
  132. *
  133. * DESCRIPTION: Release a table. The inverse of acpi_tb_acquire_table().
  134. *
  135. ******************************************************************************/
  136. void
  137. acpi_tb_release_table(struct acpi_table_header *table,
  138. u32 table_length, u8 table_flags)
  139. {
  140. switch (table_flags & ACPI_TABLE_ORIGIN_MASK) {
  141. case ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL:
  142. acpi_os_unmap_memory(table, table_length);
  143. break;
  144. case ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL:
  145. case ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL:
  146. default:
  147. break;
  148. }
  149. }
  150. /*******************************************************************************
  151. *
  152. * FUNCTION: acpi_tb_acquire_temp_table
  153. *
  154. * PARAMETERS: table_desc - Table descriptor to be acquired
  155. * address - Address of the table
  156. * flags - Allocation flags of the table
  157. *
  158. * RETURN: Status
  159. *
  160. * DESCRIPTION: This function validates the table header to obtain the length
  161. * of a table and fills the table descriptor to make its state as
  162. * "INSTALLED". Such a table descriptor is only used for verified
  163. * installation.
  164. *
  165. ******************************************************************************/
  166. acpi_status
  167. acpi_tb_acquire_temp_table(struct acpi_table_desc *table_desc,
  168. acpi_physical_address address, u8 flags)
  169. {
  170. struct acpi_table_header *table_header;
  171. switch (flags & ACPI_TABLE_ORIGIN_MASK) {
  172. case ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL:
  173. /* Get the length of the full table from the header */
  174. table_header =
  175. acpi_os_map_memory(address,
  176. sizeof(struct acpi_table_header));
  177. if (!table_header) {
  178. return (AE_NO_MEMORY);
  179. }
  180. acpi_tb_init_table_descriptor(table_desc, address, flags,
  181. table_header);
  182. acpi_os_unmap_memory(table_header,
  183. sizeof(struct acpi_table_header));
  184. return (AE_OK);
  185. case ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL:
  186. case ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL:
  187. table_header = ACPI_CAST_PTR(struct acpi_table_header,
  188. ACPI_PHYSADDR_TO_PTR(address));
  189. if (!table_header) {
  190. return (AE_NO_MEMORY);
  191. }
  192. acpi_tb_init_table_descriptor(table_desc, address, flags,
  193. table_header);
  194. return (AE_OK);
  195. default:
  196. break;
  197. }
  198. /* Table is not valid yet */
  199. return (AE_NO_MEMORY);
  200. }
  201. /*******************************************************************************
  202. *
  203. * FUNCTION: acpi_tb_release_temp_table
  204. *
  205. * PARAMETERS: table_desc - Table descriptor to be released
  206. *
  207. * RETURN: Status
  208. *
  209. * DESCRIPTION: The inverse of acpi_tb_acquire_temp_table().
  210. *
  211. *****************************************************************************/
  212. void acpi_tb_release_temp_table(struct acpi_table_desc *table_desc)
  213. {
  214. /*
  215. * Note that the .Address is maintained by the callers of
  216. * acpi_tb_acquire_temp_table(), thus do not invoke acpi_tb_uninstall_table()
  217. * where .Address will be freed.
  218. */
  219. acpi_tb_invalidate_table(table_desc);
  220. }
  221. /******************************************************************************
  222. *
  223. * FUNCTION: acpi_tb_validate_table
  224. *
  225. * PARAMETERS: table_desc - Table descriptor
  226. *
  227. * RETURN: Status
  228. *
  229. * DESCRIPTION: This function is called to validate the table, the returned
  230. * table descriptor is in "VALIDATED" state.
  231. *
  232. *****************************************************************************/
  233. acpi_status acpi_tb_validate_table(struct acpi_table_desc *table_desc)
  234. {
  235. acpi_status status = AE_OK;
  236. ACPI_FUNCTION_TRACE(tb_validate_table);
  237. /* Validate the table if necessary */
  238. if (!table_desc->pointer) {
  239. status = acpi_tb_acquire_table(table_desc, &table_desc->pointer,
  240. &table_desc->length,
  241. &table_desc->flags);
  242. if (!table_desc->pointer) {
  243. status = AE_NO_MEMORY;
  244. }
  245. }
  246. return_ACPI_STATUS(status);
  247. }
  248. /*******************************************************************************
  249. *
  250. * FUNCTION: acpi_tb_invalidate_table
  251. *
  252. * PARAMETERS: table_desc - Table descriptor
  253. *
  254. * RETURN: None
  255. *
  256. * DESCRIPTION: Invalidate one internal ACPI table, this is the inverse of
  257. * acpi_tb_validate_table().
  258. *
  259. ******************************************************************************/
  260. void acpi_tb_invalidate_table(struct acpi_table_desc *table_desc)
  261. {
  262. ACPI_FUNCTION_TRACE(tb_invalidate_table);
  263. /* Table must be validated */
  264. if (!table_desc->pointer) {
  265. return_VOID;
  266. }
  267. acpi_tb_release_table(table_desc->pointer, table_desc->length,
  268. table_desc->flags);
  269. table_desc->pointer = NULL;
  270. return_VOID;
  271. }
  272. /******************************************************************************
  273. *
  274. * FUNCTION: acpi_tb_validate_temp_table
  275. *
  276. * PARAMETERS: table_desc - Table descriptor
  277. *
  278. * RETURN: Status
  279. *
  280. * DESCRIPTION: This function is called to validate the table, the returned
  281. * table descriptor is in "VALIDATED" state.
  282. *
  283. *****************************************************************************/
  284. acpi_status acpi_tb_validate_temp_table(struct acpi_table_desc *table_desc)
  285. {
  286. if (!table_desc->pointer && !acpi_gbl_verify_table_checksum) {
  287. /*
  288. * Only validates the header of the table.
  289. * Note that Length contains the size of the mapping after invoking
  290. * this work around, this value is required by
  291. * acpi_tb_release_temp_table().
  292. * We can do this because in acpi_init_table_descriptor(), the Length
  293. * field of the installed descriptor is filled with the actual
  294. * table length obtaining from the table header.
  295. */
  296. table_desc->length = sizeof(struct acpi_table_header);
  297. }
  298. return (acpi_tb_validate_table(table_desc));
  299. }
  300. /******************************************************************************
  301. *
  302. * FUNCTION: acpi_tb_verify_temp_table
  303. *
  304. * PARAMETERS: table_desc - Table descriptor
  305. * signature - Table signature to verify
  306. *
  307. * RETURN: Status
  308. *
  309. * DESCRIPTION: This function is called to validate and verify the table, the
  310. * returned table descriptor is in "VALIDATED" state.
  311. *
  312. *****************************************************************************/
  313. acpi_status
  314. acpi_tb_verify_temp_table(struct acpi_table_desc *table_desc, char *signature)
  315. {
  316. acpi_status status = AE_OK;
  317. ACPI_FUNCTION_TRACE(tb_verify_temp_table);
  318. /* Validate the table */
  319. status = acpi_tb_validate_temp_table(table_desc);
  320. if (ACPI_FAILURE(status)) {
  321. return_ACPI_STATUS(AE_NO_MEMORY);
  322. }
  323. /* If a particular signature is expected (DSDT/FACS), it must match */
  324. if (signature && !ACPI_COMPARE_NAME(&table_desc->signature, signature)) {
  325. ACPI_BIOS_ERROR((AE_INFO,
  326. "Invalid signature 0x%X for ACPI table, expected [%s]",
  327. table_desc->signature.integer, signature));
  328. status = AE_BAD_SIGNATURE;
  329. goto invalidate_and_exit;
  330. }
  331. /* Verify the checksum */
  332. if (acpi_gbl_verify_table_checksum) {
  333. status =
  334. acpi_tb_verify_checksum(table_desc->pointer,
  335. table_desc->length);
  336. if (ACPI_FAILURE(status)) {
  337. ACPI_EXCEPTION((AE_INFO, AE_NO_MEMORY,
  338. "%4.4s 0x%8.8X%8.8X"
  339. " Attempted table install failed",
  340. acpi_ut_valid_nameseg(table_desc->
  341. signature.
  342. ascii) ?
  343. table_desc->signature.ascii : "????",
  344. ACPI_FORMAT_UINT64(table_desc->
  345. address)));
  346. goto invalidate_and_exit;
  347. }
  348. }
  349. return_ACPI_STATUS(AE_OK);
  350. invalidate_and_exit:
  351. acpi_tb_invalidate_table(table_desc);
  352. return_ACPI_STATUS(status);
  353. }
  354. /*******************************************************************************
  355. *
  356. * FUNCTION: acpi_tb_resize_root_table_list
  357. *
  358. * PARAMETERS: None
  359. *
  360. * RETURN: Status
  361. *
  362. * DESCRIPTION: Expand the size of global table array
  363. *
  364. ******************************************************************************/
  365. acpi_status acpi_tb_resize_root_table_list(void)
  366. {
  367. struct acpi_table_desc *tables;
  368. u32 table_count;
  369. ACPI_FUNCTION_TRACE(tb_resize_root_table_list);
  370. /* allow_resize flag is a parameter to acpi_initialize_tables */
  371. if (!(acpi_gbl_root_table_list.flags & ACPI_ROOT_ALLOW_RESIZE)) {
  372. ACPI_ERROR((AE_INFO,
  373. "Resize of Root Table Array is not allowed"));
  374. return_ACPI_STATUS(AE_SUPPORT);
  375. }
  376. /* Increase the Table Array size */
  377. if (acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) {
  378. table_count = acpi_gbl_root_table_list.max_table_count;
  379. } else {
  380. table_count = acpi_gbl_root_table_list.current_table_count;
  381. }
  382. tables = ACPI_ALLOCATE_ZEROED(((acpi_size)table_count +
  383. ACPI_ROOT_TABLE_SIZE_INCREMENT) *
  384. sizeof(struct acpi_table_desc));
  385. if (!tables) {
  386. ACPI_ERROR((AE_INFO,
  387. "Could not allocate new root table array"));
  388. return_ACPI_STATUS(AE_NO_MEMORY);
  389. }
  390. /* Copy and free the previous table array */
  391. if (acpi_gbl_root_table_list.tables) {
  392. memcpy(tables, acpi_gbl_root_table_list.tables,
  393. (acpi_size)table_count * sizeof(struct acpi_table_desc));
  394. if (acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) {
  395. ACPI_FREE(acpi_gbl_root_table_list.tables);
  396. }
  397. }
  398. acpi_gbl_root_table_list.tables = tables;
  399. acpi_gbl_root_table_list.max_table_count =
  400. table_count + ACPI_ROOT_TABLE_SIZE_INCREMENT;
  401. acpi_gbl_root_table_list.flags |= ACPI_ROOT_ORIGIN_ALLOCATED;
  402. return_ACPI_STATUS(AE_OK);
  403. }
  404. /*******************************************************************************
  405. *
  406. * FUNCTION: acpi_tb_get_next_table_descriptor
  407. *
  408. * PARAMETERS: table_index - Where table index is returned
  409. * table_desc - Where table descriptor is returned
  410. *
  411. * RETURN: Status and table index/descriptor.
  412. *
  413. * DESCRIPTION: Allocate a new ACPI table entry to the global table list
  414. *
  415. ******************************************************************************/
  416. acpi_status
  417. acpi_tb_get_next_table_descriptor(u32 *table_index,
  418. struct acpi_table_desc **table_desc)
  419. {
  420. acpi_status status;
  421. u32 i;
  422. /* Ensure that there is room for the table in the Root Table List */
  423. if (acpi_gbl_root_table_list.current_table_count >=
  424. acpi_gbl_root_table_list.max_table_count) {
  425. status = acpi_tb_resize_root_table_list();
  426. if (ACPI_FAILURE(status)) {
  427. return (status);
  428. }
  429. }
  430. i = acpi_gbl_root_table_list.current_table_count;
  431. acpi_gbl_root_table_list.current_table_count++;
  432. if (table_index) {
  433. *table_index = i;
  434. }
  435. if (table_desc) {
  436. *table_desc = &acpi_gbl_root_table_list.tables[i];
  437. }
  438. return (AE_OK);
  439. }
  440. /*******************************************************************************
  441. *
  442. * FUNCTION: acpi_tb_terminate
  443. *
  444. * PARAMETERS: None
  445. *
  446. * RETURN: None
  447. *
  448. * DESCRIPTION: Delete all internal ACPI tables
  449. *
  450. ******************************************************************************/
  451. void acpi_tb_terminate(void)
  452. {
  453. u32 i;
  454. ACPI_FUNCTION_TRACE(tb_terminate);
  455. (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
  456. /* Delete the individual tables */
  457. for (i = 0; i < acpi_gbl_root_table_list.current_table_count; i++) {
  458. acpi_tb_uninstall_table(&acpi_gbl_root_table_list.tables[i]);
  459. }
  460. /*
  461. * Delete the root table array if allocated locally. Array cannot be
  462. * mapped, so we don't need to check for that flag.
  463. */
  464. if (acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) {
  465. ACPI_FREE(acpi_gbl_root_table_list.tables);
  466. }
  467. acpi_gbl_root_table_list.tables = NULL;
  468. acpi_gbl_root_table_list.flags = 0;
  469. acpi_gbl_root_table_list.current_table_count = 0;
  470. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "ACPI Tables freed\n"));
  471. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  472. return_VOID;
  473. }
  474. /*******************************************************************************
  475. *
  476. * FUNCTION: acpi_tb_delete_namespace_by_owner
  477. *
  478. * PARAMETERS: table_index - Table index
  479. *
  480. * RETURN: Status
  481. *
  482. * DESCRIPTION: Delete all namespace objects created when this table was loaded.
  483. *
  484. ******************************************************************************/
  485. acpi_status acpi_tb_delete_namespace_by_owner(u32 table_index)
  486. {
  487. acpi_owner_id owner_id;
  488. acpi_status status;
  489. ACPI_FUNCTION_TRACE(tb_delete_namespace_by_owner);
  490. status = acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
  491. if (ACPI_FAILURE(status)) {
  492. return_ACPI_STATUS(status);
  493. }
  494. if (table_index >= acpi_gbl_root_table_list.current_table_count) {
  495. /* The table index does not exist */
  496. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  497. return_ACPI_STATUS(AE_NOT_EXIST);
  498. }
  499. /* Get the owner ID for this table, used to delete namespace nodes */
  500. owner_id = acpi_gbl_root_table_list.tables[table_index].owner_id;
  501. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  502. /*
  503. * Need to acquire the namespace writer lock to prevent interference
  504. * with any concurrent namespace walks. The interpreter must be
  505. * released during the deletion since the acquisition of the deletion
  506. * lock may block, and also since the execution of a namespace walk
  507. * must be allowed to use the interpreter.
  508. */
  509. status = acpi_ut_acquire_write_lock(&acpi_gbl_namespace_rw_lock);
  510. if (ACPI_FAILURE(status)) {
  511. return_ACPI_STATUS(status);
  512. }
  513. acpi_ns_delete_namespace_by_owner(owner_id);
  514. acpi_ut_release_write_lock(&acpi_gbl_namespace_rw_lock);
  515. return_ACPI_STATUS(status);
  516. }
  517. /*******************************************************************************
  518. *
  519. * FUNCTION: acpi_tb_allocate_owner_id
  520. *
  521. * PARAMETERS: table_index - Table index
  522. *
  523. * RETURN: Status
  524. *
  525. * DESCRIPTION: Allocates owner_id in table_desc
  526. *
  527. ******************************************************************************/
  528. acpi_status acpi_tb_allocate_owner_id(u32 table_index)
  529. {
  530. acpi_status status = AE_BAD_PARAMETER;
  531. ACPI_FUNCTION_TRACE(tb_allocate_owner_id);
  532. (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
  533. if (table_index < acpi_gbl_root_table_list.current_table_count) {
  534. status =
  535. acpi_ut_allocate_owner_id(&
  536. (acpi_gbl_root_table_list.
  537. tables[table_index].owner_id));
  538. }
  539. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  540. return_ACPI_STATUS(status);
  541. }
  542. /*******************************************************************************
  543. *
  544. * FUNCTION: acpi_tb_release_owner_id
  545. *
  546. * PARAMETERS: table_index - Table index
  547. *
  548. * RETURN: Status
  549. *
  550. * DESCRIPTION: Releases owner_id in table_desc
  551. *
  552. ******************************************************************************/
  553. acpi_status acpi_tb_release_owner_id(u32 table_index)
  554. {
  555. acpi_status status = AE_BAD_PARAMETER;
  556. ACPI_FUNCTION_TRACE(tb_release_owner_id);
  557. (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
  558. if (table_index < acpi_gbl_root_table_list.current_table_count) {
  559. acpi_ut_release_owner_id(&
  560. (acpi_gbl_root_table_list.
  561. tables[table_index].owner_id));
  562. status = AE_OK;
  563. }
  564. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  565. return_ACPI_STATUS(status);
  566. }
  567. /*******************************************************************************
  568. *
  569. * FUNCTION: acpi_tb_get_owner_id
  570. *
  571. * PARAMETERS: table_index - Table index
  572. * owner_id - Where the table owner_id is returned
  573. *
  574. * RETURN: Status
  575. *
  576. * DESCRIPTION: returns owner_id for the ACPI table
  577. *
  578. ******************************************************************************/
  579. acpi_status acpi_tb_get_owner_id(u32 table_index, acpi_owner_id *owner_id)
  580. {
  581. acpi_status status = AE_BAD_PARAMETER;
  582. ACPI_FUNCTION_TRACE(tb_get_owner_id);
  583. (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
  584. if (table_index < acpi_gbl_root_table_list.current_table_count) {
  585. *owner_id =
  586. acpi_gbl_root_table_list.tables[table_index].owner_id;
  587. status = AE_OK;
  588. }
  589. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  590. return_ACPI_STATUS(status);
  591. }
  592. /*******************************************************************************
  593. *
  594. * FUNCTION: acpi_tb_is_table_loaded
  595. *
  596. * PARAMETERS: table_index - Index into the root table
  597. *
  598. * RETURN: Table Loaded Flag
  599. *
  600. ******************************************************************************/
  601. u8 acpi_tb_is_table_loaded(u32 table_index)
  602. {
  603. u8 is_loaded = FALSE;
  604. (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
  605. if (table_index < acpi_gbl_root_table_list.current_table_count) {
  606. is_loaded = (u8)
  607. (acpi_gbl_root_table_list.tables[table_index].flags &
  608. ACPI_TABLE_IS_LOADED);
  609. }
  610. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  611. return (is_loaded);
  612. }
  613. /*******************************************************************************
  614. *
  615. * FUNCTION: acpi_tb_set_table_loaded_flag
  616. *
  617. * PARAMETERS: table_index - Table index
  618. * is_loaded - TRUE if table is loaded, FALSE otherwise
  619. *
  620. * RETURN: None
  621. *
  622. * DESCRIPTION: Sets the table loaded flag to either TRUE or FALSE.
  623. *
  624. ******************************************************************************/
  625. void acpi_tb_set_table_loaded_flag(u32 table_index, u8 is_loaded)
  626. {
  627. (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
  628. if (table_index < acpi_gbl_root_table_list.current_table_count) {
  629. if (is_loaded) {
  630. acpi_gbl_root_table_list.tables[table_index].flags |=
  631. ACPI_TABLE_IS_LOADED;
  632. } else {
  633. acpi_gbl_root_table_list.tables[table_index].flags &=
  634. ~ACPI_TABLE_IS_LOADED;
  635. }
  636. }
  637. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  638. }
  639. /*******************************************************************************
  640. *
  641. * FUNCTION: acpi_tb_load_table
  642. *
  643. * PARAMETERS: table_index - Table index
  644. * parent_node - Where table index is returned
  645. *
  646. * RETURN: Status
  647. *
  648. * DESCRIPTION: Load an ACPI table
  649. *
  650. ******************************************************************************/
  651. acpi_status
  652. acpi_tb_load_table(u32 table_index, struct acpi_namespace_node *parent_node)
  653. {
  654. struct acpi_table_header *table;
  655. acpi_status status;
  656. acpi_owner_id owner_id;
  657. ACPI_FUNCTION_TRACE(tb_load_table);
  658. /*
  659. * Note: Now table is "INSTALLED", it must be validated before
  660. * using.
  661. */
  662. status = acpi_get_table_by_index(table_index, &table);
  663. if (ACPI_FAILURE(status)) {
  664. return_ACPI_STATUS(status);
  665. }
  666. status = acpi_ns_load_table(table_index, parent_node);
  667. /* Execute any module-level code that was found in the table */
  668. if (!acpi_gbl_parse_table_as_term_list
  669. && acpi_gbl_group_module_level_code) {
  670. acpi_ns_exec_module_code_list();
  671. }
  672. /*
  673. * Update GPEs for any new _Lxx/_Exx methods. Ignore errors. The host is
  674. * responsible for discovering any new wake GPEs by running _PRW methods
  675. * that may have been loaded by this table.
  676. */
  677. status = acpi_tb_get_owner_id(table_index, &owner_id);
  678. if (ACPI_SUCCESS(status)) {
  679. acpi_ev_update_gpes(owner_id);
  680. }
  681. /* Invoke table handler if present */
  682. if (acpi_gbl_table_handler) {
  683. (void)acpi_gbl_table_handler(ACPI_TABLE_EVENT_LOAD, table,
  684. acpi_gbl_table_handler_context);
  685. }
  686. return_ACPI_STATUS(status);
  687. }
  688. /*******************************************************************************
  689. *
  690. * FUNCTION: acpi_tb_install_and_load_table
  691. *
  692. * PARAMETERS: table - Pointer to the table
  693. * address - Physical address of the table
  694. * flags - Allocation flags of the table
  695. * table_index - Where table index is returned
  696. *
  697. * RETURN: Status
  698. *
  699. * DESCRIPTION: Install and load an ACPI table
  700. *
  701. ******************************************************************************/
  702. acpi_status
  703. acpi_tb_install_and_load_table(struct acpi_table_header *table,
  704. acpi_physical_address address,
  705. u8 flags, u8 override, u32 *table_index)
  706. {
  707. acpi_status status;
  708. u32 i;
  709. acpi_owner_id owner_id;
  710. ACPI_FUNCTION_TRACE(acpi_load_table);
  711. (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
  712. /* Install the table and load it into the namespace */
  713. status = acpi_tb_install_standard_table(address, flags, TRUE,
  714. override, &i);
  715. if (ACPI_FAILURE(status)) {
  716. goto unlock_and_exit;
  717. }
  718. /*
  719. * Note: Now table is "INSTALLED", it must be validated before
  720. * using.
  721. */
  722. status = acpi_tb_validate_table(&acpi_gbl_root_table_list.tables[i]);
  723. if (ACPI_FAILURE(status)) {
  724. goto unlock_and_exit;
  725. }
  726. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  727. status = acpi_ns_load_table(i, acpi_gbl_root_node);
  728. /* Execute any module-level code that was found in the table */
  729. if (!acpi_gbl_parse_table_as_term_list
  730. && acpi_gbl_group_module_level_code) {
  731. acpi_ns_exec_module_code_list();
  732. }
  733. /*
  734. * Update GPEs for any new _Lxx/_Exx methods. Ignore errors. The host is
  735. * responsible for discovering any new wake GPEs by running _PRW methods
  736. * that may have been loaded by this table.
  737. */
  738. status = acpi_tb_get_owner_id(i, &owner_id);
  739. if (ACPI_SUCCESS(status)) {
  740. acpi_ev_update_gpes(owner_id);
  741. }
  742. /* Invoke table handler if present */
  743. if (acpi_gbl_table_handler) {
  744. (void)acpi_gbl_table_handler(ACPI_TABLE_EVENT_LOAD, table,
  745. acpi_gbl_table_handler_context);
  746. }
  747. (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
  748. unlock_and_exit:
  749. *table_index = i;
  750. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  751. return_ACPI_STATUS(status);
  752. }