tbinstal.c 15 KB

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