tbinstal.c 16 KB

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