dsopcode.c 38 KB

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