tbinstal.c 16 KB

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