tbxface.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  1. /******************************************************************************
  2. *
  3. * Module Name: tbxface - Public interfaces to the ACPI subsystem
  4. * ACPI table oriented interfaces
  5. *
  6. *****************************************************************************/
  7. /*
  8. * Copyright (C) 2000 - 2006, R. Byron Moore
  9. * All rights reserved.
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions
  13. * are met:
  14. * 1. Redistributions of source code must retain the above copyright
  15. * notice, this list of conditions, and the following disclaimer,
  16. * without modification.
  17. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  18. * substantially similar to the "NO WARRANTY" disclaimer below
  19. * ("Disclaimer") and any redistribution must be conditioned upon
  20. * including a substantially similar Disclaimer requirement for further
  21. * binary redistribution.
  22. * 3. Neither the names of the above-listed copyright holders nor the names
  23. * of any contributors may be used to endorse or promote products derived
  24. * from this software without specific prior written permission.
  25. *
  26. * Alternatively, this software may be distributed under the terms of the
  27. * GNU General Public License ("GPL") version 2 as published by the Free
  28. * Software Foundation.
  29. *
  30. * NO WARRANTY
  31. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  32. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  33. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  34. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  35. * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  36. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  37. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  38. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  39. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  40. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  41. * POSSIBILITY OF SUCH DAMAGES.
  42. */
  43. #include <acpi/acpi.h>
  44. #include <acpi/acnamesp.h>
  45. #include <acpi/actables.h>
  46. #define _COMPONENT ACPI_TABLES
  47. ACPI_MODULE_NAME("tbxface")
  48. /* Local prototypes */
  49. static acpi_status acpi_tb_load_namespace(void);
  50. /*******************************************************************************
  51. *
  52. * FUNCTION: acpi_allocate_root_table
  53. *
  54. * PARAMETERS: initial_table_count - Size of initial_table_array, in number of
  55. * struct acpi_table_desc structures
  56. *
  57. * RETURN: Status
  58. *
  59. * DESCRIPTION: Allocate a root table array. Used by i_aSL compiler and
  60. * acpi_initialize_tables.
  61. *
  62. ******************************************************************************/
  63. acpi_status acpi_allocate_root_table(u32 initial_table_count)
  64. {
  65. acpi_gbl_root_table_list.size = initial_table_count;
  66. acpi_gbl_root_table_list.flags = ACPI_ROOT_ALLOW_RESIZE;
  67. return (acpi_tb_resize_root_table_list());
  68. }
  69. /*******************************************************************************
  70. *
  71. * FUNCTION: acpi_initialize_tables
  72. *
  73. * PARAMETERS: initial_table_array - Pointer to an array of pre-allocated
  74. * struct acpi_table_desc structures. If NULL, the
  75. * array is dynamically allocated.
  76. * initial_table_count - Size of initial_table_array, in number of
  77. * struct acpi_table_desc structures
  78. * allow_realloc - Flag to tell Table Manager if resize of
  79. * pre-allocated array is allowed. Ignored
  80. * if initial_table_array is NULL.
  81. *
  82. * RETURN: Status
  83. *
  84. * DESCRIPTION: Initialize the table manager, get the RSDP and RSDT/XSDT.
  85. *
  86. * NOTE: Allows static allocation of the initial table array in order
  87. * to avoid the use of dynamic memory in confined environments
  88. * such as the kernel boot sequence where it may not be available.
  89. *
  90. * If the host OS memory managers are initialized, use NULL for
  91. * initial_table_array, and the table will be dynamically allocated.
  92. *
  93. ******************************************************************************/
  94. acpi_status __init
  95. acpi_initialize_tables(struct acpi_table_desc * initial_table_array,
  96. u32 initial_table_count, u8 allow_resize)
  97. {
  98. acpi_physical_address rsdp_address;
  99. acpi_status status;
  100. ACPI_FUNCTION_TRACE(acpi_initialize_tables);
  101. /*
  102. * Set up the Root Table Array
  103. * Allocate the table array if requested
  104. */
  105. if (!initial_table_array) {
  106. status = acpi_allocate_root_table(initial_table_count);
  107. if (ACPI_FAILURE(status)) {
  108. return_ACPI_STATUS(status);
  109. }
  110. } else {
  111. /* Root Table Array has been statically allocated by the host */
  112. ACPI_MEMSET(initial_table_array, 0,
  113. initial_table_count *
  114. sizeof(struct acpi_table_desc));
  115. acpi_gbl_root_table_list.tables = initial_table_array;
  116. acpi_gbl_root_table_list.size = initial_table_count;
  117. acpi_gbl_root_table_list.flags = ACPI_ROOT_ORIGIN_UNKNOWN;
  118. if (allow_resize) {
  119. acpi_gbl_root_table_list.flags |=
  120. ACPI_ROOT_ALLOW_RESIZE;
  121. }
  122. }
  123. /* Get the address of the RSDP */
  124. rsdp_address = acpi_os_get_root_pointer();
  125. if (!rsdp_address) {
  126. return_ACPI_STATUS(AE_NOT_FOUND);
  127. }
  128. /*
  129. * Get the root table (RSDT or XSDT) and extract all entries to the local
  130. * Root Table Array. This array contains the information of the RSDT/XSDT
  131. * in a common, more useable format.
  132. */
  133. status =
  134. acpi_tb_parse_root_table(rsdp_address, ACPI_TABLE_ORIGIN_MAPPED);
  135. return_ACPI_STATUS(status);
  136. }
  137. /*******************************************************************************
  138. *
  139. * FUNCTION: acpi_reallocate_root_table
  140. *
  141. * PARAMETERS: None
  142. *
  143. * RETURN: Status
  144. *
  145. * DESCRIPTION: Reallocate Root Table List into dynamic memory. Copies the
  146. * root list from the previously provided scratch area. Should
  147. * be called once dynamic memory allocation is available in the
  148. * kernel
  149. *
  150. ******************************************************************************/
  151. acpi_status acpi_reallocate_root_table(void)
  152. {
  153. struct acpi_table_desc *tables;
  154. acpi_size new_size;
  155. ACPI_FUNCTION_TRACE(acpi_reallocate_root_table);
  156. /*
  157. * Only reallocate the root table if the host provided a static buffer
  158. * for the table array in the call to acpi_initialize_tables.
  159. */
  160. if (acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) {
  161. return_ACPI_STATUS(AE_SUPPORT);
  162. }
  163. new_size =
  164. (acpi_gbl_root_table_list.count +
  165. ACPI_ROOT_TABLE_SIZE_INCREMENT) * sizeof(struct acpi_table_desc);
  166. /* Create new array and copy the old array */
  167. tables = ACPI_ALLOCATE_ZEROED(new_size);
  168. if (!tables) {
  169. return_ACPI_STATUS(AE_NO_MEMORY);
  170. }
  171. ACPI_MEMCPY(tables, acpi_gbl_root_table_list.tables, new_size);
  172. acpi_gbl_root_table_list.size = acpi_gbl_root_table_list.count;
  173. acpi_gbl_root_table_list.tables = tables;
  174. acpi_gbl_root_table_list.flags =
  175. ACPI_ROOT_ORIGIN_ALLOCATED | ACPI_ROOT_ALLOW_RESIZE;
  176. return_ACPI_STATUS(AE_OK);
  177. }
  178. /*******************************************************************************
  179. *
  180. * FUNCTION: acpi_load_table
  181. *
  182. * PARAMETERS: table_ptr - pointer to a buffer containing the entire
  183. * table to be loaded
  184. *
  185. * RETURN: Status
  186. *
  187. * DESCRIPTION: This function is called to load a table from the caller's
  188. * buffer. The buffer must contain an entire ACPI Table including
  189. * a valid header. The header fields will be verified, and if it
  190. * is determined that the table is invalid, the call will fail.
  191. *
  192. ******************************************************************************/
  193. acpi_status acpi_load_table(struct acpi_table_header *table_ptr)
  194. {
  195. acpi_status status;
  196. acpi_native_uint table_index;
  197. /*
  198. * Install the new table into the local data structures
  199. */
  200. status = acpi_tb_add_table(table_ptr, &table_index);
  201. if (ACPI_FAILURE(status)) {
  202. return_ACPI_STATUS(status);
  203. }
  204. status = acpi_ns_load_table(table_index, acpi_gbl_root_node);
  205. return_ACPI_STATUS(status);
  206. }
  207. ACPI_EXPORT_SYMBOL(acpi_load_table)
  208. /******************************************************************************
  209. *
  210. * FUNCTION: acpi_get_table_header
  211. *
  212. * PARAMETERS: Signature - ACPI signature of needed table
  213. * Instance - Which instance (for SSDTs)
  214. * out_table_header - Where the pointer to the table header
  215. * is returned
  216. *
  217. * RETURN: Status and pointer to mapped table header
  218. *
  219. * DESCRIPTION: Finds an ACPI table header.
  220. *
  221. * NOTE: Caller is responsible in unmapping the header with
  222. * acpi_os_unmap_memory
  223. *
  224. *****************************************************************************/
  225. acpi_status
  226. acpi_get_table_header(char *signature,
  227. acpi_native_uint instance,
  228. struct acpi_table_header **out_table_header)
  229. {
  230. acpi_native_uint i;
  231. acpi_native_uint j;
  232. /* Parameter validation */
  233. if (!signature || !out_table_header) {
  234. return (AE_BAD_PARAMETER);
  235. }
  236. /*
  237. * Walk the root table list
  238. */
  239. for (i = 0, j = 0; i < acpi_gbl_root_table_list.count; i++) {
  240. if (!ACPI_COMPARE_NAME
  241. (&(acpi_gbl_root_table_list.tables[i].signature),
  242. signature)) {
  243. continue;
  244. }
  245. if (++j < instance) {
  246. continue;
  247. }
  248. *out_table_header =
  249. acpi_tb_map(acpi_gbl_root_table_list.tables[i].address,
  250. (u32) sizeof(struct acpi_table_header),
  251. acpi_gbl_root_table_list.tables[i].
  252. flags & ACPI_TABLE_ORIGIN_MASK);
  253. if (!(*out_table_header)) {
  254. return (AE_NO_MEMORY);
  255. }
  256. return (AE_OK);
  257. }
  258. return (AE_NOT_FOUND);
  259. }
  260. ACPI_EXPORT_SYMBOL(acpi_get_table_header)
  261. /******************************************************************************
  262. *
  263. * FUNCTION: acpi_unload_table_id
  264. *
  265. * PARAMETERS: id - Owner ID of the table to be removed.
  266. *
  267. * RETURN: Status
  268. *
  269. * DESCRIPTION: This routine is used to force the unload of a table (by id)
  270. *
  271. ******************************************************************************/
  272. acpi_status acpi_unload_table_id(acpi_owner_id id)
  273. {
  274. int i;
  275. acpi_status status = AE_NOT_EXIST;
  276. ACPI_FUNCTION_TRACE(acpi_unload_table);
  277. /* Find table from the requested type list */
  278. for (i = 0; i < acpi_gbl_root_table_list.count; ++i) {
  279. if (id != acpi_gbl_root_table_list.tables[i].owner_id) {
  280. continue;
  281. }
  282. /*
  283. * Delete all namespace objects owned by this table. Note that these
  284. * objects can appear anywhere in the namespace by virtue of the AML
  285. * "Scope" operator. Thus, we need to track ownership by an ID, not
  286. * simply a position within the hierarchy
  287. */
  288. acpi_tb_delete_namespace_by_owner(i);
  289. acpi_tb_release_owner_id(i);
  290. acpi_tb_set_table_loaded_flag(i, FALSE);
  291. }
  292. return_ACPI_STATUS(status);
  293. }
  294. ACPI_EXPORT_SYMBOL(acpi_unload_table_id)
  295. /*******************************************************************************
  296. *
  297. * FUNCTION: acpi_get_table
  298. *
  299. * PARAMETERS: Signature - ACPI signature of needed table
  300. * Instance - Which instance (for SSDTs)
  301. * out_table - Where the pointer to the table is returned
  302. *
  303. * RETURN: Status and pointer to table
  304. *
  305. * DESCRIPTION: Finds and verifies an ACPI table.
  306. *
  307. *****************************************************************************/
  308. acpi_status
  309. acpi_get_table(char *signature,
  310. acpi_native_uint instance, struct acpi_table_header ** out_table)
  311. {
  312. acpi_native_uint i;
  313. acpi_native_uint j;
  314. acpi_status status;
  315. /* Parameter validation */
  316. if (!signature || !out_table) {
  317. return (AE_BAD_PARAMETER);
  318. }
  319. /*
  320. * Walk the root table list
  321. */
  322. for (i = 0, j = 0; i < acpi_gbl_root_table_list.count; i++) {
  323. if (!ACPI_COMPARE_NAME
  324. (&(acpi_gbl_root_table_list.tables[i].signature),
  325. signature)) {
  326. continue;
  327. }
  328. if (++j < instance) {
  329. continue;
  330. }
  331. status =
  332. acpi_tb_verify_table(&acpi_gbl_root_table_list.tables[i]);
  333. if (ACPI_SUCCESS(status)) {
  334. *out_table = acpi_gbl_root_table_list.tables[i].pointer;
  335. }
  336. if (!acpi_gbl_permanent_mmap) {
  337. acpi_gbl_root_table_list.tables[i].pointer = 0;
  338. }
  339. return (status);
  340. }
  341. return (AE_NOT_FOUND);
  342. }
  343. ACPI_EXPORT_SYMBOL(acpi_get_table)
  344. /*******************************************************************************
  345. *
  346. * FUNCTION: acpi_get_table_by_index
  347. *
  348. * PARAMETERS: table_index - Table index
  349. * Table - Where the pointer to the table is returned
  350. *
  351. * RETURN: Status and pointer to the table
  352. *
  353. * DESCRIPTION: Obtain a table by an index into the global table list.
  354. *
  355. ******************************************************************************/
  356. acpi_status
  357. acpi_get_table_by_index(acpi_native_uint table_index,
  358. struct acpi_table_header ** table)
  359. {
  360. acpi_status status;
  361. ACPI_FUNCTION_TRACE(acpi_get_table_by_index);
  362. /* Parameter validation */
  363. if (!table) {
  364. return_ACPI_STATUS(AE_BAD_PARAMETER);
  365. }
  366. (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
  367. /* Validate index */
  368. if (table_index >= acpi_gbl_root_table_list.count) {
  369. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  370. return_ACPI_STATUS(AE_BAD_PARAMETER);
  371. }
  372. if (!acpi_gbl_root_table_list.tables[table_index].pointer) {
  373. /* Table is not mapped, map it */
  374. status =
  375. acpi_tb_verify_table(&acpi_gbl_root_table_list.
  376. tables[table_index]);
  377. if (ACPI_FAILURE(status)) {
  378. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  379. return_ACPI_STATUS(status);
  380. }
  381. }
  382. *table = acpi_gbl_root_table_list.tables[table_index].pointer;
  383. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  384. return_ACPI_STATUS(AE_OK);
  385. }
  386. ACPI_EXPORT_SYMBOL(acpi_get_table_by_index)
  387. /*******************************************************************************
  388. *
  389. * FUNCTION: acpi_tb_load_namespace
  390. *
  391. * PARAMETERS: None
  392. *
  393. * RETURN: Status
  394. *
  395. * DESCRIPTION: Load the namespace from the DSDT and all SSDTs/PSDTs found in
  396. * the RSDT/XSDT.
  397. *
  398. ******************************************************************************/
  399. static acpi_status acpi_tb_load_namespace(void)
  400. {
  401. acpi_status status;
  402. struct acpi_table_header *table;
  403. acpi_native_uint i;
  404. ACPI_FUNCTION_TRACE(tb_load_namespace);
  405. (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
  406. /*
  407. * Load the namespace. The DSDT is required, but any SSDT and PSDT tables
  408. * are optional.
  409. */
  410. if (!acpi_gbl_root_table_list.count ||
  411. !ACPI_COMPARE_NAME(&
  412. (acpi_gbl_root_table_list.
  413. tables[ACPI_TABLE_INDEX_DSDT].signature),
  414. ACPI_SIG_DSDT)
  415. ||
  416. ACPI_FAILURE(acpi_tb_verify_table
  417. (&acpi_gbl_root_table_list.
  418. tables[ACPI_TABLE_INDEX_DSDT]))) {
  419. status = AE_NO_ACPI_TABLES;
  420. goto unlock_and_exit;
  421. }
  422. /*
  423. * Find DSDT table
  424. */
  425. status =
  426. acpi_os_table_override(acpi_gbl_root_table_list.
  427. tables[ACPI_TABLE_INDEX_DSDT].pointer,
  428. &table);
  429. if (ACPI_SUCCESS(status) && table) {
  430. /*
  431. * DSDT table has been found
  432. */
  433. acpi_tb_delete_table(ACPI_TABLE_INDEX_DSDT);
  434. acpi_gbl_root_table_list.tables[ACPI_TABLE_INDEX_DSDT].pointer =
  435. table;
  436. acpi_gbl_root_table_list.tables[ACPI_TABLE_INDEX_DSDT].length =
  437. table->length;
  438. acpi_gbl_root_table_list.tables[ACPI_TABLE_INDEX_DSDT].flags =
  439. ACPI_TABLE_ORIGIN_UNKNOWN;
  440. ACPI_INFO((AE_INFO, "Table DSDT replaced by host OS"));
  441. acpi_tb_print_table_header(0, table);
  442. }
  443. status =
  444. acpi_tb_verify_table(&acpi_gbl_root_table_list.
  445. tables[ACPI_TABLE_INDEX_DSDT]);
  446. if (ACPI_FAILURE(status)) {
  447. /* A valid DSDT is required */
  448. status = AE_NO_ACPI_TABLES;
  449. goto unlock_and_exit;
  450. }
  451. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  452. /*
  453. * Load and parse tables.
  454. */
  455. status = acpi_ns_load_table(ACPI_TABLE_INDEX_DSDT, acpi_gbl_root_node);
  456. if (ACPI_FAILURE(status)) {
  457. return_ACPI_STATUS(status);
  458. }
  459. /*
  460. * Load any SSDT or PSDT tables. Note: Loop leaves tables locked
  461. */
  462. (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
  463. for (i = 0; i < acpi_gbl_root_table_list.count; ++i) {
  464. if ((!ACPI_COMPARE_NAME
  465. (&(acpi_gbl_root_table_list.tables[i].signature),
  466. ACPI_SIG_SSDT)
  467. &&
  468. !ACPI_COMPARE_NAME(&
  469. (acpi_gbl_root_table_list.tables[i].
  470. signature), ACPI_SIG_PSDT))
  471. ||
  472. ACPI_FAILURE(acpi_tb_verify_table
  473. (&acpi_gbl_root_table_list.tables[i]))) {
  474. continue;
  475. }
  476. /* Ignore errors while loading tables, get as many as possible */
  477. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  478. (void)acpi_ns_load_table(i, acpi_gbl_root_node);
  479. (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
  480. }
  481. ACPI_DEBUG_PRINT((ACPI_DB_INIT, "ACPI Tables successfully acquired\n"));
  482. unlock_and_exit:
  483. (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
  484. return_ACPI_STATUS(status);
  485. }
  486. /*******************************************************************************
  487. *
  488. * FUNCTION: acpi_load_tables
  489. *
  490. * PARAMETERS: None
  491. *
  492. * RETURN: Status
  493. *
  494. * DESCRIPTION: Load the ACPI tables from the RSDT/XSDT
  495. *
  496. ******************************************************************************/
  497. acpi_status acpi_load_tables(void)
  498. {
  499. acpi_status status;
  500. ACPI_FUNCTION_TRACE(acpi_load_tables);
  501. /*
  502. * Load the namespace from the tables
  503. */
  504. status = acpi_tb_load_namespace();
  505. if (ACPI_FAILURE(status)) {
  506. ACPI_EXCEPTION((AE_INFO, status,
  507. "While loading namespace from ACPI tables"));
  508. }
  509. return_ACPI_STATUS(status);
  510. }
  511. ACPI_EXPORT_SYMBOL(acpi_load_tables)