dsopcode.c 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472
  1. /******************************************************************************
  2. *
  3. * Module Name: dsopcode - Dispatcher Op Region support and handling of
  4. * "control" opcodes
  5. *
  6. *****************************************************************************/
  7. /*
  8. * Copyright (C) 2000 - 2008, 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, acpi_ns_get_parent_node(node),
  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, acpi_ns_get_parent_node(node),
  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 NS node in buffer obj %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 NS 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, acpi_ns_get_parent_node(node),
  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 %02x", aml_opcode));
  467. status = AE_AML_BAD_OPCODE;
  468. goto cleanup;
  469. }
  470. /* Entire field must fit within the current length of the buffer */
  471. if ((bit_offset + bit_count) > (8 * (u32) buffer_desc->buffer.length)) {
  472. ACPI_ERROR((AE_INFO,
  473. "Field [%4.4s] at %d exceeds Buffer [%4.4s] size %d (bits)",
  474. acpi_ut_get_node_name(result_desc),
  475. bit_offset + bit_count,
  476. acpi_ut_get_node_name(buffer_desc->buffer.node),
  477. 8 * (u32) buffer_desc->buffer.length));
  478. status = AE_AML_BUFFER_LIMIT;
  479. goto cleanup;
  480. }
  481. /*
  482. * Initialize areas of the field object that are common to all fields
  483. * For field_flags, use LOCK_RULE = 0 (NO_LOCK),
  484. * UPDATE_RULE = 0 (UPDATE_PRESERVE)
  485. */
  486. status = acpi_ex_prep_common_field_object(obj_desc, field_flags, 0,
  487. bit_offset, bit_count);
  488. if (ACPI_FAILURE(status)) {
  489. goto cleanup;
  490. }
  491. obj_desc->buffer_field.buffer_obj = buffer_desc;
  492. /* Reference count for buffer_desc inherits obj_desc count */
  493. buffer_desc->common.reference_count = (u16)
  494. (buffer_desc->common.reference_count +
  495. obj_desc->common.reference_count);
  496. cleanup:
  497. /* Always delete the operands */
  498. acpi_ut_remove_reference(offset_desc);
  499. acpi_ut_remove_reference(buffer_desc);
  500. if (aml_opcode == AML_CREATE_FIELD_OP) {
  501. acpi_ut_remove_reference(length_desc);
  502. }
  503. /* On failure, delete the result descriptor */
  504. if (ACPI_FAILURE(status)) {
  505. acpi_ut_remove_reference(result_desc); /* Result descriptor */
  506. } else {
  507. /* Now the address and length are valid for this buffer_field */
  508. obj_desc->buffer_field.flags |= AOPOBJ_DATA_VALID;
  509. }
  510. return_ACPI_STATUS(status);
  511. }
  512. /*******************************************************************************
  513. *
  514. * FUNCTION: acpi_ds_eval_buffer_field_operands
  515. *
  516. * PARAMETERS: walk_state - Current walk
  517. * Op - A valid buffer_field Op object
  518. *
  519. * RETURN: Status
  520. *
  521. * DESCRIPTION: Get buffer_field Buffer and Index
  522. * Called from acpi_ds_exec_end_op during buffer_field parse tree walk
  523. *
  524. ******************************************************************************/
  525. acpi_status
  526. acpi_ds_eval_buffer_field_operands(struct acpi_walk_state *walk_state,
  527. union acpi_parse_object *op)
  528. {
  529. acpi_status status;
  530. union acpi_operand_object *obj_desc;
  531. struct acpi_namespace_node *node;
  532. union acpi_parse_object *next_op;
  533. ACPI_FUNCTION_TRACE_PTR(ds_eval_buffer_field_operands, op);
  534. /*
  535. * This is where we evaluate the address and length fields of the
  536. * create_xxx_field declaration
  537. */
  538. node = op->common.node;
  539. /* next_op points to the op that holds the Buffer */
  540. next_op = op->common.value.arg;
  541. /* Evaluate/create the address and length operands */
  542. status = acpi_ds_create_operands(walk_state, next_op);
  543. if (ACPI_FAILURE(status)) {
  544. return_ACPI_STATUS(status);
  545. }
  546. obj_desc = acpi_ns_get_attached_object(node);
  547. if (!obj_desc) {
  548. return_ACPI_STATUS(AE_NOT_EXIST);
  549. }
  550. /* Resolve the operands */
  551. status = acpi_ex_resolve_operands(op->common.aml_opcode,
  552. ACPI_WALK_OPERANDS, walk_state);
  553. if (ACPI_FAILURE(status)) {
  554. ACPI_ERROR((AE_INFO, "(%s) bad operand(s) (%X)",
  555. acpi_ps_get_opcode_name(op->common.aml_opcode),
  556. status));
  557. return_ACPI_STATUS(status);
  558. }
  559. /* Initialize the Buffer Field */
  560. if (op->common.aml_opcode == AML_CREATE_FIELD_OP) {
  561. /* NOTE: Slightly different operands for this opcode */
  562. status =
  563. acpi_ds_init_buffer_field(op->common.aml_opcode, obj_desc,
  564. walk_state->operands[0],
  565. walk_state->operands[1],
  566. walk_state->operands[2],
  567. walk_state->operands[3]);
  568. } else {
  569. /* All other, create_xxx_field opcodes */
  570. status =
  571. acpi_ds_init_buffer_field(op->common.aml_opcode, obj_desc,
  572. walk_state->operands[0],
  573. walk_state->operands[1], NULL,
  574. walk_state->operands[2]);
  575. }
  576. return_ACPI_STATUS(status);
  577. }
  578. /*******************************************************************************
  579. *
  580. * FUNCTION: acpi_ds_eval_region_operands
  581. *
  582. * PARAMETERS: walk_state - Current walk
  583. * Op - A valid region Op object
  584. *
  585. * RETURN: Status
  586. *
  587. * DESCRIPTION: Get region address and length
  588. * Called from acpi_ds_exec_end_op during op_region parse tree walk
  589. *
  590. ******************************************************************************/
  591. acpi_status
  592. acpi_ds_eval_region_operands(struct acpi_walk_state *walk_state,
  593. union acpi_parse_object *op)
  594. {
  595. acpi_status status;
  596. union acpi_operand_object *obj_desc;
  597. union acpi_operand_object *operand_desc;
  598. struct acpi_namespace_node *node;
  599. union acpi_parse_object *next_op;
  600. ACPI_FUNCTION_TRACE_PTR(ds_eval_region_operands, op);
  601. /*
  602. * This is where we evaluate the address and length fields of the
  603. * op_region declaration
  604. */
  605. node = op->common.node;
  606. /* next_op points to the op that holds the space_iD */
  607. next_op = op->common.value.arg;
  608. /* next_op points to address op */
  609. next_op = next_op->common.next;
  610. /* Evaluate/create the address and length operands */
  611. status = acpi_ds_create_operands(walk_state, next_op);
  612. if (ACPI_FAILURE(status)) {
  613. return_ACPI_STATUS(status);
  614. }
  615. /* Resolve the length and address operands to numbers */
  616. status = acpi_ex_resolve_operands(op->common.aml_opcode,
  617. ACPI_WALK_OPERANDS, walk_state);
  618. if (ACPI_FAILURE(status)) {
  619. return_ACPI_STATUS(status);
  620. }
  621. obj_desc = acpi_ns_get_attached_object(node);
  622. if (!obj_desc) {
  623. return_ACPI_STATUS(AE_NOT_EXIST);
  624. }
  625. /*
  626. * Get the length operand and save it
  627. * (at Top of stack)
  628. */
  629. operand_desc = walk_state->operands[walk_state->num_operands - 1];
  630. obj_desc->region.length = (u32) operand_desc->integer.value;
  631. acpi_ut_remove_reference(operand_desc);
  632. /*
  633. * Get the address and save it
  634. * (at top of stack - 1)
  635. */
  636. operand_desc = walk_state->operands[walk_state->num_operands - 2];
  637. obj_desc->region.address = (acpi_physical_address)
  638. operand_desc->integer.value;
  639. acpi_ut_remove_reference(operand_desc);
  640. ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "RgnObj %p Addr %8.8X%8.8X Len %X\n",
  641. obj_desc,
  642. ACPI_FORMAT_NATIVE_UINT(obj_desc->region.address),
  643. obj_desc->region.length));
  644. /* Now the address and length are valid for this opregion */
  645. obj_desc->region.flags |= AOPOBJ_DATA_VALID;
  646. return_ACPI_STATUS(status);
  647. }
  648. /*******************************************************************************
  649. *
  650. * FUNCTION: acpi_ds_eval_table_region_operands
  651. *
  652. * PARAMETERS: walk_state - Current walk
  653. * Op - A valid region Op object
  654. *
  655. * RETURN: Status
  656. *
  657. * DESCRIPTION: Get region address and length
  658. * Called from acpi_ds_exec_end_op during data_table_region parse tree walk
  659. *
  660. ******************************************************************************/
  661. acpi_status
  662. acpi_ds_eval_table_region_operands(struct acpi_walk_state *walk_state,
  663. union acpi_parse_object *op)
  664. {
  665. acpi_status status;
  666. union acpi_operand_object *obj_desc;
  667. union acpi_operand_object **operand;
  668. struct acpi_namespace_node *node;
  669. union acpi_parse_object *next_op;
  670. u32 table_index;
  671. struct acpi_table_header *table;
  672. ACPI_FUNCTION_TRACE_PTR(ds_eval_table_region_operands, op);
  673. /*
  674. * This is where we evaluate the signature_string and oem_iDString
  675. * and oem_table_iDString of the data_table_region declaration
  676. */
  677. node = op->common.node;
  678. /* next_op points to signature_string op */
  679. next_op = op->common.value.arg;
  680. /*
  681. * Evaluate/create the signature_string and oem_iDString
  682. * and oem_table_iDString operands
  683. */
  684. status = acpi_ds_create_operands(walk_state, next_op);
  685. if (ACPI_FAILURE(status)) {
  686. return_ACPI_STATUS(status);
  687. }
  688. /*
  689. * Resolve the signature_string and oem_iDString
  690. * and oem_table_iDString operands
  691. */
  692. status = acpi_ex_resolve_operands(op->common.aml_opcode,
  693. ACPI_WALK_OPERANDS, walk_state);
  694. if (ACPI_FAILURE(status)) {
  695. return_ACPI_STATUS(status);
  696. }
  697. operand = &walk_state->operands[0];
  698. /* Find the ACPI table */
  699. status = acpi_tb_find_table(operand[0]->string.pointer,
  700. operand[1]->string.pointer,
  701. operand[2]->string.pointer, &table_index);
  702. if (ACPI_FAILURE(status)) {
  703. return_ACPI_STATUS(status);
  704. }
  705. acpi_ut_remove_reference(operand[0]);
  706. acpi_ut_remove_reference(operand[1]);
  707. acpi_ut_remove_reference(operand[2]);
  708. status = acpi_get_table_by_index(table_index, &table);
  709. if (ACPI_FAILURE(status)) {
  710. return_ACPI_STATUS(status);
  711. }
  712. obj_desc = acpi_ns_get_attached_object(node);
  713. if (!obj_desc) {
  714. return_ACPI_STATUS(AE_NOT_EXIST);
  715. }
  716. obj_desc->region.address =
  717. (acpi_physical_address) ACPI_TO_INTEGER(table);
  718. obj_desc->region.length = table->length;
  719. ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "RgnObj %p Addr %8.8X%8.8X Len %X\n",
  720. obj_desc,
  721. ACPI_FORMAT_NATIVE_UINT(obj_desc->region.address),
  722. obj_desc->region.length));
  723. /* Now the address and length are valid for this opregion */
  724. obj_desc->region.flags |= AOPOBJ_DATA_VALID;
  725. return_ACPI_STATUS(status);
  726. }
  727. /*******************************************************************************
  728. *
  729. * FUNCTION: acpi_ds_eval_data_object_operands
  730. *
  731. * PARAMETERS: walk_state - Current walk
  732. * Op - A valid data_object Op object
  733. * obj_desc - data_object
  734. *
  735. * RETURN: Status
  736. *
  737. * DESCRIPTION: Get the operands and complete the following data object types:
  738. * Buffer, Package.
  739. *
  740. ******************************************************************************/
  741. acpi_status
  742. acpi_ds_eval_data_object_operands(struct acpi_walk_state *walk_state,
  743. union acpi_parse_object *op,
  744. union acpi_operand_object *obj_desc)
  745. {
  746. acpi_status status;
  747. union acpi_operand_object *arg_desc;
  748. u32 length;
  749. ACPI_FUNCTION_TRACE(ds_eval_data_object_operands);
  750. /* The first operand (for all of these data objects) is the length */
  751. /*
  752. * Set proper index into operand stack for acpi_ds_obj_stack_push
  753. * invoked inside acpi_ds_create_operand.
  754. */
  755. walk_state->operand_index = walk_state->num_operands;
  756. status = acpi_ds_create_operand(walk_state, op->common.value.arg, 1);
  757. if (ACPI_FAILURE(status)) {
  758. return_ACPI_STATUS(status);
  759. }
  760. status = acpi_ex_resolve_operands(walk_state->opcode,
  761. &(walk_state->
  762. operands[walk_state->num_operands -
  763. 1]), walk_state);
  764. if (ACPI_FAILURE(status)) {
  765. return_ACPI_STATUS(status);
  766. }
  767. /* Extract length operand */
  768. arg_desc = walk_state->operands[walk_state->num_operands - 1];
  769. length = (u32) arg_desc->integer.value;
  770. /* Cleanup for length operand */
  771. status = acpi_ds_obj_stack_pop(1, walk_state);
  772. if (ACPI_FAILURE(status)) {
  773. return_ACPI_STATUS(status);
  774. }
  775. acpi_ut_remove_reference(arg_desc);
  776. /*
  777. * Create the actual data object
  778. */
  779. switch (op->common.aml_opcode) {
  780. case AML_BUFFER_OP:
  781. status =
  782. acpi_ds_build_internal_buffer_obj(walk_state, op, length,
  783. &obj_desc);
  784. break;
  785. case AML_PACKAGE_OP:
  786. case AML_VAR_PACKAGE_OP:
  787. status =
  788. acpi_ds_build_internal_package_obj(walk_state, op, length,
  789. &obj_desc);
  790. break;
  791. default:
  792. return_ACPI_STATUS(AE_AML_BAD_OPCODE);
  793. }
  794. if (ACPI_SUCCESS(status)) {
  795. /*
  796. * Return the object in the walk_state, unless the parent is a package -
  797. * in this case, the return object will be stored in the parse tree
  798. * for the package.
  799. */
  800. if ((!op->common.parent) ||
  801. ((op->common.parent->common.aml_opcode != AML_PACKAGE_OP) &&
  802. (op->common.parent->common.aml_opcode !=
  803. AML_VAR_PACKAGE_OP)
  804. && (op->common.parent->common.aml_opcode != AML_NAME_OP))) {
  805. walk_state->result_obj = obj_desc;
  806. }
  807. }
  808. return_ACPI_STATUS(status);
  809. }
  810. /*******************************************************************************
  811. *
  812. * FUNCTION: acpi_ds_eval_bank_field_operands
  813. *
  814. * PARAMETERS: walk_state - Current walk
  815. * Op - A valid bank_field Op object
  816. *
  817. * RETURN: Status
  818. *
  819. * DESCRIPTION: Get bank_field bank_value
  820. * Called from acpi_ds_exec_end_op during bank_field parse tree walk
  821. *
  822. ******************************************************************************/
  823. acpi_status
  824. acpi_ds_eval_bank_field_operands(struct acpi_walk_state *walk_state,
  825. union acpi_parse_object *op)
  826. {
  827. acpi_status status;
  828. union acpi_operand_object *obj_desc;
  829. union acpi_operand_object *operand_desc;
  830. struct acpi_namespace_node *node;
  831. union acpi_parse_object *next_op;
  832. union acpi_parse_object *arg;
  833. ACPI_FUNCTION_TRACE_PTR(ds_eval_bank_field_operands, op);
  834. /*
  835. * This is where we evaluate the bank_value field of the
  836. * bank_field declaration
  837. */
  838. /* next_op points to the op that holds the Region */
  839. next_op = op->common.value.arg;
  840. /* next_op points to the op that holds the Bank Register */
  841. next_op = next_op->common.next;
  842. /* next_op points to the op that holds the Bank Value */
  843. next_op = next_op->common.next;
  844. /*
  845. * Set proper index into operand stack for acpi_ds_obj_stack_push
  846. * invoked inside acpi_ds_create_operand.
  847. *
  848. * We use walk_state->Operands[0] to store the evaluated bank_value
  849. */
  850. walk_state->operand_index = 0;
  851. status = acpi_ds_create_operand(walk_state, next_op, 0);
  852. if (ACPI_FAILURE(status)) {
  853. return_ACPI_STATUS(status);
  854. }
  855. status = acpi_ex_resolve_to_value(&walk_state->operands[0], walk_state);
  856. if (ACPI_FAILURE(status)) {
  857. return_ACPI_STATUS(status);
  858. }
  859. ACPI_DUMP_OPERANDS(ACPI_WALK_OPERANDS,
  860. acpi_ps_get_opcode_name(op->common.aml_opcode), 1);
  861. /*
  862. * Get the bank_value operand and save it
  863. * (at Top of stack)
  864. */
  865. operand_desc = walk_state->operands[0];
  866. /* Arg points to the start Bank Field */
  867. arg = acpi_ps_get_arg(op, 4);
  868. while (arg) {
  869. /* Ignore OFFSET and ACCESSAS terms here */
  870. if (arg->common.aml_opcode == AML_INT_NAMEDFIELD_OP) {
  871. node = arg->common.node;
  872. obj_desc = acpi_ns_get_attached_object(node);
  873. if (!obj_desc) {
  874. return_ACPI_STATUS(AE_NOT_EXIST);
  875. }
  876. obj_desc->bank_field.value =
  877. (u32) operand_desc->integer.value;
  878. }
  879. /* Move to next field in the list */
  880. arg = arg->common.next;
  881. }
  882. acpi_ut_remove_reference(operand_desc);
  883. return_ACPI_STATUS(status);
  884. }
  885. /*******************************************************************************
  886. *
  887. * FUNCTION: acpi_ds_exec_begin_control_op
  888. *
  889. * PARAMETERS: walk_list - The list that owns the walk stack
  890. * Op - The control Op
  891. *
  892. * RETURN: Status
  893. *
  894. * DESCRIPTION: Handles all control ops encountered during control method
  895. * execution.
  896. *
  897. ******************************************************************************/
  898. acpi_status
  899. acpi_ds_exec_begin_control_op(struct acpi_walk_state *walk_state,
  900. union acpi_parse_object *op)
  901. {
  902. acpi_status status = AE_OK;
  903. union acpi_generic_state *control_state;
  904. ACPI_FUNCTION_NAME(ds_exec_begin_control_op);
  905. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "Op=%p Opcode=%2.2X State=%p\n", op,
  906. op->common.aml_opcode, walk_state));
  907. switch (op->common.aml_opcode) {
  908. case AML_WHILE_OP:
  909. /*
  910. * If this is an additional iteration of a while loop, continue.
  911. * There is no need to allocate a new control state.
  912. */
  913. if (walk_state->control_state) {
  914. if (walk_state->control_state->control.aml_predicate_start
  915. == (walk_state->parser_state.aml - 1)) {
  916. /* Reset the state to start-of-loop */
  917. walk_state->control_state->common.state =
  918. ACPI_CONTROL_CONDITIONAL_EXECUTING;
  919. break;
  920. }
  921. }
  922. /*lint -fallthrough */
  923. case AML_IF_OP:
  924. /*
  925. * IF/WHILE: Create a new control state to manage these
  926. * constructs. We need to manage these as a stack, in order
  927. * to handle nesting.
  928. */
  929. control_state = acpi_ut_create_control_state();
  930. if (!control_state) {
  931. status = AE_NO_MEMORY;
  932. break;
  933. }
  934. /*
  935. * Save a pointer to the predicate for multiple executions
  936. * of a loop
  937. */
  938. control_state->control.aml_predicate_start =
  939. walk_state->parser_state.aml - 1;
  940. control_state->control.package_end =
  941. walk_state->parser_state.pkg_end;
  942. control_state->control.opcode = op->common.aml_opcode;
  943. /* Push the control state on this walk's control stack */
  944. acpi_ut_push_generic_state(&walk_state->control_state,
  945. control_state);
  946. break;
  947. case AML_ELSE_OP:
  948. /* Predicate is in the state object */
  949. /* If predicate is true, the IF was executed, ignore ELSE part */
  950. if (walk_state->last_predicate) {
  951. status = AE_CTRL_TRUE;
  952. }
  953. break;
  954. case AML_RETURN_OP:
  955. break;
  956. default:
  957. break;
  958. }
  959. return (status);
  960. }
  961. /*******************************************************************************
  962. *
  963. * FUNCTION: acpi_ds_exec_end_control_op
  964. *
  965. * PARAMETERS: walk_list - The list that owns the walk stack
  966. * Op - The control Op
  967. *
  968. * RETURN: Status
  969. *
  970. * DESCRIPTION: Handles all control ops encountered during control method
  971. * execution.
  972. *
  973. ******************************************************************************/
  974. acpi_status
  975. acpi_ds_exec_end_control_op(struct acpi_walk_state * walk_state,
  976. union acpi_parse_object * op)
  977. {
  978. acpi_status status = AE_OK;
  979. union acpi_generic_state *control_state;
  980. ACPI_FUNCTION_NAME(ds_exec_end_control_op);
  981. switch (op->common.aml_opcode) {
  982. case AML_IF_OP:
  983. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "[IF_OP] Op=%p\n", op));
  984. /*
  985. * Save the result of the predicate in case there is an
  986. * ELSE to come
  987. */
  988. walk_state->last_predicate =
  989. (u8) walk_state->control_state->common.value;
  990. /*
  991. * Pop the control state that was created at the start
  992. * of the IF and free it
  993. */
  994. control_state =
  995. acpi_ut_pop_generic_state(&walk_state->control_state);
  996. acpi_ut_delete_generic_state(control_state);
  997. break;
  998. case AML_ELSE_OP:
  999. break;
  1000. case AML_WHILE_OP:
  1001. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "[WHILE_OP] Op=%p\n", op));
  1002. control_state = walk_state->control_state;
  1003. if (control_state->common.value) {
  1004. /* Predicate was true, the body of the loop was just executed */
  1005. /*
  1006. * This loop counter mechanism allows the interpreter to escape
  1007. * possibly infinite loops. This can occur in poorly written AML
  1008. * when the hardware does not respond within a while loop and the
  1009. * loop does not implement a timeout.
  1010. */
  1011. control_state->control.loop_count++;
  1012. if (control_state->control.loop_count >
  1013. ACPI_MAX_LOOP_ITERATIONS) {
  1014. status = AE_AML_INFINITE_LOOP;
  1015. break;
  1016. }
  1017. /*
  1018. * Go back and evaluate the predicate and maybe execute the loop
  1019. * another time
  1020. */
  1021. status = AE_CTRL_PENDING;
  1022. walk_state->aml_last_while =
  1023. control_state->control.aml_predicate_start;
  1024. break;
  1025. }
  1026. /* Predicate was false, terminate this while loop */
  1027. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
  1028. "[WHILE_OP] termination! Op=%p\n", op));
  1029. /* Pop this control state and free it */
  1030. control_state =
  1031. acpi_ut_pop_generic_state(&walk_state->control_state);
  1032. acpi_ut_delete_generic_state(control_state);
  1033. break;
  1034. case AML_RETURN_OP:
  1035. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
  1036. "[RETURN_OP] Op=%p Arg=%p\n", op,
  1037. op->common.value.arg));
  1038. /*
  1039. * One optional operand -- the return value
  1040. * It can be either an immediate operand or a result that
  1041. * has been bubbled up the tree
  1042. */
  1043. if (op->common.value.arg) {
  1044. /* Since we have a real Return(), delete any implicit return */
  1045. acpi_ds_clear_implicit_return(walk_state);
  1046. /* Return statement has an immediate operand */
  1047. status =
  1048. acpi_ds_create_operands(walk_state,
  1049. op->common.value.arg);
  1050. if (ACPI_FAILURE(status)) {
  1051. return (status);
  1052. }
  1053. /*
  1054. * If value being returned is a Reference (such as
  1055. * an arg or local), resolve it now because it may
  1056. * cease to exist at the end of the method.
  1057. */
  1058. status =
  1059. acpi_ex_resolve_to_value(&walk_state->operands[0],
  1060. walk_state);
  1061. if (ACPI_FAILURE(status)) {
  1062. return (status);
  1063. }
  1064. /*
  1065. * Get the return value and save as the last result
  1066. * value. This is the only place where walk_state->return_desc
  1067. * is set to anything other than zero!
  1068. */
  1069. walk_state->return_desc = walk_state->operands[0];
  1070. } else if (walk_state->result_count) {
  1071. /* Since we have a real Return(), delete any implicit return */
  1072. acpi_ds_clear_implicit_return(walk_state);
  1073. /*
  1074. * The return value has come from a previous calculation.
  1075. *
  1076. * If value being returned is a Reference (such as
  1077. * an arg or local), resolve it now because it may
  1078. * cease to exist at the end of the method.
  1079. *
  1080. * Allow references created by the Index operator to return unchanged.
  1081. */
  1082. if ((ACPI_GET_DESCRIPTOR_TYPE
  1083. (walk_state->results->results.obj_desc[0]) ==
  1084. ACPI_DESC_TYPE_OPERAND)
  1085. && ((walk_state->results->results.obj_desc[0])->
  1086. common.type == ACPI_TYPE_LOCAL_REFERENCE)
  1087. && ((walk_state->results->results.obj_desc[0])->
  1088. reference.class != ACPI_REFCLASS_INDEX)) {
  1089. status =
  1090. acpi_ex_resolve_to_value(&walk_state->
  1091. results->results.
  1092. obj_desc[0],
  1093. walk_state);
  1094. if (ACPI_FAILURE(status)) {
  1095. return (status);
  1096. }
  1097. }
  1098. walk_state->return_desc =
  1099. walk_state->results->results.obj_desc[0];
  1100. } else {
  1101. /* No return operand */
  1102. if (walk_state->num_operands) {
  1103. acpi_ut_remove_reference(walk_state->
  1104. operands[0]);
  1105. }
  1106. walk_state->operands[0] = NULL;
  1107. walk_state->num_operands = 0;
  1108. walk_state->return_desc = NULL;
  1109. }
  1110. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
  1111. "Completed RETURN_OP State=%p, RetVal=%p\n",
  1112. walk_state, walk_state->return_desc));
  1113. /* End the control method execution right now */
  1114. status = AE_CTRL_TERMINATE;
  1115. break;
  1116. case AML_NOOP_OP:
  1117. /* Just do nothing! */
  1118. break;
  1119. case AML_BREAK_POINT_OP:
  1120. /*
  1121. * Set the single-step flag. This will cause the debugger (if present)
  1122. * to break to the console within the AML debugger at the start of the
  1123. * next AML instruction.
  1124. */
  1125. ACPI_DEBUGGER_EXEC(acpi_gbl_cm_single_step = TRUE);
  1126. ACPI_DEBUGGER_EXEC(acpi_os_printf
  1127. ("**break** Executed AML BreakPoint opcode\n"));
  1128. /* Call to the OSL in case OS wants a piece of the action */
  1129. status = acpi_os_signal(ACPI_SIGNAL_BREAKPOINT,
  1130. "Executed AML Breakpoint opcode");
  1131. break;
  1132. case AML_BREAK_OP:
  1133. case AML_CONTINUE_OP: /* ACPI 2.0 */
  1134. /* Pop and delete control states until we find a while */
  1135. while (walk_state->control_state &&
  1136. (walk_state->control_state->control.opcode !=
  1137. AML_WHILE_OP)) {
  1138. control_state =
  1139. acpi_ut_pop_generic_state(&walk_state->
  1140. control_state);
  1141. acpi_ut_delete_generic_state(control_state);
  1142. }
  1143. /* No while found? */
  1144. if (!walk_state->control_state) {
  1145. return (AE_AML_NO_WHILE);
  1146. }
  1147. /* Was: walk_state->aml_last_while = walk_state->control_state->Control.aml_predicate_start; */
  1148. walk_state->aml_last_while =
  1149. walk_state->control_state->control.package_end;
  1150. /* Return status depending on opcode */
  1151. if (op->common.aml_opcode == AML_BREAK_OP) {
  1152. status = AE_CTRL_BREAK;
  1153. } else {
  1154. status = AE_CTRL_CONTINUE;
  1155. }
  1156. break;
  1157. default:
  1158. ACPI_ERROR((AE_INFO, "Unknown control opcode=%X Op=%p",
  1159. op->common.aml_opcode, op));
  1160. status = AE_AML_BAD_OPCODE;
  1161. break;
  1162. }
  1163. return (status);
  1164. }