dsopcode.c 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473
  1. /******************************************************************************
  2. *
  3. * Module Name: dsopcode - Dispatcher Op Region support and handling of
  4. * "control" opcodes
  5. *
  6. *****************************************************************************/
  7. /*
  8. * Copyright (C) 2000 - 2010, Intel Corp.
  9. * All rights reserved.
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions
  13. * are met:
  14. * 1. Redistributions of source code must retain the above copyright
  15. * notice, this list of conditions, and the following disclaimer,
  16. * without modification.
  17. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  18. * substantially similar to the "NO WARRANTY" disclaimer below
  19. * ("Disclaimer") and any redistribution must be conditioned upon
  20. * including a substantially similar Disclaimer requirement for further
  21. * binary redistribution.
  22. * 3. Neither the names of the above-listed copyright holders nor the names
  23. * of any contributors may be used to endorse or promote products derived
  24. * from this software without specific prior written permission.
  25. *
  26. * Alternatively, this software may be distributed under the terms of the
  27. * GNU General Public License ("GPL") version 2 as published by the Free
  28. * Software Foundation.
  29. *
  30. * NO WARRANTY
  31. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  32. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  33. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  34. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  35. * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  36. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  37. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  38. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  39. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  40. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  41. * POSSIBILITY OF SUCH DAMAGES.
  42. */
  43. #include <acpi/acpi.h>
  44. #include "accommon.h"
  45. #include "acparser.h"
  46. #include "amlcode.h"
  47. #include "acdispat.h"
  48. #include "acinterp.h"
  49. #include "acnamesp.h"
  50. #include "acevents.h"
  51. #include "actables.h"
  52. #define _COMPONENT ACPI_DISPATCHER
  53. ACPI_MODULE_NAME("dsopcode")
  54. /* Local prototypes */
  55. static acpi_status
  56. acpi_ds_execute_arguments(struct acpi_namespace_node *node,
  57. struct acpi_namespace_node *scope_node,
  58. u32 aml_length, u8 * aml_start);
  59. static acpi_status
  60. acpi_ds_init_buffer_field(u16 aml_opcode,
  61. union acpi_operand_object *obj_desc,
  62. union acpi_operand_object *buffer_desc,
  63. union acpi_operand_object *offset_desc,
  64. union acpi_operand_object *length_desc,
  65. union acpi_operand_object *result_desc);
  66. /*******************************************************************************
  67. *
  68. * FUNCTION: acpi_ds_execute_arguments
  69. *
  70. * PARAMETERS: Node - Object NS node
  71. * scope_node - Parent NS node
  72. * aml_length - Length of executable AML
  73. * aml_start - Pointer to the AML
  74. *
  75. * RETURN: Status.
  76. *
  77. * DESCRIPTION: Late (deferred) execution of region or field arguments
  78. *
  79. ******************************************************************************/
  80. static acpi_status
  81. acpi_ds_execute_arguments(struct acpi_namespace_node *node,
  82. struct acpi_namespace_node *scope_node,
  83. u32 aml_length, u8 * aml_start)
  84. {
  85. acpi_status status;
  86. union acpi_parse_object *op;
  87. struct acpi_walk_state *walk_state;
  88. ACPI_FUNCTION_TRACE(ds_execute_arguments);
  89. /*
  90. * Allocate a new parser op to be the root of the parsed tree
  91. */
  92. op = acpi_ps_alloc_op(AML_INT_EVAL_SUBTREE_OP);
  93. if (!op) {
  94. return_ACPI_STATUS(AE_NO_MEMORY);
  95. }
  96. /* Save the Node for use in acpi_ps_parse_aml */
  97. op->common.node = scope_node;
  98. /* Create and initialize a new parser state */
  99. walk_state = acpi_ds_create_walk_state(0, NULL, NULL, NULL);
  100. if (!walk_state) {
  101. status = AE_NO_MEMORY;
  102. goto cleanup;
  103. }
  104. status = acpi_ds_init_aml_walk(walk_state, op, NULL, aml_start,
  105. aml_length, NULL, ACPI_IMODE_LOAD_PASS1);
  106. if (ACPI_FAILURE(status)) {
  107. acpi_ds_delete_walk_state(walk_state);
  108. goto cleanup;
  109. }
  110. /* Mark this parse as a deferred opcode */
  111. walk_state->parse_flags = ACPI_PARSE_DEFERRED_OP;
  112. walk_state->deferred_node = node;
  113. /* Pass1: Parse the entire declaration */
  114. status = acpi_ps_parse_aml(walk_state);
  115. if (ACPI_FAILURE(status)) {
  116. goto cleanup;
  117. }
  118. /* Get and init the Op created above */
  119. op->common.node = node;
  120. acpi_ps_delete_parse_tree(op);
  121. /* Evaluate the deferred arguments */
  122. op = acpi_ps_alloc_op(AML_INT_EVAL_SUBTREE_OP);
  123. if (!op) {
  124. return_ACPI_STATUS(AE_NO_MEMORY);
  125. }
  126. op->common.node = scope_node;
  127. /* Create and initialize a new parser state */
  128. walk_state = acpi_ds_create_walk_state(0, NULL, NULL, NULL);
  129. if (!walk_state) {
  130. status = AE_NO_MEMORY;
  131. goto cleanup;
  132. }
  133. /* Execute the opcode and arguments */
  134. status = acpi_ds_init_aml_walk(walk_state, op, NULL, aml_start,
  135. aml_length, NULL, ACPI_IMODE_EXECUTE);
  136. if (ACPI_FAILURE(status)) {
  137. acpi_ds_delete_walk_state(walk_state);
  138. goto cleanup;
  139. }
  140. /* Mark this execution as a deferred opcode */
  141. walk_state->deferred_node = node;
  142. status = acpi_ps_parse_aml(walk_state);
  143. cleanup:
  144. acpi_ps_delete_parse_tree(op);
  145. return_ACPI_STATUS(status);
  146. }
  147. /*******************************************************************************
  148. *
  149. * FUNCTION: acpi_ds_get_buffer_field_arguments
  150. *
  151. * PARAMETERS: obj_desc - A valid buffer_field object
  152. *
  153. * RETURN: Status.
  154. *
  155. * DESCRIPTION: Get buffer_field Buffer and Index. This implements the late
  156. * evaluation of these field attributes.
  157. *
  158. ******************************************************************************/
  159. acpi_status
  160. acpi_ds_get_buffer_field_arguments(union acpi_operand_object *obj_desc)
  161. {
  162. union acpi_operand_object *extra_desc;
  163. struct acpi_namespace_node *node;
  164. acpi_status status;
  165. ACPI_FUNCTION_TRACE_PTR(ds_get_buffer_field_arguments, obj_desc);
  166. if (obj_desc->common.flags & AOPOBJ_DATA_VALID) {
  167. return_ACPI_STATUS(AE_OK);
  168. }
  169. /* Get the AML pointer (method object) and buffer_field node */
  170. extra_desc = acpi_ns_get_secondary_object(obj_desc);
  171. node = obj_desc->buffer_field.node;
  172. ACPI_DEBUG_EXEC(acpi_ut_display_init_pathname
  173. (ACPI_TYPE_BUFFER_FIELD, node, NULL));
  174. ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "[%4.4s] BufferField Arg Init\n",
  175. acpi_ut_get_node_name(node)));
  176. /* Execute the AML code for the term_arg arguments */
  177. status = acpi_ds_execute_arguments(node, node->parent,
  178. extra_desc->extra.aml_length,
  179. extra_desc->extra.aml_start);
  180. return_ACPI_STATUS(status);
  181. }
  182. /*******************************************************************************
  183. *
  184. * FUNCTION: acpi_ds_get_bank_field_arguments
  185. *
  186. * PARAMETERS: obj_desc - A valid bank_field object
  187. *
  188. * RETURN: Status.
  189. *
  190. * DESCRIPTION: Get bank_field bank_value. This implements the late
  191. * evaluation of these field attributes.
  192. *
  193. ******************************************************************************/
  194. acpi_status
  195. acpi_ds_get_bank_field_arguments(union acpi_operand_object *obj_desc)
  196. {
  197. union acpi_operand_object *extra_desc;
  198. struct acpi_namespace_node *node;
  199. acpi_status status;
  200. ACPI_FUNCTION_TRACE_PTR(ds_get_bank_field_arguments, obj_desc);
  201. if (obj_desc->common.flags & AOPOBJ_DATA_VALID) {
  202. return_ACPI_STATUS(AE_OK);
  203. }
  204. /* Get the AML pointer (method object) and bank_field node */
  205. extra_desc = acpi_ns_get_secondary_object(obj_desc);
  206. node = obj_desc->bank_field.node;
  207. ACPI_DEBUG_EXEC(acpi_ut_display_init_pathname
  208. (ACPI_TYPE_LOCAL_BANK_FIELD, node, NULL));
  209. ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "[%4.4s] BankField Arg Init\n",
  210. acpi_ut_get_node_name(node)));
  211. /* Execute the AML code for the term_arg arguments */
  212. status = acpi_ds_execute_arguments(node, node->parent,
  213. extra_desc->extra.aml_length,
  214. extra_desc->extra.aml_start);
  215. return_ACPI_STATUS(status);
  216. }
  217. /*******************************************************************************
  218. *
  219. * FUNCTION: acpi_ds_get_buffer_arguments
  220. *
  221. * PARAMETERS: obj_desc - A valid Buffer object
  222. *
  223. * RETURN: Status.
  224. *
  225. * DESCRIPTION: Get Buffer length and initializer byte list. This implements
  226. * the late evaluation of these attributes.
  227. *
  228. ******************************************************************************/
  229. acpi_status acpi_ds_get_buffer_arguments(union acpi_operand_object *obj_desc)
  230. {
  231. struct acpi_namespace_node *node;
  232. acpi_status status;
  233. ACPI_FUNCTION_TRACE_PTR(ds_get_buffer_arguments, obj_desc);
  234. if (obj_desc->common.flags & AOPOBJ_DATA_VALID) {
  235. return_ACPI_STATUS(AE_OK);
  236. }
  237. /* Get the Buffer node */
  238. node = obj_desc->buffer.node;
  239. if (!node) {
  240. ACPI_ERROR((AE_INFO,
  241. "No pointer back to namespace node in buffer object %p",
  242. obj_desc));
  243. return_ACPI_STATUS(AE_AML_INTERNAL);
  244. }
  245. ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Buffer Arg Init\n"));
  246. /* Execute the AML code for the term_arg arguments */
  247. status = acpi_ds_execute_arguments(node, node,
  248. obj_desc->buffer.aml_length,
  249. obj_desc->buffer.aml_start);
  250. return_ACPI_STATUS(status);
  251. }
  252. /*******************************************************************************
  253. *
  254. * FUNCTION: acpi_ds_get_package_arguments
  255. *
  256. * PARAMETERS: obj_desc - A valid Package object
  257. *
  258. * RETURN: Status.
  259. *
  260. * DESCRIPTION: Get Package length and initializer byte list. This implements
  261. * the late evaluation of these attributes.
  262. *
  263. ******************************************************************************/
  264. acpi_status acpi_ds_get_package_arguments(union acpi_operand_object *obj_desc)
  265. {
  266. struct acpi_namespace_node *node;
  267. acpi_status status;
  268. ACPI_FUNCTION_TRACE_PTR(ds_get_package_arguments, obj_desc);
  269. if (obj_desc->common.flags & AOPOBJ_DATA_VALID) {
  270. return_ACPI_STATUS(AE_OK);
  271. }
  272. /* Get the Package node */
  273. node = obj_desc->package.node;
  274. if (!node) {
  275. ACPI_ERROR((AE_INFO,
  276. "No pointer back to namespace node in package %p",
  277. obj_desc));
  278. return_ACPI_STATUS(AE_AML_INTERNAL);
  279. }
  280. ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Package Arg Init\n"));
  281. /* Execute the AML code for the term_arg arguments */
  282. status = acpi_ds_execute_arguments(node, node,
  283. obj_desc->package.aml_length,
  284. obj_desc->package.aml_start);
  285. return_ACPI_STATUS(status);
  286. }
  287. /*****************************************************************************
  288. *
  289. * FUNCTION: acpi_ds_get_region_arguments
  290. *
  291. * PARAMETERS: obj_desc - A valid region object
  292. *
  293. * RETURN: Status.
  294. *
  295. * DESCRIPTION: Get region address and length. This implements the late
  296. * evaluation of these region attributes.
  297. *
  298. ****************************************************************************/
  299. acpi_status acpi_ds_get_region_arguments(union acpi_operand_object *obj_desc)
  300. {
  301. struct acpi_namespace_node *node;
  302. acpi_status status;
  303. union acpi_operand_object *extra_desc;
  304. ACPI_FUNCTION_TRACE_PTR(ds_get_region_arguments, obj_desc);
  305. if (obj_desc->region.flags & AOPOBJ_DATA_VALID) {
  306. return_ACPI_STATUS(AE_OK);
  307. }
  308. extra_desc = acpi_ns_get_secondary_object(obj_desc);
  309. if (!extra_desc) {
  310. return_ACPI_STATUS(AE_NOT_EXIST);
  311. }
  312. /* Get the Region node */
  313. node = obj_desc->region.node;
  314. ACPI_DEBUG_EXEC(acpi_ut_display_init_pathname
  315. (ACPI_TYPE_REGION, node, NULL));
  316. ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "[%4.4s] OpRegion Arg Init at AML %p\n",
  317. acpi_ut_get_node_name(node),
  318. extra_desc->extra.aml_start));
  319. /* Execute the argument AML */
  320. status = acpi_ds_execute_arguments(node, node->parent,
  321. extra_desc->extra.aml_length,
  322. extra_desc->extra.aml_start);
  323. if (ACPI_FAILURE(status)) {
  324. return_ACPI_STATUS(status);
  325. }
  326. /* Validate the region address/length via the host OS */
  327. status = acpi_os_validate_address(obj_desc->region.space_id,
  328. obj_desc->region.address,
  329. (acpi_size) obj_desc->region.length,
  330. acpi_ut_get_node_name(node));
  331. if (ACPI_FAILURE(status)) {
  332. /*
  333. * Invalid address/length. We will emit an error message and mark
  334. * the region as invalid, so that it will cause an additional error if
  335. * it is ever used. Then return AE_OK.
  336. */
  337. ACPI_EXCEPTION((AE_INFO, status,
  338. "During address validation of OpRegion [%4.4s]",
  339. node->name.ascii));
  340. obj_desc->common.flags |= AOPOBJ_INVALID;
  341. status = AE_OK;
  342. }
  343. return_ACPI_STATUS(status);
  344. }
  345. /*******************************************************************************
  346. *
  347. * FUNCTION: acpi_ds_initialize_region
  348. *
  349. * PARAMETERS: obj_handle - Region namespace node
  350. *
  351. * RETURN: Status
  352. *
  353. * DESCRIPTION: Front end to ev_initialize_region
  354. *
  355. ******************************************************************************/
  356. acpi_status acpi_ds_initialize_region(acpi_handle obj_handle)
  357. {
  358. union acpi_operand_object *obj_desc;
  359. acpi_status status;
  360. obj_desc = acpi_ns_get_attached_object(obj_handle);
  361. /* Namespace is NOT locked */
  362. status = acpi_ev_initialize_region(obj_desc, FALSE);
  363. return (status);
  364. }
  365. /*******************************************************************************
  366. *
  367. * FUNCTION: acpi_ds_init_buffer_field
  368. *
  369. * PARAMETERS: aml_opcode - create_xxx_field
  370. * obj_desc - buffer_field object
  371. * buffer_desc - Host Buffer
  372. * offset_desc - Offset into buffer
  373. * length_desc - Length of field (CREATE_FIELD_OP only)
  374. * result_desc - Where to store the result
  375. *
  376. * RETURN: Status
  377. *
  378. * DESCRIPTION: Perform actual initialization of a buffer field
  379. *
  380. ******************************************************************************/
  381. static acpi_status
  382. acpi_ds_init_buffer_field(u16 aml_opcode,
  383. union acpi_operand_object *obj_desc,
  384. union acpi_operand_object *buffer_desc,
  385. union acpi_operand_object *offset_desc,
  386. union acpi_operand_object *length_desc,
  387. union acpi_operand_object *result_desc)
  388. {
  389. u32 offset;
  390. u32 bit_offset;
  391. u32 bit_count;
  392. u8 field_flags;
  393. acpi_status status;
  394. ACPI_FUNCTION_TRACE_PTR(ds_init_buffer_field, obj_desc);
  395. /* Host object must be a Buffer */
  396. if (buffer_desc->common.type != ACPI_TYPE_BUFFER) {
  397. ACPI_ERROR((AE_INFO,
  398. "Target of Create Field is not a Buffer object - %s",
  399. acpi_ut_get_object_type_name(buffer_desc)));
  400. status = AE_AML_OPERAND_TYPE;
  401. goto cleanup;
  402. }
  403. /*
  404. * The last parameter to all of these opcodes (result_desc) started
  405. * out as a name_string, and should therefore now be a NS node
  406. * after resolution in acpi_ex_resolve_operands().
  407. */
  408. if (ACPI_GET_DESCRIPTOR_TYPE(result_desc) != ACPI_DESC_TYPE_NAMED) {
  409. ACPI_ERROR((AE_INFO,
  410. "(%s) destination not a NS Node [%s]",
  411. acpi_ps_get_opcode_name(aml_opcode),
  412. acpi_ut_get_descriptor_name(result_desc)));
  413. status = AE_AML_OPERAND_TYPE;
  414. goto cleanup;
  415. }
  416. offset = (u32) offset_desc->integer.value;
  417. /*
  418. * Setup the Bit offsets and counts, according to the opcode
  419. */
  420. switch (aml_opcode) {
  421. case AML_CREATE_FIELD_OP:
  422. /* Offset is in bits, count is in bits */
  423. field_flags = AML_FIELD_ACCESS_BYTE;
  424. bit_offset = offset;
  425. bit_count = (u32) length_desc->integer.value;
  426. /* Must have a valid (>0) bit count */
  427. if (bit_count == 0) {
  428. ACPI_ERROR((AE_INFO,
  429. "Attempt to CreateField of length zero"));
  430. status = AE_AML_OPERAND_VALUE;
  431. goto cleanup;
  432. }
  433. break;
  434. case AML_CREATE_BIT_FIELD_OP:
  435. /* Offset is in bits, Field is one bit */
  436. bit_offset = offset;
  437. bit_count = 1;
  438. field_flags = AML_FIELD_ACCESS_BYTE;
  439. break;
  440. case AML_CREATE_BYTE_FIELD_OP:
  441. /* Offset is in bytes, field is one byte */
  442. bit_offset = 8 * offset;
  443. bit_count = 8;
  444. field_flags = AML_FIELD_ACCESS_BYTE;
  445. break;
  446. case AML_CREATE_WORD_FIELD_OP:
  447. /* Offset is in bytes, field is one word */
  448. bit_offset = 8 * offset;
  449. bit_count = 16;
  450. field_flags = AML_FIELD_ACCESS_WORD;
  451. break;
  452. case AML_CREATE_DWORD_FIELD_OP:
  453. /* Offset is in bytes, field is one dword */
  454. bit_offset = 8 * offset;
  455. bit_count = 32;
  456. field_flags = AML_FIELD_ACCESS_DWORD;
  457. break;
  458. case AML_CREATE_QWORD_FIELD_OP:
  459. /* Offset is in bytes, field is one qword */
  460. bit_offset = 8 * offset;
  461. bit_count = 64;
  462. field_flags = AML_FIELD_ACCESS_QWORD;
  463. break;
  464. default:
  465. ACPI_ERROR((AE_INFO,
  466. "Unknown field creation opcode 0x%02X",
  467. aml_opcode));
  468. status = AE_AML_BAD_OPCODE;
  469. goto cleanup;
  470. }
  471. /* Entire field must fit within the current length of the buffer */
  472. if ((bit_offset + bit_count) > (8 * (u32) buffer_desc->buffer.length)) {
  473. ACPI_ERROR((AE_INFO,
  474. "Field [%4.4s] at %u exceeds Buffer [%4.4s] size %u (bits)",
  475. acpi_ut_get_node_name(result_desc),
  476. bit_offset + bit_count,
  477. acpi_ut_get_node_name(buffer_desc->buffer.node),
  478. 8 * (u32) buffer_desc->buffer.length));
  479. status = AE_AML_BUFFER_LIMIT;
  480. goto cleanup;
  481. }
  482. /*
  483. * Initialize areas of the field object that are common to all fields
  484. * For field_flags, use LOCK_RULE = 0 (NO_LOCK),
  485. * UPDATE_RULE = 0 (UPDATE_PRESERVE)
  486. */
  487. status = acpi_ex_prep_common_field_object(obj_desc, field_flags, 0,
  488. bit_offset, bit_count);
  489. if (ACPI_FAILURE(status)) {
  490. goto cleanup;
  491. }
  492. obj_desc->buffer_field.buffer_obj = buffer_desc;
  493. /* Reference count for buffer_desc inherits obj_desc count */
  494. buffer_desc->common.reference_count = (u16)
  495. (buffer_desc->common.reference_count +
  496. obj_desc->common.reference_count);
  497. cleanup:
  498. /* Always delete the operands */
  499. acpi_ut_remove_reference(offset_desc);
  500. acpi_ut_remove_reference(buffer_desc);
  501. if (aml_opcode == AML_CREATE_FIELD_OP) {
  502. acpi_ut_remove_reference(length_desc);
  503. }
  504. /* On failure, delete the result descriptor */
  505. if (ACPI_FAILURE(status)) {
  506. acpi_ut_remove_reference(result_desc); /* Result descriptor */
  507. } else {
  508. /* Now the address and length are valid for this buffer_field */
  509. obj_desc->buffer_field.flags |= AOPOBJ_DATA_VALID;
  510. }
  511. return_ACPI_STATUS(status);
  512. }
  513. /*******************************************************************************
  514. *
  515. * FUNCTION: acpi_ds_eval_buffer_field_operands
  516. *
  517. * PARAMETERS: walk_state - Current walk
  518. * Op - A valid buffer_field Op object
  519. *
  520. * RETURN: Status
  521. *
  522. * DESCRIPTION: Get buffer_field Buffer and Index
  523. * Called from acpi_ds_exec_end_op during buffer_field parse tree walk
  524. *
  525. ******************************************************************************/
  526. acpi_status
  527. acpi_ds_eval_buffer_field_operands(struct acpi_walk_state *walk_state,
  528. union acpi_parse_object *op)
  529. {
  530. acpi_status status;
  531. union acpi_operand_object *obj_desc;
  532. struct acpi_namespace_node *node;
  533. union acpi_parse_object *next_op;
  534. ACPI_FUNCTION_TRACE_PTR(ds_eval_buffer_field_operands, op);
  535. /*
  536. * This is where we evaluate the address and length fields of the
  537. * create_xxx_field declaration
  538. */
  539. node = op->common.node;
  540. /* next_op points to the op that holds the Buffer */
  541. next_op = op->common.value.arg;
  542. /* Evaluate/create the address and length operands */
  543. status = acpi_ds_create_operands(walk_state, next_op);
  544. if (ACPI_FAILURE(status)) {
  545. return_ACPI_STATUS(status);
  546. }
  547. obj_desc = acpi_ns_get_attached_object(node);
  548. if (!obj_desc) {
  549. return_ACPI_STATUS(AE_NOT_EXIST);
  550. }
  551. /* Resolve the operands */
  552. status = acpi_ex_resolve_operands(op->common.aml_opcode,
  553. ACPI_WALK_OPERANDS, walk_state);
  554. if (ACPI_FAILURE(status)) {
  555. ACPI_ERROR((AE_INFO, "(%s) bad operand(s), status 0x%X",
  556. acpi_ps_get_opcode_name(op->common.aml_opcode),
  557. status));
  558. return_ACPI_STATUS(status);
  559. }
  560. /* Initialize the Buffer Field */
  561. if (op->common.aml_opcode == AML_CREATE_FIELD_OP) {
  562. /* NOTE: Slightly different operands for this opcode */
  563. status =
  564. acpi_ds_init_buffer_field(op->common.aml_opcode, obj_desc,
  565. walk_state->operands[0],
  566. walk_state->operands[1],
  567. walk_state->operands[2],
  568. walk_state->operands[3]);
  569. } else {
  570. /* All other, create_xxx_field opcodes */
  571. status =
  572. acpi_ds_init_buffer_field(op->common.aml_opcode, obj_desc,
  573. walk_state->operands[0],
  574. walk_state->operands[1], NULL,
  575. walk_state->operands[2]);
  576. }
  577. return_ACPI_STATUS(status);
  578. }
  579. /*******************************************************************************
  580. *
  581. * FUNCTION: acpi_ds_eval_region_operands
  582. *
  583. * PARAMETERS: walk_state - Current walk
  584. * Op - A valid region Op object
  585. *
  586. * RETURN: Status
  587. *
  588. * DESCRIPTION: Get region address and length
  589. * Called from acpi_ds_exec_end_op during op_region parse tree walk
  590. *
  591. ******************************************************************************/
  592. acpi_status
  593. acpi_ds_eval_region_operands(struct acpi_walk_state *walk_state,
  594. union acpi_parse_object *op)
  595. {
  596. acpi_status status;
  597. union acpi_operand_object *obj_desc;
  598. union acpi_operand_object *operand_desc;
  599. struct acpi_namespace_node *node;
  600. union acpi_parse_object *next_op;
  601. ACPI_FUNCTION_TRACE_PTR(ds_eval_region_operands, op);
  602. /*
  603. * This is where we evaluate the address and length fields of the
  604. * op_region declaration
  605. */
  606. node = op->common.node;
  607. /* next_op points to the op that holds the space_iD */
  608. next_op = op->common.value.arg;
  609. /* next_op points to address op */
  610. next_op = next_op->common.next;
  611. /* Evaluate/create the address and length operands */
  612. status = acpi_ds_create_operands(walk_state, next_op);
  613. if (ACPI_FAILURE(status)) {
  614. return_ACPI_STATUS(status);
  615. }
  616. /* Resolve the length and address operands to numbers */
  617. status = acpi_ex_resolve_operands(op->common.aml_opcode,
  618. ACPI_WALK_OPERANDS, walk_state);
  619. if (ACPI_FAILURE(status)) {
  620. return_ACPI_STATUS(status);
  621. }
  622. obj_desc = acpi_ns_get_attached_object(node);
  623. if (!obj_desc) {
  624. return_ACPI_STATUS(AE_NOT_EXIST);
  625. }
  626. /*
  627. * Get the length operand and save it
  628. * (at Top of stack)
  629. */
  630. operand_desc = walk_state->operands[walk_state->num_operands - 1];
  631. obj_desc->region.length = (u32) operand_desc->integer.value;
  632. acpi_ut_remove_reference(operand_desc);
  633. /*
  634. * Get the address and save it
  635. * (at top of stack - 1)
  636. */
  637. operand_desc = walk_state->operands[walk_state->num_operands - 2];
  638. obj_desc->region.address = (acpi_physical_address)
  639. operand_desc->integer.value;
  640. acpi_ut_remove_reference(operand_desc);
  641. ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "RgnObj %p Addr %8.8X%8.8X Len %X\n",
  642. obj_desc,
  643. ACPI_FORMAT_NATIVE_UINT(obj_desc->region.address),
  644. obj_desc->region.length));
  645. /* Now the address and length are valid for this opregion */
  646. obj_desc->region.flags |= AOPOBJ_DATA_VALID;
  647. return_ACPI_STATUS(status);
  648. }
  649. /*******************************************************************************
  650. *
  651. * FUNCTION: acpi_ds_eval_table_region_operands
  652. *
  653. * PARAMETERS: walk_state - Current walk
  654. * Op - A valid region Op object
  655. *
  656. * RETURN: Status
  657. *
  658. * DESCRIPTION: Get region address and length
  659. * Called from acpi_ds_exec_end_op during data_table_region parse tree walk
  660. *
  661. ******************************************************************************/
  662. acpi_status
  663. acpi_ds_eval_table_region_operands(struct acpi_walk_state *walk_state,
  664. union acpi_parse_object *op)
  665. {
  666. acpi_status status;
  667. union acpi_operand_object *obj_desc;
  668. union acpi_operand_object **operand;
  669. struct acpi_namespace_node *node;
  670. union acpi_parse_object *next_op;
  671. u32 table_index;
  672. struct acpi_table_header *table;
  673. ACPI_FUNCTION_TRACE_PTR(ds_eval_table_region_operands, op);
  674. /*
  675. * This is where we evaluate the signature_string and oem_iDString
  676. * and oem_table_iDString of the data_table_region declaration
  677. */
  678. node = op->common.node;
  679. /* next_op points to signature_string op */
  680. next_op = op->common.value.arg;
  681. /*
  682. * Evaluate/create the signature_string and oem_iDString
  683. * and oem_table_iDString operands
  684. */
  685. status = acpi_ds_create_operands(walk_state, next_op);
  686. if (ACPI_FAILURE(status)) {
  687. return_ACPI_STATUS(status);
  688. }
  689. /*
  690. * Resolve the signature_string and oem_iDString
  691. * and oem_table_iDString operands
  692. */
  693. status = acpi_ex_resolve_operands(op->common.aml_opcode,
  694. ACPI_WALK_OPERANDS, walk_state);
  695. if (ACPI_FAILURE(status)) {
  696. return_ACPI_STATUS(status);
  697. }
  698. operand = &walk_state->operands[0];
  699. /* Find the ACPI table */
  700. status = acpi_tb_find_table(operand[0]->string.pointer,
  701. operand[1]->string.pointer,
  702. operand[2]->string.pointer, &table_index);
  703. if (ACPI_FAILURE(status)) {
  704. return_ACPI_STATUS(status);
  705. }
  706. acpi_ut_remove_reference(operand[0]);
  707. acpi_ut_remove_reference(operand[1]);
  708. acpi_ut_remove_reference(operand[2]);
  709. status = acpi_get_table_by_index(table_index, &table);
  710. if (ACPI_FAILURE(status)) {
  711. return_ACPI_STATUS(status);
  712. }
  713. obj_desc = acpi_ns_get_attached_object(node);
  714. if (!obj_desc) {
  715. return_ACPI_STATUS(AE_NOT_EXIST);
  716. }
  717. obj_desc->region.address =
  718. (acpi_physical_address) ACPI_TO_INTEGER(table);
  719. obj_desc->region.length = table->length;
  720. ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "RgnObj %p Addr %8.8X%8.8X Len %X\n",
  721. obj_desc,
  722. ACPI_FORMAT_NATIVE_UINT(obj_desc->region.address),
  723. obj_desc->region.length));
  724. /* Now the address and length are valid for this opregion */
  725. obj_desc->region.flags |= AOPOBJ_DATA_VALID;
  726. return_ACPI_STATUS(status);
  727. }
  728. /*******************************************************************************
  729. *
  730. * FUNCTION: acpi_ds_eval_data_object_operands
  731. *
  732. * PARAMETERS: walk_state - Current walk
  733. * Op - A valid data_object Op object
  734. * obj_desc - data_object
  735. *
  736. * RETURN: Status
  737. *
  738. * DESCRIPTION: Get the operands and complete the following data object types:
  739. * Buffer, Package.
  740. *
  741. ******************************************************************************/
  742. acpi_status
  743. acpi_ds_eval_data_object_operands(struct acpi_walk_state *walk_state,
  744. union acpi_parse_object *op,
  745. union acpi_operand_object *obj_desc)
  746. {
  747. acpi_status status;
  748. union acpi_operand_object *arg_desc;
  749. u32 length;
  750. ACPI_FUNCTION_TRACE(ds_eval_data_object_operands);
  751. /* The first operand (for all of these data objects) is the length */
  752. /*
  753. * Set proper index into operand stack for acpi_ds_obj_stack_push
  754. * invoked inside acpi_ds_create_operand.
  755. */
  756. walk_state->operand_index = walk_state->num_operands;
  757. status = acpi_ds_create_operand(walk_state, op->common.value.arg, 1);
  758. if (ACPI_FAILURE(status)) {
  759. return_ACPI_STATUS(status);
  760. }
  761. status = acpi_ex_resolve_operands(walk_state->opcode,
  762. &(walk_state->
  763. operands[walk_state->num_operands -
  764. 1]), walk_state);
  765. if (ACPI_FAILURE(status)) {
  766. return_ACPI_STATUS(status);
  767. }
  768. /* Extract length operand */
  769. arg_desc = walk_state->operands[walk_state->num_operands - 1];
  770. length = (u32) arg_desc->integer.value;
  771. /* Cleanup for length operand */
  772. status = acpi_ds_obj_stack_pop(1, walk_state);
  773. if (ACPI_FAILURE(status)) {
  774. return_ACPI_STATUS(status);
  775. }
  776. acpi_ut_remove_reference(arg_desc);
  777. /*
  778. * Create the actual data object
  779. */
  780. switch (op->common.aml_opcode) {
  781. case AML_BUFFER_OP:
  782. status =
  783. acpi_ds_build_internal_buffer_obj(walk_state, op, length,
  784. &obj_desc);
  785. break;
  786. case AML_PACKAGE_OP:
  787. case AML_VAR_PACKAGE_OP:
  788. status =
  789. acpi_ds_build_internal_package_obj(walk_state, op, length,
  790. &obj_desc);
  791. break;
  792. default:
  793. return_ACPI_STATUS(AE_AML_BAD_OPCODE);
  794. }
  795. if (ACPI_SUCCESS(status)) {
  796. /*
  797. * Return the object in the walk_state, unless the parent is a package -
  798. * in this case, the return object will be stored in the parse tree
  799. * for the package.
  800. */
  801. if ((!op->common.parent) ||
  802. ((op->common.parent->common.aml_opcode != AML_PACKAGE_OP) &&
  803. (op->common.parent->common.aml_opcode !=
  804. AML_VAR_PACKAGE_OP)
  805. && (op->common.parent->common.aml_opcode != AML_NAME_OP))) {
  806. walk_state->result_obj = obj_desc;
  807. }
  808. }
  809. return_ACPI_STATUS(status);
  810. }
  811. /*******************************************************************************
  812. *
  813. * FUNCTION: acpi_ds_eval_bank_field_operands
  814. *
  815. * PARAMETERS: walk_state - Current walk
  816. * Op - A valid bank_field Op object
  817. *
  818. * RETURN: Status
  819. *
  820. * DESCRIPTION: Get bank_field bank_value
  821. * Called from acpi_ds_exec_end_op during bank_field parse tree walk
  822. *
  823. ******************************************************************************/
  824. acpi_status
  825. acpi_ds_eval_bank_field_operands(struct acpi_walk_state *walk_state,
  826. union acpi_parse_object *op)
  827. {
  828. acpi_status status;
  829. union acpi_operand_object *obj_desc;
  830. union acpi_operand_object *operand_desc;
  831. struct acpi_namespace_node *node;
  832. union acpi_parse_object *next_op;
  833. union acpi_parse_object *arg;
  834. ACPI_FUNCTION_TRACE_PTR(ds_eval_bank_field_operands, op);
  835. /*
  836. * This is where we evaluate the bank_value field of the
  837. * bank_field declaration
  838. */
  839. /* next_op points to the op that holds the Region */
  840. next_op = op->common.value.arg;
  841. /* next_op points to the op that holds the Bank Register */
  842. next_op = next_op->common.next;
  843. /* next_op points to the op that holds the Bank Value */
  844. next_op = next_op->common.next;
  845. /*
  846. * Set proper index into operand stack for acpi_ds_obj_stack_push
  847. * invoked inside acpi_ds_create_operand.
  848. *
  849. * We use walk_state->Operands[0] to store the evaluated bank_value
  850. */
  851. walk_state->operand_index = 0;
  852. status = acpi_ds_create_operand(walk_state, next_op, 0);
  853. if (ACPI_FAILURE(status)) {
  854. return_ACPI_STATUS(status);
  855. }
  856. status = acpi_ex_resolve_to_value(&walk_state->operands[0], walk_state);
  857. if (ACPI_FAILURE(status)) {
  858. return_ACPI_STATUS(status);
  859. }
  860. ACPI_DUMP_OPERANDS(ACPI_WALK_OPERANDS,
  861. acpi_ps_get_opcode_name(op->common.aml_opcode), 1);
  862. /*
  863. * Get the bank_value operand and save it
  864. * (at Top of stack)
  865. */
  866. operand_desc = walk_state->operands[0];
  867. /* Arg points to the start Bank Field */
  868. arg = acpi_ps_get_arg(op, 4);
  869. while (arg) {
  870. /* Ignore OFFSET and ACCESSAS terms here */
  871. if (arg->common.aml_opcode == AML_INT_NAMEDFIELD_OP) {
  872. node = arg->common.node;
  873. obj_desc = acpi_ns_get_attached_object(node);
  874. if (!obj_desc) {
  875. return_ACPI_STATUS(AE_NOT_EXIST);
  876. }
  877. obj_desc->bank_field.value =
  878. (u32) operand_desc->integer.value;
  879. }
  880. /* Move to next field in the list */
  881. arg = arg->common.next;
  882. }
  883. acpi_ut_remove_reference(operand_desc);
  884. return_ACPI_STATUS(status);
  885. }
  886. /*******************************************************************************
  887. *
  888. * FUNCTION: acpi_ds_exec_begin_control_op
  889. *
  890. * PARAMETERS: walk_list - The list that owns the walk stack
  891. * Op - The control Op
  892. *
  893. * RETURN: Status
  894. *
  895. * DESCRIPTION: Handles all control ops encountered during control method
  896. * execution.
  897. *
  898. ******************************************************************************/
  899. acpi_status
  900. acpi_ds_exec_begin_control_op(struct acpi_walk_state *walk_state,
  901. union acpi_parse_object *op)
  902. {
  903. acpi_status status = AE_OK;
  904. union acpi_generic_state *control_state;
  905. ACPI_FUNCTION_NAME(ds_exec_begin_control_op);
  906. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "Op=%p Opcode=%2.2X State=%p\n", op,
  907. op->common.aml_opcode, walk_state));
  908. switch (op->common.aml_opcode) {
  909. case AML_WHILE_OP:
  910. /*
  911. * If this is an additional iteration of a while loop, continue.
  912. * There is no need to allocate a new control state.
  913. */
  914. if (walk_state->control_state) {
  915. if (walk_state->control_state->control.aml_predicate_start
  916. == (walk_state->parser_state.aml - 1)) {
  917. /* Reset the state to start-of-loop */
  918. walk_state->control_state->common.state =
  919. ACPI_CONTROL_CONDITIONAL_EXECUTING;
  920. break;
  921. }
  922. }
  923. /*lint -fallthrough */
  924. case AML_IF_OP:
  925. /*
  926. * IF/WHILE: Create a new control state to manage these
  927. * constructs. We need to manage these as a stack, in order
  928. * to handle nesting.
  929. */
  930. control_state = acpi_ut_create_control_state();
  931. if (!control_state) {
  932. status = AE_NO_MEMORY;
  933. break;
  934. }
  935. /*
  936. * Save a pointer to the predicate for multiple executions
  937. * of a loop
  938. */
  939. control_state->control.aml_predicate_start =
  940. walk_state->parser_state.aml - 1;
  941. control_state->control.package_end =
  942. walk_state->parser_state.pkg_end;
  943. control_state->control.opcode = op->common.aml_opcode;
  944. /* Push the control state on this walk's control stack */
  945. acpi_ut_push_generic_state(&walk_state->control_state,
  946. control_state);
  947. break;
  948. case AML_ELSE_OP:
  949. /* Predicate is in the state object */
  950. /* If predicate is true, the IF was executed, ignore ELSE part */
  951. if (walk_state->last_predicate) {
  952. status = AE_CTRL_TRUE;
  953. }
  954. break;
  955. case AML_RETURN_OP:
  956. break;
  957. default:
  958. break;
  959. }
  960. return (status);
  961. }
  962. /*******************************************************************************
  963. *
  964. * FUNCTION: acpi_ds_exec_end_control_op
  965. *
  966. * PARAMETERS: walk_list - The list that owns the walk stack
  967. * Op - The control Op
  968. *
  969. * RETURN: Status
  970. *
  971. * DESCRIPTION: Handles all control ops encountered during control method
  972. * execution.
  973. *
  974. ******************************************************************************/
  975. acpi_status
  976. acpi_ds_exec_end_control_op(struct acpi_walk_state * walk_state,
  977. union acpi_parse_object * op)
  978. {
  979. acpi_status status = AE_OK;
  980. union acpi_generic_state *control_state;
  981. ACPI_FUNCTION_NAME(ds_exec_end_control_op);
  982. switch (op->common.aml_opcode) {
  983. case AML_IF_OP:
  984. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "[IF_OP] Op=%p\n", op));
  985. /*
  986. * Save the result of the predicate in case there is an
  987. * ELSE to come
  988. */
  989. walk_state->last_predicate =
  990. (u8) walk_state->control_state->common.value;
  991. /*
  992. * Pop the control state that was created at the start
  993. * of the IF and free it
  994. */
  995. control_state =
  996. acpi_ut_pop_generic_state(&walk_state->control_state);
  997. acpi_ut_delete_generic_state(control_state);
  998. break;
  999. case AML_ELSE_OP:
  1000. break;
  1001. case AML_WHILE_OP:
  1002. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "[WHILE_OP] Op=%p\n", op));
  1003. control_state = walk_state->control_state;
  1004. if (control_state->common.value) {
  1005. /* Predicate was true, the body of the loop was just executed */
  1006. /*
  1007. * This loop counter mechanism allows the interpreter to escape
  1008. * possibly infinite loops. This can occur in poorly written AML
  1009. * when the hardware does not respond within a while loop and the
  1010. * loop does not implement a timeout.
  1011. */
  1012. control_state->control.loop_count++;
  1013. if (control_state->control.loop_count >
  1014. ACPI_MAX_LOOP_ITERATIONS) {
  1015. status = AE_AML_INFINITE_LOOP;
  1016. break;
  1017. }
  1018. /*
  1019. * Go back and evaluate the predicate and maybe execute the loop
  1020. * another time
  1021. */
  1022. status = AE_CTRL_PENDING;
  1023. walk_state->aml_last_while =
  1024. control_state->control.aml_predicate_start;
  1025. break;
  1026. }
  1027. /* Predicate was false, terminate this while loop */
  1028. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
  1029. "[WHILE_OP] termination! Op=%p\n", op));
  1030. /* Pop this control state and free it */
  1031. control_state =
  1032. acpi_ut_pop_generic_state(&walk_state->control_state);
  1033. acpi_ut_delete_generic_state(control_state);
  1034. break;
  1035. case AML_RETURN_OP:
  1036. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
  1037. "[RETURN_OP] Op=%p Arg=%p\n", op,
  1038. op->common.value.arg));
  1039. /*
  1040. * One optional operand -- the return value
  1041. * It can be either an immediate operand or a result that
  1042. * has been bubbled up the tree
  1043. */
  1044. if (op->common.value.arg) {
  1045. /* Since we have a real Return(), delete any implicit return */
  1046. acpi_ds_clear_implicit_return(walk_state);
  1047. /* Return statement has an immediate operand */
  1048. status =
  1049. acpi_ds_create_operands(walk_state,
  1050. op->common.value.arg);
  1051. if (ACPI_FAILURE(status)) {
  1052. return (status);
  1053. }
  1054. /*
  1055. * If value being returned is a Reference (such as
  1056. * an arg or local), resolve it now because it may
  1057. * cease to exist at the end of the method.
  1058. */
  1059. status =
  1060. acpi_ex_resolve_to_value(&walk_state->operands[0],
  1061. walk_state);
  1062. if (ACPI_FAILURE(status)) {
  1063. return (status);
  1064. }
  1065. /*
  1066. * Get the return value and save as the last result
  1067. * value. This is the only place where walk_state->return_desc
  1068. * is set to anything other than zero!
  1069. */
  1070. walk_state->return_desc = walk_state->operands[0];
  1071. } else if (walk_state->result_count) {
  1072. /* Since we have a real Return(), delete any implicit return */
  1073. acpi_ds_clear_implicit_return(walk_state);
  1074. /*
  1075. * The return value has come from a previous calculation.
  1076. *
  1077. * If value being returned is a Reference (such as
  1078. * an arg or local), resolve it now because it may
  1079. * cease to exist at the end of the method.
  1080. *
  1081. * Allow references created by the Index operator to return unchanged.
  1082. */
  1083. if ((ACPI_GET_DESCRIPTOR_TYPE
  1084. (walk_state->results->results.obj_desc[0]) ==
  1085. ACPI_DESC_TYPE_OPERAND)
  1086. && ((walk_state->results->results.obj_desc[0])->
  1087. common.type == ACPI_TYPE_LOCAL_REFERENCE)
  1088. && ((walk_state->results->results.obj_desc[0])->
  1089. reference.class != ACPI_REFCLASS_INDEX)) {
  1090. status =
  1091. acpi_ex_resolve_to_value(&walk_state->
  1092. results->results.
  1093. obj_desc[0],
  1094. walk_state);
  1095. if (ACPI_FAILURE(status)) {
  1096. return (status);
  1097. }
  1098. }
  1099. walk_state->return_desc =
  1100. walk_state->results->results.obj_desc[0];
  1101. } else {
  1102. /* No return operand */
  1103. if (walk_state->num_operands) {
  1104. acpi_ut_remove_reference(walk_state->
  1105. operands[0]);
  1106. }
  1107. walk_state->operands[0] = NULL;
  1108. walk_state->num_operands = 0;
  1109. walk_state->return_desc = NULL;
  1110. }
  1111. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
  1112. "Completed RETURN_OP State=%p, RetVal=%p\n",
  1113. walk_state, walk_state->return_desc));
  1114. /* End the control method execution right now */
  1115. status = AE_CTRL_TERMINATE;
  1116. break;
  1117. case AML_NOOP_OP:
  1118. /* Just do nothing! */
  1119. break;
  1120. case AML_BREAK_POINT_OP:
  1121. /*
  1122. * Set the single-step flag. This will cause the debugger (if present)
  1123. * to break to the console within the AML debugger at the start of the
  1124. * next AML instruction.
  1125. */
  1126. ACPI_DEBUGGER_EXEC(acpi_gbl_cm_single_step = TRUE);
  1127. ACPI_DEBUGGER_EXEC(acpi_os_printf
  1128. ("**break** Executed AML BreakPoint opcode\n"));
  1129. /* Call to the OSL in case OS wants a piece of the action */
  1130. status = acpi_os_signal(ACPI_SIGNAL_BREAKPOINT,
  1131. "Executed AML Breakpoint opcode");
  1132. break;
  1133. case AML_BREAK_OP:
  1134. case AML_CONTINUE_OP: /* ACPI 2.0 */
  1135. /* Pop and delete control states until we find a while */
  1136. while (walk_state->control_state &&
  1137. (walk_state->control_state->control.opcode !=
  1138. AML_WHILE_OP)) {
  1139. control_state =
  1140. acpi_ut_pop_generic_state(&walk_state->
  1141. control_state);
  1142. acpi_ut_delete_generic_state(control_state);
  1143. }
  1144. /* No while found? */
  1145. if (!walk_state->control_state) {
  1146. return (AE_AML_NO_WHILE);
  1147. }
  1148. /* Was: walk_state->aml_last_while = walk_state->control_state->Control.aml_predicate_start; */
  1149. walk_state->aml_last_while =
  1150. walk_state->control_state->control.package_end;
  1151. /* Return status depending on opcode */
  1152. if (op->common.aml_opcode == AML_BREAK_OP) {
  1153. status = AE_CTRL_BREAK;
  1154. } else {
  1155. status = AE_CTRL_CONTINUE;
  1156. }
  1157. break;
  1158. default:
  1159. ACPI_ERROR((AE_INFO, "Unknown control opcode=0x%X Op=%p",
  1160. op->common.aml_opcode, op));
  1161. status = AE_AML_BAD_OPCODE;
  1162. break;
  1163. }
  1164. return (status);
  1165. }