dbexec.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771
  1. /*******************************************************************************
  2. *
  3. * Module Name: dbexec - debugger control method execution
  4. *
  5. ******************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2016, Intel Corp.
  8. * All rights reserved.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions, and the following disclaimer,
  15. * without modification.
  16. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  17. * substantially similar to the "NO WARRANTY" disclaimer below
  18. * ("Disclaimer") and any redistribution must be conditioned upon
  19. * including a substantially similar Disclaimer requirement for further
  20. * binary redistribution.
  21. * 3. Neither the names of the above-listed copyright holders nor the names
  22. * of any contributors may be used to endorse or promote products derived
  23. * from this software without specific prior written permission.
  24. *
  25. * Alternatively, this software may be distributed under the terms of the
  26. * GNU General Public License ("GPL") version 2 as published by the Free
  27. * Software Foundation.
  28. *
  29. * NO WARRANTY
  30. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  31. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  32. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  33. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  34. * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  35. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  36. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  37. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  38. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  39. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  40. * POSSIBILITY OF SUCH DAMAGES.
  41. */
  42. #include <acpi/acpi.h>
  43. #include "accommon.h"
  44. #include "acdebug.h"
  45. #include "acnamesp.h"
  46. #define _COMPONENT ACPI_CA_DEBUGGER
  47. ACPI_MODULE_NAME("dbexec")
  48. static struct acpi_db_method_info acpi_gbl_db_method_info;
  49. /* Local prototypes */
  50. static acpi_status
  51. acpi_db_execute_method(struct acpi_db_method_info *info,
  52. struct acpi_buffer *return_obj);
  53. static acpi_status acpi_db_execute_setup(struct acpi_db_method_info *info);
  54. static u32 acpi_db_get_outstanding_allocations(void);
  55. static void ACPI_SYSTEM_XFACE acpi_db_method_thread(void *context);
  56. static acpi_status
  57. acpi_db_execution_walk(acpi_handle obj_handle,
  58. u32 nesting_level, void *context, void **return_value);
  59. /*******************************************************************************
  60. *
  61. * FUNCTION: acpi_db_delete_objects
  62. *
  63. * PARAMETERS: count - Count of objects in the list
  64. * objects - Array of ACPI_OBJECTs to be deleted
  65. *
  66. * RETURN: None
  67. *
  68. * DESCRIPTION: Delete a list of ACPI_OBJECTS. Handles packages and nested
  69. * packages via recursion.
  70. *
  71. ******************************************************************************/
  72. void acpi_db_delete_objects(u32 count, union acpi_object *objects)
  73. {
  74. u32 i;
  75. for (i = 0; i < count; i++) {
  76. switch (objects[i].type) {
  77. case ACPI_TYPE_BUFFER:
  78. ACPI_FREE(objects[i].buffer.pointer);
  79. break;
  80. case ACPI_TYPE_PACKAGE:
  81. /* Recursive call to delete package elements */
  82. acpi_db_delete_objects(objects[i].package.count,
  83. objects[i].package.elements);
  84. /* Free the elements array */
  85. ACPI_FREE(objects[i].package.elements);
  86. break;
  87. default:
  88. break;
  89. }
  90. }
  91. }
  92. /*******************************************************************************
  93. *
  94. * FUNCTION: acpi_db_execute_method
  95. *
  96. * PARAMETERS: info - Valid info segment
  97. * return_obj - Where to put return object
  98. *
  99. * RETURN: Status
  100. *
  101. * DESCRIPTION: Execute a control method.
  102. *
  103. ******************************************************************************/
  104. static acpi_status
  105. acpi_db_execute_method(struct acpi_db_method_info *info,
  106. struct acpi_buffer *return_obj)
  107. {
  108. acpi_status status;
  109. struct acpi_object_list param_objects;
  110. union acpi_object params[ACPI_DEBUGGER_MAX_ARGS + 1];
  111. u32 i;
  112. ACPI_FUNCTION_TRACE(db_execute_method);
  113. if (acpi_gbl_db_output_to_file && !acpi_dbg_level) {
  114. acpi_os_printf("Warning: debug output is not enabled!\n");
  115. }
  116. param_objects.count = 0;
  117. param_objects.pointer = NULL;
  118. /* Pass through any command-line arguments */
  119. if (info->args && info->args[0]) {
  120. /* Get arguments passed on the command line */
  121. for (i = 0; (info->args[i] && *(info->args[i])); i++) {
  122. /* Convert input string (token) to an actual union acpi_object */
  123. status = acpi_db_convert_to_object(info->types[i],
  124. info->args[i],
  125. &params[i]);
  126. if (ACPI_FAILURE(status)) {
  127. ACPI_EXCEPTION((AE_INFO, status,
  128. "While parsing method arguments"));
  129. goto cleanup;
  130. }
  131. }
  132. param_objects.count = i;
  133. param_objects.pointer = params;
  134. }
  135. /* Prepare for a return object of arbitrary size */
  136. return_obj->pointer = acpi_gbl_db_buffer;
  137. return_obj->length = ACPI_DEBUG_BUFFER_SIZE;
  138. /* Do the actual method execution */
  139. acpi_gbl_method_executing = TRUE;
  140. status = acpi_evaluate_object(NULL, info->pathname,
  141. &param_objects, return_obj);
  142. acpi_gbl_cm_single_step = FALSE;
  143. acpi_gbl_method_executing = FALSE;
  144. if (ACPI_FAILURE(status)) {
  145. ACPI_EXCEPTION((AE_INFO, status,
  146. "while executing %s from debugger",
  147. info->pathname));
  148. if (status == AE_BUFFER_OVERFLOW) {
  149. ACPI_ERROR((AE_INFO,
  150. "Possible overflow of internal debugger "
  151. "buffer (size 0x%X needed 0x%X)",
  152. ACPI_DEBUG_BUFFER_SIZE,
  153. (u32)return_obj->length));
  154. }
  155. }
  156. cleanup:
  157. acpi_db_delete_objects(param_objects.count, params);
  158. return_ACPI_STATUS(status);
  159. }
  160. /*******************************************************************************
  161. *
  162. * FUNCTION: acpi_db_execute_setup
  163. *
  164. * PARAMETERS: info - Valid method info
  165. *
  166. * RETURN: None
  167. *
  168. * DESCRIPTION: Setup info segment prior to method execution
  169. *
  170. ******************************************************************************/
  171. static acpi_status acpi_db_execute_setup(struct acpi_db_method_info *info)
  172. {
  173. acpi_status status;
  174. ACPI_FUNCTION_NAME(db_execute_setup);
  175. /* Catenate the current scope to the supplied name */
  176. info->pathname[0] = 0;
  177. if ((info->name[0] != '\\') && (info->name[0] != '/')) {
  178. if (acpi_ut_safe_strcat(info->pathname, sizeof(info->pathname),
  179. acpi_gbl_db_scope_buf)) {
  180. status = AE_BUFFER_OVERFLOW;
  181. goto error_exit;
  182. }
  183. }
  184. if (acpi_ut_safe_strcat(info->pathname, sizeof(info->pathname),
  185. info->name)) {
  186. status = AE_BUFFER_OVERFLOW;
  187. goto error_exit;
  188. }
  189. acpi_db_prep_namestring(info->pathname);
  190. acpi_db_set_output_destination(ACPI_DB_DUPLICATE_OUTPUT);
  191. acpi_os_printf("Evaluating %s\n", info->pathname);
  192. if (info->flags & EX_SINGLE_STEP) {
  193. acpi_gbl_cm_single_step = TRUE;
  194. acpi_db_set_output_destination(ACPI_DB_CONSOLE_OUTPUT);
  195. }
  196. else {
  197. /* No single step, allow redirection to a file */
  198. acpi_db_set_output_destination(ACPI_DB_REDIRECTABLE_OUTPUT);
  199. }
  200. return (AE_OK);
  201. error_exit:
  202. ACPI_EXCEPTION((AE_INFO, status, "During setup for method execution"));
  203. return (status);
  204. }
  205. #ifdef ACPI_DBG_TRACK_ALLOCATIONS
  206. u32 acpi_db_get_cache_info(struct acpi_memory_list *cache)
  207. {
  208. return (cache->total_allocated - cache->total_freed -
  209. cache->current_depth);
  210. }
  211. #endif
  212. /*******************************************************************************
  213. *
  214. * FUNCTION: acpi_db_get_outstanding_allocations
  215. *
  216. * PARAMETERS: None
  217. *
  218. * RETURN: Current global allocation count minus cache entries
  219. *
  220. * DESCRIPTION: Determine the current number of "outstanding" allocations --
  221. * those allocations that have not been freed and also are not
  222. * in one of the various object caches.
  223. *
  224. ******************************************************************************/
  225. static u32 acpi_db_get_outstanding_allocations(void)
  226. {
  227. u32 outstanding = 0;
  228. #ifdef ACPI_DBG_TRACK_ALLOCATIONS
  229. outstanding += acpi_db_get_cache_info(acpi_gbl_state_cache);
  230. outstanding += acpi_db_get_cache_info(acpi_gbl_ps_node_cache);
  231. outstanding += acpi_db_get_cache_info(acpi_gbl_ps_node_ext_cache);
  232. outstanding += acpi_db_get_cache_info(acpi_gbl_operand_cache);
  233. #endif
  234. return (outstanding);
  235. }
  236. /*******************************************************************************
  237. *
  238. * FUNCTION: acpi_db_execution_walk
  239. *
  240. * PARAMETERS: WALK_CALLBACK
  241. *
  242. * RETURN: Status
  243. *
  244. * DESCRIPTION: Execute a control method. Name is relative to the current
  245. * scope.
  246. *
  247. ******************************************************************************/
  248. static acpi_status
  249. acpi_db_execution_walk(acpi_handle obj_handle,
  250. u32 nesting_level, void *context, void **return_value)
  251. {
  252. union acpi_operand_object *obj_desc;
  253. struct acpi_namespace_node *node =
  254. (struct acpi_namespace_node *)obj_handle;
  255. struct acpi_buffer return_obj;
  256. acpi_status status;
  257. obj_desc = acpi_ns_get_attached_object(node);
  258. if (obj_desc->method.param_count) {
  259. return (AE_OK);
  260. }
  261. return_obj.pointer = NULL;
  262. return_obj.length = ACPI_ALLOCATE_BUFFER;
  263. acpi_ns_print_node_pathname(node, "Evaluating");
  264. /* Do the actual method execution */
  265. acpi_os_printf("\n");
  266. acpi_gbl_method_executing = TRUE;
  267. status = acpi_evaluate_object(node, NULL, NULL, &return_obj);
  268. acpi_os_printf("Evaluation of [%4.4s] returned %s\n",
  269. acpi_ut_get_node_name(node),
  270. acpi_format_exception(status));
  271. acpi_gbl_method_executing = FALSE;
  272. return (AE_OK);
  273. }
  274. /*******************************************************************************
  275. *
  276. * FUNCTION: acpi_db_execute
  277. *
  278. * PARAMETERS: name - Name of method to execute
  279. * args - Parameters to the method
  280. * Types -
  281. * flags - single step/no single step
  282. *
  283. * RETURN: None
  284. *
  285. * DESCRIPTION: Execute a control method. Name is relative to the current
  286. * scope.
  287. *
  288. ******************************************************************************/
  289. void
  290. acpi_db_execute(char *name, char **args, acpi_object_type *types, u32 flags)
  291. {
  292. acpi_status status;
  293. struct acpi_buffer return_obj;
  294. char *name_string;
  295. #ifdef ACPI_DEBUG_OUTPUT
  296. u32 previous_allocations;
  297. u32 allocations;
  298. #endif
  299. /*
  300. * Allow one execution to be performed by debugger or single step
  301. * execution will be dead locked by the interpreter mutexes.
  302. */
  303. if (acpi_gbl_method_executing) {
  304. acpi_os_printf("Only one debugger execution is allowed.\n");
  305. return;
  306. }
  307. #ifdef ACPI_DEBUG_OUTPUT
  308. /* Memory allocation tracking */
  309. previous_allocations = acpi_db_get_outstanding_allocations();
  310. #endif
  311. if (*name == '*') {
  312. (void)acpi_walk_namespace(ACPI_TYPE_METHOD, ACPI_ROOT_OBJECT,
  313. ACPI_UINT32_MAX,
  314. acpi_db_execution_walk, NULL, NULL,
  315. NULL);
  316. return;
  317. }
  318. name_string = ACPI_ALLOCATE(strlen(name) + 1);
  319. if (!name_string) {
  320. return;
  321. }
  322. memset(&acpi_gbl_db_method_info, 0, sizeof(struct acpi_db_method_info));
  323. strcpy(name_string, name);
  324. acpi_ut_strupr(name_string);
  325. /* Subcommand to Execute all predefined names in the namespace */
  326. if (!strncmp(name_string, "PREDEF", 6)) {
  327. acpi_db_evaluate_predefined_names();
  328. ACPI_FREE(name_string);
  329. return;
  330. }
  331. acpi_gbl_db_method_info.name = name_string;
  332. acpi_gbl_db_method_info.args = args;
  333. acpi_gbl_db_method_info.types = types;
  334. acpi_gbl_db_method_info.flags = flags;
  335. return_obj.pointer = NULL;
  336. return_obj.length = ACPI_ALLOCATE_BUFFER;
  337. status = acpi_db_execute_setup(&acpi_gbl_db_method_info);
  338. if (ACPI_FAILURE(status)) {
  339. ACPI_FREE(name_string);
  340. return;
  341. }
  342. /* Get the NS node, determines existence also */
  343. status = acpi_get_handle(NULL, acpi_gbl_db_method_info.pathname,
  344. &acpi_gbl_db_method_info.method);
  345. if (ACPI_SUCCESS(status)) {
  346. status = acpi_db_execute_method(&acpi_gbl_db_method_info,
  347. &return_obj);
  348. }
  349. ACPI_FREE(name_string);
  350. /*
  351. * Allow any handlers in separate threads to complete.
  352. * (Such as Notify handlers invoked from AML executed above).
  353. */
  354. acpi_os_sleep((u64)10);
  355. #ifdef ACPI_DEBUG_OUTPUT
  356. /* Memory allocation tracking */
  357. allocations =
  358. acpi_db_get_outstanding_allocations() - previous_allocations;
  359. acpi_db_set_output_destination(ACPI_DB_DUPLICATE_OUTPUT);
  360. if (allocations > 0) {
  361. acpi_os_printf
  362. ("0x%X Outstanding allocations after evaluation of %s\n",
  363. allocations, acpi_gbl_db_method_info.pathname);
  364. }
  365. #endif
  366. if (ACPI_FAILURE(status)) {
  367. acpi_os_printf("Evaluation of %s failed with status %s\n",
  368. acpi_gbl_db_method_info.pathname,
  369. acpi_format_exception(status));
  370. } else {
  371. /* Display a return object, if any */
  372. if (return_obj.length) {
  373. acpi_os_printf("Evaluation of %s returned object %p, "
  374. "external buffer length %X\n",
  375. acpi_gbl_db_method_info.pathname,
  376. return_obj.pointer,
  377. (u32)return_obj.length);
  378. acpi_db_dump_external_object(return_obj.pointer, 1);
  379. /* Dump a _PLD buffer if present */
  380. if (ACPI_COMPARE_NAME
  381. ((ACPI_CAST_PTR
  382. (struct acpi_namespace_node,
  383. acpi_gbl_db_method_info.method)->name.ascii),
  384. METHOD_NAME__PLD)) {
  385. acpi_db_dump_pld_buffer(return_obj.pointer);
  386. }
  387. } else {
  388. acpi_os_printf
  389. ("No object was returned from evaluation of %s\n",
  390. acpi_gbl_db_method_info.pathname);
  391. }
  392. }
  393. acpi_db_set_output_destination(ACPI_DB_CONSOLE_OUTPUT);
  394. }
  395. /*******************************************************************************
  396. *
  397. * FUNCTION: acpi_db_method_thread
  398. *
  399. * PARAMETERS: context - Execution info segment
  400. *
  401. * RETURN: None
  402. *
  403. * DESCRIPTION: Debugger execute thread. Waits for a command line, then
  404. * simply dispatches it.
  405. *
  406. ******************************************************************************/
  407. static void ACPI_SYSTEM_XFACE acpi_db_method_thread(void *context)
  408. {
  409. acpi_status status;
  410. struct acpi_db_method_info *info = context;
  411. struct acpi_db_method_info local_info;
  412. u32 i;
  413. u8 allow;
  414. struct acpi_buffer return_obj;
  415. /*
  416. * acpi_gbl_db_method_info.Arguments will be passed as method arguments.
  417. * Prevent acpi_gbl_db_method_info from being modified by multiple threads
  418. * concurrently.
  419. *
  420. * Note: The arguments we are passing are used by the ASL test suite
  421. * (aslts). Do not change them without updating the tests.
  422. */
  423. (void)acpi_os_wait_semaphore(info->info_gate, 1, ACPI_WAIT_FOREVER);
  424. if (info->init_args) {
  425. acpi_db_uint32_to_hex_string(info->num_created,
  426. info->index_of_thread_str);
  427. acpi_db_uint32_to_hex_string((u32)acpi_os_get_thread_id(),
  428. info->id_of_thread_str);
  429. }
  430. if (info->threads && (info->num_created < info->num_threads)) {
  431. info->threads[info->num_created++] = acpi_os_get_thread_id();
  432. }
  433. local_info = *info;
  434. local_info.args = local_info.arguments;
  435. local_info.arguments[0] = local_info.num_threads_str;
  436. local_info.arguments[1] = local_info.id_of_thread_str;
  437. local_info.arguments[2] = local_info.index_of_thread_str;
  438. local_info.arguments[3] = NULL;
  439. local_info.types = local_info.arg_types;
  440. (void)acpi_os_signal_semaphore(info->info_gate, 1);
  441. for (i = 0; i < info->num_loops; i++) {
  442. status = acpi_db_execute_method(&local_info, &return_obj);
  443. if (ACPI_FAILURE(status)) {
  444. acpi_os_printf
  445. ("%s During evaluation of %s at iteration %X\n",
  446. acpi_format_exception(status), info->pathname, i);
  447. if (status == AE_ABORT_METHOD) {
  448. break;
  449. }
  450. }
  451. #if 0
  452. if ((i % 100) == 0) {
  453. acpi_os_printf("%u loops, Thread 0x%x\n",
  454. i, acpi_os_get_thread_id());
  455. }
  456. if (return_obj.length) {
  457. acpi_os_printf
  458. ("Evaluation of %s returned object %p Buflen %X\n",
  459. info->pathname, return_obj.pointer,
  460. (u32)return_obj.length);
  461. acpi_db_dump_external_object(return_obj.pointer, 1);
  462. }
  463. #endif
  464. }
  465. /* Signal our completion */
  466. allow = 0;
  467. (void)acpi_os_wait_semaphore(info->thread_complete_gate,
  468. 1, ACPI_WAIT_FOREVER);
  469. info->num_completed++;
  470. if (info->num_completed == info->num_threads) {
  471. /* Do signal for main thread once only */
  472. allow = 1;
  473. }
  474. (void)acpi_os_signal_semaphore(info->thread_complete_gate, 1);
  475. if (allow) {
  476. status = acpi_os_signal_semaphore(info->main_thread_gate, 1);
  477. if (ACPI_FAILURE(status)) {
  478. acpi_os_printf
  479. ("Could not signal debugger thread sync semaphore, %s\n",
  480. acpi_format_exception(status));
  481. }
  482. }
  483. }
  484. /*******************************************************************************
  485. *
  486. * FUNCTION: acpi_db_create_execution_threads
  487. *
  488. * PARAMETERS: num_threads_arg - Number of threads to create
  489. * num_loops_arg - Loop count for the thread(s)
  490. * method_name_arg - Control method to execute
  491. *
  492. * RETURN: None
  493. *
  494. * DESCRIPTION: Create threads to execute method(s)
  495. *
  496. ******************************************************************************/
  497. void
  498. acpi_db_create_execution_threads(char *num_threads_arg,
  499. char *num_loops_arg, char *method_name_arg)
  500. {
  501. acpi_status status;
  502. u32 num_threads;
  503. u32 num_loops;
  504. u32 i;
  505. u32 size;
  506. acpi_mutex main_thread_gate;
  507. acpi_mutex thread_complete_gate;
  508. acpi_mutex info_gate;
  509. /* Get the arguments */
  510. num_threads = strtoul(num_threads_arg, NULL, 0);
  511. num_loops = strtoul(num_loops_arg, NULL, 0);
  512. if (!num_threads || !num_loops) {
  513. acpi_os_printf("Bad argument: Threads %X, Loops %X\n",
  514. num_threads, num_loops);
  515. return;
  516. }
  517. /*
  518. * Create the semaphore for synchronization of
  519. * the created threads with the main thread.
  520. */
  521. status = acpi_os_create_semaphore(1, 0, &main_thread_gate);
  522. if (ACPI_FAILURE(status)) {
  523. acpi_os_printf("Could not create semaphore for "
  524. "synchronization with the main thread, %s\n",
  525. acpi_format_exception(status));
  526. return;
  527. }
  528. /*
  529. * Create the semaphore for synchronization
  530. * between the created threads.
  531. */
  532. status = acpi_os_create_semaphore(1, 1, &thread_complete_gate);
  533. if (ACPI_FAILURE(status)) {
  534. acpi_os_printf("Could not create semaphore for "
  535. "synchronization between the created threads, %s\n",
  536. acpi_format_exception(status));
  537. (void)acpi_os_delete_semaphore(main_thread_gate);
  538. return;
  539. }
  540. status = acpi_os_create_semaphore(1, 1, &info_gate);
  541. if (ACPI_FAILURE(status)) {
  542. acpi_os_printf("Could not create semaphore for "
  543. "synchronization of AcpiGbl_DbMethodInfo, %s\n",
  544. acpi_format_exception(status));
  545. (void)acpi_os_delete_semaphore(thread_complete_gate);
  546. (void)acpi_os_delete_semaphore(main_thread_gate);
  547. return;
  548. }
  549. memset(&acpi_gbl_db_method_info, 0, sizeof(struct acpi_db_method_info));
  550. /* Array to store IDs of threads */
  551. acpi_gbl_db_method_info.num_threads = num_threads;
  552. size = sizeof(acpi_thread_id) * acpi_gbl_db_method_info.num_threads;
  553. acpi_gbl_db_method_info.threads = acpi_os_allocate(size);
  554. if (acpi_gbl_db_method_info.threads == NULL) {
  555. acpi_os_printf("No memory for thread IDs array\n");
  556. (void)acpi_os_delete_semaphore(main_thread_gate);
  557. (void)acpi_os_delete_semaphore(thread_complete_gate);
  558. (void)acpi_os_delete_semaphore(info_gate);
  559. return;
  560. }
  561. memset(acpi_gbl_db_method_info.threads, 0, size);
  562. /* Setup the context to be passed to each thread */
  563. acpi_gbl_db_method_info.name = method_name_arg;
  564. acpi_gbl_db_method_info.flags = 0;
  565. acpi_gbl_db_method_info.num_loops = num_loops;
  566. acpi_gbl_db_method_info.main_thread_gate = main_thread_gate;
  567. acpi_gbl_db_method_info.thread_complete_gate = thread_complete_gate;
  568. acpi_gbl_db_method_info.info_gate = info_gate;
  569. /* Init arguments to be passed to method */
  570. acpi_gbl_db_method_info.init_args = 1;
  571. acpi_gbl_db_method_info.args = acpi_gbl_db_method_info.arguments;
  572. acpi_gbl_db_method_info.arguments[0] =
  573. acpi_gbl_db_method_info.num_threads_str;
  574. acpi_gbl_db_method_info.arguments[1] =
  575. acpi_gbl_db_method_info.id_of_thread_str;
  576. acpi_gbl_db_method_info.arguments[2] =
  577. acpi_gbl_db_method_info.index_of_thread_str;
  578. acpi_gbl_db_method_info.arguments[3] = NULL;
  579. acpi_gbl_db_method_info.types = acpi_gbl_db_method_info.arg_types;
  580. acpi_gbl_db_method_info.arg_types[0] = ACPI_TYPE_INTEGER;
  581. acpi_gbl_db_method_info.arg_types[1] = ACPI_TYPE_INTEGER;
  582. acpi_gbl_db_method_info.arg_types[2] = ACPI_TYPE_INTEGER;
  583. acpi_db_uint32_to_hex_string(num_threads,
  584. acpi_gbl_db_method_info.num_threads_str);
  585. status = acpi_db_execute_setup(&acpi_gbl_db_method_info);
  586. if (ACPI_FAILURE(status)) {
  587. goto cleanup_and_exit;
  588. }
  589. /* Get the NS node, determines existence also */
  590. status = acpi_get_handle(NULL, acpi_gbl_db_method_info.pathname,
  591. &acpi_gbl_db_method_info.method);
  592. if (ACPI_FAILURE(status)) {
  593. acpi_os_printf("%s Could not get handle for %s\n",
  594. acpi_format_exception(status),
  595. acpi_gbl_db_method_info.pathname);
  596. goto cleanup_and_exit;
  597. }
  598. /* Create the threads */
  599. acpi_os_printf("Creating %X threads to execute %X times each\n",
  600. num_threads, num_loops);
  601. for (i = 0; i < (num_threads); i++) {
  602. status =
  603. acpi_os_execute(OSL_DEBUGGER_EXEC_THREAD,
  604. acpi_db_method_thread,
  605. &acpi_gbl_db_method_info);
  606. if (ACPI_FAILURE(status)) {
  607. break;
  608. }
  609. }
  610. /* Wait for all threads to complete */
  611. (void)acpi_os_wait_semaphore(main_thread_gate, 1, ACPI_WAIT_FOREVER);
  612. acpi_db_set_output_destination(ACPI_DB_DUPLICATE_OUTPUT);
  613. acpi_os_printf("All threads (%X) have completed\n", num_threads);
  614. acpi_db_set_output_destination(ACPI_DB_CONSOLE_OUTPUT);
  615. cleanup_and_exit:
  616. /* Cleanup and exit */
  617. (void)acpi_os_delete_semaphore(main_thread_gate);
  618. (void)acpi_os_delete_semaphore(thread_complete_gate);
  619. (void)acpi_os_delete_semaphore(info_gate);
  620. acpi_os_free(acpi_gbl_db_method_info.threads);
  621. acpi_gbl_db_method_info.threads = NULL;
  622. }