tbinstal.c 15 KB

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