2 /******************************************************************************
4 * Module Name: amprep - ACPI AML (p-code) execution - field prep utilities
7 *****************************************************************************/
10 * Copyright (C) 2000 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 INTERPRETER
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 (
63 else if (length
<= 16) {
66 else if (length
<= 32) {
82 case ACCESS_DWORD_ACC
:
87 /* Invalid field access type */
94 /*******************************************************************************
96 * FUNCTION: Acpi_aml_prep_common_field_objec
98 * PARAMETERS: Obj_desc - The field object
99 * Field_flags - Access, Lock_rule, or Update_rule.
100 * The format of a Field_flag is described
101 * in the ACPI specification
102 * Field_position - Field position
103 * Field_length - Field length
107 * DESCRIPTION: Initialize the areas of the field object that are common
108 * to the various types of fields.
110 ******************************************************************************/
113 acpi_aml_prep_common_field_object (
114 ACPI_OPERAND_OBJECT
*obj_desc
,
124 * Note: the structure being initialized is the
125 * ACPI_COMMON_FIELD_INFO; Therefore, we can just use the Field union to
126 * access this common area. No structure fields outside of the common area
127 * are initialized by this procedure.
130 /* Decode the Field_flags */
132 obj_desc
->field
.access
= (u8
) ((field_flags
& ACCESS_TYPE_MASK
)
133 >> ACCESS_TYPE_SHIFT
);
134 obj_desc
->field
.lock_rule
= (u8
) ((field_flags
& LOCK_RULE_MASK
)
136 obj_desc
->field
.update_rule
= (u8
) ((field_flags
& UPDATE_RULE_MASK
)
137 >> UPDATE_RULE_SHIFT
);
139 /* Other misc fields */
141 obj_desc
->field
.length
= (u16
) field_length
;
142 obj_desc
->field
.access_attribute
= field_attribute
;
144 /* Decode the access type so we can compute offsets */
146 granularity
= acpi_aml_decode_field_access_type (obj_desc
->field
.access
, obj_desc
->field
.length
);
148 return (AE_AML_OPERAND_VALUE
);
151 /* Access granularity based fields */
153 obj_desc
->field
.granularity
= (u8
) granularity
;
154 obj_desc
->field
.bit_offset
= (u8
) (field_position
% granularity
);
155 obj_desc
->field
.offset
= (u32
) field_position
/ granularity
;
162 /*******************************************************************************
164 * FUNCTION: Acpi_aml_prep_def_field_value
166 * PARAMETERS: Node - Owning Node
167 * Region - Region in which field is being defined
168 * Field_flags - Access, Lock_rule, or Update_rule.
169 * The format of a Field_flag is described
170 * in the ACPI specification
171 * Field_position - Field position
172 * Field_length - Field length
176 * DESCRIPTION: Construct an ACPI_OPERAND_OBJECT of type Def_field and
177 * connect it to the parent Node.
179 ******************************************************************************/
182 acpi_aml_prep_def_field_value (
183 ACPI_NAMESPACE_NODE
*node
,
190 ACPI_OPERAND_OBJECT
*obj_desc
;
195 /* Parameter validation */
198 return (AE_AML_NO_OPERAND
);
201 type
= acpi_ns_get_type (region
);
202 if (type
!= ACPI_TYPE_REGION
) {
203 return (AE_AML_OPERAND_TYPE
);
206 /* Allocate a new object */
208 obj_desc
= acpi_cm_create_internal_object (INTERNAL_TYPE_DEF_FIELD
);
210 return (AE_NO_MEMORY
);
214 /* Obj_desc and Region valid */
216 /* Initialize areas of the object that are common to all fields */
218 status
= acpi_aml_prep_common_field_object (obj_desc
, field_flags
, field_attribute
,
219 field_position
, field_length
);
220 if (ACPI_FAILURE (status
)) {
224 /* Initialize areas of the object that are specific to this field type */
226 obj_desc
->field
.container
= acpi_ns_get_attached_object (region
);
228 /* An additional reference for the container */
230 acpi_cm_add_reference (obj_desc
->field
.container
);
236 * Store the constructed descriptor (Obj_desc) into the Named_obj whose
237 * handle is on TOS, preserving the current type of that Named_obj.
239 status
= acpi_ns_attach_object ((ACPI_HANDLE
) node
, obj_desc
,
240 (u8
) acpi_ns_get_type ((ACPI_HANDLE
) node
));
246 /*******************************************************************************
248 * FUNCTION: Acpi_aml_prep_bank_field_value
250 * PARAMETERS: Node - Owning Node
251 * Region - Region in which field is being defined
252 * Bank_reg - Bank selection register
253 * Bank_val - Value to store in selection register
254 * Field_flags - Access, Lock_rule, or Update_rule
255 * Field_position - Field position
256 * Field_length - Field length
260 * DESCRIPTION: Construct an ACPI_OPERAND_OBJECT of type Bank_field and
261 * connect it to the parent Node.
263 ******************************************************************************/
266 acpi_aml_prep_bank_field_value (
267 ACPI_NAMESPACE_NODE
*node
,
269 ACPI_HANDLE bank_reg
,
276 ACPI_OPERAND_OBJECT
*obj_desc
;
281 /* Parameter validation */
284 return (AE_AML_NO_OPERAND
);
287 type
= acpi_ns_get_type (region
);
288 if (type
!= ACPI_TYPE_REGION
) {
289 return (AE_AML_OPERAND_TYPE
);
292 /* Allocate a new object */
294 obj_desc
= acpi_cm_create_internal_object (INTERNAL_TYPE_BANK_FIELD
);
296 return (AE_NO_MEMORY
);
299 /* Obj_desc and Region valid */
301 /* Initialize areas of the object that are common to all fields */
303 status
= acpi_aml_prep_common_field_object (obj_desc
, field_flags
, field_attribute
,
304 field_position
, field_length
);
305 if (ACPI_FAILURE (status
)) {
309 /* Initialize areas of the object that are specific to this field type */
311 obj_desc
->bank_field
.value
= bank_val
;
312 obj_desc
->bank_field
.container
= acpi_ns_get_attached_object (region
);
313 obj_desc
->bank_field
.bank_select
= acpi_ns_get_attached_object (bank_reg
);
315 /* An additional reference for the container and bank select */
316 /* TBD: [Restructure] is "Bank_select" ever a real internal object?? */
318 acpi_cm_add_reference (obj_desc
->bank_field
.container
);
319 acpi_cm_add_reference (obj_desc
->bank_field
.bank_select
);
324 * Store the constructed descriptor (Obj_desc) into the Named_obj whose
325 * handle is on TOS, preserving the current type of that Named_obj.
327 status
= acpi_ns_attach_object ((ACPI_HANDLE
) node
, obj_desc
,
328 (u8
) acpi_ns_get_type ((ACPI_HANDLE
) node
));
334 /*******************************************************************************
336 * FUNCTION: Acpi_aml_prep_index_field_value
338 * PARAMETERS: Node - Owning Node
339 * Index_reg - Index register
340 * Data_reg - Data register
341 * Field_flags - Access, Lock_rule, or Update_rule
342 * Field_position - Field position
343 * Field_length - Field length
347 * DESCRIPTION: Construct an ACPI_OPERAND_OBJECT of type Index_field and
348 * connect it to the parent Node.
350 ******************************************************************************/
353 acpi_aml_prep_index_field_value (
354 ACPI_NAMESPACE_NODE
*node
,
355 ACPI_HANDLE index_reg
,
356 ACPI_HANDLE data_reg
,
362 ACPI_OPERAND_OBJECT
*obj_desc
;
366 /* Parameter validation */
368 if (!index_reg
|| !data_reg
) {
369 return (AE_AML_NO_OPERAND
);
372 /* Allocate a new object descriptor */
374 obj_desc
= acpi_cm_create_internal_object (INTERNAL_TYPE_INDEX_FIELD
);
376 return (AE_NO_MEMORY
);
379 /* Initialize areas of the object that are common to all fields */
381 status
= acpi_aml_prep_common_field_object (obj_desc
, field_flags
, field_attribute
,
382 field_position
, field_length
);
383 if (ACPI_FAILURE (status
)) {
387 /* Initialize areas of the object that are specific to this field type */
389 obj_desc
->index_field
.value
= (u32
) (field_position
/
390 obj_desc
->field
.granularity
);
391 obj_desc
->index_field
.index
= index_reg
;
392 obj_desc
->index_field
.data
= data_reg
;
397 * Store the constructed descriptor (Obj_desc) into the Named_obj whose
398 * handle is on TOS, preserving the current type of that Named_obj.
400 status
= acpi_ns_attach_object ((ACPI_HANDLE
) node
, obj_desc
,
401 (u8
) acpi_ns_get_type ((ACPI_HANDLE
) node
));