tbinstal.c 15 KB

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