dsopcode.c 35 KB

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