tbinstal.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574
  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 the ACPI table
  94. *
  95. ******************************************************************************/
  96. acpi_status
  97. acpi_tb_add_table(struct acpi_table_desc *table_desc, u32 *table_index)
  98. {
  99. u32 i;
  100. acpi_status status = AE_OK;
  101. ACPI_FUNCTION_TRACE(tb_add_table);
  102. if (!table_desc->pointer) {
  103. status = acpi_tb_verify_table(table_desc);
  104. if (ACPI_FAILURE(status) || !table_desc->pointer) {
  105. return_ACPI_STATUS(status);
  106. }
  107. }
  108. /*
  109. * Originally, we checked the table signature for "SSDT" or "PSDT" here.
  110. * Next, we added support for OEMx tables, signature "OEM".
  111. * Valid tables were encountered with a null signature, so we've just
  112. * given up on validating the signature, since it seems to be a waste
  113. * of code. The original code was removed (05/2008).
  114. */
  115. (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
  116. /* Check if table is already registered */
  117. for (i = 0; i < acpi_gbl_root_table_list.count; ++i) {
  118. if (!acpi_gbl_root_table_list.tables[i].pointer) {
  119. status =
  120. acpi_tb_verify_table(&acpi_gbl_root_table_list.
  121. tables[i]);
  122. if (ACPI_FAILURE(status)
  123. || !acpi_gbl_root_table_list.tables[i].pointer) {
  124. continue;
  125. }
  126. }
  127. /*
  128. * Check for a table match on the entire table length,
  129. * not just the header.
  130. */
  131. if (table_desc->length !=
  132. acpi_gbl_root_table_list.tables[i].length) {
  133. continue;
  134. }
  135. if (ACPI_MEMCMP(table_desc->pointer,
  136. acpi_gbl_root_table_list.tables[i].pointer,
  137. acpi_gbl_root_table_list.tables[i].length)) {
  138. continue;
  139. }
  140. /*
  141. * Note: the current mechanism does not unregister a table if it is
  142. * dynamically unloaded. The related namespace entries are deleted,
  143. * but the table remains in the root table list.
  144. *
  145. * The assumption here is that the number of different tables that
  146. * will be loaded is actually small, and there is minimal overhead
  147. * in just keeping the table in case it is needed again.
  148. *
  149. * If this assumption changes in the future (perhaps on large
  150. * machines with many table load/unload operations), tables will
  151. * need to be unregistered when they are unloaded, and slots in the
  152. * root table list should be reused when empty.
  153. */
  154. /*
  155. * Table is already registered.
  156. * We can delete the table that was passed as a parameter.
  157. */
  158. acpi_tb_delete_table(table_desc);
  159. *table_index = i;
  160. if (acpi_gbl_root_table_list.tables[i].
  161. flags & ACPI_TABLE_IS_LOADED) {
  162. /* Table is still loaded, this is an error */
  163. status = AE_ALREADY_EXISTS;
  164. goto release;
  165. } else {
  166. /* Table was unloaded, allow it to be reloaded */
  167. table_desc->pointer =
  168. acpi_gbl_root_table_list.tables[i].pointer;
  169. table_desc->address =
  170. acpi_gbl_root_table_list.tables[i].address;
  171. status = AE_OK;
  172. goto print_header;
  173. }
  174. }
  175. /* Add the table to the global root table list */
  176. status = acpi_tb_store_table(table_desc->address, table_desc->pointer,
  177. table_desc->length, table_desc->flags,
  178. table_index);
  179. if (ACPI_FAILURE(status)) {
  180. goto release;
  181. }
  182. print_header:
  183. acpi_tb_print_table_header(table_desc->address, table_desc->pointer);
  184. release:
  185. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  186. return_ACPI_STATUS(status);
  187. }
  188. /*******************************************************************************
  189. *
  190. * FUNCTION: acpi_tb_resize_root_table_list
  191. *
  192. * PARAMETERS: None
  193. *
  194. * RETURN: Status
  195. *
  196. * DESCRIPTION: Expand the size of global table array
  197. *
  198. ******************************************************************************/
  199. acpi_status acpi_tb_resize_root_table_list(void)
  200. {
  201. struct acpi_table_desc *tables;
  202. ACPI_FUNCTION_TRACE(tb_resize_root_table_list);
  203. /* allow_resize flag is a parameter to acpi_initialize_tables */
  204. if (!(acpi_gbl_root_table_list.flags & ACPI_ROOT_ALLOW_RESIZE)) {
  205. ACPI_ERROR((AE_INFO,
  206. "Resize of Root Table Array is not allowed"));
  207. return_ACPI_STATUS(AE_SUPPORT);
  208. }
  209. /* Increase the Table Array size */
  210. tables = ACPI_ALLOCATE_ZEROED(((acpi_size) acpi_gbl_root_table_list.
  211. size + ACPI_ROOT_TABLE_SIZE_INCREMENT)
  212. * sizeof(struct acpi_table_desc));
  213. if (!tables) {
  214. ACPI_ERROR((AE_INFO,
  215. "Could not allocate new root table array"));
  216. return_ACPI_STATUS(AE_NO_MEMORY);
  217. }
  218. /* Copy and free the previous table array */
  219. if (acpi_gbl_root_table_list.tables) {
  220. ACPI_MEMCPY(tables, acpi_gbl_root_table_list.tables,
  221. (acpi_size) acpi_gbl_root_table_list.size *
  222. sizeof(struct acpi_table_desc));
  223. if (acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) {
  224. ACPI_FREE(acpi_gbl_root_table_list.tables);
  225. }
  226. }
  227. acpi_gbl_root_table_list.tables = tables;
  228. acpi_gbl_root_table_list.size += ACPI_ROOT_TABLE_SIZE_INCREMENT;
  229. acpi_gbl_root_table_list.flags |= (u8) ACPI_ROOT_ORIGIN_ALLOCATED;
  230. return_ACPI_STATUS(AE_OK);
  231. }
  232. /*******************************************************************************
  233. *
  234. * FUNCTION: acpi_tb_store_table
  235. *
  236. * PARAMETERS: Address - Table address
  237. * Table - Table header
  238. * Length - Table length
  239. * Flags - flags
  240. *
  241. * RETURN: Status and table index.
  242. *
  243. * DESCRIPTION: Add an ACPI table to the global table list
  244. *
  245. ******************************************************************************/
  246. acpi_status
  247. acpi_tb_store_table(acpi_physical_address address,
  248. struct acpi_table_header *table,
  249. u32 length, u8 flags, u32 *table_index)
  250. {
  251. acpi_status status = AE_OK;
  252. /* Ensure that there is room for the table in the Root Table List */
  253. if (acpi_gbl_root_table_list.count >= acpi_gbl_root_table_list.size) {
  254. status = acpi_tb_resize_root_table_list();
  255. if (ACPI_FAILURE(status)) {
  256. return (status);
  257. }
  258. }
  259. /* Initialize added table */
  260. acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.count].
  261. address = address;
  262. acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.count].
  263. pointer = table;
  264. acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.count].length =
  265. length;
  266. acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.count].
  267. owner_id = 0;
  268. acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.count].flags =
  269. flags;
  270. ACPI_MOVE_32_TO_32(&
  271. (acpi_gbl_root_table_list.
  272. tables[acpi_gbl_root_table_list.count].signature),
  273. table->signature);
  274. *table_index = acpi_gbl_root_table_list.count;
  275. acpi_gbl_root_table_list.count++;
  276. return (status);
  277. }
  278. /*******************************************************************************
  279. *
  280. * FUNCTION: acpi_tb_delete_table
  281. *
  282. * PARAMETERS: table_index - Table index
  283. *
  284. * RETURN: None
  285. *
  286. * DESCRIPTION: Delete one internal ACPI table
  287. *
  288. ******************************************************************************/
  289. void acpi_tb_delete_table(struct acpi_table_desc *table_desc)
  290. {
  291. /* Table must be mapped or allocated */
  292. if (!table_desc->pointer) {
  293. return;
  294. }
  295. switch (table_desc->flags & ACPI_TABLE_ORIGIN_MASK) {
  296. case ACPI_TABLE_ORIGIN_MAPPED:
  297. acpi_os_unmap_memory(table_desc->pointer, table_desc->length);
  298. break;
  299. case ACPI_TABLE_ORIGIN_ALLOCATED:
  300. ACPI_FREE(table_desc->pointer);
  301. break;
  302. default:;
  303. }
  304. table_desc->pointer = NULL;
  305. }
  306. /*******************************************************************************
  307. *
  308. * FUNCTION: acpi_tb_terminate
  309. *
  310. * PARAMETERS: None
  311. *
  312. * RETURN: None
  313. *
  314. * DESCRIPTION: Delete all internal ACPI tables
  315. *
  316. ******************************************************************************/
  317. void acpi_tb_terminate(void)
  318. {
  319. u32 i;
  320. ACPI_FUNCTION_TRACE(tb_terminate);
  321. (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
  322. /* Delete the individual tables */
  323. for (i = 0; i < acpi_gbl_root_table_list.count; ++i) {
  324. acpi_tb_delete_table(&acpi_gbl_root_table_list.tables[i]);
  325. }
  326. /*
  327. * Delete the root table array if allocated locally. Array cannot be
  328. * mapped, so we don't need to check for that flag.
  329. */
  330. if (acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) {
  331. ACPI_FREE(acpi_gbl_root_table_list.tables);
  332. }
  333. acpi_gbl_root_table_list.tables = NULL;
  334. acpi_gbl_root_table_list.flags = 0;
  335. acpi_gbl_root_table_list.count = 0;
  336. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "ACPI Tables freed\n"));
  337. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  338. }
  339. /*******************************************************************************
  340. *
  341. * FUNCTION: acpi_tb_delete_namespace_by_owner
  342. *
  343. * PARAMETERS: table_index - Table index
  344. *
  345. * RETURN: None
  346. *
  347. * DESCRIPTION: Delete all namespace objects created when this table was loaded.
  348. *
  349. ******************************************************************************/
  350. void acpi_tb_delete_namespace_by_owner(u32 table_index)
  351. {
  352. acpi_owner_id owner_id;
  353. (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
  354. if (table_index < acpi_gbl_root_table_list.count) {
  355. owner_id =
  356. acpi_gbl_root_table_list.tables[table_index].owner_id;
  357. } else {
  358. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  359. return;
  360. }
  361. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  362. acpi_ns_delete_namespace_by_owner(owner_id);
  363. }
  364. /*******************************************************************************
  365. *
  366. * FUNCTION: acpi_tb_allocate_owner_id
  367. *
  368. * PARAMETERS: table_index - Table index
  369. *
  370. * RETURN: Status
  371. *
  372. * DESCRIPTION: Allocates owner_id in table_desc
  373. *
  374. ******************************************************************************/
  375. acpi_status acpi_tb_allocate_owner_id(u32 table_index)
  376. {
  377. acpi_status status = AE_BAD_PARAMETER;
  378. ACPI_FUNCTION_TRACE(tb_allocate_owner_id);
  379. (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
  380. if (table_index < acpi_gbl_root_table_list.count) {
  381. status = acpi_ut_allocate_owner_id
  382. (&(acpi_gbl_root_table_list.tables[table_index].owner_id));
  383. }
  384. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  385. return_ACPI_STATUS(status);
  386. }
  387. /*******************************************************************************
  388. *
  389. * FUNCTION: acpi_tb_release_owner_id
  390. *
  391. * PARAMETERS: table_index - Table index
  392. *
  393. * RETURN: Status
  394. *
  395. * DESCRIPTION: Releases owner_id in table_desc
  396. *
  397. ******************************************************************************/
  398. acpi_status acpi_tb_release_owner_id(u32 table_index)
  399. {
  400. acpi_status status = AE_BAD_PARAMETER;
  401. ACPI_FUNCTION_TRACE(tb_release_owner_id);
  402. (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
  403. if (table_index < acpi_gbl_root_table_list.count) {
  404. acpi_ut_release_owner_id(&
  405. (acpi_gbl_root_table_list.
  406. tables[table_index].owner_id));
  407. status = AE_OK;
  408. }
  409. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  410. return_ACPI_STATUS(status);
  411. }
  412. /*******************************************************************************
  413. *
  414. * FUNCTION: acpi_tb_get_owner_id
  415. *
  416. * PARAMETERS: table_index - Table index
  417. * owner_id - Where the table owner_id is returned
  418. *
  419. * RETURN: Status
  420. *
  421. * DESCRIPTION: returns owner_id for the ACPI table
  422. *
  423. ******************************************************************************/
  424. acpi_status acpi_tb_get_owner_id(u32 table_index, acpi_owner_id *owner_id)
  425. {
  426. acpi_status status = AE_BAD_PARAMETER;
  427. ACPI_FUNCTION_TRACE(tb_get_owner_id);
  428. (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
  429. if (table_index < acpi_gbl_root_table_list.count) {
  430. *owner_id =
  431. acpi_gbl_root_table_list.tables[table_index].owner_id;
  432. status = AE_OK;
  433. }
  434. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  435. return_ACPI_STATUS(status);
  436. }
  437. /*******************************************************************************
  438. *
  439. * FUNCTION: acpi_tb_is_table_loaded
  440. *
  441. * PARAMETERS: table_index - Table index
  442. *
  443. * RETURN: Table Loaded Flag
  444. *
  445. ******************************************************************************/
  446. u8 acpi_tb_is_table_loaded(u32 table_index)
  447. {
  448. u8 is_loaded = FALSE;
  449. (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
  450. if (table_index < acpi_gbl_root_table_list.count) {
  451. is_loaded = (u8)
  452. (acpi_gbl_root_table_list.tables[table_index].
  453. flags & ACPI_TABLE_IS_LOADED);
  454. }
  455. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  456. return (is_loaded);
  457. }
  458. /*******************************************************************************
  459. *
  460. * FUNCTION: acpi_tb_set_table_loaded_flag
  461. *
  462. * PARAMETERS: table_index - Table index
  463. * is_loaded - TRUE if table is loaded, FALSE otherwise
  464. *
  465. * RETURN: None
  466. *
  467. * DESCRIPTION: Sets the table loaded flag to either TRUE or FALSE.
  468. *
  469. ******************************************************************************/
  470. void acpi_tb_set_table_loaded_flag(u32 table_index, u8 is_loaded)
  471. {
  472. (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
  473. if (table_index < acpi_gbl_root_table_list.count) {
  474. if (is_loaded) {
  475. acpi_gbl_root_table_list.tables[table_index].flags |=
  476. ACPI_TABLE_IS_LOADED;
  477. } else {
  478. acpi_gbl_root_table_list.tables[table_index].flags &=
  479. ~ACPI_TABLE_IS_LOADED;
  480. }
  481. }
  482. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  483. }