tbinstal.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  1. /******************************************************************************
  2. *
  3. * Module Name: tbinstal - ACPI table installation and removal
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2008, 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.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. size +
  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.size *
  244. 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.size += ACPI_ROOT_TABLE_SIZE_INCREMENT;
  251. acpi_gbl_root_table_list.flags |= (u8) ACPI_ROOT_ORIGIN_ALLOCATED;
  252. return_ACPI_STATUS(AE_OK);
  253. }
  254. /*******************************************************************************
  255. *
  256. * FUNCTION: acpi_tb_store_table
  257. *
  258. * PARAMETERS: Address - Table address
  259. * Table - Table header
  260. * Length - Table length
  261. * Flags - flags
  262. *
  263. * RETURN: Status and table index.
  264. *
  265. * DESCRIPTION: Add an ACPI table to the global table list
  266. *
  267. ******************************************************************************/
  268. acpi_status
  269. acpi_tb_store_table(acpi_physical_address address,
  270. struct acpi_table_header *table,
  271. u32 length, u8 flags, u32 *table_index)
  272. {
  273. acpi_status status = AE_OK;
  274. /* Ensure that there is room for the table in the Root Table List */
  275. if (acpi_gbl_root_table_list.count >= acpi_gbl_root_table_list.size) {
  276. status = acpi_tb_resize_root_table_list();
  277. if (ACPI_FAILURE(status)) {
  278. return (status);
  279. }
  280. }
  281. /* Initialize added table */
  282. acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.count].
  283. address = address;
  284. acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.count].
  285. pointer = table;
  286. acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.count].length =
  287. length;
  288. acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.count].
  289. owner_id = 0;
  290. acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.count].flags =
  291. flags;
  292. ACPI_MOVE_32_TO_32(&
  293. (acpi_gbl_root_table_list.
  294. tables[acpi_gbl_root_table_list.count].signature),
  295. table->signature);
  296. *table_index = acpi_gbl_root_table_list.count;
  297. acpi_gbl_root_table_list.count++;
  298. return (status);
  299. }
  300. /*******************************************************************************
  301. *
  302. * FUNCTION: acpi_tb_delete_table
  303. *
  304. * PARAMETERS: table_index - Table index
  305. *
  306. * RETURN: None
  307. *
  308. * DESCRIPTION: Delete one internal ACPI table
  309. *
  310. ******************************************************************************/
  311. void acpi_tb_delete_table(struct acpi_table_desc *table_desc)
  312. {
  313. /* Table must be mapped or allocated */
  314. if (!table_desc->pointer) {
  315. return;
  316. }
  317. switch (table_desc->flags & ACPI_TABLE_ORIGIN_MASK) {
  318. case ACPI_TABLE_ORIGIN_MAPPED:
  319. acpi_os_unmap_memory(table_desc->pointer, table_desc->length);
  320. break;
  321. case ACPI_TABLE_ORIGIN_ALLOCATED:
  322. ACPI_FREE(table_desc->pointer);
  323. break;
  324. default:;
  325. }
  326. table_desc->pointer = NULL;
  327. }
  328. /*******************************************************************************
  329. *
  330. * FUNCTION: acpi_tb_terminate
  331. *
  332. * PARAMETERS: None
  333. *
  334. * RETURN: None
  335. *
  336. * DESCRIPTION: Delete all internal ACPI tables
  337. *
  338. ******************************************************************************/
  339. void acpi_tb_terminate(void)
  340. {
  341. u32 i;
  342. ACPI_FUNCTION_TRACE(tb_terminate);
  343. (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
  344. /* Delete the individual tables */
  345. for (i = 0; i < acpi_gbl_root_table_list.count; ++i) {
  346. acpi_tb_delete_table(&acpi_gbl_root_table_list.tables[i]);
  347. }
  348. /*
  349. * Delete the root table array if allocated locally. Array cannot be
  350. * mapped, so we don't need to check for that flag.
  351. */
  352. if (acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) {
  353. ACPI_FREE(acpi_gbl_root_table_list.tables);
  354. }
  355. acpi_gbl_root_table_list.tables = NULL;
  356. acpi_gbl_root_table_list.flags = 0;
  357. acpi_gbl_root_table_list.count = 0;
  358. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "ACPI Tables freed\n"));
  359. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  360. }
  361. /*******************************************************************************
  362. *
  363. * FUNCTION: acpi_tb_delete_namespace_by_owner
  364. *
  365. * PARAMETERS: table_index - Table index
  366. *
  367. * RETURN: Status
  368. *
  369. * DESCRIPTION: Delete all namespace objects created when this table was loaded.
  370. *
  371. ******************************************************************************/
  372. acpi_status acpi_tb_delete_namespace_by_owner(u32 table_index)
  373. {
  374. acpi_owner_id owner_id;
  375. acpi_status status;
  376. ACPI_FUNCTION_TRACE(tb_delete_namespace_by_owner);
  377. status = acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
  378. if (ACPI_FAILURE(status)) {
  379. return_ACPI_STATUS(status);
  380. }
  381. if (table_index >= acpi_gbl_root_table_list.count) {
  382. /* The table index does not exist */
  383. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  384. return_ACPI_STATUS(AE_NOT_EXIST);
  385. }
  386. /* Get the owner ID for this table, used to delete namespace nodes */
  387. owner_id = acpi_gbl_root_table_list.tables[table_index].owner_id;
  388. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  389. /*
  390. * Need to acquire the namespace writer lock to prevent interference
  391. * with any concurrent namespace walks. The interpreter must be
  392. * released during the deletion since the acquisition of the deletion
  393. * lock may block, and also since the execution of a namespace walk
  394. * must be allowed to use the interpreter.
  395. */
  396. acpi_ut_release_mutex(ACPI_MTX_INTERPRETER);
  397. status = acpi_ut_acquire_write_lock(&acpi_gbl_namespace_rw_lock);
  398. acpi_ns_delete_namespace_by_owner(owner_id);
  399. if (ACPI_FAILURE(status)) {
  400. return_ACPI_STATUS(status);
  401. }
  402. acpi_ut_release_write_lock(&acpi_gbl_namespace_rw_lock);
  403. status = acpi_ut_acquire_mutex(ACPI_MTX_INTERPRETER);
  404. return_ACPI_STATUS(status);
  405. }
  406. /*******************************************************************************
  407. *
  408. * FUNCTION: acpi_tb_allocate_owner_id
  409. *
  410. * PARAMETERS: table_index - Table index
  411. *
  412. * RETURN: Status
  413. *
  414. * DESCRIPTION: Allocates owner_id in table_desc
  415. *
  416. ******************************************************************************/
  417. acpi_status acpi_tb_allocate_owner_id(u32 table_index)
  418. {
  419. acpi_status status = AE_BAD_PARAMETER;
  420. ACPI_FUNCTION_TRACE(tb_allocate_owner_id);
  421. (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
  422. if (table_index < acpi_gbl_root_table_list.count) {
  423. status = acpi_ut_allocate_owner_id
  424. (&(acpi_gbl_root_table_list.tables[table_index].owner_id));
  425. }
  426. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  427. return_ACPI_STATUS(status);
  428. }
  429. /*******************************************************************************
  430. *
  431. * FUNCTION: acpi_tb_release_owner_id
  432. *
  433. * PARAMETERS: table_index - Table index
  434. *
  435. * RETURN: Status
  436. *
  437. * DESCRIPTION: Releases owner_id in table_desc
  438. *
  439. ******************************************************************************/
  440. acpi_status acpi_tb_release_owner_id(u32 table_index)
  441. {
  442. acpi_status status = AE_BAD_PARAMETER;
  443. ACPI_FUNCTION_TRACE(tb_release_owner_id);
  444. (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
  445. if (table_index < acpi_gbl_root_table_list.count) {
  446. acpi_ut_release_owner_id(&
  447. (acpi_gbl_root_table_list.
  448. tables[table_index].owner_id));
  449. status = AE_OK;
  450. }
  451. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  452. return_ACPI_STATUS(status);
  453. }
  454. /*******************************************************************************
  455. *
  456. * FUNCTION: acpi_tb_get_owner_id
  457. *
  458. * PARAMETERS: table_index - Table index
  459. * owner_id - Where the table owner_id is returned
  460. *
  461. * RETURN: Status
  462. *
  463. * DESCRIPTION: returns owner_id for the ACPI table
  464. *
  465. ******************************************************************************/
  466. acpi_status acpi_tb_get_owner_id(u32 table_index, acpi_owner_id *owner_id)
  467. {
  468. acpi_status status = AE_BAD_PARAMETER;
  469. ACPI_FUNCTION_TRACE(tb_get_owner_id);
  470. (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
  471. if (table_index < acpi_gbl_root_table_list.count) {
  472. *owner_id =
  473. acpi_gbl_root_table_list.tables[table_index].owner_id;
  474. status = AE_OK;
  475. }
  476. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  477. return_ACPI_STATUS(status);
  478. }
  479. /*******************************************************************************
  480. *
  481. * FUNCTION: acpi_tb_is_table_loaded
  482. *
  483. * PARAMETERS: table_index - Table index
  484. *
  485. * RETURN: Table Loaded Flag
  486. *
  487. ******************************************************************************/
  488. u8 acpi_tb_is_table_loaded(u32 table_index)
  489. {
  490. u8 is_loaded = FALSE;
  491. (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
  492. if (table_index < acpi_gbl_root_table_list.count) {
  493. is_loaded = (u8)
  494. (acpi_gbl_root_table_list.tables[table_index].flags &
  495. ACPI_TABLE_IS_LOADED);
  496. }
  497. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  498. return (is_loaded);
  499. }
  500. /*******************************************************************************
  501. *
  502. * FUNCTION: acpi_tb_set_table_loaded_flag
  503. *
  504. * PARAMETERS: table_index - Table index
  505. * is_loaded - TRUE if table is loaded, FALSE otherwise
  506. *
  507. * RETURN: None
  508. *
  509. * DESCRIPTION: Sets the table loaded flag to either TRUE or FALSE.
  510. *
  511. ******************************************************************************/
  512. void acpi_tb_set_table_loaded_flag(u32 table_index, u8 is_loaded)
  513. {
  514. (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
  515. if (table_index < acpi_gbl_root_table_list.count) {
  516. if (is_loaded) {
  517. acpi_gbl_root_table_list.tables[table_index].flags |=
  518. ACPI_TABLE_IS_LOADED;
  519. } else {
  520. acpi_gbl_root_table_list.tables[table_index].flags &=
  521. ~ACPI_TABLE_IS_LOADED;
  522. }
  523. }
  524. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  525. }