dsfield.c 19 KB

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