- Kai Germaschewski: ISDN update (including Makefiles)
[davej-history.git] / drivers / acpi / interpreter / amprep.c
bloba4aa6b834217ac676606f15986c004092f41fbe5
2 /******************************************************************************
4 * Module Name: amprep - ACPI AML (p-code) execution - field prep utilities
5 * $Revision: 69 $
7 *****************************************************************************/
9 /*
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
28 #include "acpi.h"
29 #include "acinterp.h"
30 #include "amlcode.h"
31 #include "acnamesp.h"
32 #include "acparser.h"
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 ******************************************************************************/
51 static u32
52 acpi_aml_decode_field_access_type (
53 u32 access)
56 switch (access)
58 case ACCESS_ANY_ACC:
59 return (8);
60 break;
62 case ACCESS_BYTE_ACC:
63 return (8);
64 break;
66 case ACCESS_WORD_ACC:
67 return (16);
68 break;
70 case ACCESS_DWORD_ACC:
71 return (32);
72 break;
74 default:
75 /* Invalid field access type */
77 return (0);
82 /*******************************************************************************
84 * FUNCTION: Acpi_aml_prep_common_field_objec
86 * PARAMETERS: Obj_desc - The field object
87 * Field_flags - Access, Lock_rule, or Update_rule.
88 * The format of a Field_flag is described
89 * in the ACPI specification
90 * Field_position - Field position
91 * Field_length - Field length
93 * RETURN: Status
95 * DESCRIPTION: Initialize the areas of the field object that are common
96 * to the various types of fields.
98 ******************************************************************************/
100 static ACPI_STATUS
101 acpi_aml_prep_common_field_object (
102 ACPI_OPERAND_OBJECT *obj_desc,
103 u8 field_flags,
104 u8 field_attribute,
105 u32 field_position,
106 u32 field_length)
108 u32 granularity;
112 * Note: the structure being initialized is the
113 * ACPI_COMMON_FIELD_INFO; Therefore, we can just use the Field union to
114 * access this common area. No structure fields outside of the common area
115 * are initialized by this procedure.
118 /* Decode the Field_flags */
120 obj_desc->field.access = (u8) ((field_flags & ACCESS_TYPE_MASK)
121 >> ACCESS_TYPE_SHIFT);
122 obj_desc->field.lock_rule = (u8) ((field_flags & LOCK_RULE_MASK)
123 >> LOCK_RULE_SHIFT);
124 obj_desc->field.update_rule = (u8) ((field_flags & UPDATE_RULE_MASK)
125 >> UPDATE_RULE_SHIFT);
127 /* Other misc fields */
129 obj_desc->field.length = (u16) field_length;
130 obj_desc->field.access_attribute = field_attribute;
132 /* Decode the access type so we can compute offsets */
134 granularity = acpi_aml_decode_field_access_type (obj_desc->field.access);
135 if (!granularity) {
136 return (AE_AML_OPERAND_VALUE);
139 /* Access granularity based fields */
141 obj_desc->field.granularity = (u8) granularity;
142 obj_desc->field.bit_offset = (u8) (field_position % granularity);
143 obj_desc->field.offset = (u32) field_position / granularity;
146 return (AE_OK);
150 /*******************************************************************************
152 * FUNCTION: Acpi_aml_prep_def_field_value
154 * PARAMETERS: Node - Owning Node
155 * Region - Region in which field is being defined
156 * Field_flags - Access, Lock_rule, or Update_rule.
157 * The format of a Field_flag is described
158 * in the ACPI specification
159 * Field_position - Field position
160 * Field_length - Field length
162 * RETURN: Status
164 * DESCRIPTION: Construct an ACPI_OPERAND_OBJECT of type Def_field and
165 * connect it to the parent Node.
167 ******************************************************************************/
169 ACPI_STATUS
170 acpi_aml_prep_def_field_value (
171 ACPI_NAMESPACE_NODE *node,
172 ACPI_HANDLE region,
173 u8 field_flags,
174 u8 field_attribute,
175 u32 field_position,
176 u32 field_length)
178 ACPI_OPERAND_OBJECT *obj_desc;
179 u32 type;
180 ACPI_STATUS status;
183 /* Parameter validation */
185 if (!region) {
186 return (AE_AML_NO_OPERAND);
189 type = acpi_ns_get_type (region);
190 if (type != ACPI_TYPE_REGION) {
191 return (AE_AML_OPERAND_TYPE);
194 /* Allocate a new object */
196 obj_desc = acpi_cm_create_internal_object (INTERNAL_TYPE_DEF_FIELD);
197 if (!obj_desc) {
198 return (AE_NO_MEMORY);
202 /* Obj_desc and Region valid */
204 /* Initialize areas of the object that are common to all fields */
206 status = acpi_aml_prep_common_field_object (obj_desc, field_flags, field_attribute,
207 field_position, field_length);
208 if (ACPI_FAILURE (status)) {
209 return (status);
212 /* Initialize areas of the object that are specific to this field type */
214 obj_desc->field.container = acpi_ns_get_attached_object (region);
216 /* An additional reference for the container */
218 acpi_cm_add_reference (obj_desc->field.container);
221 /* Debug info */
224 * Store the constructed descriptor (Obj_desc) into the Named_obj whose
225 * handle is on TOS, preserving the current type of that Named_obj.
227 status = acpi_ns_attach_object ((ACPI_HANDLE) node, obj_desc,
228 (u8) acpi_ns_get_type ((ACPI_HANDLE) node));
230 return (status);
234 /*******************************************************************************
236 * FUNCTION: Acpi_aml_prep_bank_field_value
238 * PARAMETERS: Node - Owning Node
239 * Region - Region in which field is being defined
240 * Bank_reg - Bank selection register
241 * Bank_val - Value to store in selection register
242 * Field_flags - Access, Lock_rule, or Update_rule
243 * Field_position - Field position
244 * Field_length - Field length
246 * RETURN: Status
248 * DESCRIPTION: Construct an ACPI_OPERAND_OBJECT of type Bank_field and
249 * connect it to the parent Node.
251 ******************************************************************************/
253 ACPI_STATUS
254 acpi_aml_prep_bank_field_value (
255 ACPI_NAMESPACE_NODE *node,
256 ACPI_HANDLE region,
257 ACPI_HANDLE bank_reg,
258 u32 bank_val,
259 u8 field_flags,
260 u8 field_attribute,
261 u32 field_position,
262 u32 field_length)
264 ACPI_OPERAND_OBJECT *obj_desc;
265 u32 type;
266 ACPI_STATUS status;
269 /* Parameter validation */
271 if (!region) {
272 return (AE_AML_NO_OPERAND);
275 type = acpi_ns_get_type (region);
276 if (type != ACPI_TYPE_REGION) {
277 return (AE_AML_OPERAND_TYPE);
280 /* Allocate a new object */
282 obj_desc = acpi_cm_create_internal_object (INTERNAL_TYPE_BANK_FIELD);
283 if (!obj_desc) {
284 return (AE_NO_MEMORY);
287 /* Obj_desc and Region valid */
289 /* Initialize areas of the object that are common to all fields */
291 status = acpi_aml_prep_common_field_object (obj_desc, field_flags, field_attribute,
292 field_position, field_length);
293 if (ACPI_FAILURE (status)) {
294 return (status);
297 /* Initialize areas of the object that are specific to this field type */
299 obj_desc->bank_field.value = bank_val;
300 obj_desc->bank_field.container = acpi_ns_get_attached_object (region);
301 obj_desc->bank_field.bank_select = acpi_ns_get_attached_object (bank_reg);
303 /* An additional reference for the container and bank select */
304 /* TBD: [Restructure] is "Bank_select" ever a real internal object?? */
306 acpi_cm_add_reference (obj_desc->bank_field.container);
307 acpi_cm_add_reference (obj_desc->bank_field.bank_select);
309 /* Debug info */
312 * Store the constructed descriptor (Obj_desc) into the Named_obj whose
313 * handle is on TOS, preserving the current type of that Named_obj.
315 status = acpi_ns_attach_object ((ACPI_HANDLE) node, obj_desc,
316 (u8) acpi_ns_get_type ((ACPI_HANDLE) node));
318 return (status);
322 /*******************************************************************************
324 * FUNCTION: Acpi_aml_prep_index_field_value
326 * PARAMETERS: Node - Owning Node
327 * Index_reg - Index register
328 * Data_reg - Data register
329 * Field_flags - Access, Lock_rule, or Update_rule
330 * Field_position - Field position
331 * Field_length - Field length
333 * RETURN: Status
335 * DESCRIPTION: Construct an ACPI_OPERAND_OBJECT of type Index_field and
336 * connect it to the parent Node.
338 ******************************************************************************/
340 ACPI_STATUS
341 acpi_aml_prep_index_field_value (
342 ACPI_NAMESPACE_NODE *node,
343 ACPI_HANDLE index_reg,
344 ACPI_HANDLE data_reg,
345 u8 field_flags,
346 u8 field_attribute,
347 u32 field_position,
348 u32 field_length)
350 ACPI_OPERAND_OBJECT *obj_desc;
351 ACPI_STATUS status;
354 /* Parameter validation */
356 if (!index_reg || !data_reg) {
357 return (AE_AML_NO_OPERAND);
360 /* Allocate a new object descriptor */
362 obj_desc = acpi_cm_create_internal_object (INTERNAL_TYPE_INDEX_FIELD);
363 if (!obj_desc) {
364 return (AE_NO_MEMORY);
367 /* Initialize areas of the object that are common to all fields */
369 status = acpi_aml_prep_common_field_object (obj_desc, field_flags, field_attribute,
370 field_position, field_length);
371 if (ACPI_FAILURE (status)) {
372 return (status);
375 /* Initialize areas of the object that are specific to this field type */
377 obj_desc->index_field.value = (u32) (field_position /
378 obj_desc->field.granularity);
379 obj_desc->index_field.index = index_reg;
380 obj_desc->index_field.data = data_reg;
382 /* Debug info */
385 * Store the constructed descriptor (Obj_desc) into the Named_obj whose
386 * handle is on TOS, preserving the current type of that Named_obj.
388 status = acpi_ns_attach_object ((ACPI_HANDLE) node, obj_desc,
389 (u8) acpi_ns_get_type ((ACPI_HANDLE) node));
391 return (status);