1 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
2 /*******************************************************************************
4 * Module Name: dbutils - AML debugger utilities
6 ******************************************************************************/
13 #define _COMPONENT ACPI_CA_DEBUGGER
14 ACPI_MODULE_NAME("dbutils")
16 /* Local prototypes */
17 #ifdef ACPI_OBSOLETE_FUNCTIONS
18 acpi_status
acpi_db_second_pass_parse(union acpi_parse_object
*root
);
20 void acpi_db_dump_buffer(u32 address
);
23 /*******************************************************************************
25 * FUNCTION: acpi_db_match_argument
27 * PARAMETERS: user_argument - User command line
28 * arguments - Array of commands to match against
30 * RETURN: Index into command array or ACPI_TYPE_NOT_FOUND if not found
32 * DESCRIPTION: Search command array for a command match
34 ******************************************************************************/
37 acpi_db_match_argument(char *user_argument
,
38 struct acpi_db_argument_info
*arguments
)
42 if (!user_argument
|| user_argument
[0] == 0) {
43 return (ACPI_TYPE_NOT_FOUND
);
46 for (i
= 0; arguments
[i
].name
; i
++) {
47 if (strstr(ACPI_CAST_PTR(char, arguments
[i
].name
),
49 user_argument
)) == arguments
[i
].name
) {
54 /* Argument not recognized */
56 return (ACPI_TYPE_NOT_FOUND
);
59 /*******************************************************************************
61 * FUNCTION: acpi_db_set_output_destination
63 * PARAMETERS: output_flags - Current flags word
67 * DESCRIPTION: Set the current destination for debugger output. Also sets
68 * the debug output level accordingly.
70 ******************************************************************************/
72 void acpi_db_set_output_destination(u32 output_flags
)
75 acpi_gbl_db_output_flags
= (u8
)output_flags
;
77 if ((output_flags
& ACPI_DB_REDIRECTABLE_OUTPUT
) &&
78 acpi_gbl_db_output_to_file
) {
79 acpi_dbg_level
= acpi_gbl_db_debug_level
;
81 acpi_dbg_level
= acpi_gbl_db_console_debug_level
;
85 /*******************************************************************************
87 * FUNCTION: acpi_db_dump_external_object
89 * PARAMETERS: obj_desc - External ACPI object to dump
90 * level - Nesting level.
94 * DESCRIPTION: Dump the contents of an ACPI external object
96 ******************************************************************************/
98 void acpi_db_dump_external_object(union acpi_object
*obj_desc
, u32 level
)
103 acpi_os_printf("[Null Object]\n");
107 for (i
= 0; i
< level
; i
++) {
111 switch (obj_desc
->type
) {
114 acpi_os_printf("[Null Object] (Type=0)\n");
117 case ACPI_TYPE_INTEGER
:
119 acpi_os_printf("[Integer] = %8.8X%8.8X\n",
120 ACPI_FORMAT_UINT64(obj_desc
->integer
.value
));
123 case ACPI_TYPE_STRING
:
125 acpi_os_printf("[String] Length %.2X = ",
126 obj_desc
->string
.length
);
127 acpi_ut_print_string(obj_desc
->string
.pointer
, ACPI_UINT8_MAX
);
128 acpi_os_printf("\n");
131 case ACPI_TYPE_BUFFER
:
133 acpi_os_printf("[Buffer] Length %.2X = ",
134 obj_desc
->buffer
.length
);
135 if (obj_desc
->buffer
.length
) {
136 if (obj_desc
->buffer
.length
> 16) {
137 acpi_os_printf("\n");
140 acpi_ut_debug_dump_buffer(ACPI_CAST_PTR
142 obj_desc
->buffer
.pointer
),
143 obj_desc
->buffer
.length
,
144 DB_BYTE_DISPLAY
, _COMPONENT
);
146 acpi_os_printf("\n");
150 case ACPI_TYPE_PACKAGE
:
152 acpi_os_printf("[Package] Contains %u Elements:\n",
153 obj_desc
->package
.count
);
155 for (i
= 0; i
< obj_desc
->package
.count
; i
++) {
156 acpi_db_dump_external_object(&obj_desc
->package
.
157 elements
[i
], level
+ 1);
161 case ACPI_TYPE_LOCAL_REFERENCE
:
163 acpi_os_printf("[Object Reference] = ");
164 acpi_db_display_internal_object(obj_desc
->reference
.handle
,
168 case ACPI_TYPE_PROCESSOR
:
170 acpi_os_printf("[Processor]\n");
173 case ACPI_TYPE_POWER
:
175 acpi_os_printf("[Power Resource]\n");
180 acpi_os_printf("[Unknown Type] %X\n", obj_desc
->type
);
185 /*******************************************************************************
187 * FUNCTION: acpi_db_prep_namestring
189 * PARAMETERS: name - String to prepare
193 * DESCRIPTION: Translate all forward slashes and dots to backslashes.
195 ******************************************************************************/
197 void acpi_db_prep_namestring(char *name
)
204 acpi_ut_strupr(name
);
206 /* Convert a leading forward slash to a backslash */
212 /* Ignore a leading backslash, this is the root prefix */
214 if (ACPI_IS_ROOT_PREFIX(*name
)) {
218 /* Convert all slash path separators to dots */
221 if ((*name
== '/') || (*name
== '\\')) {
229 /*******************************************************************************
231 * FUNCTION: acpi_db_local_ns_lookup
233 * PARAMETERS: name - Name to lookup
235 * RETURN: Pointer to a namespace node, null on failure
237 * DESCRIPTION: Lookup a name in the ACPI namespace
239 * Note: Currently begins search from the root. Could be enhanced to use
240 * the current prefix (scope) node as the search beginning point.
242 ******************************************************************************/
244 struct acpi_namespace_node
*acpi_db_local_ns_lookup(char *name
)
248 struct acpi_namespace_node
*node
= NULL
;
250 acpi_db_prep_namestring(name
);
252 /* Build an internal namestring */
254 status
= acpi_ns_internalize_name(name
, &internal_path
);
255 if (ACPI_FAILURE(status
)) {
256 acpi_os_printf("Invalid namestring: %s\n", name
);
262 * (Uses root node as the search starting point)
264 status
= acpi_ns_lookup(NULL
, internal_path
, ACPI_TYPE_ANY
,
266 ACPI_NS_NO_UPSEARCH
| ACPI_NS_DONT_OPEN_SCOPE
,
268 if (ACPI_FAILURE(status
)) {
269 acpi_os_printf("Could not locate name: %s, %s\n",
270 name
, acpi_format_exception(status
));
273 ACPI_FREE(internal_path
);
277 /*******************************************************************************
279 * FUNCTION: acpi_db_uint32_to_hex_string
281 * PARAMETERS: value - The value to be converted to string
282 * buffer - Buffer for result (not less than 11 bytes)
286 * DESCRIPTION: Convert the unsigned 32-bit value to the hexadecimal image
288 * NOTE: It is the caller's responsibility to ensure that the length of buffer
291 ******************************************************************************/
293 void acpi_db_uint32_to_hex_string(u32 value
, char *buffer
)
304 for (i
= 7; i
>= 0; i
--) {
305 buffer
[i
] = acpi_gbl_upper_hex_digits
[value
& 0x0F];
310 #ifdef ACPI_OBSOLETE_FUNCTIONS
311 /*******************************************************************************
313 * FUNCTION: acpi_db_second_pass_parse
315 * PARAMETERS: root - Root of the parse tree
319 * DESCRIPTION: Second pass parse of the ACPI tables. We need to wait until
320 * second pass to parse the control methods
322 ******************************************************************************/
324 acpi_status
acpi_db_second_pass_parse(union acpi_parse_object
*root
)
326 union acpi_parse_object
*op
= root
;
327 union acpi_parse_object
*method
;
328 union acpi_parse_object
*search_op
;
329 union acpi_parse_object
*start_op
;
330 acpi_status status
= AE_OK
;
332 struct acpi_walk_state
*walk_state
;
334 ACPI_FUNCTION_ENTRY();
336 acpi_os_printf("Pass two parse ....\n");
339 if (op
->common
.aml_opcode
== AML_METHOD_OP
) {
342 /* Create a new walk state for the parse */
345 acpi_ds_create_walk_state(0, NULL
, NULL
, NULL
);
347 return (AE_NO_MEMORY
);
350 /* Init the Walk State */
352 walk_state
->parser_state
.aml
=
353 walk_state
->parser_state
.aml_start
=
355 walk_state
->parser_state
.aml_end
=
356 walk_state
->parser_state
.pkg_end
=
357 method
->named
.data
+ method
->named
.length
;
358 walk_state
->parser_state
.start_scope
= op
;
360 walk_state
->descending_callback
=
361 acpi_ds_load1_begin_op
;
362 walk_state
->ascending_callback
= acpi_ds_load1_end_op
;
364 /* Perform the AML parse */
366 status
= acpi_ps_parse_aml(walk_state
);
369 (method
->common
.value
.arg
)->common
.aml_offset
+ 1;
370 start_op
= (method
->common
.value
.arg
)->common
.next
;
371 search_op
= start_op
;
374 search_op
->common
.aml_offset
+= base_aml_offset
;
376 acpi_ps_get_depth_next(start_op
, search_op
);
380 if (op
->common
.aml_opcode
== AML_REGION_OP
) {
382 /* TBD: [Investigate] this isn't quite the right thing to do! */
385 * Method = (ACPI_DEFERRED_OP *) Op;
386 * Status = acpi_ps_parse_aml (Op, Method->Body, Method->body_length);
390 if (ACPI_FAILURE(status
)) {
394 op
= acpi_ps_get_depth_next(root
, op
);
400 /*******************************************************************************
402 * FUNCTION: acpi_db_dump_buffer
404 * PARAMETERS: address - Pointer to the buffer
408 * DESCRIPTION: Print a portion of a buffer
410 ******************************************************************************/
412 void acpi_db_dump_buffer(u32 address
)
415 acpi_os_printf("\nLocation %X:\n", address
);
417 acpi_dbg_level
|= ACPI_LV_TABLES
;
418 acpi_ut_debug_dump_buffer(ACPI_TO_POINTER(address
), 64, DB_BYTE_DISPLAY
,