tbinstal.c 16 KB

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