These changes are the raw update to linux-4.4.6-rt14. Kernel sources
[kvmfornfv.git] / kernel / drivers / acpi / acpica / dbfileio.c
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 /*
9  * Copyright (C) 2000 - 2015, Intel Corp.
10  * All rights reserved.
11  *
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.
26  *
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.
30  *
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.
43  */
44
45 #include <acpi/acpi.h>
46 #include "accommon.h"
47 #include "acdebug.h"
48 #include "actables.h"
49
50 #define _COMPONENT          ACPI_CA_DEBUGGER
51 ACPI_MODULE_NAME("dbfileio")
52
53 #ifdef ACPI_DEBUGGER
54 /*******************************************************************************
55  *
56  * FUNCTION:    acpi_db_close_debug_file
57  *
58  * PARAMETERS:  None
59  *
60  * RETURN:      None
61  *
62  * DESCRIPTION: If open, close the current debug output file
63  *
64  ******************************************************************************/
65 void acpi_db_close_debug_file(void)
66 {
67
68 #ifdef ACPI_APPLICATION
69
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);
76         }
77 #endif
78 }
79
80 /*******************************************************************************
81  *
82  * FUNCTION:    acpi_db_open_debug_file
83  *
84  * PARAMETERS:  name                - Filename to open
85  *
86  * RETURN:      None
87  *
88  * DESCRIPTION: Open a file where debug output will be directed.
89  *
90  ******************************************************************************/
91
92 void acpi_db_open_debug_file(char *name)
93 {
94
95 #ifdef ACPI_APPLICATION
96
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;
102         }
103
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;
108
109 #endif
110 }
111 #endif
112
113 #ifdef ACPI_APPLICATION
114 #include "acapps.h"
115
116 /*******************************************************************************
117  *
118  * FUNCTION:    ae_local_load_table
119  *
120  * PARAMETERS:  table           - pointer to a buffer containing the entire
121  *                                table to be loaded
122  *
123  * RETURN:      Status
124  *
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.
129  *
130  ******************************************************************************/
131
132 static acpi_status ae_local_load_table(struct acpi_table_header *table)
133 {
134         acpi_status status = AE_OK;
135
136         ACPI_FUNCTION_TRACE(ae_local_load_table);
137
138 #if 0
139 /*    struct acpi_table_desc          table_info; */
140
141         if (!table) {
142                 return_ACPI_STATUS(AE_BAD_PARAMETER);
143         }
144
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);
149         }
150
151         /* Install the new table into the local data structures */
152
153         status = acpi_tb_init_table_descriptor(&table_info);
154         if (ACPI_FAILURE(status)) {
155                 if (status == AE_ALREADY_EXISTS) {
156
157                         /* Table already exists, no error */
158
159                         status = AE_OK;
160                 }
161
162                 /* Free table allocated by acpi_tb_get_table */
163
164                 acpi_tb_delete_single_table(&table_info);
165                 return_ACPI_STATUS(status);
166         }
167 #if (!defined (ACPI_NO_METHOD_EXECUTION) && !defined (ACPI_CONSTANT_EVAL_ONLY))
168
169         status =
170             acpi_ns_load_table(table_info.installed_desc, acpi_gbl_root_node);
171         if (ACPI_FAILURE(status)) {
172
173                 /* Uninstall table and free the buffer */
174
175                 acpi_tb_delete_tables_by_type(ACPI_TABLE_ID_DSDT);
176                 return_ACPI_STATUS(status);
177         }
178 #endif
179 #endif
180
181         return_ACPI_STATUS(status);
182 }
183 #endif
184
185 /*******************************************************************************
186  *
187  * FUNCTION:    acpi_db_get_table_from_file
188  *
189  * PARAMETERS:  filename        - File where table is located
190  *              return_table    - Where a pointer to the table is returned
191  *
192  * RETURN:      Status
193  *
194  * DESCRIPTION: Load an ACPI table from a file
195  *
196  ******************************************************************************/
197
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)
202 {
203 #ifdef ACPI_APPLICATION
204         acpi_status status;
205         struct acpi_table_header *table;
206         u8 is_aml_table = TRUE;
207
208         status = acpi_ut_read_table_from_file(filename, &table);
209         if (ACPI_FAILURE(status)) {
210                 return (status);
211         }
212
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);
221                 }
222         }
223
224         if (is_aml_table) {
225
226                 /* Attempt to recognize and install the table */
227
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));
237                         }
238
239                         return (status);
240                 }
241
242                 acpi_tb_print_table_header(0, table);
243
244                 fprintf(stderr,
245                         "Acpi table [%4.4s] successfully installed and loaded\n",
246                         table->signature);
247         }
248
249         acpi_gbl_acpi_hardware_present = FALSE;
250         if (return_table) {
251                 *return_table = table;
252         }
253
254 #endif                          /* ACPI_APPLICATION */
255         return (AE_OK);
256 }