dsfield.c 17 KB

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