dbexec.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764
  1. /*******************************************************************************
  2. *
  3. * Module Name: dbexec - debugger control method execution
  4. *
  5. ******************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2015, 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. } else {
  318. name_string = ACPI_ALLOCATE(strlen(name) + 1);
  319. if (!name_string) {
  320. return;
  321. }
  322. memset(&acpi_gbl_db_method_info, 0,
  323. sizeof(struct acpi_db_method_info));
  324. strcpy(name_string, name);
  325. acpi_ut_strupr(name_string);
  326. acpi_gbl_db_method_info.name = name_string;
  327. acpi_gbl_db_method_info.args = args;
  328. acpi_gbl_db_method_info.types = types;
  329. acpi_gbl_db_method_info.flags = flags;
  330. return_obj.pointer = NULL;
  331. return_obj.length = ACPI_ALLOCATE_BUFFER;
  332. status = acpi_db_execute_setup(&acpi_gbl_db_method_info);
  333. if (ACPI_FAILURE(status)) {
  334. ACPI_FREE(name_string);
  335. return;
  336. }
  337. /* Get the NS node, determines existence also */
  338. status = acpi_get_handle(NULL, acpi_gbl_db_method_info.pathname,
  339. &acpi_gbl_db_method_info.method);
  340. if (ACPI_SUCCESS(status)) {
  341. status =
  342. acpi_db_execute_method(&acpi_gbl_db_method_info,
  343. &return_obj);
  344. }
  345. ACPI_FREE(name_string);
  346. }
  347. /*
  348. * Allow any handlers in separate threads to complete.
  349. * (Such as Notify handlers invoked from AML executed above).
  350. */
  351. acpi_os_sleep((u64)10);
  352. #ifdef ACPI_DEBUG_OUTPUT
  353. /* Memory allocation tracking */
  354. allocations =
  355. acpi_db_get_outstanding_allocations() - previous_allocations;
  356. acpi_db_set_output_destination(ACPI_DB_DUPLICATE_OUTPUT);
  357. if (allocations > 0) {
  358. acpi_os_printf
  359. ("0x%X Outstanding allocations after evaluation of %s\n",
  360. allocations, acpi_gbl_db_method_info.pathname);
  361. }
  362. #endif
  363. if (ACPI_FAILURE(status)) {
  364. acpi_os_printf("Evaluation of %s failed with status %s\n",
  365. acpi_gbl_db_method_info.pathname,
  366. acpi_format_exception(status));
  367. } else {
  368. /* Display a return object, if any */
  369. if (return_obj.length) {
  370. acpi_os_printf("Evaluation of %s returned object %p, "
  371. "external buffer length %X\n",
  372. acpi_gbl_db_method_info.pathname,
  373. return_obj.pointer,
  374. (u32)return_obj.length);
  375. acpi_db_dump_external_object(return_obj.pointer, 1);
  376. /* Dump a _PLD buffer if present */
  377. if (ACPI_COMPARE_NAME
  378. ((ACPI_CAST_PTR
  379. (struct acpi_namespace_node,
  380. acpi_gbl_db_method_info.method)->name.ascii),
  381. METHOD_NAME__PLD)) {
  382. acpi_db_dump_pld_buffer(return_obj.pointer);
  383. }
  384. } else {
  385. acpi_os_printf
  386. ("No object was returned from evaluation of %s\n",
  387. acpi_gbl_db_method_info.pathname);
  388. }
  389. }
  390. acpi_db_set_output_destination(ACPI_DB_CONSOLE_OUTPUT);
  391. }
  392. /*******************************************************************************
  393. *
  394. * FUNCTION: acpi_db_method_thread
  395. *
  396. * PARAMETERS: context - Execution info segment
  397. *
  398. * RETURN: None
  399. *
  400. * DESCRIPTION: Debugger execute thread. Waits for a command line, then
  401. * simply dispatches it.
  402. *
  403. ******************************************************************************/
  404. static void ACPI_SYSTEM_XFACE acpi_db_method_thread(void *context)
  405. {
  406. acpi_status status;
  407. struct acpi_db_method_info *info = context;
  408. struct acpi_db_method_info local_info;
  409. u32 i;
  410. u8 allow;
  411. struct acpi_buffer return_obj;
  412. /*
  413. * acpi_gbl_db_method_info.Arguments will be passed as method arguments.
  414. * Prevent acpi_gbl_db_method_info from being modified by multiple threads
  415. * concurrently.
  416. *
  417. * Note: The arguments we are passing are used by the ASL test suite
  418. * (aslts). Do not change them without updating the tests.
  419. */
  420. (void)acpi_os_wait_semaphore(info->info_gate, 1, ACPI_WAIT_FOREVER);
  421. if (info->init_args) {
  422. acpi_db_uint32_to_hex_string(info->num_created,
  423. info->index_of_thread_str);
  424. acpi_db_uint32_to_hex_string((u32)acpi_os_get_thread_id(),
  425. info->id_of_thread_str);
  426. }
  427. if (info->threads && (info->num_created < info->num_threads)) {
  428. info->threads[info->num_created++] = acpi_os_get_thread_id();
  429. }
  430. local_info = *info;
  431. local_info.args = local_info.arguments;
  432. local_info.arguments[0] = local_info.num_threads_str;
  433. local_info.arguments[1] = local_info.id_of_thread_str;
  434. local_info.arguments[2] = local_info.index_of_thread_str;
  435. local_info.arguments[3] = NULL;
  436. local_info.types = local_info.arg_types;
  437. (void)acpi_os_signal_semaphore(info->info_gate, 1);
  438. for (i = 0; i < info->num_loops; i++) {
  439. status = acpi_db_execute_method(&local_info, &return_obj);
  440. if (ACPI_FAILURE(status)) {
  441. acpi_os_printf
  442. ("%s During evaluation of %s at iteration %X\n",
  443. acpi_format_exception(status), info->pathname, i);
  444. if (status == AE_ABORT_METHOD) {
  445. break;
  446. }
  447. }
  448. #if 0
  449. if ((i % 100) == 0) {
  450. acpi_os_printf("%u loops, Thread 0x%x\n",
  451. i, acpi_os_get_thread_id());
  452. }
  453. if (return_obj.length) {
  454. acpi_os_printf
  455. ("Evaluation of %s returned object %p Buflen %X\n",
  456. info->pathname, return_obj.pointer,
  457. (u32)return_obj.length);
  458. acpi_db_dump_external_object(return_obj.pointer, 1);
  459. }
  460. #endif
  461. }
  462. /* Signal our completion */
  463. allow = 0;
  464. (void)acpi_os_wait_semaphore(info->thread_complete_gate,
  465. 1, ACPI_WAIT_FOREVER);
  466. info->num_completed++;
  467. if (info->num_completed == info->num_threads) {
  468. /* Do signal for main thread once only */
  469. allow = 1;
  470. }
  471. (void)acpi_os_signal_semaphore(info->thread_complete_gate, 1);
  472. if (allow) {
  473. status = acpi_os_signal_semaphore(info->main_thread_gate, 1);
  474. if (ACPI_FAILURE(status)) {
  475. acpi_os_printf
  476. ("Could not signal debugger thread sync semaphore, %s\n",
  477. acpi_format_exception(status));
  478. }
  479. }
  480. }
  481. /*******************************************************************************
  482. *
  483. * FUNCTION: acpi_db_create_execution_threads
  484. *
  485. * PARAMETERS: num_threads_arg - Number of threads to create
  486. * num_loops_arg - Loop count for the thread(s)
  487. * method_name_arg - Control method to execute
  488. *
  489. * RETURN: None
  490. *
  491. * DESCRIPTION: Create threads to execute method(s)
  492. *
  493. ******************************************************************************/
  494. void
  495. acpi_db_create_execution_threads(char *num_threads_arg,
  496. char *num_loops_arg, char *method_name_arg)
  497. {
  498. acpi_status status;
  499. u32 num_threads;
  500. u32 num_loops;
  501. u32 i;
  502. u32 size;
  503. acpi_mutex main_thread_gate;
  504. acpi_mutex thread_complete_gate;
  505. acpi_mutex info_gate;
  506. /* Get the arguments */
  507. num_threads = strtoul(num_threads_arg, NULL, 0);
  508. num_loops = strtoul(num_loops_arg, NULL, 0);
  509. if (!num_threads || !num_loops) {
  510. acpi_os_printf("Bad argument: Threads %X, Loops %X\n",
  511. num_threads, num_loops);
  512. return;
  513. }
  514. /*
  515. * Create the semaphore for synchronization of
  516. * the created threads with the main thread.
  517. */
  518. status = acpi_os_create_semaphore(1, 0, &main_thread_gate);
  519. if (ACPI_FAILURE(status)) {
  520. acpi_os_printf("Could not create semaphore for "
  521. "synchronization with the main thread, %s\n",
  522. acpi_format_exception(status));
  523. return;
  524. }
  525. /*
  526. * Create the semaphore for synchronization
  527. * between the created threads.
  528. */
  529. status = acpi_os_create_semaphore(1, 1, &thread_complete_gate);
  530. if (ACPI_FAILURE(status)) {
  531. acpi_os_printf("Could not create semaphore for "
  532. "synchronization between the created threads, %s\n",
  533. acpi_format_exception(status));
  534. (void)acpi_os_delete_semaphore(main_thread_gate);
  535. return;
  536. }
  537. status = acpi_os_create_semaphore(1, 1, &info_gate);
  538. if (ACPI_FAILURE(status)) {
  539. acpi_os_printf("Could not create semaphore for "
  540. "synchronization of AcpiGbl_DbMethodInfo, %s\n",
  541. acpi_format_exception(status));
  542. (void)acpi_os_delete_semaphore(thread_complete_gate);
  543. (void)acpi_os_delete_semaphore(main_thread_gate);
  544. return;
  545. }
  546. memset(&acpi_gbl_db_method_info, 0, sizeof(struct acpi_db_method_info));
  547. /* Array to store IDs of threads */
  548. acpi_gbl_db_method_info.num_threads = num_threads;
  549. size = sizeof(acpi_thread_id) * acpi_gbl_db_method_info.num_threads;
  550. acpi_gbl_db_method_info.threads = acpi_os_allocate(size);
  551. if (acpi_gbl_db_method_info.threads == NULL) {
  552. acpi_os_printf("No memory for thread IDs array\n");
  553. (void)acpi_os_delete_semaphore(main_thread_gate);
  554. (void)acpi_os_delete_semaphore(thread_complete_gate);
  555. (void)acpi_os_delete_semaphore(info_gate);
  556. return;
  557. }
  558. memset(acpi_gbl_db_method_info.threads, 0, size);
  559. /* Setup the context to be passed to each thread */
  560. acpi_gbl_db_method_info.name = method_name_arg;
  561. acpi_gbl_db_method_info.flags = 0;
  562. acpi_gbl_db_method_info.num_loops = num_loops;
  563. acpi_gbl_db_method_info.main_thread_gate = main_thread_gate;
  564. acpi_gbl_db_method_info.thread_complete_gate = thread_complete_gate;
  565. acpi_gbl_db_method_info.info_gate = info_gate;
  566. /* Init arguments to be passed to method */
  567. acpi_gbl_db_method_info.init_args = 1;
  568. acpi_gbl_db_method_info.args = acpi_gbl_db_method_info.arguments;
  569. acpi_gbl_db_method_info.arguments[0] =
  570. acpi_gbl_db_method_info.num_threads_str;
  571. acpi_gbl_db_method_info.arguments[1] =
  572. acpi_gbl_db_method_info.id_of_thread_str;
  573. acpi_gbl_db_method_info.arguments[2] =
  574. acpi_gbl_db_method_info.index_of_thread_str;
  575. acpi_gbl_db_method_info.arguments[3] = NULL;
  576. acpi_gbl_db_method_info.types = acpi_gbl_db_method_info.arg_types;
  577. acpi_gbl_db_method_info.arg_types[0] = ACPI_TYPE_INTEGER;
  578. acpi_gbl_db_method_info.arg_types[1] = ACPI_TYPE_INTEGER;
  579. acpi_gbl_db_method_info.arg_types[2] = ACPI_TYPE_INTEGER;
  580. acpi_db_uint32_to_hex_string(num_threads,
  581. acpi_gbl_db_method_info.num_threads_str);
  582. status = acpi_db_execute_setup(&acpi_gbl_db_method_info);
  583. if (ACPI_FAILURE(status)) {
  584. goto cleanup_and_exit;
  585. }
  586. /* Get the NS node, determines existence also */
  587. status = acpi_get_handle(NULL, acpi_gbl_db_method_info.pathname,
  588. &acpi_gbl_db_method_info.method);
  589. if (ACPI_FAILURE(status)) {
  590. acpi_os_printf("%s Could not get handle for %s\n",
  591. acpi_format_exception(status),
  592. acpi_gbl_db_method_info.pathname);
  593. goto cleanup_and_exit;
  594. }
  595. /* Create the threads */
  596. acpi_os_printf("Creating %X threads to execute %X times each\n",
  597. num_threads, num_loops);
  598. for (i = 0; i < (num_threads); i++) {
  599. status =
  600. acpi_os_execute(OSL_DEBUGGER_EXEC_THREAD,
  601. acpi_db_method_thread,
  602. &acpi_gbl_db_method_info);
  603. if (ACPI_FAILURE(status)) {
  604. break;
  605. }
  606. }
  607. /* Wait for all threads to complete */
  608. (void)acpi_os_wait_semaphore(main_thread_gate, 1, ACPI_WAIT_FOREVER);
  609. acpi_db_set_output_destination(ACPI_DB_DUPLICATE_OUTPUT);
  610. acpi_os_printf("All threads (%X) have completed\n", num_threads);
  611. acpi_db_set_output_destination(ACPI_DB_CONSOLE_OUTPUT);
  612. cleanup_and_exit:
  613. /* Cleanup and exit */
  614. (void)acpi_os_delete_semaphore(main_thread_gate);
  615. (void)acpi_os_delete_semaphore(thread_complete_gate);
  616. (void)acpi_os_delete_semaphore(info_gate);
  617. acpi_os_free(acpi_gbl_db_method_info.threads);
  618. acpi_gbl_db_method_info.threads = NULL;
  619. }