File: dbfileio.c

package info (click to toggle)
kernel-image-2.4.17-hppa 32.4
  • links: PTS
  • area: main
  • in suites: woody
  • size: 156,356 kB
  • ctags: 442,585
  • sloc: ansic: 2,542,442; asm: 144,771; makefile: 8,468; sh: 3,097; perl: 2,578; yacc: 1,177; tcl: 577; lex: 352; awk: 251; lisp: 218; sed: 72
file content (381 lines) | stat: -rw-r--r-- 9,933 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
/*******************************************************************************
 *
 * Module Name: dbfileio - Debugger file I/O commands.  These can't usually
 *              be used when running the debugger in Ring 0 (Kernel mode)
 *              $Revision: 53 $
 *
 ******************************************************************************/

/*
 *  Copyright (C) 2000, 2001 R. Byron Moore
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */


#include "acpi.h"
#include "acdebug.h"
#include "acnamesp.h"
#include "acparser.h"
#include "acevents.h"
#include "actables.h"

#ifdef ENABLE_DEBUGGER

#define _COMPONENT          ACPI_DEBUGGER
	 MODULE_NAME         ("dbfileio")


/*
 * NOTE: this is here for lack of a better place.  It is used in all
 * flavors of the debugger, need LCD file
 */
#ifdef ACPI_APPLICATION
#include <stdio.h>
FILE                        *acpi_gbl_debug_file = NULL;
#endif


acpi_table_header           *acpi_gbl_db_table_ptr = NULL;


/*******************************************************************************
 *
 * FUNCTION:    Acpi_db_match_argument
 *
 * PARAMETERS:  User_argument           - User command line
 *              Arguments               - Array of commands to match against
 *
 * RETURN:      Index into command array or ACPI_TYPE_NOT_FOUND if not found
 *
 * DESCRIPTION: Search command array for a command match
 *
 ******************************************************************************/

acpi_object_type8
acpi_db_match_argument (
	NATIVE_CHAR             *user_argument,
	ARGUMENT_INFO           *arguments)
{
	u32                     i;


	if (!user_argument || user_argument[0] == 0) {
		return (ACPI_TYPE_NOT_FOUND);
	}

	for (i = 0; arguments[i].name; i++) {
		if (STRSTR (arguments[i].name, user_argument) == arguments[i].name) {
			return ((acpi_object_type8) i);
		}
	}

	/* Argument not recognized */

	return (ACPI_TYPE_NOT_FOUND);
}


/*******************************************************************************
 *
 * FUNCTION:    Acpi_db_close_debug_file
 *
 * PARAMETERS:  None
 *
 * RETURN:      Status
 *
 * DESCRIPTION: If open, close the current debug output file
 *
 ******************************************************************************/

void
acpi_db_close_debug_file (
	void)
{

#ifdef ACPI_APPLICATION

	if (acpi_gbl_debug_file) {
	   fclose (acpi_gbl_debug_file);
	   acpi_gbl_debug_file = NULL;
	   acpi_gbl_db_output_to_file = FALSE;
	   acpi_os_printf ("Debug output file %s closed\n", acpi_gbl_db_debug_filename);
	}
#endif

}


/*******************************************************************************
 *
 * FUNCTION:    Acpi_db_open_debug_file
 *
 * PARAMETERS:  Name                - Filename to open
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Open a file where debug output will be directed.
 *
 ******************************************************************************/

void
acpi_db_open_debug_file (
	NATIVE_CHAR             *name)
{

#ifdef ACPI_APPLICATION

	acpi_db_close_debug_file ();
	acpi_gbl_debug_file = fopen (name, "w+");
	if (acpi_gbl_debug_file) {
		acpi_os_printf ("Debug output file %s opened\n", name);
		STRCPY (acpi_gbl_db_debug_filename, name);
		acpi_gbl_db_output_to_file = TRUE;
	}
	else {
		acpi_os_printf ("Could not open debug file %s\n", name);
	}

#endif
}


#ifdef ACPI_APPLICATION
/*******************************************************************************
 *
 * FUNCTION:    Acpi_db_load_table
 *
 * PARAMETERS:  fp              - File that contains table
 *              Table_ptr       - Return value, buffer with table
 *              Table_lenght    - Return value, length of table
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Load the DSDT from the file pointer
 *
 ******************************************************************************/

acpi_status
acpi_db_load_table(
	FILE                    *fp,
	acpi_table_header       **table_ptr,
	u32                     *table_length)
{
	acpi_table_header       table_header;
	u8                      *aml_start;
	u32                     aml_length;
	u32                     actual;
	acpi_status             status;


	/* Read the table header */

	if (fread (&table_header, 1, sizeof (table_header), fp) != sizeof (acpi_table_header)) {
		acpi_os_printf ("Couldn't read the table header\n");
		return (AE_BAD_SIGNATURE);
	}


	/* Validate the table header/length */

	status = acpi_tb_validate_table_header (&table_header);
	if ((ACPI_FAILURE (status)) ||
		(table_header.length > 524288)) /* 1/2 Mbyte should be enough */ {
		acpi_os_printf ("Table header is invalid!\n");
		return (AE_ERROR);
	}


	/* We only support a limited number of table types */

	if (STRNCMP ((char *) table_header.signature, DSDT_SIG, 4) &&
		STRNCMP ((char *) table_header.signature, PSDT_SIG, 4) &&
		STRNCMP ((char *) table_header.signature, SSDT_SIG, 4)) {
		acpi_os_printf ("Table signature is invalid\n");
		DUMP_BUFFER (&table_header, sizeof (acpi_table_header));
		return (AE_ERROR);
	}

	/* Allocate a buffer for the table */

	*table_length = table_header.length;
	*table_ptr = acpi_os_allocate ((size_t) *table_length);
	if (!*table_ptr) {
		acpi_os_printf ("Could not allocate memory for ACPI table %4.4s (size=%X)\n",
				 table_header.signature, table_header.length);
		return (AE_NO_MEMORY);
	}


	aml_start = (u8 *) *table_ptr + sizeof (table_header);
	aml_length = *table_length - sizeof (table_header);

	/* Copy the header to the buffer */

	MEMCPY (*table_ptr, &table_header, sizeof (table_header));

	/* Get the rest of the table */

	actual = fread (aml_start, 1, (size_t) aml_length, fp);
	if (actual == aml_length) {
		return (AE_OK);
	}

	if (actual > 0) {
		acpi_os_printf ("Warning - reading table, asked for %X got %X\n", aml_length, actual);
		return (AE_OK);
	}


	acpi_os_printf ("Error - could not read the table file\n");
	acpi_os_free (*table_ptr);
	*table_ptr = NULL;
	*table_length = 0;

	return (AE_ERROR);
}
#endif


/*******************************************************************************
 *
 * FUNCTION:    Ae_local_load_table
 *
 * PARAMETERS:  Table_ptr       - pointer to a buffer containing the entire
 *                                table to be loaded
 *
 * RETURN:      Status
 *
 * DESCRIPTION: This function is called to load a table from the caller's
 *              buffer.  The buffer must contain an entire ACPI Table including
 *              a valid header.  The header fields will be verified, and if it
 *              is determined that the table is invalid, the call will fail.
 *
 *              If the call fails an appropriate status will be returned.
 *
 ******************************************************************************/

acpi_status
ae_local_load_table (
	acpi_table_header       *table_ptr)
{
	acpi_status             status;
	acpi_table_desc         table_info;


	FUNCTION_TRACE ("Ae_local_load_table");

	if (!table_ptr) {
		return_ACPI_STATUS (AE_BAD_PARAMETER);
	}

	/* Install the new table into the local data structures */

	table_info.pointer = table_ptr;

	status = acpi_tb_install_table (NULL, &table_info);
	if (ACPI_FAILURE (status)) {
		/* Free table allocated by Acpi_tb_get_table */

		acpi_tb_delete_single_table (&table_info);
		return_ACPI_STATUS (status);
	}


#ifndef PARSER_ONLY
	status = acpi_ns_load_table (table_info.installed_desc, acpi_gbl_root_node);
	if (ACPI_FAILURE (status)) {
		/* Uninstall table and free the buffer */

		acpi_tb_delete_acpi_table (ACPI_TABLE_DSDT);
		return_ACPI_STATUS (status);
	}
#endif

	return_ACPI_STATUS (status);
}


/*******************************************************************************
 *
 * FUNCTION:    Acpi_db_load_acpi_table
 *
 * PARAMETERS:  Filname         - File where table is located
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Load an ACPI table from a file
 *
 ******************************************************************************/

acpi_status
acpi_db_load_acpi_table (
	NATIVE_CHAR             *filename)
{
#ifdef ACPI_APPLICATION
	FILE                    *fp;
	acpi_status             status;
	u32                     table_length;


	/* Open the file */

	fp = fopen (filename, "rb");
	if (!fp) {
		acpi_os_printf ("Could not open file %s\n", filename);
		return (AE_ERROR);
	}


	/* Get the entire file */

	acpi_os_printf ("Loading Acpi table from file %s\n", filename);
	status = acpi_db_load_table (fp, &acpi_gbl_db_table_ptr, &table_length);
	fclose(fp);

	if (ACPI_FAILURE (status)) {
		acpi_os_printf ("Couldn't get table from the file\n");
		return (status);
	}

	/* Attempt to recognize and install the table */

	status = ae_local_load_table (acpi_gbl_db_table_ptr);
	if (ACPI_FAILURE (status)) {
		if (status == AE_EXIST) {
			acpi_os_printf ("Table %4.4s is already installed\n",
					  &acpi_gbl_db_table_ptr->signature);
		}
		else {
			acpi_os_printf ("Could not install table, %s\n",
					  acpi_format_exception (status));
		}

		acpi_os_free (acpi_gbl_db_table_ptr);
		return (status);
	}

	acpi_os_printf ("%4.4s at %p successfully installed and loaded\n",
			  &acpi_gbl_db_table_ptr->signature, acpi_gbl_db_table_ptr);

	acpi_gbl_acpi_hardware_present = FALSE;

#endif  /* ACPI_APPLICATION */
	return (AE_OK);
}


#endif  /* ENABLE_DEBUGGER */