:pserver:cvsanon@mok.lvcm.com:/CVS/ReactOS reactos
[reactos.git] / drivers / bus / acpi / executer / amstoren.c
1
2 /******************************************************************************
3  *
4  * Module Name: amstoren - AML Interpreter object store support,
5  *                        Store to Node (namespace object)
6  *              $Revision$
7  *
8  *****************************************************************************/
9
10 /*
11  *  Copyright (C) 2000, 2001 R. Byron Moore
12  *
13  *  This program is free software; you can redistribute it and/or modify
14  *  it under the terms of the GNU General Public License as published by
15  *  the Free Software Foundation; either version 2 of the License, or
16  *  (at your option) any later version.
17  *
18  *  This program is distributed in the hope that it will be useful,
19  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
20  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  *  GNU General Public License for more details.
22  *
23  *  You should have received a copy of the GNU General Public License
24  *  along with this program; if not, write to the Free Software
25  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26  */
27
28
29 #include "acpi.h"
30 #include "acparser.h"
31 #include "acdispat.h"
32 #include "acinterp.h"
33 #include "amlcode.h"
34 #include "acnamesp.h"
35 #include "actables.h"
36
37
38 #define _COMPONENT          ACPI_EXECUTER
39          MODULE_NAME         ("amstoren")
40
41
42 /*******************************************************************************
43  *
44  * FUNCTION:    Acpi_aml_resolve_object
45  *
46  * PARAMETERS:  Source_desc_ptr     - Pointer to the source object
47  *              Target_type         - Current type of the target
48  *              Walk_state          - Current walk state
49  *
50  * RETURN:      Status, resolved object in Source_desc_ptr.
51  *
52  * DESCRIPTION: Resolve an object.  If the object is a reference, dereference
53  *              it and return the actual object in the Source_desc_ptr.
54  *
55  ******************************************************************************/
56
57 ACPI_STATUS
58 acpi_aml_resolve_object (
59         ACPI_OPERAND_OBJECT     **source_desc_ptr,
60         OBJECT_TYPE_INTERNAL    target_type,
61         ACPI_WALK_STATE         *walk_state)
62 {
63         ACPI_OPERAND_OBJECT     *source_desc = *source_desc_ptr;
64         ACPI_STATUS             status = AE_OK;
65
66
67         /*
68          * Ensure we have a Source that can be stored in the target
69          */
70         switch (target_type) {
71
72         /* This case handles the "interchangeable" types Integer, String, and Buffer. */
73
74         /*
75          * These cases all require only Integers or values that
76          * can be converted to Integers (Strings or Buffers)
77          */
78         case ACPI_TYPE_INTEGER:
79         case ACPI_TYPE_FIELD_UNIT:
80         case INTERNAL_TYPE_BANK_FIELD:
81         case INTERNAL_TYPE_INDEX_FIELD:
82
83         /*
84          * Stores into a Field/Region or into a Buffer/String
85          * are all essentially the same.
86          */
87         case ACPI_TYPE_STRING:
88         case ACPI_TYPE_BUFFER:
89         case INTERNAL_TYPE_DEF_FIELD:
90
91                 /*
92                  * If Source_desc is not a valid type, try to resolve it to one.
93                  */
94                 if ((source_desc->common.type != ACPI_TYPE_INTEGER)    &&
95                         (source_desc->common.type != ACPI_TYPE_BUFFER)     &&
96                         (source_desc->common.type != ACPI_TYPE_STRING)) {
97                         /*
98                          * Initially not a valid type, convert
99                          */
100                         status = acpi_aml_resolve_to_value (source_desc_ptr, walk_state);
101                         if (ACPI_SUCCESS (status) &&
102                                 (source_desc->common.type != ACPI_TYPE_INTEGER)    &&
103                                 (source_desc->common.type != ACPI_TYPE_BUFFER)     &&
104                                 (source_desc->common.type != ACPI_TYPE_STRING)) {
105                                 /*
106                                  * Conversion successful but still not a valid type
107                                  */
108                                 status = AE_AML_OPERAND_TYPE;
109                         }
110                 }
111                 break;
112
113
114         case INTERNAL_TYPE_ALIAS:
115
116                 /*
117                  * Aliases are resolved by Acpi_aml_prep_operands
118                  */
119                 status = AE_AML_INTERNAL;
120                 break;
121
122
123         case ACPI_TYPE_PACKAGE:
124         default:
125
126                 /*
127                  * All other types than Alias and the various Fields come here,
128                  * including the untyped case - ACPI_TYPE_ANY.
129                  */
130                 break;
131         }
132
133         return (status);
134 }
135
136
137 /*******************************************************************************
138  *
139  * FUNCTION:    Acpi_aml_store_object
140  *
141  * PARAMETERS:  Source_desc         - Object to store
142  *              Target_type         - Current type of the target
143  *              Target_desc_ptr     - Pointer to the target
144  *              Walk_state          - Current walk state
145  *
146  * RETURN:      Status
147  *
148  * DESCRIPTION: "Store" an object to another object.  This may include
149  *              converting the source type to the target type (implicit
150  *              conversion), and a copy of the value of the source to
151  *              the target.
152  *
153  ******************************************************************************/
154
155 ACPI_STATUS
156 acpi_aml_store_object (
157         ACPI_OPERAND_OBJECT     *source_desc,
158         OBJECT_TYPE_INTERNAL    target_type,
159         ACPI_OPERAND_OBJECT     **target_desc_ptr,
160         ACPI_WALK_STATE         *walk_state)
161 {
162         ACPI_OPERAND_OBJECT     *target_desc = *target_desc_ptr;
163         ACPI_STATUS             status = AE_OK;
164
165
166         /*
167          * Perform the "implicit conversion" of the source to the current type
168          * of the target - As per the ACPI specification.
169          *
170          * If no conversion performed, Source_desc is left alone, otherwise it
171          * is updated with a new object.
172          */
173         status = acpi_aml_convert_to_target_type (target_type, &source_desc, walk_state);
174         if (ACPI_FAILURE (status)) {
175                 return (status);
176         }
177
178         /*
179          * We now have two objects of identical types, and we can perform a
180          * copy of the *value* of the source object.
181          */
182         switch (target_type) {
183         case ACPI_TYPE_ANY:
184         case INTERNAL_TYPE_DEF_ANY:
185
186                 /*
187                  * The target namespace node is uninitialized (has no target object),
188                  * and will take on the type of the source object
189                  */
190
191                 *target_desc_ptr = source_desc;
192                 break;
193
194
195         case ACPI_TYPE_INTEGER:
196
197                 target_desc->integer.value = source_desc->integer.value;
198
199                 /* Truncate value if we are executing from a 32-bit ACPI table */
200
201                 acpi_aml_truncate_for32bit_table (target_desc, walk_state);
202                 break;
203
204
205         case ACPI_TYPE_FIELD_UNIT:
206
207                 status = acpi_aml_copy_integer_to_field_unit (source_desc, target_desc);
208                 break;
209
210
211         case INTERNAL_TYPE_BANK_FIELD:
212
213                 status = acpi_aml_copy_integer_to_bank_field (source_desc, target_desc);
214                 break;
215
216
217         case INTERNAL_TYPE_INDEX_FIELD:
218
219                 status = acpi_aml_copy_integer_to_index_field (source_desc, target_desc);
220                 break;
221
222
223         case ACPI_TYPE_STRING:
224
225                 status = acpi_aml_copy_string_to_string (source_desc, target_desc);
226                 break;
227
228
229         case ACPI_TYPE_BUFFER:
230
231                 status = acpi_aml_copy_buffer_to_buffer (source_desc, target_desc);
232                 break;
233
234
235         case ACPI_TYPE_PACKAGE:
236
237                 /*
238                  * TBD: [Unhandled] Not real sure what to do here
239                  */
240                 status = AE_NOT_IMPLEMENTED;
241                 break;
242
243
244         default:
245
246                 /*
247                  * All other types come here.
248                  */
249                 status = AE_NOT_IMPLEMENTED;
250                 break;
251         }
252
253
254         return (status);
255 }
256
257