tbinstal.c 15 KB

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