dsfield.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  1. /******************************************************************************
  2. *
  3. * Module Name: dsfield - Dispatcher field routines
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2008, 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. static acpi_status
  53. acpi_ds_get_field_names(struct acpi_create_field_info *info,
  54. struct acpi_walk_state *walk_state,
  55. union acpi_parse_object *arg);
  56. /*******************************************************************************
  57. *
  58. * FUNCTION: acpi_ds_create_buffer_field
  59. *
  60. * PARAMETERS: Op - Current parse op (create_xXField)
  61. * walk_state - Current state
  62. *
  63. * RETURN: Status
  64. *
  65. * DESCRIPTION: Execute the create_field operators:
  66. * create_bit_field_op,
  67. * create_byte_field_op,
  68. * create_word_field_op,
  69. * create_dword_field_op,
  70. * create_qword_field_op,
  71. * create_field_op (all of which define a field in a buffer)
  72. *
  73. ******************************************************************************/
  74. acpi_status
  75. acpi_ds_create_buffer_field(union acpi_parse_object *op,
  76. struct acpi_walk_state *walk_state)
  77. {
  78. union acpi_parse_object *arg;
  79. struct acpi_namespace_node *node;
  80. acpi_status status;
  81. union acpi_operand_object *obj_desc;
  82. union acpi_operand_object *second_desc = NULL;
  83. u32 flags;
  84. ACPI_FUNCTION_TRACE(ds_create_buffer_field);
  85. /*
  86. * Get the name_string argument (name of the new buffer_field)
  87. */
  88. if (op->common.aml_opcode == AML_CREATE_FIELD_OP) {
  89. /* For create_field, name is the 4th argument */
  90. arg = acpi_ps_get_arg(op, 3);
  91. } else {
  92. /* For all other create_xXXField operators, name is the 3rd argument */
  93. arg = acpi_ps_get_arg(op, 2);
  94. }
  95. if (!arg) {
  96. return_ACPI_STATUS(AE_AML_NO_OPERAND);
  97. }
  98. if (walk_state->deferred_node) {
  99. node = walk_state->deferred_node;
  100. status = AE_OK;
  101. } else {
  102. /* Execute flag should always be set when this function is entered */
  103. if (!(walk_state->parse_flags & ACPI_PARSE_EXECUTE)) {
  104. return_ACPI_STATUS(AE_AML_INTERNAL);
  105. }
  106. /* Creating new namespace node, should not already exist */
  107. flags = ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE |
  108. ACPI_NS_ERROR_IF_FOUND;
  109. /* Mark node temporary if we are executing a method */
  110. if (walk_state->method_node) {
  111. flags |= ACPI_NS_TEMPORARY;
  112. }
  113. /* Enter the name_string into the namespace */
  114. status =
  115. acpi_ns_lookup(walk_state->scope_info,
  116. arg->common.value.string, ACPI_TYPE_ANY,
  117. ACPI_IMODE_LOAD_PASS1, flags, walk_state,
  118. &node);
  119. if (ACPI_FAILURE(status)) {
  120. ACPI_ERROR_NAMESPACE(arg->common.value.string, status);
  121. return_ACPI_STATUS(status);
  122. }
  123. }
  124. /*
  125. * We could put the returned object (Node) on the object stack for later,
  126. * but for now, we will put it in the "op" object that the parser uses,
  127. * so we can get it again at the end of this scope.
  128. */
  129. op->common.node = node;
  130. /*
  131. * If there is no object attached to the node, this node was just created
  132. * and we need to create the field object. Otherwise, this was a lookup
  133. * of an existing node and we don't want to create the field object again.
  134. */
  135. obj_desc = acpi_ns_get_attached_object(node);
  136. if (obj_desc) {
  137. return_ACPI_STATUS(AE_OK);
  138. }
  139. /*
  140. * The Field definition is not fully parsed at this time.
  141. * (We must save the address of the AML for the buffer and index operands)
  142. */
  143. /* Create the buffer field object */
  144. obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_BUFFER_FIELD);
  145. if (!obj_desc) {
  146. status = AE_NO_MEMORY;
  147. goto cleanup;
  148. }
  149. /*
  150. * Remember location in AML stream of the field unit opcode and operands --
  151. * since the buffer and index operands must be evaluated.
  152. */
  153. second_desc = obj_desc->common.next_object;
  154. second_desc->extra.aml_start = op->named.data;
  155. second_desc->extra.aml_length = op->named.length;
  156. obj_desc->buffer_field.node = node;
  157. /* Attach constructed field descriptors to parent node */
  158. status = acpi_ns_attach_object(node, obj_desc, ACPI_TYPE_BUFFER_FIELD);
  159. if (ACPI_FAILURE(status)) {
  160. goto cleanup;
  161. }
  162. cleanup:
  163. /* Remove local reference to the object */
  164. acpi_ut_remove_reference(obj_desc);
  165. return_ACPI_STATUS(status);
  166. }
  167. /*******************************************************************************
  168. *
  169. * FUNCTION: acpi_ds_get_field_names
  170. *
  171. * PARAMETERS: Info - create_field info structure
  172. * ` walk_state - Current method state
  173. * Arg - First parser arg for the field name list
  174. *
  175. * RETURN: Status
  176. *
  177. * DESCRIPTION: Process all named fields in a field declaration. Names are
  178. * entered into the namespace.
  179. *
  180. ******************************************************************************/
  181. static acpi_status
  182. acpi_ds_get_field_names(struct acpi_create_field_info *info,
  183. struct acpi_walk_state *walk_state,
  184. union acpi_parse_object *arg)
  185. {
  186. acpi_status status;
  187. acpi_integer position;
  188. ACPI_FUNCTION_TRACE_PTR(ds_get_field_names, info);
  189. /* First field starts at bit zero */
  190. info->field_bit_position = 0;
  191. /* Process all elements in the field list (of parse nodes) */
  192. while (arg) {
  193. /*
  194. * Three types of field elements are handled:
  195. * 1) Offset - specifies a bit offset
  196. * 2) access_as - changes the access mode
  197. * 3) Name - Enters a new named field into the namespace
  198. */
  199. switch (arg->common.aml_opcode) {
  200. case AML_INT_RESERVEDFIELD_OP:
  201. position = (acpi_integer) info->field_bit_position
  202. + (acpi_integer) arg->common.value.size;
  203. if (position > ACPI_UINT32_MAX) {
  204. ACPI_ERROR((AE_INFO,
  205. "Bit offset within field too large (> 0xFFFFFFFF)"));
  206. return_ACPI_STATUS(AE_SUPPORT);
  207. }
  208. info->field_bit_position = (u32) position;
  209. break;
  210. case AML_INT_ACCESSFIELD_OP:
  211. /*
  212. * Get a new access_type and access_attribute -- to be used for all
  213. * field units that follow, until field end or another access_as
  214. * keyword.
  215. *
  216. * In field_flags, preserve the flag bits other than the
  217. * ACCESS_TYPE bits
  218. */
  219. info->field_flags = (u8)
  220. ((info->
  221. field_flags & ~(AML_FIELD_ACCESS_TYPE_MASK)) |
  222. ((u8) ((u32) arg->common.value.integer >> 8)));
  223. info->attribute = (u8) (arg->common.value.integer);
  224. break;
  225. case AML_INT_NAMEDFIELD_OP:
  226. /* Lookup the name, it should already exist */
  227. status = acpi_ns_lookup(walk_state->scope_info,
  228. (char *)&arg->named.name,
  229. info->field_type,
  230. ACPI_IMODE_EXECUTE,
  231. ACPI_NS_DONT_OPEN_SCOPE,
  232. walk_state, &info->field_node);
  233. if (ACPI_FAILURE(status)) {
  234. ACPI_ERROR_NAMESPACE((char *)&arg->named.name,
  235. status);
  236. return_ACPI_STATUS(status);
  237. } else {
  238. arg->common.node = info->field_node;
  239. info->field_bit_length = arg->common.value.size;
  240. /*
  241. * If there is no object attached to the node, this node was
  242. * just created and we need to create the field object.
  243. * Otherwise, this was a lookup of an existing node and we
  244. * don't want to create the field object again.
  245. */
  246. if (!acpi_ns_get_attached_object
  247. (info->field_node)) {
  248. status = acpi_ex_prep_field_value(info);
  249. if (ACPI_FAILURE(status)) {
  250. return_ACPI_STATUS(status);
  251. }
  252. }
  253. }
  254. /* Keep track of bit position for the next field */
  255. position = (acpi_integer) info->field_bit_position
  256. + (acpi_integer) arg->common.value.size;
  257. if (position > ACPI_UINT32_MAX) {
  258. ACPI_ERROR((AE_INFO,
  259. "Field [%4.4s] bit offset too large (> 0xFFFFFFFF)",
  260. ACPI_CAST_PTR(char,
  261. &info->field_node->
  262. name)));
  263. return_ACPI_STATUS(AE_SUPPORT);
  264. }
  265. info->field_bit_position += info->field_bit_length;
  266. break;
  267. default:
  268. ACPI_ERROR((AE_INFO,
  269. "Invalid opcode in field list: %X",
  270. arg->common.aml_opcode));
  271. return_ACPI_STATUS(AE_AML_BAD_OPCODE);
  272. }
  273. arg = arg->common.next;
  274. }
  275. return_ACPI_STATUS(AE_OK);
  276. }
  277. /*******************************************************************************
  278. *
  279. * FUNCTION: acpi_ds_create_field
  280. *
  281. * PARAMETERS: Op - Op containing the Field definition and args
  282. * region_node - Object for the containing Operation Region
  283. * ` walk_state - Current method state
  284. *
  285. * RETURN: Status
  286. *
  287. * DESCRIPTION: Create a new field in the specified operation region
  288. *
  289. ******************************************************************************/
  290. acpi_status
  291. acpi_ds_create_field(union acpi_parse_object *op,
  292. struct acpi_namespace_node *region_node,
  293. struct acpi_walk_state *walk_state)
  294. {
  295. acpi_status status;
  296. union acpi_parse_object *arg;
  297. struct acpi_create_field_info info;
  298. ACPI_FUNCTION_TRACE_PTR(ds_create_field, op);
  299. /* First arg is the name of the parent op_region (must already exist) */
  300. arg = op->common.value.arg;
  301. if (!region_node) {
  302. status =
  303. acpi_ns_lookup(walk_state->scope_info,
  304. arg->common.value.name, ACPI_TYPE_REGION,
  305. ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT,
  306. walk_state, &region_node);
  307. if (ACPI_FAILURE(status)) {
  308. ACPI_ERROR_NAMESPACE(arg->common.value.name, status);
  309. return_ACPI_STATUS(status);
  310. }
  311. }
  312. /* Second arg is the field flags */
  313. arg = arg->common.next;
  314. info.field_flags = (u8) arg->common.value.integer;
  315. info.attribute = 0;
  316. /* Each remaining arg is a Named Field */
  317. info.field_type = ACPI_TYPE_LOCAL_REGION_FIELD;
  318. info.region_node = region_node;
  319. status = acpi_ds_get_field_names(&info, walk_state, arg->common.next);
  320. return_ACPI_STATUS(status);
  321. }
  322. /*******************************************************************************
  323. *
  324. * FUNCTION: acpi_ds_init_field_objects
  325. *
  326. * PARAMETERS: Op - Op containing the Field definition and args
  327. * ` walk_state - Current method state
  328. *
  329. * RETURN: Status
  330. *
  331. * DESCRIPTION: For each "Field Unit" name in the argument list that is
  332. * part of the field declaration, enter the name into the
  333. * namespace.
  334. *
  335. ******************************************************************************/
  336. acpi_status
  337. acpi_ds_init_field_objects(union acpi_parse_object *op,
  338. struct acpi_walk_state *walk_state)
  339. {
  340. acpi_status status;
  341. union acpi_parse_object *arg = NULL;
  342. struct acpi_namespace_node *node;
  343. u8 type = 0;
  344. u32 flags;
  345. ACPI_FUNCTION_TRACE_PTR(ds_init_field_objects, op);
  346. /* Execute flag should always be set when this function is entered */
  347. if (!(walk_state->parse_flags & ACPI_PARSE_EXECUTE)) {
  348. if (walk_state->parse_flags & ACPI_PARSE_DEFERRED_OP) {
  349. /* bank_field Op is deferred, just return OK */
  350. return_ACPI_STATUS(AE_OK);
  351. }
  352. return_ACPI_STATUS(AE_AML_INTERNAL);
  353. }
  354. /*
  355. * Get the field_list argument for this opcode. This is the start of the
  356. * list of field elements.
  357. */
  358. switch (walk_state->opcode) {
  359. case AML_FIELD_OP:
  360. arg = acpi_ps_get_arg(op, 2);
  361. type = ACPI_TYPE_LOCAL_REGION_FIELD;
  362. break;
  363. case AML_BANK_FIELD_OP:
  364. arg = acpi_ps_get_arg(op, 4);
  365. type = ACPI_TYPE_LOCAL_BANK_FIELD;
  366. break;
  367. case AML_INDEX_FIELD_OP:
  368. arg = acpi_ps_get_arg(op, 3);
  369. type = ACPI_TYPE_LOCAL_INDEX_FIELD;
  370. break;
  371. default:
  372. return_ACPI_STATUS(AE_BAD_PARAMETER);
  373. }
  374. /* Creating new namespace node(s), should not already exist */
  375. flags = ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE |
  376. ACPI_NS_ERROR_IF_FOUND;
  377. /* Mark node(s) temporary if we are executing a method */
  378. if (walk_state->method_node) {
  379. flags |= ACPI_NS_TEMPORARY;
  380. }
  381. /*
  382. * Walk the list of entries in the field_list
  383. * Note: field_list can be of zero length. In this case, Arg will be NULL.
  384. */
  385. while (arg) {
  386. /*
  387. * Ignore OFFSET and ACCESSAS terms here; we are only interested in the
  388. * field names in order to enter them into the namespace.
  389. */
  390. if (arg->common.aml_opcode == AML_INT_NAMEDFIELD_OP) {
  391. status = acpi_ns_lookup(walk_state->scope_info,
  392. (char *)&arg->named.name, type,
  393. ACPI_IMODE_LOAD_PASS1, flags,
  394. walk_state, &node);
  395. if (ACPI_FAILURE(status)) {
  396. ACPI_ERROR_NAMESPACE((char *)&arg->named.name,
  397. status);
  398. if (status != AE_ALREADY_EXISTS) {
  399. return_ACPI_STATUS(status);
  400. }
  401. /* Name already exists, just ignore this error */
  402. status = AE_OK;
  403. }
  404. arg->common.node = node;
  405. }
  406. /* Get the next field element in the list */
  407. arg = arg->common.next;
  408. }
  409. return_ACPI_STATUS(AE_OK);
  410. }
  411. /*******************************************************************************
  412. *
  413. * FUNCTION: acpi_ds_create_bank_field
  414. *
  415. * PARAMETERS: Op - Op containing the Field definition and args
  416. * region_node - Object for the containing Operation Region
  417. * walk_state - Current method state
  418. *
  419. * RETURN: Status
  420. *
  421. * DESCRIPTION: Create a new bank field in the specified operation region
  422. *
  423. ******************************************************************************/
  424. acpi_status
  425. acpi_ds_create_bank_field(union acpi_parse_object *op,
  426. struct acpi_namespace_node *region_node,
  427. struct acpi_walk_state *walk_state)
  428. {
  429. acpi_status status;
  430. union acpi_parse_object *arg;
  431. struct acpi_create_field_info info;
  432. ACPI_FUNCTION_TRACE_PTR(ds_create_bank_field, op);
  433. /* First arg is the name of the parent op_region (must already exist) */
  434. arg = op->common.value.arg;
  435. if (!region_node) {
  436. status =
  437. acpi_ns_lookup(walk_state->scope_info,
  438. arg->common.value.name, ACPI_TYPE_REGION,
  439. ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT,
  440. walk_state, &region_node);
  441. if (ACPI_FAILURE(status)) {
  442. ACPI_ERROR_NAMESPACE(arg->common.value.name, status);
  443. return_ACPI_STATUS(status);
  444. }
  445. }
  446. /* Second arg is the Bank Register (Field) (must already exist) */
  447. arg = arg->common.next;
  448. status =
  449. acpi_ns_lookup(walk_state->scope_info, arg->common.value.string,
  450. ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
  451. ACPI_NS_SEARCH_PARENT, walk_state,
  452. &info.register_node);
  453. if (ACPI_FAILURE(status)) {
  454. ACPI_ERROR_NAMESPACE(arg->common.value.string, status);
  455. return_ACPI_STATUS(status);
  456. }
  457. /*
  458. * Third arg is the bank_value
  459. * This arg is a term_arg, not a constant
  460. * It will be evaluated later, by acpi_ds_eval_bank_field_operands
  461. */
  462. arg = arg->common.next;
  463. /* Fourth arg is the field flags */
  464. arg = arg->common.next;
  465. info.field_flags = (u8) arg->common.value.integer;
  466. /* Each remaining arg is a Named Field */
  467. info.field_type = ACPI_TYPE_LOCAL_BANK_FIELD;
  468. info.region_node = region_node;
  469. /*
  470. * Use Info.data_register_node to store bank_field Op
  471. * It's safe because data_register_node will never be used when create bank field
  472. * We store aml_start and aml_length in the bank_field Op for late evaluation
  473. * Used in acpi_ex_prep_field_value(Info)
  474. *
  475. * TBD: Or, should we add a field in struct acpi_create_field_info, like "void *ParentOp"?
  476. */
  477. info.data_register_node = (struct acpi_namespace_node *)op;
  478. status = acpi_ds_get_field_names(&info, walk_state, arg->common.next);
  479. return_ACPI_STATUS(status);
  480. }
  481. /*******************************************************************************
  482. *
  483. * FUNCTION: acpi_ds_create_index_field
  484. *
  485. * PARAMETERS: Op - Op containing the Field definition and args
  486. * region_node - Object for the containing Operation Region
  487. * ` walk_state - Current method state
  488. *
  489. * RETURN: Status
  490. *
  491. * DESCRIPTION: Create a new index field in the specified operation region
  492. *
  493. ******************************************************************************/
  494. acpi_status
  495. acpi_ds_create_index_field(union acpi_parse_object *op,
  496. struct acpi_namespace_node *region_node,
  497. struct acpi_walk_state *walk_state)
  498. {
  499. acpi_status status;
  500. union acpi_parse_object *arg;
  501. struct acpi_create_field_info info;
  502. ACPI_FUNCTION_TRACE_PTR(ds_create_index_field, op);
  503. /* First arg is the name of the Index register (must already exist) */
  504. arg = op->common.value.arg;
  505. status =
  506. acpi_ns_lookup(walk_state->scope_info, arg->common.value.string,
  507. ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
  508. ACPI_NS_SEARCH_PARENT, walk_state,
  509. &info.register_node);
  510. if (ACPI_FAILURE(status)) {
  511. ACPI_ERROR_NAMESPACE(arg->common.value.string, status);
  512. return_ACPI_STATUS(status);
  513. }
  514. /* Second arg is the data register (must already exist) */
  515. arg = arg->common.next;
  516. status =
  517. acpi_ns_lookup(walk_state->scope_info, arg->common.value.string,
  518. ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
  519. ACPI_NS_SEARCH_PARENT, walk_state,
  520. &info.data_register_node);
  521. if (ACPI_FAILURE(status)) {
  522. ACPI_ERROR_NAMESPACE(arg->common.value.string, status);
  523. return_ACPI_STATUS(status);
  524. }
  525. /* Next arg is the field flags */
  526. arg = arg->common.next;
  527. info.field_flags = (u8) arg->common.value.integer;
  528. /* Each remaining arg is a Named Field */
  529. info.field_type = ACPI_TYPE_LOCAL_INDEX_FIELD;
  530. info.region_node = region_node;
  531. status = acpi_ds_get_field_names(&info, walk_state, arg->common.next);
  532. return_ACPI_STATUS(status);
  533. }