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