2 /******************************************************************************
4 * Module Name: amprep - ACPI AML (p-code) execution - field prep utilities
7 *****************************************************************************/
10 * Copyright (C) 2000, 2001 R. Byron Moore
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
35 #define _COMPONENT ACPI_EXECUTER
36 MODULE_NAME ("amprep")
39 /*******************************************************************************
41 * FUNCTION: Acpi_aml_decode_field_access_type
43 * PARAMETERS: Access - Encoded field access bits
45 * RETURN: Field granularity (8, 16, or 32)
47 * DESCRIPTION: Decode the Access_type bits of a field definition.
49 ******************************************************************************/
52 acpi_aml_decode_field_access_type (
62 else if (length <= 16) {
65 else if (length <= 32) {
81 case ACCESS_DWORD_ACC:
86 /* Invalid field access type */
93 /*******************************************************************************
95 * FUNCTION: Acpi_aml_prep_common_field_objec
97 * PARAMETERS: Obj_desc - The field object
98 * Field_flags - Access, Lock_rule, or Update_rule.
99 * The format of a Field_flag is described
100 * in the ACPI specification
101 * Field_position - Field position
102 * Field_length - Field length
106 * DESCRIPTION: Initialize the areas of the field object that are common
107 * to the various types of fields.
109 ******************************************************************************/
112 acpi_aml_prep_common_field_object (
113 ACPI_OPERAND_OBJECT *obj_desc,
123 * Note: the structure being initialized is the
124 * ACPI_COMMON_FIELD_INFO; Therefore, we can just use the Field union to
125 * access this common area. No structure fields outside of the common area
126 * are initialized by this procedure.
129 /* Decode the Field_flags */
131 obj_desc->field.access = (u8) ((field_flags & ACCESS_TYPE_MASK)
132 >> ACCESS_TYPE_SHIFT);
133 obj_desc->field.lock_rule = (u8) ((field_flags & LOCK_RULE_MASK)
135 obj_desc->field.update_rule = (u8) ((field_flags & UPDATE_RULE_MASK)
136 >> UPDATE_RULE_SHIFT);
138 /* Other misc fields */
140 obj_desc->field.length = (u16) field_length;
141 obj_desc->field.access_attribute = field_attribute;
143 /* Decode the access type so we can compute offsets */
145 granularity = acpi_aml_decode_field_access_type (obj_desc->field.access, obj_desc->field.length);
147 return (AE_AML_OPERAND_VALUE);
150 /* Access granularity based fields */
152 obj_desc->field.granularity = (u8) granularity;
153 obj_desc->field.bit_offset = (u8) (field_position % granularity);
154 obj_desc->field.offset = (u32) field_position / granularity;
161 /*******************************************************************************
163 * FUNCTION: Acpi_aml_prep_def_field_value
165 * PARAMETERS: Node - Owning Node
166 * Region - Region in which field is being defined
167 * Field_flags - Access, Lock_rule, or Update_rule.
168 * The format of a Field_flag is described
169 * in the ACPI specification
170 * Field_position - Field position
171 * Field_length - Field length
175 * DESCRIPTION: Construct an ACPI_OPERAND_OBJECT of type Def_field and
176 * connect it to the parent Node.
178 ******************************************************************************/
181 acpi_aml_prep_def_field_value (
182 ACPI_NAMESPACE_NODE *node,
189 ACPI_OPERAND_OBJECT *obj_desc;
194 /* Parameter validation */
197 return (AE_AML_NO_OPERAND);
200 type = acpi_ns_get_type (region);
201 if (type != ACPI_TYPE_REGION) {
202 return (AE_AML_OPERAND_TYPE);
205 /* Allocate a new object */
207 obj_desc = acpi_cm_create_internal_object (INTERNAL_TYPE_DEF_FIELD);
209 return (AE_NO_MEMORY);
213 /* Obj_desc and Region valid */
215 /* Initialize areas of the object that are common to all fields */
217 status = acpi_aml_prep_common_field_object (obj_desc, field_flags, field_attribute,
218 field_position, field_length);
219 if (ACPI_FAILURE (status)) {
223 /* Initialize areas of the object that are specific to this field type */
225 obj_desc->field.container = acpi_ns_get_attached_object (region);
227 /* An additional reference for the container */
229 acpi_cm_add_reference (obj_desc->field.container);
235 * Store the constructed descriptor (Obj_desc) into the Named_obj whose
236 * handle is on TOS, preserving the current type of that Named_obj.
238 status = acpi_ns_attach_object ((ACPI_HANDLE) node, obj_desc,
239 (u8) acpi_ns_get_type ((ACPI_HANDLE) node));
245 /*******************************************************************************
247 * FUNCTION: Acpi_aml_prep_bank_field_value
249 * PARAMETERS: Node - Owning Node
250 * Region - Region in which field is being defined
251 * Bank_reg - Bank selection register
252 * Bank_val - Value to store in selection register
253 * Field_flags - Access, Lock_rule, or Update_rule
254 * Field_position - Field position
255 * Field_length - Field length
259 * DESCRIPTION: Construct an ACPI_OPERAND_OBJECT of type Bank_field and
260 * connect it to the parent Node.
262 ******************************************************************************/
265 acpi_aml_prep_bank_field_value (
266 ACPI_NAMESPACE_NODE *node,
268 ACPI_HANDLE bank_reg,
275 ACPI_OPERAND_OBJECT *obj_desc;
280 /* Parameter validation */
283 return (AE_AML_NO_OPERAND);
286 type = acpi_ns_get_type (region);
287 if (type != ACPI_TYPE_REGION) {
288 return (AE_AML_OPERAND_TYPE);
291 /* Allocate a new object */
293 obj_desc = acpi_cm_create_internal_object (INTERNAL_TYPE_BANK_FIELD);
295 return (AE_NO_MEMORY);
298 /* Obj_desc and Region valid */
300 /* Initialize areas of the object that are common to all fields */
302 status = acpi_aml_prep_common_field_object (obj_desc, field_flags, field_attribute,
303 field_position, field_length);
304 if (ACPI_FAILURE (status)) {
308 /* Initialize areas of the object that are specific to this field type */
310 obj_desc->bank_field.value = bank_val;
311 obj_desc->bank_field.container = acpi_ns_get_attached_object (region);
312 obj_desc->bank_field.bank_select = acpi_ns_get_attached_object (bank_reg);
314 /* An additional reference for the container and bank select */
315 /* TBD: [Restructure] is "Bank_select" ever a real internal object?? */
317 acpi_cm_add_reference (obj_desc->bank_field.container);
318 acpi_cm_add_reference (obj_desc->bank_field.bank_select);
323 * Store the constructed descriptor (Obj_desc) into the Named_obj whose
324 * handle is on TOS, preserving the current type of that Named_obj.
326 status = acpi_ns_attach_object ((ACPI_HANDLE) node, obj_desc,
327 (u8) acpi_ns_get_type ((ACPI_HANDLE) node));
333 /*******************************************************************************
335 * FUNCTION: Acpi_aml_prep_index_field_value
337 * PARAMETERS: Node - Owning Node
338 * Index_reg - Index register
339 * Data_reg - Data register
340 * Field_flags - Access, Lock_rule, or Update_rule
341 * Field_position - Field position
342 * Field_length - Field length
346 * DESCRIPTION: Construct an ACPI_OPERAND_OBJECT of type Index_field and
347 * connect it to the parent Node.
349 ******************************************************************************/
352 acpi_aml_prep_index_field_value (
353 ACPI_NAMESPACE_NODE *node,
354 ACPI_HANDLE index_reg,
355 ACPI_HANDLE data_reg,
361 ACPI_OPERAND_OBJECT *obj_desc;
365 /* Parameter validation */
367 if (!index_reg || !data_reg) {
368 return (AE_AML_NO_OPERAND);
371 /* Allocate a new object descriptor */
373 obj_desc = acpi_cm_create_internal_object (INTERNAL_TYPE_INDEX_FIELD);
375 return (AE_NO_MEMORY);
378 /* Initialize areas of the object that are common to all fields */
380 status = acpi_aml_prep_common_field_object (obj_desc, field_flags, field_attribute,
381 field_position, field_length);
382 if (ACPI_FAILURE (status)) {
386 /* Initialize areas of the object that are specific to this field type */
388 obj_desc->index_field.value = (u32) (field_position /
389 obj_desc->field.granularity);
390 obj_desc->index_field.index = index_reg;
391 obj_desc->index_field.data = data_reg;
396 * Store the constructed descriptor (Obj_desc) into the Named_obj whose
397 * handle is on TOS, preserving the current type of that Named_obj.
399 status = acpi_ns_attach_object ((ACPI_HANDLE) node, obj_desc,
400 (u8) acpi_ns_get_type ((ACPI_HANDLE) node));