tbinstal.c 15 KB

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