dsfield.c 17 KB

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