tbinstal.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580
  1. /******************************************************************************
  2. *
  3. * Module Name: tbinstal - ACPI table installation and removal
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2005, 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/actables.h>
  44. #define _COMPONENT ACPI_TABLES
  45. ACPI_MODULE_NAME ("tbinstal")
  46. /* Local prototypes */
  47. static acpi_status
  48. acpi_tb_match_signature (
  49. char *signature,
  50. struct acpi_table_desc *table_info,
  51. u8 search_type);
  52. /*******************************************************************************
  53. *
  54. * FUNCTION: acpi_tb_match_signature
  55. *
  56. * PARAMETERS: Signature - Table signature to match
  57. * table_info - Return data
  58. * search_type - Table type to match (primary/secondary)
  59. *
  60. * RETURN: Status
  61. *
  62. * DESCRIPTION: Compare signature against the list of "ACPI-subsystem-owned"
  63. * tables (DSDT/FADT/SSDT, etc.) Returns the table_type_iD on match.
  64. *
  65. ******************************************************************************/
  66. static acpi_status
  67. acpi_tb_match_signature (
  68. char *signature,
  69. struct acpi_table_desc *table_info,
  70. u8 search_type)
  71. {
  72. acpi_native_uint i;
  73. ACPI_FUNCTION_TRACE ("tb_match_signature");
  74. /* Search for a signature match among the known table types */
  75. for (i = 0; i < NUM_ACPI_TABLE_TYPES; i++) {
  76. if (!(acpi_gbl_table_data[i].flags & search_type)) {
  77. continue;
  78. }
  79. if (!ACPI_STRNCMP (signature, acpi_gbl_table_data[i].signature,
  80. acpi_gbl_table_data[i].sig_length)) {
  81. /* Found a signature match, return index if requested */
  82. if (table_info) {
  83. table_info->type = (u8) i;
  84. }
  85. ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
  86. "Table [%4.4s] is an ACPI table consumed by the core subsystem\n",
  87. (char *) acpi_gbl_table_data[i].signature));
  88. return_ACPI_STATUS (AE_OK);
  89. }
  90. }
  91. ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
  92. "Table [%4.4s] is not an ACPI table consumed by the core subsystem - ignored\n",
  93. (char *) signature));
  94. return_ACPI_STATUS (AE_TABLE_NOT_SUPPORTED);
  95. }
  96. /*******************************************************************************
  97. *
  98. * FUNCTION: acpi_tb_install_table
  99. *
  100. * PARAMETERS: table_info - Return value from acpi_tb_get_table_body
  101. *
  102. * RETURN: Status
  103. *
  104. * DESCRIPTION: Install the table into the global data structures.
  105. *
  106. ******************************************************************************/
  107. acpi_status
  108. acpi_tb_install_table (
  109. struct acpi_table_desc *table_info)
  110. {
  111. acpi_status status;
  112. ACPI_FUNCTION_TRACE ("tb_install_table");
  113. /* Lock tables while installing */
  114. status = acpi_ut_acquire_mutex (ACPI_MTX_TABLES);
  115. if (ACPI_FAILURE (status)) {
  116. ACPI_REPORT_ERROR (("Could not acquire table mutex, %s\n",
  117. acpi_format_exception (status)));
  118. return_ACPI_STATUS (status);
  119. }
  120. /*
  121. * Ignore a table that is already installed. For example, some BIOS
  122. * ASL code will repeatedly attempt to load the same SSDT.
  123. */
  124. status = acpi_tb_is_table_installed (table_info);
  125. if (ACPI_FAILURE (status)) {
  126. goto unlock_and_exit;
  127. }
  128. /* Install the table into the global data structure */
  129. status = acpi_tb_init_table_descriptor (table_info->type, table_info);
  130. if (ACPI_FAILURE (status)) {
  131. ACPI_REPORT_ERROR (("Could not install table [%4.4s], %s\n",
  132. table_info->pointer->signature, acpi_format_exception (status)));
  133. }
  134. ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "%s located at %p\n",
  135. acpi_gbl_table_data[table_info->type].name, table_info->pointer));
  136. unlock_and_exit:
  137. (void) acpi_ut_release_mutex (ACPI_MTX_TABLES);
  138. return_ACPI_STATUS (status);
  139. }
  140. /*******************************************************************************
  141. *
  142. * FUNCTION: acpi_tb_recognize_table
  143. *
  144. * PARAMETERS: table_info - Return value from acpi_tb_get_table_body
  145. * search_type - Table type to match (primary/secondary)
  146. *
  147. * RETURN: Status
  148. *
  149. * DESCRIPTION: Check a table signature for a match against known table types
  150. *
  151. * NOTE: All table pointers are validated as follows:
  152. * 1) Table pointer must point to valid physical memory
  153. * 2) Signature must be 4 ASCII chars, even if we don't recognize the
  154. * name
  155. * 3) Table must be readable for length specified in the header
  156. * 4) Table checksum must be valid (with the exception of the FACS
  157. * which has no checksum for some odd reason)
  158. *
  159. ******************************************************************************/
  160. acpi_status
  161. acpi_tb_recognize_table (
  162. struct acpi_table_desc *table_info,
  163. u8 search_type)
  164. {
  165. struct acpi_table_header *table_header;
  166. acpi_status status;
  167. ACPI_FUNCTION_TRACE ("tb_recognize_table");
  168. /* Ensure that we have a valid table pointer */
  169. table_header = (struct acpi_table_header *) table_info->pointer;
  170. if (!table_header) {
  171. return_ACPI_STATUS (AE_BAD_PARAMETER);
  172. }
  173. /*
  174. * We only "recognize" a limited number of ACPI tables -- namely, the
  175. * ones that are used by the subsystem (DSDT, FADT, etc.)
  176. *
  177. * An AE_TABLE_NOT_SUPPORTED means that the table was not recognized.
  178. * This can be any one of many valid ACPI tables, it just isn't one of
  179. * the tables that is consumed by the core subsystem
  180. */
  181. status = acpi_tb_match_signature (table_header->signature,
  182. table_info, search_type);
  183. if (ACPI_FAILURE (status)) {
  184. return_ACPI_STATUS (status);
  185. }
  186. status = acpi_tb_validate_table_header (table_header);
  187. if (ACPI_FAILURE (status)) {
  188. return_ACPI_STATUS (status);
  189. }
  190. /* Return the table type and length via the info struct */
  191. table_info->length = (acpi_size) table_header->length;
  192. return_ACPI_STATUS (status);
  193. }
  194. /*******************************************************************************
  195. *
  196. * FUNCTION: acpi_tb_init_table_descriptor
  197. *
  198. * PARAMETERS: table_type - The type of the table
  199. * table_info - A table info struct
  200. *
  201. * RETURN: None.
  202. *
  203. * DESCRIPTION: Install a table into the global data structs.
  204. *
  205. ******************************************************************************/
  206. acpi_status
  207. acpi_tb_init_table_descriptor (
  208. acpi_table_type table_type,
  209. struct acpi_table_desc *table_info)
  210. {
  211. struct acpi_table_list *list_head;
  212. struct acpi_table_desc *table_desc;
  213. acpi_status status;
  214. ACPI_FUNCTION_TRACE_U32 ("tb_init_table_descriptor", table_type);
  215. /* Allocate a descriptor for this table */
  216. table_desc = ACPI_MEM_CALLOCATE (sizeof (struct acpi_table_desc));
  217. if (!table_desc) {
  218. return_ACPI_STATUS (AE_NO_MEMORY);
  219. }
  220. /* Get a new owner ID for the table */
  221. status = acpi_ut_allocate_owner_id (&table_desc->owner_id);
  222. if (ACPI_FAILURE (status)) {
  223. return_ACPI_STATUS (status);
  224. }
  225. /* Install the table into the global data structure */
  226. list_head = &acpi_gbl_table_lists[table_type];
  227. /*
  228. * Two major types of tables: 1) Only one instance is allowed. This
  229. * includes most ACPI tables such as the DSDT. 2) Multiple instances of
  230. * the table are allowed. This includes SSDT and PSDTs.
  231. */
  232. if (ACPI_IS_SINGLE_TABLE (acpi_gbl_table_data[table_type].flags)) {
  233. /*
  234. * Only one table allowed, and a table has alread been installed
  235. * at this location, so return an error.
  236. */
  237. if (list_head->next) {
  238. ACPI_MEM_FREE (table_desc);
  239. return_ACPI_STATUS (AE_ALREADY_EXISTS);
  240. }
  241. table_desc->next = list_head->next;
  242. list_head->next = table_desc;
  243. if (table_desc->next) {
  244. table_desc->next->prev = table_desc;
  245. }
  246. list_head->count++;
  247. }
  248. else {
  249. /*
  250. * Link the new table in to the list of tables of this type.
  251. * Insert at the end of the list, order IS IMPORTANT.
  252. *
  253. * table_desc->Prev & Next are already NULL from calloc()
  254. */
  255. list_head->count++;
  256. if (!list_head->next) {
  257. list_head->next = table_desc;
  258. }
  259. else {
  260. table_desc->next = list_head->next;
  261. while (table_desc->next->next) {
  262. table_desc->next = table_desc->next->next;
  263. }
  264. table_desc->next->next = table_desc;
  265. table_desc->prev = table_desc->next;
  266. table_desc->next = NULL;
  267. }
  268. }
  269. /* Finish initialization of the table descriptor */
  270. table_desc->type = (u8) table_type;
  271. table_desc->pointer = table_info->pointer;
  272. table_desc->length = table_info->length;
  273. table_desc->allocation = table_info->allocation;
  274. table_desc->aml_start = (u8 *) (table_desc->pointer + 1),
  275. table_desc->aml_length = (u32) (table_desc->length -
  276. (u32) sizeof (struct acpi_table_header));
  277. table_desc->loaded_into_namespace = FALSE;
  278. /*
  279. * Set the appropriate global pointer (if there is one) to point to the
  280. * newly installed table
  281. */
  282. if (acpi_gbl_table_data[table_type].global_ptr) {
  283. *(acpi_gbl_table_data[table_type].global_ptr) = table_info->pointer;
  284. }
  285. /* Return Data */
  286. table_info->owner_id = table_desc->owner_id;
  287. table_info->installed_desc = table_desc;
  288. return_ACPI_STATUS (AE_OK);
  289. }
  290. /*******************************************************************************
  291. *
  292. * FUNCTION: acpi_tb_delete_all_tables
  293. *
  294. * PARAMETERS: None.
  295. *
  296. * RETURN: None.
  297. *
  298. * DESCRIPTION: Delete all internal ACPI tables
  299. *
  300. ******************************************************************************/
  301. void
  302. acpi_tb_delete_all_tables (
  303. void)
  304. {
  305. acpi_table_type type;
  306. /*
  307. * Free memory allocated for ACPI tables
  308. * Memory can either be mapped or allocated
  309. */
  310. for (type = 0; type < NUM_ACPI_TABLE_TYPES; type++) {
  311. acpi_tb_delete_tables_by_type (type);
  312. }
  313. }
  314. /*******************************************************************************
  315. *
  316. * FUNCTION: acpi_tb_delete_tables_by_type
  317. *
  318. * PARAMETERS: Type - The table type to be deleted
  319. *
  320. * RETURN: None.
  321. *
  322. * DESCRIPTION: Delete an internal ACPI table
  323. * Locks the ACPI table mutex
  324. *
  325. ******************************************************************************/
  326. void
  327. acpi_tb_delete_tables_by_type (
  328. acpi_table_type type)
  329. {
  330. struct acpi_table_desc *table_desc;
  331. u32 count;
  332. u32 i;
  333. ACPI_FUNCTION_TRACE_U32 ("tb_delete_tables_by_type", type);
  334. if (type > ACPI_TABLE_MAX) {
  335. return_VOID;
  336. }
  337. if (ACPI_FAILURE (acpi_ut_acquire_mutex (ACPI_MTX_TABLES))) {
  338. return;
  339. }
  340. /* Clear the appropriate "typed" global table pointer */
  341. switch (type) {
  342. case ACPI_TABLE_RSDP:
  343. acpi_gbl_RSDP = NULL;
  344. break;
  345. case ACPI_TABLE_DSDT:
  346. acpi_gbl_DSDT = NULL;
  347. break;
  348. case ACPI_TABLE_FADT:
  349. acpi_gbl_FADT = NULL;
  350. break;
  351. case ACPI_TABLE_FACS:
  352. acpi_gbl_FACS = NULL;
  353. break;
  354. case ACPI_TABLE_XSDT:
  355. acpi_gbl_XSDT = NULL;
  356. break;
  357. case ACPI_TABLE_SSDT:
  358. case ACPI_TABLE_PSDT:
  359. default:
  360. break;
  361. }
  362. /*
  363. * Free the table
  364. * 1) Get the head of the list
  365. */
  366. table_desc = acpi_gbl_table_lists[type].next;
  367. count = acpi_gbl_table_lists[type].count;
  368. /*
  369. * 2) Walk the entire list, deleting both the allocated tables
  370. * and the table descriptors
  371. */
  372. for (i = 0; i < count; i++) {
  373. table_desc = acpi_tb_uninstall_table (table_desc);
  374. }
  375. (void) acpi_ut_release_mutex (ACPI_MTX_TABLES);
  376. return_VOID;
  377. }
  378. /*******************************************************************************
  379. *
  380. * FUNCTION: acpi_tb_delete_single_table
  381. *
  382. * PARAMETERS: table_info - A table info struct
  383. *
  384. * RETURN: None.
  385. *
  386. * DESCRIPTION: Low-level free for a single ACPI table. Handles cases where
  387. * the table was allocated a buffer or was mapped.
  388. *
  389. ******************************************************************************/
  390. void
  391. acpi_tb_delete_single_table (
  392. struct acpi_table_desc *table_desc)
  393. {
  394. /* Must have a valid table descriptor and pointer */
  395. if ((!table_desc) ||
  396. (!table_desc->pointer)) {
  397. return;
  398. }
  399. /* Valid table, determine type of memory allocation */
  400. switch (table_desc->allocation) {
  401. case ACPI_MEM_NOT_ALLOCATED:
  402. break;
  403. case ACPI_MEM_ALLOCATED:
  404. ACPI_MEM_FREE (table_desc->pointer);
  405. break;
  406. case ACPI_MEM_MAPPED:
  407. acpi_os_unmap_memory (table_desc->pointer, table_desc->length);
  408. break;
  409. default:
  410. break;
  411. }
  412. }
  413. /*******************************************************************************
  414. *
  415. * FUNCTION: acpi_tb_uninstall_table
  416. *
  417. * PARAMETERS: table_info - A table info struct
  418. *
  419. * RETURN: Pointer to the next table in the list (of same type)
  420. *
  421. * DESCRIPTION: Free the memory associated with an internal ACPI table that
  422. * is either installed or has never been installed.
  423. * Table mutex should be locked.
  424. *
  425. ******************************************************************************/
  426. struct acpi_table_desc *
  427. acpi_tb_uninstall_table (
  428. struct acpi_table_desc *table_desc)
  429. {
  430. struct acpi_table_desc *next_desc;
  431. ACPI_FUNCTION_TRACE_PTR ("tb_uninstall_table", table_desc);
  432. if (!table_desc) {
  433. return_PTR (NULL);
  434. }
  435. /* Unlink the descriptor from the doubly linked list */
  436. if (table_desc->prev) {
  437. table_desc->prev->next = table_desc->next;
  438. }
  439. else {
  440. /* Is first on list, update list head */
  441. acpi_gbl_table_lists[table_desc->type].next = table_desc->next;
  442. }
  443. if (table_desc->next) {
  444. table_desc->next->prev = table_desc->prev;
  445. }
  446. /* Free the memory allocated for the table itself */
  447. acpi_tb_delete_single_table (table_desc);
  448. /* Free the table descriptor */
  449. next_desc = table_desc->next;
  450. ACPI_MEM_FREE (table_desc);
  451. /* Return pointer to the next descriptor */
  452. return_PTR (next_desc);
  453. }