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