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