Merge tag 'trace-v5.11-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt...
[linux/fpc-iii.git] / drivers / acpi / acpica / dbexec.c
blobd3a9521e2dc888d3d497b7de02ad9fa558cef5f5
1 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
2 /*******************************************************************************
4 * Module Name: dbexec - debugger control method execution
6 ******************************************************************************/
8 #include <acpi/acpi.h>
9 #include "accommon.h"
10 #include "acdebug.h"
11 #include "acnamesp.h"
13 #define _COMPONENT ACPI_CA_DEBUGGER
14 ACPI_MODULE_NAME("dbexec")
16 static struct acpi_db_method_info acpi_gbl_db_method_info;
18 /* Local prototypes */
20 static acpi_status
21 acpi_db_execute_method(struct acpi_db_method_info *info,
22 struct acpi_buffer *return_obj);
24 static acpi_status acpi_db_execute_setup(struct acpi_db_method_info *info);
26 static u32 acpi_db_get_outstanding_allocations(void);
28 static void ACPI_SYSTEM_XFACE acpi_db_method_thread(void *context);
30 static acpi_status
31 acpi_db_execution_walk(acpi_handle obj_handle,
32 u32 nesting_level, void *context, void **return_value);
34 static void ACPI_SYSTEM_XFACE acpi_db_single_execution_thread(void *context);
36 /*******************************************************************************
38 * FUNCTION: acpi_db_delete_objects
40 * PARAMETERS: count - Count of objects in the list
41 * objects - Array of ACPI_OBJECTs to be deleted
43 * RETURN: None
45 * DESCRIPTION: Delete a list of ACPI_OBJECTS. Handles packages and nested
46 * packages via recursion.
48 ******************************************************************************/
50 void acpi_db_delete_objects(u32 count, union acpi_object *objects)
52 u32 i;
54 for (i = 0; i < count; i++) {
55 switch (objects[i].type) {
56 case ACPI_TYPE_BUFFER:
58 ACPI_FREE(objects[i].buffer.pointer);
59 break;
61 case ACPI_TYPE_PACKAGE:
63 /* Recursive call to delete package elements */
65 acpi_db_delete_objects(objects[i].package.count,
66 objects[i].package.elements);
68 /* Free the elements array */
70 ACPI_FREE(objects[i].package.elements);
71 break;
73 default:
75 break;
80 /*******************************************************************************
82 * FUNCTION: acpi_db_execute_method
84 * PARAMETERS: info - Valid info segment
85 * return_obj - Where to put return object
87 * RETURN: Status
89 * DESCRIPTION: Execute a control method. Used to evaluate objects via the
90 * "EXECUTE" or "EVALUATE" commands.
92 ******************************************************************************/
94 static acpi_status
95 acpi_db_execute_method(struct acpi_db_method_info *info,
96 struct acpi_buffer *return_obj)
98 acpi_status status;
99 struct acpi_object_list param_objects;
100 union acpi_object params[ACPI_DEBUGGER_MAX_ARGS + 1];
101 u32 i;
103 ACPI_FUNCTION_TRACE(db_execute_method);
105 if (acpi_gbl_db_output_to_file && !acpi_dbg_level) {
106 acpi_os_printf("Warning: debug output is not enabled!\n");
109 param_objects.count = 0;
110 param_objects.pointer = NULL;
112 /* Pass through any command-line arguments */
114 if (info->args && info->args[0]) {
116 /* Get arguments passed on the command line */
118 for (i = 0; (info->args[i] && *(info->args[i])); i++) {
120 /* Convert input string (token) to an actual union acpi_object */
122 status = acpi_db_convert_to_object(info->types[i],
123 info->args[i],
124 &params[i]);
125 if (ACPI_FAILURE(status)) {
126 ACPI_EXCEPTION((AE_INFO, status,
127 "While parsing method arguments"));
128 goto cleanup;
132 param_objects.count = i;
133 param_objects.pointer = params;
136 /* Prepare for a return object of arbitrary size */
138 return_obj->pointer = acpi_gbl_db_buffer;
139 return_obj->length = ACPI_DEBUG_BUFFER_SIZE;
141 /* Do the actual method execution */
143 acpi_gbl_method_executing = TRUE;
144 status = acpi_evaluate_object(NULL, info->pathname,
145 &param_objects, return_obj);
147 acpi_gbl_cm_single_step = FALSE;
148 acpi_gbl_method_executing = FALSE;
150 if (ACPI_FAILURE(status)) {
151 if ((status == AE_ABORT_METHOD) || acpi_gbl_abort_method) {
153 /* Clear the abort and fall back to the debugger prompt */
155 ACPI_EXCEPTION((AE_INFO, status,
156 "Aborting top-level method"));
158 acpi_gbl_abort_method = FALSE;
159 status = AE_OK;
160 goto cleanup;
163 ACPI_EXCEPTION((AE_INFO, status,
164 "while executing %s from AML Debugger",
165 info->pathname));
167 if (status == AE_BUFFER_OVERFLOW) {
168 ACPI_ERROR((AE_INFO,
169 "Possible buffer overflow within AML Debugger "
170 "buffer (size 0x%X needed 0x%X)",
171 ACPI_DEBUG_BUFFER_SIZE,
172 (u32)return_obj->length));
176 cleanup:
177 acpi_db_delete_objects(param_objects.count, params);
178 return_ACPI_STATUS(status);
181 /*******************************************************************************
183 * FUNCTION: acpi_db_execute_setup
185 * PARAMETERS: info - Valid method info
187 * RETURN: None
189 * DESCRIPTION: Setup info segment prior to method execution
191 ******************************************************************************/
193 static acpi_status acpi_db_execute_setup(struct acpi_db_method_info *info)
195 acpi_status status;
197 ACPI_FUNCTION_NAME(db_execute_setup);
199 /* Concatenate the current scope to the supplied name */
201 info->pathname[0] = 0;
202 if ((info->name[0] != '\\') && (info->name[0] != '/')) {
203 if (acpi_ut_safe_strcat(info->pathname, sizeof(info->pathname),
204 acpi_gbl_db_scope_buf)) {
205 status = AE_BUFFER_OVERFLOW;
206 goto error_exit;
210 if (acpi_ut_safe_strcat(info->pathname, sizeof(info->pathname),
211 info->name)) {
212 status = AE_BUFFER_OVERFLOW;
213 goto error_exit;
216 acpi_db_prep_namestring(info->pathname);
218 acpi_db_set_output_destination(ACPI_DB_DUPLICATE_OUTPUT);
219 acpi_os_printf("Evaluating %s\n", info->pathname);
221 if (info->flags & EX_SINGLE_STEP) {
222 acpi_gbl_cm_single_step = TRUE;
223 acpi_db_set_output_destination(ACPI_DB_CONSOLE_OUTPUT);
226 else {
227 /* No single step, allow redirection to a file */
229 acpi_db_set_output_destination(ACPI_DB_REDIRECTABLE_OUTPUT);
232 return (AE_OK);
234 error_exit:
236 ACPI_EXCEPTION((AE_INFO, status, "During setup for method execution"));
237 return (status);
240 #ifdef ACPI_DBG_TRACK_ALLOCATIONS
241 u32 acpi_db_get_cache_info(struct acpi_memory_list *cache)
244 return (cache->total_allocated - cache->total_freed -
245 cache->current_depth);
247 #endif
249 /*******************************************************************************
251 * FUNCTION: acpi_db_get_outstanding_allocations
253 * PARAMETERS: None
255 * RETURN: Current global allocation count minus cache entries
257 * DESCRIPTION: Determine the current number of "outstanding" allocations --
258 * those allocations that have not been freed and also are not
259 * in one of the various object caches.
261 ******************************************************************************/
263 static u32 acpi_db_get_outstanding_allocations(void)
265 u32 outstanding = 0;
267 #ifdef ACPI_DBG_TRACK_ALLOCATIONS
269 outstanding += acpi_db_get_cache_info(acpi_gbl_state_cache);
270 outstanding += acpi_db_get_cache_info(acpi_gbl_ps_node_cache);
271 outstanding += acpi_db_get_cache_info(acpi_gbl_ps_node_ext_cache);
272 outstanding += acpi_db_get_cache_info(acpi_gbl_operand_cache);
273 #endif
275 return (outstanding);
278 /*******************************************************************************
280 * FUNCTION: acpi_db_execution_walk
282 * PARAMETERS: WALK_CALLBACK
284 * RETURN: Status
286 * DESCRIPTION: Execute a control method. Name is relative to the current
287 * scope.
289 ******************************************************************************/
291 static acpi_status
292 acpi_db_execution_walk(acpi_handle obj_handle,
293 u32 nesting_level, void *context, void **return_value)
295 union acpi_operand_object *obj_desc;
296 struct acpi_namespace_node *node =
297 (struct acpi_namespace_node *)obj_handle;
298 struct acpi_buffer return_obj;
299 acpi_status status;
301 obj_desc = acpi_ns_get_attached_object(node);
302 if (obj_desc->method.param_count) {
303 return (AE_OK);
306 return_obj.pointer = NULL;
307 return_obj.length = ACPI_ALLOCATE_BUFFER;
309 acpi_ns_print_node_pathname(node, "Evaluating");
311 /* Do the actual method execution */
313 acpi_os_printf("\n");
314 acpi_gbl_method_executing = TRUE;
316 status = acpi_evaluate_object(node, NULL, NULL, &return_obj);
318 acpi_gbl_method_executing = FALSE;
320 acpi_os_printf("Evaluation of [%4.4s] returned %s\n",
321 acpi_ut_get_node_name(node),
322 acpi_format_exception(status));
324 return (AE_OK);
327 /*******************************************************************************
329 * FUNCTION: acpi_db_execute
331 * PARAMETERS: name - Name of method to execute
332 * args - Parameters to the method
333 * Types -
334 * flags - single step/no single step
336 * RETURN: None
338 * DESCRIPTION: Execute a control method. Name is relative to the current
339 * scope. Function used for the "EXECUTE", "EVALUATE", and
340 * "ALL" commands
342 ******************************************************************************/
344 void
345 acpi_db_execute(char *name, char **args, acpi_object_type *types, u32 flags)
347 acpi_status status;
348 struct acpi_buffer return_obj;
349 char *name_string;
351 #ifdef ACPI_DEBUG_OUTPUT
352 u32 previous_allocations;
353 u32 allocations;
354 #endif
357 * Allow one execution to be performed by debugger or single step
358 * execution will be dead locked by the interpreter mutexes.
360 if (acpi_gbl_method_executing) {
361 acpi_os_printf("Only one debugger execution is allowed.\n");
362 return;
364 #ifdef ACPI_DEBUG_OUTPUT
365 /* Memory allocation tracking */
367 previous_allocations = acpi_db_get_outstanding_allocations();
368 #endif
370 if (*name == '*') {
371 (void)acpi_walk_namespace(ACPI_TYPE_METHOD, ACPI_ROOT_OBJECT,
372 ACPI_UINT32_MAX,
373 acpi_db_execution_walk, NULL, NULL,
374 NULL);
375 return;
378 if ((flags & EX_ALL) && (strlen(name) > 4)) {
379 acpi_os_printf("Input name (%s) must be a 4-char NameSeg\n",
380 name);
381 return;
384 name_string = ACPI_ALLOCATE(strlen(name) + 1);
385 if (!name_string) {
386 return;
389 memset(&acpi_gbl_db_method_info, 0, sizeof(struct acpi_db_method_info));
390 strcpy(name_string, name);
391 acpi_ut_strupr(name_string);
393 /* Subcommand to Execute all predefined names in the namespace */
395 if (!strncmp(name_string, "PREDEF", 6)) {
396 acpi_db_evaluate_predefined_names();
397 ACPI_FREE(name_string);
398 return;
401 /* Command (ALL <nameseg>) to execute all methods of a particular name */
403 else if (flags & EX_ALL) {
404 acpi_gbl_db_method_info.name = name_string;
405 return_obj.pointer = NULL;
406 return_obj.length = ACPI_ALLOCATE_BUFFER;
407 acpi_db_evaluate_all(name_string);
408 ACPI_FREE(name_string);
409 return;
410 } else {
411 acpi_gbl_db_method_info.name = name_string;
412 acpi_gbl_db_method_info.args = args;
413 acpi_gbl_db_method_info.types = types;
414 acpi_gbl_db_method_info.flags = flags;
416 return_obj.pointer = NULL;
417 return_obj.length = ACPI_ALLOCATE_BUFFER;
420 status = acpi_db_execute_setup(&acpi_gbl_db_method_info);
421 if (ACPI_FAILURE(status)) {
422 ACPI_FREE(name_string);
423 return;
426 /* Get the NS node, determines existence also */
428 status = acpi_get_handle(NULL, acpi_gbl_db_method_info.pathname,
429 &acpi_gbl_db_method_info.method);
430 if (ACPI_SUCCESS(status)) {
431 status = acpi_db_execute_method(&acpi_gbl_db_method_info,
432 &return_obj);
434 ACPI_FREE(name_string);
437 * Allow any handlers in separate threads to complete.
438 * (Such as Notify handlers invoked from AML executed above).
440 acpi_os_sleep((u64)10);
442 #ifdef ACPI_DEBUG_OUTPUT
444 /* Memory allocation tracking */
446 allocations =
447 acpi_db_get_outstanding_allocations() - previous_allocations;
449 acpi_db_set_output_destination(ACPI_DB_DUPLICATE_OUTPUT);
451 if (allocations > 0) {
452 acpi_os_printf
453 ("0x%X Outstanding allocations after evaluation of %s\n",
454 allocations, acpi_gbl_db_method_info.pathname);
456 #endif
458 if (ACPI_FAILURE(status)) {
459 acpi_os_printf("Evaluation of %s failed with status %s\n",
460 acpi_gbl_db_method_info.pathname,
461 acpi_format_exception(status));
462 } else {
463 /* Display a return object, if any */
465 if (return_obj.length) {
466 acpi_os_printf("Evaluation of %s returned object %p, "
467 "external buffer length %X\n",
468 acpi_gbl_db_method_info.pathname,
469 return_obj.pointer,
470 (u32)return_obj.length);
472 acpi_db_dump_external_object(return_obj.pointer, 1);
473 acpi_os_printf("\n");
475 /* Dump a _PLD buffer if present */
477 if (ACPI_COMPARE_NAMESEG
478 ((ACPI_CAST_PTR
479 (struct acpi_namespace_node,
480 acpi_gbl_db_method_info.method)->name.ascii),
481 METHOD_NAME__PLD)) {
482 acpi_db_dump_pld_buffer(return_obj.pointer);
484 } else {
485 acpi_os_printf
486 ("No object was returned from evaluation of %s\n",
487 acpi_gbl_db_method_info.pathname);
491 acpi_db_set_output_destination(ACPI_DB_CONSOLE_OUTPUT);
494 /*******************************************************************************
496 * FUNCTION: acpi_db_method_thread
498 * PARAMETERS: context - Execution info segment
500 * RETURN: None
502 * DESCRIPTION: Debugger execute thread. Waits for a command line, then
503 * simply dispatches it.
505 ******************************************************************************/
507 static void ACPI_SYSTEM_XFACE acpi_db_method_thread(void *context)
509 acpi_status status;
510 struct acpi_db_method_info *info = context;
511 struct acpi_db_method_info local_info;
512 u32 i;
513 u8 allow;
514 struct acpi_buffer return_obj;
517 * acpi_gbl_db_method_info.Arguments will be passed as method arguments.
518 * Prevent acpi_gbl_db_method_info from being modified by multiple threads
519 * concurrently.
521 * Note: The arguments we are passing are used by the ASL test suite
522 * (aslts). Do not change them without updating the tests.
524 (void)acpi_os_wait_semaphore(info->info_gate, 1, ACPI_WAIT_FOREVER);
526 if (info->init_args) {
527 acpi_db_uint32_to_hex_string(info->num_created,
528 info->index_of_thread_str);
529 acpi_db_uint32_to_hex_string((u32)acpi_os_get_thread_id(),
530 info->id_of_thread_str);
533 if (info->threads && (info->num_created < info->num_threads)) {
534 info->threads[info->num_created++] = acpi_os_get_thread_id();
537 local_info = *info;
538 local_info.args = local_info.arguments;
539 local_info.arguments[0] = local_info.num_threads_str;
540 local_info.arguments[1] = local_info.id_of_thread_str;
541 local_info.arguments[2] = local_info.index_of_thread_str;
542 local_info.arguments[3] = NULL;
544 local_info.types = local_info.arg_types;
546 (void)acpi_os_signal_semaphore(info->info_gate, 1);
548 for (i = 0; i < info->num_loops; i++) {
549 status = acpi_db_execute_method(&local_info, &return_obj);
550 if (ACPI_FAILURE(status)) {
551 acpi_os_printf
552 ("%s During evaluation of %s at iteration %X\n",
553 acpi_format_exception(status), info->pathname, i);
554 if (status == AE_ABORT_METHOD) {
555 break;
558 #if 0
559 if ((i % 100) == 0) {
560 acpi_os_printf("%u loops, Thread 0x%x\n",
561 i, acpi_os_get_thread_id());
564 if (return_obj.length) {
565 acpi_os_printf
566 ("Evaluation of %s returned object %p Buflen %X\n",
567 info->pathname, return_obj.pointer,
568 (u32)return_obj.length);
569 acpi_db_dump_external_object(return_obj.pointer, 1);
571 #endif
574 /* Signal our completion */
576 allow = 0;
577 (void)acpi_os_wait_semaphore(info->thread_complete_gate,
578 1, ACPI_WAIT_FOREVER);
579 info->num_completed++;
581 if (info->num_completed == info->num_threads) {
583 /* Do signal for main thread once only */
584 allow = 1;
587 (void)acpi_os_signal_semaphore(info->thread_complete_gate, 1);
589 if (allow) {
590 status = acpi_os_signal_semaphore(info->main_thread_gate, 1);
591 if (ACPI_FAILURE(status)) {
592 acpi_os_printf
593 ("Could not signal debugger thread sync semaphore, %s\n",
594 acpi_format_exception(status));
599 /*******************************************************************************
601 * FUNCTION: acpi_db_single_execution_thread
603 * PARAMETERS: context - Method info struct
605 * RETURN: None
607 * DESCRIPTION: Create one thread and execute a method
609 ******************************************************************************/
611 static void ACPI_SYSTEM_XFACE acpi_db_single_execution_thread(void *context)
613 struct acpi_db_method_info *info = context;
614 acpi_status status;
615 struct acpi_buffer return_obj;
617 acpi_os_printf("\n");
619 status = acpi_db_execute_method(info, &return_obj);
620 if (ACPI_FAILURE(status)) {
621 acpi_os_printf("%s During evaluation of %s\n",
622 acpi_format_exception(status), info->pathname);
623 return;
626 /* Display a return object, if any */
628 if (return_obj.length) {
629 acpi_os_printf("Evaluation of %s returned object %p, "
630 "external buffer length %X\n",
631 acpi_gbl_db_method_info.pathname,
632 return_obj.pointer, (u32)return_obj.length);
634 acpi_db_dump_external_object(return_obj.pointer, 1);
637 acpi_os_printf("\nBackground thread completed\n%c ",
638 ACPI_DEBUGGER_COMMAND_PROMPT);
641 /*******************************************************************************
643 * FUNCTION: acpi_db_create_execution_thread
645 * PARAMETERS: method_name_arg - Control method to execute
646 * arguments - Array of arguments to the method
647 * types - Corresponding array of object types
649 * RETURN: None
651 * DESCRIPTION: Create a single thread to evaluate a namespace object. Handles
652 * arguments passed on command line for control methods.
654 ******************************************************************************/
656 void
657 acpi_db_create_execution_thread(char *method_name_arg,
658 char **arguments, acpi_object_type *types)
660 acpi_status status;
661 u32 i;
663 memset(&acpi_gbl_db_method_info, 0, sizeof(struct acpi_db_method_info));
664 acpi_gbl_db_method_info.name = method_name_arg;
665 acpi_gbl_db_method_info.init_args = 1;
666 acpi_gbl_db_method_info.args = acpi_gbl_db_method_info.arguments;
667 acpi_gbl_db_method_info.types = acpi_gbl_db_method_info.arg_types;
669 /* Setup method arguments, up to 7 (0-6) */
671 for (i = 0; (i < ACPI_METHOD_NUM_ARGS) && *arguments; i++) {
672 acpi_gbl_db_method_info.arguments[i] = *arguments;
673 arguments++;
675 acpi_gbl_db_method_info.arg_types[i] = *types;
676 types++;
679 status = acpi_db_execute_setup(&acpi_gbl_db_method_info);
680 if (ACPI_FAILURE(status)) {
681 return;
684 /* Get the NS node, determines existence also */
686 status = acpi_get_handle(NULL, acpi_gbl_db_method_info.pathname,
687 &acpi_gbl_db_method_info.method);
688 if (ACPI_FAILURE(status)) {
689 acpi_os_printf("%s Could not get handle for %s\n",
690 acpi_format_exception(status),
691 acpi_gbl_db_method_info.pathname);
692 return;
695 status = acpi_os_execute(OSL_DEBUGGER_EXEC_THREAD,
696 acpi_db_single_execution_thread,
697 &acpi_gbl_db_method_info);
698 if (ACPI_FAILURE(status)) {
699 return;
702 acpi_os_printf("\nBackground thread started\n");
705 /*******************************************************************************
707 * FUNCTION: acpi_db_create_execution_threads
709 * PARAMETERS: num_threads_arg - Number of threads to create
710 * num_loops_arg - Loop count for the thread(s)
711 * method_name_arg - Control method to execute
713 * RETURN: None
715 * DESCRIPTION: Create threads to execute method(s)
717 ******************************************************************************/
719 void
720 acpi_db_create_execution_threads(char *num_threads_arg,
721 char *num_loops_arg, char *method_name_arg)
723 acpi_status status;
724 u32 num_threads;
725 u32 num_loops;
726 u32 i;
727 u32 size;
728 acpi_mutex main_thread_gate;
729 acpi_mutex thread_complete_gate;
730 acpi_mutex info_gate;
732 /* Get the arguments */
734 num_threads = strtoul(num_threads_arg, NULL, 0);
735 num_loops = strtoul(num_loops_arg, NULL, 0);
737 if (!num_threads || !num_loops) {
738 acpi_os_printf("Bad argument: Threads %X, Loops %X\n",
739 num_threads, num_loops);
740 return;
744 * Create the semaphore for synchronization of
745 * the created threads with the main thread.
747 status = acpi_os_create_semaphore(1, 0, &main_thread_gate);
748 if (ACPI_FAILURE(status)) {
749 acpi_os_printf("Could not create semaphore for "
750 "synchronization with the main thread, %s\n",
751 acpi_format_exception(status));
752 return;
756 * Create the semaphore for synchronization
757 * between the created threads.
759 status = acpi_os_create_semaphore(1, 1, &thread_complete_gate);
760 if (ACPI_FAILURE(status)) {
761 acpi_os_printf("Could not create semaphore for "
762 "synchronization between the created threads, %s\n",
763 acpi_format_exception(status));
765 (void)acpi_os_delete_semaphore(main_thread_gate);
766 return;
769 status = acpi_os_create_semaphore(1, 1, &info_gate);
770 if (ACPI_FAILURE(status)) {
771 acpi_os_printf("Could not create semaphore for "
772 "synchronization of AcpiGbl_DbMethodInfo, %s\n",
773 acpi_format_exception(status));
775 (void)acpi_os_delete_semaphore(thread_complete_gate);
776 (void)acpi_os_delete_semaphore(main_thread_gate);
777 return;
780 memset(&acpi_gbl_db_method_info, 0, sizeof(struct acpi_db_method_info));
782 /* Array to store IDs of threads */
784 acpi_gbl_db_method_info.num_threads = num_threads;
785 size = sizeof(acpi_thread_id) * acpi_gbl_db_method_info.num_threads;
787 acpi_gbl_db_method_info.threads = acpi_os_allocate(size);
788 if (acpi_gbl_db_method_info.threads == NULL) {
789 acpi_os_printf("No memory for thread IDs array\n");
790 (void)acpi_os_delete_semaphore(main_thread_gate);
791 (void)acpi_os_delete_semaphore(thread_complete_gate);
792 (void)acpi_os_delete_semaphore(info_gate);
793 return;
795 memset(acpi_gbl_db_method_info.threads, 0, size);
797 /* Setup the context to be passed to each thread */
799 acpi_gbl_db_method_info.name = method_name_arg;
800 acpi_gbl_db_method_info.flags = 0;
801 acpi_gbl_db_method_info.num_loops = num_loops;
802 acpi_gbl_db_method_info.main_thread_gate = main_thread_gate;
803 acpi_gbl_db_method_info.thread_complete_gate = thread_complete_gate;
804 acpi_gbl_db_method_info.info_gate = info_gate;
806 /* Init arguments to be passed to method */
808 acpi_gbl_db_method_info.init_args = 1;
809 acpi_gbl_db_method_info.args = acpi_gbl_db_method_info.arguments;
810 acpi_gbl_db_method_info.arguments[0] =
811 acpi_gbl_db_method_info.num_threads_str;
812 acpi_gbl_db_method_info.arguments[1] =
813 acpi_gbl_db_method_info.id_of_thread_str;
814 acpi_gbl_db_method_info.arguments[2] =
815 acpi_gbl_db_method_info.index_of_thread_str;
816 acpi_gbl_db_method_info.arguments[3] = NULL;
818 acpi_gbl_db_method_info.types = acpi_gbl_db_method_info.arg_types;
819 acpi_gbl_db_method_info.arg_types[0] = ACPI_TYPE_INTEGER;
820 acpi_gbl_db_method_info.arg_types[1] = ACPI_TYPE_INTEGER;
821 acpi_gbl_db_method_info.arg_types[2] = ACPI_TYPE_INTEGER;
823 acpi_db_uint32_to_hex_string(num_threads,
824 acpi_gbl_db_method_info.num_threads_str);
826 status = acpi_db_execute_setup(&acpi_gbl_db_method_info);
827 if (ACPI_FAILURE(status)) {
828 goto cleanup_and_exit;
831 /* Get the NS node, determines existence also */
833 status = acpi_get_handle(NULL, acpi_gbl_db_method_info.pathname,
834 &acpi_gbl_db_method_info.method);
835 if (ACPI_FAILURE(status)) {
836 acpi_os_printf("%s Could not get handle for %s\n",
837 acpi_format_exception(status),
838 acpi_gbl_db_method_info.pathname);
839 goto cleanup_and_exit;
842 /* Create the threads */
844 acpi_os_printf("Creating %X threads to execute %X times each\n",
845 num_threads, num_loops);
847 for (i = 0; i < (num_threads); i++) {
848 status =
849 acpi_os_execute(OSL_DEBUGGER_EXEC_THREAD,
850 acpi_db_method_thread,
851 &acpi_gbl_db_method_info);
852 if (ACPI_FAILURE(status)) {
853 break;
857 /* Wait for all threads to complete */
859 (void)acpi_os_wait_semaphore(main_thread_gate, 1, ACPI_WAIT_FOREVER);
861 acpi_db_set_output_destination(ACPI_DB_DUPLICATE_OUTPUT);
862 acpi_os_printf("All threads (%X) have completed\n", num_threads);
863 acpi_db_set_output_destination(ACPI_DB_CONSOLE_OUTPUT);
865 cleanup_and_exit:
867 /* Cleanup and exit */
869 (void)acpi_os_delete_semaphore(main_thread_gate);
870 (void)acpi_os_delete_semaphore(thread_complete_gate);
871 (void)acpi_os_delete_semaphore(info_gate);
873 acpi_os_free(acpi_gbl_db_method_info.threads);
874 acpi_gbl_db_method_info.threads = NULL;