Linux Audio

Check our new training course

Embedded Linux Audio

Check our new training course
with Creative Commons CC-BY-SA
lecture materials

Bootlin logo

Elixir Cross Referencer

Loading...
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405

/******************************************************************************
 *
 * Module Name: amprep - ACPI AML (p-code) execution - field prep utilities
 *              $Revision: 73 $
 *
 *****************************************************************************/

/*
 *  Copyright (C) 2000, 2001 R. Byron Moore
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */


#include "acpi.h"
#include "acinterp.h"
#include "amlcode.h"
#include "acnamesp.h"
#include "acparser.h"


#define _COMPONENT          INTERPRETER
	 MODULE_NAME         ("amprep")


/*******************************************************************************
 *
 * FUNCTION:    Acpi_aml_decode_field_access_type
 *
 * PARAMETERS:  Access          - Encoded field access bits
 *
 * RETURN:      Field granularity (8, 16, or 32)
 *
 * DESCRIPTION: Decode the Access_type bits of a field definition.
 *
 ******************************************************************************/

static u32
acpi_aml_decode_field_access_type (
	u32                     access,
	u16                     length)
{

	switch (access)
	{
	case ACCESS_ANY_ACC:
		if (length <= 8) {
			return (8);
		}
		else if (length <= 16) {
			return (16);
		}
		else if (length <= 32) {
			return (32);
		}
		else {
			return (8);
		}
		break;

	case ACCESS_BYTE_ACC:
		return (8);
		break;

	case ACCESS_WORD_ACC:
		return (16);
		break;

	case ACCESS_DWORD_ACC:
		return (32);
		break;

	default:
		/* Invalid field access type */

		return (0);
	}
}


/*******************************************************************************
 *
 * FUNCTION:    Acpi_aml_prep_common_field_objec
 *
 * PARAMETERS:  Obj_desc            - The field object
 *              Field_flags         - Access, Lock_rule, or Update_rule.
 *                                    The format of a Field_flag is described
 *                                    in the ACPI specification
 *              Field_position      - Field position
 *              Field_length        - Field length
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Initialize the areas of the field object that are common
 *              to the various types of fields.
 *
 ******************************************************************************/

static ACPI_STATUS
acpi_aml_prep_common_field_object (
	ACPI_OPERAND_OBJECT     *obj_desc,
	u8                      field_flags,
	u8                      field_attribute,
	u32                     field_position,
	u32                     field_length)
{
	u32                     granularity;


	/*
	 * Note: the structure being initialized is the
	 * ACPI_COMMON_FIELD_INFO;  Therefore, we can just use the Field union to
	 * access this common area.  No structure fields outside of the common area
	 * are initialized by this procedure.
	 */

	/* Decode the Field_flags */

	obj_desc->field.access          = (u8) ((field_flags & ACCESS_TYPE_MASK)
			 >> ACCESS_TYPE_SHIFT);
	obj_desc->field.lock_rule       = (u8) ((field_flags & LOCK_RULE_MASK)
			 >> LOCK_RULE_SHIFT);
	obj_desc->field.update_rule     = (u8) ((field_flags & UPDATE_RULE_MASK)
			 >> UPDATE_RULE_SHIFT);

	/* Other misc fields */

	obj_desc->field.length          = (u16) field_length;
	obj_desc->field.access_attribute = field_attribute;

	/* Decode the access type so we can compute offsets */

	granularity = acpi_aml_decode_field_access_type (obj_desc->field.access, obj_desc->field.length);
	if (!granularity) {
		return (AE_AML_OPERAND_VALUE);
	}

	/* Access granularity based fields */

	obj_desc->field.granularity     = (u8) granularity;
	obj_desc->field.bit_offset      = (u8) (field_position % granularity);
	obj_desc->field.offset          = (u32) field_position / granularity;


	return (AE_OK);
}


/*******************************************************************************
 *
 * FUNCTION:    Acpi_aml_prep_def_field_value
 *
 * PARAMETERS:  Node            - Owning Node
 *              Region              - Region in which field is being defined
 *              Field_flags         - Access, Lock_rule, or Update_rule.
 *                                    The format of a Field_flag is described
 *                                    in the ACPI specification
 *              Field_position      - Field position
 *              Field_length        - Field length
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Construct an ACPI_OPERAND_OBJECT  of type Def_field and
 *              connect it to the parent Node.
 *
 ******************************************************************************/

ACPI_STATUS
acpi_aml_prep_def_field_value (
	ACPI_NAMESPACE_NODE     *node,
	ACPI_HANDLE             region,
	u8                      field_flags,
	u8                      field_attribute,
	u32                     field_position,
	u32                     field_length)
{
	ACPI_OPERAND_OBJECT     *obj_desc;
	u32                     type;
	ACPI_STATUS             status;


	/* Parameter validation */

	if (!region) {
		return (AE_AML_NO_OPERAND);
	}

	type = acpi_ns_get_type (region);
	if (type != ACPI_TYPE_REGION) {
		return (AE_AML_OPERAND_TYPE);
	}

	/* Allocate a new object */

	obj_desc = acpi_cm_create_internal_object (INTERNAL_TYPE_DEF_FIELD);
	if (!obj_desc) {
		return (AE_NO_MEMORY);
	}


	/* Obj_desc and Region valid */

	/* Initialize areas of the object that are common to all fields */

	status = acpi_aml_prep_common_field_object (obj_desc, field_flags, field_attribute,
			  field_position, field_length);
	if (ACPI_FAILURE (status)) {
		return (status);
	}

	/* Initialize areas of the object that are specific to this field type */

	obj_desc->field.container = acpi_ns_get_attached_object (region);

	/* An additional reference for the container */

	acpi_cm_add_reference (obj_desc->field.container);


	/* Debug info */

	/*
	 * Store the constructed descriptor (Obj_desc) into the Named_obj whose
	 * handle is on TOS, preserving the current type of that Named_obj.
	 */
	status = acpi_ns_attach_object ((ACPI_HANDLE) node, obj_desc,
			  (u8) acpi_ns_get_type ((ACPI_HANDLE) node));

	return (status);
}


/*******************************************************************************
 *
 * FUNCTION:    Acpi_aml_prep_bank_field_value
 *
 * PARAMETERS:  Node            - Owning Node
 *              Region              - Region in which field is being defined
 *              Bank_reg            - Bank selection register
 *              Bank_val            - Value to store in selection register
 *              Field_flags         - Access, Lock_rule, or Update_rule
 *              Field_position      - Field position
 *              Field_length        - Field length
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Construct an ACPI_OPERAND_OBJECT  of type Bank_field and
 *              connect it to the parent Node.
 *
 ******************************************************************************/

ACPI_STATUS
acpi_aml_prep_bank_field_value (
	ACPI_NAMESPACE_NODE     *node,
	ACPI_HANDLE             region,
	ACPI_HANDLE             bank_reg,
	u32                     bank_val,
	u8                      field_flags,
	u8                      field_attribute,
	u32                     field_position,
	u32                     field_length)
{
	ACPI_OPERAND_OBJECT     *obj_desc;
	u32                     type;
	ACPI_STATUS             status;


	/* Parameter validation */

	if (!region) {
		return (AE_AML_NO_OPERAND);
	}

	type = acpi_ns_get_type (region);
	if (type != ACPI_TYPE_REGION) {
		return (AE_AML_OPERAND_TYPE);
	}

	/* Allocate a new object */

	obj_desc = acpi_cm_create_internal_object (INTERNAL_TYPE_BANK_FIELD);
	if (!obj_desc) {
		return (AE_NO_MEMORY);
	}

	/*  Obj_desc and Region valid   */

	/* Initialize areas of the object that are common to all fields */

	status = acpi_aml_prep_common_field_object (obj_desc, field_flags, field_attribute,
			  field_position, field_length);
	if (ACPI_FAILURE (status)) {
		return (status);
	}

	/* Initialize areas of the object that are specific to this field type */

	obj_desc->bank_field.value      = bank_val;
	obj_desc->bank_field.container  = acpi_ns_get_attached_object (region);
	obj_desc->bank_field.bank_select = acpi_ns_get_attached_object (bank_reg);

	/* An additional reference for the container and bank select */
	/* TBD: [Restructure] is "Bank_select" ever a real internal object?? */

	acpi_cm_add_reference (obj_desc->bank_field.container);
	acpi_cm_add_reference (obj_desc->bank_field.bank_select);

	/* Debug info */

	/*
	 * Store the constructed descriptor (Obj_desc) into the Named_obj whose
	 * handle is on TOS, preserving the current type of that Named_obj.
	 */
	status = acpi_ns_attach_object ((ACPI_HANDLE) node, obj_desc,
			 (u8) acpi_ns_get_type ((ACPI_HANDLE) node));

	return (status);
}


/*******************************************************************************
 *
 * FUNCTION:    Acpi_aml_prep_index_field_value
 *
 * PARAMETERS:  Node            - Owning Node
 *              Index_reg           - Index register
 *              Data_reg            - Data register
 *              Field_flags         - Access, Lock_rule, or Update_rule
 *              Field_position      - Field position
 *              Field_length        - Field length
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Construct an ACPI_OPERAND_OBJECT  of type Index_field and
 *              connect it to the parent Node.
 *
 ******************************************************************************/

ACPI_STATUS
acpi_aml_prep_index_field_value (
	ACPI_NAMESPACE_NODE     *node,
	ACPI_HANDLE             index_reg,
	ACPI_HANDLE             data_reg,
	u8                      field_flags,
	u8                      field_attribute,
	u32                     field_position,
	u32                     field_length)
{
	ACPI_OPERAND_OBJECT     *obj_desc;
	ACPI_STATUS             status;


	/* Parameter validation */

	if (!index_reg || !data_reg) {
		return (AE_AML_NO_OPERAND);
	}

	/* Allocate a new object descriptor */

	obj_desc = acpi_cm_create_internal_object (INTERNAL_TYPE_INDEX_FIELD);
	if (!obj_desc) {
		return (AE_NO_MEMORY);
	}

	/* Initialize areas of the object that are common to all fields */

	status = acpi_aml_prep_common_field_object (obj_desc, field_flags, field_attribute,
			  field_position, field_length);
	if (ACPI_FAILURE (status)) {
		return (status);
	}

	/* Initialize areas of the object that are specific to this field type */

	obj_desc->index_field.value     = (u32) (field_position /
			   obj_desc->field.granularity);
	obj_desc->index_field.index     = index_reg;
	obj_desc->index_field.data      = data_reg;

	/* Debug info */

	/*
	 * Store the constructed descriptor (Obj_desc) into the Named_obj whose
	 * handle is on TOS, preserving the current type of that Named_obj.
	 */
	status = acpi_ns_attach_object ((ACPI_HANDLE) node, obj_desc,
			 (u8) acpi_ns_get_type ((ACPI_HANDLE) node));

	return (status);
}