tbinstal.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  1. /******************************************************************************
  2. *
  3. * Module Name: tbinstal - ACPI table installation and removal
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2011, 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. #define _COMPONENT ACPI_TABLES
  47. ACPI_MODULE_NAME("tbinstal")
  48. /******************************************************************************
  49. *
  50. * FUNCTION: acpi_tb_verify_table
  51. *
  52. * PARAMETERS: table_desc - table
  53. *
  54. * RETURN: Status
  55. *
  56. * DESCRIPTION: this function is called to verify and map table
  57. *
  58. *****************************************************************************/
  59. acpi_status acpi_tb_verify_table(struct acpi_table_desc *table_desc)
  60. {
  61. acpi_status status = AE_OK;
  62. ACPI_FUNCTION_TRACE(tb_verify_table);
  63. /* Map the table if necessary */
  64. if (!table_desc->pointer) {
  65. if ((table_desc->flags & ACPI_TABLE_ORIGIN_MASK) ==
  66. ACPI_TABLE_ORIGIN_MAPPED) {
  67. table_desc->pointer =
  68. acpi_os_map_memory(table_desc->address,
  69. table_desc->length);
  70. }
  71. if (!table_desc->pointer) {
  72. return_ACPI_STATUS(AE_NO_MEMORY);
  73. }
  74. }
  75. /* FACS is the odd table, has no standard ACPI header and no checksum */
  76. if (!ACPI_COMPARE_NAME(&table_desc->signature, ACPI_SIG_FACS)) {
  77. /* Always calculate checksum, ignore bad checksum if requested */
  78. status =
  79. acpi_tb_verify_checksum(table_desc->pointer,
  80. table_desc->length);
  81. }
  82. return_ACPI_STATUS(status);
  83. }
  84. /*******************************************************************************
  85. *
  86. * FUNCTION: acpi_tb_add_table
  87. *
  88. * PARAMETERS: table_desc - Table descriptor
  89. * table_index - Where the table index is returned
  90. *
  91. * RETURN: Status
  92. *
  93. * DESCRIPTION: This function is called to add an ACPI table. It is used to
  94. * dynamically load tables via the Load and load_table AML
  95. * operators.
  96. *
  97. ******************************************************************************/
  98. acpi_status
  99. acpi_tb_add_table(struct acpi_table_desc *table_desc, u32 *table_index)
  100. {
  101. u32 i;
  102. acpi_status status = AE_OK;
  103. struct acpi_table_header *override_table = NULL;
  104. ACPI_FUNCTION_TRACE(tb_add_table);
  105. if (!table_desc->pointer) {
  106. status = acpi_tb_verify_table(table_desc);
  107. if (ACPI_FAILURE(status) || !table_desc->pointer) {
  108. return_ACPI_STATUS(status);
  109. }
  110. }
  111. /*
  112. * Originally, we checked the table signature for "SSDT" or "PSDT" here.
  113. * Next, we added support for OEMx tables, signature "OEM".
  114. * Valid tables were encountered with a null signature, so we've just
  115. * given up on validating the signature, since it seems to be a waste
  116. * of code. The original code was removed (05/2008).
  117. */
  118. (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
  119. /* Check if table is already registered */
  120. for (i = 0; i < acpi_gbl_root_table_list.current_table_count; ++i) {
  121. if (!acpi_gbl_root_table_list.tables[i].pointer) {
  122. status =
  123. acpi_tb_verify_table(&acpi_gbl_root_table_list.
  124. tables[i]);
  125. if (ACPI_FAILURE(status)
  126. || !acpi_gbl_root_table_list.tables[i].pointer) {
  127. continue;
  128. }
  129. }
  130. /*
  131. * Check for a table match on the entire table length,
  132. * not just the header.
  133. */
  134. if (table_desc->length !=
  135. acpi_gbl_root_table_list.tables[i].length) {
  136. continue;
  137. }
  138. if (ACPI_MEMCMP(table_desc->pointer,
  139. acpi_gbl_root_table_list.tables[i].pointer,
  140. acpi_gbl_root_table_list.tables[i].length)) {
  141. continue;
  142. }
  143. /*
  144. * Note: the current mechanism does not unregister a table if it is
  145. * dynamically unloaded. The related namespace entries are deleted,
  146. * but the table remains in the root table list.
  147. *
  148. * The assumption here is that the number of different tables that
  149. * will be loaded is actually small, and there is minimal overhead
  150. * in just keeping the table in case it is needed again.
  151. *
  152. * If this assumption changes in the future (perhaps on large
  153. * machines with many table load/unload operations), tables will
  154. * need to be unregistered when they are unloaded, and slots in the
  155. * root table list should be reused when empty.
  156. */
  157. /*
  158. * Table is already registered.
  159. * We can delete the table that was passed as a parameter.
  160. */
  161. acpi_tb_delete_table(table_desc);
  162. *table_index = i;
  163. if (acpi_gbl_root_table_list.tables[i].
  164. flags & ACPI_TABLE_IS_LOADED) {
  165. /* Table is still loaded, this is an error */
  166. status = AE_ALREADY_EXISTS;
  167. goto release;
  168. } else {
  169. /* Table was unloaded, allow it to be reloaded */
  170. table_desc->pointer =
  171. acpi_gbl_root_table_list.tables[i].pointer;
  172. table_desc->address =
  173. acpi_gbl_root_table_list.tables[i].address;
  174. status = AE_OK;
  175. goto print_header;
  176. }
  177. }
  178. /*
  179. * ACPI Table Override:
  180. * Allow the host to override dynamically loaded tables.
  181. */
  182. status = acpi_os_table_override(table_desc->pointer, &override_table);
  183. if (ACPI_SUCCESS(status) && override_table) {
  184. ACPI_INFO((AE_INFO,
  185. "%4.4s @ 0x%p Table override, replaced with:",
  186. table_desc->pointer->signature,
  187. ACPI_CAST_PTR(void, table_desc->address)));
  188. /* We can delete the table that was passed as a parameter */
  189. acpi_tb_delete_table(table_desc);
  190. /* Setup descriptor for the new table */
  191. table_desc->address = ACPI_PTR_TO_PHYSADDR(override_table);
  192. table_desc->pointer = override_table;
  193. table_desc->length = override_table->length;
  194. table_desc->flags = ACPI_TABLE_ORIGIN_OVERRIDE;
  195. }
  196. /* Add the table to the global root table list */
  197. status = acpi_tb_store_table(table_desc->address, table_desc->pointer,
  198. table_desc->length, table_desc->flags,
  199. table_index);
  200. if (ACPI_FAILURE(status)) {
  201. goto release;
  202. }
  203. print_header:
  204. acpi_tb_print_table_header(table_desc->address, table_desc->pointer);
  205. release:
  206. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  207. return_ACPI_STATUS(status);
  208. }
  209. /*******************************************************************************
  210. *
  211. * FUNCTION: acpi_tb_resize_root_table_list
  212. *
  213. * PARAMETERS: None
  214. *
  215. * RETURN: Status
  216. *
  217. * DESCRIPTION: Expand the size of global table array
  218. *
  219. ******************************************************************************/
  220. acpi_status acpi_tb_resize_root_table_list(void)
  221. {
  222. struct acpi_table_desc *tables;
  223. ACPI_FUNCTION_TRACE(tb_resize_root_table_list);
  224. /* allow_resize flag is a parameter to acpi_initialize_tables */
  225. if (!(acpi_gbl_root_table_list.flags & ACPI_ROOT_ALLOW_RESIZE)) {
  226. ACPI_ERROR((AE_INFO,
  227. "Resize of Root Table Array is not allowed"));
  228. return_ACPI_STATUS(AE_SUPPORT);
  229. }
  230. /* Increase the Table Array size */
  231. tables = ACPI_ALLOCATE_ZEROED(((acpi_size) acpi_gbl_root_table_list.
  232. max_table_count +
  233. ACPI_ROOT_TABLE_SIZE_INCREMENT) *
  234. sizeof(struct acpi_table_desc));
  235. if (!tables) {
  236. ACPI_ERROR((AE_INFO,
  237. "Could not allocate new root table array"));
  238. return_ACPI_STATUS(AE_NO_MEMORY);
  239. }
  240. /* Copy and free the previous table array */
  241. if (acpi_gbl_root_table_list.tables) {
  242. ACPI_MEMCPY(tables, acpi_gbl_root_table_list.tables,
  243. (acpi_size) acpi_gbl_root_table_list.
  244. max_table_count * sizeof(struct acpi_table_desc));
  245. if (acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) {
  246. ACPI_FREE(acpi_gbl_root_table_list.tables);
  247. }
  248. }
  249. acpi_gbl_root_table_list.tables = tables;
  250. acpi_gbl_root_table_list.max_table_count +=
  251. ACPI_ROOT_TABLE_SIZE_INCREMENT;
  252. acpi_gbl_root_table_list.flags |= (u8)ACPI_ROOT_ORIGIN_ALLOCATED;
  253. return_ACPI_STATUS(AE_OK);
  254. }
  255. /*******************************************************************************
  256. *
  257. * FUNCTION: acpi_tb_store_table
  258. *
  259. * PARAMETERS: Address - Table address
  260. * Table - Table header
  261. * Length - Table length
  262. * Flags - flags
  263. *
  264. * RETURN: Status and table index.
  265. *
  266. * DESCRIPTION: Add an ACPI table to the global table list
  267. *
  268. ******************************************************************************/
  269. acpi_status
  270. acpi_tb_store_table(acpi_physical_address address,
  271. struct acpi_table_header *table,
  272. u32 length, u8 flags, u32 *table_index)
  273. {
  274. acpi_status status;
  275. struct acpi_table_desc *new_table;
  276. /* Ensure that there is room for the table in the Root Table List */
  277. if (acpi_gbl_root_table_list.current_table_count >=
  278. acpi_gbl_root_table_list.max_table_count) {
  279. status = acpi_tb_resize_root_table_list();
  280. if (ACPI_FAILURE(status)) {
  281. return (status);
  282. }
  283. }
  284. new_table =
  285. &acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.
  286. current_table_count];
  287. /* Initialize added table */
  288. new_table->address = address;
  289. new_table->pointer = table;
  290. new_table->length = length;
  291. new_table->owner_id = 0;
  292. new_table->flags = flags;
  293. ACPI_MOVE_32_TO_32(&new_table->signature, table->signature);
  294. *table_index = acpi_gbl_root_table_list.current_table_count;
  295. acpi_gbl_root_table_list.current_table_count++;
  296. return (AE_OK);
  297. }
  298. /*******************************************************************************
  299. *
  300. * FUNCTION: acpi_tb_delete_table
  301. *
  302. * PARAMETERS: table_index - Table index
  303. *
  304. * RETURN: None
  305. *
  306. * DESCRIPTION: Delete one internal ACPI table
  307. *
  308. ******************************************************************************/
  309. void acpi_tb_delete_table(struct acpi_table_desc *table_desc)
  310. {
  311. /* Table must be mapped or allocated */
  312. if (!table_desc->pointer) {
  313. return;
  314. }
  315. switch (table_desc->flags & ACPI_TABLE_ORIGIN_MASK) {
  316. case ACPI_TABLE_ORIGIN_MAPPED:
  317. acpi_os_unmap_memory(table_desc->pointer, table_desc->length);
  318. break;
  319. case ACPI_TABLE_ORIGIN_ALLOCATED:
  320. ACPI_FREE(table_desc->pointer);
  321. break;
  322. default:;
  323. }
  324. table_desc->pointer = NULL;
  325. }
  326. /*******************************************************************************
  327. *
  328. * FUNCTION: acpi_tb_terminate
  329. *
  330. * PARAMETERS: None
  331. *
  332. * RETURN: None
  333. *
  334. * DESCRIPTION: Delete all internal ACPI tables
  335. *
  336. ******************************************************************************/
  337. void acpi_tb_terminate(void)
  338. {
  339. u32 i;
  340. ACPI_FUNCTION_TRACE(tb_terminate);
  341. (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
  342. /* Delete the individual tables */
  343. for (i = 0; i < acpi_gbl_root_table_list.current_table_count; i++) {
  344. acpi_tb_delete_table(&acpi_gbl_root_table_list.tables[i]);
  345. }
  346. /*
  347. * Delete the root table array if allocated locally. Array cannot be
  348. * mapped, so we don't need to check for that flag.
  349. */
  350. if (acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) {
  351. ACPI_FREE(acpi_gbl_root_table_list.tables);
  352. }
  353. acpi_gbl_root_table_list.tables = NULL;
  354. acpi_gbl_root_table_list.flags = 0;
  355. acpi_gbl_root_table_list.current_table_count = 0;
  356. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "ACPI Tables freed\n"));
  357. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  358. }
  359. /*******************************************************************************
  360. *
  361. * FUNCTION: acpi_tb_delete_namespace_by_owner
  362. *
  363. * PARAMETERS: table_index - Table index
  364. *
  365. * RETURN: Status
  366. *
  367. * DESCRIPTION: Delete all namespace objects created when this table was loaded.
  368. *
  369. ******************************************************************************/
  370. acpi_status acpi_tb_delete_namespace_by_owner(u32 table_index)
  371. {
  372. acpi_owner_id owner_id;
  373. acpi_status status;
  374. ACPI_FUNCTION_TRACE(tb_delete_namespace_by_owner);
  375. status = acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
  376. if (ACPI_FAILURE(status)) {
  377. return_ACPI_STATUS(status);
  378. }
  379. if (table_index >= acpi_gbl_root_table_list.current_table_count) {
  380. /* The table index does not exist */
  381. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  382. return_ACPI_STATUS(AE_NOT_EXIST);
  383. }
  384. /* Get the owner ID for this table, used to delete namespace nodes */
  385. owner_id = acpi_gbl_root_table_list.tables[table_index].owner_id;
  386. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  387. /*
  388. * Need to acquire the namespace writer lock to prevent interference
  389. * with any concurrent namespace walks. The interpreter must be
  390. * released during the deletion since the acquisition of the deletion
  391. * lock may block, and also since the execution of a namespace walk
  392. * must be allowed to use the interpreter.
  393. */
  394. (void)acpi_ut_release_mutex(ACPI_MTX_INTERPRETER);
  395. status = acpi_ut_acquire_write_lock(&acpi_gbl_namespace_rw_lock);
  396. acpi_ns_delete_namespace_by_owner(owner_id);
  397. if (ACPI_FAILURE(status)) {
  398. return_ACPI_STATUS(status);
  399. }
  400. acpi_ut_release_write_lock(&acpi_gbl_namespace_rw_lock);
  401. status = acpi_ut_acquire_mutex(ACPI_MTX_INTERPRETER);
  402. return_ACPI_STATUS(status);
  403. }
  404. /*******************************************************************************
  405. *
  406. * FUNCTION: acpi_tb_allocate_owner_id
  407. *
  408. * PARAMETERS: table_index - Table index
  409. *
  410. * RETURN: Status
  411. *
  412. * DESCRIPTION: Allocates owner_id in table_desc
  413. *
  414. ******************************************************************************/
  415. acpi_status acpi_tb_allocate_owner_id(u32 table_index)
  416. {
  417. acpi_status status = AE_BAD_PARAMETER;
  418. ACPI_FUNCTION_TRACE(tb_allocate_owner_id);
  419. (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
  420. if (table_index < acpi_gbl_root_table_list.current_table_count) {
  421. status = acpi_ut_allocate_owner_id
  422. (&(acpi_gbl_root_table_list.tables[table_index].owner_id));
  423. }
  424. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  425. return_ACPI_STATUS(status);
  426. }
  427. /*******************************************************************************
  428. *
  429. * FUNCTION: acpi_tb_release_owner_id
  430. *
  431. * PARAMETERS: table_index - Table index
  432. *
  433. * RETURN: Status
  434. *
  435. * DESCRIPTION: Releases owner_id in table_desc
  436. *
  437. ******************************************************************************/
  438. acpi_status acpi_tb_release_owner_id(u32 table_index)
  439. {
  440. acpi_status status = AE_BAD_PARAMETER;
  441. ACPI_FUNCTION_TRACE(tb_release_owner_id);
  442. (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
  443. if (table_index < acpi_gbl_root_table_list.current_table_count) {
  444. acpi_ut_release_owner_id(&
  445. (acpi_gbl_root_table_list.
  446. tables[table_index].owner_id));
  447. status = AE_OK;
  448. }
  449. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  450. return_ACPI_STATUS(status);
  451. }
  452. /*******************************************************************************
  453. *
  454. * FUNCTION: acpi_tb_get_owner_id
  455. *
  456. * PARAMETERS: table_index - Table index
  457. * owner_id - Where the table owner_id is returned
  458. *
  459. * RETURN: Status
  460. *
  461. * DESCRIPTION: returns owner_id for the ACPI table
  462. *
  463. ******************************************************************************/
  464. acpi_status acpi_tb_get_owner_id(u32 table_index, acpi_owner_id *owner_id)
  465. {
  466. acpi_status status = AE_BAD_PARAMETER;
  467. ACPI_FUNCTION_TRACE(tb_get_owner_id);
  468. (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
  469. if (table_index < acpi_gbl_root_table_list.current_table_count) {
  470. *owner_id =
  471. acpi_gbl_root_table_list.tables[table_index].owner_id;
  472. status = AE_OK;
  473. }
  474. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  475. return_ACPI_STATUS(status);
  476. }
  477. /*******************************************************************************
  478. *
  479. * FUNCTION: acpi_tb_is_table_loaded
  480. *
  481. * PARAMETERS: table_index - Table index
  482. *
  483. * RETURN: Table Loaded Flag
  484. *
  485. ******************************************************************************/
  486. u8 acpi_tb_is_table_loaded(u32 table_index)
  487. {
  488. u8 is_loaded = FALSE;
  489. (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
  490. if (table_index < acpi_gbl_root_table_list.current_table_count) {
  491. is_loaded = (u8)
  492. (acpi_gbl_root_table_list.tables[table_index].flags &
  493. ACPI_TABLE_IS_LOADED);
  494. }
  495. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  496. return (is_loaded);
  497. }
  498. /*******************************************************************************
  499. *
  500. * FUNCTION: acpi_tb_set_table_loaded_flag
  501. *
  502. * PARAMETERS: table_index - Table index
  503. * is_loaded - TRUE if table is loaded, FALSE otherwise
  504. *
  505. * RETURN: None
  506. *
  507. * DESCRIPTION: Sets the table loaded flag to either TRUE or FALSE.
  508. *
  509. ******************************************************************************/
  510. void acpi_tb_set_table_loaded_flag(u32 table_index, u8 is_loaded)
  511. {
  512. (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
  513. if (table_index < acpi_gbl_root_table_list.current_table_count) {
  514. if (is_loaded) {
  515. acpi_gbl_root_table_list.tables[table_index].flags |=
  516. ACPI_TABLE_IS_LOADED;
  517. } else {
  518. acpi_gbl_root_table_list.tables[table_index].flags &=
  519. ~ACPI_TABLE_IS_LOADED;
  520. }
  521. }
  522. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  523. }