rsutils.c revision 1.3.2.2 1 1.3.2.2 bouyer /*******************************************************************************
2 1.3.2.2 bouyer *
3 1.3.2.2 bouyer * Module Name: rsutils - Utilities for the resource manager
4 1.3.2.2 bouyer *
5 1.3.2.2 bouyer ******************************************************************************/
6 1.3.2.2 bouyer
7 1.3.2.2 bouyer /*
8 1.3.2.2 bouyer * Copyright (C) 2000 - 2011, Intel Corp.
9 1.3.2.2 bouyer * All rights reserved.
10 1.3.2.2 bouyer *
11 1.3.2.2 bouyer * Redistribution and use in source and binary forms, with or without
12 1.3.2.2 bouyer * modification, are permitted provided that the following conditions
13 1.3.2.2 bouyer * are met:
14 1.3.2.2 bouyer * 1. Redistributions of source code must retain the above copyright
15 1.3.2.2 bouyer * notice, this list of conditions, and the following disclaimer,
16 1.3.2.2 bouyer * without modification.
17 1.3.2.2 bouyer * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 1.3.2.2 bouyer * substantially similar to the "NO WARRANTY" disclaimer below
19 1.3.2.2 bouyer * ("Disclaimer") and any redistribution must be conditioned upon
20 1.3.2.2 bouyer * including a substantially similar Disclaimer requirement for further
21 1.3.2.2 bouyer * binary redistribution.
22 1.3.2.2 bouyer * 3. Neither the names of the above-listed copyright holders nor the names
23 1.3.2.2 bouyer * of any contributors may be used to endorse or promote products derived
24 1.3.2.2 bouyer * from this software without specific prior written permission.
25 1.3.2.2 bouyer *
26 1.3.2.2 bouyer * Alternatively, this software may be distributed under the terms of the
27 1.3.2.2 bouyer * GNU General Public License ("GPL") version 2 as published by the Free
28 1.3.2.2 bouyer * Software Foundation.
29 1.3.2.2 bouyer *
30 1.3.2.2 bouyer * NO WARRANTY
31 1.3.2.2 bouyer * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 1.3.2.2 bouyer * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 1.3.2.2 bouyer * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 1.3.2.2 bouyer * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 1.3.2.2 bouyer * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 1.3.2.2 bouyer * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 1.3.2.2 bouyer * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 1.3.2.2 bouyer * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 1.3.2.2 bouyer * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 1.3.2.2 bouyer * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 1.3.2.2 bouyer * POSSIBILITY OF SUCH DAMAGES.
42 1.3.2.2 bouyer */
43 1.3.2.2 bouyer
44 1.3.2.2 bouyer
45 1.3.2.2 bouyer #define __RSUTILS_C__
46 1.3.2.2 bouyer
47 1.3.2.2 bouyer #include "acpi.h"
48 1.3.2.2 bouyer #include "accommon.h"
49 1.3.2.2 bouyer #include "acnamesp.h"
50 1.3.2.2 bouyer #include "acresrc.h"
51 1.3.2.2 bouyer
52 1.3.2.2 bouyer
53 1.3.2.2 bouyer #define _COMPONENT ACPI_RESOURCES
54 1.3.2.2 bouyer ACPI_MODULE_NAME ("rsutils")
55 1.3.2.2 bouyer
56 1.3.2.2 bouyer
57 1.3.2.2 bouyer /*******************************************************************************
58 1.3.2.2 bouyer *
59 1.3.2.2 bouyer * FUNCTION: AcpiRsDecodeBitmask
60 1.3.2.2 bouyer *
61 1.3.2.2 bouyer * PARAMETERS: Mask - Bitmask to decode
62 1.3.2.2 bouyer * List - Where the converted list is returned
63 1.3.2.2 bouyer *
64 1.3.2.2 bouyer * RETURN: Count of bits set (length of list)
65 1.3.2.2 bouyer *
66 1.3.2.2 bouyer * DESCRIPTION: Convert a bit mask into a list of values
67 1.3.2.2 bouyer *
68 1.3.2.2 bouyer ******************************************************************************/
69 1.3.2.2 bouyer
70 1.3.2.2 bouyer UINT8
71 1.3.2.2 bouyer AcpiRsDecodeBitmask (
72 1.3.2.2 bouyer UINT16 Mask,
73 1.3.2.2 bouyer UINT8 *List)
74 1.3.2.2 bouyer {
75 1.3.2.2 bouyer UINT8 i;
76 1.3.2.2 bouyer UINT8 BitCount;
77 1.3.2.2 bouyer
78 1.3.2.2 bouyer
79 1.3.2.2 bouyer ACPI_FUNCTION_ENTRY ();
80 1.3.2.2 bouyer
81 1.3.2.2 bouyer
82 1.3.2.2 bouyer /* Decode the mask bits */
83 1.3.2.2 bouyer
84 1.3.2.2 bouyer for (i = 0, BitCount = 0; Mask; i++)
85 1.3.2.2 bouyer {
86 1.3.2.2 bouyer if (Mask & 0x0001)
87 1.3.2.2 bouyer {
88 1.3.2.2 bouyer List[BitCount] = i;
89 1.3.2.2 bouyer BitCount++;
90 1.3.2.2 bouyer }
91 1.3.2.2 bouyer
92 1.3.2.2 bouyer Mask >>= 1;
93 1.3.2.2 bouyer }
94 1.3.2.2 bouyer
95 1.3.2.2 bouyer return (BitCount);
96 1.3.2.2 bouyer }
97 1.3.2.2 bouyer
98 1.3.2.2 bouyer
99 1.3.2.2 bouyer /*******************************************************************************
100 1.3.2.2 bouyer *
101 1.3.2.2 bouyer * FUNCTION: AcpiRsEncodeBitmask
102 1.3.2.2 bouyer *
103 1.3.2.2 bouyer * PARAMETERS: List - List of values to encode
104 1.3.2.2 bouyer * Count - Length of list
105 1.3.2.2 bouyer *
106 1.3.2.2 bouyer * RETURN: Encoded bitmask
107 1.3.2.2 bouyer *
108 1.3.2.2 bouyer * DESCRIPTION: Convert a list of values to an encoded bitmask
109 1.3.2.2 bouyer *
110 1.3.2.2 bouyer ******************************************************************************/
111 1.3.2.2 bouyer
112 1.3.2.2 bouyer UINT16
113 1.3.2.2 bouyer AcpiRsEncodeBitmask (
114 1.3.2.2 bouyer UINT8 *List,
115 1.3.2.2 bouyer UINT8 Count)
116 1.3.2.2 bouyer {
117 1.3.2.2 bouyer UINT32 i;
118 1.3.2.2 bouyer UINT16 Mask;
119 1.3.2.2 bouyer
120 1.3.2.2 bouyer
121 1.3.2.2 bouyer ACPI_FUNCTION_ENTRY ();
122 1.3.2.2 bouyer
123 1.3.2.2 bouyer
124 1.3.2.2 bouyer /* Encode the list into a single bitmask */
125 1.3.2.2 bouyer
126 1.3.2.2 bouyer for (i = 0, Mask = 0; i < Count; i++)
127 1.3.2.2 bouyer {
128 1.3.2.2 bouyer Mask |= (0x1 << List[i]);
129 1.3.2.2 bouyer }
130 1.3.2.2 bouyer
131 1.3.2.2 bouyer return (Mask);
132 1.3.2.2 bouyer }
133 1.3.2.2 bouyer
134 1.3.2.2 bouyer
135 1.3.2.2 bouyer /*******************************************************************************
136 1.3.2.2 bouyer *
137 1.3.2.2 bouyer * FUNCTION: AcpiRsMoveData
138 1.3.2.2 bouyer *
139 1.3.2.2 bouyer * PARAMETERS: Destination - Pointer to the destination descriptor
140 1.3.2.2 bouyer * Source - Pointer to the source descriptor
141 1.3.2.2 bouyer * ItemCount - How many items to move
142 1.3.2.2 bouyer * MoveType - Byte width
143 1.3.2.2 bouyer *
144 1.3.2.2 bouyer * RETURN: None
145 1.3.2.2 bouyer *
146 1.3.2.2 bouyer * DESCRIPTION: Move multiple data items from one descriptor to another. Handles
147 1.3.2.2 bouyer * alignment issues and endian issues if necessary, as configured
148 1.3.2.2 bouyer * via the ACPI_MOVE_* macros. (This is why a memcpy is not used)
149 1.3.2.2 bouyer *
150 1.3.2.2 bouyer ******************************************************************************/
151 1.3.2.2 bouyer
152 1.3.2.2 bouyer void
153 1.3.2.2 bouyer AcpiRsMoveData (
154 1.3.2.2 bouyer void *Destination,
155 1.3.2.2 bouyer void *Source,
156 1.3.2.2 bouyer UINT16 ItemCount,
157 1.3.2.2 bouyer UINT8 MoveType)
158 1.3.2.2 bouyer {
159 1.3.2.2 bouyer UINT32 i;
160 1.3.2.2 bouyer
161 1.3.2.2 bouyer
162 1.3.2.2 bouyer ACPI_FUNCTION_ENTRY ();
163 1.3.2.2 bouyer
164 1.3.2.2 bouyer
165 1.3.2.2 bouyer /* One move per item */
166 1.3.2.2 bouyer
167 1.3.2.2 bouyer for (i = 0; i < ItemCount; i++)
168 1.3.2.2 bouyer {
169 1.3.2.2 bouyer switch (MoveType)
170 1.3.2.2 bouyer {
171 1.3.2.2 bouyer /*
172 1.3.2.2 bouyer * For the 8-bit case, we can perform the move all at once
173 1.3.2.2 bouyer * since there are no alignment or endian issues
174 1.3.2.2 bouyer */
175 1.3.2.2 bouyer case ACPI_RSC_MOVE8:
176 1.3.2.2 bouyer ACPI_MEMCPY (Destination, Source, ItemCount);
177 1.3.2.2 bouyer return;
178 1.3.2.2 bouyer
179 1.3.2.2 bouyer /*
180 1.3.2.2 bouyer * 16-, 32-, and 64-bit cases must use the move macros that perform
181 1.3.2.2 bouyer * endian conversion and/or accomodate hardware that cannot perform
182 1.3.2.2 bouyer * misaligned memory transfers
183 1.3.2.2 bouyer */
184 1.3.2.2 bouyer case ACPI_RSC_MOVE16:
185 1.3.2.2 bouyer ACPI_MOVE_16_TO_16 (&ACPI_CAST_PTR (UINT16, Destination)[i],
186 1.3.2.2 bouyer &ACPI_CAST_PTR (UINT16, Source)[i]);
187 1.3.2.2 bouyer break;
188 1.3.2.2 bouyer
189 1.3.2.2 bouyer case ACPI_RSC_MOVE32:
190 1.3.2.2 bouyer ACPI_MOVE_32_TO_32 (&ACPI_CAST_PTR (UINT32, Destination)[i],
191 1.3.2.2 bouyer &ACPI_CAST_PTR (UINT32, Source)[i]);
192 1.3.2.2 bouyer break;
193 1.3.2.2 bouyer
194 1.3.2.2 bouyer case ACPI_RSC_MOVE64:
195 1.3.2.2 bouyer ACPI_MOVE_64_TO_64 (&ACPI_CAST_PTR (UINT64, Destination)[i],
196 1.3.2.2 bouyer &ACPI_CAST_PTR (UINT64, Source)[i]);
197 1.3.2.2 bouyer break;
198 1.3.2.2 bouyer
199 1.3.2.2 bouyer default:
200 1.3.2.2 bouyer return;
201 1.3.2.2 bouyer }
202 1.3.2.2 bouyer }
203 1.3.2.2 bouyer }
204 1.3.2.2 bouyer
205 1.3.2.2 bouyer
206 1.3.2.2 bouyer /*******************************************************************************
207 1.3.2.2 bouyer *
208 1.3.2.2 bouyer * FUNCTION: AcpiRsSetResourceLength
209 1.3.2.2 bouyer *
210 1.3.2.2 bouyer * PARAMETERS: TotalLength - Length of the AML descriptor, including
211 1.3.2.2 bouyer * the header and length fields.
212 1.3.2.2 bouyer * Aml - Pointer to the raw AML descriptor
213 1.3.2.2 bouyer *
214 1.3.2.2 bouyer * RETURN: None
215 1.3.2.2 bouyer *
216 1.3.2.2 bouyer * DESCRIPTION: Set the ResourceLength field of an AML
217 1.3.2.2 bouyer * resource descriptor, both Large and Small descriptors are
218 1.3.2.2 bouyer * supported automatically. Note: Descriptor Type field must
219 1.3.2.2 bouyer * be valid.
220 1.3.2.2 bouyer *
221 1.3.2.2 bouyer ******************************************************************************/
222 1.3.2.2 bouyer
223 1.3.2.2 bouyer void
224 1.3.2.2 bouyer AcpiRsSetResourceLength (
225 1.3.2.2 bouyer ACPI_RSDESC_SIZE TotalLength,
226 1.3.2.2 bouyer AML_RESOURCE *Aml)
227 1.3.2.2 bouyer {
228 1.3.2.2 bouyer ACPI_RS_LENGTH ResourceLength;
229 1.3.2.2 bouyer
230 1.3.2.2 bouyer
231 1.3.2.2 bouyer ACPI_FUNCTION_ENTRY ();
232 1.3.2.2 bouyer
233 1.3.2.2 bouyer
234 1.3.2.2 bouyer /* Length is the total descriptor length minus the header length */
235 1.3.2.2 bouyer
236 1.3.2.2 bouyer ResourceLength = (ACPI_RS_LENGTH)
237 1.3.2.2 bouyer (TotalLength - AcpiUtGetResourceHeaderLength (Aml));
238 1.3.2.2 bouyer
239 1.3.2.2 bouyer /* Length is stored differently for large and small descriptors */
240 1.3.2.2 bouyer
241 1.3.2.2 bouyer if (Aml->SmallHeader.DescriptorType & ACPI_RESOURCE_NAME_LARGE)
242 1.3.2.2 bouyer {
243 1.3.2.2 bouyer /* Large descriptor -- bytes 1-2 contain the 16-bit length */
244 1.3.2.2 bouyer
245 1.3.2.2 bouyer ACPI_MOVE_16_TO_16 (&Aml->LargeHeader.ResourceLength, &ResourceLength);
246 1.3.2.2 bouyer }
247 1.3.2.2 bouyer else
248 1.3.2.2 bouyer {
249 1.3.2.2 bouyer /* Small descriptor -- bits 2:0 of byte 0 contain the length */
250 1.3.2.2 bouyer
251 1.3.2.2 bouyer Aml->SmallHeader.DescriptorType = (UINT8)
252 1.3.2.2 bouyer
253 1.3.2.2 bouyer /* Clear any existing length, preserving descriptor type bits */
254 1.3.2.2 bouyer
255 1.3.2.2 bouyer ((Aml->SmallHeader.DescriptorType & ~ACPI_RESOURCE_NAME_SMALL_LENGTH_MASK)
256 1.3.2.2 bouyer
257 1.3.2.2 bouyer | ResourceLength);
258 1.3.2.2 bouyer }
259 1.3.2.2 bouyer }
260 1.3.2.2 bouyer
261 1.3.2.2 bouyer
262 1.3.2.2 bouyer /*******************************************************************************
263 1.3.2.2 bouyer *
264 1.3.2.2 bouyer * FUNCTION: AcpiRsSetResourceHeader
265 1.3.2.2 bouyer *
266 1.3.2.2 bouyer * PARAMETERS: DescriptorType - Byte to be inserted as the type
267 1.3.2.2 bouyer * TotalLength - Length of the AML descriptor, including
268 1.3.2.2 bouyer * the header and length fields.
269 1.3.2.2 bouyer * Aml - Pointer to the raw AML descriptor
270 1.3.2.2 bouyer *
271 1.3.2.2 bouyer * RETURN: None
272 1.3.2.2 bouyer *
273 1.3.2.2 bouyer * DESCRIPTION: Set the DescriptorType and ResourceLength fields of an AML
274 1.3.2.2 bouyer * resource descriptor, both Large and Small descriptors are
275 1.3.2.2 bouyer * supported automatically
276 1.3.2.2 bouyer *
277 1.3.2.2 bouyer ******************************************************************************/
278 1.3.2.2 bouyer
279 1.3.2.2 bouyer void
280 1.3.2.2 bouyer AcpiRsSetResourceHeader (
281 1.3.2.2 bouyer UINT8 DescriptorType,
282 1.3.2.2 bouyer ACPI_RSDESC_SIZE TotalLength,
283 1.3.2.2 bouyer AML_RESOURCE *Aml)
284 1.3.2.2 bouyer {
285 1.3.2.2 bouyer ACPI_FUNCTION_ENTRY ();
286 1.3.2.2 bouyer
287 1.3.2.2 bouyer
288 1.3.2.2 bouyer /* Set the Resource Type */
289 1.3.2.2 bouyer
290 1.3.2.2 bouyer Aml->SmallHeader.DescriptorType = DescriptorType;
291 1.3.2.2 bouyer
292 1.3.2.2 bouyer /* Set the Resource Length */
293 1.3.2.2 bouyer
294 1.3.2.2 bouyer AcpiRsSetResourceLength (TotalLength, Aml);
295 1.3.2.2 bouyer }
296 1.3.2.2 bouyer
297 1.3.2.2 bouyer
298 1.3.2.2 bouyer /*******************************************************************************
299 1.3.2.2 bouyer *
300 1.3.2.2 bouyer * FUNCTION: AcpiRsStrcpy
301 1.3.2.2 bouyer *
302 1.3.2.2 bouyer * PARAMETERS: Destination - Pointer to the destination string
303 1.3.2.2 bouyer * Source - Pointer to the source string
304 1.3.2.2 bouyer *
305 1.3.2.2 bouyer * RETURN: String length, including NULL terminator
306 1.3.2.2 bouyer *
307 1.3.2.2 bouyer * DESCRIPTION: Local string copy that returns the string length, saving a
308 1.3.2.2 bouyer * strcpy followed by a strlen.
309 1.3.2.2 bouyer *
310 1.3.2.2 bouyer ******************************************************************************/
311 1.3.2.2 bouyer
312 1.3.2.2 bouyer static UINT16
313 1.3.2.2 bouyer AcpiRsStrcpy (
314 1.3.2.2 bouyer char *Destination,
315 1.3.2.2 bouyer char *Source)
316 1.3.2.2 bouyer {
317 1.3.2.2 bouyer UINT16 i;
318 1.3.2.2 bouyer
319 1.3.2.2 bouyer
320 1.3.2.2 bouyer ACPI_FUNCTION_ENTRY ();
321 1.3.2.2 bouyer
322 1.3.2.2 bouyer
323 1.3.2.2 bouyer for (i = 0; Source[i]; i++)
324 1.3.2.2 bouyer {
325 1.3.2.2 bouyer Destination[i] = Source[i];
326 1.3.2.2 bouyer }
327 1.3.2.2 bouyer
328 1.3.2.2 bouyer Destination[i] = 0;
329 1.3.2.2 bouyer
330 1.3.2.2 bouyer /* Return string length including the NULL terminator */
331 1.3.2.2 bouyer
332 1.3.2.2 bouyer return ((UINT16) (i + 1));
333 1.3.2.2 bouyer }
334 1.3.2.2 bouyer
335 1.3.2.2 bouyer
336 1.3.2.2 bouyer /*******************************************************************************
337 1.3.2.2 bouyer *
338 1.3.2.2 bouyer * FUNCTION: AcpiRsGetResourceSource
339 1.3.2.2 bouyer *
340 1.3.2.2 bouyer * PARAMETERS: ResourceLength - Length field of the descriptor
341 1.3.2.2 bouyer * MinimumLength - Minimum length of the descriptor (minus
342 1.3.2.2 bouyer * any optional fields)
343 1.3.2.2 bouyer * ResourceSource - Where the ResourceSource is returned
344 1.3.2.2 bouyer * Aml - Pointer to the raw AML descriptor
345 1.3.2.2 bouyer * StringPtr - (optional) where to store the actual
346 1.3.2.2 bouyer * ResourceSource string
347 1.3.2.2 bouyer *
348 1.3.2.2 bouyer * RETURN: Length of the string plus NULL terminator, rounded up to native
349 1.3.2.2 bouyer * word boundary
350 1.3.2.2 bouyer *
351 1.3.2.2 bouyer * DESCRIPTION: Copy the optional ResourceSource data from a raw AML descriptor
352 1.3.2.2 bouyer * to an internal resource descriptor
353 1.3.2.2 bouyer *
354 1.3.2.2 bouyer ******************************************************************************/
355 1.3.2.2 bouyer
356 1.3.2.2 bouyer ACPI_RS_LENGTH
357 1.3.2.2 bouyer AcpiRsGetResourceSource (
358 1.3.2.2 bouyer ACPI_RS_LENGTH ResourceLength,
359 1.3.2.2 bouyer ACPI_RS_LENGTH MinimumLength,
360 1.3.2.2 bouyer ACPI_RESOURCE_SOURCE *ResourceSource,
361 1.3.2.2 bouyer AML_RESOURCE *Aml,
362 1.3.2.2 bouyer char *StringPtr)
363 1.3.2.2 bouyer {
364 1.3.2.2 bouyer ACPI_RSDESC_SIZE TotalLength;
365 1.3.2.2 bouyer UINT8 *AmlResourceSource;
366 1.3.2.2 bouyer
367 1.3.2.2 bouyer
368 1.3.2.2 bouyer ACPI_FUNCTION_ENTRY ();
369 1.3.2.2 bouyer
370 1.3.2.2 bouyer
371 1.3.2.2 bouyer TotalLength = ResourceLength + sizeof (AML_RESOURCE_LARGE_HEADER);
372 1.3.2.2 bouyer AmlResourceSource = ACPI_ADD_PTR (UINT8, Aml, MinimumLength);
373 1.3.2.2 bouyer
374 1.3.2.2 bouyer /*
375 1.3.2.2 bouyer * ResourceSource is present if the length of the descriptor is longer than
376 1.3.2.2 bouyer * the minimum length.
377 1.3.2.2 bouyer *
378 1.3.2.2 bouyer * Note: Some resource descriptors will have an additional null, so
379 1.3.2.2 bouyer * we add 1 to the minimum length.
380 1.3.2.2 bouyer */
381 1.3.2.2 bouyer if (TotalLength > (ACPI_RSDESC_SIZE) (MinimumLength + 1))
382 1.3.2.2 bouyer {
383 1.3.2.2 bouyer /* Get the ResourceSourceIndex */
384 1.3.2.2 bouyer
385 1.3.2.2 bouyer ResourceSource->Index = AmlResourceSource[0];
386 1.3.2.2 bouyer
387 1.3.2.2 bouyer ResourceSource->StringPtr = StringPtr;
388 1.3.2.2 bouyer if (!StringPtr)
389 1.3.2.2 bouyer {
390 1.3.2.2 bouyer /*
391 1.3.2.2 bouyer * String destination pointer is not specified; Set the String
392 1.3.2.2 bouyer * pointer to the end of the current ResourceSource structure.
393 1.3.2.2 bouyer */
394 1.3.2.2 bouyer ResourceSource->StringPtr = ACPI_ADD_PTR (char, ResourceSource,
395 1.3.2.2 bouyer sizeof (ACPI_RESOURCE_SOURCE));
396 1.3.2.2 bouyer }
397 1.3.2.2 bouyer
398 1.3.2.2 bouyer /*
399 1.3.2.2 bouyer * In order for the Resource length to be a multiple of the native
400 1.3.2.2 bouyer * word, calculate the length of the string (+1 for NULL terminator)
401 1.3.2.2 bouyer * and expand to the next word multiple.
402 1.3.2.2 bouyer *
403 1.3.2.2 bouyer * Zero the entire area of the buffer.
404 1.3.2.2 bouyer */
405 1.3.2.2 bouyer TotalLength = (UINT32) ACPI_STRLEN (
406 1.3.2.2 bouyer ACPI_CAST_PTR (char, &AmlResourceSource[1])) + 1;
407 1.3.2.2 bouyer TotalLength = (UINT32) ACPI_ROUND_UP_TO_NATIVE_WORD (TotalLength);
408 1.3.2.2 bouyer
409 1.3.2.2 bouyer ACPI_MEMSET (ResourceSource->StringPtr, 0, TotalLength);
410 1.3.2.2 bouyer
411 1.3.2.2 bouyer /* Copy the ResourceSource string to the destination */
412 1.3.2.2 bouyer
413 1.3.2.2 bouyer ResourceSource->StringLength = AcpiRsStrcpy (ResourceSource->StringPtr,
414 1.3.2.2 bouyer ACPI_CAST_PTR (char, &AmlResourceSource[1]));
415 1.3.2.2 bouyer
416 1.3.2.2 bouyer return ((ACPI_RS_LENGTH) TotalLength);
417 1.3.2.2 bouyer }
418 1.3.2.2 bouyer
419 1.3.2.2 bouyer /* ResourceSource is not present */
420 1.3.2.2 bouyer
421 1.3.2.2 bouyer ResourceSource->Index = 0;
422 1.3.2.2 bouyer ResourceSource->StringLength = 0;
423 1.3.2.2 bouyer ResourceSource->StringPtr = NULL;
424 1.3.2.2 bouyer return (0);
425 1.3.2.2 bouyer }
426 1.3.2.2 bouyer
427 1.3.2.2 bouyer
428 1.3.2.2 bouyer /*******************************************************************************
429 1.3.2.2 bouyer *
430 1.3.2.2 bouyer * FUNCTION: AcpiRsSetResourceSource
431 1.3.2.2 bouyer *
432 1.3.2.2 bouyer * PARAMETERS: Aml - Pointer to the raw AML descriptor
433 1.3.2.2 bouyer * MinimumLength - Minimum length of the descriptor (minus
434 1.3.2.2 bouyer * any optional fields)
435 1.3.2.2 bouyer * ResourceSource - Internal ResourceSource
436 1.3.2.2 bouyer
437 1.3.2.2 bouyer *
438 1.3.2.2 bouyer * RETURN: Total length of the AML descriptor
439 1.3.2.2 bouyer *
440 1.3.2.2 bouyer * DESCRIPTION: Convert an optional ResourceSource from internal format to a
441 1.3.2.2 bouyer * raw AML resource descriptor
442 1.3.2.2 bouyer *
443 1.3.2.2 bouyer ******************************************************************************/
444 1.3.2.2 bouyer
445 1.3.2.2 bouyer ACPI_RSDESC_SIZE
446 1.3.2.2 bouyer AcpiRsSetResourceSource (
447 1.3.2.2 bouyer AML_RESOURCE *Aml,
448 1.3.2.2 bouyer ACPI_RS_LENGTH MinimumLength,
449 1.3.2.2 bouyer ACPI_RESOURCE_SOURCE *ResourceSource)
450 1.3.2.2 bouyer {
451 1.3.2.2 bouyer UINT8 *AmlResourceSource;
452 1.3.2.2 bouyer ACPI_RSDESC_SIZE DescriptorLength;
453 1.3.2.2 bouyer
454 1.3.2.2 bouyer
455 1.3.2.2 bouyer ACPI_FUNCTION_ENTRY ();
456 1.3.2.2 bouyer
457 1.3.2.2 bouyer
458 1.3.2.2 bouyer DescriptorLength = MinimumLength;
459 1.3.2.2 bouyer
460 1.3.2.2 bouyer /* Non-zero string length indicates presence of a ResourceSource */
461 1.3.2.2 bouyer
462 1.3.2.2 bouyer if (ResourceSource->StringLength)
463 1.3.2.2 bouyer {
464 1.3.2.2 bouyer /* Point to the end of the AML descriptor */
465 1.3.2.2 bouyer
466 1.3.2.2 bouyer AmlResourceSource = ACPI_ADD_PTR (UINT8, Aml, MinimumLength);
467 1.3.2.2 bouyer
468 1.3.2.2 bouyer /* Copy the ResourceSourceIndex */
469 1.3.2.2 bouyer
470 1.3.2.2 bouyer AmlResourceSource[0] = (UINT8) ResourceSource->Index;
471 1.3.2.2 bouyer
472 1.3.2.2 bouyer /* Copy the ResourceSource string */
473 1.3.2.2 bouyer
474 1.3.2.2 bouyer ACPI_STRCPY (ACPI_CAST_PTR (char, &AmlResourceSource[1]),
475 1.3.2.2 bouyer ResourceSource->StringPtr);
476 1.3.2.2 bouyer
477 1.3.2.2 bouyer /*
478 1.3.2.2 bouyer * Add the length of the string (+ 1 for null terminator) to the
479 1.3.2.2 bouyer * final descriptor length
480 1.3.2.2 bouyer */
481 1.3.2.2 bouyer DescriptorLength += ((ACPI_RSDESC_SIZE) ResourceSource->StringLength + 1);
482 1.3.2.2 bouyer }
483 1.3.2.2 bouyer
484 1.3.2.2 bouyer /* Return the new total length of the AML descriptor */
485 1.3.2.2 bouyer
486 1.3.2.2 bouyer return (DescriptorLength);
487 1.3.2.2 bouyer }
488 1.3.2.2 bouyer
489 1.3.2.2 bouyer
490 1.3.2.2 bouyer /*******************************************************************************
491 1.3.2.2 bouyer *
492 1.3.2.2 bouyer * FUNCTION: AcpiRsGetPrtMethodData
493 1.3.2.2 bouyer *
494 1.3.2.2 bouyer * PARAMETERS: Node - Device node
495 1.3.2.2 bouyer * RetBuffer - Pointer to a buffer structure for the
496 1.3.2.2 bouyer * results
497 1.3.2.2 bouyer *
498 1.3.2.2 bouyer * RETURN: Status
499 1.3.2.2 bouyer *
500 1.3.2.2 bouyer * DESCRIPTION: This function is called to get the _PRT value of an object
501 1.3.2.2 bouyer * contained in an object specified by the handle passed in
502 1.3.2.2 bouyer *
503 1.3.2.2 bouyer * If the function fails an appropriate status will be returned
504 1.3.2.2 bouyer * and the contents of the callers buffer is undefined.
505 1.3.2.2 bouyer *
506 1.3.2.2 bouyer ******************************************************************************/
507 1.3.2.2 bouyer
508 1.3.2.2 bouyer ACPI_STATUS
509 1.3.2.2 bouyer AcpiRsGetPrtMethodData (
510 1.3.2.2 bouyer ACPI_NAMESPACE_NODE *Node,
511 1.3.2.2 bouyer ACPI_BUFFER *RetBuffer)
512 1.3.2.2 bouyer {
513 1.3.2.2 bouyer ACPI_OPERAND_OBJECT *ObjDesc;
514 1.3.2.2 bouyer ACPI_STATUS Status;
515 1.3.2.2 bouyer
516 1.3.2.2 bouyer
517 1.3.2.2 bouyer ACPI_FUNCTION_TRACE (RsGetPrtMethodData);
518 1.3.2.2 bouyer
519 1.3.2.2 bouyer
520 1.3.2.2 bouyer /* Parameters guaranteed valid by caller */
521 1.3.2.2 bouyer
522 1.3.2.2 bouyer /* Execute the method, no parameters */
523 1.3.2.2 bouyer
524 1.3.2.2 bouyer Status = AcpiUtEvaluateObject (Node, METHOD_NAME__PRT,
525 1.3.2.2 bouyer ACPI_BTYPE_PACKAGE, &ObjDesc);
526 1.3.2.2 bouyer if (ACPI_FAILURE (Status))
527 1.3.2.2 bouyer {
528 1.3.2.2 bouyer return_ACPI_STATUS (Status);
529 1.3.2.2 bouyer }
530 1.3.2.2 bouyer
531 1.3.2.2 bouyer /*
532 1.3.2.2 bouyer * Create a resource linked list from the byte stream buffer that comes
533 1.3.2.2 bouyer * back from the _CRS method execution.
534 1.3.2.2 bouyer */
535 1.3.2.2 bouyer Status = AcpiRsCreatePciRoutingTable (ObjDesc, RetBuffer);
536 1.3.2.2 bouyer
537 1.3.2.2 bouyer /* On exit, we must delete the object returned by EvaluateObject */
538 1.3.2.2 bouyer
539 1.3.2.2 bouyer AcpiUtRemoveReference (ObjDesc);
540 1.3.2.2 bouyer return_ACPI_STATUS (Status);
541 1.3.2.2 bouyer }
542 1.3.2.2 bouyer
543 1.3.2.2 bouyer
544 1.3.2.2 bouyer /*******************************************************************************
545 1.3.2.2 bouyer *
546 1.3.2.2 bouyer * FUNCTION: AcpiRsGetCrsMethodData
547 1.3.2.2 bouyer *
548 1.3.2.2 bouyer * PARAMETERS: Node - Device node
549 1.3.2.2 bouyer * RetBuffer - Pointer to a buffer structure for the
550 1.3.2.2 bouyer * results
551 1.3.2.2 bouyer *
552 1.3.2.2 bouyer * RETURN: Status
553 1.3.2.2 bouyer *
554 1.3.2.2 bouyer * DESCRIPTION: This function is called to get the _CRS value of an object
555 1.3.2.2 bouyer * contained in an object specified by the handle passed in
556 1.3.2.2 bouyer *
557 1.3.2.2 bouyer * If the function fails an appropriate status will be returned
558 1.3.2.2 bouyer * and the contents of the callers buffer is undefined.
559 1.3.2.2 bouyer *
560 1.3.2.2 bouyer ******************************************************************************/
561 1.3.2.2 bouyer
562 1.3.2.2 bouyer ACPI_STATUS
563 1.3.2.2 bouyer AcpiRsGetCrsMethodData (
564 1.3.2.2 bouyer ACPI_NAMESPACE_NODE *Node,
565 1.3.2.2 bouyer ACPI_BUFFER *RetBuffer)
566 1.3.2.2 bouyer {
567 1.3.2.2 bouyer ACPI_OPERAND_OBJECT *ObjDesc;
568 1.3.2.2 bouyer ACPI_STATUS Status;
569 1.3.2.2 bouyer
570 1.3.2.2 bouyer
571 1.3.2.2 bouyer ACPI_FUNCTION_TRACE (RsGetCrsMethodData);
572 1.3.2.2 bouyer
573 1.3.2.2 bouyer
574 1.3.2.2 bouyer /* Parameters guaranteed valid by caller */
575 1.3.2.2 bouyer
576 1.3.2.2 bouyer /* Execute the method, no parameters */
577 1.3.2.2 bouyer
578 1.3.2.2 bouyer Status = AcpiUtEvaluateObject (Node, METHOD_NAME__CRS,
579 1.3.2.2 bouyer ACPI_BTYPE_BUFFER, &ObjDesc);
580 1.3.2.2 bouyer if (ACPI_FAILURE (Status))
581 1.3.2.2 bouyer {
582 1.3.2.2 bouyer return_ACPI_STATUS (Status);
583 1.3.2.2 bouyer }
584 1.3.2.2 bouyer
585 1.3.2.2 bouyer /*
586 1.3.2.2 bouyer * Make the call to create a resource linked list from the
587 1.3.2.2 bouyer * byte stream buffer that comes back from the _CRS method
588 1.3.2.2 bouyer * execution.
589 1.3.2.2 bouyer */
590 1.3.2.2 bouyer Status = AcpiRsCreateResourceList (ObjDesc, RetBuffer);
591 1.3.2.2 bouyer
592 1.3.2.2 bouyer /* On exit, we must delete the object returned by evaluateObject */
593 1.3.2.2 bouyer
594 1.3.2.2 bouyer AcpiUtRemoveReference (ObjDesc);
595 1.3.2.2 bouyer return_ACPI_STATUS (Status);
596 1.3.2.2 bouyer }
597 1.3.2.2 bouyer
598 1.3.2.2 bouyer
599 1.3.2.2 bouyer /*******************************************************************************
600 1.3.2.2 bouyer *
601 1.3.2.2 bouyer * FUNCTION: AcpiRsGetPrsMethodData
602 1.3.2.2 bouyer *
603 1.3.2.2 bouyer * PARAMETERS: Node - Device node
604 1.3.2.2 bouyer * RetBuffer - Pointer to a buffer structure for the
605 1.3.2.2 bouyer * results
606 1.3.2.2 bouyer *
607 1.3.2.2 bouyer * RETURN: Status
608 1.3.2.2 bouyer *
609 1.3.2.2 bouyer * DESCRIPTION: This function is called to get the _PRS value of an object
610 1.3.2.2 bouyer * contained in an object specified by the handle passed in
611 1.3.2.2 bouyer *
612 1.3.2.2 bouyer * If the function fails an appropriate status will be returned
613 1.3.2.2 bouyer * and the contents of the callers buffer is undefined.
614 1.3.2.2 bouyer *
615 1.3.2.2 bouyer ******************************************************************************/
616 1.3.2.2 bouyer
617 1.3.2.2 bouyer ACPI_STATUS
618 1.3.2.2 bouyer AcpiRsGetPrsMethodData (
619 1.3.2.2 bouyer ACPI_NAMESPACE_NODE *Node,
620 1.3.2.2 bouyer ACPI_BUFFER *RetBuffer)
621 1.3.2.2 bouyer {
622 1.3.2.2 bouyer ACPI_OPERAND_OBJECT *ObjDesc;
623 1.3.2.2 bouyer ACPI_STATUS Status;
624 1.3.2.2 bouyer
625 1.3.2.2 bouyer
626 1.3.2.2 bouyer ACPI_FUNCTION_TRACE (RsGetPrsMethodData);
627 1.3.2.2 bouyer
628 1.3.2.2 bouyer
629 1.3.2.2 bouyer /* Parameters guaranteed valid by caller */
630 1.3.2.2 bouyer
631 1.3.2.2 bouyer /* Execute the method, no parameters */
632 1.3.2.2 bouyer
633 1.3.2.2 bouyer Status = AcpiUtEvaluateObject (Node, METHOD_NAME__PRS,
634 1.3.2.2 bouyer ACPI_BTYPE_BUFFER, &ObjDesc);
635 1.3.2.2 bouyer if (ACPI_FAILURE (Status))
636 1.3.2.2 bouyer {
637 1.3.2.2 bouyer return_ACPI_STATUS (Status);
638 1.3.2.2 bouyer }
639 1.3.2.2 bouyer
640 1.3.2.2 bouyer /*
641 1.3.2.2 bouyer * Make the call to create a resource linked list from the
642 1.3.2.2 bouyer * byte stream buffer that comes back from the _CRS method
643 1.3.2.2 bouyer * execution.
644 1.3.2.2 bouyer */
645 1.3.2.2 bouyer Status = AcpiRsCreateResourceList (ObjDesc, RetBuffer);
646 1.3.2.2 bouyer
647 1.3.2.2 bouyer /* On exit, we must delete the object returned by evaluateObject */
648 1.3.2.2 bouyer
649 1.3.2.2 bouyer AcpiUtRemoveReference (ObjDesc);
650 1.3.2.2 bouyer return_ACPI_STATUS (Status);
651 1.3.2.2 bouyer }
652 1.3.2.2 bouyer
653 1.3.2.2 bouyer
654 1.3.2.2 bouyer /*******************************************************************************
655 1.3.2.2 bouyer *
656 1.3.2.2 bouyer * FUNCTION: AcpiRsGetMethodData
657 1.3.2.2 bouyer *
658 1.3.2.2 bouyer * PARAMETERS: Handle - Handle to the containing object
659 1.3.2.2 bouyer * Path - Path to method, relative to Handle
660 1.3.2.2 bouyer * RetBuffer - Pointer to a buffer structure for the
661 1.3.2.2 bouyer * results
662 1.3.2.2 bouyer *
663 1.3.2.2 bouyer * RETURN: Status
664 1.3.2.2 bouyer *
665 1.3.2.2 bouyer * DESCRIPTION: This function is called to get the _CRS or _PRS value of an
666 1.3.2.2 bouyer * object contained in an object specified by the handle passed in
667 1.3.2.2 bouyer *
668 1.3.2.2 bouyer * If the function fails an appropriate status will be returned
669 1.3.2.2 bouyer * and the contents of the callers buffer is undefined.
670 1.3.2.2 bouyer *
671 1.3.2.2 bouyer ******************************************************************************/
672 1.3.2.2 bouyer
673 1.3.2.2 bouyer ACPI_STATUS
674 1.3.2.2 bouyer AcpiRsGetMethodData (
675 1.3.2.2 bouyer ACPI_HANDLE Handle,
676 1.3.2.2 bouyer char *Path,
677 1.3.2.2 bouyer ACPI_BUFFER *RetBuffer)
678 1.3.2.2 bouyer {
679 1.3.2.2 bouyer ACPI_OPERAND_OBJECT *ObjDesc;
680 1.3.2.2 bouyer ACPI_STATUS Status;
681 1.3.2.2 bouyer
682 1.3.2.2 bouyer
683 1.3.2.2 bouyer ACPI_FUNCTION_TRACE (RsGetMethodData);
684 1.3.2.2 bouyer
685 1.3.2.2 bouyer
686 1.3.2.2 bouyer /* Parameters guaranteed valid by caller */
687 1.3.2.2 bouyer
688 1.3.2.2 bouyer /* Execute the method, no parameters */
689 1.3.2.2 bouyer
690 1.3.2.2 bouyer Status = AcpiUtEvaluateObject (Handle, Path, ACPI_BTYPE_BUFFER, &ObjDesc);
691 1.3.2.2 bouyer if (ACPI_FAILURE (Status))
692 1.3.2.2 bouyer {
693 1.3.2.2 bouyer return_ACPI_STATUS (Status);
694 1.3.2.2 bouyer }
695 1.3.2.2 bouyer
696 1.3.2.2 bouyer /*
697 1.3.2.2 bouyer * Make the call to create a resource linked list from the
698 1.3.2.2 bouyer * byte stream buffer that comes back from the method
699 1.3.2.2 bouyer * execution.
700 1.3.2.2 bouyer */
701 1.3.2.2 bouyer Status = AcpiRsCreateResourceList (ObjDesc, RetBuffer);
702 1.3.2.2 bouyer
703 1.3.2.2 bouyer /* On exit, we must delete the object returned by EvaluateObject */
704 1.3.2.2 bouyer
705 1.3.2.2 bouyer AcpiUtRemoveReference (ObjDesc);
706 1.3.2.2 bouyer return_ACPI_STATUS (Status);
707 1.3.2.2 bouyer }
708 1.3.2.2 bouyer
709 1.3.2.2 bouyer
710 1.3.2.2 bouyer /*******************************************************************************
711 1.3.2.2 bouyer *
712 1.3.2.2 bouyer * FUNCTION: AcpiRsSetSrsMethodData
713 1.3.2.2 bouyer *
714 1.3.2.2 bouyer * PARAMETERS: Node - Device node
715 1.3.2.2 bouyer * InBuffer - Pointer to a buffer structure of the
716 1.3.2.2 bouyer * parameter
717 1.3.2.2 bouyer *
718 1.3.2.2 bouyer * RETURN: Status
719 1.3.2.2 bouyer *
720 1.3.2.2 bouyer * DESCRIPTION: This function is called to set the _SRS of an object contained
721 1.3.2.2 bouyer * in an object specified by the handle passed in
722 1.3.2.2 bouyer *
723 1.3.2.2 bouyer * If the function fails an appropriate status will be returned
724 1.3.2.2 bouyer * and the contents of the callers buffer is undefined.
725 1.3.2.2 bouyer *
726 1.3.2.2 bouyer * Note: Parameters guaranteed valid by caller
727 1.3.2.2 bouyer *
728 1.3.2.2 bouyer ******************************************************************************/
729 1.3.2.2 bouyer
730 1.3.2.2 bouyer ACPI_STATUS
731 1.3.2.2 bouyer AcpiRsSetSrsMethodData (
732 1.3.2.2 bouyer ACPI_NAMESPACE_NODE *Node,
733 1.3.2.2 bouyer ACPI_BUFFER *InBuffer)
734 1.3.2.2 bouyer {
735 1.3.2.2 bouyer ACPI_EVALUATE_INFO *Info;
736 1.3.2.2 bouyer ACPI_OPERAND_OBJECT *Args[2];
737 1.3.2.2 bouyer ACPI_STATUS Status;
738 1.3.2.2 bouyer ACPI_BUFFER Buffer;
739 1.3.2.2 bouyer
740 1.3.2.2 bouyer
741 1.3.2.2 bouyer ACPI_FUNCTION_TRACE (RsSetSrsMethodData);
742 1.3.2.2 bouyer
743 1.3.2.2 bouyer
744 1.3.2.2 bouyer /* Allocate and initialize the evaluation information block */
745 1.3.2.2 bouyer
746 1.3.2.2 bouyer Info = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO));
747 1.3.2.2 bouyer if (!Info)
748 1.3.2.2 bouyer {
749 1.3.2.2 bouyer return_ACPI_STATUS (AE_NO_MEMORY);
750 1.3.2.2 bouyer }
751 1.3.2.2 bouyer
752 1.3.2.2 bouyer Info->PrefixNode = Node;
753 1.3.2.2 bouyer Info->Pathname = __UNCONST(METHOD_NAME__SRS);
754 1.3.2.2 bouyer Info->Parameters = Args;
755 1.3.2.2 bouyer Info->Flags = ACPI_IGNORE_RETURN_VALUE;
756 1.3.2.2 bouyer
757 1.3.2.2 bouyer /*
758 1.3.2.2 bouyer * The InBuffer parameter will point to a linked list of
759 1.3.2.2 bouyer * resource parameters. It needs to be formatted into a
760 1.3.2.2 bouyer * byte stream to be sent in as an input parameter to _SRS
761 1.3.2.2 bouyer *
762 1.3.2.2 bouyer * Convert the linked list into a byte stream
763 1.3.2.2 bouyer */
764 1.3.2.2 bouyer Buffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
765 1.3.2.2 bouyer Status = AcpiRsCreateAmlResources (InBuffer->Pointer, &Buffer);
766 1.3.2.2 bouyer if (ACPI_FAILURE (Status))
767 1.3.2.2 bouyer {
768 1.3.2.2 bouyer goto Cleanup;
769 1.3.2.2 bouyer }
770 1.3.2.2 bouyer
771 1.3.2.2 bouyer /* Create and initialize the method parameter object */
772 1.3.2.2 bouyer
773 1.3.2.2 bouyer Args[0] = AcpiUtCreateInternalObject (ACPI_TYPE_BUFFER);
774 1.3.2.2 bouyer if (!Args[0])
775 1.3.2.2 bouyer {
776 1.3.2.2 bouyer /*
777 1.3.2.2 bouyer * Must free the buffer allocated above (otherwise it is freed
778 1.3.2.2 bouyer * later)
779 1.3.2.2 bouyer */
780 1.3.2.2 bouyer ACPI_FREE (Buffer.Pointer);
781 1.3.2.2 bouyer Status = AE_NO_MEMORY;
782 1.3.2.2 bouyer goto Cleanup;
783 1.3.2.2 bouyer }
784 1.3.2.2 bouyer
785 1.3.2.2 bouyer Args[0]->Buffer.Length = (UINT32) Buffer.Length;
786 1.3.2.2 bouyer Args[0]->Buffer.Pointer = Buffer.Pointer;
787 1.3.2.2 bouyer Args[0]->Common.Flags = AOPOBJ_DATA_VALID;
788 1.3.2.2 bouyer Args[1] = NULL;
789 1.3.2.2 bouyer
790 1.3.2.2 bouyer /* Execute the method, no return value is expected */
791 1.3.2.2 bouyer
792 1.3.2.2 bouyer Status = AcpiNsEvaluate (Info);
793 1.3.2.2 bouyer
794 1.3.2.2 bouyer /* Clean up and return the status from AcpiNsEvaluate */
795 1.3.2.2 bouyer
796 1.3.2.2 bouyer AcpiUtRemoveReference (Args[0]);
797 1.3.2.2 bouyer
798 1.3.2.2 bouyer Cleanup:
799 1.3.2.2 bouyer ACPI_FREE (Info);
800 1.3.2.2 bouyer return_ACPI_STATUS (Status);
801 1.3.2.2 bouyer }
802 1.3.2.2 bouyer
803