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
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
|
/******************************************************************************
*
* Module Name: amstoren - AML Interpreter object store support,
* Store to Node (namespace object)
* $Revision: 24 $
*
*****************************************************************************/
/*
* Copyright (C) 2000 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 "acparser.h"
#include "acdispat.h"
#include "acinterp.h"
#include "amlcode.h"
#include "acnamesp.h"
#include "actables.h"
#define _COMPONENT INTERPRETER
MODULE_NAME ("amstoren")
/*******************************************************************************
*
* FUNCTION: Acpi_aml_store_object_to_node
*
* PARAMETERS: *Val_desc - Value to be stored
* *Node - Named object to recieve the value
*
* RETURN: Status
*
* DESCRIPTION: Store the object to the named object.
*
* The Assignment of an object to a named object is handled here
* The val passed in will replace the current value (if any)
* with the input value.
*
* When storing into an object the data is converted to the
* target object type then stored in the object. This means
* that the target object type (for an initialized target) will
* not be changed by a store operation.
*
* NOTE: the global lock is acquired early. This will result
* in the global lock being held a bit longer. Also, if the
* function fails during set up we may get the lock when we
* don't really need it. I don't think we care.
*
******************************************************************************/
ACPI_STATUS
acpi_aml_store_object_to_node (
ACPI_OPERAND_OBJECT *val_desc,
ACPI_NAMESPACE_NODE *node,
ACPI_WALK_STATE *walk_state)
{
ACPI_STATUS status = AE_OK;
u8 *buffer = NULL;
u32 length = 0;
u32 mask;
u32 new_value;
u8 locked = FALSE;
u8 *location=NULL;
ACPI_OPERAND_OBJECT *dest_desc;
OBJECT_TYPE_INTERNAL destination_type = ACPI_TYPE_ANY;
/*
* Assuming the parameters are valid!!!
*/
ACPI_ASSERT((node) && (val_desc));
destination_type = acpi_ns_get_type (node);
/*
* First ensure we have a value that can be stored in the target
*/
switch (destination_type)
{
/* Type of Name's existing value */
case INTERNAL_TYPE_ALIAS:
/*
* Aliases are resolved by Acpi_aml_prep_operands
*/
status = AE_AML_INTERNAL;
break;
case INTERNAL_TYPE_BANK_FIELD:
case INTERNAL_TYPE_INDEX_FIELD:
case ACPI_TYPE_FIELD_UNIT:
case ACPI_TYPE_NUMBER:
/*
* These cases all require only number values or values that
* can be converted to numbers.
*
* If value is not a Number, try to resolve it to one.
*/
if (val_desc->common.type != ACPI_TYPE_NUMBER) {
/*
* Initially not a number, convert
*/
status = acpi_aml_resolve_to_value (&val_desc, walk_state);
if (ACPI_SUCCESS (status) &&
(val_desc->common.type != ACPI_TYPE_NUMBER))
{
/*
* Conversion successful but still not a number
*/
status = AE_AML_OPERAND_TYPE;
}
}
break;
case ACPI_TYPE_STRING:
case ACPI_TYPE_BUFFER:
case INTERNAL_TYPE_DEF_FIELD:
/*
* Storing into a Field in a region or into a buffer or into
* a string all is essentially the same.
*
* If value is not a valid type, try to resolve it to one.
*/
if ((val_desc->common.type != ACPI_TYPE_NUMBER) &&
(val_desc->common.type != ACPI_TYPE_BUFFER) &&
(val_desc->common.type != ACPI_TYPE_STRING))
{
/*
* Initially not a valid type, convert
*/
status = acpi_aml_resolve_to_value (&val_desc, walk_state);
if (ACPI_SUCCESS (status) &&
(val_desc->common.type != ACPI_TYPE_NUMBER) &&
(val_desc->common.type != ACPI_TYPE_BUFFER) &&
(val_desc->common.type != ACPI_TYPE_STRING))
{
/*
* Conversion successful but still not a valid type
*/
status = AE_AML_OPERAND_TYPE;
}
}
break;
case ACPI_TYPE_PACKAGE:
/*
* TBD: [Unhandled] Not real sure what to do here
*/
status = AE_NOT_IMPLEMENTED;
break;
default:
/*
* All other types than Alias and the various Fields come here.
* Store Val_desc as the new value of the Name, and set
* the Name's type to that of the value being stored in it.
* Val_desc reference count is incremented by Attach_object.
*/
status = acpi_ns_attach_object (node, val_desc, val_desc->common.type);
goto clean_up_and_bail_out;
break;
}
/* Exit now if failure above */
if (ACPI_FAILURE (status)) {
goto clean_up_and_bail_out;
}
/*
* Get descriptor for object attached to Node
*/
dest_desc = acpi_ns_get_attached_object (node);
if (!dest_desc) {
/*
* There is no existing object attached to this Node
*/
status = AE_AML_INTERNAL;
goto clean_up_and_bail_out;
}
/*
* Make sure the destination Object is the same as the Node
*/
if (dest_desc->common.type != (u8) destination_type) {
status = AE_AML_INTERNAL;
goto clean_up_and_bail_out;
}
/*
* Acpi_everything is ready to execute now, We have
* a value we can handle, just perform the update
*/
switch (destination_type)
{
/* Type of Name's existing value */
case INTERNAL_TYPE_BANK_FIELD:
/*
* Get the global lock if needed
*/
locked = acpi_aml_acquire_global_lock (dest_desc->bank_field.lock_rule);
/*
* Set Bank value to select proper Bank
* Perform the update (Set Bank Select)
*/
status = acpi_aml_access_named_field (ACPI_WRITE,
dest_desc->bank_field.bank_select,
&dest_desc->bank_field.value,
sizeof (dest_desc->bank_field.value));
if (ACPI_SUCCESS (status)) {
/* Set bank select successful, set data value */
status = acpi_aml_access_named_field (ACPI_WRITE,
dest_desc->bank_field.bank_select,
&val_desc->bank_field.value,
sizeof (val_desc->bank_field.value));
}
break;
case INTERNAL_TYPE_DEF_FIELD:
/*
* Get the global lock if needed
*/
locked = acpi_aml_acquire_global_lock (val_desc->field.lock_rule);
/*
* Perform the update
*/
switch (val_desc->common.type)
{
case ACPI_TYPE_NUMBER:
buffer = (u8 *) &val_desc->number.value;
length = sizeof (val_desc->number.value);
break;
case ACPI_TYPE_BUFFER:
buffer = (u8 *) val_desc->buffer.pointer;
length = val_desc->buffer.length;
break;
case ACPI_TYPE_STRING:
buffer = (u8 *) val_desc->string.pointer;
length = val_desc->string.length;
break;
}
status = acpi_aml_access_named_field (ACPI_WRITE,
node, buffer, length);
break; /* Global Lock released below */
case ACPI_TYPE_STRING:
/*
* Perform the update
*/
switch (val_desc->common.type)
{
case ACPI_TYPE_NUMBER:
buffer = (u8 *) &val_desc->number.value;
length = sizeof (val_desc->number.value);
break;
case ACPI_TYPE_BUFFER:
buffer = (u8 *) val_desc->buffer.pointer;
length = val_desc->buffer.length;
break;
case ACPI_TYPE_STRING:
buffer = (u8 *) val_desc->string.pointer;
length = val_desc->string.length;
break;
}
/*
* Setting a string value replaces the old string
*/
if (length < dest_desc->string.length) {
/*
* Zero fill, not willing to do pointer arithmetic for
* archetecture independance. Just clear the whole thing
*/
MEMSET(dest_desc->string.pointer, 0, dest_desc->string.length);
MEMCPY(dest_desc->string.pointer, buffer, length);
}
else {
/*
* Free the current buffer, then allocate a buffer
* large enough to hold the value
*/
if ( dest_desc->string.pointer &&
!acpi_tb_system_table_pointer (dest_desc->string.pointer))
{
/*
* Only free if not a pointer into the DSDT
*/
acpi_cm_free(dest_desc->string.pointer);
}
dest_desc->string.pointer = acpi_cm_allocate (length + 1);
dest_desc->string.length = length;
if (!dest_desc->string.pointer) {
status = AE_NO_MEMORY;
goto clean_up_and_bail_out;
}
MEMCPY(dest_desc->string.pointer, buffer, length);
}
break;
case ACPI_TYPE_BUFFER:
/*
* Perform the update to the buffer
*/
switch (val_desc->common.type)
{
case ACPI_TYPE_NUMBER:
buffer = (u8 *) &val_desc->number.value;
length = sizeof (val_desc->number.value);
break;
case ACPI_TYPE_BUFFER:
buffer = (u8 *) val_desc->buffer.pointer;
length = val_desc->buffer.length;
break;
case ACPI_TYPE_STRING:
buffer = (u8 *) val_desc->string.pointer;
length = val_desc->string.length;
break;
}
/*
* Buffer is a static allocation,
* only place what will fit in the buffer.
*/
if (length <= dest_desc->buffer.length) {
/*
* Zero fill first, not willing to do pointer arithmetic for
* archetecture independence. Just clear the whole thing
*/
MEMSET(dest_desc->buffer.pointer, 0, dest_desc->buffer.length);
MEMCPY(dest_desc->buffer.pointer, buffer, length);
}
else {
/*
* truncate, copy only what will fit
*/
MEMCPY(dest_desc->buffer.pointer, buffer, dest_desc->buffer.length);
}
break;
case INTERNAL_TYPE_INDEX_FIELD:
/*
* Get the global lock if needed
*/
locked = acpi_aml_acquire_global_lock (dest_desc->index_field.lock_rule);
/*
* Set Index value to select proper Data register
* perform the update (Set index)
*/
status = acpi_aml_access_named_field (ACPI_WRITE,
dest_desc->index_field.index,
&dest_desc->index_field.value,
sizeof (dest_desc->index_field.value));
if (ACPI_SUCCESS (status)) {
/* set index successful, next set Data value */
status = acpi_aml_access_named_field (ACPI_WRITE,
dest_desc->index_field.data,
&val_desc->number.value,
sizeof (val_desc->number.value));
}
break;
case ACPI_TYPE_FIELD_UNIT:
/*
* If the Field Buffer and Index have not been previously evaluated,
* evaluate them and save the results.
*/
if (!(dest_desc->common.flags & AOPOBJ_DATA_VALID)) {
status = acpi_ds_get_field_unit_arguments (dest_desc);
if (ACPI_FAILURE (status)) {
return (status);
}
}
if ((!dest_desc->field_unit.container ||
ACPI_TYPE_BUFFER != dest_desc->field_unit.container->common.type))
{
status = AE_AML_INTERNAL;
goto clean_up_and_bail_out;
}
/*
* Get the global lock if needed
*/
locked = acpi_aml_acquire_global_lock (dest_desc->field_unit.lock_rule);
/*
* TBD: [Unhandled] REMOVE this limitation
* Make sure the operation is within the limits of our implementation
* this is not a Spec limitation!!
*/
if (dest_desc->field_unit.length + dest_desc->field_unit.bit_offset > 32) {
status = AE_NOT_IMPLEMENTED;
goto clean_up_and_bail_out;
}
/* Field location is (base of buffer) + (byte offset) */
location = dest_desc->field_unit.container->buffer.pointer
+ dest_desc->field_unit.offset;
/*
* Construct Mask with 1 bits where the field is,
* 0 bits elsewhere
*/
mask = ((u32) 1 << dest_desc->field_unit.length) - ((u32)1
<< dest_desc->field_unit.bit_offset);
/* Zero out the field in the buffer */
MOVE_UNALIGNED32_TO_32 (&new_value, location);
new_value &= ~mask;
/*
* Shift and mask the new value into position,
* and or it into the buffer.
*/
new_value |= (val_desc->number.value << dest_desc->field_unit.bit_offset) &
mask;
/* Store back the value */
MOVE_UNALIGNED32_TO_32 (location, &new_value);
break;
case ACPI_TYPE_NUMBER:
dest_desc->number.value = val_desc->number.value;
/* Truncate value if we are executing from a 32-bit ACPI table */
acpi_aml_truncate_for32bit_table (dest_desc, walk_state);
break;
case ACPI_TYPE_PACKAGE:
/*
* TBD: [Unhandled] Not real sure what to do here
*/
status = AE_NOT_IMPLEMENTED;
break;
default:
/*
* All other types than Alias and the various Fields come here.
* Store Val_desc as the new value of the Name, and set
* the Name's type to that of the value being stored in it.
* Val_desc reference count is incremented by Attach_object.
*/
status = AE_NOT_IMPLEMENTED;
break;
}
clean_up_and_bail_out:
/*
* Release global lock if we acquired it earlier
*/
acpi_aml_release_global_lock (locked);
return (status);
}
|