rsutils.c revision 77424
1/*******************************************************************************
2 *
3 * Module Name: rsutils - Utilities for the resource manager
4 *              $Revision: 19 $
5 *
6 ******************************************************************************/
7
8/******************************************************************************
9 *
10 * 1. Copyright Notice
11 *
12 * Some or all of this work - Copyright (c) 1999, 2000, 2001, Intel Corp.
13 * All rights reserved.
14 *
15 * 2. License
16 *
17 * 2.1. This is your license from Intel Corp. under its intellectual property
18 * rights.  You may have additional license terms from the party that provided
19 * you this software, covering your right to use that party's intellectual
20 * property rights.
21 *
22 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23 * copy of the source code appearing in this file ("Covered Code") an
24 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25 * base code distributed originally by Intel ("Original Intel Code") to copy,
26 * make derivatives, distribute, use and display any portion of the Covered
27 * Code in any form, with the right to sublicense such rights; and
28 *
29 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30 * license (with the right to sublicense), under only those claims of Intel
31 * patents that are infringed by the Original Intel Code, to make, use, sell,
32 * offer to sell, and import the Covered Code and derivative works thereof
33 * solely to the minimum extent necessary to exercise the above copyright
34 * license, and in no event shall the patent license extend to any additions
35 * to or modifications of the Original Intel Code.  No other license or right
36 * is granted directly or by implication, estoppel or otherwise;
37 *
38 * The above copyright and patent license is granted only if the following
39 * conditions are met:
40 *
41 * 3. Conditions
42 *
43 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44 * Redistribution of source code of any substantial portion of the Covered
45 * Code or modification with rights to further distribute source must include
46 * the above Copyright Notice, the above License, this list of Conditions,
47 * and the following Disclaimer and Export Compliance provision.  In addition,
48 * Licensee must cause all Covered Code to which Licensee contributes to
49 * contain a file documenting the changes Licensee made to create that Covered
50 * Code and the date of any change.  Licensee must include in that file the
51 * documentation of any changes made by any predecessor Licensee.  Licensee
52 * must include a prominent statement that the modification is derived,
53 * directly or indirectly, from Original Intel Code.
54 *
55 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56 * Redistribution of source code of any substantial portion of the Covered
57 * Code or modification without rights to further distribute source must
58 * include the following Disclaimer and Export Compliance provision in the
59 * documentation and/or other materials provided with distribution.  In
60 * addition, Licensee may not authorize further sublicense of source of any
61 * portion of the Covered Code, and must include terms to the effect that the
62 * license from Licensee to its licensee is limited to the intellectual
63 * property embodied in the software Licensee provides to its licensee, and
64 * not to intellectual property embodied in modifications its licensee may
65 * make.
66 *
67 * 3.3. Redistribution of Executable. Redistribution in executable form of any
68 * substantial portion of the Covered Code or modification must reproduce the
69 * above Copyright Notice, and the following Disclaimer and Export Compliance
70 * provision in the documentation and/or other materials provided with the
71 * distribution.
72 *
73 * 3.4. Intel retains all right, title, and interest in and to the Original
74 * Intel Code.
75 *
76 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77 * Intel shall be used in advertising or otherwise to promote the sale, use or
78 * other dealings in products derived from or relating to the Covered Code
79 * without prior written authorization from Intel.
80 *
81 * 4. Disclaimer and Export Compliance
82 *
83 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84 * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
86 * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
87 * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
88 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
89 * PARTICULAR PURPOSE.
90 *
91 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
97 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
98 * LIMITED REMEDY.
99 *
100 * 4.3. Licensee shall not export, either directly or indirectly, any of this
101 * software or system incorporating such software without first obtaining any
102 * required license or other approval from the U. S. Department of Commerce or
103 * any other agency or department of the United States Government.  In the
104 * event Licensee exports any such software from the United States or
105 * re-exports any such software from a foreign destination, Licensee shall
106 * ensure that the distribution and export/re-export of the software is in
107 * compliance with all laws, regulations, orders, or other restrictions of the
108 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109 * any of its subsidiaries will export/re-export any technical data, process,
110 * software, or service, directly or indirectly, to any country for which the
111 * United States government or any agency thereof requires an export license,
112 * other governmental approval, or letter of assurance, without first obtaining
113 * such license, approval or letter.
114 *
115 *****************************************************************************/
116
117
118#define __RSUTILS_C__
119
120#include "acpi.h"
121#include "acnamesp.h"
122#include "acresrc.h"
123
124
125#define _COMPONENT          ACPI_RESOURCES
126        MODULE_NAME         ("rsutils")
127
128
129/*******************************************************************************
130 *
131 * FUNCTION:    AcpiRsGetPrtMethodData
132 *
133 * PARAMETERS:  Handle          - a handle to the containing object
134 *              RetBuffer       - a pointer to a buffer structure for the
135 *                                  results
136 *
137 * RETURN:      Status
138 *
139 * DESCRIPTION: This function is called to get the _PRT value of an object
140 *              contained in an object specified by the handle passed in
141 *
142 *              If the function fails an appropriate status will be returned
143 *              and the contents of the callers buffer is undefined.
144 *
145 ******************************************************************************/
146
147ACPI_STATUS
148AcpiRsGetPrtMethodData (
149    ACPI_HANDLE             Handle,
150    ACPI_BUFFER             *RetBuffer)
151{
152    ACPI_OPERAND_OBJECT     *RetObj;
153    ACPI_STATUS             Status;
154    UINT32                  BufferSpaceNeeded;
155
156
157    FUNCTION_TRACE ("RsGetPrtMethodData");
158
159
160    /* already validated params, so we won't repeat here */
161
162    BufferSpaceNeeded = RetBuffer->Length;
163
164    /*
165     *  Execute the method, no parameters
166     */
167    Status = AcpiNsEvaluateRelative (Handle, "_PRT", NULL, &RetObj);
168    if (ACPI_FAILURE (Status))
169    {
170        return_ACPI_STATUS (Status);
171    }
172
173    if (!RetObj)
174    {
175        /* Return object is required */
176
177        DEBUG_PRINTP (ACPI_ERROR, ("No object was returned from _PRT\n"));
178        return_ACPI_STATUS (AE_TYPE);
179    }
180
181
182    /*
183     * The return object will be a package, so check the
184     *  parameters.  If the return object is not a package,
185     *  then the underlying AML code is corrupt or improperly
186     *  written.
187     */
188    if (ACPI_TYPE_PACKAGE != RetObj->Common.Type)
189    {
190        Status = AE_AML_OPERAND_TYPE;
191        goto Cleanup;
192    }
193
194    /*
195     * Make the call to create a resource linked list from the
196     *  byte stream buffer that comes back from the _CRS method
197     *  execution.
198     */
199    Status = AcpiRsCreatePciRoutingTable (RetObj, RetBuffer->Pointer,
200                    &BufferSpaceNeeded);
201
202    /*
203     * Tell the user how much of the buffer we have used or is needed
204     *  and return the final status.
205     */
206    RetBuffer->Length = BufferSpaceNeeded;
207
208
209    /* On exit, we must delete the object returned by evaluateObject */
210
211Cleanup:
212
213    AcpiUtRemoveReference (RetObj);
214    return_ACPI_STATUS (Status);
215}
216
217
218/*******************************************************************************
219 *
220 * FUNCTION:    AcpiRsGetCrsMethodData
221 *
222 * PARAMETERS:  Handle          - a handle to the containing object
223 *              RetBuffer       - a pointer to a buffer structure for the
224 *                                  results
225 *
226 * RETURN:      Status
227 *
228 * DESCRIPTION: This function is called to get the _CRS value of an object
229 *              contained in an object specified by the handle passed in
230 *
231 *              If the function fails an appropriate status will be returned
232 *              and the contents of the callers buffer is undefined.
233 *
234 ******************************************************************************/
235
236ACPI_STATUS
237AcpiRsGetCrsMethodData (
238    ACPI_HANDLE             Handle,
239    ACPI_BUFFER             *RetBuffer)
240{
241    ACPI_OPERAND_OBJECT     *RetObj;
242    ACPI_STATUS             Status;
243    UINT32                  BufferSpaceNeeded = RetBuffer->Length;
244
245
246    FUNCTION_TRACE ("RsGetCrsMethodData");
247
248
249    /* already validated params, so we won't repeat here */
250
251    /*
252     *  Execute the method, no parameters
253     */
254    Status = AcpiNsEvaluateRelative (Handle, "_CRS", NULL, &RetObj);
255    if (ACPI_FAILURE (Status))
256    {
257        return_ACPI_STATUS (Status);
258    }
259
260    if (!RetObj)
261    {
262        /* Return object is required */
263
264        DEBUG_PRINTP (ACPI_ERROR, ("No object was returned from _CRS\n"));
265        return_ACPI_STATUS (AE_TYPE);
266    }
267
268    /*
269     * The return object will be a buffer, but check the
270     *  parameters.  If the return object is not a buffer,
271     *  then the underlying AML code is corrupt or improperly
272     *  written.
273     */
274    if (ACPI_TYPE_BUFFER != RetObj->Common.Type)
275    {
276        Status = AE_AML_OPERAND_TYPE;
277        goto Cleanup;
278    }
279
280    /*
281     * Make the call to create a resource linked list from the
282     *  byte stream buffer that comes back from the _CRS method
283     *  execution.
284     */
285    Status = AcpiRsCreateResourceList (RetObj, RetBuffer->Pointer,
286                &BufferSpaceNeeded);
287
288
289    /*
290     * Tell the user how much of the buffer we have used or is needed
291     *  and return the final status.
292     */
293    RetBuffer->Length = BufferSpaceNeeded;
294
295
296    /* On exit, we must delete the object returned by evaluateObject */
297
298Cleanup:
299
300    AcpiUtRemoveReference (RetObj);
301    return_ACPI_STATUS (Status);
302}
303
304
305/*******************************************************************************
306 *
307 * FUNCTION:    AcpiRsGetPrsMethodData
308 *
309 * PARAMETERS:  Handle          - a handle to the containing object
310 *              RetBuffer       - a pointer to a buffer structure for the
311 *                                  results
312 *
313 * RETURN:      Status
314 *
315 * DESCRIPTION: This function is called to get the _PRS value of an object
316 *              contained in an object specified by the handle passed in
317 *
318 *              If the function fails an appropriate status will be returned
319 *              and the contents of the callers buffer is undefined.
320 *
321 ******************************************************************************/
322
323ACPI_STATUS
324AcpiRsGetPrsMethodData (
325    ACPI_HANDLE             Handle,
326    ACPI_BUFFER             *RetBuffer)
327{
328    ACPI_OPERAND_OBJECT     *RetObj;
329    ACPI_STATUS             Status;
330    UINT32                  BufferSpaceNeeded = RetBuffer->Length;
331
332
333    FUNCTION_TRACE ("RsGetPrsMethodData");
334
335
336    /* already validated params, so we won't repeat here */
337
338    /*
339     *  Execute the method, no parameters
340     */
341    Status = AcpiNsEvaluateRelative (Handle, "_PRS", NULL, &RetObj);
342    if (ACPI_FAILURE (Status))
343    {
344        return_ACPI_STATUS (Status);
345    }
346
347    if (!RetObj)
348    {
349        /* Return object is required */
350
351        DEBUG_PRINTP (ACPI_ERROR, ("No object was returned from _PRS\n"));
352        return_ACPI_STATUS (AE_TYPE);
353    }
354
355    /*
356     * The return object will be a buffer, but check the
357     *  parameters.  If the return object is not a buffer,
358     *  then the underlying AML code is corrupt or improperly
359     *  written..
360     */
361    if (ACPI_TYPE_BUFFER != RetObj->Common.Type)
362    {
363        Status = AE_AML_OPERAND_TYPE;
364        goto Cleanup;
365    }
366
367    /*
368     * Make the call to create a resource linked list from the
369     *  byte stream buffer that comes back from the _CRS method
370     *  execution.
371     */
372    Status = AcpiRsCreateResourceList (RetObj, RetBuffer->Pointer,
373                &BufferSpaceNeeded);
374
375    /*
376     * Tell the user how much of the buffer we have used or is needed
377     *  and return the final status.
378     */
379    RetBuffer->Length = BufferSpaceNeeded;
380
381
382    /* On exit, we must delete the object returned by evaluateObject */
383
384Cleanup:
385
386    AcpiUtRemoveReference (RetObj);
387    return_ACPI_STATUS (Status);
388}
389
390
391/*******************************************************************************
392 *
393 * FUNCTION:    AcpiRsSetSrsMethodData
394 *
395 * PARAMETERS:  Handle          - a handle to the containing object
396 *              InBuffer        - a pointer to a buffer structure of the
397 *                                  parameter
398 *
399 * RETURN:      Status
400 *
401 * DESCRIPTION: This function is called to set the _SRS of an object contained
402 *              in an object specified by the handle passed in
403 *
404 *              If the function fails an appropriate status will be returned
405 *              and the contents of the callers buffer is undefined.
406 *
407 ******************************************************************************/
408
409ACPI_STATUS
410AcpiRsSetSrsMethodData (
411    ACPI_HANDLE             Handle,
412    ACPI_BUFFER             *InBuffer)
413{
414    ACPI_OPERAND_OBJECT     *Params[2];
415    ACPI_OPERAND_OBJECT     ParamObj;
416    ACPI_STATUS             Status;
417    UINT8                   *ByteStream = NULL;
418    UINT32                  BufferSizeNeeded = 0;
419
420
421    FUNCTION_TRACE ("RsSetSrsMethodData");
422
423
424    /* already validated params, so we won't repeat here */
425
426    /*
427     * The InBuffer parameter will point to a linked list of
428     * resource parameters.  It needs to be formatted into a
429     * byte stream to be sent in as an input parameter.
430     */
431    BufferSizeNeeded = 0;
432
433    /*
434     * First call is to get the buffer size needed
435     */
436    Status = AcpiRsCreateByteStream (InBuffer->Pointer, ByteStream,
437                &BufferSizeNeeded);
438    /*
439     * We expect a return of AE_BUFFER_OVERFLOW
440     * if not, exit with the error
441     */
442    if (AE_BUFFER_OVERFLOW != Status)
443    {
444        return_ACPI_STATUS (Status);
445    }
446
447    /*
448     * Allocate the buffer needed
449     */
450    ByteStream = AcpiUtCallocate(BufferSizeNeeded);
451    if (NULL == ByteStream)
452    {
453        return_ACPI_STATUS (AE_NO_MEMORY);
454    }
455
456    /*
457     * Now call to convert the linked list into a byte stream
458     */
459    Status = AcpiRsCreateByteStream (InBuffer->Pointer, ByteStream,
460                &BufferSizeNeeded);
461    if (ACPI_FAILURE (Status))
462    {
463        goto Cleanup;
464    }
465
466    /*
467     * Init the param object
468     */
469    AcpiUtInitStaticObject (&ParamObj);
470
471    /*
472     * Method requires one parameter.  Set it up
473     */
474    Params [0] = &ParamObj;
475    Params [1] = NULL;
476
477    /*
478     *  Set up the parameter object
479     */
480    ParamObj.Common.Type    = ACPI_TYPE_BUFFER;
481    ParamObj.Buffer.Length  = BufferSizeNeeded;
482    ParamObj.Buffer.Pointer = ByteStream;
483
484    /*
485     * Execute the method, no return value
486     */
487    Status = AcpiNsEvaluateRelative (Handle, "_SRS", Params, NULL);
488
489    /*
490     * Clean up and return the status from AcpiNsEvaluateRelative
491     */
492Cleanup:
493
494    AcpiUtFree (ByteStream);
495    return_ACPI_STATUS (Status);
496}
497
498