rsxface.c revision 1.4 1 1.1 jruoho /*******************************************************************************
2 1.1 jruoho *
3 1.1 jruoho * Module Name: rsxface - Public interfaces to the resource manager
4 1.1 jruoho *
5 1.1 jruoho ******************************************************************************/
6 1.1 jruoho
7 1.3 jruoho /*
8 1.4 christos * Copyright (C) 2000 - 2013, 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 __RSXFACE_C__
46 1.4 christos #define EXPORT_ACPI_INTERFACES
47 1.1 jruoho
48 1.1 jruoho #include "acpi.h"
49 1.1 jruoho #include "accommon.h"
50 1.1 jruoho #include "acresrc.h"
51 1.1 jruoho #include "acnamesp.h"
52 1.1 jruoho
53 1.1 jruoho #define _COMPONENT ACPI_RESOURCES
54 1.1 jruoho ACPI_MODULE_NAME ("rsxface")
55 1.1 jruoho
56 1.1 jruoho /* Local macros for 16,32-bit to 64-bit conversion */
57 1.1 jruoho
58 1.1 jruoho #define ACPI_COPY_FIELD(Out, In, Field) ((Out)->Field = (In)->Field)
59 1.1 jruoho #define ACPI_COPY_ADDRESS(Out, In) \
60 1.1 jruoho ACPI_COPY_FIELD(Out, In, ResourceType); \
61 1.1 jruoho ACPI_COPY_FIELD(Out, In, ProducerConsumer); \
62 1.1 jruoho ACPI_COPY_FIELD(Out, In, Decode); \
63 1.1 jruoho ACPI_COPY_FIELD(Out, In, MinAddressFixed); \
64 1.1 jruoho ACPI_COPY_FIELD(Out, In, MaxAddressFixed); \
65 1.1 jruoho ACPI_COPY_FIELD(Out, In, Info); \
66 1.1 jruoho ACPI_COPY_FIELD(Out, In, Granularity); \
67 1.1 jruoho ACPI_COPY_FIELD(Out, In, Minimum); \
68 1.1 jruoho ACPI_COPY_FIELD(Out, In, Maximum); \
69 1.1 jruoho ACPI_COPY_FIELD(Out, In, TranslationOffset); \
70 1.1 jruoho ACPI_COPY_FIELD(Out, In, AddressLength); \
71 1.1 jruoho ACPI_COPY_FIELD(Out, In, ResourceSource);
72 1.1 jruoho
73 1.1 jruoho
74 1.1 jruoho /* Local prototypes */
75 1.1 jruoho
76 1.1 jruoho static ACPI_STATUS
77 1.1 jruoho AcpiRsMatchVendorResource (
78 1.1 jruoho ACPI_RESOURCE *Resource,
79 1.1 jruoho void *Context);
80 1.1 jruoho
81 1.1 jruoho static ACPI_STATUS
82 1.1 jruoho AcpiRsValidateParameters (
83 1.1 jruoho ACPI_HANDLE DeviceHandle,
84 1.1 jruoho ACPI_BUFFER *Buffer,
85 1.1 jruoho ACPI_NAMESPACE_NODE **ReturnNode);
86 1.1 jruoho
87 1.1 jruoho
88 1.1 jruoho /*******************************************************************************
89 1.1 jruoho *
90 1.1 jruoho * FUNCTION: AcpiRsValidateParameters
91 1.1 jruoho *
92 1.1 jruoho * PARAMETERS: DeviceHandle - Handle to a device
93 1.1 jruoho * Buffer - Pointer to a data buffer
94 1.1 jruoho * ReturnNode - Pointer to where the device node is returned
95 1.1 jruoho *
96 1.1 jruoho * RETURN: Status
97 1.1 jruoho *
98 1.1 jruoho * DESCRIPTION: Common parameter validation for resource interfaces
99 1.1 jruoho *
100 1.1 jruoho ******************************************************************************/
101 1.1 jruoho
102 1.1 jruoho static ACPI_STATUS
103 1.1 jruoho AcpiRsValidateParameters (
104 1.1 jruoho ACPI_HANDLE DeviceHandle,
105 1.1 jruoho ACPI_BUFFER *Buffer,
106 1.1 jruoho ACPI_NAMESPACE_NODE **ReturnNode)
107 1.1 jruoho {
108 1.1 jruoho ACPI_STATUS Status;
109 1.1 jruoho ACPI_NAMESPACE_NODE *Node;
110 1.1 jruoho
111 1.1 jruoho
112 1.1 jruoho ACPI_FUNCTION_TRACE (RsValidateParameters);
113 1.1 jruoho
114 1.1 jruoho
115 1.1 jruoho /*
116 1.1 jruoho * Must have a valid handle to an ACPI device
117 1.1 jruoho */
118 1.1 jruoho if (!DeviceHandle)
119 1.1 jruoho {
120 1.1 jruoho return_ACPI_STATUS (AE_BAD_PARAMETER);
121 1.1 jruoho }
122 1.1 jruoho
123 1.1 jruoho Node = AcpiNsValidateHandle (DeviceHandle);
124 1.1 jruoho if (!Node)
125 1.1 jruoho {
126 1.1 jruoho return_ACPI_STATUS (AE_BAD_PARAMETER);
127 1.1 jruoho }
128 1.1 jruoho
129 1.1 jruoho if (Node->Type != ACPI_TYPE_DEVICE)
130 1.1 jruoho {
131 1.1 jruoho return_ACPI_STATUS (AE_TYPE);
132 1.1 jruoho }
133 1.1 jruoho
134 1.1 jruoho /*
135 1.1 jruoho * Validate the user buffer object
136 1.1 jruoho *
137 1.1 jruoho * if there is a non-zero buffer length we also need a valid pointer in
138 1.1 jruoho * the buffer. If it's a zero buffer length, we'll be returning the
139 1.1 jruoho * needed buffer size (later), so keep going.
140 1.1 jruoho */
141 1.1 jruoho Status = AcpiUtValidateBuffer (Buffer);
142 1.1 jruoho if (ACPI_FAILURE (Status))
143 1.1 jruoho {
144 1.1 jruoho return_ACPI_STATUS (Status);
145 1.1 jruoho }
146 1.1 jruoho
147 1.1 jruoho *ReturnNode = Node;
148 1.1 jruoho return_ACPI_STATUS (AE_OK);
149 1.1 jruoho }
150 1.1 jruoho
151 1.1 jruoho
152 1.1 jruoho /*******************************************************************************
153 1.1 jruoho *
154 1.1 jruoho * FUNCTION: AcpiGetIrqRoutingTable
155 1.1 jruoho *
156 1.1 jruoho * PARAMETERS: DeviceHandle - Handle to the Bus device we are querying
157 1.1 jruoho * RetBuffer - Pointer to a buffer to receive the
158 1.1 jruoho * current resources for the device
159 1.1 jruoho *
160 1.1 jruoho * RETURN: Status
161 1.1 jruoho *
162 1.1 jruoho * DESCRIPTION: This function is called to get the IRQ routing table for a
163 1.1 jruoho * specific bus. The caller must first acquire a handle for the
164 1.1 jruoho * desired bus. The routine table is placed in the buffer pointed
165 1.1 jruoho * to by the RetBuffer variable parameter.
166 1.1 jruoho *
167 1.1 jruoho * If the function fails an appropriate status will be returned
168 1.1 jruoho * and the value of RetBuffer is undefined.
169 1.1 jruoho *
170 1.1 jruoho * This function attempts to execute the _PRT method contained in
171 1.1 jruoho * the object indicated by the passed DeviceHandle.
172 1.1 jruoho *
173 1.1 jruoho ******************************************************************************/
174 1.1 jruoho
175 1.1 jruoho ACPI_STATUS
176 1.1 jruoho AcpiGetIrqRoutingTable (
177 1.1 jruoho ACPI_HANDLE DeviceHandle,
178 1.1 jruoho ACPI_BUFFER *RetBuffer)
179 1.1 jruoho {
180 1.1 jruoho ACPI_STATUS Status;
181 1.1 jruoho ACPI_NAMESPACE_NODE *Node;
182 1.1 jruoho
183 1.1 jruoho
184 1.1 jruoho ACPI_FUNCTION_TRACE (AcpiGetIrqRoutingTable);
185 1.1 jruoho
186 1.1 jruoho
187 1.1 jruoho /* Validate parameters then dispatch to internal routine */
188 1.1 jruoho
189 1.1 jruoho Status = AcpiRsValidateParameters (DeviceHandle, RetBuffer, &Node);
190 1.1 jruoho if (ACPI_FAILURE (Status))
191 1.1 jruoho {
192 1.1 jruoho return_ACPI_STATUS (Status);
193 1.1 jruoho }
194 1.1 jruoho
195 1.1 jruoho Status = AcpiRsGetPrtMethodData (Node, RetBuffer);
196 1.1 jruoho return_ACPI_STATUS (Status);
197 1.1 jruoho }
198 1.1 jruoho
199 1.1 jruoho ACPI_EXPORT_SYMBOL (AcpiGetIrqRoutingTable)
200 1.1 jruoho
201 1.1 jruoho
202 1.1 jruoho /*******************************************************************************
203 1.1 jruoho *
204 1.1 jruoho * FUNCTION: AcpiGetCurrentResources
205 1.1 jruoho *
206 1.1 jruoho * PARAMETERS: DeviceHandle - Handle to the device object for the
207 1.1 jruoho * device we are querying
208 1.1 jruoho * RetBuffer - Pointer to a buffer to receive the
209 1.1 jruoho * current resources for the device
210 1.1 jruoho *
211 1.1 jruoho * RETURN: Status
212 1.1 jruoho *
213 1.1 jruoho * DESCRIPTION: This function is called to get the current resources for a
214 1.1 jruoho * specific device. The caller must first acquire a handle for
215 1.1 jruoho * the desired device. The resource data is placed in the buffer
216 1.1 jruoho * pointed to by the RetBuffer variable parameter.
217 1.1 jruoho *
218 1.1 jruoho * If the function fails an appropriate status will be returned
219 1.1 jruoho * and the value of RetBuffer is undefined.
220 1.1 jruoho *
221 1.1 jruoho * This function attempts to execute the _CRS method contained in
222 1.1 jruoho * the object indicated by the passed DeviceHandle.
223 1.1 jruoho *
224 1.1 jruoho ******************************************************************************/
225 1.1 jruoho
226 1.1 jruoho ACPI_STATUS
227 1.1 jruoho AcpiGetCurrentResources (
228 1.1 jruoho ACPI_HANDLE DeviceHandle,
229 1.1 jruoho ACPI_BUFFER *RetBuffer)
230 1.1 jruoho {
231 1.1 jruoho ACPI_STATUS Status;
232 1.1 jruoho ACPI_NAMESPACE_NODE *Node;
233 1.1 jruoho
234 1.1 jruoho
235 1.1 jruoho ACPI_FUNCTION_TRACE (AcpiGetCurrentResources);
236 1.1 jruoho
237 1.1 jruoho
238 1.1 jruoho /* Validate parameters then dispatch to internal routine */
239 1.1 jruoho
240 1.1 jruoho Status = AcpiRsValidateParameters (DeviceHandle, RetBuffer, &Node);
241 1.1 jruoho if (ACPI_FAILURE (Status))
242 1.1 jruoho {
243 1.1 jruoho return_ACPI_STATUS (Status);
244 1.1 jruoho }
245 1.1 jruoho
246 1.1 jruoho Status = AcpiRsGetCrsMethodData (Node, RetBuffer);
247 1.1 jruoho return_ACPI_STATUS (Status);
248 1.1 jruoho }
249 1.1 jruoho
250 1.1 jruoho ACPI_EXPORT_SYMBOL (AcpiGetCurrentResources)
251 1.1 jruoho
252 1.1 jruoho
253 1.1 jruoho /*******************************************************************************
254 1.1 jruoho *
255 1.1 jruoho * FUNCTION: AcpiGetPossibleResources
256 1.1 jruoho *
257 1.1 jruoho * PARAMETERS: DeviceHandle - Handle to the device object for the
258 1.1 jruoho * device we are querying
259 1.1 jruoho * RetBuffer - Pointer to a buffer to receive the
260 1.1 jruoho * resources for the device
261 1.1 jruoho *
262 1.1 jruoho * RETURN: Status
263 1.1 jruoho *
264 1.1 jruoho * DESCRIPTION: This function is called to get a list of the possible resources
265 1.1 jruoho * for a specific device. The caller must first acquire a handle
266 1.1 jruoho * for the desired device. The resource data is placed in the
267 1.1 jruoho * buffer pointed to by the RetBuffer variable.
268 1.1 jruoho *
269 1.1 jruoho * If the function fails an appropriate status will be returned
270 1.1 jruoho * and the value of RetBuffer is undefined.
271 1.1 jruoho *
272 1.1 jruoho ******************************************************************************/
273 1.1 jruoho
274 1.1 jruoho ACPI_STATUS
275 1.1 jruoho AcpiGetPossibleResources (
276 1.1 jruoho ACPI_HANDLE DeviceHandle,
277 1.1 jruoho ACPI_BUFFER *RetBuffer)
278 1.1 jruoho {
279 1.1 jruoho ACPI_STATUS Status;
280 1.1 jruoho ACPI_NAMESPACE_NODE *Node;
281 1.1 jruoho
282 1.1 jruoho
283 1.1 jruoho ACPI_FUNCTION_TRACE (AcpiGetPossibleResources);
284 1.1 jruoho
285 1.1 jruoho
286 1.1 jruoho /* Validate parameters then dispatch to internal routine */
287 1.1 jruoho
288 1.1 jruoho Status = AcpiRsValidateParameters (DeviceHandle, RetBuffer, &Node);
289 1.1 jruoho if (ACPI_FAILURE (Status))
290 1.1 jruoho {
291 1.1 jruoho return_ACPI_STATUS (Status);
292 1.1 jruoho }
293 1.1 jruoho
294 1.1 jruoho Status = AcpiRsGetPrsMethodData (Node, RetBuffer);
295 1.1 jruoho return_ACPI_STATUS (Status);
296 1.1 jruoho }
297 1.1 jruoho
298 1.1 jruoho ACPI_EXPORT_SYMBOL (AcpiGetPossibleResources)
299 1.1 jruoho
300 1.1 jruoho
301 1.1 jruoho /*******************************************************************************
302 1.1 jruoho *
303 1.1 jruoho * FUNCTION: AcpiSetCurrentResources
304 1.1 jruoho *
305 1.1 jruoho * PARAMETERS: DeviceHandle - Handle to the device object for the
306 1.1 jruoho * device we are setting resources
307 1.1 jruoho * InBuffer - Pointer to a buffer containing the
308 1.1 jruoho * resources to be set for the device
309 1.1 jruoho *
310 1.1 jruoho * RETURN: Status
311 1.1 jruoho *
312 1.1 jruoho * DESCRIPTION: This function is called to set the current resources for a
313 1.1 jruoho * specific device. The caller must first acquire a handle for
314 1.1 jruoho * the desired device. The resource data is passed to the routine
315 1.1 jruoho * the buffer pointed to by the InBuffer variable.
316 1.1 jruoho *
317 1.1 jruoho ******************************************************************************/
318 1.1 jruoho
319 1.1 jruoho ACPI_STATUS
320 1.1 jruoho AcpiSetCurrentResources (
321 1.1 jruoho ACPI_HANDLE DeviceHandle,
322 1.1 jruoho ACPI_BUFFER *InBuffer)
323 1.1 jruoho {
324 1.1 jruoho ACPI_STATUS Status;
325 1.1 jruoho ACPI_NAMESPACE_NODE *Node;
326 1.1 jruoho
327 1.1 jruoho
328 1.1 jruoho ACPI_FUNCTION_TRACE (AcpiSetCurrentResources);
329 1.1 jruoho
330 1.1 jruoho
331 1.1 jruoho /* Validate the buffer, don't allow zero length */
332 1.1 jruoho
333 1.1 jruoho if ((!InBuffer) ||
334 1.1 jruoho (!InBuffer->Pointer) ||
335 1.1 jruoho (!InBuffer->Length))
336 1.1 jruoho {
337 1.1 jruoho return_ACPI_STATUS (AE_BAD_PARAMETER);
338 1.1 jruoho }
339 1.1 jruoho
340 1.1 jruoho /* Validate parameters then dispatch to internal routine */
341 1.1 jruoho
342 1.1 jruoho Status = AcpiRsValidateParameters (DeviceHandle, InBuffer, &Node);
343 1.1 jruoho if (ACPI_FAILURE (Status))
344 1.1 jruoho {
345 1.1 jruoho return_ACPI_STATUS (Status);
346 1.1 jruoho }
347 1.1 jruoho
348 1.1 jruoho Status = AcpiRsSetSrsMethodData (Node, InBuffer);
349 1.1 jruoho return_ACPI_STATUS (Status);
350 1.1 jruoho }
351 1.1 jruoho
352 1.1 jruoho ACPI_EXPORT_SYMBOL (AcpiSetCurrentResources)
353 1.1 jruoho
354 1.1 jruoho
355 1.4 christos /*******************************************************************************
356 1.4 christos *
357 1.4 christos * FUNCTION: AcpiGetEventResources
358 1.4 christos *
359 1.4 christos * PARAMETERS: DeviceHandle - Handle to the device object for the
360 1.4 christos * device we are getting resources
361 1.4 christos * InBuffer - Pointer to a buffer containing the
362 1.4 christos * resources to be set for the device
363 1.4 christos *
364 1.4 christos * RETURN: Status
365 1.4 christos *
366 1.4 christos * DESCRIPTION: This function is called to get the event resources for a
367 1.4 christos * specific device. The caller must first acquire a handle for
368 1.4 christos * the desired device. The resource data is passed to the routine
369 1.4 christos * the buffer pointed to by the InBuffer variable. Uses the
370 1.4 christos * _AEI method.
371 1.4 christos *
372 1.4 christos ******************************************************************************/
373 1.4 christos
374 1.4 christos ACPI_STATUS
375 1.4 christos AcpiGetEventResources (
376 1.4 christos ACPI_HANDLE DeviceHandle,
377 1.4 christos ACPI_BUFFER *RetBuffer)
378 1.4 christos {
379 1.4 christos ACPI_STATUS Status;
380 1.4 christos ACPI_NAMESPACE_NODE *Node;
381 1.4 christos
382 1.4 christos
383 1.4 christos ACPI_FUNCTION_TRACE (AcpiGetEventResources);
384 1.4 christos
385 1.4 christos
386 1.4 christos /* Validate parameters then dispatch to internal routine */
387 1.4 christos
388 1.4 christos Status = AcpiRsValidateParameters (DeviceHandle, RetBuffer, &Node);
389 1.4 christos if (ACPI_FAILURE (Status))
390 1.4 christos {
391 1.4 christos return_ACPI_STATUS (Status);
392 1.4 christos }
393 1.4 christos
394 1.4 christos Status = AcpiRsGetAeiMethodData (Node, RetBuffer);
395 1.4 christos return_ACPI_STATUS (Status);
396 1.4 christos }
397 1.4 christos
398 1.4 christos ACPI_EXPORT_SYMBOL (AcpiGetEventResources)
399 1.4 christos
400 1.4 christos
401 1.1 jruoho /******************************************************************************
402 1.1 jruoho *
403 1.1 jruoho * FUNCTION: AcpiResourceToAddress64
404 1.1 jruoho *
405 1.1 jruoho * PARAMETERS: Resource - Pointer to a resource
406 1.1 jruoho * Out - Pointer to the users's return buffer
407 1.1 jruoho * (a struct acpi_resource_address64)
408 1.1 jruoho *
409 1.1 jruoho * RETURN: Status
410 1.1 jruoho *
411 1.1 jruoho * DESCRIPTION: If the resource is an address16, address32, or address64,
412 1.1 jruoho * copy it to the address64 return buffer. This saves the
413 1.1 jruoho * caller from having to duplicate code for different-sized
414 1.1 jruoho * addresses.
415 1.1 jruoho *
416 1.1 jruoho ******************************************************************************/
417 1.1 jruoho
418 1.1 jruoho ACPI_STATUS
419 1.1 jruoho AcpiResourceToAddress64 (
420 1.1 jruoho ACPI_RESOURCE *Resource,
421 1.1 jruoho ACPI_RESOURCE_ADDRESS64 *Out)
422 1.1 jruoho {
423 1.1 jruoho ACPI_RESOURCE_ADDRESS16 *Address16;
424 1.1 jruoho ACPI_RESOURCE_ADDRESS32 *Address32;
425 1.1 jruoho
426 1.1 jruoho
427 1.1 jruoho if (!Resource || !Out)
428 1.1 jruoho {
429 1.1 jruoho return (AE_BAD_PARAMETER);
430 1.1 jruoho }
431 1.1 jruoho
432 1.1 jruoho /* Convert 16 or 32 address descriptor to 64 */
433 1.1 jruoho
434 1.1 jruoho switch (Resource->Type)
435 1.1 jruoho {
436 1.1 jruoho case ACPI_RESOURCE_TYPE_ADDRESS16:
437 1.1 jruoho
438 1.1 jruoho Address16 = ACPI_CAST_PTR (ACPI_RESOURCE_ADDRESS16, &Resource->Data);
439 1.1 jruoho ACPI_COPY_ADDRESS (Out, Address16);
440 1.1 jruoho break;
441 1.1 jruoho
442 1.1 jruoho case ACPI_RESOURCE_TYPE_ADDRESS32:
443 1.1 jruoho
444 1.1 jruoho Address32 = ACPI_CAST_PTR (ACPI_RESOURCE_ADDRESS32, &Resource->Data);
445 1.1 jruoho ACPI_COPY_ADDRESS (Out, Address32);
446 1.1 jruoho break;
447 1.1 jruoho
448 1.1 jruoho case ACPI_RESOURCE_TYPE_ADDRESS64:
449 1.1 jruoho
450 1.1 jruoho /* Simple copy for 64 bit source */
451 1.1 jruoho
452 1.1 jruoho ACPI_MEMCPY (Out, &Resource->Data, sizeof (ACPI_RESOURCE_ADDRESS64));
453 1.1 jruoho break;
454 1.1 jruoho
455 1.1 jruoho default:
456 1.4 christos
457 1.1 jruoho return (AE_BAD_PARAMETER);
458 1.1 jruoho }
459 1.1 jruoho
460 1.1 jruoho return (AE_OK);
461 1.1 jruoho }
462 1.1 jruoho
463 1.1 jruoho ACPI_EXPORT_SYMBOL (AcpiResourceToAddress64)
464 1.1 jruoho
465 1.1 jruoho
466 1.1 jruoho /*******************************************************************************
467 1.1 jruoho *
468 1.1 jruoho * FUNCTION: AcpiGetVendorResource
469 1.1 jruoho *
470 1.1 jruoho * PARAMETERS: DeviceHandle - Handle for the parent device object
471 1.1 jruoho * Name - Method name for the parent resource
472 1.1 jruoho * (METHOD_NAME__CRS or METHOD_NAME__PRS)
473 1.1 jruoho * Uuid - Pointer to the UUID to be matched.
474 1.1 jruoho * includes both subtype and 16-byte UUID
475 1.1 jruoho * RetBuffer - Where the vendor resource is returned
476 1.1 jruoho *
477 1.1 jruoho * RETURN: Status
478 1.1 jruoho *
479 1.4 christos * DESCRIPTION: Walk a resource template for the specified device to find a
480 1.1 jruoho * vendor-defined resource that matches the supplied UUID and
481 1.1 jruoho * UUID subtype. Returns a ACPI_RESOURCE of type Vendor.
482 1.1 jruoho *
483 1.1 jruoho ******************************************************************************/
484 1.1 jruoho
485 1.1 jruoho ACPI_STATUS
486 1.1 jruoho AcpiGetVendorResource (
487 1.1 jruoho ACPI_HANDLE DeviceHandle,
488 1.1 jruoho char *Name,
489 1.1 jruoho ACPI_VENDOR_UUID *Uuid,
490 1.1 jruoho ACPI_BUFFER *RetBuffer)
491 1.1 jruoho {
492 1.1 jruoho ACPI_VENDOR_WALK_INFO Info;
493 1.1 jruoho ACPI_STATUS Status;
494 1.1 jruoho
495 1.1 jruoho
496 1.1 jruoho /* Other parameters are validated by AcpiWalkResources */
497 1.1 jruoho
498 1.1 jruoho if (!Uuid || !RetBuffer)
499 1.1 jruoho {
500 1.1 jruoho return (AE_BAD_PARAMETER);
501 1.1 jruoho }
502 1.1 jruoho
503 1.1 jruoho Info.Uuid = Uuid;
504 1.1 jruoho Info.Buffer = RetBuffer;
505 1.1 jruoho Info.Status = AE_NOT_EXIST;
506 1.1 jruoho
507 1.1 jruoho /* Walk the _CRS or _PRS resource list for this device */
508 1.1 jruoho
509 1.1 jruoho Status = AcpiWalkResources (DeviceHandle, Name, AcpiRsMatchVendorResource,
510 1.1 jruoho &Info);
511 1.1 jruoho if (ACPI_FAILURE (Status))
512 1.1 jruoho {
513 1.1 jruoho return (Status);
514 1.1 jruoho }
515 1.1 jruoho
516 1.1 jruoho return (Info.Status);
517 1.1 jruoho }
518 1.1 jruoho
519 1.1 jruoho ACPI_EXPORT_SYMBOL (AcpiGetVendorResource)
520 1.1 jruoho
521 1.1 jruoho
522 1.1 jruoho /*******************************************************************************
523 1.1 jruoho *
524 1.1 jruoho * FUNCTION: AcpiRsMatchVendorResource
525 1.1 jruoho *
526 1.1 jruoho * PARAMETERS: ACPI_WALK_RESOURCE_CALLBACK
527 1.1 jruoho *
528 1.1 jruoho * RETURN: Status
529 1.1 jruoho *
530 1.1 jruoho * DESCRIPTION: Match a vendor resource via the ACPI 3.0 UUID
531 1.1 jruoho *
532 1.1 jruoho ******************************************************************************/
533 1.1 jruoho
534 1.1 jruoho static ACPI_STATUS
535 1.1 jruoho AcpiRsMatchVendorResource (
536 1.1 jruoho ACPI_RESOURCE *Resource,
537 1.1 jruoho void *Context)
538 1.1 jruoho {
539 1.1 jruoho ACPI_VENDOR_WALK_INFO *Info = Context;
540 1.1 jruoho ACPI_RESOURCE_VENDOR_TYPED *Vendor;
541 1.1 jruoho ACPI_BUFFER *Buffer;
542 1.1 jruoho ACPI_STATUS Status;
543 1.1 jruoho
544 1.1 jruoho
545 1.1 jruoho /* Ignore all descriptors except Vendor */
546 1.1 jruoho
547 1.1 jruoho if (Resource->Type != ACPI_RESOURCE_TYPE_VENDOR)
548 1.1 jruoho {
549 1.1 jruoho return (AE_OK);
550 1.1 jruoho }
551 1.1 jruoho
552 1.1 jruoho Vendor = &Resource->Data.VendorTyped;
553 1.1 jruoho
554 1.1 jruoho /*
555 1.1 jruoho * For a valid match, these conditions must hold:
556 1.1 jruoho *
557 1.1 jruoho * 1) Length of descriptor data must be at least as long as a UUID struct
558 1.1 jruoho * 2) The UUID subtypes must match
559 1.1 jruoho * 3) The UUID data must match
560 1.1 jruoho */
561 1.1 jruoho if ((Vendor->ByteLength < (ACPI_UUID_LENGTH + 1)) ||
562 1.1 jruoho (Vendor->UuidSubtype != Info->Uuid->Subtype) ||
563 1.1 jruoho (ACPI_MEMCMP (Vendor->Uuid, Info->Uuid->Data, ACPI_UUID_LENGTH)))
564 1.1 jruoho {
565 1.1 jruoho return (AE_OK);
566 1.1 jruoho }
567 1.1 jruoho
568 1.1 jruoho /* Validate/Allocate/Clear caller buffer */
569 1.1 jruoho
570 1.1 jruoho Buffer = Info->Buffer;
571 1.1 jruoho Status = AcpiUtInitializeBuffer (Buffer, Resource->Length);
572 1.1 jruoho if (ACPI_FAILURE (Status))
573 1.1 jruoho {
574 1.1 jruoho return (Status);
575 1.1 jruoho }
576 1.1 jruoho
577 1.1 jruoho /* Found the correct resource, copy and return it */
578 1.1 jruoho
579 1.1 jruoho ACPI_MEMCPY (Buffer->Pointer, Resource, Resource->Length);
580 1.1 jruoho Buffer->Length = Resource->Length;
581 1.1 jruoho
582 1.1 jruoho /* Found the desired descriptor, terminate resource walk */
583 1.1 jruoho
584 1.1 jruoho Info->Status = AE_OK;
585 1.1 jruoho return (AE_CTRL_TERMINATE);
586 1.1 jruoho }
587 1.1 jruoho
588 1.1 jruoho
589 1.1 jruoho /*******************************************************************************
590 1.1 jruoho *
591 1.4 christos * FUNCTION: AcpiWalkResourceBuffer
592 1.1 jruoho *
593 1.4 christos * PARAMETERS: Buffer - Formatted buffer returned by one of the
594 1.4 christos * various Get*Resource functions
595 1.1 jruoho * UserFunction - Called for each resource
596 1.1 jruoho * Context - Passed to UserFunction
597 1.1 jruoho *
598 1.1 jruoho * RETURN: Status
599 1.1 jruoho *
600 1.4 christos * DESCRIPTION: Walks the input resource template. The UserFunction is called
601 1.4 christos * once for each resource in the list.
602 1.1 jruoho *
603 1.1 jruoho ******************************************************************************/
604 1.1 jruoho
605 1.1 jruoho ACPI_STATUS
606 1.4 christos AcpiWalkResourceBuffer (
607 1.4 christos ACPI_BUFFER *Buffer,
608 1.1 jruoho ACPI_WALK_RESOURCE_CALLBACK UserFunction,
609 1.1 jruoho void *Context)
610 1.1 jruoho {
611 1.4 christos ACPI_STATUS Status = AE_OK;
612 1.1 jruoho ACPI_RESOURCE *Resource;
613 1.1 jruoho ACPI_RESOURCE *ResourceEnd;
614 1.1 jruoho
615 1.4 christos ACPI_FUNCTION_TRACE (AcpiWalkResourceBuffer);
616 1.1 jruoho
617 1.1 jruoho
618 1.1 jruoho /* Parameter validation */
619 1.1 jruoho
620 1.4 christos if (!Buffer || !Buffer->Pointer || !UserFunction)
621 1.1 jruoho {
622 1.1 jruoho return_ACPI_STATUS (AE_BAD_PARAMETER);
623 1.1 jruoho }
624 1.1 jruoho
625 1.4 christos /* Buffer contains the resource list and length */
626 1.1 jruoho
627 1.4 christos Resource = ACPI_CAST_PTR (ACPI_RESOURCE, Buffer->Pointer);
628 1.4 christos ResourceEnd = ACPI_ADD_PTR (ACPI_RESOURCE, Buffer->Pointer, Buffer->Length);
629 1.1 jruoho
630 1.1 jruoho /* Walk the resource list until the EndTag is found (or buffer end) */
631 1.1 jruoho
632 1.1 jruoho while (Resource < ResourceEnd)
633 1.1 jruoho {
634 1.4 christos /* Sanity check the resource type */
635 1.1 jruoho
636 1.1 jruoho if (Resource->Type > ACPI_RESOURCE_TYPE_MAX)
637 1.1 jruoho {
638 1.1 jruoho Status = AE_AML_INVALID_RESOURCE_TYPE;
639 1.1 jruoho break;
640 1.1 jruoho }
641 1.1 jruoho
642 1.4 christos /* Sanity check the length. It must not be zero, or we loop forever */
643 1.4 christos
644 1.4 christos if (!Resource->Length)
645 1.4 christos {
646 1.4 christos return_ACPI_STATUS (AE_AML_BAD_RESOURCE_LENGTH);
647 1.4 christos }
648 1.4 christos
649 1.1 jruoho /* Invoke the user function, abort on any error returned */
650 1.1 jruoho
651 1.1 jruoho Status = UserFunction (Resource, Context);
652 1.1 jruoho if (ACPI_FAILURE (Status))
653 1.1 jruoho {
654 1.1 jruoho if (Status == AE_CTRL_TERMINATE)
655 1.1 jruoho {
656 1.1 jruoho /* This is an OK termination by the user function */
657 1.1 jruoho
658 1.1 jruoho Status = AE_OK;
659 1.1 jruoho }
660 1.1 jruoho break;
661 1.1 jruoho }
662 1.1 jruoho
663 1.1 jruoho /* EndTag indicates end-of-list */
664 1.1 jruoho
665 1.1 jruoho if (Resource->Type == ACPI_RESOURCE_TYPE_END_TAG)
666 1.1 jruoho {
667 1.1 jruoho break;
668 1.1 jruoho }
669 1.1 jruoho
670 1.1 jruoho /* Get the next resource descriptor */
671 1.1 jruoho
672 1.4 christos Resource = ACPI_NEXT_RESOURCE (Resource);
673 1.1 jruoho }
674 1.1 jruoho
675 1.4 christos return_ACPI_STATUS (Status);
676 1.4 christos }
677 1.4 christos
678 1.4 christos ACPI_EXPORT_SYMBOL (AcpiWalkResourceBuffer)
679 1.4 christos
680 1.4 christos
681 1.4 christos /*******************************************************************************
682 1.4 christos *
683 1.4 christos * FUNCTION: AcpiWalkResources
684 1.4 christos *
685 1.4 christos * PARAMETERS: DeviceHandle - Handle to the device object for the
686 1.4 christos * device we are querying
687 1.4 christos * Name - Method name of the resources we want.
688 1.4 christos * (METHOD_NAME__CRS, METHOD_NAME__PRS, or
689 1.4 christos * METHOD_NAME__AEI)
690 1.4 christos * UserFunction - Called for each resource
691 1.4 christos * Context - Passed to UserFunction
692 1.4 christos *
693 1.4 christos * RETURN: Status
694 1.4 christos *
695 1.4 christos * DESCRIPTION: Retrieves the current or possible resource list for the
696 1.4 christos * specified device. The UserFunction is called once for
697 1.4 christos * each resource in the list.
698 1.4 christos *
699 1.4 christos ******************************************************************************/
700 1.4 christos
701 1.4 christos ACPI_STATUS
702 1.4 christos AcpiWalkResources (
703 1.4 christos ACPI_HANDLE DeviceHandle,
704 1.4 christos const char *Name,
705 1.4 christos ACPI_WALK_RESOURCE_CALLBACK UserFunction,
706 1.4 christos void *Context)
707 1.4 christos {
708 1.4 christos ACPI_STATUS Status;
709 1.4 christos ACPI_BUFFER Buffer;
710 1.4 christos
711 1.4 christos
712 1.4 christos ACPI_FUNCTION_TRACE (AcpiWalkResources);
713 1.4 christos
714 1.4 christos
715 1.4 christos /* Parameter validation */
716 1.4 christos
717 1.4 christos if (!DeviceHandle || !UserFunction || !Name ||
718 1.4 christos (!ACPI_COMPARE_NAME (Name, METHOD_NAME__CRS) &&
719 1.4 christos !ACPI_COMPARE_NAME (Name, METHOD_NAME__PRS) &&
720 1.4 christos !ACPI_COMPARE_NAME (Name, METHOD_NAME__AEI)))
721 1.4 christos {
722 1.4 christos return_ACPI_STATUS (AE_BAD_PARAMETER);
723 1.4 christos }
724 1.4 christos
725 1.4 christos /* Get the _CRS/_PRS/_AEI resource list */
726 1.4 christos
727 1.4 christos Buffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
728 1.4 christos Status = AcpiRsGetMethodData (DeviceHandle, __UNCONST(Name), &Buffer);
729 1.4 christos if (ACPI_FAILURE (Status))
730 1.4 christos {
731 1.4 christos return_ACPI_STATUS (Status);
732 1.4 christos }
733 1.4 christos
734 1.4 christos /* Walk the resource list and cleanup */
735 1.4 christos
736 1.4 christos Status = AcpiWalkResourceBuffer (&Buffer, UserFunction, Context);
737 1.1 jruoho ACPI_FREE (Buffer.Pointer);
738 1.1 jruoho return_ACPI_STATUS (Status);
739 1.1 jruoho }
740 1.1 jruoho
741 1.1 jruoho ACPI_EXPORT_SYMBOL (AcpiWalkResources)
742