dbexec.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782
  1. /*******************************************************************************
  2. *
  3. * Module Name: dbexec - debugger control method execution
  4. *
  5. ******************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2017, 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. if ((status == AE_ABORT_METHOD) || acpi_gbl_abort_method) {
  146. /* Clear the abort and fall back to the debugger prompt */
  147. ACPI_EXCEPTION((AE_INFO, status,
  148. "Aborting top-level method"));
  149. acpi_gbl_abort_method = FALSE;
  150. status = AE_OK;
  151. goto cleanup;
  152. }
  153. ACPI_EXCEPTION((AE_INFO, status,
  154. "while executing %s from debugger",
  155. info->pathname));
  156. if (status == AE_BUFFER_OVERFLOW) {
  157. ACPI_ERROR((AE_INFO,
  158. "Possible overflow of internal debugger "
  159. "buffer (size 0x%X needed 0x%X)",
  160. ACPI_DEBUG_BUFFER_SIZE,
  161. (u32)return_obj->length));
  162. }
  163. }
  164. cleanup:
  165. acpi_db_delete_objects(param_objects.count, params);
  166. return_ACPI_STATUS(status);
  167. }
  168. /*******************************************************************************
  169. *
  170. * FUNCTION: acpi_db_execute_setup
  171. *
  172. * PARAMETERS: info - Valid method info
  173. *
  174. * RETURN: None
  175. *
  176. * DESCRIPTION: Setup info segment prior to method execution
  177. *
  178. ******************************************************************************/
  179. static acpi_status acpi_db_execute_setup(struct acpi_db_method_info *info)
  180. {
  181. acpi_status status;
  182. ACPI_FUNCTION_NAME(db_execute_setup);
  183. /* Catenate the current scope to the supplied name */
  184. info->pathname[0] = 0;
  185. if ((info->name[0] != '\\') && (info->name[0] != '/')) {
  186. if (acpi_ut_safe_strcat(info->pathname, sizeof(info->pathname),
  187. acpi_gbl_db_scope_buf)) {
  188. status = AE_BUFFER_OVERFLOW;
  189. goto error_exit;
  190. }
  191. }
  192. if (acpi_ut_safe_strcat(info->pathname, sizeof(info->pathname),
  193. info->name)) {
  194. status = AE_BUFFER_OVERFLOW;
  195. goto error_exit;
  196. }
  197. acpi_db_prep_namestring(info->pathname);
  198. acpi_db_set_output_destination(ACPI_DB_DUPLICATE_OUTPUT);
  199. acpi_os_printf("Evaluating %s\n", info->pathname);
  200. if (info->flags & EX_SINGLE_STEP) {
  201. acpi_gbl_cm_single_step = TRUE;
  202. acpi_db_set_output_destination(ACPI_DB_CONSOLE_OUTPUT);
  203. }
  204. else {
  205. /* No single step, allow redirection to a file */
  206. acpi_db_set_output_destination(ACPI_DB_REDIRECTABLE_OUTPUT);
  207. }
  208. return (AE_OK);
  209. error_exit:
  210. ACPI_EXCEPTION((AE_INFO, status, "During setup for method execution"));
  211. return (status);
  212. }
  213. #ifdef ACPI_DBG_TRACK_ALLOCATIONS
  214. u32 acpi_db_get_cache_info(struct acpi_memory_list *cache)
  215. {
  216. return (cache->total_allocated - cache->total_freed -
  217. cache->current_depth);
  218. }
  219. #endif
  220. /*******************************************************************************
  221. *
  222. * FUNCTION: acpi_db_get_outstanding_allocations
  223. *
  224. * PARAMETERS: None
  225. *
  226. * RETURN: Current global allocation count minus cache entries
  227. *
  228. * DESCRIPTION: Determine the current number of "outstanding" allocations --
  229. * those allocations that have not been freed and also are not
  230. * in one of the various object caches.
  231. *
  232. ******************************************************************************/
  233. static u32 acpi_db_get_outstanding_allocations(void)
  234. {
  235. u32 outstanding = 0;
  236. #ifdef ACPI_DBG_TRACK_ALLOCATIONS
  237. outstanding += acpi_db_get_cache_info(acpi_gbl_state_cache);
  238. outstanding += acpi_db_get_cache_info(acpi_gbl_ps_node_cache);
  239. outstanding += acpi_db_get_cache_info(acpi_gbl_ps_node_ext_cache);
  240. outstanding += acpi_db_get_cache_info(acpi_gbl_operand_cache);
  241. #endif
  242. return (outstanding);
  243. }
  244. /*******************************************************************************
  245. *
  246. * FUNCTION: acpi_db_execution_walk
  247. *
  248. * PARAMETERS: WALK_CALLBACK
  249. *
  250. * RETURN: Status
  251. *
  252. * DESCRIPTION: Execute a control method. Name is relative to the current
  253. * scope.
  254. *
  255. ******************************************************************************/
  256. static acpi_status
  257. acpi_db_execution_walk(acpi_handle obj_handle,
  258. u32 nesting_level, void *context, void **return_value)
  259. {
  260. union acpi_operand_object *obj_desc;
  261. struct acpi_namespace_node *node =
  262. (struct acpi_namespace_node *)obj_handle;
  263. struct acpi_buffer return_obj;
  264. acpi_status status;
  265. obj_desc = acpi_ns_get_attached_object(node);
  266. if (obj_desc->method.param_count) {
  267. return (AE_OK);
  268. }
  269. return_obj.pointer = NULL;
  270. return_obj.length = ACPI_ALLOCATE_BUFFER;
  271. acpi_ns_print_node_pathname(node, "Evaluating");
  272. /* Do the actual method execution */
  273. acpi_os_printf("\n");
  274. acpi_gbl_method_executing = TRUE;
  275. status = acpi_evaluate_object(node, NULL, NULL, &return_obj);
  276. acpi_os_printf("Evaluation of [%4.4s] returned %s\n",
  277. acpi_ut_get_node_name(node),
  278. acpi_format_exception(status));
  279. acpi_gbl_method_executing = FALSE;
  280. return (AE_OK);
  281. }
  282. /*******************************************************************************
  283. *
  284. * FUNCTION: acpi_db_execute
  285. *
  286. * PARAMETERS: name - Name of method to execute
  287. * args - Parameters to the method
  288. * Types -
  289. * flags - single step/no single step
  290. *
  291. * RETURN: None
  292. *
  293. * DESCRIPTION: Execute a control method. Name is relative to the current
  294. * scope.
  295. *
  296. ******************************************************************************/
  297. void
  298. acpi_db_execute(char *name, char **args, acpi_object_type *types, u32 flags)
  299. {
  300. acpi_status status;
  301. struct acpi_buffer return_obj;
  302. char *name_string;
  303. #ifdef ACPI_DEBUG_OUTPUT
  304. u32 previous_allocations;
  305. u32 allocations;
  306. #endif
  307. /*
  308. * Allow one execution to be performed by debugger or single step
  309. * execution will be dead locked by the interpreter mutexes.
  310. */
  311. if (acpi_gbl_method_executing) {
  312. acpi_os_printf("Only one debugger execution is allowed.\n");
  313. return;
  314. }
  315. #ifdef ACPI_DEBUG_OUTPUT
  316. /* Memory allocation tracking */
  317. previous_allocations = acpi_db_get_outstanding_allocations();
  318. #endif
  319. if (*name == '*') {
  320. (void)acpi_walk_namespace(ACPI_TYPE_METHOD, ACPI_ROOT_OBJECT,
  321. ACPI_UINT32_MAX,
  322. acpi_db_execution_walk, NULL, NULL,
  323. NULL);
  324. return;
  325. }
  326. name_string = ACPI_ALLOCATE(strlen(name) + 1);
  327. if (!name_string) {
  328. return;
  329. }
  330. memset(&acpi_gbl_db_method_info, 0, sizeof(struct acpi_db_method_info));
  331. strcpy(name_string, name);
  332. acpi_ut_strupr(name_string);
  333. /* Subcommand to Execute all predefined names in the namespace */
  334. if (!strncmp(name_string, "PREDEF", 6)) {
  335. acpi_db_evaluate_predefined_names();
  336. ACPI_FREE(name_string);
  337. return;
  338. }
  339. acpi_gbl_db_method_info.name = name_string;
  340. acpi_gbl_db_method_info.args = args;
  341. acpi_gbl_db_method_info.types = types;
  342. acpi_gbl_db_method_info.flags = flags;
  343. return_obj.pointer = NULL;
  344. return_obj.length = ACPI_ALLOCATE_BUFFER;
  345. status = acpi_db_execute_setup(&acpi_gbl_db_method_info);
  346. if (ACPI_FAILURE(status)) {
  347. ACPI_FREE(name_string);
  348. return;
  349. }
  350. /* Get the NS node, determines existence also */
  351. status = acpi_get_handle(NULL, acpi_gbl_db_method_info.pathname,
  352. &acpi_gbl_db_method_info.method);
  353. if (ACPI_SUCCESS(status)) {
  354. status = acpi_db_execute_method(&acpi_gbl_db_method_info,
  355. &return_obj);
  356. }
  357. ACPI_FREE(name_string);
  358. /*
  359. * Allow any handlers in separate threads to complete.
  360. * (Such as Notify handlers invoked from AML executed above).
  361. */
  362. acpi_os_sleep((u64)10);
  363. #ifdef ACPI_DEBUG_OUTPUT
  364. /* Memory allocation tracking */
  365. allocations =
  366. acpi_db_get_outstanding_allocations() - previous_allocations;
  367. acpi_db_set_output_destination(ACPI_DB_DUPLICATE_OUTPUT);
  368. if (allocations > 0) {
  369. acpi_os_printf
  370. ("0x%X Outstanding allocations after evaluation of %s\n",
  371. allocations, acpi_gbl_db_method_info.pathname);
  372. }
  373. #endif
  374. if (ACPI_FAILURE(status)) {
  375. acpi_os_printf("Evaluation of %s failed with status %s\n",
  376. acpi_gbl_db_method_info.pathname,
  377. acpi_format_exception(status));
  378. } else {
  379. /* Display a return object, if any */
  380. if (return_obj.length) {
  381. acpi_os_printf("Evaluation of %s returned object %p, "
  382. "external buffer length %X\n",
  383. acpi_gbl_db_method_info.pathname,
  384. return_obj.pointer,
  385. (u32)return_obj.length);
  386. acpi_db_dump_external_object(return_obj.pointer, 1);
  387. /* Dump a _PLD buffer if present */
  388. if (ACPI_COMPARE_NAME
  389. ((ACPI_CAST_PTR
  390. (struct acpi_namespace_node,
  391. acpi_gbl_db_method_info.method)->name.ascii),
  392. METHOD_NAME__PLD)) {
  393. acpi_db_dump_pld_buffer(return_obj.pointer);
  394. }
  395. } else {
  396. acpi_os_printf
  397. ("No object was returned from evaluation of %s\n",
  398. acpi_gbl_db_method_info.pathname);
  399. }
  400. }
  401. acpi_db_set_output_destination(ACPI_DB_CONSOLE_OUTPUT);
  402. }
  403. /*******************************************************************************
  404. *
  405. * FUNCTION: acpi_db_method_thread
  406. *
  407. * PARAMETERS: context - Execution info segment
  408. *
  409. * RETURN: None
  410. *
  411. * DESCRIPTION: Debugger execute thread. Waits for a command line, then
  412. * simply dispatches it.
  413. *
  414. ******************************************************************************/
  415. static void ACPI_SYSTEM_XFACE acpi_db_method_thread(void *context)
  416. {
  417. acpi_status status;
  418. struct acpi_db_method_info *info = context;
  419. struct acpi_db_method_info local_info;
  420. u32 i;
  421. u8 allow;
  422. struct acpi_buffer return_obj;
  423. /*
  424. * acpi_gbl_db_method_info.Arguments will be passed as method arguments.
  425. * Prevent acpi_gbl_db_method_info from being modified by multiple threads
  426. * concurrently.
  427. *
  428. * Note: The arguments we are passing are used by the ASL test suite
  429. * (aslts). Do not change them without updating the tests.
  430. */
  431. (void)acpi_os_wait_semaphore(info->info_gate, 1, ACPI_WAIT_FOREVER);
  432. if (info->init_args) {
  433. acpi_db_uint32_to_hex_string(info->num_created,
  434. info->index_of_thread_str);
  435. acpi_db_uint32_to_hex_string((u32)acpi_os_get_thread_id(),
  436. info->id_of_thread_str);
  437. }
  438. if (info->threads && (info->num_created < info->num_threads)) {
  439. info->threads[info->num_created++] = acpi_os_get_thread_id();
  440. }
  441. local_info = *info;
  442. local_info.args = local_info.arguments;
  443. local_info.arguments[0] = local_info.num_threads_str;
  444. local_info.arguments[1] = local_info.id_of_thread_str;
  445. local_info.arguments[2] = local_info.index_of_thread_str;
  446. local_info.arguments[3] = NULL;
  447. local_info.types = local_info.arg_types;
  448. (void)acpi_os_signal_semaphore(info->info_gate, 1);
  449. for (i = 0; i < info->num_loops; i++) {
  450. status = acpi_db_execute_method(&local_info, &return_obj);
  451. if (ACPI_FAILURE(status)) {
  452. acpi_os_printf
  453. ("%s During evaluation of %s at iteration %X\n",
  454. acpi_format_exception(status), info->pathname, i);
  455. if (status == AE_ABORT_METHOD) {
  456. break;
  457. }
  458. }
  459. #if 0
  460. if ((i % 100) == 0) {
  461. acpi_os_printf("%u loops, Thread 0x%x\n",
  462. i, acpi_os_get_thread_id());
  463. }
  464. if (return_obj.length) {
  465. acpi_os_printf
  466. ("Evaluation of %s returned object %p Buflen %X\n",
  467. info->pathname, return_obj.pointer,
  468. (u32)return_obj.length);
  469. acpi_db_dump_external_object(return_obj.pointer, 1);
  470. }
  471. #endif
  472. }
  473. /* Signal our completion */
  474. allow = 0;
  475. (void)acpi_os_wait_semaphore(info->thread_complete_gate,
  476. 1, ACPI_WAIT_FOREVER);
  477. info->num_completed++;
  478. if (info->num_completed == info->num_threads) {
  479. /* Do signal for main thread once only */
  480. allow = 1;
  481. }
  482. (void)acpi_os_signal_semaphore(info->thread_complete_gate, 1);
  483. if (allow) {
  484. status = acpi_os_signal_semaphore(info->main_thread_gate, 1);
  485. if (ACPI_FAILURE(status)) {
  486. acpi_os_printf
  487. ("Could not signal debugger thread sync semaphore, %s\n",
  488. acpi_format_exception(status));
  489. }
  490. }
  491. }
  492. /*******************************************************************************
  493. *
  494. * FUNCTION: acpi_db_create_execution_threads
  495. *
  496. * PARAMETERS: num_threads_arg - Number of threads to create
  497. * num_loops_arg - Loop count for the thread(s)
  498. * method_name_arg - Control method to execute
  499. *
  500. * RETURN: None
  501. *
  502. * DESCRIPTION: Create threads to execute method(s)
  503. *
  504. ******************************************************************************/
  505. void
  506. acpi_db_create_execution_threads(char *num_threads_arg,
  507. char *num_loops_arg, char *method_name_arg)
  508. {
  509. acpi_status status;
  510. u32 num_threads;
  511. u32 num_loops;
  512. u32 i;
  513. u32 size;
  514. acpi_mutex main_thread_gate;
  515. acpi_mutex thread_complete_gate;
  516. acpi_mutex info_gate;
  517. /* Get the arguments */
  518. num_threads = strtoul(num_threads_arg, NULL, 0);
  519. num_loops = strtoul(num_loops_arg, NULL, 0);
  520. if (!num_threads || !num_loops) {
  521. acpi_os_printf("Bad argument: Threads %X, Loops %X\n",
  522. num_threads, num_loops);
  523. return;
  524. }
  525. /*
  526. * Create the semaphore for synchronization of
  527. * the created threads with the main thread.
  528. */
  529. status = acpi_os_create_semaphore(1, 0, &main_thread_gate);
  530. if (ACPI_FAILURE(status)) {
  531. acpi_os_printf("Could not create semaphore for "
  532. "synchronization with the main thread, %s\n",
  533. acpi_format_exception(status));
  534. return;
  535. }
  536. /*
  537. * Create the semaphore for synchronization
  538. * between the created threads.
  539. */
  540. status = acpi_os_create_semaphore(1, 1, &thread_complete_gate);
  541. if (ACPI_FAILURE(status)) {
  542. acpi_os_printf("Could not create semaphore for "
  543. "synchronization between the created threads, %s\n",
  544. acpi_format_exception(status));
  545. (void)acpi_os_delete_semaphore(main_thread_gate);
  546. return;
  547. }
  548. status = acpi_os_create_semaphore(1, 1, &info_gate);
  549. if (ACPI_FAILURE(status)) {
  550. acpi_os_printf("Could not create semaphore for "
  551. "synchronization of AcpiGbl_DbMethodInfo, %s\n",
  552. acpi_format_exception(status));
  553. (void)acpi_os_delete_semaphore(thread_complete_gate);
  554. (void)acpi_os_delete_semaphore(main_thread_gate);
  555. return;
  556. }
  557. memset(&acpi_gbl_db_method_info, 0, sizeof(struct acpi_db_method_info));
  558. /* Array to store IDs of threads */
  559. acpi_gbl_db_method_info.num_threads = num_threads;
  560. size = sizeof(acpi_thread_id) * acpi_gbl_db_method_info.num_threads;
  561. acpi_gbl_db_method_info.threads = acpi_os_allocate(size);
  562. if (acpi_gbl_db_method_info.threads == NULL) {
  563. acpi_os_printf("No memory for thread IDs array\n");
  564. (void)acpi_os_delete_semaphore(main_thread_gate);
  565. (void)acpi_os_delete_semaphore(thread_complete_gate);
  566. (void)acpi_os_delete_semaphore(info_gate);
  567. return;
  568. }
  569. memset(acpi_gbl_db_method_info.threads, 0, size);
  570. /* Setup the context to be passed to each thread */
  571. acpi_gbl_db_method_info.name = method_name_arg;
  572. acpi_gbl_db_method_info.flags = 0;
  573. acpi_gbl_db_method_info.num_loops = num_loops;
  574. acpi_gbl_db_method_info.main_thread_gate = main_thread_gate;
  575. acpi_gbl_db_method_info.thread_complete_gate = thread_complete_gate;
  576. acpi_gbl_db_method_info.info_gate = info_gate;
  577. /* Init arguments to be passed to method */
  578. acpi_gbl_db_method_info.init_args = 1;
  579. acpi_gbl_db_method_info.args = acpi_gbl_db_method_info.arguments;
  580. acpi_gbl_db_method_info.arguments[0] =
  581. acpi_gbl_db_method_info.num_threads_str;
  582. acpi_gbl_db_method_info.arguments[1] =
  583. acpi_gbl_db_method_info.id_of_thread_str;
  584. acpi_gbl_db_method_info.arguments[2] =
  585. acpi_gbl_db_method_info.index_of_thread_str;
  586. acpi_gbl_db_method_info.arguments[3] = NULL;
  587. acpi_gbl_db_method_info.types = acpi_gbl_db_method_info.arg_types;
  588. acpi_gbl_db_method_info.arg_types[0] = ACPI_TYPE_INTEGER;
  589. acpi_gbl_db_method_info.arg_types[1] = ACPI_TYPE_INTEGER;
  590. acpi_gbl_db_method_info.arg_types[2] = ACPI_TYPE_INTEGER;
  591. acpi_db_uint32_to_hex_string(num_threads,
  592. acpi_gbl_db_method_info.num_threads_str);
  593. status = acpi_db_execute_setup(&acpi_gbl_db_method_info);
  594. if (ACPI_FAILURE(status)) {
  595. goto cleanup_and_exit;
  596. }
  597. /* Get the NS node, determines existence also */
  598. status = acpi_get_handle(NULL, acpi_gbl_db_method_info.pathname,
  599. &acpi_gbl_db_method_info.method);
  600. if (ACPI_FAILURE(status)) {
  601. acpi_os_printf("%s Could not get handle for %s\n",
  602. acpi_format_exception(status),
  603. acpi_gbl_db_method_info.pathname);
  604. goto cleanup_and_exit;
  605. }
  606. /* Create the threads */
  607. acpi_os_printf("Creating %X threads to execute %X times each\n",
  608. num_threads, num_loops);
  609. for (i = 0; i < (num_threads); i++) {
  610. status =
  611. acpi_os_execute(OSL_DEBUGGER_EXEC_THREAD,
  612. acpi_db_method_thread,
  613. &acpi_gbl_db_method_info);
  614. if (ACPI_FAILURE(status)) {
  615. break;
  616. }
  617. }
  618. /* Wait for all threads to complete */
  619. (void)acpi_os_wait_semaphore(main_thread_gate, 1, ACPI_WAIT_FOREVER);
  620. acpi_db_set_output_destination(ACPI_DB_DUPLICATE_OUTPUT);
  621. acpi_os_printf("All threads (%X) have completed\n", num_threads);
  622. acpi_db_set_output_destination(ACPI_DB_CONSOLE_OUTPUT);
  623. cleanup_and_exit:
  624. /* Cleanup and exit */
  625. (void)acpi_os_delete_semaphore(main_thread_gate);
  626. (void)acpi_os_delete_semaphore(thread_complete_gate);
  627. (void)acpi_os_delete_semaphore(info_gate);
  628. acpi_os_free(acpi_gbl_db_method_info.threads);
  629. acpi_gbl_db_method_info.threads = NULL;
  630. }