dbtest.c 28 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057
  1. /*******************************************************************************
  2. *
  3. * Module Name: dbtest - Various debug-related tests
  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. #include "acpredef.h"
  47. #define _COMPONENT ACPI_CA_DEBUGGER
  48. ACPI_MODULE_NAME("dbtest")
  49. /* Local prototypes */
  50. static void acpi_db_test_all_objects(void);
  51. static acpi_status
  52. acpi_db_test_one_object(acpi_handle obj_handle,
  53. u32 nesting_level, void *context, void **return_value);
  54. static acpi_status
  55. acpi_db_test_integer_type(struct acpi_namespace_node *node, u32 bit_length);
  56. static acpi_status
  57. acpi_db_test_buffer_type(struct acpi_namespace_node *node, u32 bit_length);
  58. static acpi_status
  59. acpi_db_test_string_type(struct acpi_namespace_node *node, u32 byte_length);
  60. static acpi_status
  61. acpi_db_read_from_object(struct acpi_namespace_node *node,
  62. acpi_object_type expected_type,
  63. union acpi_object **value);
  64. static acpi_status
  65. acpi_db_write_to_object(struct acpi_namespace_node *node,
  66. union acpi_object *value);
  67. static void acpi_db_evaluate_all_predefined_names(char *count_arg);
  68. static acpi_status
  69. acpi_db_evaluate_one_predefined_name(acpi_handle obj_handle,
  70. u32 nesting_level,
  71. void *context, void **return_value);
  72. /*
  73. * Test subcommands
  74. */
  75. static struct acpi_db_argument_info acpi_db_test_types[] = {
  76. {"OBJECTS"},
  77. {"PREDEFINED"},
  78. {NULL} /* Must be null terminated */
  79. };
  80. #define CMD_TEST_OBJECTS 0
  81. #define CMD_TEST_PREDEFINED 1
  82. #define BUFFER_FILL_VALUE 0xFF
  83. /*
  84. * Support for the special debugger read/write control methods.
  85. * These methods are installed into the current namespace and are
  86. * used to read and write the various namespace objects. The point
  87. * is to force the AML interpreter do all of the work.
  88. */
  89. #define ACPI_DB_READ_METHOD "\\_T98"
  90. #define ACPI_DB_WRITE_METHOD "\\_T99"
  91. static acpi_handle read_handle = NULL;
  92. static acpi_handle write_handle = NULL;
  93. /* ASL Definitions of the debugger read/write control methods */
  94. #if 0
  95. definition_block("ssdt.aml", "SSDT", 2, "Intel", "DEBUG", 0x00000001)
  96. {
  97. method(_T98, 1, not_serialized) { /* Read */
  98. return (de_ref_of(arg0))
  99. }
  100. }
  101. definition_block("ssdt2.aml", "SSDT", 2, "Intel", "DEBUG", 0x00000001)
  102. {
  103. method(_T99, 2, not_serialized) { /* Write */
  104. store(arg1, arg0)
  105. }
  106. }
  107. #endif
  108. static unsigned char read_method_code[] = {
  109. 0x53, 0x53, 0x44, 0x54, 0x2E, 0x00, 0x00, 0x00, /* 00000000 "SSDT...." */
  110. 0x02, 0xC9, 0x49, 0x6E, 0x74, 0x65, 0x6C, 0x00, /* 00000008 "..Intel." */
  111. 0x44, 0x45, 0x42, 0x55, 0x47, 0x00, 0x00, 0x00, /* 00000010 "DEBUG..." */
  112. 0x01, 0x00, 0x00, 0x00, 0x49, 0x4E, 0x54, 0x4C, /* 00000018 "....INTL" */
  113. 0x18, 0x12, 0x13, 0x20, 0x14, 0x09, 0x5F, 0x54, /* 00000020 "... .._T" */
  114. 0x39, 0x38, 0x01, 0xA4, 0x83, 0x68 /* 00000028 "98...h" */
  115. };
  116. static unsigned char write_method_code[] = {
  117. 0x53, 0x53, 0x44, 0x54, 0x2E, 0x00, 0x00, 0x00, /* 00000000 "SSDT...." */
  118. 0x02, 0x15, 0x49, 0x6E, 0x74, 0x65, 0x6C, 0x00, /* 00000008 "..Intel." */
  119. 0x44, 0x45, 0x42, 0x55, 0x47, 0x00, 0x00, 0x00, /* 00000010 "DEBUG..." */
  120. 0x01, 0x00, 0x00, 0x00, 0x49, 0x4E, 0x54, 0x4C, /* 00000018 "....INTL" */
  121. 0x18, 0x12, 0x13, 0x20, 0x14, 0x09, 0x5F, 0x54, /* 00000020 "... .._T" */
  122. 0x39, 0x39, 0x02, 0x70, 0x69, 0x68 /* 00000028 "99.pih" */
  123. };
  124. /*******************************************************************************
  125. *
  126. * FUNCTION: acpi_db_execute_test
  127. *
  128. * PARAMETERS: type_arg - Subcommand
  129. *
  130. * RETURN: None
  131. *
  132. * DESCRIPTION: Execute various debug tests.
  133. *
  134. * Note: Code is prepared for future expansion of the TEST command.
  135. *
  136. ******************************************************************************/
  137. void acpi_db_execute_test(char *type_arg)
  138. {
  139. u32 temp;
  140. acpi_ut_strupr(type_arg);
  141. temp = acpi_db_match_argument(type_arg, acpi_db_test_types);
  142. if (temp == ACPI_TYPE_NOT_FOUND) {
  143. acpi_os_printf("Invalid or unsupported argument\n");
  144. return;
  145. }
  146. switch (temp) {
  147. case CMD_TEST_OBJECTS:
  148. acpi_db_test_all_objects();
  149. break;
  150. case CMD_TEST_PREDEFINED:
  151. acpi_db_evaluate_all_predefined_names(NULL);
  152. break;
  153. default:
  154. break;
  155. }
  156. }
  157. /*******************************************************************************
  158. *
  159. * FUNCTION: acpi_db_test_all_objects
  160. *
  161. * PARAMETERS: None
  162. *
  163. * RETURN: None
  164. *
  165. * DESCRIPTION: This test implements the OBJECTS subcommand. It exercises the
  166. * namespace by reading/writing/comparing all data objects such
  167. * as integers, strings, buffers, fields, buffer fields, etc.
  168. *
  169. ******************************************************************************/
  170. static void acpi_db_test_all_objects(void)
  171. {
  172. acpi_status status;
  173. /* Install the debugger read-object control method if necessary */
  174. if (!read_handle) {
  175. status = acpi_install_method(read_method_code);
  176. if (ACPI_FAILURE(status)) {
  177. acpi_os_printf
  178. ("%s, Could not install debugger read method\n",
  179. acpi_format_exception(status));
  180. return;
  181. }
  182. status =
  183. acpi_get_handle(NULL, ACPI_DB_READ_METHOD, &read_handle);
  184. if (ACPI_FAILURE(status)) {
  185. acpi_os_printf
  186. ("Could not obtain handle for debug method %s\n",
  187. ACPI_DB_READ_METHOD);
  188. return;
  189. }
  190. }
  191. /* Install the debugger write-object control method if necessary */
  192. if (!write_handle) {
  193. status = acpi_install_method(write_method_code);
  194. if (ACPI_FAILURE(status)) {
  195. acpi_os_printf
  196. ("%s, Could not install debugger write method\n",
  197. acpi_format_exception(status));
  198. return;
  199. }
  200. status =
  201. acpi_get_handle(NULL, ACPI_DB_WRITE_METHOD, &write_handle);
  202. if (ACPI_FAILURE(status)) {
  203. acpi_os_printf
  204. ("Could not obtain handle for debug method %s\n",
  205. ACPI_DB_WRITE_METHOD);
  206. return;
  207. }
  208. }
  209. /* Walk the entire namespace, testing each supported named data object */
  210. (void)acpi_walk_namespace(ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
  211. ACPI_UINT32_MAX, acpi_db_test_one_object,
  212. NULL, NULL, NULL);
  213. }
  214. /*******************************************************************************
  215. *
  216. * FUNCTION: acpi_db_test_one_object
  217. *
  218. * PARAMETERS: acpi_walk_callback
  219. *
  220. * RETURN: Status
  221. *
  222. * DESCRIPTION: Test one namespace object. Supported types are Integer,
  223. * String, Buffer, buffer_field, and field_unit. All other object
  224. * types are simply ignored.
  225. *
  226. * Note: Support for Packages is not implemented.
  227. *
  228. ******************************************************************************/
  229. static acpi_status
  230. acpi_db_test_one_object(acpi_handle obj_handle,
  231. u32 nesting_level, void *context, void **return_value)
  232. {
  233. struct acpi_namespace_node *node;
  234. union acpi_operand_object *obj_desc;
  235. union acpi_operand_object *region_obj;
  236. acpi_object_type local_type;
  237. u32 bit_length = 0;
  238. u32 byte_length = 0;
  239. acpi_status status = AE_OK;
  240. node = ACPI_CAST_PTR(struct acpi_namespace_node, obj_handle);
  241. obj_desc = node->object;
  242. /*
  243. * For the supported types, get the actual bit length or
  244. * byte length. Map the type to one of Integer/String/Buffer.
  245. */
  246. switch (node->type) {
  247. case ACPI_TYPE_INTEGER:
  248. /* Integer width is either 32 or 64 */
  249. local_type = ACPI_TYPE_INTEGER;
  250. bit_length = acpi_gbl_integer_bit_width;
  251. break;
  252. case ACPI_TYPE_STRING:
  253. local_type = ACPI_TYPE_STRING;
  254. byte_length = obj_desc->string.length;
  255. break;
  256. case ACPI_TYPE_BUFFER:
  257. local_type = ACPI_TYPE_BUFFER;
  258. byte_length = obj_desc->buffer.length;
  259. bit_length = byte_length * 8;
  260. break;
  261. case ACPI_TYPE_FIELD_UNIT:
  262. case ACPI_TYPE_BUFFER_FIELD:
  263. case ACPI_TYPE_LOCAL_REGION_FIELD:
  264. case ACPI_TYPE_LOCAL_INDEX_FIELD:
  265. case ACPI_TYPE_LOCAL_BANK_FIELD:
  266. local_type = ACPI_TYPE_INTEGER;
  267. if (obj_desc) {
  268. /*
  269. * Returned object will be a Buffer if the field length
  270. * is larger than the size of an Integer (32 or 64 bits
  271. * depending on the DSDT version).
  272. */
  273. bit_length = obj_desc->common_field.bit_length;
  274. byte_length = ACPI_ROUND_BITS_UP_TO_BYTES(bit_length);
  275. if (bit_length > acpi_gbl_integer_bit_width) {
  276. local_type = ACPI_TYPE_BUFFER;
  277. }
  278. }
  279. break;
  280. default:
  281. /* Ignore all other types */
  282. return (AE_OK);
  283. }
  284. /* Emit the common prefix: Type:Name */
  285. acpi_os_printf("%14s: %4.4s",
  286. acpi_ut_get_type_name(node->type), node->name.ascii);
  287. if (!obj_desc) {
  288. acpi_os_printf(" Ignoring, no attached object\n");
  289. return (AE_OK);
  290. }
  291. /*
  292. * Check for unsupported region types. Note: acpi_exec simulates
  293. * access to system_memory, system_IO, PCI_Config, and EC.
  294. */
  295. switch (node->type) {
  296. case ACPI_TYPE_LOCAL_REGION_FIELD:
  297. region_obj = obj_desc->field.region_obj;
  298. switch (region_obj->region.space_id) {
  299. case ACPI_ADR_SPACE_SYSTEM_MEMORY:
  300. case ACPI_ADR_SPACE_SYSTEM_IO:
  301. case ACPI_ADR_SPACE_PCI_CONFIG:
  302. case ACPI_ADR_SPACE_EC:
  303. break;
  304. default:
  305. acpi_os_printf
  306. (" %s space is not supported [%4.4s]\n",
  307. acpi_ut_get_region_name(region_obj->region.
  308. space_id),
  309. region_obj->region.node->name.ascii);
  310. return (AE_OK);
  311. }
  312. break;
  313. default:
  314. break;
  315. }
  316. /* At this point, we have resolved the object to one of the major types */
  317. switch (local_type) {
  318. case ACPI_TYPE_INTEGER:
  319. status = acpi_db_test_integer_type(node, bit_length);
  320. break;
  321. case ACPI_TYPE_STRING:
  322. status = acpi_db_test_string_type(node, byte_length);
  323. break;
  324. case ACPI_TYPE_BUFFER:
  325. status = acpi_db_test_buffer_type(node, bit_length);
  326. break;
  327. default:
  328. acpi_os_printf(" Ignoring, type not implemented (%2.2X)",
  329. local_type);
  330. break;
  331. }
  332. switch (node->type) {
  333. case ACPI_TYPE_LOCAL_REGION_FIELD:
  334. region_obj = obj_desc->field.region_obj;
  335. acpi_os_printf(" (%s)",
  336. acpi_ut_get_region_name(region_obj->region.
  337. space_id));
  338. break;
  339. default:
  340. break;
  341. }
  342. acpi_os_printf("\n");
  343. return (status);
  344. }
  345. /*******************************************************************************
  346. *
  347. * FUNCTION: acpi_db_test_integer_type
  348. *
  349. * PARAMETERS: node - Parent NS node for the object
  350. * bit_length - Actual length of the object. Used for
  351. * support of arbitrary length field_unit
  352. * and buffer_field objects.
  353. *
  354. * RETURN: Status
  355. *
  356. * DESCRIPTION: Test read/write for an Integer-valued object. Performs a
  357. * write/read/compare of an arbitrary new value, then performs
  358. * a write/read/compare of the original value.
  359. *
  360. ******************************************************************************/
  361. static acpi_status
  362. acpi_db_test_integer_type(struct acpi_namespace_node *node, u32 bit_length)
  363. {
  364. union acpi_object *temp1 = NULL;
  365. union acpi_object *temp2 = NULL;
  366. union acpi_object *temp3 = NULL;
  367. union acpi_object write_value;
  368. u64 value_to_write;
  369. acpi_status status;
  370. if (bit_length > 64) {
  371. acpi_os_printf(" Invalid length for an Integer: %u",
  372. bit_length);
  373. return (AE_OK);
  374. }
  375. /* Read the original value */
  376. status = acpi_db_read_from_object(node, ACPI_TYPE_INTEGER, &temp1);
  377. if (ACPI_FAILURE(status)) {
  378. return (status);
  379. }
  380. acpi_os_printf(" (%4.4X/%3.3X) %8.8X%8.8X",
  381. bit_length, ACPI_ROUND_BITS_UP_TO_BYTES(bit_length),
  382. ACPI_FORMAT_UINT64(temp1->integer.value));
  383. value_to_write = ACPI_UINT64_MAX >> (64 - bit_length);
  384. if (temp1->integer.value == value_to_write) {
  385. value_to_write = 0;
  386. }
  387. /* Write a new value */
  388. write_value.type = ACPI_TYPE_INTEGER;
  389. write_value.integer.value = value_to_write;
  390. status = acpi_db_write_to_object(node, &write_value);
  391. if (ACPI_FAILURE(status)) {
  392. goto exit;
  393. }
  394. /* Ensure that we can read back the new value */
  395. status = acpi_db_read_from_object(node, ACPI_TYPE_INTEGER, &temp2);
  396. if (ACPI_FAILURE(status)) {
  397. goto exit;
  398. }
  399. if (temp2->integer.value != value_to_write) {
  400. acpi_os_printf(" MISMATCH 2: %8.8X%8.8X, expecting %8.8X%8.8X",
  401. ACPI_FORMAT_UINT64(temp2->integer.value),
  402. ACPI_FORMAT_UINT64(value_to_write));
  403. }
  404. /* Write back the original value */
  405. write_value.integer.value = temp1->integer.value;
  406. status = acpi_db_write_to_object(node, &write_value);
  407. if (ACPI_FAILURE(status)) {
  408. goto exit;
  409. }
  410. /* Ensure that we can read back the original value */
  411. status = acpi_db_read_from_object(node, ACPI_TYPE_INTEGER, &temp3);
  412. if (ACPI_FAILURE(status)) {
  413. goto exit;
  414. }
  415. if (temp3->integer.value != temp1->integer.value) {
  416. acpi_os_printf(" MISMATCH 3: %8.8X%8.8X, expecting %8.8X%8.8X",
  417. ACPI_FORMAT_UINT64(temp3->integer.value),
  418. ACPI_FORMAT_UINT64(temp1->integer.value));
  419. }
  420. exit:
  421. if (temp1) {
  422. acpi_os_free(temp1);
  423. }
  424. if (temp2) {
  425. acpi_os_free(temp2);
  426. }
  427. if (temp3) {
  428. acpi_os_free(temp3);
  429. }
  430. return (AE_OK);
  431. }
  432. /*******************************************************************************
  433. *
  434. * FUNCTION: acpi_db_test_buffer_type
  435. *
  436. * PARAMETERS: node - Parent NS node for the object
  437. * bit_length - Actual length of the object.
  438. *
  439. * RETURN: Status
  440. *
  441. * DESCRIPTION: Test read/write for an Buffer-valued object. Performs a
  442. * write/read/compare of an arbitrary new value, then performs
  443. * a write/read/compare of the original value.
  444. *
  445. ******************************************************************************/
  446. static acpi_status
  447. acpi_db_test_buffer_type(struct acpi_namespace_node *node, u32 bit_length)
  448. {
  449. union acpi_object *temp1 = NULL;
  450. union acpi_object *temp2 = NULL;
  451. union acpi_object *temp3 = NULL;
  452. u8 *buffer;
  453. union acpi_object write_value;
  454. acpi_status status;
  455. u32 byte_length;
  456. u32 i;
  457. u8 extra_bits;
  458. byte_length = ACPI_ROUND_BITS_UP_TO_BYTES(bit_length);
  459. if (byte_length == 0) {
  460. acpi_os_printf(" Ignoring zero length buffer");
  461. return (AE_OK);
  462. }
  463. /* Allocate a local buffer */
  464. buffer = ACPI_ALLOCATE_ZEROED(byte_length);
  465. if (!buffer) {
  466. return (AE_NO_MEMORY);
  467. }
  468. /* Read the original value */
  469. status = acpi_db_read_from_object(node, ACPI_TYPE_BUFFER, &temp1);
  470. if (ACPI_FAILURE(status)) {
  471. goto exit;
  472. }
  473. /* Emit a few bytes of the buffer */
  474. acpi_os_printf(" (%4.4X/%3.3X)", bit_length, temp1->buffer.length);
  475. for (i = 0; ((i < 4) && (i < byte_length)); i++) {
  476. acpi_os_printf(" %2.2X", temp1->buffer.pointer[i]);
  477. }
  478. acpi_os_printf("... ");
  479. /*
  480. * Write a new value.
  481. *
  482. * Handle possible extra bits at the end of the buffer. Can
  483. * happen for field_units larger than an integer, but the bit
  484. * count is not an integral number of bytes. Zero out the
  485. * unused bits.
  486. */
  487. memset(buffer, BUFFER_FILL_VALUE, byte_length);
  488. extra_bits = bit_length % 8;
  489. if (extra_bits) {
  490. buffer[byte_length - 1] = ACPI_MASK_BITS_ABOVE(extra_bits);
  491. }
  492. write_value.type = ACPI_TYPE_BUFFER;
  493. write_value.buffer.length = byte_length;
  494. write_value.buffer.pointer = buffer;
  495. status = acpi_db_write_to_object(node, &write_value);
  496. if (ACPI_FAILURE(status)) {
  497. goto exit;
  498. }
  499. /* Ensure that we can read back the new value */
  500. status = acpi_db_read_from_object(node, ACPI_TYPE_BUFFER, &temp2);
  501. if (ACPI_FAILURE(status)) {
  502. goto exit;
  503. }
  504. if (memcmp(temp2->buffer.pointer, buffer, byte_length)) {
  505. acpi_os_printf(" MISMATCH 2: New buffer value");
  506. }
  507. /* Write back the original value */
  508. write_value.buffer.length = byte_length;
  509. write_value.buffer.pointer = temp1->buffer.pointer;
  510. status = acpi_db_write_to_object(node, &write_value);
  511. if (ACPI_FAILURE(status)) {
  512. goto exit;
  513. }
  514. /* Ensure that we can read back the original value */
  515. status = acpi_db_read_from_object(node, ACPI_TYPE_BUFFER, &temp3);
  516. if (ACPI_FAILURE(status)) {
  517. goto exit;
  518. }
  519. if (memcmp(temp1->buffer.pointer, temp3->buffer.pointer, byte_length)) {
  520. acpi_os_printf(" MISMATCH 3: While restoring original buffer");
  521. }
  522. exit:
  523. ACPI_FREE(buffer);
  524. if (temp1) {
  525. acpi_os_free(temp1);
  526. }
  527. if (temp2) {
  528. acpi_os_free(temp2);
  529. }
  530. if (temp3) {
  531. acpi_os_free(temp3);
  532. }
  533. return (status);
  534. }
  535. /*******************************************************************************
  536. *
  537. * FUNCTION: acpi_db_test_string_type
  538. *
  539. * PARAMETERS: node - Parent NS node for the object
  540. * byte_length - Actual length of the object.
  541. *
  542. * RETURN: Status
  543. *
  544. * DESCRIPTION: Test read/write for an String-valued object. Performs a
  545. * write/read/compare of an arbitrary new value, then performs
  546. * a write/read/compare of the original value.
  547. *
  548. ******************************************************************************/
  549. static acpi_status
  550. acpi_db_test_string_type(struct acpi_namespace_node *node, u32 byte_length)
  551. {
  552. union acpi_object *temp1 = NULL;
  553. union acpi_object *temp2 = NULL;
  554. union acpi_object *temp3 = NULL;
  555. char *value_to_write = "Test String from AML Debugger";
  556. union acpi_object write_value;
  557. acpi_status status;
  558. /* Read the original value */
  559. status = acpi_db_read_from_object(node, ACPI_TYPE_STRING, &temp1);
  560. if (ACPI_FAILURE(status)) {
  561. return (status);
  562. }
  563. acpi_os_printf(" (%4.4X/%3.3X) \"%s\"", (temp1->string.length * 8),
  564. temp1->string.length, temp1->string.pointer);
  565. /* Write a new value */
  566. write_value.type = ACPI_TYPE_STRING;
  567. write_value.string.length = strlen(value_to_write);
  568. write_value.string.pointer = value_to_write;
  569. status = acpi_db_write_to_object(node, &write_value);
  570. if (ACPI_FAILURE(status)) {
  571. goto exit;
  572. }
  573. /* Ensure that we can read back the new value */
  574. status = acpi_db_read_from_object(node, ACPI_TYPE_STRING, &temp2);
  575. if (ACPI_FAILURE(status)) {
  576. goto exit;
  577. }
  578. if (strcmp(temp2->string.pointer, value_to_write)) {
  579. acpi_os_printf(" MISMATCH 2: %s, expecting %s",
  580. temp2->string.pointer, value_to_write);
  581. }
  582. /* Write back the original value */
  583. write_value.string.length = strlen(temp1->string.pointer);
  584. write_value.string.pointer = temp1->string.pointer;
  585. status = acpi_db_write_to_object(node, &write_value);
  586. if (ACPI_FAILURE(status)) {
  587. goto exit;
  588. }
  589. /* Ensure that we can read back the original value */
  590. status = acpi_db_read_from_object(node, ACPI_TYPE_STRING, &temp3);
  591. if (ACPI_FAILURE(status)) {
  592. goto exit;
  593. }
  594. if (strcmp(temp1->string.pointer, temp3->string.pointer)) {
  595. acpi_os_printf(" MISMATCH 3: %s, expecting %s",
  596. temp3->string.pointer, temp1->string.pointer);
  597. }
  598. exit:
  599. if (temp1) {
  600. acpi_os_free(temp1);
  601. }
  602. if (temp2) {
  603. acpi_os_free(temp2);
  604. }
  605. if (temp3) {
  606. acpi_os_free(temp3);
  607. }
  608. return (status);
  609. }
  610. /*******************************************************************************
  611. *
  612. * FUNCTION: acpi_db_read_from_object
  613. *
  614. * PARAMETERS: node - Parent NS node for the object
  615. * expected_type - Object type expected from the read
  616. * value - Where the value read is returned
  617. *
  618. * RETURN: Status
  619. *
  620. * DESCRIPTION: Performs a read from the specified object by invoking the
  621. * special debugger control method that reads the object. Thus,
  622. * the AML interpreter is doing all of the work, increasing the
  623. * validity of the test.
  624. *
  625. ******************************************************************************/
  626. static acpi_status
  627. acpi_db_read_from_object(struct acpi_namespace_node *node,
  628. acpi_object_type expected_type,
  629. union acpi_object **value)
  630. {
  631. union acpi_object *ret_value;
  632. struct acpi_object_list param_objects;
  633. union acpi_object params[2];
  634. struct acpi_buffer return_obj;
  635. acpi_status status;
  636. params[0].type = ACPI_TYPE_LOCAL_REFERENCE;
  637. params[0].reference.actual_type = node->type;
  638. params[0].reference.handle = ACPI_CAST_PTR(acpi_handle, node);
  639. param_objects.count = 1;
  640. param_objects.pointer = params;
  641. return_obj.length = ACPI_ALLOCATE_BUFFER;
  642. acpi_gbl_method_executing = TRUE;
  643. status = acpi_evaluate_object(read_handle, NULL,
  644. &param_objects, &return_obj);
  645. acpi_gbl_method_executing = FALSE;
  646. if (ACPI_FAILURE(status)) {
  647. acpi_os_printf("Could not read from object, %s",
  648. acpi_format_exception(status));
  649. return (status);
  650. }
  651. ret_value = (union acpi_object *)return_obj.pointer;
  652. switch (ret_value->type) {
  653. case ACPI_TYPE_INTEGER:
  654. case ACPI_TYPE_BUFFER:
  655. case ACPI_TYPE_STRING:
  656. /*
  657. * Did we receive the type we wanted? Most important for the
  658. * Integer/Buffer case (when a field is larger than an Integer,
  659. * it should return a Buffer).
  660. */
  661. if (ret_value->type != expected_type) {
  662. acpi_os_printf
  663. (" Type mismatch: Expected %s, Received %s",
  664. acpi_ut_get_type_name(expected_type),
  665. acpi_ut_get_type_name(ret_value->type));
  666. return (AE_TYPE);
  667. }
  668. *value = ret_value;
  669. break;
  670. default:
  671. acpi_os_printf(" Unsupported return object type, %s",
  672. acpi_ut_get_type_name(ret_value->type));
  673. acpi_os_free(return_obj.pointer);
  674. return (AE_TYPE);
  675. }
  676. return (status);
  677. }
  678. /*******************************************************************************
  679. *
  680. * FUNCTION: acpi_db_write_to_object
  681. *
  682. * PARAMETERS: node - Parent NS node for the object
  683. * value - Value to be written
  684. *
  685. * RETURN: Status
  686. *
  687. * DESCRIPTION: Performs a write to the specified object by invoking the
  688. * special debugger control method that writes the object. Thus,
  689. * the AML interpreter is doing all of the work, increasing the
  690. * validity of the test.
  691. *
  692. ******************************************************************************/
  693. static acpi_status
  694. acpi_db_write_to_object(struct acpi_namespace_node *node,
  695. union acpi_object *value)
  696. {
  697. struct acpi_object_list param_objects;
  698. union acpi_object params[2];
  699. acpi_status status;
  700. params[0].type = ACPI_TYPE_LOCAL_REFERENCE;
  701. params[0].reference.actual_type = node->type;
  702. params[0].reference.handle = ACPI_CAST_PTR(acpi_handle, node);
  703. /* Copy the incoming user parameter */
  704. memcpy(&params[1], value, sizeof(union acpi_object));
  705. param_objects.count = 2;
  706. param_objects.pointer = params;
  707. acpi_gbl_method_executing = TRUE;
  708. status = acpi_evaluate_object(write_handle, NULL, &param_objects, NULL);
  709. acpi_gbl_method_executing = FALSE;
  710. if (ACPI_FAILURE(status)) {
  711. acpi_os_printf("Could not write to object, %s",
  712. acpi_format_exception(status));
  713. }
  714. return (status);
  715. }
  716. /*******************************************************************************
  717. *
  718. * FUNCTION: acpi_db_evaluate_all_predefined_names
  719. *
  720. * PARAMETERS: count_arg - Max number of methods to execute
  721. *
  722. * RETURN: None
  723. *
  724. * DESCRIPTION: Namespace batch execution. Execute predefined names in the
  725. * namespace, up to the max count, if specified.
  726. *
  727. ******************************************************************************/
  728. static void acpi_db_evaluate_all_predefined_names(char *count_arg)
  729. {
  730. struct acpi_db_execute_walk info;
  731. info.count = 0;
  732. info.max_count = ACPI_UINT32_MAX;
  733. if (count_arg) {
  734. info.max_count = strtoul(count_arg, NULL, 0);
  735. }
  736. /* Search all nodes in namespace */
  737. (void)acpi_walk_namespace(ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
  738. ACPI_UINT32_MAX,
  739. acpi_db_evaluate_one_predefined_name, NULL,
  740. (void *)&info, NULL);
  741. acpi_os_printf("Evaluated %u predefined names in the namespace\n",
  742. info.count);
  743. }
  744. /*******************************************************************************
  745. *
  746. * FUNCTION: acpi_db_evaluate_one_predefined_name
  747. *
  748. * PARAMETERS: Callback from walk_namespace
  749. *
  750. * RETURN: Status
  751. *
  752. * DESCRIPTION: Batch execution module. Currently only executes predefined
  753. * ACPI names.
  754. *
  755. ******************************************************************************/
  756. static acpi_status
  757. acpi_db_evaluate_one_predefined_name(acpi_handle obj_handle,
  758. u32 nesting_level,
  759. void *context, void **return_value)
  760. {
  761. struct acpi_namespace_node *node =
  762. (struct acpi_namespace_node *)obj_handle;
  763. struct acpi_db_execute_walk *info =
  764. (struct acpi_db_execute_walk *)context;
  765. char *pathname;
  766. const union acpi_predefined_info *predefined;
  767. struct acpi_device_info *obj_info;
  768. struct acpi_object_list param_objects;
  769. union acpi_object params[ACPI_METHOD_NUM_ARGS];
  770. union acpi_object *this_param;
  771. struct acpi_buffer return_obj;
  772. acpi_status status;
  773. u16 arg_type_list;
  774. u8 arg_count;
  775. u8 arg_type;
  776. u32 i;
  777. /* The name must be a predefined ACPI name */
  778. predefined = acpi_ut_match_predefined_method(node->name.ascii);
  779. if (!predefined) {
  780. return (AE_OK);
  781. }
  782. if (node->type == ACPI_TYPE_LOCAL_SCOPE) {
  783. return (AE_OK);
  784. }
  785. pathname = acpi_ns_get_external_pathname(node);
  786. if (!pathname) {
  787. return (AE_OK);
  788. }
  789. /* Get the object info for number of method parameters */
  790. status = acpi_get_object_info(obj_handle, &obj_info);
  791. if (ACPI_FAILURE(status)) {
  792. ACPI_FREE(pathname);
  793. return (status);
  794. }
  795. param_objects.count = 0;
  796. param_objects.pointer = NULL;
  797. if (obj_info->type == ACPI_TYPE_METHOD) {
  798. /* Setup default parameters (with proper types) */
  799. arg_type_list = predefined->info.argument_list;
  800. arg_count = METHOD_GET_ARG_COUNT(arg_type_list);
  801. /*
  802. * Setup the ACPI-required number of arguments, regardless of what
  803. * the actual method defines. If there is a difference, then the
  804. * method is wrong and a warning will be issued during execution.
  805. */
  806. this_param = params;
  807. for (i = 0; i < arg_count; i++) {
  808. arg_type = METHOD_GET_NEXT_TYPE(arg_type_list);
  809. this_param->type = arg_type;
  810. switch (arg_type) {
  811. case ACPI_TYPE_INTEGER:
  812. this_param->integer.value = 1;
  813. break;
  814. case ACPI_TYPE_STRING:
  815. this_param->string.pointer =
  816. "This is the default argument string";
  817. this_param->string.length =
  818. strlen(this_param->string.pointer);
  819. break;
  820. case ACPI_TYPE_BUFFER:
  821. this_param->buffer.pointer = (u8 *)params; /* just a garbage buffer */
  822. this_param->buffer.length = 48;
  823. break;
  824. case ACPI_TYPE_PACKAGE:
  825. this_param->package.elements = NULL;
  826. this_param->package.count = 0;
  827. break;
  828. default:
  829. acpi_os_printf
  830. ("%s: Unsupported argument type: %u\n",
  831. pathname, arg_type);
  832. break;
  833. }
  834. this_param++;
  835. }
  836. param_objects.count = arg_count;
  837. param_objects.pointer = params;
  838. }
  839. ACPI_FREE(obj_info);
  840. return_obj.pointer = NULL;
  841. return_obj.length = ACPI_ALLOCATE_BUFFER;
  842. /* Do the actual method execution */
  843. acpi_gbl_method_executing = TRUE;
  844. status = acpi_evaluate_object(node, NULL, &param_objects, &return_obj);
  845. acpi_os_printf("%-32s returned %s\n",
  846. pathname, acpi_format_exception(status));
  847. acpi_gbl_method_executing = FALSE;
  848. ACPI_FREE(pathname);
  849. /* Ignore status from method execution */
  850. status = AE_OK;
  851. /* Update count, check if we have executed enough methods */
  852. info->count++;
  853. if (info->count >= info->max_count) {
  854. status = AE_CTRL_TERMINATE;
  855. }
  856. return (status);
  857. }