aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/acpi/acpica
diff options
context:
space:
mode:
authorBob Moore <robert.moore@intel.com>2015-12-29 00:54:58 -0500
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2015-12-31 21:47:34 -0500
commit2ba7379b5abcaf2e0e7ece01b1e0c925e0057cd4 (patch)
tree0895da8abd7a272d22b0c7330f28cc44566cfa6a /drivers/acpi/acpica
parent675dfa0af8414958a11645eb53413f8e5af2f142 (diff)
ACPICA: Disassembler/tools: Support for multiple ACPI tables in one file
ACPICA commit 5be7dc4d0d69b2953d156f5bc4d3e8a65a390837 Matches the support in iASL and acpi_exec. Link: https://github.com/acpica/acpica/commit/5be7dc4d Signed-off-by: Bob Moore <robert.moore@intel.com> Signed-off-by: Lv Zheng <lv.zheng@intel.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Diffstat (limited to 'drivers/acpi/acpica')
-rw-r--r--drivers/acpi/acpica/Makefile1
-rw-r--r--drivers/acpi/acpica/acapps.h39
-rw-r--r--drivers/acpi/acpica/acdebug.h5
-rw-r--r--drivers/acpi/acpica/aclocal.h7
-rw-r--r--drivers/acpi/acpica/acutils.h12
-rw-r--r--drivers/acpi/acpica/dbfileio.c123
-rw-r--r--drivers/acpi/acpica/dbinput.c19
-rw-r--r--drivers/acpi/acpica/tbxfload.c2
-rw-r--r--drivers/acpi/acpica/utfileio.c359
9 files changed, 53 insertions, 514 deletions
diff --git a/drivers/acpi/acpica/Makefile b/drivers/acpi/acpica/Makefile
index e75f40164258..f682374c19f4 100644
--- a/drivers/acpi/acpica/Makefile
+++ b/drivers/acpi/acpica/Makefile
@@ -197,7 +197,6 @@ acpi-$(ACPI_FUTURE_USAGE) += \
197 dbfileio.o \ 197 dbfileio.o \
198 dbtest.o \ 198 dbtest.o \
199 utcache.o \ 199 utcache.o \
200 utfileio.o \
201 utprint.o \ 200 utprint.o \
202 uttrack.o \ 201 uttrack.o \
203 utuuid.o 202 utuuid.o
diff --git a/drivers/acpi/acpica/acapps.h b/drivers/acpi/acpica/acapps.h
index e4cc48fbf4ee..185c2eb78bf9 100644
--- a/drivers/acpi/acpica/acapps.h
+++ b/drivers/acpi/acpica/acapps.h
@@ -44,6 +44,8 @@
44#ifndef _ACAPPS 44#ifndef _ACAPPS
45#define _ACAPPS 45#define _ACAPPS
46 46
47#include <stdio.h>
48
47/* Common info for tool signons */ 49/* Common info for tool signons */
48 50
49#define ACPICA_NAME "Intel ACPI Component Architecture" 51#define ACPICA_NAME "Intel ACPI Component Architecture"
@@ -90,6 +92,18 @@
90#define FILE_SUFFIX_DISASSEMBLY "dsl" 92#define FILE_SUFFIX_DISASSEMBLY "dsl"
91#define FILE_SUFFIX_BINARY_TABLE ".dat" /* Needs the dot */ 93#define FILE_SUFFIX_BINARY_TABLE ".dat" /* Needs the dot */
92 94
95/* acfileio */
96
97acpi_status
98acpi_ac_get_all_tables_from_file(char *filename,
99 u8 get_only_aml_tables,
100 struct acpi_new_table_desc **return_list_head);
101
102/* Values for get_only_aml_tables */
103
104#define ACPI_GET_ONLY_AML_TABLES TRUE
105#define ACPI_GET_ALL_TABLES FALSE
106
93/* 107/*
94 * getopt 108 * getopt
95 */ 109 */
@@ -107,30 +121,6 @@ extern char *acpi_gbl_optarg;
107 */ 121 */
108u32 cm_get_file_size(ACPI_FILE file); 122u32 cm_get_file_size(ACPI_FILE file);
109 123
110#ifndef ACPI_DUMP_APP
111/*
112 * adisasm
113 */
114acpi_status
115ad_aml_disassemble(u8 out_to_file,
116 char *filename, char *prefix, char **out_filename);
117
118void ad_print_statistics(void);
119
120acpi_status ad_find_dsdt(u8 **dsdt_ptr, u32 *dsdt_length);
121
122void ad_dump_tables(void);
123
124acpi_status ad_get_local_tables(void);
125
126acpi_status
127ad_parse_table(struct acpi_table_header *table,
128 acpi_owner_id * owner_id, u8 load_table, u8 external);
129
130acpi_status ad_display_tables(char *filename, struct acpi_table_header *table);
131
132acpi_status ad_display_statistics(void);
133
134/* 124/*
135 * adwalk 125 * adwalk
136 */ 126 */
@@ -168,6 +158,5 @@ char *ad_generate_filename(char *prefix, char *table_id);
168void 158void
169ad_write_table(struct acpi_table_header *table, 159ad_write_table(struct acpi_table_header *table,
170 u32 length, char *table_name, char *oem_table_id); 160 u32 length, char *table_name, char *oem_table_id);
171#endif
172 161
173#endif /* _ACAPPS */ 162#endif /* _ACAPPS */
diff --git a/drivers/acpi/acpica/acdebug.h b/drivers/acpi/acpica/acdebug.h
index dcaa15d5fe27..ecb05f1c1d5c 100644
--- a/drivers/acpi/acpica/acdebug.h
+++ b/drivers/acpi/acpica/acdebug.h
@@ -245,10 +245,7 @@ void acpi_db_open_debug_file(char *name);
245 245
246acpi_status acpi_db_load_acpi_table(char *filename); 246acpi_status acpi_db_load_acpi_table(char *filename);
247 247
248acpi_status 248acpi_status acpi_db_load_tables(struct acpi_new_table_desc *list_head);
249acpi_db_get_table_from_file(char *filename,
250 struct acpi_table_header **table,
251 u8 must_be_aml_table);
252 249
253/* 250/*
254 * dbhistry - debugger HISTORY command 251 * dbhistry - debugger HISTORY command
diff --git a/drivers/acpi/acpica/aclocal.h b/drivers/acpi/acpica/aclocal.h
index e1dd784d8515..4fd50404245b 100644
--- a/drivers/acpi/acpica/aclocal.h
+++ b/drivers/acpi/acpica/aclocal.h
@@ -219,6 +219,13 @@ struct acpi_table_list {
219#define ACPI_ROOT_ORIGIN_ALLOCATED (1) 219#define ACPI_ROOT_ORIGIN_ALLOCATED (1)
220#define ACPI_ROOT_ALLOW_RESIZE (2) 220#define ACPI_ROOT_ALLOW_RESIZE (2)
221 221
222/* List to manage incoming ACPI tables */
223
224struct acpi_new_table_desc {
225 struct acpi_table_header *table;
226 struct acpi_new_table_desc *next;
227};
228
222/* Predefined table indexes */ 229/* Predefined table indexes */
223 230
224#define ACPI_INVALID_TABLE_INDEX (0xFFFFFFFF) 231#define ACPI_INVALID_TABLE_INDEX (0xFFFFFFFF)
diff --git a/drivers/acpi/acpica/acutils.h b/drivers/acpi/acpica/acutils.h
index 5d3ae91a4152..67763486bd9d 100644
--- a/drivers/acpi/acpica/acutils.h
+++ b/drivers/acpi/acpica/acutils.h
@@ -353,18 +353,6 @@ acpi_ut_execute_power_methods(struct acpi_namespace_node *device_node,
353 u8 method_count, u8 *out_values); 353 u8 method_count, u8 *out_values);
354 354
355/* 355/*
356 * utfileio - file operations
357 */
358#ifdef ACPI_APPLICATION
359
360acpi_status
361acpi_ut_read_tables_from_file(FILE * file, struct acpi_table_header **table);
362
363acpi_status
364acpi_ut_read_table_from_file(char *filename, struct acpi_table_header **table);
365#endif
366
367/*
368 * utids - device ID support 356 * utids - device ID support
369 */ 357 */
370acpi_status 358acpi_status
diff --git a/drivers/acpi/acpica/dbfileio.c b/drivers/acpi/acpica/dbfileio.c
index d0e6b20ce82a..31f54d71c51a 100644
--- a/drivers/acpi/acpica/dbfileio.c
+++ b/drivers/acpi/acpica/dbfileio.c
@@ -46,6 +46,10 @@
46#include "accommon.h" 46#include "accommon.h"
47#include "acdebug.h" 47#include "acdebug.h"
48#include "actables.h" 48#include "actables.h"
49#include <stdio.h>
50#ifdef ACPI_APPLICATION
51#include "acapps.h"
52#endif
49 53
50#define _COMPONENT ACPI_CA_DEBUGGER 54#define _COMPONENT ACPI_CA_DEBUGGER
51ACPI_MODULE_NAME("dbfileio") 55ACPI_MODULE_NAME("dbfileio")
@@ -110,122 +114,31 @@ void acpi_db_open_debug_file(char *name)
110} 114}
111#endif 115#endif
112 116
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
132static 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/******************************************************************************* 117/*******************************************************************************
186 * 118 *
187 * FUNCTION: acpi_db_get_table_from_file 119 * FUNCTION: acpi_db_load_tables
188 * 120 *
189 * PARAMETERS: filename - File where table is located 121 * PARAMETERS: list_head - List of ACPI tables to load
190 * return_table - Where a pointer to the table is returned
191 * 122 *
192 * RETURN: Status 123 * RETURN: Status
193 * 124 *
194 * DESCRIPTION: Load an ACPI table from a file 125 * DESCRIPTION: Load ACPI tables from a previously constructed table list.
195 * 126 *
196 ******************************************************************************/ 127 ******************************************************************************/
197 128
198acpi_status 129acpi_status acpi_db_load_tables(struct acpi_new_table_desc *list_head)
199acpi_db_get_table_from_file(char *filename,
200 struct acpi_table_header **return_table,
201 u8 must_be_aml_file)
202{ 130{
203#ifdef ACPI_APPLICATION
204 acpi_status status; 131 acpi_status status;
132 struct acpi_new_table_desc *table_list_head;
205 struct acpi_table_header *table; 133 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 134
224 if (is_aml_table) { 135 /* Load all ACPI tables in the list */
225 136
226 /* Attempt to recognize and install the table */ 137 table_list_head = list_head;
138 while (table_list_head) {
139 table = table_list_head->table;
227 140
228 status = ae_local_load_table(table); 141 status = acpi_load_table(table);
229 if (ACPI_FAILURE(status)) { 142 if (ACPI_FAILURE(status)) {
230 if (status == AE_ALREADY_EXISTS) { 143 if (status == AE_ALREADY_EXISTS) {
231 acpi_os_printf 144 acpi_os_printf
@@ -239,18 +152,12 @@ acpi_db_get_table_from_file(char *filename,
239 return (status); 152 return (status);
240 } 153 }
241 154
242 acpi_tb_print_table_header(0, table);
243
244 fprintf(stderr, 155 fprintf(stderr,
245 "Acpi table [%4.4s] successfully installed and loaded\n", 156 "Acpi table [%4.4s] successfully installed and loaded\n",
246 table->signature); 157 table->signature);
247 }
248 158
249 acpi_gbl_acpi_hardware_present = FALSE; 159 table_list_head = table_list_head->next;
250 if (return_table) {
251 *return_table = table;
252 } 160 }
253 161
254#endif /* ACPI_APPLICATION */
255 return (AE_OK); 162 return (AE_OK);
256} 163}
diff --git a/drivers/acpi/acpica/dbinput.c b/drivers/acpi/acpica/dbinput.c
index 2bf8e6b90d5b..71357febd0d5 100644
--- a/drivers/acpi/acpica/dbinput.c
+++ b/drivers/acpi/acpica/dbinput.c
@@ -45,6 +45,10 @@
45#include "accommon.h" 45#include "accommon.h"
46#include "acdebug.h" 46#include "acdebug.h"
47 47
48#ifdef ACPI_APPLICATION
49#include "acapps.h"
50#endif
51
48#define _COMPONENT ACPI_CA_DEBUGGER 52#define _COMPONENT ACPI_CA_DEBUGGER
49ACPI_MODULE_NAME("dbinput") 53ACPI_MODULE_NAME("dbinput")
50 54
@@ -1048,11 +1052,18 @@ acpi_db_command_dispatch(char *input_buffer,
1048 acpi_db_close_debug_file(); 1052 acpi_db_close_debug_file();
1049 break; 1053 break;
1050 1054
1051 case CMD_LOAD: 1055 case CMD_LOAD:{
1056 struct acpi_new_table_desc *list_head = NULL;
1052 1057
1053 status = 1058 status =
1054 acpi_db_get_table_from_file(acpi_gbl_db_args[1], NULL, 1059 acpi_ac_get_all_tables_from_file(acpi_gbl_db_args
1055 FALSE); 1060 [1],
1061 ACPI_GET_ALL_TABLES,
1062 &list_head);
1063 if (ACPI_SUCCESS(status)) {
1064 acpi_db_load_tables(list_head);
1065 }
1066 }
1056 break; 1067 break;
1057 1068
1058 case CMD_OPEN: 1069 case CMD_OPEN:
diff --git a/drivers/acpi/acpica/tbxfload.c b/drivers/acpi/acpica/tbxfload.c
index 9a7d72b75355..ca2f1366b498 100644
--- a/drivers/acpi/acpica/tbxfload.c
+++ b/drivers/acpi/acpica/tbxfload.c
@@ -207,7 +207,7 @@ acpi_status acpi_tb_load_namespace(void)
207 207
208 if (!tables_failed) { 208 if (!tables_failed) {
209 ACPI_INFO((AE_INFO, 209 ACPI_INFO((AE_INFO,
210 "%u ACPI AML tables successfully acquired and loaded", 210 "%u ACPI AML tables successfully acquired and loaded\n",
211 tables_loaded)); 211 tables_loaded));
212 } else { 212 } else {
213 ACPI_ERROR((AE_INFO, 213 ACPI_ERROR((AE_INFO,
diff --git a/drivers/acpi/acpica/utfileio.c b/drivers/acpi/acpica/utfileio.c
deleted file mode 100644
index e72948606039..000000000000
--- a/drivers/acpi/acpica/utfileio.c
+++ /dev/null
@@ -1,359 +0,0 @@
1/*******************************************************************************
2 *
3 * Module Name: utfileio - simple file I/O routines
4 *
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
44#include <acpi/acpi.h>
45#include "accommon.h"
46#include "actables.h"
47#include "acapps.h"
48#include "errno.h"
49
50#ifdef ACPI_ASL_COMPILER
51#include "aslcompiler.h"
52#endif
53
54#define _COMPONENT ACPI_CA_DEBUGGER
55ACPI_MODULE_NAME("utfileio")
56
57#ifdef ACPI_APPLICATION
58/* Local prototypes */
59static acpi_status
60acpi_ut_check_text_mode_corruption(u8 *table,
61 u32 table_length, u32 file_length);
62
63static acpi_status
64acpi_ut_read_table(FILE * fp,
65 struct acpi_table_header **table, u32 *table_length);
66
67/*******************************************************************************
68 *
69 * FUNCTION: acpi_ut_check_text_mode_corruption
70 *
71 * PARAMETERS: table - Table buffer
72 * table_length - Length of table from the table header
73 * file_length - Length of the file that contains the table
74 *
75 * RETURN: Status
76 *
77 * DESCRIPTION: Check table for text mode file corruption where all linefeed
78 * characters (LF) have been replaced by carriage return linefeed
79 * pairs (CR/LF).
80 *
81 ******************************************************************************/
82
83static acpi_status
84acpi_ut_check_text_mode_corruption(u8 *table, u32 table_length, u32 file_length)
85{
86 u32 i;
87 u32 pairs = 0;
88
89 if (table_length != file_length) {
90 ACPI_WARNING((AE_INFO,
91 "File length (0x%X) is not the same as the table length (0x%X)",
92 file_length, table_length));
93 }
94
95 /* Scan entire table to determine if each LF has been prefixed with a CR */
96
97 for (i = 1; i < file_length; i++) {
98 if (table[i] == 0x0A) {
99 if (table[i - 1] != 0x0D) {
100
101 /* The LF does not have a preceding CR, table not corrupted */
102
103 return (AE_OK);
104 } else {
105 /* Found a CR/LF pair */
106
107 pairs++;
108 }
109
110 i++;
111 }
112 }
113
114 if (!pairs) {
115 return (AE_OK);
116 }
117
118 /*
119 * Entire table scanned, each CR is part of a CR/LF pair --
120 * meaning that the table was treated as a text file somewhere.
121 *
122 * NOTE: We can't "fix" the table, because any existing CR/LF pairs in the
123 * original table are left untouched by the text conversion process --
124 * meaning that we cannot simply replace CR/LF pairs with LFs.
125 */
126 acpi_os_printf("Table has been corrupted by text mode conversion\n");
127 acpi_os_printf("All LFs (%u) were changed to CR/LF pairs\n", pairs);
128 acpi_os_printf("Table cannot be repaired!\n");
129
130 return (AE_BAD_VALUE);
131}
132
133/*******************************************************************************
134 *
135 * FUNCTION: acpi_ut_read_table
136 *
137 * PARAMETERS: fp - File that contains table
138 * table - Return value, buffer with table
139 * table_length - Return value, length of table
140 *
141 * RETURN: Status
142 *
143 * DESCRIPTION: Load the DSDT from the file pointer
144 *
145 ******************************************************************************/
146
147static acpi_status
148acpi_ut_read_table(FILE * fp,
149 struct acpi_table_header **table, u32 *table_length)
150{
151 struct acpi_table_header table_header;
152 u32 actual;
153 acpi_status status;
154 u32 file_size;
155 u8 standard_header = TRUE;
156 s32 count;
157
158 /* Get the file size */
159
160 file_size = cm_get_file_size(fp);
161 if (file_size == ACPI_UINT32_MAX) {
162 return (AE_ERROR);
163 }
164
165 if (file_size < 4) {
166 return (AE_BAD_HEADER);
167 }
168
169 /* Read the signature */
170
171 fseek(fp, 0, SEEK_SET);
172
173 count = fread(&table_header, 1, sizeof(struct acpi_table_header), fp);
174 if (count != sizeof(struct acpi_table_header)) {
175 acpi_os_printf("Could not read the table header\n");
176 return (AE_BAD_HEADER);
177 }
178
179 /* The RSDP table does not have standard ACPI header */
180
181 if (ACPI_VALIDATE_RSDP_SIG(table_header.signature)) {
182 *table_length = file_size;
183 standard_header = FALSE;
184 } else {
185
186#if 0
187 /* Validate the table header/length */
188
189 status = acpi_tb_validate_table_header(&table_header);
190 if (ACPI_FAILURE(status)) {
191 acpi_os_printf("Table header is invalid!\n");
192 return (status);
193 }
194#endif
195
196 /* File size must be at least as long as the Header-specified length */
197
198 if (table_header.length > file_size) {
199 acpi_os_printf
200 ("TableHeader length [0x%X] greater than the input file size [0x%X]\n",
201 table_header.length, file_size);
202
203#ifdef ACPI_ASL_COMPILER
204 acpi_os_printf("File is corrupt or is ASCII text -- "
205 "it must be a binary file\n");
206#endif
207 return (AE_BAD_HEADER);
208 }
209#ifdef ACPI_OBSOLETE_CODE
210 /* We only support a limited number of table types */
211
212 if (!ACPI_COMPARE_NAME
213 ((char *)table_header.signature, ACPI_SIG_DSDT)
214 && !ACPI_COMPARE_NAME((char *)table_header.signature,
215 ACPI_SIG_PSDT)
216 && !ACPI_COMPARE_NAME((char *)table_header.signature,
217 ACPI_SIG_SSDT)) {
218 acpi_os_printf
219 ("Table signature [%4.4s] is invalid or not supported\n",
220 (char *)table_header.signature);
221 ACPI_DUMP_BUFFER(&table_header,
222 sizeof(struct acpi_table_header));
223 return (AE_ERROR);
224 }
225#endif
226
227 *table_length = table_header.length;
228 }
229
230 /* Allocate a buffer for the table */
231
232 *table = acpi_os_allocate((size_t) file_size);
233 if (!*table) {
234 acpi_os_printf
235 ("Could not allocate memory for ACPI table %4.4s (size=0x%X)\n",
236 table_header.signature, *table_length);
237 return (AE_NO_MEMORY);
238 }
239
240 /* Get the rest of the table */
241
242 fseek(fp, 0, SEEK_SET);
243 actual = fread(*table, 1, (size_t) file_size, fp);
244 if (actual == file_size) {
245 if (standard_header) {
246
247 /* Now validate the checksum */
248
249 status = acpi_tb_verify_checksum((void *)*table,
250 ACPI_CAST_PTR(struct
251 acpi_table_header,
252 *table)->
253 length);
254
255 if (status == AE_BAD_CHECKSUM) {
256 status =
257 acpi_ut_check_text_mode_corruption((u8 *)
258 *table,
259 file_size,
260 (*table)->
261 length);
262 return (status);
263 }
264 }
265 return (AE_OK);
266 }
267
268 if (actual > 0) {
269 acpi_os_printf("Warning - reading table, asked for %X got %X\n",
270 file_size, actual);
271 return (AE_OK);
272 }
273
274 acpi_os_printf("Error - could not read the table file\n");
275 acpi_os_free(*table);
276 *table = NULL;
277 *table_length = 0;
278 return (AE_ERROR);
279}
280
281/*******************************************************************************
282 *
283 * FUNCTION: acpi_ut_read_table_from_file
284 *
285 * PARAMETERS: filename - File where table is located
286 * table - Where a pointer to the table is returned
287 *
288 * RETURN: Status
289 *
290 * DESCRIPTION: Get an ACPI table from a file
291 *
292 ******************************************************************************/
293
294acpi_status
295acpi_ut_read_tables_from_file(FILE * file, struct acpi_table_header ** table)
296{
297 struct acpi_table_header table_header;
298 s32 count;
299 long position;
300
301 position = ftell(file);
302 count = fread(&table_header, 1, sizeof(struct acpi_table_header), file);
303 if (count < sizeof(struct acpi_table_header)) {
304 return (AE_CTRL_TERMINATE);
305 }
306
307 /* Allocate a buffer for the table */
308
309 *table = acpi_os_allocate((size_t) table_header.length);
310 fseek(file, position, SEEK_SET);
311
312 count = fread(*table, 1, table_header.length, file);
313
314 return (AE_OK);
315}
316
317acpi_status
318acpi_ut_read_table_from_file(char *filename, struct acpi_table_header ** table)
319{
320 FILE *file;
321 u32 file_size;
322 u32 table_length;
323 acpi_status status = AE_ERROR;
324
325 /* Open the file, get current size */
326
327 file = fopen(filename, "rb");
328 if (!file) {
329 perror("Could not open input file");
330
331 if (errno == ENOENT) {
332 return (AE_NOT_EXIST);
333 }
334
335 return (status);
336 }
337
338 file_size = cm_get_file_size(file);
339 if (file_size == ACPI_UINT32_MAX) {
340 goto exit;
341 }
342
343 /* Get the entire file */
344
345 fprintf(stderr,
346 "Reading ACPI table from file %12s - Length %.8u (0x%06X)\n",
347 filename, file_size, file_size);
348
349 status = acpi_ut_read_table(file, table, &table_length);
350 if (ACPI_FAILURE(status)) {
351 acpi_os_printf("Could not get table from the file\n");
352 }
353
354exit:
355 fclose(file);
356 return (status);
357}
358
359#endif