aslresource.c revision 1.1.1.2 1 1.1 jruoho
2 1.1 jruoho /******************************************************************************
3 1.1 jruoho *
4 1.1 jruoho * Module Name: aslresource - Resource template/descriptor utilities
5 1.1 jruoho *
6 1.1 jruoho *****************************************************************************/
7 1.1 jruoho
8 1.1.1.2 jruoho /*
9 1.1.1.2 jruoho * Copyright (C) 2000 - 2011, Intel Corp.
10 1.1 jruoho * All rights reserved.
11 1.1 jruoho *
12 1.1.1.2 jruoho * Redistribution and use in source and binary forms, with or without
13 1.1.1.2 jruoho * modification, are permitted provided that the following conditions
14 1.1.1.2 jruoho * are met:
15 1.1.1.2 jruoho * 1. Redistributions of source code must retain the above copyright
16 1.1.1.2 jruoho * notice, this list of conditions, and the following disclaimer,
17 1.1.1.2 jruoho * without modification.
18 1.1.1.2 jruoho * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 1.1.1.2 jruoho * substantially similar to the "NO WARRANTY" disclaimer below
20 1.1.1.2 jruoho * ("Disclaimer") and any redistribution must be conditioned upon
21 1.1.1.2 jruoho * including a substantially similar Disclaimer requirement for further
22 1.1.1.2 jruoho * binary redistribution.
23 1.1.1.2 jruoho * 3. Neither the names of the above-listed copyright holders nor the names
24 1.1.1.2 jruoho * of any contributors may be used to endorse or promote products derived
25 1.1.1.2 jruoho * from this software without specific prior written permission.
26 1.1.1.2 jruoho *
27 1.1.1.2 jruoho * Alternatively, this software may be distributed under the terms of the
28 1.1.1.2 jruoho * GNU General Public License ("GPL") version 2 as published by the Free
29 1.1.1.2 jruoho * Software Foundation.
30 1.1.1.2 jruoho *
31 1.1.1.2 jruoho * NO WARRANTY
32 1.1.1.2 jruoho * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 1.1.1.2 jruoho * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 1.1.1.2 jruoho * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35 1.1.1.2 jruoho * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 1.1.1.2 jruoho * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 1.1.1.2 jruoho * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 1.1.1.2 jruoho * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 1.1.1.2 jruoho * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 1.1.1.2 jruoho * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 1.1.1.2 jruoho * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 1.1.1.2 jruoho * POSSIBILITY OF SUCH DAMAGES.
43 1.1.1.2 jruoho */
44 1.1 jruoho
45 1.1 jruoho
46 1.1 jruoho #include "aslcompiler.h"
47 1.1 jruoho #include "aslcompiler.y.h"
48 1.1 jruoho #include "amlcode.h"
49 1.1 jruoho
50 1.1 jruoho
51 1.1 jruoho #define _COMPONENT ACPI_COMPILER
52 1.1 jruoho ACPI_MODULE_NAME ("aslresource")
53 1.1 jruoho
54 1.1 jruoho
55 1.1 jruoho /*******************************************************************************
56 1.1 jruoho *
57 1.1 jruoho * FUNCTION: RsSmallAddressCheck
58 1.1 jruoho *
59 1.1 jruoho * PARAMETERS: Minimum - Address Min value
60 1.1 jruoho * Maximum - Address Max value
61 1.1 jruoho * Length - Address range value
62 1.1 jruoho * Alignment - Address alignment value
63 1.1 jruoho * MinOp - Original Op for Address Min
64 1.1 jruoho * MaxOp - Original Op for Address Max
65 1.1 jruoho * LengthOp - Original Op for address range
66 1.1 jruoho * AlignOp - Original Op for address alignment. If
67 1.1 jruoho * NULL, means "zero value for alignment is
68 1.1 jruoho * OK, and means 64K alignment" (for
69 1.1 jruoho * Memory24 descriptor)
70 1.1.1.2 jruoho * Op - Parent Op for entire construct
71 1.1 jruoho *
72 1.1 jruoho * RETURN: None. Adds error messages to error log if necessary
73 1.1 jruoho *
74 1.1 jruoho * DESCRIPTION: Perform common value checks for "small" address descriptors.
75 1.1 jruoho * Currently:
76 1.1 jruoho * Io, Memory24, Memory32
77 1.1 jruoho *
78 1.1 jruoho ******************************************************************************/
79 1.1 jruoho
80 1.1 jruoho void
81 1.1 jruoho RsSmallAddressCheck (
82 1.1 jruoho UINT8 Type,
83 1.1 jruoho UINT32 Minimum,
84 1.1 jruoho UINT32 Maximum,
85 1.1 jruoho UINT32 Length,
86 1.1 jruoho UINT32 Alignment,
87 1.1 jruoho ACPI_PARSE_OBJECT *MinOp,
88 1.1 jruoho ACPI_PARSE_OBJECT *MaxOp,
89 1.1 jruoho ACPI_PARSE_OBJECT *LengthOp,
90 1.1.1.2 jruoho ACPI_PARSE_OBJECT *AlignOp,
91 1.1.1.2 jruoho ACPI_PARSE_OBJECT *Op)
92 1.1 jruoho {
93 1.1 jruoho
94 1.1 jruoho if (Gbl_NoResourceChecking)
95 1.1 jruoho {
96 1.1 jruoho return;
97 1.1 jruoho }
98 1.1 jruoho
99 1.1.1.2 jruoho /*
100 1.1.1.2 jruoho * Check for a so-called "null descriptor". These are descriptors that are
101 1.1.1.2 jruoho * created with most fields set to zero. The intent is that the descriptor
102 1.1.1.2 jruoho * will be updated/completed at runtime via a BufferField.
103 1.1.1.2 jruoho *
104 1.1.1.2 jruoho * If the descriptor does NOT have a resource tag, it cannot be referenced
105 1.1.1.2 jruoho * by a BufferField and we will flag this as an error. Conversely, if
106 1.1.1.2 jruoho * the descriptor has a resource tag, we will assume that a BufferField
107 1.1.1.2 jruoho * will be used to dynamically update it, so no error.
108 1.1.1.2 jruoho *
109 1.1.1.2 jruoho * A possible enhancement to this check would be to verify that in fact
110 1.1.1.2 jruoho * a BufferField is created using the resource tag, and perhaps even
111 1.1.1.2 jruoho * verify that a Store is performed to the BufferField.
112 1.1.1.2 jruoho *
113 1.1.1.2 jruoho * Note: for these descriptors, Alignment is allowed to be zero
114 1.1.1.2 jruoho */
115 1.1.1.2 jruoho if (!Minimum && !Maximum && !Length)
116 1.1.1.2 jruoho {
117 1.1.1.2 jruoho if (!Op->Asl.ExternalName)
118 1.1.1.2 jruoho {
119 1.1.1.2 jruoho /* No resource tag. Descriptor is fixed and is also illegal */
120 1.1.1.2 jruoho
121 1.1.1.2 jruoho AslError (ASL_ERROR, ASL_MSG_NULL_DESCRIPTOR, Op, NULL);
122 1.1.1.2 jruoho }
123 1.1.1.2 jruoho
124 1.1.1.2 jruoho return;
125 1.1.1.2 jruoho }
126 1.1.1.2 jruoho
127 1.1 jruoho /* Special case for Memory24, values are compressed */
128 1.1 jruoho
129 1.1 jruoho if (Type == ACPI_RESOURCE_NAME_MEMORY24)
130 1.1 jruoho {
131 1.1 jruoho if (!Alignment) /* Alignment==0 means 64K - no invalid alignment */
132 1.1 jruoho {
133 1.1 jruoho Alignment = ACPI_UINT16_MAX + 1;
134 1.1 jruoho }
135 1.1 jruoho
136 1.1 jruoho Minimum <<= 8;
137 1.1 jruoho Maximum <<= 8;
138 1.1 jruoho Length *= 256;
139 1.1 jruoho }
140 1.1 jruoho
141 1.1 jruoho /* IO descriptor has different definition of min/max, don't check */
142 1.1 jruoho
143 1.1 jruoho if (Type != ACPI_RESOURCE_NAME_IO)
144 1.1 jruoho {
145 1.1 jruoho /* Basic checks on Min/Max/Length */
146 1.1 jruoho
147 1.1 jruoho if (Minimum > Maximum)
148 1.1 jruoho {
149 1.1 jruoho AslError (ASL_ERROR, ASL_MSG_INVALID_MIN_MAX, MinOp, NULL);
150 1.1 jruoho }
151 1.1 jruoho else if (Length > (Maximum - Minimum + 1))
152 1.1 jruoho {
153 1.1 jruoho AslError (ASL_ERROR, ASL_MSG_INVALID_LENGTH, LengthOp, NULL);
154 1.1 jruoho }
155 1.1 jruoho }
156 1.1 jruoho
157 1.1 jruoho /* Alignment of zero is not in ACPI spec, but is used to mean byte acc */
158 1.1 jruoho
159 1.1 jruoho if (!Alignment)
160 1.1 jruoho {
161 1.1 jruoho Alignment = 1;
162 1.1 jruoho }
163 1.1 jruoho
164 1.1 jruoho /* Addresses must be an exact multiple of the alignment value */
165 1.1 jruoho
166 1.1 jruoho if (Minimum % Alignment)
167 1.1 jruoho {
168 1.1 jruoho AslError (ASL_ERROR, ASL_MSG_ALIGNMENT, MinOp, NULL);
169 1.1 jruoho }
170 1.1 jruoho if (Maximum % Alignment)
171 1.1 jruoho {
172 1.1 jruoho AslError (ASL_ERROR, ASL_MSG_ALIGNMENT, MaxOp, NULL);
173 1.1 jruoho }
174 1.1 jruoho }
175 1.1 jruoho
176 1.1 jruoho
177 1.1 jruoho /*******************************************************************************
178 1.1 jruoho *
179 1.1 jruoho * FUNCTION: RsLargeAddressCheck
180 1.1 jruoho *
181 1.1 jruoho * PARAMETERS: Minimum - Address Min value
182 1.1 jruoho * Maximum - Address Max value
183 1.1 jruoho * Length - Address range value
184 1.1 jruoho * Granularity - Address granularity value
185 1.1 jruoho * Flags - General flags for address descriptors:
186 1.1 jruoho * _MIF, _MAF, _DEC
187 1.1 jruoho * MinOp - Original Op for Address Min
188 1.1 jruoho * MaxOp - Original Op for Address Max
189 1.1 jruoho * LengthOp - Original Op for address range
190 1.1 jruoho * GranOp - Original Op for address granularity
191 1.1.1.2 jruoho * Op - Parent Op for entire construct
192 1.1 jruoho *
193 1.1 jruoho * RETURN: None. Adds error messages to error log if necessary
194 1.1 jruoho *
195 1.1 jruoho * DESCRIPTION: Perform common value checks for "large" address descriptors.
196 1.1 jruoho * Currently:
197 1.1 jruoho * WordIo, WordBusNumber, WordSpace
198 1.1 jruoho * DWordIo, DWordMemory, DWordSpace
199 1.1 jruoho * QWordIo, QWordMemory, QWordSpace
200 1.1 jruoho * ExtendedIo, ExtendedMemory, ExtendedSpace
201 1.1 jruoho *
202 1.1 jruoho * _MIF flag set means that the minimum address is fixed and is not relocatable
203 1.1 jruoho * _MAF flag set means that the maximum address is fixed and is not relocatable
204 1.1 jruoho * Length of zero means that the record size is variable
205 1.1 jruoho *
206 1.1 jruoho * This function implements the LEN/MIF/MAF/MIN/MAX/GRA rules within Table 6-40
207 1.1 jruoho * of the ACPI 4.0a specification. Added 04/2010.
208 1.1 jruoho *
209 1.1 jruoho ******************************************************************************/
210 1.1 jruoho
211 1.1 jruoho void
212 1.1 jruoho RsLargeAddressCheck (
213 1.1 jruoho UINT64 Minimum,
214 1.1 jruoho UINT64 Maximum,
215 1.1 jruoho UINT64 Length,
216 1.1 jruoho UINT64 Granularity,
217 1.1 jruoho UINT8 Flags,
218 1.1 jruoho ACPI_PARSE_OBJECT *MinOp,
219 1.1 jruoho ACPI_PARSE_OBJECT *MaxOp,
220 1.1 jruoho ACPI_PARSE_OBJECT *LengthOp,
221 1.1.1.2 jruoho ACPI_PARSE_OBJECT *GranOp,
222 1.1.1.2 jruoho ACPI_PARSE_OBJECT *Op)
223 1.1 jruoho {
224 1.1 jruoho
225 1.1 jruoho if (Gbl_NoResourceChecking)
226 1.1 jruoho {
227 1.1 jruoho return;
228 1.1 jruoho }
229 1.1 jruoho
230 1.1.1.2 jruoho /*
231 1.1.1.2 jruoho * Check for a so-called "null descriptor". These are descriptors that are
232 1.1.1.2 jruoho * created with most fields set to zero. The intent is that the descriptor
233 1.1.1.2 jruoho * will be updated/completed at runtime via a BufferField.
234 1.1.1.2 jruoho *
235 1.1.1.2 jruoho * If the descriptor does NOT have a resource tag, it cannot be referenced
236 1.1.1.2 jruoho * by a BufferField and we will flag this as an error. Conversely, if
237 1.1.1.2 jruoho * the descriptor has a resource tag, we will assume that a BufferField
238 1.1.1.2 jruoho * will be used to dynamically update it, so no error.
239 1.1.1.2 jruoho *
240 1.1.1.2 jruoho * A possible enhancement to this check would be to verify that in fact
241 1.1.1.2 jruoho * a BufferField is created using the resource tag, and perhaps even
242 1.1.1.2 jruoho * verify that a Store is performed to the BufferField.
243 1.1.1.2 jruoho */
244 1.1.1.2 jruoho if (!Minimum && !Maximum && !Length && !Granularity)
245 1.1.1.2 jruoho {
246 1.1.1.2 jruoho if (!Op->Asl.ExternalName)
247 1.1.1.2 jruoho {
248 1.1.1.2 jruoho /* No resource tag. Descriptor is fixed and is also illegal */
249 1.1.1.2 jruoho
250 1.1.1.2 jruoho AslError (ASL_ERROR, ASL_MSG_NULL_DESCRIPTOR, Op, NULL);
251 1.1.1.2 jruoho }
252 1.1.1.2 jruoho
253 1.1.1.2 jruoho return;
254 1.1.1.2 jruoho }
255 1.1.1.2 jruoho
256 1.1 jruoho /* Basic checks on Min/Max/Length */
257 1.1 jruoho
258 1.1 jruoho if (Minimum > Maximum)
259 1.1 jruoho {
260 1.1 jruoho AslError (ASL_ERROR, ASL_MSG_INVALID_MIN_MAX, MinOp, NULL);
261 1.1 jruoho return;
262 1.1 jruoho }
263 1.1 jruoho else if (Length > (Maximum - Minimum + 1))
264 1.1 jruoho {
265 1.1 jruoho AslError (ASL_ERROR, ASL_MSG_INVALID_LENGTH, LengthOp, NULL);
266 1.1 jruoho return;
267 1.1 jruoho }
268 1.1 jruoho
269 1.1 jruoho /* If specified (non-zero), ensure granularity is a power-of-two minus one */
270 1.1 jruoho
271 1.1 jruoho if (Granularity)
272 1.1 jruoho {
273 1.1 jruoho if ((Granularity + 1) &
274 1.1 jruoho Granularity)
275 1.1 jruoho {
276 1.1 jruoho AslError (ASL_ERROR, ASL_MSG_INVALID_GRANULARITY, GranOp, NULL);
277 1.1 jruoho return;
278 1.1 jruoho }
279 1.1 jruoho }
280 1.1 jruoho
281 1.1 jruoho /*
282 1.1 jruoho * Check the various combinations of Length, MinFixed, and MaxFixed
283 1.1 jruoho */
284 1.1 jruoho if (Length)
285 1.1 jruoho {
286 1.1 jruoho /* Fixed non-zero length */
287 1.1 jruoho
288 1.1 jruoho switch (Flags & (ACPI_RESOURCE_FLAG_MIF | ACPI_RESOURCE_FLAG_MAF))
289 1.1 jruoho {
290 1.1 jruoho case 0:
291 1.1 jruoho /*
292 1.1 jruoho * Fixed length, variable locations (both _MIN and _MAX).
293 1.1 jruoho * Length must be a multiple of granularity
294 1.1 jruoho */
295 1.1 jruoho if (Granularity & Length)
296 1.1 jruoho {
297 1.1 jruoho AslError (ASL_ERROR, ASL_MSG_ALIGNMENT, LengthOp, NULL);
298 1.1 jruoho }
299 1.1 jruoho break;
300 1.1 jruoho
301 1.1 jruoho case (ACPI_RESOURCE_FLAG_MIF | ACPI_RESOURCE_FLAG_MAF):
302 1.1 jruoho
303 1.1 jruoho /* Fixed length, fixed location. Granularity must be zero */
304 1.1 jruoho
305 1.1 jruoho if (Granularity != 0)
306 1.1 jruoho {
307 1.1 jruoho AslError (ASL_ERROR, ASL_MSG_INVALID_GRAN_FIXED, GranOp, NULL);
308 1.1 jruoho }
309 1.1 jruoho
310 1.1 jruoho /* Length must be exactly the size of the min/max window */
311 1.1 jruoho
312 1.1 jruoho if (Length != (Maximum - Minimum + 1))
313 1.1 jruoho {
314 1.1 jruoho AslError (ASL_ERROR, ASL_MSG_INVALID_LENGTH_FIXED, LengthOp, NULL);
315 1.1 jruoho }
316 1.1 jruoho break;
317 1.1 jruoho
318 1.1 jruoho /* All other combinations are invalid */
319 1.1 jruoho
320 1.1 jruoho case ACPI_RESOURCE_FLAG_MIF:
321 1.1 jruoho case ACPI_RESOURCE_FLAG_MAF:
322 1.1 jruoho default:
323 1.1 jruoho AslError (ASL_ERROR, ASL_MSG_INVALID_ADDR_FLAGS, LengthOp, NULL);
324 1.1 jruoho }
325 1.1 jruoho }
326 1.1 jruoho else
327 1.1 jruoho {
328 1.1 jruoho /* Variable length (length==0) */
329 1.1 jruoho
330 1.1 jruoho switch (Flags & (ACPI_RESOURCE_FLAG_MIF | ACPI_RESOURCE_FLAG_MAF))
331 1.1 jruoho {
332 1.1 jruoho case 0:
333 1.1 jruoho /*
334 1.1 jruoho * Both _MIN and _MAX are variable.
335 1.1 jruoho * No additional requirements, just exit
336 1.1 jruoho */
337 1.1 jruoho break;
338 1.1 jruoho
339 1.1 jruoho case ACPI_RESOURCE_FLAG_MIF:
340 1.1 jruoho
341 1.1 jruoho /* _MIN is fixed. _MIN must be multiple of _GRA */
342 1.1 jruoho
343 1.1 jruoho /*
344 1.1 jruoho * The granularity is defined by the ACPI specification to be a
345 1.1 jruoho * power-of-two minus one, therefore the granularity is a
346 1.1 jruoho * bitmask which can be used to easily validate the addresses.
347 1.1 jruoho */
348 1.1 jruoho if (Granularity & Minimum)
349 1.1 jruoho {
350 1.1 jruoho AslError (ASL_ERROR, ASL_MSG_ALIGNMENT, MinOp, NULL);
351 1.1 jruoho }
352 1.1 jruoho break;
353 1.1 jruoho
354 1.1 jruoho case ACPI_RESOURCE_FLAG_MAF:
355 1.1 jruoho
356 1.1 jruoho /* _MAX is fixed. (_MAX + 1) must be multiple of _GRA */
357 1.1 jruoho
358 1.1 jruoho if (Granularity & (Maximum + 1))
359 1.1 jruoho {
360 1.1 jruoho AslError (ASL_ERROR, ASL_MSG_ALIGNMENT, MaxOp, "-1");
361 1.1 jruoho }
362 1.1 jruoho break;
363 1.1 jruoho
364 1.1 jruoho /* Both MIF/MAF set is invalid if length is zero */
365 1.1 jruoho
366 1.1 jruoho case (ACPI_RESOURCE_FLAG_MIF | ACPI_RESOURCE_FLAG_MAF):
367 1.1 jruoho default:
368 1.1 jruoho AslError (ASL_ERROR, ASL_MSG_INVALID_ADDR_FLAGS, LengthOp, NULL);
369 1.1 jruoho }
370 1.1 jruoho }
371 1.1 jruoho }
372 1.1 jruoho
373 1.1 jruoho
374 1.1 jruoho /*******************************************************************************
375 1.1 jruoho *
376 1.1 jruoho * FUNCTION: RsGetStringDataLength
377 1.1 jruoho *
378 1.1 jruoho * PARAMETERS: InitializerOp - Start of a subtree of init nodes
379 1.1 jruoho *
380 1.1 jruoho * RETURN: Valid string length if a string node is found (otherwise 0)
381 1.1 jruoho *
382 1.1 jruoho * DESCRIPTION: In a list of peer nodes, find the first one that contains a
383 1.1 jruoho * string and return the length of the string.
384 1.1 jruoho *
385 1.1 jruoho ******************************************************************************/
386 1.1 jruoho
387 1.1 jruoho UINT16
388 1.1 jruoho RsGetStringDataLength (
389 1.1 jruoho ACPI_PARSE_OBJECT *InitializerOp)
390 1.1 jruoho {
391 1.1 jruoho
392 1.1 jruoho while (InitializerOp)
393 1.1 jruoho {
394 1.1 jruoho if (InitializerOp->Asl.ParseOpcode == PARSEOP_STRING_LITERAL)
395 1.1 jruoho {
396 1.1 jruoho return ((UINT16) (strlen (InitializerOp->Asl.Value.String) + 1));
397 1.1 jruoho }
398 1.1 jruoho InitializerOp = ASL_GET_PEER_NODE (InitializerOp);
399 1.1 jruoho }
400 1.1 jruoho
401 1.1 jruoho return 0;
402 1.1 jruoho }
403 1.1 jruoho
404 1.1 jruoho
405 1.1 jruoho /*******************************************************************************
406 1.1 jruoho *
407 1.1 jruoho * FUNCTION: RsAllocateResourceNode
408 1.1 jruoho *
409 1.1 jruoho * PARAMETERS: Size - Size of node in bytes
410 1.1 jruoho *
411 1.1 jruoho * RETURN: The allocated node - aborts on allocation failure
412 1.1 jruoho *
413 1.1 jruoho * DESCRIPTION: Allocate a resource description node and the resource
414 1.1 jruoho * descriptor itself (the nodes are used to link descriptors).
415 1.1 jruoho *
416 1.1 jruoho ******************************************************************************/
417 1.1 jruoho
418 1.1 jruoho ASL_RESOURCE_NODE *
419 1.1 jruoho RsAllocateResourceNode (
420 1.1 jruoho UINT32 Size)
421 1.1 jruoho {
422 1.1 jruoho ASL_RESOURCE_NODE *Rnode;
423 1.1 jruoho
424 1.1 jruoho
425 1.1 jruoho /* Allocate the node */
426 1.1 jruoho
427 1.1 jruoho Rnode = UtLocalCalloc (sizeof (ASL_RESOURCE_NODE));
428 1.1 jruoho
429 1.1 jruoho /* Allocate the resource descriptor itself */
430 1.1 jruoho
431 1.1 jruoho Rnode->Buffer = UtLocalCalloc (Size);
432 1.1 jruoho Rnode->BufferLength = Size;
433 1.1 jruoho
434 1.1 jruoho return (Rnode);
435 1.1 jruoho }
436 1.1 jruoho
437 1.1 jruoho
438 1.1 jruoho /*******************************************************************************
439 1.1 jruoho *
440 1.1 jruoho * FUNCTION: RsCreateBitField
441 1.1 jruoho *
442 1.1 jruoho * PARAMETERS: Op - Resource field node
443 1.1 jruoho * Name - Name of the field (Used only to reference
444 1.1 jruoho * the field in the ASL, not in the AML)
445 1.1 jruoho * ByteOffset - Offset from the field start
446 1.1 jruoho * BitOffset - Additional bit offset
447 1.1 jruoho *
448 1.1 jruoho * RETURN: None, sets fields within the input node
449 1.1 jruoho *
450 1.1 jruoho * DESCRIPTION: Utility function to generate a named bit field within a
451 1.1 jruoho * resource descriptor. Mark a node as 1) a field in a resource
452 1.1 jruoho * descriptor, and 2) set the value to be a BIT offset
453 1.1 jruoho *
454 1.1 jruoho ******************************************************************************/
455 1.1 jruoho
456 1.1 jruoho void
457 1.1 jruoho RsCreateBitField (
458 1.1 jruoho ACPI_PARSE_OBJECT *Op,
459 1.1 jruoho char *Name,
460 1.1 jruoho UINT32 ByteOffset,
461 1.1 jruoho UINT32 BitOffset)
462 1.1 jruoho {
463 1.1 jruoho
464 1.1 jruoho Op->Asl.ExternalName = Name;
465 1.1 jruoho Op->Asl.Value.Integer = ((UINT64) ByteOffset * 8) + BitOffset;
466 1.1 jruoho Op->Asl.CompileFlags |= (NODE_IS_RESOURCE_FIELD | NODE_IS_BIT_OFFSET);
467 1.1 jruoho }
468 1.1 jruoho
469 1.1 jruoho
470 1.1 jruoho /*******************************************************************************
471 1.1 jruoho *
472 1.1 jruoho * FUNCTION: RsCreateByteField
473 1.1 jruoho *
474 1.1 jruoho * PARAMETERS: Op - Resource field node
475 1.1 jruoho * Name - Name of the field (Used only to reference
476 1.1 jruoho * the field in the ASL, not in the AML)
477 1.1 jruoho * ByteOffset - Offset from the field start
478 1.1 jruoho *
479 1.1 jruoho * RETURN: None, sets fields within the input node
480 1.1 jruoho *
481 1.1 jruoho * DESCRIPTION: Utility function to generate a named byte field within a
482 1.1 jruoho * resource descriptor. Mark a node as 1) a field in a resource
483 1.1 jruoho * descriptor, and 2) set the value to be a BYTE offset
484 1.1 jruoho *
485 1.1 jruoho ******************************************************************************/
486 1.1 jruoho
487 1.1 jruoho void
488 1.1 jruoho RsCreateByteField (
489 1.1 jruoho ACPI_PARSE_OBJECT *Op,
490 1.1 jruoho char *Name,
491 1.1 jruoho UINT32 ByteOffset)
492 1.1 jruoho {
493 1.1 jruoho
494 1.1 jruoho Op->Asl.ExternalName = Name;
495 1.1 jruoho Op->Asl.Value.Integer = ByteOffset;
496 1.1 jruoho Op->Asl.CompileFlags |= NODE_IS_RESOURCE_FIELD;
497 1.1 jruoho }
498 1.1 jruoho
499 1.1 jruoho
500 1.1 jruoho /*******************************************************************************
501 1.1 jruoho *
502 1.1 jruoho * FUNCTION: RsSetFlagBits
503 1.1 jruoho *
504 1.1 jruoho * PARAMETERS: *Flags - Pointer to the flag byte
505 1.1 jruoho * Op - Flag initialization node
506 1.1 jruoho * Position - Bit position within the flag byte
507 1.1 jruoho * Default - Used if the node is DEFAULT.
508 1.1 jruoho *
509 1.1 jruoho * RETURN: Sets bits within the *Flags output byte.
510 1.1 jruoho *
511 1.1 jruoho * DESCRIPTION: Set a bit in a cumulative flags word from an initialization
512 1.1 jruoho * node. Will use a default value if the node is DEFAULT, meaning
513 1.1 jruoho * that no value was specified in the ASL. Used to merge multiple
514 1.1 jruoho * keywords into a single flags byte.
515 1.1 jruoho *
516 1.1 jruoho ******************************************************************************/
517 1.1 jruoho
518 1.1 jruoho void
519 1.1 jruoho RsSetFlagBits (
520 1.1 jruoho UINT8 *Flags,
521 1.1 jruoho ACPI_PARSE_OBJECT *Op,
522 1.1 jruoho UINT8 Position,
523 1.1 jruoho UINT8 DefaultBit)
524 1.1 jruoho {
525 1.1 jruoho
526 1.1 jruoho if (Op->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG)
527 1.1 jruoho {
528 1.1 jruoho /* Use the default bit */
529 1.1 jruoho
530 1.1 jruoho *Flags |= (DefaultBit << Position);
531 1.1 jruoho }
532 1.1 jruoho else
533 1.1 jruoho {
534 1.1 jruoho /* Use the bit specified in the initialization node */
535 1.1 jruoho
536 1.1 jruoho *Flags |= (((UINT8) Op->Asl.Value.Integer) << Position);
537 1.1 jruoho }
538 1.1 jruoho }
539 1.1 jruoho
540 1.1 jruoho
541 1.1 jruoho /*******************************************************************************
542 1.1 jruoho *
543 1.1 jruoho * FUNCTION: RsCompleteNodeAndGetNext
544 1.1 jruoho *
545 1.1 jruoho * PARAMETERS: Op - Resource node to be completed
546 1.1 jruoho *
547 1.1 jruoho * RETURN: The next peer to the input node.
548 1.1 jruoho *
549 1.1 jruoho * DESCRIPTION: Mark the current node completed and return the next peer.
550 1.1 jruoho * The node ParseOpcode is set to DEFAULT_ARG, meaning that
551 1.1 jruoho * this node is to be ignored from now on.
552 1.1 jruoho *
553 1.1 jruoho ******************************************************************************/
554 1.1 jruoho
555 1.1 jruoho ACPI_PARSE_OBJECT *
556 1.1 jruoho RsCompleteNodeAndGetNext (
557 1.1 jruoho ACPI_PARSE_OBJECT *Op)
558 1.1 jruoho {
559 1.1 jruoho
560 1.1 jruoho /* Mark this node unused */
561 1.1 jruoho
562 1.1 jruoho Op->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
563 1.1 jruoho
564 1.1 jruoho /* Move on to the next peer node in the initializer list */
565 1.1 jruoho
566 1.1 jruoho return (ASL_GET_PEER_NODE (Op));
567 1.1 jruoho }
568 1.1 jruoho
569 1.1 jruoho
570 1.1 jruoho /*******************************************************************************
571 1.1 jruoho *
572 1.1 jruoho * FUNCTION: RsCheckListForDuplicates
573 1.1 jruoho *
574 1.1 jruoho * PARAMETERS: Op - First op in the initializer list
575 1.1 jruoho *
576 1.1 jruoho * RETURN: None
577 1.1 jruoho *
578 1.1 jruoho * DESCRIPTION: Check an initializer list for duplicate values. Emits an error
579 1.1 jruoho * if any duplicates are found.
580 1.1 jruoho *
581 1.1 jruoho ******************************************************************************/
582 1.1 jruoho
583 1.1 jruoho void
584 1.1 jruoho RsCheckListForDuplicates (
585 1.1 jruoho ACPI_PARSE_OBJECT *Op)
586 1.1 jruoho {
587 1.1 jruoho ACPI_PARSE_OBJECT *NextValueOp = Op;
588 1.1 jruoho ACPI_PARSE_OBJECT *NextOp;
589 1.1 jruoho UINT32 Value;
590 1.1 jruoho
591 1.1 jruoho
592 1.1 jruoho if (!Op)
593 1.1 jruoho {
594 1.1 jruoho return;
595 1.1 jruoho }
596 1.1 jruoho
597 1.1 jruoho /* Search list once for each value in the list */
598 1.1 jruoho
599 1.1 jruoho while (NextValueOp)
600 1.1 jruoho {
601 1.1 jruoho Value = (UINT32) NextValueOp->Asl.Value.Integer;
602 1.1 jruoho
603 1.1 jruoho /* Compare this value to all remaining values in the list */
604 1.1 jruoho
605 1.1 jruoho NextOp = ASL_GET_PEER_NODE (NextValueOp);
606 1.1 jruoho while (NextOp)
607 1.1 jruoho {
608 1.1 jruoho if (NextOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG)
609 1.1 jruoho {
610 1.1 jruoho /* Compare values */
611 1.1 jruoho
612 1.1 jruoho if (Value == (UINT32) NextOp->Asl.Value.Integer)
613 1.1 jruoho {
614 1.1 jruoho /* Emit error only once per duplicate node */
615 1.1 jruoho
616 1.1 jruoho if (!(NextOp->Asl.CompileFlags & NODE_IS_DUPLICATE))
617 1.1 jruoho {
618 1.1 jruoho NextOp->Asl.CompileFlags |= NODE_IS_DUPLICATE;
619 1.1 jruoho AslError (ASL_ERROR, ASL_MSG_DUPLICATE_ITEM,
620 1.1 jruoho NextOp, NULL);
621 1.1 jruoho }
622 1.1 jruoho }
623 1.1 jruoho }
624 1.1 jruoho
625 1.1 jruoho NextOp = ASL_GET_PEER_NODE (NextOp);
626 1.1 jruoho }
627 1.1 jruoho
628 1.1 jruoho NextValueOp = ASL_GET_PEER_NODE (NextValueOp);
629 1.1 jruoho }
630 1.1 jruoho }
631 1.1 jruoho
632 1.1 jruoho
633 1.1 jruoho /*******************************************************************************
634 1.1 jruoho *
635 1.1 jruoho * FUNCTION: RsDoOneResourceDescriptor
636 1.1 jruoho *
637 1.1 jruoho * PARAMETERS: DescriptorTypeOp - Parent parse node of the descriptor
638 1.1 jruoho * CurrentByteOffset - Offset in the resource descriptor
639 1.1 jruoho * buffer.
640 1.1 jruoho *
641 1.1 jruoho * RETURN: A valid resource node for the descriptor
642 1.1 jruoho *
643 1.1 jruoho * DESCRIPTION: Dispatches the processing of one resource descriptor
644 1.1 jruoho *
645 1.1 jruoho ******************************************************************************/
646 1.1 jruoho
647 1.1 jruoho ASL_RESOURCE_NODE *
648 1.1 jruoho RsDoOneResourceDescriptor (
649 1.1 jruoho ACPI_PARSE_OBJECT *DescriptorTypeOp,
650 1.1 jruoho UINT32 CurrentByteOffset,
651 1.1 jruoho UINT8 *State)
652 1.1 jruoho {
653 1.1 jruoho ASL_RESOURCE_NODE *Rnode = NULL;
654 1.1 jruoho
655 1.1 jruoho
656 1.1 jruoho /* Construct the resource */
657 1.1 jruoho
658 1.1 jruoho switch (DescriptorTypeOp->Asl.ParseOpcode)
659 1.1 jruoho {
660 1.1 jruoho case PARSEOP_DMA:
661 1.1 jruoho Rnode = RsDoDmaDescriptor (DescriptorTypeOp,
662 1.1 jruoho CurrentByteOffset);
663 1.1 jruoho break;
664 1.1 jruoho
665 1.1 jruoho case PARSEOP_DWORDIO:
666 1.1 jruoho Rnode = RsDoDwordIoDescriptor (DescriptorTypeOp,
667 1.1 jruoho CurrentByteOffset);
668 1.1 jruoho break;
669 1.1 jruoho
670 1.1 jruoho case PARSEOP_DWORDMEMORY:
671 1.1 jruoho Rnode = RsDoDwordMemoryDescriptor (DescriptorTypeOp,
672 1.1 jruoho CurrentByteOffset);
673 1.1 jruoho break;
674 1.1 jruoho
675 1.1 jruoho case PARSEOP_DWORDSPACE:
676 1.1 jruoho Rnode = RsDoDwordSpaceDescriptor (DescriptorTypeOp,
677 1.1 jruoho CurrentByteOffset);
678 1.1 jruoho break;
679 1.1 jruoho
680 1.1 jruoho case PARSEOP_ENDDEPENDENTFN:
681 1.1 jruoho switch (*State)
682 1.1 jruoho {
683 1.1 jruoho case ACPI_RSTATE_NORMAL:
684 1.1 jruoho AslError (ASL_ERROR, ASL_MSG_MISSING_STARTDEPENDENT,
685 1.1 jruoho DescriptorTypeOp, NULL);
686 1.1 jruoho break;
687 1.1 jruoho
688 1.1 jruoho case ACPI_RSTATE_START_DEPENDENT:
689 1.1 jruoho AslError (ASL_ERROR, ASL_MSG_DEPENDENT_NESTING,
690 1.1 jruoho DescriptorTypeOp, NULL);
691 1.1 jruoho break;
692 1.1 jruoho
693 1.1 jruoho case ACPI_RSTATE_DEPENDENT_LIST:
694 1.1 jruoho default:
695 1.1 jruoho break;
696 1.1 jruoho }
697 1.1 jruoho
698 1.1 jruoho *State = ACPI_RSTATE_NORMAL;
699 1.1 jruoho Rnode = RsDoEndDependentDescriptor (DescriptorTypeOp,
700 1.1 jruoho CurrentByteOffset);
701 1.1 jruoho break;
702 1.1 jruoho
703 1.1 jruoho case PARSEOP_ENDTAG:
704 1.1 jruoho Rnode = RsDoEndTagDescriptor (DescriptorTypeOp,
705 1.1 jruoho CurrentByteOffset);
706 1.1 jruoho break;
707 1.1 jruoho
708 1.1 jruoho case PARSEOP_EXTENDEDIO:
709 1.1 jruoho Rnode = RsDoExtendedIoDescriptor (DescriptorTypeOp,
710 1.1 jruoho CurrentByteOffset);
711 1.1 jruoho break;
712 1.1 jruoho
713 1.1 jruoho case PARSEOP_EXTENDEDMEMORY:
714 1.1 jruoho Rnode = RsDoExtendedMemoryDescriptor (DescriptorTypeOp,
715 1.1 jruoho CurrentByteOffset);
716 1.1 jruoho break;
717 1.1 jruoho
718 1.1 jruoho case PARSEOP_EXTENDEDSPACE:
719 1.1 jruoho Rnode = RsDoExtendedSpaceDescriptor (DescriptorTypeOp,
720 1.1 jruoho CurrentByteOffset);
721 1.1 jruoho break;
722 1.1 jruoho
723 1.1 jruoho case PARSEOP_FIXEDIO:
724 1.1 jruoho Rnode = RsDoFixedIoDescriptor (DescriptorTypeOp,
725 1.1 jruoho CurrentByteOffset);
726 1.1 jruoho break;
727 1.1 jruoho
728 1.1 jruoho case PARSEOP_INTERRUPT:
729 1.1 jruoho Rnode = RsDoInterruptDescriptor (DescriptorTypeOp,
730 1.1 jruoho CurrentByteOffset);
731 1.1 jruoho break;
732 1.1 jruoho
733 1.1 jruoho case PARSEOP_IO:
734 1.1 jruoho Rnode = RsDoIoDescriptor (DescriptorTypeOp,
735 1.1 jruoho CurrentByteOffset);
736 1.1 jruoho break;
737 1.1 jruoho
738 1.1 jruoho case PARSEOP_IRQ:
739 1.1 jruoho Rnode = RsDoIrqDescriptor (DescriptorTypeOp,
740 1.1 jruoho CurrentByteOffset);
741 1.1 jruoho break;
742 1.1 jruoho
743 1.1 jruoho case PARSEOP_IRQNOFLAGS:
744 1.1 jruoho Rnode = RsDoIrqNoFlagsDescriptor (DescriptorTypeOp,
745 1.1 jruoho CurrentByteOffset);
746 1.1 jruoho break;
747 1.1 jruoho
748 1.1 jruoho case PARSEOP_MEMORY24:
749 1.1 jruoho Rnode = RsDoMemory24Descriptor (DescriptorTypeOp,
750 1.1 jruoho CurrentByteOffset);
751 1.1 jruoho break;
752 1.1 jruoho
753 1.1 jruoho case PARSEOP_MEMORY32:
754 1.1 jruoho Rnode = RsDoMemory32Descriptor (DescriptorTypeOp,
755 1.1 jruoho CurrentByteOffset);
756 1.1 jruoho break;
757 1.1 jruoho
758 1.1 jruoho case PARSEOP_MEMORY32FIXED:
759 1.1 jruoho Rnode = RsDoMemory32FixedDescriptor (DescriptorTypeOp,
760 1.1 jruoho CurrentByteOffset);
761 1.1 jruoho break;
762 1.1 jruoho
763 1.1 jruoho case PARSEOP_QWORDIO:
764 1.1 jruoho Rnode = RsDoQwordIoDescriptor (DescriptorTypeOp,
765 1.1 jruoho CurrentByteOffset);
766 1.1 jruoho break;
767 1.1 jruoho
768 1.1 jruoho case PARSEOP_QWORDMEMORY:
769 1.1 jruoho Rnode = RsDoQwordMemoryDescriptor (DescriptorTypeOp,
770 1.1 jruoho CurrentByteOffset);
771 1.1 jruoho break;
772 1.1 jruoho
773 1.1 jruoho case PARSEOP_QWORDSPACE:
774 1.1 jruoho Rnode = RsDoQwordSpaceDescriptor (DescriptorTypeOp,
775 1.1 jruoho CurrentByteOffset);
776 1.1 jruoho break;
777 1.1 jruoho
778 1.1 jruoho case PARSEOP_REGISTER:
779 1.1 jruoho Rnode = RsDoGeneralRegisterDescriptor (DescriptorTypeOp,
780 1.1 jruoho CurrentByteOffset);
781 1.1 jruoho break;
782 1.1 jruoho
783 1.1 jruoho case PARSEOP_STARTDEPENDENTFN:
784 1.1 jruoho switch (*State)
785 1.1 jruoho {
786 1.1 jruoho case ACPI_RSTATE_START_DEPENDENT:
787 1.1 jruoho AslError (ASL_ERROR, ASL_MSG_DEPENDENT_NESTING,
788 1.1 jruoho DescriptorTypeOp, NULL);
789 1.1 jruoho break;
790 1.1 jruoho
791 1.1 jruoho case ACPI_RSTATE_NORMAL:
792 1.1 jruoho case ACPI_RSTATE_DEPENDENT_LIST:
793 1.1 jruoho default:
794 1.1 jruoho break;
795 1.1 jruoho }
796 1.1 jruoho
797 1.1 jruoho *State = ACPI_RSTATE_START_DEPENDENT;
798 1.1 jruoho Rnode = RsDoStartDependentDescriptor (DescriptorTypeOp,
799 1.1 jruoho CurrentByteOffset);
800 1.1 jruoho *State = ACPI_RSTATE_DEPENDENT_LIST;
801 1.1 jruoho break;
802 1.1 jruoho
803 1.1 jruoho case PARSEOP_STARTDEPENDENTFN_NOPRI:
804 1.1 jruoho switch (*State)
805 1.1 jruoho {
806 1.1 jruoho case ACPI_RSTATE_START_DEPENDENT:
807 1.1 jruoho AslError (ASL_ERROR, ASL_MSG_DEPENDENT_NESTING,
808 1.1 jruoho DescriptorTypeOp, NULL);
809 1.1 jruoho break;
810 1.1 jruoho
811 1.1 jruoho case ACPI_RSTATE_NORMAL:
812 1.1 jruoho case ACPI_RSTATE_DEPENDENT_LIST:
813 1.1 jruoho default:
814 1.1 jruoho break;
815 1.1 jruoho }
816 1.1 jruoho
817 1.1 jruoho *State = ACPI_RSTATE_START_DEPENDENT;
818 1.1 jruoho Rnode = RsDoStartDependentNoPriDescriptor (DescriptorTypeOp,
819 1.1 jruoho CurrentByteOffset);
820 1.1 jruoho *State = ACPI_RSTATE_DEPENDENT_LIST;
821 1.1 jruoho break;
822 1.1 jruoho
823 1.1 jruoho case PARSEOP_VENDORLONG:
824 1.1 jruoho Rnode = RsDoVendorLargeDescriptor (DescriptorTypeOp,
825 1.1 jruoho CurrentByteOffset);
826 1.1 jruoho break;
827 1.1 jruoho
828 1.1 jruoho case PARSEOP_VENDORSHORT:
829 1.1 jruoho Rnode = RsDoVendorSmallDescriptor (DescriptorTypeOp,
830 1.1 jruoho CurrentByteOffset);
831 1.1 jruoho break;
832 1.1 jruoho
833 1.1 jruoho case PARSEOP_WORDBUSNUMBER:
834 1.1 jruoho Rnode = RsDoWordBusNumberDescriptor (DescriptorTypeOp,
835 1.1 jruoho CurrentByteOffset);
836 1.1 jruoho break;
837 1.1 jruoho
838 1.1 jruoho case PARSEOP_WORDIO:
839 1.1 jruoho Rnode = RsDoWordIoDescriptor (DescriptorTypeOp,
840 1.1 jruoho CurrentByteOffset);
841 1.1 jruoho break;
842 1.1 jruoho
843 1.1 jruoho case PARSEOP_WORDSPACE:
844 1.1 jruoho Rnode = RsDoWordSpaceDescriptor (DescriptorTypeOp,
845 1.1 jruoho CurrentByteOffset);
846 1.1 jruoho break;
847 1.1 jruoho
848 1.1 jruoho case PARSEOP_DEFAULT_ARG:
849 1.1 jruoho /* Just ignore any of these, they are used as fillers/placeholders */
850 1.1 jruoho break;
851 1.1 jruoho
852 1.1 jruoho default:
853 1.1 jruoho printf ("Unknown resource descriptor type [%s]\n",
854 1.1 jruoho DescriptorTypeOp->Asl.ParseOpName);
855 1.1 jruoho break;
856 1.1 jruoho }
857 1.1 jruoho
858 1.1 jruoho /*
859 1.1 jruoho * Mark original node as unused, but head of a resource descriptor.
860 1.1 jruoho * This allows the resource to be installed in the namespace so that
861 1.1 jruoho * references to the descriptor can be resolved.
862 1.1 jruoho */
863 1.1 jruoho DescriptorTypeOp->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
864 1.1 jruoho DescriptorTypeOp->Asl.CompileFlags = NODE_IS_RESOURCE_DESC;
865 1.1 jruoho DescriptorTypeOp->Asl.Value.Integer = CurrentByteOffset;
866 1.1 jruoho
867 1.1 jruoho if (Rnode)
868 1.1 jruoho {
869 1.1 jruoho DescriptorTypeOp->Asl.FinalAmlLength = Rnode->BufferLength;
870 1.1 jruoho }
871 1.1 jruoho
872 1.1 jruoho return (Rnode);
873 1.1 jruoho }
874 1.1 jruoho
875 1.1 jruoho
876 1.1 jruoho /*******************************************************************************
877 1.1 jruoho *
878 1.1 jruoho * FUNCTION: RsLinkDescriptorChain
879 1.1 jruoho *
880 1.1 jruoho * PARAMETERS: PreviousRnode - Pointer to the node that will be previous
881 1.1 jruoho * to the linked node, At exit, set to the
882 1.1 jruoho * last node in the new chain.
883 1.1 jruoho * Rnode - Resource node to link into the list
884 1.1 jruoho *
885 1.1 jruoho * RETURN: Cumulative buffer byte offset of the new segment of chain
886 1.1 jruoho *
887 1.1 jruoho * DESCRIPTION: Link a descriptor chain at the end of an existing chain.
888 1.1 jruoho *
889 1.1 jruoho ******************************************************************************/
890 1.1 jruoho
891 1.1 jruoho UINT32
892 1.1 jruoho RsLinkDescriptorChain (
893 1.1 jruoho ASL_RESOURCE_NODE **PreviousRnode,
894 1.1 jruoho ASL_RESOURCE_NODE *Rnode)
895 1.1 jruoho {
896 1.1 jruoho ASL_RESOURCE_NODE *LastRnode;
897 1.1 jruoho UINT32 CurrentByteOffset;
898 1.1 jruoho
899 1.1 jruoho
900 1.1 jruoho /* Anything to do? */
901 1.1 jruoho
902 1.1 jruoho if (!Rnode)
903 1.1 jruoho {
904 1.1 jruoho return 0;
905 1.1 jruoho }
906 1.1 jruoho
907 1.1 jruoho /* Point the previous node to the new node */
908 1.1 jruoho
909 1.1 jruoho (*PreviousRnode)->Next = Rnode;
910 1.1 jruoho CurrentByteOffset = Rnode->BufferLength;
911 1.1 jruoho
912 1.1 jruoho /* Walk to the end of the chain headed by Rnode */
913 1.1 jruoho
914 1.1 jruoho LastRnode = Rnode;
915 1.1 jruoho while (LastRnode->Next)
916 1.1 jruoho {
917 1.1 jruoho LastRnode = LastRnode->Next;
918 1.1 jruoho CurrentByteOffset += LastRnode->BufferLength;
919 1.1 jruoho }
920 1.1 jruoho
921 1.1 jruoho /* Previous node becomes the last node in the chain */
922 1.1 jruoho
923 1.1 jruoho *PreviousRnode = LastRnode;
924 1.1 jruoho return CurrentByteOffset;
925 1.1 jruoho }
926 1.1 jruoho
927 1.1 jruoho
928 1.1 jruoho /*******************************************************************************
929 1.1 jruoho *
930 1.1 jruoho * FUNCTION: RsDoResourceTemplate
931 1.1 jruoho *
932 1.1 jruoho * PARAMETERS: Op - Parent of a resource template list
933 1.1 jruoho *
934 1.1 jruoho * RETURN: None. Sets input node to point to a list of AML code
935 1.1 jruoho *
936 1.1 jruoho * DESCRIPTION: Merge a list of resource descriptors into a single AML buffer,
937 1.1 jruoho * in preparation for output to the AML output file.
938 1.1 jruoho *
939 1.1 jruoho ******************************************************************************/
940 1.1 jruoho
941 1.1 jruoho void
942 1.1 jruoho RsDoResourceTemplate (
943 1.1 jruoho ACPI_PARSE_OBJECT *Op)
944 1.1 jruoho {
945 1.1 jruoho ACPI_PARSE_OBJECT *BufferLengthOp;
946 1.1 jruoho ACPI_PARSE_OBJECT *BufferOp;
947 1.1 jruoho ACPI_PARSE_OBJECT *DescriptorTypeOp;
948 1.1 jruoho ACPI_PARSE_OBJECT *LastOp = NULL;
949 1.1 jruoho UINT32 CurrentByteOffset = 0;
950 1.1 jruoho ASL_RESOURCE_NODE HeadRnode;
951 1.1 jruoho ASL_RESOURCE_NODE *PreviousRnode;
952 1.1 jruoho ASL_RESOURCE_NODE *Rnode;
953 1.1 jruoho UINT8 State;
954 1.1 jruoho
955 1.1 jruoho
956 1.1 jruoho /* Mark parent as containing a resource template */
957 1.1 jruoho
958 1.1 jruoho if (Op->Asl.Parent)
959 1.1 jruoho {
960 1.1 jruoho Op->Asl.Parent->Asl.CompileFlags |= NODE_IS_RESOURCE_DESC;
961 1.1 jruoho }
962 1.1 jruoho
963 1.1 jruoho /* ResourceTemplate Opcode is first (Op) */
964 1.1 jruoho /* Buffer Length node is first child */
965 1.1 jruoho
966 1.1 jruoho BufferLengthOp = ASL_GET_CHILD_NODE (Op);
967 1.1 jruoho
968 1.1 jruoho /* Buffer Op is first peer */
969 1.1 jruoho
970 1.1 jruoho BufferOp = ASL_GET_PEER_NODE (BufferLengthOp);
971 1.1 jruoho
972 1.1 jruoho /* First Descriptor type is next */
973 1.1 jruoho
974 1.1 jruoho DescriptorTypeOp = ASL_GET_PEER_NODE (BufferOp);
975 1.1 jruoho
976 1.1 jruoho /*
977 1.1 jruoho * Process all resource descriptors in the list
978 1.1 jruoho * Note: It is assumed that the EndTag node has been automatically
979 1.1 jruoho * inserted at the end of the template by the parser.
980 1.1 jruoho */
981 1.1 jruoho State = ACPI_RSTATE_NORMAL;
982 1.1 jruoho PreviousRnode = &HeadRnode;
983 1.1 jruoho while (DescriptorTypeOp)
984 1.1 jruoho {
985 1.1 jruoho DescriptorTypeOp->Asl.CompileFlags |= NODE_IS_RESOURCE_DESC;
986 1.1 jruoho Rnode = RsDoOneResourceDescriptor (DescriptorTypeOp, CurrentByteOffset,
987 1.1 jruoho &State);
988 1.1 jruoho
989 1.1 jruoho /*
990 1.1 jruoho * Update current byte offset to indicate the number of bytes from the
991 1.1 jruoho * start of the buffer. Buffer can include multiple descriptors, we
992 1.1 jruoho * must keep track of the offset of not only each descriptor, but each
993 1.1 jruoho * element (field) within each descriptor as well.
994 1.1 jruoho */
995 1.1 jruoho CurrentByteOffset += RsLinkDescriptorChain (&PreviousRnode, Rnode);
996 1.1 jruoho
997 1.1 jruoho /* Get the next descriptor in the list */
998 1.1 jruoho
999 1.1 jruoho LastOp = DescriptorTypeOp;
1000 1.1 jruoho DescriptorTypeOp = ASL_GET_PEER_NODE (DescriptorTypeOp);
1001 1.1 jruoho }
1002 1.1 jruoho
1003 1.1 jruoho if (State == ACPI_RSTATE_DEPENDENT_LIST)
1004 1.1 jruoho {
1005 1.1 jruoho if (LastOp)
1006 1.1 jruoho {
1007 1.1 jruoho LastOp = LastOp->Asl.Parent;
1008 1.1 jruoho }
1009 1.1 jruoho AslError (ASL_ERROR, ASL_MSG_MISSING_ENDDEPENDENT, LastOp, NULL);
1010 1.1 jruoho }
1011 1.1 jruoho
1012 1.1 jruoho /*
1013 1.1 jruoho * Transform the nodes into the following
1014 1.1 jruoho *
1015 1.1 jruoho * Op -> AML_BUFFER_OP
1016 1.1 jruoho * First Child -> BufferLength
1017 1.1 jruoho * Second Child -> Descriptor Buffer (raw byte data)
1018 1.1 jruoho */
1019 1.1 jruoho Op->Asl.ParseOpcode = PARSEOP_BUFFER;
1020 1.1 jruoho Op->Asl.AmlOpcode = AML_BUFFER_OP;
1021 1.1 jruoho Op->Asl.CompileFlags = NODE_AML_PACKAGE | NODE_IS_RESOURCE_DESC;
1022 1.1 jruoho
1023 1.1 jruoho BufferLengthOp->Asl.ParseOpcode = PARSEOP_INTEGER;
1024 1.1 jruoho BufferLengthOp->Asl.Value.Integer = CurrentByteOffset;
1025 1.1 jruoho (void) OpcSetOptimalIntegerSize (BufferLengthOp);
1026 1.1 jruoho
1027 1.1 jruoho BufferOp->Asl.ParseOpcode = PARSEOP_RAW_DATA;
1028 1.1 jruoho BufferOp->Asl.AmlOpcode = AML_RAW_DATA_CHAIN;
1029 1.1 jruoho BufferOp->Asl.AmlOpcodeLength = 0;
1030 1.1 jruoho BufferOp->Asl.AmlLength = CurrentByteOffset;
1031 1.1 jruoho BufferOp->Asl.Value.Buffer = (UINT8 *) HeadRnode.Next;
1032 1.1 jruoho BufferOp->Asl.CompileFlags |= NODE_IS_RESOURCE_DATA;
1033 1.1 jruoho
1034 1.1 jruoho return;
1035 1.1 jruoho }
1036 1.1 jruoho
1037 1.1 jruoho
1038