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
31 #define _COMPONENT ACPI_EXECUTER
32 MODULE_NAME ("amprep")
35 /*******************************************************************************
37 * FUNCTION: Acpi_aml_decode_field_access_type
39 * PARAMETERS: Access - Encoded field access bits
41 * RETURN: Field granularity (8, 16, or 32)
43 * DESCRIPTION: Decode the Access_type bits of a field definition.
45 ******************************************************************************/
48 acpi_aml_decode_field_access_type (
58 else if (length
<= 16) {
61 else if (length
<= 32) {
77 case ACCESS_DWORD_ACC
:
82 /* Invalid field access type */
89 /*******************************************************************************
91 * FUNCTION: Acpi_aml_prep_common_field_objec
93 * PARAMETERS: Obj_desc - The field object
94 * Field_flags - Access, Lock_rule, or Update_rule.
95 * The format of a Field_flag is described
96 * in the ACPI specification
97 * Field_position - Field position
98 * Field_length - Field length
102 * DESCRIPTION: Initialize the areas of the field object that are common
103 * to the various types of fields.
105 ******************************************************************************/
108 acpi_aml_prep_common_field_object (
109 ACPI_OPERAND_OBJECT
*obj_desc
,
119 * Note: the structure being initialized is the
120 * ACPI_COMMON_FIELD_INFO; Therefore, we can just use the Field union to
121 * access this common area. No structure fields outside of the common area
122 * are initialized by this procedure.
125 /* Decode the Field_flags */
127 obj_desc
->field
.access
= (u8
) ((field_flags
& ACCESS_TYPE_MASK
)
128 >> ACCESS_TYPE_SHIFT
);
129 obj_desc
->field
.lock_rule
= (u8
) ((field_flags
& LOCK_RULE_MASK
)
131 obj_desc
->field
.update_rule
= (u8
) ((field_flags
& UPDATE_RULE_MASK
)
132 >> UPDATE_RULE_SHIFT
);
134 /* Other misc fields */
136 obj_desc
->field
.length
= (u16
) field_length
;
137 obj_desc
->field
.access_attribute
= field_attribute
;
139 /* Decode the access type so we can compute offsets */
141 granularity
= acpi_aml_decode_field_access_type (obj_desc
->field
.access
, obj_desc
->field
.length
);
143 return (AE_AML_OPERAND_VALUE
);
146 /* Access granularity based fields */
148 obj_desc
->field
.granularity
= (u8
) granularity
;
149 obj_desc
->field
.bit_offset
= (u8
) (field_position
% granularity
);
150 obj_desc
->field
.offset
= (u32
) field_position
/ granularity
;
157 /*******************************************************************************
159 * FUNCTION: Acpi_aml_prep_def_field_value
161 * PARAMETERS: Node - Owning Node
162 * Region - Region in which field is being defined
163 * Field_flags - Access, Lock_rule, or Update_rule.
164 * The format of a Field_flag is described
165 * in the ACPI specification
166 * Field_position - Field position
167 * Field_length - Field length
171 * DESCRIPTION: Construct an ACPI_OPERAND_OBJECT of type Def_field and
172 * connect it to the parent Node.
174 ******************************************************************************/
177 acpi_aml_prep_def_field_value (
178 ACPI_NAMESPACE_NODE
*node
,
185 ACPI_OPERAND_OBJECT
*obj_desc
;
190 /* Parameter validation */
193 return (AE_AML_NO_OPERAND
);
196 type
= acpi_ns_get_type (region
);
197 if (type
!= ACPI_TYPE_REGION
) {
198 return (AE_AML_OPERAND_TYPE
);
201 /* Allocate a new object */
203 obj_desc
= acpi_cm_create_internal_object (INTERNAL_TYPE_DEF_FIELD
);
205 return (AE_NO_MEMORY
);
209 /* Obj_desc and Region valid */
211 /* Initialize areas of the object that are common to all fields */
213 status
= acpi_aml_prep_common_field_object (obj_desc
, field_flags
, field_attribute
,
214 field_position
, field_length
);
215 if (ACPI_FAILURE (status
)) {
219 /* Initialize areas of the object that are specific to this field type */
221 obj_desc
->field
.container
= acpi_ns_get_attached_object (region
);
223 /* An additional reference for the container */
225 acpi_cm_add_reference (obj_desc
->field
.container
);
231 * Store the constructed descriptor (Obj_desc) into the Named_obj whose
232 * handle is on TOS, preserving the current type of that Named_obj.
234 status
= acpi_ns_attach_object ((ACPI_HANDLE
) node
, obj_desc
,
235 (u8
) acpi_ns_get_type ((ACPI_HANDLE
) node
));
241 /*******************************************************************************
243 * FUNCTION: Acpi_aml_prep_bank_field_value
245 * PARAMETERS: Node - Owning Node
246 * Region - Region in which field is being defined
247 * Bank_reg - Bank selection register
248 * Bank_val - Value to store in selection register
249 * Field_flags - Access, Lock_rule, or Update_rule
250 * Field_position - Field position
251 * Field_length - Field length
255 * DESCRIPTION: Construct an ACPI_OPERAND_OBJECT of type Bank_field and
256 * connect it to the parent Node.
258 ******************************************************************************/
261 acpi_aml_prep_bank_field_value (
262 ACPI_NAMESPACE_NODE
*node
,
264 ACPI_HANDLE bank_reg
,
271 ACPI_OPERAND_OBJECT
*obj_desc
;
276 /* Parameter validation */
279 return (AE_AML_NO_OPERAND
);
282 type
= acpi_ns_get_type (region
);
283 if (type
!= ACPI_TYPE_REGION
) {
284 return (AE_AML_OPERAND_TYPE
);
287 /* Allocate a new object */
289 obj_desc
= acpi_cm_create_internal_object (INTERNAL_TYPE_BANK_FIELD
);
291 return (AE_NO_MEMORY
);
294 /* Obj_desc and Region valid */
296 /* Initialize areas of the object that are common to all fields */
298 status
= acpi_aml_prep_common_field_object (obj_desc
, field_flags
, field_attribute
,
299 field_position
, field_length
);
300 if (ACPI_FAILURE (status
)) {
304 /* Initialize areas of the object that are specific to this field type */
306 obj_desc
->bank_field
.value
= bank_val
;
307 obj_desc
->bank_field
.container
= acpi_ns_get_attached_object (region
);
308 obj_desc
->bank_field
.bank_select
= acpi_ns_get_attached_object (bank_reg
);
310 /* An additional reference for the container and bank select */
311 /* TBD: [Restructure] is "Bank_select" ever a real internal object?? */
313 acpi_cm_add_reference (obj_desc
->bank_field
.container
);
314 acpi_cm_add_reference (obj_desc
->bank_field
.bank_select
);
319 * Store the constructed descriptor (Obj_desc) into the Named_obj whose
320 * handle is on TOS, preserving the current type of that Named_obj.
322 status
= acpi_ns_attach_object ((ACPI_HANDLE
) node
, obj_desc
,
323 (u8
) acpi_ns_get_type ((ACPI_HANDLE
) node
));
329 /*******************************************************************************
331 * FUNCTION: Acpi_aml_prep_index_field_value
333 * PARAMETERS: Node - Owning Node
334 * Index_reg - Index register
335 * Data_reg - Data register
336 * Field_flags - Access, Lock_rule, or Update_rule
337 * Field_position - Field position
338 * Field_length - Field length
342 * DESCRIPTION: Construct an ACPI_OPERAND_OBJECT of type Index_field and
343 * connect it to the parent Node.
345 ******************************************************************************/
348 acpi_aml_prep_index_field_value (
349 ACPI_NAMESPACE_NODE
*node
,
350 ACPI_HANDLE index_reg
,
351 ACPI_HANDLE data_reg
,
357 ACPI_OPERAND_OBJECT
*obj_desc
;
361 /* Parameter validation */
363 if (!index_reg
|| !data_reg
) {
364 return (AE_AML_NO_OPERAND
);
367 /* Allocate a new object descriptor */
369 obj_desc
= acpi_cm_create_internal_object (INTERNAL_TYPE_INDEX_FIELD
);
371 return (AE_NO_MEMORY
);
374 /* Initialize areas of the object that are common to all fields */
376 status
= acpi_aml_prep_common_field_object (obj_desc
, field_flags
, field_attribute
,
377 field_position
, field_length
);
378 if (ACPI_FAILURE (status
)) {
382 /* Initialize areas of the object that are specific to this field type */
384 obj_desc
->index_field
.value
= (u32
) (field_position
/
385 obj_desc
->field
.granularity
);
386 obj_desc
->index_field
.index
= index_reg
;
387 obj_desc
->index_field
.data
= data_reg
;
392 * Store the constructed descriptor (Obj_desc) into the Named_obj whose
393 * handle is on TOS, preserving the current type of that Named_obj.
395 status
= acpi_ns_attach_object ((ACPI_HANDLE
) node
, obj_desc
,
396 (u8
) acpi_ns_get_type ((ACPI_HANDLE
) node
));