tbinstal.c 15 KB

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