dsfield.c 23 KB

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