1 /*******************************************************************************
3 * Module Name: dbutils - AML debugger utilities
5 ******************************************************************************/
8 * Copyright (C) 2000 - 2016, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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.
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.
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.
44 #include <acpi/acpi.h>
49 #define _COMPONENT ACPI_CA_DEBUGGER
50 ACPI_MODULE_NAME("dbutils")
52 /* Local prototypes */
53 #ifdef ACPI_OBSOLETE_FUNCTIONS
54 acpi_status acpi_db_second_pass_parse(union acpi_parse_object *root);
56 void acpi_db_dump_buffer(u32 address);
59 static char *gbl_hex_to_ascii = "0123456789ABCDEF";
61 /*******************************************************************************
63 * FUNCTION: acpi_db_match_argument
65 * PARAMETERS: user_argument - User command line
66 * arguments - Array of commands to match against
68 * RETURN: Index into command array or ACPI_TYPE_NOT_FOUND if not found
70 * DESCRIPTION: Search command array for a command match
72 ******************************************************************************/
75 acpi_db_match_argument(char *user_argument,
76 struct acpi_db_argument_info *arguments)
80 if (!user_argument || user_argument[0] == 0) {
81 return (ACPI_TYPE_NOT_FOUND);
84 for (i = 0; arguments[i].name; i++) {
85 if (strstr(arguments[i].name, user_argument) ==
91 /* Argument not recognized */
93 return (ACPI_TYPE_NOT_FOUND);
96 /*******************************************************************************
98 * FUNCTION: acpi_db_set_output_destination
100 * PARAMETERS: output_flags - Current flags word
104 * DESCRIPTION: Set the current destination for debugger output. Also sets
105 * the debug output level accordingly.
107 ******************************************************************************/
109 void acpi_db_set_output_destination(u32 output_flags)
112 acpi_gbl_db_output_flags = (u8)output_flags;
114 if ((output_flags & ACPI_DB_REDIRECTABLE_OUTPUT) &&
115 acpi_gbl_db_output_to_file) {
116 acpi_dbg_level = acpi_gbl_db_debug_level;
118 acpi_dbg_level = acpi_gbl_db_console_debug_level;
122 /*******************************************************************************
124 * FUNCTION: acpi_db_dump_external_object
126 * PARAMETERS: obj_desc - External ACPI object to dump
127 * level - Nesting level.
131 * DESCRIPTION: Dump the contents of an ACPI external object
133 ******************************************************************************/
135 void acpi_db_dump_external_object(union acpi_object *obj_desc, u32 level)
140 acpi_os_printf("[Null Object]\n");
144 for (i = 0; i < level; i++) {
148 switch (obj_desc->type) {
151 acpi_os_printf("[Null Object] (Type=0)\n");
154 case ACPI_TYPE_INTEGER:
156 acpi_os_printf("[Integer] = %8.8X%8.8X\n",
157 ACPI_FORMAT_UINT64(obj_desc->integer.value));
160 case ACPI_TYPE_STRING:
162 acpi_os_printf("[String] Length %.2X = ",
163 obj_desc->string.length);
164 acpi_ut_print_string(obj_desc->string.pointer, ACPI_UINT8_MAX);
165 acpi_os_printf("\n");
168 case ACPI_TYPE_BUFFER:
170 acpi_os_printf("[Buffer] Length %.2X = ",
171 obj_desc->buffer.length);
172 if (obj_desc->buffer.length) {
173 if (obj_desc->buffer.length > 16) {
174 acpi_os_printf("\n");
177 acpi_ut_debug_dump_buffer(ACPI_CAST_PTR
179 obj_desc->buffer.pointer),
180 obj_desc->buffer.length,
181 DB_BYTE_DISPLAY, _COMPONENT);
183 acpi_os_printf("\n");
187 case ACPI_TYPE_PACKAGE:
189 acpi_os_printf("[Package] Contains %u Elements:\n",
190 obj_desc->package.count);
192 for (i = 0; i < obj_desc->package.count; i++) {
193 acpi_db_dump_external_object(&obj_desc->package.
194 elements[i], level + 1);
198 case ACPI_TYPE_LOCAL_REFERENCE:
200 acpi_os_printf("[Object Reference] = ");
201 acpi_db_display_internal_object(obj_desc->reference.handle,
205 case ACPI_TYPE_PROCESSOR:
207 acpi_os_printf("[Processor]\n");
210 case ACPI_TYPE_POWER:
212 acpi_os_printf("[Power Resource]\n");
217 acpi_os_printf("[Unknown Type] %X\n", obj_desc->type);
222 /*******************************************************************************
224 * FUNCTION: acpi_db_prep_namestring
226 * PARAMETERS: name - String to prepare
230 * DESCRIPTION: Translate all forward slashes and dots to backslashes.
232 ******************************************************************************/
234 void acpi_db_prep_namestring(char *name)
241 acpi_ut_strupr(name);
243 /* Convert a leading forward slash to a backslash */
249 /* Ignore a leading backslash, this is the root prefix */
251 if (ACPI_IS_ROOT_PREFIX(*name)) {
255 /* Convert all slash path separators to dots */
258 if ((*name == '/') || (*name == '\\')) {
266 /*******************************************************************************
268 * FUNCTION: acpi_db_local_ns_lookup
270 * PARAMETERS: name - Name to lookup
272 * RETURN: Pointer to a namespace node, null on failure
274 * DESCRIPTION: Lookup a name in the ACPI namespace
276 * Note: Currently begins search from the root. Could be enhanced to use
277 * the current prefix (scope) node as the search beginning point.
279 ******************************************************************************/
281 struct acpi_namespace_node *acpi_db_local_ns_lookup(char *name)
285 struct acpi_namespace_node *node = NULL;
287 acpi_db_prep_namestring(name);
289 /* Build an internal namestring */
291 status = acpi_ns_internalize_name(name, &internal_path);
292 if (ACPI_FAILURE(status)) {
293 acpi_os_printf("Invalid namestring: %s\n", name);
299 * (Uses root node as the search starting point)
301 status = acpi_ns_lookup(NULL, internal_path, ACPI_TYPE_ANY,
303 ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE,
305 if (ACPI_FAILURE(status)) {
306 acpi_os_printf("Could not locate name: %s, %s\n",
307 name, acpi_format_exception(status));
310 ACPI_FREE(internal_path);
314 /*******************************************************************************
316 * FUNCTION: acpi_db_uint32_to_hex_string
318 * PARAMETERS: value - The value to be converted to string
319 * buffer - Buffer for result (not less than 11 bytes)
323 * DESCRIPTION: Convert the unsigned 32-bit value to the hexadecimal image
325 * NOTE: It is the caller's responsibility to ensure that the length of buffer
328 ******************************************************************************/
330 void acpi_db_uint32_to_hex_string(u32 value, char *buffer)
341 for (i = 7; i >= 0; i--) {
342 buffer[i] = gbl_hex_to_ascii[value & 0x0F];
347 #ifdef ACPI_OBSOLETE_FUNCTIONS
348 /*******************************************************************************
350 * FUNCTION: acpi_db_second_pass_parse
352 * PARAMETERS: root - Root of the parse tree
356 * DESCRIPTION: Second pass parse of the ACPI tables. We need to wait until
357 * second pass to parse the control methods
359 ******************************************************************************/
361 acpi_status acpi_db_second_pass_parse(union acpi_parse_object *root)
363 union acpi_parse_object *op = root;
364 union acpi_parse_object *method;
365 union acpi_parse_object *search_op;
366 union acpi_parse_object *start_op;
367 acpi_status status = AE_OK;
369 struct acpi_walk_state *walk_state;
371 ACPI_FUNCTION_ENTRY();
373 acpi_os_printf("Pass two parse ....\n");
376 if (op->common.aml_opcode == AML_METHOD_OP) {
379 /* Create a new walk state for the parse */
382 acpi_ds_create_walk_state(0, NULL, NULL, NULL);
384 return (AE_NO_MEMORY);
387 /* Init the Walk State */
389 walk_state->parser_state.aml =
390 walk_state->parser_state.aml_start =
392 walk_state->parser_state.aml_end =
393 walk_state->parser_state.pkg_end =
394 method->named.data + method->named.length;
395 walk_state->parser_state.start_scope = op;
397 walk_state->descending_callback =
398 acpi_ds_load1_begin_op;
399 walk_state->ascending_callback = acpi_ds_load1_end_op;
401 /* Perform the AML parse */
403 status = acpi_ps_parse_aml(walk_state);
406 (method->common.value.arg)->common.aml_offset + 1;
407 start_op = (method->common.value.arg)->common.next;
408 search_op = start_op;
411 search_op->common.aml_offset += base_aml_offset;
413 acpi_ps_get_depth_next(start_op, search_op);
417 if (op->common.aml_opcode == AML_REGION_OP) {
419 /* TBD: [Investigate] this isn't quite the right thing to do! */
422 * Method = (ACPI_DEFERRED_OP *) Op;
423 * Status = acpi_ps_parse_aml (Op, Method->Body, Method->body_length);
427 if (ACPI_FAILURE(status)) {
431 op = acpi_ps_get_depth_next(root, op);
437 /*******************************************************************************
439 * FUNCTION: acpi_db_dump_buffer
441 * PARAMETERS: address - Pointer to the buffer
445 * DESCRIPTION: Print a portion of a buffer
447 ******************************************************************************/
449 void acpi_db_dump_buffer(u32 address)
452 acpi_os_printf("\nLocation %X:\n", address);
454 acpi_dbg_level |= ACPI_LV_TABLES;
455 acpi_ut_debug_dump_buffer(ACPI_TO_POINTER(address), 64, DB_BYTE_DISPLAY,