ACPICA: Linuxize: Export debugger files to Linux
[linux-2.6/btrfs-unstable.git] / drivers / acpi / acpica / dbfileio.c
blobd0e6b20ce82ab7861cb50a1bd7241d3c0cc24adf
1 /*******************************************************************************
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)
6 ******************************************************************************/
8 /*
9 * Copyright (C) 2000 - 2015, Intel Corp.
10 * All rights reserved.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions, and the following disclaimer,
17 * without modification.
18 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 * substantially similar to the "NO WARRANTY" disclaimer below
20 * ("Disclaimer") and any redistribution must be conditioned upon
21 * including a substantially similar Disclaimer requirement for further
22 * binary redistribution.
23 * 3. Neither the names of the above-listed copyright holders nor the names
24 * of any contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
27 * Alternatively, this software may be distributed under the terms of the
28 * GNU General Public License ("GPL") version 2 as published by the Free
29 * Software Foundation.
31 * NO WARRANTY
32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 * POSSIBILITY OF SUCH DAMAGES.
45 #include <acpi/acpi.h>
46 #include "accommon.h"
47 #include "acdebug.h"
48 #include "actables.h"
50 #define _COMPONENT ACPI_CA_DEBUGGER
51 ACPI_MODULE_NAME("dbfileio")
53 #ifdef ACPI_DEBUGGER
54 /*******************************************************************************
56 * FUNCTION: acpi_db_close_debug_file
58 * PARAMETERS: None
60 * RETURN: None
62 * DESCRIPTION: If open, close the current debug output file
64 ******************************************************************************/
65 void acpi_db_close_debug_file(void)
68 #ifdef ACPI_APPLICATION
70 if (acpi_gbl_debug_file) {
71 fclose(acpi_gbl_debug_file);
72 acpi_gbl_debug_file = NULL;
73 acpi_gbl_db_output_to_file = FALSE;
74 acpi_os_printf("Debug output file %s closed\n",
75 acpi_gbl_db_debug_filename);
77 #endif
80 /*******************************************************************************
82 * FUNCTION: acpi_db_open_debug_file
84 * PARAMETERS: name - Filename to open
86 * RETURN: None
88 * DESCRIPTION: Open a file where debug output will be directed.
90 ******************************************************************************/
92 void acpi_db_open_debug_file(char *name)
95 #ifdef ACPI_APPLICATION
97 acpi_db_close_debug_file();
98 acpi_gbl_debug_file = fopen(name, "w+");
99 if (!acpi_gbl_debug_file) {
100 acpi_os_printf("Could not open debug file %s\n", name);
101 return;
104 acpi_os_printf("Debug output file %s opened\n", name);
105 strncpy(acpi_gbl_db_debug_filename, name,
106 sizeof(acpi_gbl_db_debug_filename));
107 acpi_gbl_db_output_to_file = TRUE;
109 #endif
111 #endif
113 #ifdef ACPI_APPLICATION
114 #include "acapps.h"
116 /*******************************************************************************
118 * FUNCTION: ae_local_load_table
120 * PARAMETERS: table - pointer to a buffer containing the entire
121 * table to be loaded
123 * RETURN: Status
125 * DESCRIPTION: This function is called to load a table from the caller's
126 * buffer. The buffer must contain an entire ACPI Table including
127 * a valid header. The header fields will be verified, and if it
128 * is determined that the table is invalid, the call will fail.
130 ******************************************************************************/
132 static acpi_status ae_local_load_table(struct acpi_table_header *table)
134 acpi_status status = AE_OK;
136 ACPI_FUNCTION_TRACE(ae_local_load_table);
138 #if 0
139 /* struct acpi_table_desc table_info; */
141 if (!table) {
142 return_ACPI_STATUS(AE_BAD_PARAMETER);
145 table_info.pointer = table;
146 status = acpi_tb_recognize_table(&table_info, ACPI_TABLE_ALL);
147 if (ACPI_FAILURE(status)) {
148 return_ACPI_STATUS(status);
151 /* Install the new table into the local data structures */
153 status = acpi_tb_init_table_descriptor(&table_info);
154 if (ACPI_FAILURE(status)) {
155 if (status == AE_ALREADY_EXISTS) {
157 /* Table already exists, no error */
159 status = AE_OK;
162 /* Free table allocated by acpi_tb_get_table */
164 acpi_tb_delete_single_table(&table_info);
165 return_ACPI_STATUS(status);
167 #if (!defined (ACPI_NO_METHOD_EXECUTION) && !defined (ACPI_CONSTANT_EVAL_ONLY))
169 status =
170 acpi_ns_load_table(table_info.installed_desc, acpi_gbl_root_node);
171 if (ACPI_FAILURE(status)) {
173 /* Uninstall table and free the buffer */
175 acpi_tb_delete_tables_by_type(ACPI_TABLE_ID_DSDT);
176 return_ACPI_STATUS(status);
178 #endif
179 #endif
181 return_ACPI_STATUS(status);
183 #endif
185 /*******************************************************************************
187 * FUNCTION: acpi_db_get_table_from_file
189 * PARAMETERS: filename - File where table is located
190 * return_table - Where a pointer to the table is returned
192 * RETURN: Status
194 * DESCRIPTION: Load an ACPI table from a file
196 ******************************************************************************/
198 acpi_status
199 acpi_db_get_table_from_file(char *filename,
200 struct acpi_table_header **return_table,
201 u8 must_be_aml_file)
203 #ifdef ACPI_APPLICATION
204 acpi_status status;
205 struct acpi_table_header *table;
206 u8 is_aml_table = TRUE;
208 status = acpi_ut_read_table_from_file(filename, &table);
209 if (ACPI_FAILURE(status)) {
210 return (status);
213 if (must_be_aml_file) {
214 is_aml_table = acpi_ut_is_aml_table(table);
215 if (!is_aml_table) {
216 ACPI_EXCEPTION((AE_INFO, AE_OK,
217 "Input for -e is not an AML table: "
218 "\"%4.4s\" (must be DSDT/SSDT)",
219 table->signature));
220 return (AE_TYPE);
224 if (is_aml_table) {
226 /* Attempt to recognize and install the table */
228 status = ae_local_load_table(table);
229 if (ACPI_FAILURE(status)) {
230 if (status == AE_ALREADY_EXISTS) {
231 acpi_os_printf
232 ("Table %4.4s is already installed\n",
233 table->signature);
234 } else {
235 acpi_os_printf("Could not install table, %s\n",
236 acpi_format_exception(status));
239 return (status);
242 acpi_tb_print_table_header(0, table);
244 fprintf(stderr,
245 "Acpi table [%4.4s] successfully installed and loaded\n",
246 table->signature);
249 acpi_gbl_acpi_hardware_present = FALSE;
250 if (return_table) {
251 *return_table = table;
254 #endif /* ACPI_APPLICATION */
255 return (AE_OK);