dsfield.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796
  1. /******************************************************************************
  2. *
  3. * Module Name: dsfield - Dispatcher field routines
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2016, 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. return_ACPI_STATUS(AE_AML_INTERNAL);
  165. }
  166. /* Creating new namespace node, should not already exist */
  167. flags = ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE |
  168. ACPI_NS_ERROR_IF_FOUND;
  169. /*
  170. * Mark node temporary if we are executing a normal control
  171. * method. (Don't mark if this is a module-level code method)
  172. */
  173. if (walk_state->method_node &&
  174. !(walk_state->parse_flags & ACPI_PARSE_MODULE_LEVEL)) {
  175. flags |= ACPI_NS_TEMPORARY;
  176. }
  177. /* Enter the name_string into the namespace */
  178. status = acpi_ns_lookup(walk_state->scope_info,
  179. arg->common.value.string, ACPI_TYPE_ANY,
  180. ACPI_IMODE_LOAD_PASS1, flags,
  181. walk_state, &node);
  182. if (ACPI_FAILURE(status)) {
  183. ACPI_ERROR_NAMESPACE(arg->common.value.string, status);
  184. return_ACPI_STATUS(status);
  185. }
  186. }
  187. /*
  188. * We could put the returned object (Node) on the object stack for later,
  189. * but for now, we will put it in the "op" object that the parser uses,
  190. * so we can get it again at the end of this scope.
  191. */
  192. op->common.node = node;
  193. /*
  194. * If there is no object attached to the node, this node was just created
  195. * and we need to create the field object. Otherwise, this was a lookup
  196. * of an existing node and we don't want to create the field object again.
  197. */
  198. obj_desc = acpi_ns_get_attached_object(node);
  199. if (obj_desc) {
  200. return_ACPI_STATUS(AE_OK);
  201. }
  202. /*
  203. * The Field definition is not fully parsed at this time.
  204. * (We must save the address of the AML for the buffer and index operands)
  205. */
  206. /* Create the buffer field object */
  207. obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_BUFFER_FIELD);
  208. if (!obj_desc) {
  209. status = AE_NO_MEMORY;
  210. goto cleanup;
  211. }
  212. /*
  213. * Remember location in AML stream of the field unit opcode and operands
  214. * -- since the buffer and index operands must be evaluated.
  215. */
  216. second_desc = obj_desc->common.next_object;
  217. second_desc->extra.aml_start = op->named.data;
  218. second_desc->extra.aml_length = op->named.length;
  219. obj_desc->buffer_field.node = node;
  220. /* Attach constructed field descriptors to parent node */
  221. status = acpi_ns_attach_object(node, obj_desc, ACPI_TYPE_BUFFER_FIELD);
  222. if (ACPI_FAILURE(status)) {
  223. goto cleanup;
  224. }
  225. cleanup:
  226. /* Remove local reference to the object */
  227. acpi_ut_remove_reference(obj_desc);
  228. return_ACPI_STATUS(status);
  229. }
  230. /*******************************************************************************
  231. *
  232. * FUNCTION: acpi_ds_get_field_names
  233. *
  234. * PARAMETERS: info - create_field info structure
  235. * ` walk_state - Current method state
  236. * arg - First parser arg for the field name list
  237. *
  238. * RETURN: Status
  239. *
  240. * DESCRIPTION: Process all named fields in a field declaration. Names are
  241. * entered into the namespace.
  242. *
  243. ******************************************************************************/
  244. static acpi_status
  245. acpi_ds_get_field_names(struct acpi_create_field_info *info,
  246. struct acpi_walk_state *walk_state,
  247. union acpi_parse_object *arg)
  248. {
  249. acpi_status status;
  250. u64 position;
  251. union acpi_parse_object *child;
  252. ACPI_FUNCTION_TRACE_PTR(ds_get_field_names, info);
  253. /* First field starts at bit zero */
  254. info->field_bit_position = 0;
  255. /* Process all elements in the field list (of parse nodes) */
  256. while (arg) {
  257. /*
  258. * Four types of field elements are handled:
  259. * 1) name - Enters a new named field into the namespace
  260. * 2) offset - specifies a bit offset
  261. * 3) access_as - changes the access mode/attributes
  262. * 4) connection - Associate a resource template with the field
  263. */
  264. switch (arg->common.aml_opcode) {
  265. case AML_INT_RESERVEDFIELD_OP:
  266. position = (u64)info->field_bit_position +
  267. (u64)arg->common.value.size;
  268. if (position > ACPI_UINT32_MAX) {
  269. ACPI_ERROR((AE_INFO,
  270. "Bit offset within field too large (> 0xFFFFFFFF)"));
  271. return_ACPI_STATUS(AE_SUPPORT);
  272. }
  273. info->field_bit_position = (u32) position;
  274. break;
  275. case AML_INT_ACCESSFIELD_OP:
  276. case AML_INT_EXTACCESSFIELD_OP:
  277. /*
  278. * Get new access_type, access_attribute, and access_length fields
  279. * -- to be used for all field units that follow, until the
  280. * end-of-field or another access_as keyword is encountered.
  281. * NOTE. These three bytes are encoded in the integer value
  282. * of the parseop for convenience.
  283. *
  284. * In field_flags, preserve the flag bits other than the
  285. * ACCESS_TYPE bits.
  286. */
  287. /* access_type (byte_acc, word_acc, etc.) */
  288. info->field_flags = (u8)
  289. ((info->
  290. field_flags & ~(AML_FIELD_ACCESS_TYPE_MASK)) |
  291. ((u8)((u32)(arg->common.value.integer & 0x07))));
  292. /* access_attribute (attrib_quick, attrib_byte, etc.) */
  293. info->attribute = (u8)
  294. ((arg->common.value.integer >> 8) & 0xFF);
  295. /* access_length (for serial/buffer protocols) */
  296. info->access_length = (u8)
  297. ((arg->common.value.integer >> 16) & 0xFF);
  298. break;
  299. case AML_INT_CONNECTION_OP:
  300. /*
  301. * Clear any previous connection. New connection is used for all
  302. * fields that follow, similar to access_as
  303. */
  304. info->resource_buffer = NULL;
  305. info->connection_node = NULL;
  306. info->pin_number_index = 0;
  307. /*
  308. * A Connection() is either an actual resource descriptor (buffer)
  309. * or a named reference to a resource template
  310. */
  311. child = arg->common.value.arg;
  312. if (child->common.aml_opcode == AML_INT_BYTELIST_OP) {
  313. info->resource_buffer = child->named.data;
  314. info->resource_length =
  315. (u16)child->named.value.integer;
  316. } else {
  317. /* Lookup the Connection() namepath, it should already exist */
  318. status = acpi_ns_lookup(walk_state->scope_info,
  319. child->common.value.
  320. name, ACPI_TYPE_ANY,
  321. ACPI_IMODE_EXECUTE,
  322. ACPI_NS_DONT_OPEN_SCOPE,
  323. walk_state,
  324. &info->connection_node);
  325. if (ACPI_FAILURE(status)) {
  326. ACPI_ERROR_NAMESPACE(child->common.
  327. value.name,
  328. status);
  329. return_ACPI_STATUS(status);
  330. }
  331. }
  332. break;
  333. case AML_INT_NAMEDFIELD_OP:
  334. /* Lookup the name, it should already exist */
  335. status = acpi_ns_lookup(walk_state->scope_info,
  336. (char *)&arg->named.name,
  337. info->field_type,
  338. ACPI_IMODE_EXECUTE,
  339. ACPI_NS_DONT_OPEN_SCOPE,
  340. walk_state, &info->field_node);
  341. if (ACPI_FAILURE(status)) {
  342. ACPI_ERROR_NAMESPACE((char *)&arg->named.name,
  343. status);
  344. return_ACPI_STATUS(status);
  345. } else {
  346. arg->common.node = info->field_node;
  347. info->field_bit_length = arg->common.value.size;
  348. /*
  349. * If there is no object attached to the node, this node was
  350. * just created and we need to create the field object.
  351. * Otherwise, this was a lookup of an existing node and we
  352. * don't want to create the field object again.
  353. */
  354. if (!acpi_ns_get_attached_object
  355. (info->field_node)) {
  356. status = acpi_ex_prep_field_value(info);
  357. if (ACPI_FAILURE(status)) {
  358. return_ACPI_STATUS(status);
  359. }
  360. }
  361. }
  362. /* Keep track of bit position for the next field */
  363. position = (u64)info->field_bit_position +
  364. (u64)arg->common.value.size;
  365. if (position > ACPI_UINT32_MAX) {
  366. ACPI_ERROR((AE_INFO,
  367. "Field [%4.4s] bit offset too large (> 0xFFFFFFFF)",
  368. ACPI_CAST_PTR(char,
  369. &info->field_node->
  370. name)));
  371. return_ACPI_STATUS(AE_SUPPORT);
  372. }
  373. info->field_bit_position += info->field_bit_length;
  374. info->pin_number_index++; /* Index relative to previous Connection() */
  375. break;
  376. default:
  377. ACPI_ERROR((AE_INFO,
  378. "Invalid opcode in field list: 0x%X",
  379. arg->common.aml_opcode));
  380. return_ACPI_STATUS(AE_AML_BAD_OPCODE);
  381. }
  382. arg = arg->common.next;
  383. }
  384. return_ACPI_STATUS(AE_OK);
  385. }
  386. /*******************************************************************************
  387. *
  388. * FUNCTION: acpi_ds_create_field
  389. *
  390. * PARAMETERS: op - Op containing the Field definition and args
  391. * region_node - Object for the containing Operation Region
  392. * ` walk_state - Current method state
  393. *
  394. * RETURN: Status
  395. *
  396. * DESCRIPTION: Create a new field in the specified operation region
  397. *
  398. ******************************************************************************/
  399. acpi_status
  400. acpi_ds_create_field(union acpi_parse_object *op,
  401. struct acpi_namespace_node *region_node,
  402. struct acpi_walk_state *walk_state)
  403. {
  404. acpi_status status;
  405. union acpi_parse_object *arg;
  406. struct acpi_create_field_info info;
  407. ACPI_FUNCTION_TRACE_PTR(ds_create_field, op);
  408. /* First arg is the name of the parent op_region (must already exist) */
  409. arg = op->common.value.arg;
  410. if (!region_node) {
  411. status =
  412. acpi_ns_lookup(walk_state->scope_info,
  413. arg->common.value.name, ACPI_TYPE_REGION,
  414. ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT,
  415. walk_state, &region_node);
  416. #ifdef ACPI_ASL_COMPILER
  417. status = acpi_ds_create_external_region(status, arg,
  418. arg->common.value.name,
  419. walk_state,
  420. &region_node);
  421. #endif
  422. if (ACPI_FAILURE(status)) {
  423. ACPI_ERROR_NAMESPACE(arg->common.value.name, status);
  424. return_ACPI_STATUS(status);
  425. }
  426. }
  427. memset(&info, 0, sizeof(struct acpi_create_field_info));
  428. /* Second arg is the field flags */
  429. arg = arg->common.next;
  430. info.field_flags = (u8) arg->common.value.integer;
  431. info.attribute = 0;
  432. /* Each remaining arg is a Named Field */
  433. info.field_type = ACPI_TYPE_LOCAL_REGION_FIELD;
  434. info.region_node = region_node;
  435. status = acpi_ds_get_field_names(&info, walk_state, arg->common.next);
  436. return_ACPI_STATUS(status);
  437. }
  438. /*******************************************************************************
  439. *
  440. * FUNCTION: acpi_ds_init_field_objects
  441. *
  442. * PARAMETERS: op - Op containing the Field definition and args
  443. * ` walk_state - Current method state
  444. *
  445. * RETURN: Status
  446. *
  447. * DESCRIPTION: For each "Field Unit" name in the argument list that is
  448. * part of the field declaration, enter the name into the
  449. * namespace.
  450. *
  451. ******************************************************************************/
  452. acpi_status
  453. acpi_ds_init_field_objects(union acpi_parse_object *op,
  454. struct acpi_walk_state *walk_state)
  455. {
  456. acpi_status status;
  457. union acpi_parse_object *arg = NULL;
  458. struct acpi_namespace_node *node;
  459. u8 type = 0;
  460. u32 flags;
  461. ACPI_FUNCTION_TRACE_PTR(ds_init_field_objects, op);
  462. /* Execute flag should always be set when this function is entered */
  463. if (!(walk_state->parse_flags & ACPI_PARSE_EXECUTE)) {
  464. if (walk_state->parse_flags & ACPI_PARSE_DEFERRED_OP) {
  465. /* bank_field Op is deferred, just return OK */
  466. return_ACPI_STATUS(AE_OK);
  467. }
  468. return_ACPI_STATUS(AE_AML_INTERNAL);
  469. }
  470. /*
  471. * Get the field_list argument for this opcode. This is the start of the
  472. * list of field elements.
  473. */
  474. switch (walk_state->opcode) {
  475. case AML_FIELD_OP:
  476. arg = acpi_ps_get_arg(op, 2);
  477. type = ACPI_TYPE_LOCAL_REGION_FIELD;
  478. break;
  479. case AML_BANK_FIELD_OP:
  480. arg = acpi_ps_get_arg(op, 4);
  481. type = ACPI_TYPE_LOCAL_BANK_FIELD;
  482. break;
  483. case AML_INDEX_FIELD_OP:
  484. arg = acpi_ps_get_arg(op, 3);
  485. type = ACPI_TYPE_LOCAL_INDEX_FIELD;
  486. break;
  487. default:
  488. return_ACPI_STATUS(AE_BAD_PARAMETER);
  489. }
  490. /* Creating new namespace node(s), should not already exist */
  491. flags = ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE |
  492. ACPI_NS_ERROR_IF_FOUND;
  493. /*
  494. * Mark node(s) temporary if we are executing a normal control
  495. * method. (Don't mark if this is a module-level code method)
  496. */
  497. if (walk_state->method_node &&
  498. !(walk_state->parse_flags & ACPI_PARSE_MODULE_LEVEL)) {
  499. flags |= ACPI_NS_TEMPORARY;
  500. }
  501. /*
  502. * Walk the list of entries in the field_list
  503. * Note: field_list can be of zero length. In this case, Arg will be NULL.
  504. */
  505. while (arg) {
  506. /*
  507. * Ignore OFFSET/ACCESSAS/CONNECTION terms here; we are only interested
  508. * in the field names in order to enter them into the namespace.
  509. */
  510. if (arg->common.aml_opcode == AML_INT_NAMEDFIELD_OP) {
  511. status = acpi_ns_lookup(walk_state->scope_info,
  512. (char *)&arg->named.name, type,
  513. ACPI_IMODE_LOAD_PASS1, flags,
  514. walk_state, &node);
  515. if (ACPI_FAILURE(status)) {
  516. ACPI_ERROR_NAMESPACE((char *)&arg->named.name,
  517. status);
  518. if (status != AE_ALREADY_EXISTS) {
  519. return_ACPI_STATUS(status);
  520. }
  521. /* Name already exists, just ignore this error */
  522. status = AE_OK;
  523. }
  524. arg->common.node = node;
  525. }
  526. /* Get the next field element in the list */
  527. arg = arg->common.next;
  528. }
  529. return_ACPI_STATUS(AE_OK);
  530. }
  531. /*******************************************************************************
  532. *
  533. * FUNCTION: acpi_ds_create_bank_field
  534. *
  535. * PARAMETERS: op - Op containing the Field definition and args
  536. * region_node - Object for the containing Operation Region
  537. * walk_state - Current method state
  538. *
  539. * RETURN: Status
  540. *
  541. * DESCRIPTION: Create a new bank field in the specified operation region
  542. *
  543. ******************************************************************************/
  544. acpi_status
  545. acpi_ds_create_bank_field(union acpi_parse_object *op,
  546. struct acpi_namespace_node *region_node,
  547. struct acpi_walk_state *walk_state)
  548. {
  549. acpi_status status;
  550. union acpi_parse_object *arg;
  551. struct acpi_create_field_info info;
  552. ACPI_FUNCTION_TRACE_PTR(ds_create_bank_field, op);
  553. /* First arg is the name of the parent op_region (must already exist) */
  554. arg = op->common.value.arg;
  555. if (!region_node) {
  556. status =
  557. acpi_ns_lookup(walk_state->scope_info,
  558. arg->common.value.name, ACPI_TYPE_REGION,
  559. ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT,
  560. walk_state, &region_node);
  561. #ifdef ACPI_ASL_COMPILER
  562. status = acpi_ds_create_external_region(status, arg,
  563. arg->common.value.name,
  564. walk_state,
  565. &region_node);
  566. #endif
  567. if (ACPI_FAILURE(status)) {
  568. ACPI_ERROR_NAMESPACE(arg->common.value.name, status);
  569. return_ACPI_STATUS(status);
  570. }
  571. }
  572. /* Second arg is the Bank Register (Field) (must already exist) */
  573. arg = arg->common.next;
  574. status =
  575. acpi_ns_lookup(walk_state->scope_info, arg->common.value.string,
  576. ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
  577. ACPI_NS_SEARCH_PARENT, walk_state,
  578. &info.register_node);
  579. if (ACPI_FAILURE(status)) {
  580. ACPI_ERROR_NAMESPACE(arg->common.value.string, status);
  581. return_ACPI_STATUS(status);
  582. }
  583. /*
  584. * Third arg is the bank_value
  585. * This arg is a term_arg, not a constant
  586. * It will be evaluated later, by acpi_ds_eval_bank_field_operands
  587. */
  588. arg = arg->common.next;
  589. /* Fourth arg is the field flags */
  590. arg = arg->common.next;
  591. info.field_flags = (u8) arg->common.value.integer;
  592. /* Each remaining arg is a Named Field */
  593. info.field_type = ACPI_TYPE_LOCAL_BANK_FIELD;
  594. info.region_node = region_node;
  595. /*
  596. * Use Info.data_register_node to store bank_field Op
  597. * It's safe because data_register_node will never be used when create
  598. * bank field \we store aml_start and aml_length in the bank_field Op for
  599. * late evaluation. Used in acpi_ex_prep_field_value(Info)
  600. *
  601. * TBD: Or, should we add a field in struct acpi_create_field_info, like
  602. * "void *ParentOp"?
  603. */
  604. info.data_register_node = (struct acpi_namespace_node *)op;
  605. status = acpi_ds_get_field_names(&info, walk_state, arg->common.next);
  606. return_ACPI_STATUS(status);
  607. }
  608. /*******************************************************************************
  609. *
  610. * FUNCTION: acpi_ds_create_index_field
  611. *
  612. * PARAMETERS: op - Op containing the Field definition and args
  613. * region_node - Object for the containing Operation Region
  614. * ` walk_state - Current method state
  615. *
  616. * RETURN: Status
  617. *
  618. * DESCRIPTION: Create a new index field in the specified operation region
  619. *
  620. ******************************************************************************/
  621. acpi_status
  622. acpi_ds_create_index_field(union acpi_parse_object *op,
  623. struct acpi_namespace_node *region_node,
  624. struct acpi_walk_state *walk_state)
  625. {
  626. acpi_status status;
  627. union acpi_parse_object *arg;
  628. struct acpi_create_field_info info;
  629. ACPI_FUNCTION_TRACE_PTR(ds_create_index_field, op);
  630. /* First arg is the name of the Index register (must already exist) */
  631. arg = op->common.value.arg;
  632. status =
  633. acpi_ns_lookup(walk_state->scope_info, arg->common.value.string,
  634. ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
  635. ACPI_NS_SEARCH_PARENT, walk_state,
  636. &info.register_node);
  637. if (ACPI_FAILURE(status)) {
  638. ACPI_ERROR_NAMESPACE(arg->common.value.string, status);
  639. return_ACPI_STATUS(status);
  640. }
  641. /* Second arg is the data register (must already exist) */
  642. arg = arg->common.next;
  643. status =
  644. acpi_ns_lookup(walk_state->scope_info, arg->common.value.string,
  645. ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
  646. ACPI_NS_SEARCH_PARENT, walk_state,
  647. &info.data_register_node);
  648. if (ACPI_FAILURE(status)) {
  649. ACPI_ERROR_NAMESPACE(arg->common.value.string, status);
  650. return_ACPI_STATUS(status);
  651. }
  652. /* Next arg is the field flags */
  653. arg = arg->common.next;
  654. info.field_flags = (u8) arg->common.value.integer;
  655. /* Each remaining arg is a Named Field */
  656. info.field_type = ACPI_TYPE_LOCAL_INDEX_FIELD;
  657. info.region_node = region_node;
  658. status = acpi_ds_get_field_names(&info, walk_state, arg->common.next);
  659. return_ACPI_STATUS(status);
  660. }