dbfileio.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. /*******************************************************************************
  2. *
  3. * Module Name: dbfileio - Debugger file I/O commands. These can't usually
  4. * be used when running the debugger in Ring 0 (Kernel mode)
  5. *
  6. ******************************************************************************/
  7. /*
  8. * Copyright (C) 2000 - 2015, Intel Corp.
  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 "accommon.h"
  45. #include "acdebug.h"
  46. #include "actables.h"
  47. #define _COMPONENT ACPI_CA_DEBUGGER
  48. ACPI_MODULE_NAME("dbfileio")
  49. #ifdef ACPI_DEBUGGER
  50. /*******************************************************************************
  51. *
  52. * FUNCTION: acpi_db_close_debug_file
  53. *
  54. * PARAMETERS: None
  55. *
  56. * RETURN: None
  57. *
  58. * DESCRIPTION: If open, close the current debug output file
  59. *
  60. ******************************************************************************/
  61. void acpi_db_close_debug_file(void)
  62. {
  63. #ifdef ACPI_APPLICATION
  64. if (acpi_gbl_debug_file) {
  65. fclose(acpi_gbl_debug_file);
  66. acpi_gbl_debug_file = NULL;
  67. acpi_gbl_db_output_to_file = FALSE;
  68. acpi_os_printf("Debug output file %s closed\n",
  69. acpi_gbl_db_debug_filename);
  70. }
  71. #endif
  72. }
  73. /*******************************************************************************
  74. *
  75. * FUNCTION: acpi_db_open_debug_file
  76. *
  77. * PARAMETERS: name - Filename to open
  78. *
  79. * RETURN: None
  80. *
  81. * DESCRIPTION: Open a file where debug output will be directed.
  82. *
  83. ******************************************************************************/
  84. void acpi_db_open_debug_file(char *name)
  85. {
  86. #ifdef ACPI_APPLICATION
  87. acpi_db_close_debug_file();
  88. acpi_gbl_debug_file = fopen(name, "w+");
  89. if (!acpi_gbl_debug_file) {
  90. acpi_os_printf("Could not open debug file %s\n", name);
  91. return;
  92. }
  93. acpi_os_printf("Debug output file %s opened\n", name);
  94. strncpy(acpi_gbl_db_debug_filename, name,
  95. sizeof(acpi_gbl_db_debug_filename));
  96. acpi_gbl_db_output_to_file = TRUE;
  97. #endif
  98. }
  99. #endif
  100. #ifdef ACPI_APPLICATION
  101. #include "acapps.h"
  102. /*******************************************************************************
  103. *
  104. * FUNCTION: ae_local_load_table
  105. *
  106. * PARAMETERS: table - pointer to a buffer containing the entire
  107. * table to be loaded
  108. *
  109. * RETURN: Status
  110. *
  111. * DESCRIPTION: This function is called to load a table from the caller's
  112. * buffer. The buffer must contain an entire ACPI Table including
  113. * a valid header. The header fields will be verified, and if it
  114. * is determined that the table is invalid, the call will fail.
  115. *
  116. ******************************************************************************/
  117. static acpi_status ae_local_load_table(struct acpi_table_header *table)
  118. {
  119. acpi_status status = AE_OK;
  120. ACPI_FUNCTION_TRACE(ae_local_load_table);
  121. #if 0
  122. /* struct acpi_table_desc table_info; */
  123. if (!table) {
  124. return_ACPI_STATUS(AE_BAD_PARAMETER);
  125. }
  126. table_info.pointer = table;
  127. status = acpi_tb_recognize_table(&table_info, ACPI_TABLE_ALL);
  128. if (ACPI_FAILURE(status)) {
  129. return_ACPI_STATUS(status);
  130. }
  131. /* Install the new table into the local data structures */
  132. status = acpi_tb_init_table_descriptor(&table_info);
  133. if (ACPI_FAILURE(status)) {
  134. if (status == AE_ALREADY_EXISTS) {
  135. /* Table already exists, no error */
  136. status = AE_OK;
  137. }
  138. /* Free table allocated by acpi_tb_get_table */
  139. acpi_tb_delete_single_table(&table_info);
  140. return_ACPI_STATUS(status);
  141. }
  142. #if (!defined (ACPI_NO_METHOD_EXECUTION) && !defined (ACPI_CONSTANT_EVAL_ONLY))
  143. status =
  144. acpi_ns_load_table(table_info.installed_desc, acpi_gbl_root_node);
  145. if (ACPI_FAILURE(status)) {
  146. /* Uninstall table and free the buffer */
  147. acpi_tb_delete_tables_by_type(ACPI_TABLE_ID_DSDT);
  148. return_ACPI_STATUS(status);
  149. }
  150. #endif
  151. #endif
  152. return_ACPI_STATUS(status);
  153. }
  154. #endif
  155. /*******************************************************************************
  156. *
  157. * FUNCTION: acpi_db_get_table_from_file
  158. *
  159. * PARAMETERS: filename - File where table is located
  160. * return_table - Where a pointer to the table is returned
  161. *
  162. * RETURN: Status
  163. *
  164. * DESCRIPTION: Load an ACPI table from a file
  165. *
  166. ******************************************************************************/
  167. acpi_status
  168. acpi_db_get_table_from_file(char *filename,
  169. struct acpi_table_header **return_table,
  170. u8 must_be_aml_file)
  171. {
  172. #ifdef ACPI_APPLICATION
  173. acpi_status status;
  174. struct acpi_table_header *table;
  175. u8 is_aml_table = TRUE;
  176. status = acpi_ut_read_table_from_file(filename, &table);
  177. if (ACPI_FAILURE(status)) {
  178. return (status);
  179. }
  180. if (must_be_aml_file) {
  181. is_aml_table = acpi_ut_is_aml_table(table);
  182. if (!is_aml_table) {
  183. ACPI_EXCEPTION((AE_INFO, AE_OK,
  184. "Input for -e is not an AML table: "
  185. "\"%4.4s\" (must be DSDT/SSDT)",
  186. table->signature));
  187. return (AE_TYPE);
  188. }
  189. }
  190. if (is_aml_table) {
  191. /* Attempt to recognize and install the table */
  192. status = ae_local_load_table(table);
  193. if (ACPI_FAILURE(status)) {
  194. if (status == AE_ALREADY_EXISTS) {
  195. acpi_os_printf
  196. ("Table %4.4s is already installed\n",
  197. table->signature);
  198. } else {
  199. acpi_os_printf("Could not install table, %s\n",
  200. acpi_format_exception(status));
  201. }
  202. return (status);
  203. }
  204. acpi_tb_print_table_header(0, table);
  205. fprintf(stderr,
  206. "Acpi table [%4.4s] successfully installed and loaded\n",
  207. table->signature);
  208. }
  209. acpi_gbl_acpi_hardware_present = FALSE;
  210. if (return_table) {
  211. *return_table = table;
  212. }
  213. #endif /* ACPI_APPLICATION */
  214. return (AE_OK);
  215. }