dsfield.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807
  1. /******************************************************************************
  2. *
  3. * Module Name: dsfield - Dispatcher field routines
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2018, Intel Corp.
  8. * All rights reserved.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions, and the following disclaimer,
  15. * without modification.
  16. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  17. * substantially similar to the "NO WARRANTY" disclaimer below
  18. * ("Disclaimer") and any redistribution must be conditioned upon
  19. * including a substantially similar Disclaimer requirement for further
  20. * binary redistribution.
  21. * 3. Neither the names of the above-listed copyright holders nor the names
  22. * of any contributors may be used to endorse or promote products derived
  23. * from this software without specific prior written permission.
  24. *
  25. * Alternatively, this software may be distributed under the terms of the
  26. * GNU General Public License ("GPL") version 2 as published by the Free
  27. * Software Foundation.
  28. *
  29. * NO WARRANTY
  30. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  31. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  32. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  33. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  34. * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  35. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  36. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  37. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  38. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  39. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  40. * POSSIBILITY OF SUCH DAMAGES.
  41. */
  42. #include <acpi/acpi.h>
  43. #include "accommon.h"
  44. #include "amlcode.h"
  45. #include "acdispat.h"
  46. #include "acinterp.h"
  47. #include "acnamesp.h"
  48. #include "acparser.h"
  49. #define _COMPONENT ACPI_DISPATCHER
  50. ACPI_MODULE_NAME("dsfield")
  51. /* Local prototypes */
  52. #ifdef ACPI_ASL_COMPILER
  53. #include "acdisasm.h"
  54. static acpi_status
  55. acpi_ds_create_external_region(acpi_status lookup_status,
  56. union acpi_parse_object *op,
  57. char *path,
  58. struct acpi_walk_state *walk_state,
  59. struct acpi_namespace_node **node);
  60. #endif
  61. static acpi_status
  62. acpi_ds_get_field_names(struct acpi_create_field_info *info,
  63. struct acpi_walk_state *walk_state,
  64. union acpi_parse_object *arg);
  65. #ifdef ACPI_ASL_COMPILER
  66. /*******************************************************************************
  67. *
  68. * FUNCTION: acpi_ds_create_external_region (iASL Disassembler only)
  69. *
  70. * PARAMETERS: lookup_status - Status from ns_lookup operation
  71. * op - Op containing the Field definition and args
  72. * path - Pathname of the region
  73. * ` walk_state - Current method state
  74. * node - Where the new region node is returned
  75. *
  76. * RETURN: Status
  77. *
  78. * DESCRIPTION: Add region to the external list if NOT_FOUND. Create a new
  79. * region node/object.
  80. *
  81. ******************************************************************************/
  82. static acpi_status
  83. acpi_ds_create_external_region(acpi_status lookup_status,
  84. union acpi_parse_object *op,
  85. char *path,
  86. struct acpi_walk_state *walk_state,
  87. struct acpi_namespace_node **node)
  88. {
  89. acpi_status status;
  90. union acpi_operand_object *obj_desc;
  91. if (lookup_status != AE_NOT_FOUND) {
  92. return (lookup_status);
  93. }
  94. /*
  95. * Table disassembly:
  96. * operation_region not found. Generate an External for it, and
  97. * insert the name into the namespace.
  98. */
  99. acpi_dm_add_op_to_external_list(op, path, ACPI_TYPE_REGION, 0, 0);
  100. status = acpi_ns_lookup(walk_state->scope_info, path, ACPI_TYPE_REGION,
  101. ACPI_IMODE_LOAD_PASS1, ACPI_NS_SEARCH_PARENT,
  102. walk_state, node);
  103. if (ACPI_FAILURE(status)) {
  104. return (status);
  105. }
  106. /* Must create and install a region object for the new node */
  107. obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_REGION);
  108. if (!obj_desc) {
  109. return (AE_NO_MEMORY);
  110. }
  111. obj_desc->region.node = *node;
  112. status = acpi_ns_attach_object(*node, obj_desc, ACPI_TYPE_REGION);
  113. return (status);
  114. }
  115. #endif
  116. /*******************************************************************************
  117. *
  118. * FUNCTION: acpi_ds_create_buffer_field
  119. *
  120. * PARAMETERS: op - Current parse op (create_XXField)
  121. * walk_state - Current state
  122. *
  123. * RETURN: Status
  124. *
  125. * DESCRIPTION: Execute the create_field operators:
  126. * create_bit_field_op,
  127. * create_byte_field_op,
  128. * create_word_field_op,
  129. * create_dword_field_op,
  130. * create_qword_field_op,
  131. * create_field_op (all of which define a field in a buffer)
  132. *
  133. ******************************************************************************/
  134. acpi_status
  135. acpi_ds_create_buffer_field(union acpi_parse_object *op,
  136. struct acpi_walk_state *walk_state)
  137. {
  138. union acpi_parse_object *arg;
  139. struct acpi_namespace_node *node;
  140. acpi_status status;
  141. union acpi_operand_object *obj_desc;
  142. union acpi_operand_object *second_desc = NULL;
  143. u32 flags;
  144. ACPI_FUNCTION_TRACE(ds_create_buffer_field);
  145. /*
  146. * Get the name_string argument (name of the new buffer_field)
  147. */
  148. if (op->common.aml_opcode == AML_CREATE_FIELD_OP) {
  149. /* For create_field, name is the 4th argument */
  150. arg = acpi_ps_get_arg(op, 3);
  151. } else {
  152. /* For all other create_XXXField operators, name is the 3rd argument */
  153. arg = acpi_ps_get_arg(op, 2);
  154. }
  155. if (!arg) {
  156. return_ACPI_STATUS(AE_AML_NO_OPERAND);
  157. }
  158. if (walk_state->deferred_node) {
  159. node = walk_state->deferred_node;
  160. status = AE_OK;
  161. } else {
  162. /* Execute flag should always be set when this function is entered */
  163. if (!(walk_state->parse_flags & ACPI_PARSE_EXECUTE)) {
  164. ACPI_ERROR((AE_INFO, "Parse execute mode is not set"));
  165. return_ACPI_STATUS(AE_AML_INTERNAL);
  166. }
  167. /* Creating new namespace node, should not already exist */
  168. flags = ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE |
  169. ACPI_NS_ERROR_IF_FOUND;
  170. /*
  171. * Mark node temporary if we are executing a normal control
  172. * method. (Don't mark if this is a module-level code method)
  173. */
  174. if (walk_state->method_node &&
  175. !(walk_state->parse_flags & ACPI_PARSE_MODULE_LEVEL)) {
  176. flags |= ACPI_NS_TEMPORARY;
  177. }
  178. /* Enter the name_string into the namespace */
  179. status = acpi_ns_lookup(walk_state->scope_info,
  180. arg->common.value.string, ACPI_TYPE_ANY,
  181. ACPI_IMODE_LOAD_PASS1, flags,
  182. walk_state, &node);
  183. if (ACPI_FAILURE(status)) {
  184. ACPI_ERROR_NAMESPACE(walk_state->scope_info,
  185. arg->common.value.string, status);
  186. return_ACPI_STATUS(status);
  187. }
  188. }
  189. /*
  190. * We could put the returned object (Node) on the object stack for later,
  191. * but for now, we will put it in the "op" object that the parser uses,
  192. * so we can get it again at the end of this scope.
  193. */
  194. op->common.node = node;
  195. /*
  196. * If there is no object attached to the node, this node was just created
  197. * and we need to create the field object. Otherwise, this was a lookup
  198. * of an existing node and we don't want to create the field object again.
  199. */
  200. obj_desc = acpi_ns_get_attached_object(node);
  201. if (obj_desc) {
  202. return_ACPI_STATUS(AE_OK);
  203. }
  204. /*
  205. * The Field definition is not fully parsed at this time.
  206. * (We must save the address of the AML for the buffer and index operands)
  207. */
  208. /* Create the buffer field object */
  209. obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_BUFFER_FIELD);
  210. if (!obj_desc) {
  211. status = AE_NO_MEMORY;
  212. goto cleanup;
  213. }
  214. /*
  215. * Remember location in AML stream of the field unit opcode and operands
  216. * -- since the buffer and index operands must be evaluated.
  217. */
  218. second_desc = obj_desc->common.next_object;
  219. second_desc->extra.aml_start = op->named.data;
  220. second_desc->extra.aml_length = op->named.length;
  221. obj_desc->buffer_field.node = node;
  222. /* Attach constructed field descriptors to parent node */
  223. status = acpi_ns_attach_object(node, obj_desc, ACPI_TYPE_BUFFER_FIELD);
  224. if (ACPI_FAILURE(status)) {
  225. goto cleanup;
  226. }
  227. cleanup:
  228. /* Remove local reference to the object */
  229. acpi_ut_remove_reference(obj_desc);
  230. return_ACPI_STATUS(status);
  231. }
  232. /*******************************************************************************
  233. *
  234. * FUNCTION: acpi_ds_get_field_names
  235. *
  236. * PARAMETERS: info - create_field info structure
  237. * ` walk_state - Current method state
  238. * arg - First parser arg for the field name list
  239. *
  240. * RETURN: Status
  241. *
  242. * DESCRIPTION: Process all named fields in a field declaration. Names are
  243. * entered into the namespace.
  244. *
  245. ******************************************************************************/
  246. static acpi_status
  247. acpi_ds_get_field_names(struct acpi_create_field_info *info,
  248. struct acpi_walk_state *walk_state,
  249. union acpi_parse_object *arg)
  250. {
  251. acpi_status status;
  252. u64 position;
  253. union acpi_parse_object *child;
  254. ACPI_FUNCTION_TRACE_PTR(ds_get_field_names, info);
  255. /* First field starts at bit zero */
  256. info->field_bit_position = 0;
  257. /* Process all elements in the field list (of parse nodes) */
  258. while (arg) {
  259. /*
  260. * Four types of field elements are handled:
  261. * 1) name - Enters a new named field into the namespace
  262. * 2) offset - specifies a bit offset
  263. * 3) access_as - changes the access mode/attributes
  264. * 4) connection - Associate a resource template with the field
  265. */
  266. switch (arg->common.aml_opcode) {
  267. case AML_INT_RESERVEDFIELD_OP:
  268. position = (u64)info->field_bit_position +
  269. (u64)arg->common.value.size;
  270. if (position > ACPI_UINT32_MAX) {
  271. ACPI_ERROR((AE_INFO,
  272. "Bit offset within field too large (> 0xFFFFFFFF)"));
  273. return_ACPI_STATUS(AE_SUPPORT);
  274. }
  275. info->field_bit_position = (u32) position;
  276. break;
  277. case AML_INT_ACCESSFIELD_OP:
  278. case AML_INT_EXTACCESSFIELD_OP:
  279. /*
  280. * Get new access_type, access_attribute, and access_length fields
  281. * -- to be used for all field units that follow, until the
  282. * end-of-field or another access_as keyword is encountered.
  283. * NOTE. These three bytes are encoded in the integer value
  284. * of the parseop for convenience.
  285. *
  286. * In field_flags, preserve the flag bits other than the
  287. * ACCESS_TYPE bits.
  288. */
  289. /* access_type (byte_acc, word_acc, etc.) */
  290. info->field_flags = (u8)
  291. ((info->
  292. field_flags & ~(AML_FIELD_ACCESS_TYPE_MASK)) |
  293. ((u8)((u32)(arg->common.value.integer & 0x07))));
  294. /* access_attribute (attrib_quick, attrib_byte, etc.) */
  295. info->attribute = (u8)
  296. ((arg->common.value.integer >> 8) & 0xFF);
  297. /* access_length (for serial/buffer protocols) */
  298. info->access_length = (u8)
  299. ((arg->common.value.integer >> 16) & 0xFF);
  300. break;
  301. case AML_INT_CONNECTION_OP:
  302. /*
  303. * Clear any previous connection. New connection is used for all
  304. * fields that follow, similar to access_as
  305. */
  306. info->resource_buffer = NULL;
  307. info->connection_node = NULL;
  308. info->pin_number_index = 0;
  309. /*
  310. * A Connection() is either an actual resource descriptor (buffer)
  311. * or a named reference to a resource template
  312. */
  313. child = arg->common.value.arg;
  314. if (child->common.aml_opcode == AML_INT_BYTELIST_OP) {
  315. info->resource_buffer = child->named.data;
  316. info->resource_length =
  317. (u16)child->named.value.integer;
  318. } else {
  319. /* Lookup the Connection() namepath, it should already exist */
  320. status = acpi_ns_lookup(walk_state->scope_info,
  321. child->common.value.
  322. name, ACPI_TYPE_ANY,
  323. ACPI_IMODE_EXECUTE,
  324. ACPI_NS_DONT_OPEN_SCOPE,
  325. walk_state,
  326. &info->connection_node);
  327. if (ACPI_FAILURE(status)) {
  328. ACPI_ERROR_NAMESPACE(walk_state->
  329. scope_info,
  330. child->common.
  331. value.name,
  332. status);
  333. return_ACPI_STATUS(status);
  334. }
  335. }
  336. break;
  337. case AML_INT_NAMEDFIELD_OP:
  338. /* Lookup the name, it should already exist */
  339. status = acpi_ns_lookup(walk_state->scope_info,
  340. (char *)&arg->named.name,
  341. info->field_type,
  342. ACPI_IMODE_EXECUTE,
  343. ACPI_NS_DONT_OPEN_SCOPE,
  344. walk_state, &info->field_node);
  345. if (ACPI_FAILURE(status)) {
  346. ACPI_ERROR_NAMESPACE(walk_state->scope_info,
  347. (char *)&arg->named.name,
  348. status);
  349. return_ACPI_STATUS(status);
  350. } else {
  351. arg->common.node = info->field_node;
  352. info->field_bit_length = arg->common.value.size;
  353. /*
  354. * If there is no object attached to the node, this node was
  355. * just created and we need to create the field object.
  356. * Otherwise, this was a lookup of an existing node and we
  357. * don't want to create the field object again.
  358. */
  359. if (!acpi_ns_get_attached_object
  360. (info->field_node)) {
  361. status = acpi_ex_prep_field_value(info);
  362. if (ACPI_FAILURE(status)) {
  363. return_ACPI_STATUS(status);
  364. }
  365. }
  366. }
  367. /* Keep track of bit position for the next field */
  368. position = (u64)info->field_bit_position +
  369. (u64)arg->common.value.size;
  370. if (position > ACPI_UINT32_MAX) {
  371. ACPI_ERROR((AE_INFO,
  372. "Field [%4.4s] bit offset too large (> 0xFFFFFFFF)",
  373. ACPI_CAST_PTR(char,
  374. &info->field_node->
  375. name)));
  376. return_ACPI_STATUS(AE_SUPPORT);
  377. }
  378. info->field_bit_position += info->field_bit_length;
  379. info->pin_number_index++; /* Index relative to previous Connection() */
  380. break;
  381. default:
  382. ACPI_ERROR((AE_INFO,
  383. "Invalid opcode in field list: 0x%X",
  384. arg->common.aml_opcode));
  385. return_ACPI_STATUS(AE_AML_BAD_OPCODE);
  386. }
  387. arg = arg->common.next;
  388. }
  389. return_ACPI_STATUS(AE_OK);
  390. }
  391. /*******************************************************************************
  392. *
  393. * FUNCTION: acpi_ds_create_field
  394. *
  395. * PARAMETERS: op - Op containing the Field definition and args
  396. * region_node - Object for the containing Operation Region
  397. * ` walk_state - Current method state
  398. *
  399. * RETURN: Status
  400. *
  401. * DESCRIPTION: Create a new field in the specified operation region
  402. *
  403. ******************************************************************************/
  404. acpi_status
  405. acpi_ds_create_field(union acpi_parse_object *op,
  406. struct acpi_namespace_node *region_node,
  407. struct acpi_walk_state *walk_state)
  408. {
  409. acpi_status status;
  410. union acpi_parse_object *arg;
  411. struct acpi_create_field_info info;
  412. ACPI_FUNCTION_TRACE_PTR(ds_create_field, op);
  413. /* First arg is the name of the parent op_region (must already exist) */
  414. arg = op->common.value.arg;
  415. if (!region_node) {
  416. status =
  417. acpi_ns_lookup(walk_state->scope_info,
  418. arg->common.value.name, ACPI_TYPE_REGION,
  419. ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT,
  420. walk_state, &region_node);
  421. #ifdef ACPI_ASL_COMPILER
  422. status = acpi_ds_create_external_region(status, arg,
  423. arg->common.value.name,
  424. walk_state,
  425. &region_node);
  426. #endif
  427. if (ACPI_FAILURE(status)) {
  428. ACPI_ERROR_NAMESPACE(walk_state->scope_info,
  429. arg->common.value.name, status);
  430. return_ACPI_STATUS(status);
  431. }
  432. }
  433. memset(&info, 0, sizeof(struct acpi_create_field_info));
  434. /* Second arg is the field flags */
  435. arg = arg->common.next;
  436. info.field_flags = (u8) arg->common.value.integer;
  437. info.attribute = 0;
  438. /* Each remaining arg is a Named Field */
  439. info.field_type = ACPI_TYPE_LOCAL_REGION_FIELD;
  440. info.region_node = region_node;
  441. status = acpi_ds_get_field_names(&info, walk_state, arg->common.next);
  442. return_ACPI_STATUS(status);
  443. }
  444. /*******************************************************************************
  445. *
  446. * FUNCTION: acpi_ds_init_field_objects
  447. *
  448. * PARAMETERS: op - Op containing the Field definition and args
  449. * ` walk_state - Current method state
  450. *
  451. * RETURN: Status
  452. *
  453. * DESCRIPTION: For each "Field Unit" name in the argument list that is
  454. * part of the field declaration, enter the name into the
  455. * namespace.
  456. *
  457. ******************************************************************************/
  458. acpi_status
  459. acpi_ds_init_field_objects(union acpi_parse_object *op,
  460. struct acpi_walk_state *walk_state)
  461. {
  462. acpi_status status;
  463. union acpi_parse_object *arg = NULL;
  464. struct acpi_namespace_node *node;
  465. u8 type = 0;
  466. u32 flags;
  467. ACPI_FUNCTION_TRACE_PTR(ds_init_field_objects, op);
  468. /* Execute flag should always be set when this function is entered */
  469. if (!(walk_state->parse_flags & ACPI_PARSE_EXECUTE)) {
  470. if (walk_state->parse_flags & ACPI_PARSE_DEFERRED_OP) {
  471. /* bank_field Op is deferred, just return OK */
  472. return_ACPI_STATUS(AE_OK);
  473. }
  474. ACPI_ERROR((AE_INFO, "Parse deferred mode is not set"));
  475. return_ACPI_STATUS(AE_AML_INTERNAL);
  476. }
  477. /*
  478. * Get the field_list argument for this opcode. This is the start of the
  479. * list of field elements.
  480. */
  481. switch (walk_state->opcode) {
  482. case AML_FIELD_OP:
  483. arg = acpi_ps_get_arg(op, 2);
  484. type = ACPI_TYPE_LOCAL_REGION_FIELD;
  485. break;
  486. case AML_BANK_FIELD_OP:
  487. arg = acpi_ps_get_arg(op, 4);
  488. type = ACPI_TYPE_LOCAL_BANK_FIELD;
  489. break;
  490. case AML_INDEX_FIELD_OP:
  491. arg = acpi_ps_get_arg(op, 3);
  492. type = ACPI_TYPE_LOCAL_INDEX_FIELD;
  493. break;
  494. default:
  495. return_ACPI_STATUS(AE_BAD_PARAMETER);
  496. }
  497. /* Creating new namespace node(s), should not already exist */
  498. flags = ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE |
  499. ACPI_NS_ERROR_IF_FOUND;
  500. /*
  501. * Mark node(s) temporary if we are executing a normal control
  502. * method. (Don't mark if this is a module-level code method)
  503. */
  504. if (walk_state->method_node &&
  505. !(walk_state->parse_flags & ACPI_PARSE_MODULE_LEVEL)) {
  506. flags |= ACPI_NS_TEMPORARY;
  507. }
  508. /*
  509. * Walk the list of entries in the field_list
  510. * Note: field_list can be of zero length. In this case, Arg will be NULL.
  511. */
  512. while (arg) {
  513. /*
  514. * Ignore OFFSET/ACCESSAS/CONNECTION terms here; we are only interested
  515. * in the field names in order to enter them into the namespace.
  516. */
  517. if (arg->common.aml_opcode == AML_INT_NAMEDFIELD_OP) {
  518. status = acpi_ns_lookup(walk_state->scope_info,
  519. (char *)&arg->named.name, type,
  520. ACPI_IMODE_LOAD_PASS1, flags,
  521. walk_state, &node);
  522. if (ACPI_FAILURE(status)) {
  523. ACPI_ERROR_NAMESPACE(walk_state->scope_info,
  524. (char *)&arg->named.name,
  525. status);
  526. if (status != AE_ALREADY_EXISTS) {
  527. return_ACPI_STATUS(status);
  528. }
  529. /* Name already exists, just ignore this error */
  530. status = AE_OK;
  531. }
  532. arg->common.node = node;
  533. }
  534. /* Get the next field element in the list */
  535. arg = arg->common.next;
  536. }
  537. return_ACPI_STATUS(AE_OK);
  538. }
  539. /*******************************************************************************
  540. *
  541. * FUNCTION: acpi_ds_create_bank_field
  542. *
  543. * PARAMETERS: op - Op containing the Field definition and args
  544. * region_node - Object for the containing Operation Region
  545. * walk_state - Current method state
  546. *
  547. * RETURN: Status
  548. *
  549. * DESCRIPTION: Create a new bank field in the specified operation region
  550. *
  551. ******************************************************************************/
  552. acpi_status
  553. acpi_ds_create_bank_field(union acpi_parse_object *op,
  554. struct acpi_namespace_node *region_node,
  555. struct acpi_walk_state *walk_state)
  556. {
  557. acpi_status status;
  558. union acpi_parse_object *arg;
  559. struct acpi_create_field_info info;
  560. ACPI_FUNCTION_TRACE_PTR(ds_create_bank_field, op);
  561. /* First arg is the name of the parent op_region (must already exist) */
  562. arg = op->common.value.arg;
  563. if (!region_node) {
  564. status =
  565. acpi_ns_lookup(walk_state->scope_info,
  566. arg->common.value.name, ACPI_TYPE_REGION,
  567. ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT,
  568. walk_state, &region_node);
  569. #ifdef ACPI_ASL_COMPILER
  570. status = acpi_ds_create_external_region(status, arg,
  571. arg->common.value.name,
  572. walk_state,
  573. &region_node);
  574. #endif
  575. if (ACPI_FAILURE(status)) {
  576. ACPI_ERROR_NAMESPACE(walk_state->scope_info,
  577. arg->common.value.name, status);
  578. return_ACPI_STATUS(status);
  579. }
  580. }
  581. /* Second arg is the Bank Register (Field) (must already exist) */
  582. arg = arg->common.next;
  583. status =
  584. acpi_ns_lookup(walk_state->scope_info, arg->common.value.string,
  585. ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
  586. ACPI_NS_SEARCH_PARENT, walk_state,
  587. &info.register_node);
  588. if (ACPI_FAILURE(status)) {
  589. ACPI_ERROR_NAMESPACE(walk_state->scope_info,
  590. arg->common.value.string, status);
  591. return_ACPI_STATUS(status);
  592. }
  593. /*
  594. * Third arg is the bank_value
  595. * This arg is a term_arg, not a constant
  596. * It will be evaluated later, by acpi_ds_eval_bank_field_operands
  597. */
  598. arg = arg->common.next;
  599. /* Fourth arg is the field flags */
  600. arg = arg->common.next;
  601. info.field_flags = (u8) arg->common.value.integer;
  602. /* Each remaining arg is a Named Field */
  603. info.field_type = ACPI_TYPE_LOCAL_BANK_FIELD;
  604. info.region_node = region_node;
  605. /*
  606. * Use Info.data_register_node to store bank_field Op
  607. * It's safe because data_register_node will never be used when create
  608. * bank field \we store aml_start and aml_length in the bank_field Op for
  609. * late evaluation. Used in acpi_ex_prep_field_value(Info)
  610. *
  611. * TBD: Or, should we add a field in struct acpi_create_field_info, like
  612. * "void *ParentOp"?
  613. */
  614. info.data_register_node = (struct acpi_namespace_node *)op;
  615. status = acpi_ds_get_field_names(&info, walk_state, arg->common.next);
  616. return_ACPI_STATUS(status);
  617. }
  618. /*******************************************************************************
  619. *
  620. * FUNCTION: acpi_ds_create_index_field
  621. *
  622. * PARAMETERS: op - Op containing the Field definition and args
  623. * region_node - Object for the containing Operation Region
  624. * ` walk_state - Current method state
  625. *
  626. * RETURN: Status
  627. *
  628. * DESCRIPTION: Create a new index field in the specified operation region
  629. *
  630. ******************************************************************************/
  631. acpi_status
  632. acpi_ds_create_index_field(union acpi_parse_object *op,
  633. struct acpi_namespace_node *region_node,
  634. struct acpi_walk_state *walk_state)
  635. {
  636. acpi_status status;
  637. union acpi_parse_object *arg;
  638. struct acpi_create_field_info info;
  639. ACPI_FUNCTION_TRACE_PTR(ds_create_index_field, op);
  640. /* First arg is the name of the Index register (must already exist) */
  641. arg = op->common.value.arg;
  642. status =
  643. acpi_ns_lookup(walk_state->scope_info, arg->common.value.string,
  644. ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
  645. ACPI_NS_SEARCH_PARENT, walk_state,
  646. &info.register_node);
  647. if (ACPI_FAILURE(status)) {
  648. ACPI_ERROR_NAMESPACE(walk_state->scope_info,
  649. arg->common.value.string, status);
  650. return_ACPI_STATUS(status);
  651. }
  652. /* Second arg is the data register (must already exist) */
  653. arg = arg->common.next;
  654. status =
  655. acpi_ns_lookup(walk_state->scope_info, arg->common.value.string,
  656. ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
  657. ACPI_NS_SEARCH_PARENT, walk_state,
  658. &info.data_register_node);
  659. if (ACPI_FAILURE(status)) {
  660. ACPI_ERROR_NAMESPACE(walk_state->scope_info,
  661. arg->common.value.string, status);
  662. return_ACPI_STATUS(status);
  663. }
  664. /* Next arg is the field flags */
  665. arg = arg->common.next;
  666. info.field_flags = (u8) arg->common.value.integer;
  667. /* Each remaining arg is a Named Field */
  668. info.field_type = ACPI_TYPE_LOCAL_INDEX_FIELD;
  669. info.region_node = region_node;
  670. status = acpi_ds_get_field_names(&info, walk_state, arg->common.next);
  671. return_ACPI_STATUS(status);
  672. }