More Makefile cleanups, otherwise mainly noticeable are the netfilter fix
[davej-history.git] / drivers / acpi / interpreter / amprep.c
blob266cb0105e6831d98bd8e099e86f185fd4e653c8
2 /******************************************************************************
4 * Module Name: amprep - ACPI AML (p-code) execution - field prep utilities
5 * $Revision: 72 $
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,
54 u16 length)
57 switch (access)
59 case ACCESS_ANY_ACC:
60 if (length <= 8) {
61 return (8);
63 else if (length <= 16) {
64 return (16);
66 else if (length <= 32) {
67 return (32);
69 else {
70 return (8);
72 break;
74 case ACCESS_BYTE_ACC:
75 return (8);
76 break;
78 case ACCESS_WORD_ACC:
79 return (16);
80 break;
82 case ACCESS_DWORD_ACC:
83 return (32);
84 break;
86 default:
87 /* Invalid field access type */
89 return (0);
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
105 * RETURN: Status
107 * DESCRIPTION: Initialize the areas of the field object that are common
108 * to the various types of fields.
110 ******************************************************************************/
112 static ACPI_STATUS
113 acpi_aml_prep_common_field_object (
114 ACPI_OPERAND_OBJECT *obj_desc,
115 u8 field_flags,
116 u8 field_attribute,
117 u32 field_position,
118 u32 field_length)
120 u32 granularity;
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)
135 >> LOCK_RULE_SHIFT);
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);
147 if (!granularity) {
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;
158 return (AE_OK);
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
174 * RETURN: Status
176 * DESCRIPTION: Construct an ACPI_OPERAND_OBJECT of type Def_field and
177 * connect it to the parent Node.
179 ******************************************************************************/
181 ACPI_STATUS
182 acpi_aml_prep_def_field_value (
183 ACPI_NAMESPACE_NODE *node,
184 ACPI_HANDLE region,
185 u8 field_flags,
186 u8 field_attribute,
187 u32 field_position,
188 u32 field_length)
190 ACPI_OPERAND_OBJECT *obj_desc;
191 u32 type;
192 ACPI_STATUS status;
195 /* Parameter validation */
197 if (!region) {
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);
209 if (!obj_desc) {
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)) {
221 return (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);
233 /* Debug info */
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));
242 return (status);
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
258 * RETURN: Status
260 * DESCRIPTION: Construct an ACPI_OPERAND_OBJECT of type Bank_field and
261 * connect it to the parent Node.
263 ******************************************************************************/
265 ACPI_STATUS
266 acpi_aml_prep_bank_field_value (
267 ACPI_NAMESPACE_NODE *node,
268 ACPI_HANDLE region,
269 ACPI_HANDLE bank_reg,
270 u32 bank_val,
271 u8 field_flags,
272 u8 field_attribute,
273 u32 field_position,
274 u32 field_length)
276 ACPI_OPERAND_OBJECT *obj_desc;
277 u32 type;
278 ACPI_STATUS status;
281 /* Parameter validation */
283 if (!region) {
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);
295 if (!obj_desc) {
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)) {
306 return (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);
321 /* Debug info */
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));
330 return (status);
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
345 * RETURN: Status
347 * DESCRIPTION: Construct an ACPI_OPERAND_OBJECT of type Index_field and
348 * connect it to the parent Node.
350 ******************************************************************************/
352 ACPI_STATUS
353 acpi_aml_prep_index_field_value (
354 ACPI_NAMESPACE_NODE *node,
355 ACPI_HANDLE index_reg,
356 ACPI_HANDLE data_reg,
357 u8 field_flags,
358 u8 field_attribute,
359 u32 field_position,
360 u32 field_length)
362 ACPI_OPERAND_OBJECT *obj_desc;
363 ACPI_STATUS status;
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);
375 if (!obj_desc) {
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)) {
384 return (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;
394 /* Debug info */
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));
403 return (status);