blob: 465ed8137167ce6112387e719c4d299b14aa1268 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*******************************************************************************
2 *
3 * Module Name: rsxface - Public interfaces to the resource manager
4 *
5 ******************************************************************************/
6
7/*
Bob Moorec8100dc2016-01-15 08:17:03 +08008 * Copyright (C) 2000 - 2016, Intel Corp.
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 * 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
Lv Zheng839e9282013-10-29 09:29:51 +080044#define EXPORT_ACPI_INTERFACES
45
Linus Torvalds1da177e2005-04-16 15:20:36 -070046#include <acpi/acpi.h>
Len Browne2f7a772009-01-09 00:30:03 -050047#include "accommon.h"
48#include "acresrc.h"
49#include "acnamesp.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
51#define _COMPONENT ACPI_RESOURCES
Len Brown4be44fc2005-08-05 00:44:28 -040052ACPI_MODULE_NAME("rsxface")
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
Robert Moore44f6c012005-04-18 22:49:35 -040054/* Local macros for 16,32-bit to 64-bit conversion */
Robert Moore44f6c012005-04-18 22:49:35 -040055#define ACPI_COPY_FIELD(out, in, field) ((out)->field = (in)->field)
Bob Moore1fad8732015-12-29 13:54:36 +080056#define ACPI_COPY_ADDRESS(out, in) \
Robert Moore44f6c012005-04-18 22:49:35 -040057 ACPI_COPY_FIELD(out, in, resource_type); \
58 ACPI_COPY_FIELD(out, in, producer_consumer); \
59 ACPI_COPY_FIELD(out, in, decode); \
60 ACPI_COPY_FIELD(out, in, min_address_fixed); \
61 ACPI_COPY_FIELD(out, in, max_address_fixed); \
Bob Moore08978312005-10-21 00:00:00 -040062 ACPI_COPY_FIELD(out, in, info); \
Lv Zhenga45de932015-01-26 16:58:56 +080063 ACPI_COPY_FIELD(out, in, address.granularity); \
64 ACPI_COPY_FIELD(out, in, address.minimum); \
65 ACPI_COPY_FIELD(out, in, address.maximum); \
66 ACPI_COPY_FIELD(out, in, address.translation_offset); \
67 ACPI_COPY_FIELD(out, in, address.address_length); \
Robert Moore44f6c012005-04-18 22:49:35 -040068 ACPI_COPY_FIELD(out, in, resource_source);
Bob Moorec51a4de2005-11-17 13:07:00 -050069/* Local prototypes */
70static acpi_status
71acpi_rs_match_vendor_resource(struct acpi_resource *resource, void *context);
72
Bob Moore41195322006-05-26 16:36:00 -040073static acpi_status
74acpi_rs_validate_parameters(acpi_handle device_handle,
75 struct acpi_buffer *buffer,
76 struct acpi_namespace_node **return_node);
77
78/*******************************************************************************
79 *
80 * FUNCTION: acpi_rs_validate_parameters
81 *
82 * PARAMETERS: device_handle - Handle to a device
Bob Mooreba494be2012-07-12 09:40:10 +080083 * buffer - Pointer to a data buffer
Bob Moore41195322006-05-26 16:36:00 -040084 * return_node - Pointer to where the device node is returned
85 *
86 * RETURN: Status
87 *
88 * DESCRIPTION: Common parameter validation for resource interfaces
89 *
90 ******************************************************************************/
91
92static acpi_status
93acpi_rs_validate_parameters(acpi_handle device_handle,
94 struct acpi_buffer *buffer,
95 struct acpi_namespace_node **return_node)
96{
97 acpi_status status;
98 struct acpi_namespace_node *node;
99
100 ACPI_FUNCTION_TRACE(rs_validate_parameters);
101
102 /*
103 * Must have a valid handle to an ACPI device
104 */
105 if (!device_handle) {
106 return_ACPI_STATUS(AE_BAD_PARAMETER);
107 }
108
Bob Mooref24b6642009-12-11 14:57:00 +0800109 node = acpi_ns_validate_handle(device_handle);
Bob Moore41195322006-05-26 16:36:00 -0400110 if (!node) {
111 return_ACPI_STATUS(AE_BAD_PARAMETER);
112 }
113
114 if (node->type != ACPI_TYPE_DEVICE) {
115 return_ACPI_STATUS(AE_TYPE);
116 }
117
118 /*
119 * Validate the user buffer object
120 *
121 * if there is a non-zero buffer length we also need a valid pointer in
122 * the buffer. If it's a zero buffer length, we'll be returning the
123 * needed buffer size (later), so keep going.
124 */
125 status = acpi_ut_validate_buffer(buffer);
126 if (ACPI_FAILURE(status)) {
127 return_ACPI_STATUS(status);
128 }
129
130 *return_node = node;
131 return_ACPI_STATUS(AE_OK);
132}
133
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134/*******************************************************************************
135 *
136 * FUNCTION: acpi_get_irq_routing_table
137 *
Bob Moore41195322006-05-26 16:36:00 -0400138 * PARAMETERS: device_handle - Handle to the Bus device we are querying
139 * ret_buffer - Pointer to a buffer to receive the
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 * current resources for the device
141 *
142 * RETURN: Status
143 *
144 * DESCRIPTION: This function is called to get the IRQ routing table for a
Bob Moore41195322006-05-26 16:36:00 -0400145 * specific bus. The caller must first acquire a handle for the
146 * desired bus. The routine table is placed in the buffer pointed
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 * to by the ret_buffer variable parameter.
148 *
149 * If the function fails an appropriate status will be returned
150 * and the value of ret_buffer is undefined.
151 *
152 * This function attempts to execute the _PRT method contained in
153 * the object indicated by the passed device_handle.
154 *
155 ******************************************************************************/
Bob Moorec51a4de2005-11-17 13:07:00 -0500156
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400158acpi_get_irq_routing_table(acpi_handle device_handle,
159 struct acpi_buffer *ret_buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160{
Len Brown4be44fc2005-08-05 00:44:28 -0400161 acpi_status status;
Bob Moore41195322006-05-26 16:36:00 -0400162 struct acpi_namespace_node *node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163
Bob Mooreb229cf92006-04-21 17:15:00 -0400164 ACPI_FUNCTION_TRACE(acpi_get_irq_routing_table);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165
Bob Moore41195322006-05-26 16:36:00 -0400166 /* Validate parameters then dispatch to internal routine */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167
Bob Moore41195322006-05-26 16:36:00 -0400168 status = acpi_rs_validate_parameters(device_handle, ret_buffer, &node);
Len Brown4be44fc2005-08-05 00:44:28 -0400169 if (ACPI_FAILURE(status)) {
170 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 }
172
Bob Moore41195322006-05-26 16:36:00 -0400173 status = acpi_rs_get_prt_method_data(node, ret_buffer);
Len Brown4be44fc2005-08-05 00:44:28 -0400174 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175}
176
Bob Moore83135242006-10-03 00:00:00 -0400177ACPI_EXPORT_SYMBOL(acpi_get_irq_routing_table)
178
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179/*******************************************************************************
180 *
181 * FUNCTION: acpi_get_current_resources
182 *
Bob Moore41195322006-05-26 16:36:00 -0400183 * PARAMETERS: device_handle - Handle to the device object for the
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 * device we are querying
Bob Moore41195322006-05-26 16:36:00 -0400185 * ret_buffer - Pointer to a buffer to receive the
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 * current resources for the device
187 *
188 * RETURN: Status
189 *
190 * DESCRIPTION: This function is called to get the current resources for a
Bob Moore41195322006-05-26 16:36:00 -0400191 * specific device. The caller must first acquire a handle for
192 * the desired device. The resource data is placed in the buffer
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 * pointed to by the ret_buffer variable parameter.
194 *
195 * If the function fails an appropriate status will be returned
196 * and the value of ret_buffer is undefined.
197 *
198 * This function attempts to execute the _CRS method contained in
199 * the object indicated by the passed device_handle.
200 *
201 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400203acpi_get_current_resources(acpi_handle device_handle,
204 struct acpi_buffer *ret_buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205{
Len Brown4be44fc2005-08-05 00:44:28 -0400206 acpi_status status;
Bob Moore41195322006-05-26 16:36:00 -0400207 struct acpi_namespace_node *node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208
Bob Mooreb229cf92006-04-21 17:15:00 -0400209 ACPI_FUNCTION_TRACE(acpi_get_current_resources);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210
Bob Moore41195322006-05-26 16:36:00 -0400211 /* Validate parameters then dispatch to internal routine */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212
Bob Moore41195322006-05-26 16:36:00 -0400213 status = acpi_rs_validate_parameters(device_handle, ret_buffer, &node);
Len Brown4be44fc2005-08-05 00:44:28 -0400214 if (ACPI_FAILURE(status)) {
215 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 }
217
Bob Moore41195322006-05-26 16:36:00 -0400218 status = acpi_rs_get_crs_method_data(node, ret_buffer);
Len Brown4be44fc2005-08-05 00:44:28 -0400219 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221
Bob Moore83135242006-10-03 00:00:00 -0400222ACPI_EXPORT_SYMBOL(acpi_get_current_resources)
Lv Zheng4d946f72015-10-19 10:25:56 +0800223
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224/*******************************************************************************
225 *
226 * FUNCTION: acpi_get_possible_resources
227 *
Bob Moore41195322006-05-26 16:36:00 -0400228 * PARAMETERS: device_handle - Handle to the device object for the
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 * device we are querying
Bob Moore41195322006-05-26 16:36:00 -0400230 * ret_buffer - Pointer to a buffer to receive the
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 * resources for the device
232 *
233 * RETURN: Status
234 *
235 * DESCRIPTION: This function is called to get a list of the possible resources
Bob Moore41195322006-05-26 16:36:00 -0400236 * for a specific device. The caller must first acquire a handle
237 * for the desired device. The resource data is placed in the
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 * buffer pointed to by the ret_buffer variable.
239 *
240 * If the function fails an appropriate status will be returned
241 * and the value of ret_buffer is undefined.
242 *
243 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400245acpi_get_possible_resources(acpi_handle device_handle,
246 struct acpi_buffer *ret_buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247{
Len Brown4be44fc2005-08-05 00:44:28 -0400248 acpi_status status;
Bob Moore41195322006-05-26 16:36:00 -0400249 struct acpi_namespace_node *node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250
Bob Mooreb229cf92006-04-21 17:15:00 -0400251 ACPI_FUNCTION_TRACE(acpi_get_possible_resources);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252
Bob Moore41195322006-05-26 16:36:00 -0400253 /* Validate parameters then dispatch to internal routine */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254
Bob Moore41195322006-05-26 16:36:00 -0400255 status = acpi_rs_validate_parameters(device_handle, ret_buffer, &node);
Len Brown4be44fc2005-08-05 00:44:28 -0400256 if (ACPI_FAILURE(status)) {
257 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 }
259
Bob Moore41195322006-05-26 16:36:00 -0400260 status = acpi_rs_get_prs_method_data(node, ret_buffer);
Len Brown4be44fc2005-08-05 00:44:28 -0400261 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263
Bob Moore83135242006-10-03 00:00:00 -0400264ACPI_EXPORT_SYMBOL(acpi_get_possible_resources)
Lv Zheng4d946f72015-10-19 10:25:56 +0800265
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266/*******************************************************************************
267 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 * FUNCTION: acpi_set_current_resources
269 *
Bob Moore41195322006-05-26 16:36:00 -0400270 * PARAMETERS: device_handle - Handle to the device object for the
271 * device we are setting resources
272 * in_buffer - Pointer to a buffer containing the
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 * resources to be set for the device
274 *
275 * RETURN: Status
276 *
277 * DESCRIPTION: This function is called to set the current resources for a
Bob Moore41195322006-05-26 16:36:00 -0400278 * specific device. The caller must first acquire a handle for
279 * the desired device. The resource data is passed to the routine
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 * the buffer pointed to by the in_buffer variable.
281 *
282 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400284acpi_set_current_resources(acpi_handle device_handle,
285 struct acpi_buffer *in_buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286{
Len Brown4be44fc2005-08-05 00:44:28 -0400287 acpi_status status;
Bob Moore41195322006-05-26 16:36:00 -0400288 struct acpi_namespace_node *node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289
Bob Mooreb229cf92006-04-21 17:15:00 -0400290 ACPI_FUNCTION_TRACE(acpi_set_current_resources);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291
Bob Moore41195322006-05-26 16:36:00 -0400292 /* Validate the buffer, don't allow zero length */
Robert Moore44f6c012005-04-18 22:49:35 -0400293
Bob Moore41195322006-05-26 16:36:00 -0400294 if ((!in_buffer) || (!in_buffer->pointer) || (!in_buffer->length)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400295 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 }
297
Bob Moore41195322006-05-26 16:36:00 -0400298 /* Validate parameters then dispatch to internal routine */
299
300 status = acpi_rs_validate_parameters(device_handle, in_buffer, &node);
301 if (ACPI_FAILURE(status)) {
302 return_ACPI_STATUS(status);
303 }
304
305 status = acpi_rs_set_srs_method_data(node, in_buffer);
Len Brown4be44fc2005-08-05 00:44:28 -0400306 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308
Bob Moore83135242006-10-03 00:00:00 -0400309ACPI_EXPORT_SYMBOL(acpi_set_current_resources)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310
Bob Moorea91cdde2011-11-16 14:46:57 +0800311/*******************************************************************************
312 *
313 * FUNCTION: acpi_get_event_resources
314 *
315 * PARAMETERS: device_handle - Handle to the device object for the
316 * device we are getting resources
317 * in_buffer - Pointer to a buffer containing the
318 * resources to be set for the device
319 *
320 * RETURN: Status
321 *
322 * DESCRIPTION: This function is called to get the event resources for a
323 * specific device. The caller must first acquire a handle for
324 * the desired device. The resource data is passed to the routine
325 * the buffer pointed to by the in_buffer variable. Uses the
326 * _AEI method.
327 *
328 ******************************************************************************/
329acpi_status
330acpi_get_event_resources(acpi_handle device_handle,
331 struct acpi_buffer *ret_buffer)
332{
333 acpi_status status;
334 struct acpi_namespace_node *node;
335
336 ACPI_FUNCTION_TRACE(acpi_get_event_resources);
337
338 /* Validate parameters then dispatch to internal routine */
339
340 status = acpi_rs_validate_parameters(device_handle, ret_buffer, &node);
341 if (ACPI_FAILURE(status)) {
342 return_ACPI_STATUS(status);
343 }
344
345 status = acpi_rs_get_aei_method_data(node, ret_buffer);
346 return_ACPI_STATUS(status);
347}
348
349ACPI_EXPORT_SYMBOL(acpi_get_event_resources)
350
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351/******************************************************************************
352 *
353 * FUNCTION: acpi_resource_to_address64
354 *
Bob Mooreba494be2012-07-12 09:40:10 +0800355 * PARAMETERS: resource - Pointer to a resource
356 * out - Pointer to the users's return buffer
Bob Moore41195322006-05-26 16:36:00 -0400357 * (a struct acpi_resource_address64)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 *
359 * RETURN: Status
360 *
361 * DESCRIPTION: If the resource is an address16, address32, or address64,
Bob Moore41195322006-05-26 16:36:00 -0400362 * copy it to the address64 return buffer. This saves the
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 * caller from having to duplicate code for different-sized
364 * addresses.
365 *
366 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400368acpi_resource_to_address64(struct acpi_resource *resource,
369 struct acpi_resource_address64 *out)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370{
Len Brown4be44fc2005-08-05 00:44:28 -0400371 struct acpi_resource_address16 *address16;
372 struct acpi_resource_address32 *address32;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373
Bob Moorec51a4de2005-11-17 13:07:00 -0500374 if (!resource || !out) {
375 return (AE_BAD_PARAMETER);
376 }
377
378 /* Convert 16 or 32 address descriptor to 64 */
379
Robert Moorebda663d2005-09-16 16:51:15 -0400380 switch (resource->type) {
Bob Moore50eca3e2005-09-30 19:03:00 -0400381 case ACPI_RESOURCE_TYPE_ADDRESS16:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382
Bob Mooreba9c3f52009-04-22 13:13:48 +0800383 address16 =
384 ACPI_CAST_PTR(struct acpi_resource_address16,
385 &resource->data);
Len Brown4be44fc2005-08-05 00:44:28 -0400386 ACPI_COPY_ADDRESS(out, address16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 break;
388
Bob Moore50eca3e2005-09-30 19:03:00 -0400389 case ACPI_RESOURCE_TYPE_ADDRESS32:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390
Bob Mooreba9c3f52009-04-22 13:13:48 +0800391 address32 =
392 ACPI_CAST_PTR(struct acpi_resource_address32,
393 &resource->data);
Len Brown4be44fc2005-08-05 00:44:28 -0400394 ACPI_COPY_ADDRESS(out, address32);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 break;
396
Bob Moore50eca3e2005-09-30 19:03:00 -0400397 case ACPI_RESOURCE_TYPE_ADDRESS64:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398
399 /* Simple copy for 64 bit source */
400
Bob Moore4fa46162015-07-01 14:45:11 +0800401 memcpy(out, &resource->data,
402 sizeof(struct acpi_resource_address64));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 break;
404
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 default:
Chao Guan1d1ea1b2013-06-08 00:58:14 +0000406
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 return (AE_BAD_PARAMETER);
408 }
409
410 return (AE_OK);
411}
Len Brown4be44fc2005-08-05 00:44:28 -0400412
Bob Moore83135242006-10-03 00:00:00 -0400413ACPI_EXPORT_SYMBOL(acpi_resource_to_address64)
Bob Moorec51a4de2005-11-17 13:07:00 -0500414
415/*******************************************************************************
416 *
417 * FUNCTION: acpi_get_vendor_resource
418 *
Bob Moore41195322006-05-26 16:36:00 -0400419 * PARAMETERS: device_handle - Handle for the parent device object
Bob Mooreba494be2012-07-12 09:40:10 +0800420 * name - Method name for the parent resource
Bob Moore41195322006-05-26 16:36:00 -0400421 * (METHOD_NAME__CRS or METHOD_NAME__PRS)
Bob Mooreba494be2012-07-12 09:40:10 +0800422 * uuid - Pointer to the UUID to be matched.
Bob Moore41195322006-05-26 16:36:00 -0400423 * includes both subtype and 16-byte UUID
424 * ret_buffer - Where the vendor resource is returned
Bob Moorec51a4de2005-11-17 13:07:00 -0500425 *
426 * RETURN: Status
427 *
Bob Mooreafb1bbe2012-12-31 00:03:58 +0000428 * DESCRIPTION: Walk a resource template for the specified device to find a
Bob Moorec51a4de2005-11-17 13:07:00 -0500429 * vendor-defined resource that matches the supplied UUID and
430 * UUID subtype. Returns a struct acpi_resource of type Vendor.
431 *
432 ******************************************************************************/
Bob Moorec51a4de2005-11-17 13:07:00 -0500433acpi_status
434acpi_get_vendor_resource(acpi_handle device_handle,
435 char *name,
Lv Zhengf5c1e1c2016-05-05 12:57:53 +0800436 struct acpi_vendor_uuid *uuid,
437 struct acpi_buffer *ret_buffer)
Bob Moorec51a4de2005-11-17 13:07:00 -0500438{
439 struct acpi_vendor_walk_info info;
440 acpi_status status;
441
442 /* Other parameters are validated by acpi_walk_resources */
443
444 if (!uuid || !ret_buffer) {
445 return (AE_BAD_PARAMETER);
446 }
447
448 info.uuid = uuid;
449 info.buffer = ret_buffer;
450 info.status = AE_NOT_EXIST;
451
452 /* Walk the _CRS or _PRS resource list for this device */
453
454 status =
455 acpi_walk_resources(device_handle, name,
456 acpi_rs_match_vendor_resource, &info);
457 if (ACPI_FAILURE(status)) {
458 return (status);
459 }
460
461 return (info.status);
462}
463
Bob Moore83135242006-10-03 00:00:00 -0400464ACPI_EXPORT_SYMBOL(acpi_get_vendor_resource)
465
Bob Moorec51a4de2005-11-17 13:07:00 -0500466/*******************************************************************************
467 *
468 * FUNCTION: acpi_rs_match_vendor_resource
469 *
Bob Moore616861242006-03-17 16:44:00 -0500470 * PARAMETERS: acpi_walk_resource_callback
Bob Moorec51a4de2005-11-17 13:07:00 -0500471 *
472 * RETURN: Status
473 *
474 * DESCRIPTION: Match a vendor resource via the ACPI 3.0 UUID
475 *
476 ******************************************************************************/
Bob Moorec51a4de2005-11-17 13:07:00 -0500477static acpi_status
478acpi_rs_match_vendor_resource(struct acpi_resource *resource, void *context)
479{
480 struct acpi_vendor_walk_info *info = context;
481 struct acpi_resource_vendor_typed *vendor;
482 struct acpi_buffer *buffer;
483 acpi_status status;
484
485 /* Ignore all descriptors except Vendor */
486
487 if (resource->type != ACPI_RESOURCE_TYPE_VENDOR) {
488 return (AE_OK);
489 }
490
491 vendor = &resource->data.vendor_typed;
492
493 /*
494 * For a valid match, these conditions must hold:
495 *
496 * 1) Length of descriptor data must be at least as long as a UUID struct
497 * 2) The UUID subtypes must match
498 * 3) The UUID data must match
499 */
500 if ((vendor->byte_length < (ACPI_UUID_LENGTH + 1)) ||
501 (vendor->uuid_subtype != info->uuid->subtype) ||
Bob Moore4fa46162015-07-01 14:45:11 +0800502 (memcmp(vendor->uuid, info->uuid->data, ACPI_UUID_LENGTH))) {
Bob Moorec51a4de2005-11-17 13:07:00 -0500503 return (AE_OK);
504 }
505
506 /* Validate/Allocate/Clear caller buffer */
507
508 buffer = info->buffer;
509 status = acpi_ut_initialize_buffer(buffer, resource->length);
510 if (ACPI_FAILURE(status)) {
511 return (status);
512 }
513
514 /* Found the correct resource, copy and return it */
515
Bob Moore4fa46162015-07-01 14:45:11 +0800516 memcpy(buffer->pointer, resource, resource->length);
Bob Moorec51a4de2005-11-17 13:07:00 -0500517 buffer->length = resource->length;
518
519 /* Found the desired descriptor, terminate resource walk */
520
521 info->status = AE_OK;
522 return (AE_CTRL_TERMINATE);
523}
Bob Moore83135242006-10-03 00:00:00 -0400524
Bob Moore41195322006-05-26 16:36:00 -0400525/*******************************************************************************
526 *
Bob Mooreafb1bbe2012-12-31 00:03:58 +0000527 * FUNCTION: acpi_walk_resource_buffer
Bob Moore41195322006-05-26 16:36:00 -0400528 *
Bob Mooreafb1bbe2012-12-31 00:03:58 +0000529 * PARAMETERS: buffer - Formatted buffer returned by one of the
530 * various Get*Resource functions
Bob Moore41195322006-05-26 16:36:00 -0400531 * user_function - Called for each resource
Bob Mooreba494be2012-07-12 09:40:10 +0800532 * context - Passed to user_function
Bob Moore41195322006-05-26 16:36:00 -0400533 *
534 * RETURN: Status
535 *
Bob Mooreafb1bbe2012-12-31 00:03:58 +0000536 * DESCRIPTION: Walks the input resource template. The user_function is called
537 * once for each resource in the list.
Bob Moore41195322006-05-26 16:36:00 -0400538 *
539 ******************************************************************************/
Bob Mooreafb1bbe2012-12-31 00:03:58 +0000540
Bob Moore41195322006-05-26 16:36:00 -0400541acpi_status
Lv Zhengf5c1e1c2016-05-05 12:57:53 +0800542acpi_walk_resource_buffer(struct acpi_buffer *buffer,
Bob Mooreafb1bbe2012-12-31 00:03:58 +0000543 acpi_walk_resource_callback user_function,
544 void *context)
Bob Moore41195322006-05-26 16:36:00 -0400545{
Bob Mooreafb1bbe2012-12-31 00:03:58 +0000546 acpi_status status = AE_OK;
Bob Moore41195322006-05-26 16:36:00 -0400547 struct acpi_resource *resource;
548 struct acpi_resource *resource_end;
549
Bob Mooreafb1bbe2012-12-31 00:03:58 +0000550 ACPI_FUNCTION_TRACE(acpi_walk_resource_buffer);
Bob Moore41195322006-05-26 16:36:00 -0400551
552 /* Parameter validation */
553
Bob Mooreafb1bbe2012-12-31 00:03:58 +0000554 if (!buffer || !buffer->pointer || !user_function) {
Bob Moore41195322006-05-26 16:36:00 -0400555 return_ACPI_STATUS(AE_BAD_PARAMETER);
556 }
557
Bob Mooreafb1bbe2012-12-31 00:03:58 +0000558 /* Buffer contains the resource list and length */
Bob Moore41195322006-05-26 16:36:00 -0400559
Bob Mooreafb1bbe2012-12-31 00:03:58 +0000560 resource = ACPI_CAST_PTR(struct acpi_resource, buffer->pointer);
Bob Moore41195322006-05-26 16:36:00 -0400561 resource_end =
Bob Mooreafb1bbe2012-12-31 00:03:58 +0000562 ACPI_ADD_PTR(struct acpi_resource, buffer->pointer, buffer->length);
Bob Moore41195322006-05-26 16:36:00 -0400563
564 /* Walk the resource list until the end_tag is found (or buffer end) */
565
566 while (resource < resource_end) {
567
Bob Moorec13085e2013-03-08 09:19:38 +0000568 /* Sanity check the resource type */
Bob Moore41195322006-05-26 16:36:00 -0400569
570 if (resource->type > ACPI_RESOURCE_TYPE_MAX) {
571 status = AE_AML_INVALID_RESOURCE_TYPE;
572 break;
573 }
574
Bob Moorec13085e2013-03-08 09:19:38 +0000575 /* Sanity check the length. It must not be zero, or we loop forever */
576
577 if (!resource->length) {
578 return_ACPI_STATUS(AE_AML_BAD_RESOURCE_LENGTH);
579 }
580
Bob Moore41195322006-05-26 16:36:00 -0400581 /* Invoke the user function, abort on any error returned */
582
583 status = user_function(resource, context);
584 if (ACPI_FAILURE(status)) {
585 if (status == AE_CTRL_TERMINATE) {
586
587 /* This is an OK termination by the user function */
588
589 status = AE_OK;
590 }
591 break;
592 }
593
594 /* end_tag indicates end-of-list */
595
596 if (resource->type == ACPI_RESOURCE_TYPE_END_TAG) {
597 break;
598 }
599
600 /* Get the next resource descriptor */
601
Lv Zhengfb4e5022012-12-19 05:38:31 +0000602 resource = ACPI_NEXT_RESOURCE(resource);
Bob Moore41195322006-05-26 16:36:00 -0400603 }
604
Bob Mooreafb1bbe2012-12-31 00:03:58 +0000605 return_ACPI_STATUS(status);
606}
607
608ACPI_EXPORT_SYMBOL(acpi_walk_resource_buffer)
609
610/*******************************************************************************
611 *
612 * FUNCTION: acpi_walk_resources
613 *
614 * PARAMETERS: device_handle - Handle to the device object for the
615 * device we are querying
616 * name - Method name of the resources we want.
617 * (METHOD_NAME__CRS, METHOD_NAME__PRS, or
618 * METHOD_NAME__AEI)
619 * user_function - Called for each resource
620 * context - Passed to user_function
621 *
622 * RETURN: Status
623 *
624 * DESCRIPTION: Retrieves the current or possible resource list for the
625 * specified device. The user_function is called once for
626 * each resource in the list.
627 *
628 ******************************************************************************/
629acpi_status
630acpi_walk_resources(acpi_handle device_handle,
631 char *name,
632 acpi_walk_resource_callback user_function, void *context)
633{
634 acpi_status status;
635 struct acpi_buffer buffer;
636
637 ACPI_FUNCTION_TRACE(acpi_walk_resources);
638
639 /* Parameter validation */
640
641 if (!device_handle || !user_function || !name ||
642 (!ACPI_COMPARE_NAME(name, METHOD_NAME__CRS) &&
643 !ACPI_COMPARE_NAME(name, METHOD_NAME__PRS) &&
644 !ACPI_COMPARE_NAME(name, METHOD_NAME__AEI))) {
645 return_ACPI_STATUS(AE_BAD_PARAMETER);
646 }
647
648 /* Get the _CRS/_PRS/_AEI resource list */
649
650 buffer.length = ACPI_ALLOCATE_LOCAL_BUFFER;
651 status = acpi_rs_get_method_data(device_handle, name, &buffer);
652 if (ACPI_FAILURE(status)) {
653 return_ACPI_STATUS(status);
654 }
655
656 /* Walk the resource list and cleanup */
657
658 status = acpi_walk_resource_buffer(&buffer, user_function, context);
Bob Moore41195322006-05-26 16:36:00 -0400659 ACPI_FREE(buffer.pointer);
660 return_ACPI_STATUS(status);
661}
662
663ACPI_EXPORT_SYMBOL(acpi_walk_resources)