]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - sys/contrib/dev/acpica/resources/rslist.c
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / sys / contrib / dev / acpica / resources / rslist.c
1 /*******************************************************************************
2  *
3  * Module Name: rslist - Linked list utilities
4  *
5  ******************************************************************************/
6
7 /*
8  * Copyright (C) 2000 - 2011, Intel Corp.
9  * All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions, and the following disclaimer,
16  *    without modification.
17  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18  *    substantially similar to the "NO WARRANTY" disclaimer below
19  *    ("Disclaimer") and any redistribution must be conditioned upon
20  *    including a substantially similar Disclaimer requirement for further
21  *    binary redistribution.
22  * 3. Neither the names of the above-listed copyright holders nor the names
23  *    of any contributors may be used to endorse or promote products derived
24  *    from this software without specific prior written permission.
25  *
26  * Alternatively, this software may be distributed under the terms of the
27  * GNU General Public License ("GPL") version 2 as published by the Free
28  * Software Foundation.
29  *
30  * NO WARRANTY
31  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41  * POSSIBILITY OF SUCH DAMAGES.
42  */
43
44 #define __RSLIST_C__
45
46 #include <contrib/dev/acpica/include/acpi.h>
47 #include <contrib/dev/acpica/include/accommon.h>
48 #include <contrib/dev/acpica/include/acresrc.h>
49
50 #define _COMPONENT          ACPI_RESOURCES
51         ACPI_MODULE_NAME    ("rslist")
52
53
54 /*******************************************************************************
55  *
56  * FUNCTION:    AcpiRsConvertAmlToResources
57  *
58  * PARAMETERS:  ACPI_WALK_AML_CALLBACK
59  *              ResourcePtr             - Pointer to the buffer that will
60  *                                        contain the output structures
61  *
62  * RETURN:      Status
63  *
64  * DESCRIPTION: Convert an AML resource to an internal representation of the
65  *              resource that is aligned and easier to access.
66  *
67  ******************************************************************************/
68
69 ACPI_STATUS
70 AcpiRsConvertAmlToResources (
71     UINT8                   *Aml,
72     UINT32                  Length,
73     UINT32                  Offset,
74     UINT8                   ResourceIndex,
75     void                    *Context)
76 {
77     ACPI_RESOURCE           **ResourcePtr = ACPI_CAST_INDIRECT_PTR (
78                                 ACPI_RESOURCE, Context);
79     ACPI_RESOURCE           *Resource;
80     ACPI_STATUS             Status;
81
82
83     ACPI_FUNCTION_TRACE (RsConvertAmlToResources);
84
85
86     /*
87      * Check that the input buffer and all subsequent pointers into it
88      * are aligned on a native word boundary. Most important on IA64
89      */
90     Resource = *ResourcePtr;
91     if (ACPI_IS_MISALIGNED (Resource))
92     {
93         ACPI_WARNING ((AE_INFO,
94             "Misaligned resource pointer %p", Resource));
95     }
96
97     /* Convert the AML byte stream resource to a local resource struct */
98
99     Status = AcpiRsConvertAmlToResource (
100                 Resource, ACPI_CAST_PTR (AML_RESOURCE, Aml),
101                 AcpiGbl_GetResourceDispatch[ResourceIndex]);
102     if (ACPI_FAILURE (Status))
103     {
104         ACPI_EXCEPTION ((AE_INFO, Status,
105             "Could not convert AML resource (Type 0x%X)", *Aml));
106         return_ACPI_STATUS (Status);
107     }
108
109     ACPI_DEBUG_PRINT ((ACPI_DB_RESOURCES,
110         "Type %.2X, AmlLength %.2X InternalLength %.2X\n",
111         AcpiUtGetResourceType (Aml), Length,
112         Resource->Length));
113
114     /* Point to the next structure in the output buffer */
115
116     *ResourcePtr = ACPI_ADD_PTR (void, Resource, Resource->Length);
117     return_ACPI_STATUS (AE_OK);
118 }
119
120
121 /*******************************************************************************
122  *
123  * FUNCTION:    AcpiRsConvertResourcesToAml
124  *
125  * PARAMETERS:  Resource            - Pointer to the resource linked list
126  *              AmlSizeNeeded       - Calculated size of the byte stream
127  *                                    needed from calling AcpiRsGetAmlLength()
128  *                                    The size of the OutputBuffer is
129  *                                    guaranteed to be >= AmlSizeNeeded
130  *              OutputBuffer        - Pointer to the buffer that will
131  *                                    contain the byte stream
132  *
133  * RETURN:      Status
134  *
135  * DESCRIPTION: Takes the resource linked list and parses it, creating a
136  *              byte stream of resources in the caller's output buffer
137  *
138  ******************************************************************************/
139
140 ACPI_STATUS
141 AcpiRsConvertResourcesToAml (
142     ACPI_RESOURCE           *Resource,
143     ACPI_SIZE               AmlSizeNeeded,
144     UINT8                   *OutputBuffer)
145 {
146     UINT8                   *Aml = OutputBuffer;
147     UINT8                   *EndAml = OutputBuffer + AmlSizeNeeded;
148     ACPI_STATUS             Status;
149
150
151     ACPI_FUNCTION_TRACE (RsConvertResourcesToAml);
152
153
154     /* Walk the resource descriptor list, convert each descriptor */
155
156     while (Aml < EndAml)
157     {
158         /* Validate the (internal) Resource Type */
159
160         if (Resource->Type > ACPI_RESOURCE_TYPE_MAX)
161         {
162             ACPI_ERROR ((AE_INFO,
163                 "Invalid descriptor type (0x%X) in resource list",
164                 Resource->Type));
165             return_ACPI_STATUS (AE_BAD_DATA);
166         }
167
168         /* Perform the conversion */
169
170         Status = AcpiRsConvertResourceToAml (Resource,
171                     ACPI_CAST_PTR (AML_RESOURCE, Aml),
172                     AcpiGbl_SetResourceDispatch[Resource->Type]);
173         if (ACPI_FAILURE (Status))
174         {
175             ACPI_EXCEPTION ((AE_INFO, Status,
176                 "Could not convert resource (type 0x%X) to AML",
177                 Resource->Type));
178             return_ACPI_STATUS (Status);
179         }
180
181         /* Perform final sanity check on the new AML resource descriptor */
182
183         Status = AcpiUtValidateResource (
184                     ACPI_CAST_PTR (AML_RESOURCE, Aml), NULL);
185         if (ACPI_FAILURE (Status))
186         {
187             return_ACPI_STATUS (Status);
188         }
189
190         /* Check for end-of-list, normal exit */
191
192         if (Resource->Type == ACPI_RESOURCE_TYPE_END_TAG)
193         {
194             /* An End Tag indicates the end of the input Resource Template */
195
196             return_ACPI_STATUS (AE_OK);
197         }
198
199         /*
200          * Extract the total length of the new descriptor and set the
201          * Aml to point to the next (output) resource descriptor
202          */
203         Aml += AcpiUtGetDescriptorLength (Aml);
204
205         /* Point to the next input resource descriptor */
206
207         Resource = ACPI_ADD_PTR (ACPI_RESOURCE, Resource, Resource->Length);
208     }
209
210     /* Completed buffer, but did not find an EndTag resource descriptor */
211
212     return_ACPI_STATUS (AE_AML_NO_RESOURCE_END_TAG);
213 }
214