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