dbtest.c 26 KB

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