summaryrefslogtreecommitdiffstats
path: root/drivers/acpi/acpica/dbutils.c
blob: ae80106d100052da4ce5196be2fbeebac23488e7 (plain)
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
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
/*******************************************************************************
 *
 * Module Name: dbutils - AML debugger utilities
 *
 ******************************************************************************/

/*
 * Copyright (C) 2000 - 2016, Intel Corp.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions, and the following disclaimer,
 *    without modification.
 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
 *    substantially similar to the "NO WARRANTY" disclaimer below
 *    ("Disclaimer") and any redistribution must be conditioned upon
 *    including a substantially similar Disclaimer requirement for further
 *    binary redistribution.
 * 3. Neither the names of the above-listed copyright holders nor the names
 *    of any contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * Alternatively, this software may be distributed under the terms of the
 * GNU General Public License ("GPL") version 2 as published by the Free
 * Software Foundation.
 *
 * NO WARRANTY
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGES.
 */

#include <acpi/acpi.h>
#include "accommon.h"
#include "acnamesp.h"
#include "acdebug.h"

#define _COMPONENT          ACPI_CA_DEBUGGER
ACPI_MODULE_NAME("dbutils")

/* Local prototypes */
#ifdef ACPI_OBSOLETE_FUNCTIONS
acpi_status acpi_db_second_pass_parse(union acpi_parse_object *root);

void acpi_db_dump_buffer(u32 address);
#endif

/*******************************************************************************
 *
 * 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_type
acpi_db_match_argument(char *user_argument,
		       struct acpi_db_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(ACPI_CAST_PTR(char, arguments[i].name),
			   ACPI_CAST_PTR(char,
					 user_argument)) == arguments[i].name) {
			return (i);
		}
	}

	/* Argument not recognized */

	return (ACPI_TYPE_NOT_FOUND);
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_db_set_output_destination
 *
 * PARAMETERS:  output_flags        - Current flags word
 *
 * RETURN:      None
 *
 * DESCRIPTION: Set the current destination for debugger output. Also sets
 *              the debug output level accordingly.
 *
 ******************************************************************************/

void acpi_db_set_output_destination(u32 output_flags)
{

	acpi_gbl_db_output_flags = (u8)output_flags;

	if ((output_flags & ACPI_DB_REDIRECTABLE_OUTPUT) &&
	    acpi_gbl_db_output_to_file) {
		acpi_dbg_level = acpi_gbl_db_debug_level;
	} else {
		acpi_dbg_level = acpi_gbl_db_console_debug_level;
	}
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_db_dump_external_object
 *
 * PARAMETERS:  obj_desc        - External ACPI object to dump
 *              level           - Nesting level.
 *
 * RETURN:      None
 *
 * DESCRIPTION: Dump the contents of an ACPI external object
 *
 ******************************************************************************/

void acpi_db_dump_external_object(union acpi_object *obj_desc, u32 level)
{
	u32 i;

	if (!obj_desc) {
		acpi_os_printf("[Null Object]\n");
		return;
	}

	for (i = 0; i < level; i++) {
		acpi_os_printf(" ");
	}

	switch (obj_desc->type) {
	case ACPI_TYPE_ANY:

		acpi_os_printf("[Null Object] (Type=0)\n");
		break;

	case ACPI_TYPE_INTEGER:

		acpi_os_printf("[Integer] = %8.8X%8.8X\n",
			       ACPI_FORMAT_UINT64(obj_desc->integer.value));
		break;

	case ACPI_TYPE_STRING:

		acpi_os_printf("[String] Length %.2X = ",
			       obj_desc->string.length);
		acpi_ut_print_string(obj_desc->string.pointer, ACPI_UINT8_MAX);
		acpi_os_printf("\n");
		break;

	case ACPI_TYPE_BUFFER:

		acpi_os_printf("[Buffer] Length %.2X = ",
			       obj_desc->buffer.length);
		if (obj_desc->buffer.length) {
			if (obj_desc->buffer.length > 16) {
				acpi_os_printf("\n");
			}

			acpi_ut_debug_dump_buffer(ACPI_CAST_PTR
						  (u8,
						   obj_desc->buffer.pointer),
						  obj_desc->buffer.length,
						  DB_BYTE_DISPLAY, _COMPONENT);
		} else {
			acpi_os_printf("\n");
		}
		break;

	case ACPI_TYPE_PACKAGE:

		acpi_os_printf("[Package] Contains %u Elements:\n",
			       obj_desc->package.count);

		for (i = 0; i < obj_desc->package.count; i++) {
			acpi_db_dump_external_object(&obj_desc->package.
						     elements[i], level + 1);
		}
		break;

	case ACPI_TYPE_LOCAL_REFERENCE:

		acpi_os_printf("[Object Reference] = ");
		acpi_db_display_internal_object(obj_desc->reference.handle,
						NULL);
		break;

	case ACPI_TYPE_PROCESSOR:

		acpi_os_printf("[Processor]\n");
		break;

	case ACPI_TYPE_POWER:

		acpi_os_printf("[Power Resource]\n");
		break;

	default:

		acpi_os_printf("[Unknown Type] %X\n", obj_desc->type);
		break;
	}
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_db_prep_namestring
 *
 * PARAMETERS:  name            - String to prepare
 *
 * RETURN:      None
 *
 * DESCRIPTION: Translate all forward slashes and dots to backslashes.
 *
 ******************************************************************************/

void acpi_db_prep_namestring(char *name)
{

	if (!name) {
		return;
	}

	acpi_ut_strupr(name);

	/* Convert a leading forward slash to a backslash */

	if (*name == '/') {
		*name = '\\';
	}

	/* Ignore a leading backslash, this is the root prefix */

	if (ACPI_IS_ROOT_PREFIX(*name)) {
		name++;
	}

	/* Convert all slash path separators to dots */

	while (*name) {
		if ((*name == '/') || (*name == '\\')) {
			*name = '.';
		}

		name++;
	}
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_db_local_ns_lookup
 *
 * PARAMETERS:  name            - Name to lookup
 *
 * RETURN:      Pointer to a namespace node, null on failure
 *
 * DESCRIPTION: Lookup a name in the ACPI namespace
 *
 * Note: Currently begins search from the root. Could be enhanced to use
 * the current prefix (scope) node as the search beginning point.
 *
 ******************************************************************************/

struct acpi_namespace_node *acpi_db_local_ns_lookup(char *name)
{
	char *internal_path;
	acpi_status status;
	struct acpi_namespace_node *node = NULL;

	acpi_db_prep_namestring(name);

	/* Build an internal namestring */

	status = acpi_ns_internalize_name(name, &internal_path);
	if (ACPI_FAILURE(status)) {
		acpi_os_printf("Invalid namestring: %s\n", name);
		return (NULL);
	}

	/*
	 * Lookup the name.
	 * (Uses root node as the search starting point)
	 */
	status = acpi_ns_lookup(NULL, internal_path, ACPI_TYPE_ANY,
				ACPI_IMODE_EXECUTE,
				ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE,
				NULL, &node);
	if (ACPI_FAILURE(status)) {
		acpi_os_printf("Could not locate name: %s, %s\n",
			       name, acpi_format_exception(status));
	}

	ACPI_FREE(internal_path);
	return (node);
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_db_uint32_to_hex_string
 *
 * PARAMETERS:  value           - The value to be converted to string
 *              buffer          - Buffer for result (not less than 11 bytes)
 *
 * RETURN:      None
 *
 * DESCRIPTION: Convert the unsigned 32-bit value to the hexadecimal image
 *
 * NOTE: It is the caller's responsibility to ensure that the length of buffer
 *       is sufficient.
 *
 ******************************************************************************/

void acpi_db_uint32_to_hex_string(u32 value, char *buffer)
{
	int i;

	if (value == 0) {
		strcpy(buffer, "0");
		return;
	}

	buffer[8] = '\0';

	for (i = 7; i >= 0; i--) {
		buffer[i] = acpi_gbl_upper_hex_digits[value & 0x0F];
		value = value >> 4;
	}
}

#ifdef ACPI_OBSOLETE_FUNCTIONS
/*******************************************************************************
 *
 * FUNCTION:    acpi_db_second_pass_parse
 *
 * PARAMETERS:  root            - Root of the parse tree
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Second pass parse of the ACPI tables. We need to wait until
 *              second pass to parse the control methods
 *
 ******************************************************************************/

acpi_status acpi_db_second_pass_parse(union acpi_parse_object *root)
{
	union acpi_parse_object *op = root;
	union acpi_parse_object *method;
	union acpi_parse_object *search_op;
	union acpi_parse_object *start_op;
	acpi_status status = AE_OK;
	u32 base_aml_offset;
	struct acpi_walk_state *walk_state;

	ACPI_FUNCTION_ENTRY();

	acpi_os_printf("Pass two parse ....\n");

	while (op) {
		if (op->common.aml_opcode == AML_METHOD_OP) {
			method = op;

			/* Create a new walk state for the parse */

			walk_state =
			    acpi_ds_create_walk_state(0, NULL, NULL, NULL);
			if (!walk_state) {
				return (AE_NO_MEMORY);
			}

			/* Init the Walk State */

			walk_state->parser_state.aml =
			    walk_state->parser_state.aml_start =
			    method->named.data;
			walk_state->parser_state.aml_end =
			    walk_state->parser_state.pkg_end =
			    method->named.data + method->named.length;
			walk_state->parser_state.start_scope = op;

			walk_state->descending_callback =
			    acpi_ds_load1_begin_op;
			walk_state->ascending_callback = acpi_ds_load1_end_op;

			/* Perform the AML parse */

			status = acpi_ps_parse_aml(walk_state);

			base_aml_offset =
			    (method->common.value.arg)->common.aml_offset + 1;
			start_op = (method->common.value.arg)->common.next;
			search_op = start_op;

			while (search_op) {
				search_op->common.aml_offset += base_aml_offset;
				search_op =
				    acpi_ps_get_depth_next(start_op, search_op);
			}
		}

		if (op->common.aml_opcode == AML_REGION_OP) {

			/* TBD: [Investigate] this isn't quite the right thing to do! */
			/*
			 *
			 * Method = (ACPI_DEFERRED_OP *) Op;
			 * Status = acpi_ps_parse_aml (Op, Method->Body, Method->body_length);
			 */
		}

		if (ACPI_FAILURE(status)) {
			break;
		}

		op = acpi_ps_get_depth_next(root, op);
	}

	return (status);
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_db_dump_buffer
 *
 * PARAMETERS:  address             - Pointer to the buffer
 *
 * RETURN:      None
 *
 * DESCRIPTION: Print a portion of a buffer
 *
 ******************************************************************************/

void acpi_db_dump_buffer(u32 address)
{

	acpi_os_printf("\nLocation %X:\n", address);

	acpi_dbg_level |= ACPI_LV_TABLES;
	acpi_ut_debug_dump_buffer(ACPI_TO_POINTER(address), 64, DB_BYTE_DISPLAY,
				  ACPI_UINT32_MAX);
}
#endif
OpenPOWER on IntegriCloud