xref: /openbmc/linux/drivers/acpi/acpica/dbinput.c (revision 1372a51b)
1 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
2 /*******************************************************************************
3  *
4  * Module Name: dbinput - user front-end to the AML debugger
5  *
6  ******************************************************************************/
7 
8 #include <acpi/acpi.h>
9 #include "accommon.h"
10 #include "acdebug.h"
11 
12 #ifdef ACPI_APPLICATION
13 #include "acapps.h"
14 #endif
15 
16 #define _COMPONENT          ACPI_CA_DEBUGGER
17 ACPI_MODULE_NAME("dbinput")
18 
19 /* Local prototypes */
20 static u32 acpi_db_get_line(char *input_buffer);
21 
22 static u32 acpi_db_match_command(char *user_command);
23 
24 static void acpi_db_display_command_info(const char *command, u8 display_all);
25 
26 static void acpi_db_display_help(char *command);
27 
28 static u8
29 acpi_db_match_command_help(const char *command,
30 			   const struct acpi_db_command_help *help);
31 
32 /*
33  * Top-level debugger commands.
34  *
35  * This list of commands must match the string table below it
36  */
37 enum acpi_ex_debugger_commands {
38 	CMD_NOT_FOUND = 0,
39 	CMD_NULL,
40 	CMD_ALLOCATIONS,
41 	CMD_ARGS,
42 	CMD_ARGUMENTS,
43 	CMD_BREAKPOINT,
44 	CMD_BUSINFO,
45 	CMD_CALL,
46 	CMD_DEBUG,
47 	CMD_DISASSEMBLE,
48 	CMD_DISASM,
49 	CMD_DUMP,
50 	CMD_EVALUATE,
51 	CMD_EXECUTE,
52 	CMD_EXIT,
53 	CMD_FIELDS,
54 	CMD_FIND,
55 	CMD_GO,
56 	CMD_HANDLERS,
57 	CMD_HELP,
58 	CMD_HELP2,
59 	CMD_HISTORY,
60 	CMD_HISTORY_EXE,
61 	CMD_HISTORY_LAST,
62 	CMD_INFORMATION,
63 	CMD_INTEGRITY,
64 	CMD_INTO,
65 	CMD_LEVEL,
66 	CMD_LIST,
67 	CMD_LOCALS,
68 	CMD_LOCKS,
69 	CMD_METHODS,
70 	CMD_NAMESPACE,
71 	CMD_NOTIFY,
72 	CMD_OBJECTS,
73 	CMD_OSI,
74 	CMD_OWNER,
75 	CMD_PATHS,
76 	CMD_PREDEFINED,
77 	CMD_PREFIX,
78 	CMD_QUIT,
79 	CMD_REFERENCES,
80 	CMD_RESOURCES,
81 	CMD_RESULTS,
82 	CMD_SET,
83 	CMD_STATS,
84 	CMD_STOP,
85 	CMD_TABLES,
86 	CMD_TEMPLATE,
87 	CMD_TRACE,
88 	CMD_TREE,
89 	CMD_TYPE,
90 #ifdef ACPI_APPLICATION
91 	CMD_ENABLEACPI,
92 	CMD_EVENT,
93 	CMD_GPE,
94 	CMD_GPES,
95 	CMD_SCI,
96 	CMD_SLEEP,
97 
98 	CMD_CLOSE,
99 	CMD_LOAD,
100 	CMD_OPEN,
101 	CMD_UNLOAD,
102 
103 	CMD_TERMINATE,
104 	CMD_BACKGROUND,
105 	CMD_THREADS,
106 
107 	CMD_TEST,
108 #endif
109 };
110 
111 #define CMD_FIRST_VALID     2
112 
113 /* Second parameter is the required argument count */
114 
115 static const struct acpi_db_command_info acpi_gbl_db_commands[] = {
116 	{"<NOT FOUND>", 0},
117 	{"<NULL>", 0},
118 	{"ALLOCATIONS", 0},
119 	{"ARGS", 0},
120 	{"ARGUMENTS", 0},
121 	{"BREAKPOINT", 1},
122 	{"BUSINFO", 0},
123 	{"CALL", 0},
124 	{"DEBUG", 1},
125 	{"DISASSEMBLE", 1},
126 	{"DISASM", 1},
127 	{"DUMP", 1},
128 	{"EVALUATE", 1},
129 	{"EXECUTE", 1},
130 	{"EXIT", 0},
131 	{"FIELDS", 1},
132 	{"FIND", 1},
133 	{"GO", 0},
134 	{"HANDLERS", 0},
135 	{"HELP", 0},
136 	{"?", 0},
137 	{"HISTORY", 0},
138 	{"!", 1},
139 	{"!!", 0},
140 	{"INFORMATION", 0},
141 	{"INTEGRITY", 0},
142 	{"INTO", 0},
143 	{"LEVEL", 0},
144 	{"LIST", 0},
145 	{"LOCALS", 0},
146 	{"LOCKS", 0},
147 	{"METHODS", 0},
148 	{"NAMESPACE", 0},
149 	{"NOTIFY", 2},
150 	{"OBJECTS", 0},
151 	{"OSI", 0},
152 	{"OWNER", 1},
153 	{"PATHS", 0},
154 	{"PREDEFINED", 0},
155 	{"PREFIX", 0},
156 	{"QUIT", 0},
157 	{"REFERENCES", 1},
158 	{"RESOURCES", 0},
159 	{"RESULTS", 0},
160 	{"SET", 3},
161 	{"STATS", 1},
162 	{"STOP", 0},
163 	{"TABLES", 0},
164 	{"TEMPLATE", 1},
165 	{"TRACE", 1},
166 	{"TREE", 0},
167 	{"TYPE", 1},
168 #ifdef ACPI_APPLICATION
169 	{"ENABLEACPI", 0},
170 	{"EVENT", 1},
171 	{"GPE", 1},
172 	{"GPES", 0},
173 	{"SCI", 0},
174 	{"SLEEP", 0},
175 
176 	{"CLOSE", 0},
177 	{"LOAD", 1},
178 	{"OPEN", 1},
179 	{"UNLOAD", 1},
180 
181 	{"TERMINATE", 0},
182 	{"BACKGROUND", 1},
183 	{"THREADS", 3},
184 
185 	{"TEST", 1},
186 #endif
187 	{NULL, 0}
188 };
189 
190 /*
191  * Help for all debugger commands. First argument is the number of lines
192  * of help to output for the command.
193  *
194  * Note: Some commands are not supported by the kernel-level version of
195  * the debugger.
196  */
197 static const struct acpi_db_command_help acpi_gbl_db_command_help[] = {
198 	{0, "\nNamespace Access:", "\n"},
199 	{1, "  Businfo", "Display system bus info\n"},
200 	{1, "  Disassemble <Method>", "Disassemble a control method\n"},
201 	{1, "  Find <AcpiName> (? is wildcard)",
202 	 "Find ACPI name(s) with wildcards\n"},
203 	{1, "  Integrity", "Validate namespace integrity\n"},
204 	{1, "  Methods", "Display list of loaded control methods\n"},
205 	{1, "  Fields <AddressSpaceId>",
206 	 "Display list of loaded field units by space ID\n"},
207 	{1, "  Namespace [Object] [Depth]",
208 	 "Display loaded namespace tree/subtree\n"},
209 	{1, "  Notify <Object> <Value>", "Send a notification on Object\n"},
210 	{1, "  Objects [ObjectType]",
211 	 "Display summary of all objects or just given type\n"},
212 	{1, "  Owner <OwnerId> [Depth]",
213 	 "Display loaded namespace by object owner\n"},
214 	{1, "  Paths", "Display full pathnames of namespace objects\n"},
215 	{1, "  Predefined", "Check all predefined names\n"},
216 	{1, "  Prefix [<Namepath>]", "Set or Get current execution prefix\n"},
217 	{1, "  References <Addr>", "Find all references to object at addr\n"},
218 	{1, "  Resources [DeviceName]",
219 	 "Display Device resources (no arg = all devices)\n"},
220 	{1, "  Set N <NamedObject> <Value>", "Set value for named integer\n"},
221 	{1, "  Template <Object>", "Format/dump a Buffer/ResourceTemplate\n"},
222 	{1, "  Type <Object>", "Display object type\n"},
223 
224 	{0, "\nControl Method Execution:", "\n"},
225 	{1, "  Evaluate <Namepath> [Arguments]",
226 	 "Evaluate object or control method\n"},
227 	{1, "  Execute <Namepath> [Arguments]", "Synonym for Evaluate\n"},
228 #ifdef ACPI_APPLICATION
229 	{1, "  Background <Namepath> [Arguments]",
230 	 "Evaluate object/method in a separate thread\n"},
231 	{1, "  Thread <Threads><Loops><NamePath>",
232 	 "Spawn threads to execute method(s)\n"},
233 #endif
234 	{1, "  Debug <Namepath> [Arguments]", "Single-Step a control method\n"},
235 	{7, "  [Arguments] formats:", "Control method argument formats\n"},
236 	{1, "     Hex Integer", "Integer\n"},
237 	{1, "     \"Ascii String\"", "String\n"},
238 	{1, "     (Hex Byte List)", "Buffer\n"},
239 	{1, "         (01 42 7A BF)", "Buffer example (4 bytes)\n"},
240 	{1, "     [Package Element List]", "Package\n"},
241 	{1, "         [0x01 0x1234 \"string\"]",
242 	 "Package example (3 elements)\n"},
243 
244 	{0, "\nMiscellaneous:", "\n"},
245 	{1, "  Allocations", "Display list of current memory allocations\n"},
246 	{2, "  Dump <Address>|<Namepath>", "\n"},
247 	{0, "       [Byte|Word|Dword|Qword]",
248 	 "Display ACPI objects or memory\n"},
249 	{1, "  Handlers", "Info about global handlers\n"},
250 	{1, "  Help [Command]", "This help screen or individual command\n"},
251 	{1, "  History", "Display command history buffer\n"},
252 	{1, "  Level <DebugLevel>] [console]",
253 	 "Get/Set debug level for file or console\n"},
254 	{1, "  Locks", "Current status of internal mutexes\n"},
255 	{1, "  Osi [Install|Remove <name>]",
256 	 "Display or modify global _OSI list\n"},
257 	{1, "  Quit or Exit", "Exit this command\n"},
258 	{8, "  Stats <SubCommand>",
259 	 "Display namespace and memory statistics\n"},
260 	{1, "     Allocations", "Display list of current memory allocations\n"},
261 	{1, "     Memory", "Dump internal memory lists\n"},
262 	{1, "     Misc", "Namespace search and mutex stats\n"},
263 	{1, "     Objects", "Summary of namespace objects\n"},
264 	{1, "     Sizes", "Sizes for each of the internal objects\n"},
265 	{1, "     Stack", "Display CPU stack usage\n"},
266 	{1, "     Tables", "Info about current ACPI table(s)\n"},
267 	{1, "  Tables", "Display info about loaded ACPI tables\n"},
268 #ifdef ACPI_APPLICATION
269 	{1, "  Terminate", "Delete namespace and all internal objects\n"},
270 #endif
271 	{1, "  ! <CommandNumber>", "Execute command from history buffer\n"},
272 	{1, "  !!", "Execute last command again\n"},
273 
274 	{0, "\nMethod and Namespace Debugging:", "\n"},
275 	{5, "  Trace <State> [<Namepath>] [Once]",
276 	 "Trace control method execution\n"},
277 	{1, "     Enable", "Enable all messages\n"},
278 	{1, "     Disable", "Disable tracing\n"},
279 	{1, "     Method", "Enable method execution messages\n"},
280 	{1, "     Opcode", "Enable opcode execution messages\n"},
281 	{3, "  Test <TestName>", "Invoke a debug test\n"},
282 	{1, "     Objects", "Read/write/compare all namespace data objects\n"},
283 	{1, "     Predefined",
284 	 "Validate all ACPI predefined names (_STA, etc.)\n"},
285 	{1, "  Execute predefined",
286 	 "Execute all predefined (public) methods\n"},
287 
288 	{0, "\nControl Method Single-Step Execution:", "\n"},
289 	{1, "  Arguments (or Args)", "Display method arguments\n"},
290 	{1, "  Breakpoint <AmlOffset>", "Set an AML execution breakpoint\n"},
291 	{1, "  Call", "Run to next control method invocation\n"},
292 	{1, "  Go", "Allow method to run to completion\n"},
293 	{1, "  Information", "Display info about the current method\n"},
294 	{1, "  Into", "Step into (not over) a method call\n"},
295 	{1, "  List [# of Aml Opcodes]", "Display method ASL statements\n"},
296 	{1, "  Locals", "Display method local variables\n"},
297 	{1, "  Results", "Display method result stack\n"},
298 	{1, "  Set <A|L> <#> <Value>", "Set method data (Arguments/Locals)\n"},
299 	{1, "  Stop", "Terminate control method\n"},
300 	{1, "  Tree", "Display control method calling tree\n"},
301 	{1, "  <Enter>", "Single step next AML opcode (over calls)\n"},
302 
303 #ifdef ACPI_APPLICATION
304 	{0, "\nFile Operations:", "\n"},
305 	{1, "  Close", "Close debug output file\n"},
306 	{1, "  Load <Input Filename>", "Load ACPI table from a file\n"},
307 	{1, "  Open <Output Filename>", "Open a file for debug output\n"},
308 	{1, "  Unload <Namepath>",
309 	 "Unload an ACPI table via namespace object\n"},
310 
311 	{0, "\nHardware Simulation:", "\n"},
312 	{1, "  EnableAcpi", "Enable ACPI (hardware) mode\n"},
313 	{1, "  Event <F|G> <Value>", "Generate AcpiEvent (Fixed/GPE)\n"},
314 	{1, "  Gpe <GpeNum> [GpeBlockDevice]", "Simulate a GPE\n"},
315 	{1, "  Gpes", "Display info on all GPE devices\n"},
316 	{1, "  Sci", "Generate an SCI\n"},
317 	{1, "  Sleep [SleepState]", "Simulate sleep/wake sequence(s) (0-5)\n"},
318 #endif
319 	{0, NULL, NULL}
320 };
321 
322 /*******************************************************************************
323  *
324  * FUNCTION:    acpi_db_match_command_help
325  *
326  * PARAMETERS:  command             - Command string to match
327  *              help                - Help table entry to attempt match
328  *
329  * RETURN:      TRUE if command matched, FALSE otherwise
330  *
331  * DESCRIPTION: Attempt to match a command in the help table in order to
332  *              print help information for a single command.
333  *
334  ******************************************************************************/
335 
336 static u8
337 acpi_db_match_command_help(const char *command,
338 			   const struct acpi_db_command_help *help)
339 {
340 	char *invocation = help->invocation;
341 	u32 line_count;
342 
343 	/* Valid commands in the help table begin with a couple of spaces */
344 
345 	if (*invocation != ' ') {
346 		return (FALSE);
347 	}
348 
349 	while (*invocation == ' ') {
350 		invocation++;
351 	}
352 
353 	/* Match command name (full command or substring) */
354 
355 	while ((*command) && (*invocation) && (*invocation != ' ')) {
356 		if (tolower((int)*command) != tolower((int)*invocation)) {
357 			return (FALSE);
358 		}
359 
360 		invocation++;
361 		command++;
362 	}
363 
364 	/* Print the appropriate number of help lines */
365 
366 	line_count = help->line_count;
367 	while (line_count) {
368 		acpi_os_printf("%-38s : %s", help->invocation,
369 			       help->description);
370 		help++;
371 		line_count--;
372 	}
373 
374 	return (TRUE);
375 }
376 
377 /*******************************************************************************
378  *
379  * FUNCTION:    acpi_db_display_command_info
380  *
381  * PARAMETERS:  command             - Command string to match
382  *              display_all         - Display all matching commands, or just
383  *                                    the first one (substring match)
384  *
385  * RETURN:      None
386  *
387  * DESCRIPTION: Display help information for a Debugger command.
388  *
389  ******************************************************************************/
390 
391 static void acpi_db_display_command_info(const char *command, u8 display_all)
392 {
393 	const struct acpi_db_command_help *next;
394 	u8 matched;
395 
396 	next = acpi_gbl_db_command_help;
397 	while (next->invocation) {
398 		matched = acpi_db_match_command_help(command, next);
399 		if (!display_all && matched) {
400 			return;
401 		}
402 
403 		next++;
404 	}
405 }
406 
407 /*******************************************************************************
408  *
409  * FUNCTION:    acpi_db_display_help
410  *
411  * PARAMETERS:  command             - Optional command string to display help.
412  *                                    if not specified, all debugger command
413  *                                    help strings are displayed
414  *
415  * RETURN:      None
416  *
417  * DESCRIPTION: Display help for a single debugger command, or all of them.
418  *
419  ******************************************************************************/
420 
421 static void acpi_db_display_help(char *command)
422 {
423 	const struct acpi_db_command_help *next = acpi_gbl_db_command_help;
424 
425 	if (!command) {
426 
427 		/* No argument to help, display help for all commands */
428 
429 		acpi_os_printf("\nSummary of AML Debugger Commands\n\n");
430 
431 		while (next->invocation) {
432 			acpi_os_printf("%-38s%s", next->invocation,
433 				       next->description);
434 			next++;
435 		}
436 		acpi_os_printf("\n");
437 
438 	} else {
439 		/* Display help for all commands that match the subtring */
440 
441 		acpi_db_display_command_info(command, TRUE);
442 	}
443 }
444 
445 /*******************************************************************************
446  *
447  * FUNCTION:    acpi_db_get_next_token
448  *
449  * PARAMETERS:  string          - Command buffer
450  *              next            - Return value, end of next token
451  *
452  * RETURN:      Pointer to the start of the next token.
453  *
454  * DESCRIPTION: Command line parsing. Get the next token on the command line
455  *
456  ******************************************************************************/
457 
458 char *acpi_db_get_next_token(char *string,
459 			     char **next, acpi_object_type *return_type)
460 {
461 	char *start;
462 	u32 depth;
463 	acpi_object_type type = ACPI_TYPE_INTEGER;
464 
465 	/* At end of buffer? */
466 
467 	if (!string || !(*string)) {
468 		return (NULL);
469 	}
470 
471 	/* Remove any spaces at the beginning */
472 
473 	if (*string == ' ') {
474 		while (*string && (*string == ' ')) {
475 			string++;
476 		}
477 
478 		if (!(*string)) {
479 			return (NULL);
480 		}
481 	}
482 
483 	switch (*string) {
484 	case '"':
485 
486 		/* This is a quoted string, scan until closing quote */
487 
488 		string++;
489 		start = string;
490 		type = ACPI_TYPE_STRING;
491 
492 		/* Find end of string */
493 
494 		while (*string && (*string != '"')) {
495 			string++;
496 		}
497 		break;
498 
499 	case '(':
500 
501 		/* This is the start of a buffer, scan until closing paren */
502 
503 		string++;
504 		start = string;
505 		type = ACPI_TYPE_BUFFER;
506 
507 		/* Find end of buffer */
508 
509 		while (*string && (*string != ')')) {
510 			string++;
511 		}
512 		break;
513 
514 	case '{':
515 
516 		/* This is the start of a field unit, scan until closing brace */
517 
518 		string++;
519 		start = string;
520 		type = ACPI_TYPE_FIELD_UNIT;
521 
522 		/* Find end of buffer */
523 
524 		while (*string && (*string != '}')) {
525 			string++;
526 		}
527 		break;
528 
529 	case '[':
530 
531 		/* This is the start of a package, scan until closing bracket */
532 
533 		string++;
534 		depth = 1;
535 		start = string;
536 		type = ACPI_TYPE_PACKAGE;
537 
538 		/* Find end of package (closing bracket) */
539 
540 		while (*string) {
541 
542 			/* Handle String package elements */
543 
544 			if (*string == '"') {
545 				/* Find end of string */
546 
547 				string++;
548 				while (*string && (*string != '"')) {
549 					string++;
550 				}
551 				if (!(*string)) {
552 					break;
553 				}
554 			} else if (*string == '[') {
555 				depth++;	/* A nested package declaration */
556 			} else if (*string == ']') {
557 				depth--;
558 				if (depth == 0) {	/* Found final package closing bracket */
559 					break;
560 				}
561 			}
562 
563 			string++;
564 		}
565 		break;
566 
567 	default:
568 
569 		start = string;
570 
571 		/* Find end of token */
572 
573 		while (*string && (*string != ' ')) {
574 			string++;
575 		}
576 		break;
577 	}
578 
579 	if (!(*string)) {
580 		*next = NULL;
581 	} else {
582 		*string = 0;
583 		*next = string + 1;
584 	}
585 
586 	*return_type = type;
587 	return (start);
588 }
589 
590 /*******************************************************************************
591  *
592  * FUNCTION:    acpi_db_get_line
593  *
594  * PARAMETERS:  input_buffer        - Command line buffer
595  *
596  * RETURN:      Count of arguments to the command
597  *
598  * DESCRIPTION: Get the next command line from the user. Gets entire line
599  *              up to the next newline
600  *
601  ******************************************************************************/
602 
603 static u32 acpi_db_get_line(char *input_buffer)
604 {
605 	u32 i;
606 	u32 count;
607 	char *next;
608 	char *this;
609 
610 	if (acpi_ut_safe_strcpy
611 	    (acpi_gbl_db_parsed_buf, sizeof(acpi_gbl_db_parsed_buf),
612 	     input_buffer)) {
613 		acpi_os_printf
614 		    ("Buffer overflow while parsing input line (max %u characters)\n",
615 		     (u32)sizeof(acpi_gbl_db_parsed_buf));
616 		return (0);
617 	}
618 
619 	this = acpi_gbl_db_parsed_buf;
620 	for (i = 0; i < ACPI_DEBUGGER_MAX_ARGS; i++) {
621 		acpi_gbl_db_args[i] = acpi_db_get_next_token(this, &next,
622 							     &acpi_gbl_db_arg_types
623 							     [i]);
624 		if (!acpi_gbl_db_args[i]) {
625 			break;
626 		}
627 
628 		this = next;
629 	}
630 
631 	/* Uppercase the actual command */
632 
633 	acpi_ut_strupr(acpi_gbl_db_args[0]);
634 
635 	count = i;
636 	if (count) {
637 		count--;	/* Number of args only */
638 	}
639 
640 	return (count);
641 }
642 
643 /*******************************************************************************
644  *
645  * FUNCTION:    acpi_db_match_command
646  *
647  * PARAMETERS:  user_command            - User command line
648  *
649  * RETURN:      Index into command array, -1 if not found
650  *
651  * DESCRIPTION: Search command array for a command match
652  *
653  ******************************************************************************/
654 
655 static u32 acpi_db_match_command(char *user_command)
656 {
657 	u32 i;
658 
659 	if (!user_command || user_command[0] == 0) {
660 		return (CMD_NULL);
661 	}
662 
663 	for (i = CMD_FIRST_VALID; acpi_gbl_db_commands[i].name; i++) {
664 		if (strstr
665 		    (ACPI_CAST_PTR(char, acpi_gbl_db_commands[i].name),
666 		     user_command) == acpi_gbl_db_commands[i].name) {
667 			return (i);
668 		}
669 	}
670 
671 	/* Command not recognized */
672 
673 	return (CMD_NOT_FOUND);
674 }
675 
676 /*******************************************************************************
677  *
678  * FUNCTION:    acpi_db_command_dispatch
679  *
680  * PARAMETERS:  input_buffer        - Command line buffer
681  *              walk_state          - Current walk
682  *              op                  - Current (executing) parse op
683  *
684  * RETURN:      Status
685  *
686  * DESCRIPTION: Command dispatcher.
687  *
688  ******************************************************************************/
689 
690 acpi_status
691 acpi_db_command_dispatch(char *input_buffer,
692 			 struct acpi_walk_state *walk_state,
693 			 union acpi_parse_object *op)
694 {
695 	u32 temp;
696 	u64 temp64;
697 	u32 command_index;
698 	u32 param_count;
699 	char *command_line;
700 	acpi_status status = AE_CTRL_TRUE;
701 
702 	/* If acpi_terminate has been called, terminate this thread */
703 
704 	if (acpi_gbl_db_terminate_loop) {
705 		return (AE_CTRL_TERMINATE);
706 	}
707 
708 	/* Find command and add to the history buffer */
709 
710 	param_count = acpi_db_get_line(input_buffer);
711 	command_index = acpi_db_match_command(acpi_gbl_db_args[0]);
712 
713 	/*
714 	 * We don't want to add the !! command to the history buffer. It
715 	 * would cause an infinite loop because it would always be the
716 	 * previous command.
717 	 */
718 	if (command_index != CMD_HISTORY_LAST) {
719 		acpi_db_add_to_history(input_buffer);
720 	}
721 
722 	/* Verify that we have the minimum number of params */
723 
724 	if (param_count < acpi_gbl_db_commands[command_index].min_args) {
725 		acpi_os_printf
726 		    ("%u parameters entered, [%s] requires %u parameters\n",
727 		     param_count, acpi_gbl_db_commands[command_index].name,
728 		     acpi_gbl_db_commands[command_index].min_args);
729 
730 		acpi_db_display_command_info(acpi_gbl_db_commands
731 					     [command_index].name, FALSE);
732 		return (AE_CTRL_TRUE);
733 	}
734 
735 	/* Decode and dispatch the command */
736 
737 	switch (command_index) {
738 	case CMD_NULL:
739 
740 		if (op) {
741 			return (AE_OK);
742 		}
743 		break;
744 
745 	case CMD_ALLOCATIONS:
746 
747 #ifdef ACPI_DBG_TRACK_ALLOCATIONS
748 		acpi_ut_dump_allocations((u32)-1, NULL);
749 #endif
750 		break;
751 
752 	case CMD_ARGS:
753 	case CMD_ARGUMENTS:
754 
755 		acpi_db_display_arguments();
756 		break;
757 
758 	case CMD_BREAKPOINT:
759 
760 		acpi_db_set_method_breakpoint(acpi_gbl_db_args[1], walk_state,
761 					      op);
762 		break;
763 
764 	case CMD_BUSINFO:
765 
766 		acpi_db_get_bus_info();
767 		break;
768 
769 	case CMD_CALL:
770 
771 		acpi_db_set_method_call_breakpoint(op);
772 		status = AE_OK;
773 		break;
774 
775 	case CMD_DEBUG:
776 
777 		acpi_db_execute(acpi_gbl_db_args[1],
778 				&acpi_gbl_db_args[2], &acpi_gbl_db_arg_types[2],
779 				EX_SINGLE_STEP);
780 		break;
781 
782 	case CMD_DISASSEMBLE:
783 	case CMD_DISASM:
784 
785 #ifdef ACPI_DISASSEMBLER
786 		(void)acpi_db_disassemble_method(acpi_gbl_db_args[1]);
787 #else
788 		acpi_os_printf
789 		    ("The AML Disassembler is not configured/present\n");
790 #endif
791 		break;
792 
793 	case CMD_DUMP:
794 
795 		acpi_db_decode_and_display_object(acpi_gbl_db_args[1],
796 						  acpi_gbl_db_args[2]);
797 		break;
798 
799 	case CMD_EVALUATE:
800 	case CMD_EXECUTE:
801 
802 		acpi_db_execute(acpi_gbl_db_args[1],
803 				&acpi_gbl_db_args[2], &acpi_gbl_db_arg_types[2],
804 				EX_NO_SINGLE_STEP);
805 		break;
806 
807 	case CMD_FIND:
808 
809 		status = acpi_db_find_name_in_namespace(acpi_gbl_db_args[1]);
810 		break;
811 
812 	case CMD_FIELDS:
813 
814 		status = acpi_ut_strtoul64(acpi_gbl_db_args[1], &temp64);
815 
816 		if (ACPI_FAILURE(status)
817 		    || temp64 >= ACPI_NUM_PREDEFINED_REGIONS) {
818 			acpi_os_printf
819 			    ("Invalid adress space ID: must be between 0 and %u inclusive\n",
820 			     ACPI_NUM_PREDEFINED_REGIONS - 1);
821 			return (AE_OK);
822 		}
823 
824 		status = acpi_db_display_fields((u32)temp64);
825 		break;
826 
827 	case CMD_GO:
828 
829 		acpi_gbl_cm_single_step = FALSE;
830 		return (AE_OK);
831 
832 	case CMD_HANDLERS:
833 
834 		acpi_db_display_handlers();
835 		break;
836 
837 	case CMD_HELP:
838 	case CMD_HELP2:
839 
840 		acpi_db_display_help(acpi_gbl_db_args[1]);
841 		break;
842 
843 	case CMD_HISTORY:
844 
845 		acpi_db_display_history();
846 		break;
847 
848 	case CMD_HISTORY_EXE:	/* ! command */
849 
850 		command_line = acpi_db_get_from_history(acpi_gbl_db_args[1]);
851 		if (!command_line) {
852 			return (AE_CTRL_TRUE);
853 		}
854 
855 		status = acpi_db_command_dispatch(command_line, walk_state, op);
856 		return (status);
857 
858 	case CMD_HISTORY_LAST:	/* !! command */
859 
860 		command_line = acpi_db_get_from_history(NULL);
861 		if (!command_line) {
862 			return (AE_CTRL_TRUE);
863 		}
864 
865 		status = acpi_db_command_dispatch(command_line, walk_state, op);
866 		return (status);
867 
868 	case CMD_INFORMATION:
869 
870 		acpi_db_display_method_info(op);
871 		break;
872 
873 	case CMD_INTEGRITY:
874 
875 		acpi_db_check_integrity();
876 		break;
877 
878 	case CMD_INTO:
879 
880 		if (op) {
881 			acpi_gbl_cm_single_step = TRUE;
882 			return (AE_OK);
883 		}
884 		break;
885 
886 	case CMD_LEVEL:
887 
888 		if (param_count == 0) {
889 			acpi_os_printf
890 			    ("Current debug level for file output is:    %8.8X\n",
891 			     acpi_gbl_db_debug_level);
892 			acpi_os_printf
893 			    ("Current debug level for console output is: %8.8X\n",
894 			     acpi_gbl_db_console_debug_level);
895 		} else if (param_count == 2) {
896 			temp = acpi_gbl_db_console_debug_level;
897 			acpi_gbl_db_console_debug_level =
898 			    strtoul(acpi_gbl_db_args[1], NULL, 16);
899 			acpi_os_printf
900 			    ("Debug Level for console output was %8.8X, now %8.8X\n",
901 			     temp, acpi_gbl_db_console_debug_level);
902 		} else {
903 			temp = acpi_gbl_db_debug_level;
904 			acpi_gbl_db_debug_level =
905 			    strtoul(acpi_gbl_db_args[1], NULL, 16);
906 			acpi_os_printf
907 			    ("Debug Level for file output was %8.8X, now %8.8X\n",
908 			     temp, acpi_gbl_db_debug_level);
909 		}
910 		break;
911 
912 	case CMD_LIST:
913 
914 #ifdef ACPI_DISASSEMBLER
915 		acpi_db_disassemble_aml(acpi_gbl_db_args[1], op);
916 #else
917 		acpi_os_printf
918 		    ("The AML Disassembler is not configured/present\n");
919 #endif
920 		break;
921 
922 	case CMD_LOCKS:
923 
924 		acpi_db_display_locks();
925 		break;
926 
927 	case CMD_LOCALS:
928 
929 		acpi_db_display_locals();
930 		break;
931 
932 	case CMD_METHODS:
933 
934 		status = acpi_db_display_objects("METHOD", acpi_gbl_db_args[1]);
935 		break;
936 
937 	case CMD_NAMESPACE:
938 
939 		acpi_db_dump_namespace(acpi_gbl_db_args[1],
940 				       acpi_gbl_db_args[2]);
941 		break;
942 
943 	case CMD_NOTIFY:
944 
945 		temp = strtoul(acpi_gbl_db_args[2], NULL, 0);
946 		acpi_db_send_notify(acpi_gbl_db_args[1], temp);
947 		break;
948 
949 	case CMD_OBJECTS:
950 
951 		acpi_ut_strupr(acpi_gbl_db_args[1]);
952 		status =
953 		    acpi_db_display_objects(acpi_gbl_db_args[1],
954 					    acpi_gbl_db_args[2]);
955 		break;
956 
957 	case CMD_OSI:
958 
959 		acpi_db_display_interfaces(acpi_gbl_db_args[1],
960 					   acpi_gbl_db_args[2]);
961 		break;
962 
963 	case CMD_OWNER:
964 
965 		acpi_db_dump_namespace_by_owner(acpi_gbl_db_args[1],
966 						acpi_gbl_db_args[2]);
967 		break;
968 
969 	case CMD_PATHS:
970 
971 		acpi_db_dump_namespace_paths();
972 		break;
973 
974 	case CMD_PREFIX:
975 
976 		acpi_db_set_scope(acpi_gbl_db_args[1]);
977 		break;
978 
979 	case CMD_REFERENCES:
980 
981 		acpi_db_find_references(acpi_gbl_db_args[1]);
982 		break;
983 
984 	case CMD_RESOURCES:
985 
986 		acpi_db_display_resources(acpi_gbl_db_args[1]);
987 		break;
988 
989 	case CMD_RESULTS:
990 
991 		acpi_db_display_results();
992 		break;
993 
994 	case CMD_SET:
995 
996 		acpi_db_set_method_data(acpi_gbl_db_args[1],
997 					acpi_gbl_db_args[2],
998 					acpi_gbl_db_args[3]);
999 		break;
1000 
1001 	case CMD_STATS:
1002 
1003 		status = acpi_db_display_statistics(acpi_gbl_db_args[1]);
1004 		break;
1005 
1006 	case CMD_STOP:
1007 
1008 		return (AE_NOT_IMPLEMENTED);
1009 
1010 	case CMD_TABLES:
1011 
1012 		acpi_db_display_table_info(acpi_gbl_db_args[1]);
1013 		break;
1014 
1015 	case CMD_TEMPLATE:
1016 
1017 		acpi_db_display_template(acpi_gbl_db_args[1]);
1018 		break;
1019 
1020 	case CMD_TRACE:
1021 
1022 		acpi_db_trace(acpi_gbl_db_args[1], acpi_gbl_db_args[2],
1023 			      acpi_gbl_db_args[3]);
1024 		break;
1025 
1026 	case CMD_TREE:
1027 
1028 		acpi_db_display_calling_tree();
1029 		break;
1030 
1031 	case CMD_TYPE:
1032 
1033 		acpi_db_display_object_type(acpi_gbl_db_args[1]);
1034 		break;
1035 
1036 #ifdef ACPI_APPLICATION
1037 
1038 		/* Hardware simulation commands. */
1039 
1040 	case CMD_ENABLEACPI:
1041 #if (!ACPI_REDUCED_HARDWARE)
1042 
1043 		status = acpi_enable();
1044 		if (ACPI_FAILURE(status)) {
1045 			acpi_os_printf("AcpiEnable failed (Status=%X)\n",
1046 				       status);
1047 			return (status);
1048 		}
1049 #endif				/* !ACPI_REDUCED_HARDWARE */
1050 		break;
1051 
1052 	case CMD_EVENT:
1053 
1054 		acpi_os_printf("Event command not implemented\n");
1055 		break;
1056 
1057 	case CMD_GPE:
1058 
1059 		acpi_db_generate_gpe(acpi_gbl_db_args[1], acpi_gbl_db_args[2]);
1060 		break;
1061 
1062 	case CMD_GPES:
1063 
1064 		acpi_db_display_gpes();
1065 		break;
1066 
1067 	case CMD_SCI:
1068 
1069 		acpi_db_generate_sci();
1070 		break;
1071 
1072 	case CMD_SLEEP:
1073 
1074 		status = acpi_db_sleep(acpi_gbl_db_args[1]);
1075 		break;
1076 
1077 		/* File I/O commands. */
1078 
1079 	case CMD_CLOSE:
1080 
1081 		acpi_db_close_debug_file();
1082 		break;
1083 
1084 	case CMD_LOAD:{
1085 			struct acpi_new_table_desc *list_head = NULL;
1086 
1087 			status =
1088 			    ac_get_all_tables_from_file(acpi_gbl_db_args[1],
1089 							ACPI_GET_ALL_TABLES,
1090 							&list_head);
1091 			if (ACPI_SUCCESS(status)) {
1092 				acpi_db_load_tables(list_head);
1093 			}
1094 		}
1095 		break;
1096 
1097 	case CMD_OPEN:
1098 
1099 		acpi_db_open_debug_file(acpi_gbl_db_args[1]);
1100 		break;
1101 
1102 		/* User space commands. */
1103 
1104 	case CMD_TERMINATE:
1105 
1106 		acpi_db_set_output_destination(ACPI_DB_REDIRECTABLE_OUTPUT);
1107 		acpi_ut_subsystem_shutdown();
1108 
1109 		/*
1110 		 * TBD: [Restructure] Need some way to re-initialize without
1111 		 * re-creating the semaphores!
1112 		 */
1113 
1114 		acpi_gbl_db_terminate_loop = TRUE;
1115 		/*  acpi_initialize (NULL); */
1116 		break;
1117 
1118 	case CMD_BACKGROUND:
1119 
1120 		acpi_db_create_execution_thread(acpi_gbl_db_args[1],
1121 						&acpi_gbl_db_args[2],
1122 						&acpi_gbl_db_arg_types[2]);
1123 		break;
1124 
1125 	case CMD_THREADS:
1126 
1127 		acpi_db_create_execution_threads(acpi_gbl_db_args[1],
1128 						 acpi_gbl_db_args[2],
1129 						 acpi_gbl_db_args[3]);
1130 		break;
1131 
1132 		/* Debug test commands. */
1133 
1134 	case CMD_PREDEFINED:
1135 
1136 		acpi_db_check_predefined_names();
1137 		break;
1138 
1139 	case CMD_TEST:
1140 
1141 		acpi_db_execute_test(acpi_gbl_db_args[1]);
1142 		break;
1143 
1144 	case CMD_UNLOAD:
1145 
1146 		acpi_db_unload_acpi_table(acpi_gbl_db_args[1]);
1147 		break;
1148 #endif
1149 
1150 	case CMD_EXIT:
1151 	case CMD_QUIT:
1152 
1153 		if (op) {
1154 			acpi_os_printf("Method execution terminated\n");
1155 			return (AE_CTRL_TERMINATE);
1156 		}
1157 
1158 		if (!acpi_gbl_db_output_to_file) {
1159 			acpi_dbg_level = ACPI_DEBUG_DEFAULT;
1160 		}
1161 #ifdef ACPI_APPLICATION
1162 		acpi_db_close_debug_file();
1163 #endif
1164 		acpi_gbl_db_terminate_loop = TRUE;
1165 		return (AE_CTRL_TERMINATE);
1166 
1167 	case CMD_NOT_FOUND:
1168 	default:
1169 
1170 		acpi_os_printf("%s: unknown command\n", acpi_gbl_db_args[0]);
1171 		return (AE_CTRL_TRUE);
1172 	}
1173 
1174 	if (ACPI_SUCCESS(status)) {
1175 		status = AE_CTRL_TRUE;
1176 	}
1177 
1178 	return (status);
1179 }
1180 
1181 /*******************************************************************************
1182  *
1183  * FUNCTION:    acpi_db_execute_thread
1184  *
1185  * PARAMETERS:  context         - Not used
1186  *
1187  * RETURN:      None
1188  *
1189  * DESCRIPTION: Debugger execute thread. Waits for a command line, then
1190  *              simply dispatches it.
1191  *
1192  ******************************************************************************/
1193 
1194 void ACPI_SYSTEM_XFACE acpi_db_execute_thread(void *context)
1195 {
1196 
1197 	(void)acpi_db_user_commands();
1198 	acpi_gbl_db_threads_terminated = TRUE;
1199 }
1200 
1201 /*******************************************************************************
1202  *
1203  * FUNCTION:    acpi_db_user_commands
1204  *
1205  * PARAMETERS:  None
1206  *
1207  * RETURN:      None
1208  *
1209  * DESCRIPTION: Command line execution for the AML debugger. Commands are
1210  *              matched and dispatched here.
1211  *
1212  ******************************************************************************/
1213 
1214 acpi_status acpi_db_user_commands(void)
1215 {
1216 	acpi_status status = AE_OK;
1217 
1218 	acpi_os_printf("\n");
1219 
1220 	/* TBD: [Restructure] Need a separate command line buffer for step mode */
1221 
1222 	while (!acpi_gbl_db_terminate_loop) {
1223 
1224 		/* Wait the readiness of the command */
1225 
1226 		status = acpi_os_wait_command_ready();
1227 		if (ACPI_FAILURE(status)) {
1228 			break;
1229 		}
1230 
1231 		/* Just call to the command line interpreter */
1232 
1233 		acpi_gbl_method_executing = FALSE;
1234 		acpi_gbl_step_to_next_call = FALSE;
1235 
1236 		(void)acpi_db_command_dispatch(acpi_gbl_db_line_buf, NULL,
1237 					       NULL);
1238 
1239 		/* Notify the completion of the command */
1240 
1241 		status = acpi_os_notify_command_complete();
1242 		if (ACPI_FAILURE(status)) {
1243 			break;
1244 		}
1245 	}
1246 
1247 	if (ACPI_FAILURE(status) && status != AE_CTRL_TERMINATE) {
1248 		ACPI_EXCEPTION((AE_INFO, status, "While parsing command line"));
1249 	}
1250 	return (status);
1251 }
1252