aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/acpi/resources/rsxface.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/acpi/resources/rsxface.c')
-rw-r--r--drivers/acpi/resources/rsxface.c368
1 files changed, 208 insertions, 160 deletions
diff --git a/drivers/acpi/resources/rsxface.c b/drivers/acpi/resources/rsxface.c
index 8c1628c12cc8..1999e2ab7daa 100644
--- a/drivers/acpi/resources/rsxface.c
+++ b/drivers/acpi/resources/rsxface.c
@@ -43,6 +43,7 @@
43 43
44#include <acpi/acpi.h> 44#include <acpi/acpi.h>
45#include <acpi/acresrc.h> 45#include <acpi/acresrc.h>
46#include <acpi/acnamesp.h>
46 47
47#define _COMPONENT ACPI_RESOURCES 48#define _COMPONENT ACPI_RESOURCES
48ACPI_MODULE_NAME("rsxface") 49ACPI_MODULE_NAME("rsxface")
@@ -66,19 +67,80 @@ ACPI_MODULE_NAME("rsxface")
66static acpi_status 67static acpi_status
67acpi_rs_match_vendor_resource(struct acpi_resource *resource, void *context); 68acpi_rs_match_vendor_resource(struct acpi_resource *resource, void *context);
68 69
70static acpi_status
71acpi_rs_validate_parameters(acpi_handle device_handle,
72 struct acpi_buffer *buffer,
73 struct acpi_namespace_node **return_node);
74
75/*******************************************************************************
76 *
77 * FUNCTION: acpi_rs_validate_parameters
78 *
79 * PARAMETERS: device_handle - Handle to a device
80 * Buffer - Pointer to a data buffer
81 * return_node - Pointer to where the device node is returned
82 *
83 * RETURN: Status
84 *
85 * DESCRIPTION: Common parameter validation for resource interfaces
86 *
87 ******************************************************************************/
88
89static acpi_status
90acpi_rs_validate_parameters(acpi_handle device_handle,
91 struct acpi_buffer *buffer,
92 struct acpi_namespace_node **return_node)
93{
94 acpi_status status;
95 struct acpi_namespace_node *node;
96
97 ACPI_FUNCTION_TRACE(rs_validate_parameters);
98
99 /*
100 * Must have a valid handle to an ACPI device
101 */
102 if (!device_handle) {
103 return_ACPI_STATUS(AE_BAD_PARAMETER);
104 }
105
106 node = acpi_ns_map_handle_to_node(device_handle);
107 if (!node) {
108 return_ACPI_STATUS(AE_BAD_PARAMETER);
109 }
110
111 if (node->type != ACPI_TYPE_DEVICE) {
112 return_ACPI_STATUS(AE_TYPE);
113 }
114
115 /*
116 * Validate the user buffer object
117 *
118 * if there is a non-zero buffer length we also need a valid pointer in
119 * the buffer. If it's a zero buffer length, we'll be returning the
120 * needed buffer size (later), so keep going.
121 */
122 status = acpi_ut_validate_buffer(buffer);
123 if (ACPI_FAILURE(status)) {
124 return_ACPI_STATUS(status);
125 }
126
127 *return_node = node;
128 return_ACPI_STATUS(AE_OK);
129}
130
69/******************************************************************************* 131/*******************************************************************************
70 * 132 *
71 * FUNCTION: acpi_get_irq_routing_table 133 * FUNCTION: acpi_get_irq_routing_table
72 * 134 *
73 * PARAMETERS: device_handle - a handle to the Bus device we are querying 135 * PARAMETERS: device_handle - Handle to the Bus device we are querying
74 * ret_buffer - a pointer to a buffer to receive the 136 * ret_buffer - Pointer to a buffer to receive the
75 * current resources for the device 137 * current resources for the device
76 * 138 *
77 * RETURN: Status 139 * RETURN: Status
78 * 140 *
79 * DESCRIPTION: This function is called to get the IRQ routing table for a 141 * DESCRIPTION: This function is called to get the IRQ routing table for a
80 * specific bus. The caller must first acquire a handle for the 142 * specific bus. The caller must first acquire a handle for the
81 * desired bus. The routine table is placed in the buffer pointed 143 * desired bus. The routine table is placed in the buffer pointed
82 * to by the ret_buffer variable parameter. 144 * to by the ret_buffer variable parameter.
83 * 145 *
84 * If the function fails an appropriate status will be returned 146 * If the function fails an appropriate status will be returned
@@ -94,25 +156,18 @@ acpi_get_irq_routing_table(acpi_handle device_handle,
94 struct acpi_buffer *ret_buffer) 156 struct acpi_buffer *ret_buffer)
95{ 157{
96 acpi_status status; 158 acpi_status status;
159 struct acpi_namespace_node *node;
97 160
98 ACPI_FUNCTION_TRACE(acpi_get_irq_routing_table); 161 ACPI_FUNCTION_TRACE(acpi_get_irq_routing_table);
99 162
100 /* 163 /* Validate parameters then dispatch to internal routine */
101 * Must have a valid handle and buffer, So we have to have a handle
102 * and a return buffer structure, and if there is a non-zero buffer length
103 * we also need a valid pointer in the buffer. If it's a zero buffer length,
104 * we'll be returning the needed buffer size, so keep going.
105 */
106 if (!device_handle) {
107 return_ACPI_STATUS(AE_BAD_PARAMETER);
108 }
109 164
110 status = acpi_ut_validate_buffer(ret_buffer); 165 status = acpi_rs_validate_parameters(device_handle, ret_buffer, &node);
111 if (ACPI_FAILURE(status)) { 166 if (ACPI_FAILURE(status)) {
112 return_ACPI_STATUS(status); 167 return_ACPI_STATUS(status);
113 } 168 }
114 169
115 status = acpi_rs_get_prt_method_data(device_handle, ret_buffer); 170 status = acpi_rs_get_prt_method_data(node, ret_buffer);
116 return_ACPI_STATUS(status); 171 return_ACPI_STATUS(status);
117} 172}
118 173
@@ -122,16 +177,16 @@ ACPI_EXPORT_SYMBOL(acpi_get_irq_routing_table)
122 * 177 *
123 * FUNCTION: acpi_get_current_resources 178 * FUNCTION: acpi_get_current_resources
124 * 179 *
125 * PARAMETERS: device_handle - a handle to the device object for the 180 * PARAMETERS: device_handle - Handle to the device object for the
126 * device we are querying 181 * device we are querying
127 * ret_buffer - a pointer to a buffer to receive the 182 * ret_buffer - Pointer to a buffer to receive the
128 * current resources for the device 183 * current resources for the device
129 * 184 *
130 * RETURN: Status 185 * RETURN: Status
131 * 186 *
132 * DESCRIPTION: This function is called to get the current resources for a 187 * DESCRIPTION: This function is called to get the current resources for a
133 * specific device. The caller must first acquire a handle for 188 * specific device. The caller must first acquire a handle for
134 * the desired device. The resource data is placed in the buffer 189 * the desired device. The resource data is placed in the buffer
135 * pointed to by the ret_buffer variable parameter. 190 * pointed to by the ret_buffer variable parameter.
136 * 191 *
137 * If the function fails an appropriate status will be returned 192 * If the function fails an appropriate status will be returned
@@ -146,25 +201,18 @@ acpi_get_current_resources(acpi_handle device_handle,
146 struct acpi_buffer *ret_buffer) 201 struct acpi_buffer *ret_buffer)
147{ 202{
148 acpi_status status; 203 acpi_status status;
204 struct acpi_namespace_node *node;
149 205
150 ACPI_FUNCTION_TRACE(acpi_get_current_resources); 206 ACPI_FUNCTION_TRACE(acpi_get_current_resources);
151 207
152 /* 208 /* Validate parameters then dispatch to internal routine */
153 * Must have a valid handle and buffer, So we have to have a handle
154 * and a return buffer structure, and if there is a non-zero buffer length
155 * we also need a valid pointer in the buffer. If it's a zero buffer length,
156 * we'll be returning the needed buffer size, so keep going.
157 */
158 if (!device_handle) {
159 return_ACPI_STATUS(AE_BAD_PARAMETER);
160 }
161 209
162 status = acpi_ut_validate_buffer(ret_buffer); 210 status = acpi_rs_validate_parameters(device_handle, ret_buffer, &node);
163 if (ACPI_FAILURE(status)) { 211 if (ACPI_FAILURE(status)) {
164 return_ACPI_STATUS(status); 212 return_ACPI_STATUS(status);
165 } 213 }
166 214
167 status = acpi_rs_get_crs_method_data(device_handle, ret_buffer); 215 status = acpi_rs_get_crs_method_data(node, ret_buffer);
168 return_ACPI_STATUS(status); 216 return_ACPI_STATUS(status);
169} 217}
170 218
@@ -175,16 +223,16 @@ ACPI_EXPORT_SYMBOL(acpi_get_current_resources)
175 * 223 *
176 * FUNCTION: acpi_get_possible_resources 224 * FUNCTION: acpi_get_possible_resources
177 * 225 *
178 * PARAMETERS: device_handle - a handle to the device object for the 226 * PARAMETERS: device_handle - Handle to the device object for the
179 * device we are querying 227 * device we are querying
180 * ret_buffer - a pointer to a buffer to receive the 228 * ret_buffer - Pointer to a buffer to receive the
181 * resources for the device 229 * resources for the device
182 * 230 *
183 * RETURN: Status 231 * RETURN: Status
184 * 232 *
185 * DESCRIPTION: This function is called to get a list of the possible resources 233 * DESCRIPTION: This function is called to get a list of the possible resources
186 * for a specific device. The caller must first acquire a handle 234 * for a specific device. The caller must first acquire a handle
187 * for the desired device. The resource data is placed in the 235 * for the desired device. The resource data is placed in the
188 * buffer pointed to by the ret_buffer variable. 236 * buffer pointed to by the ret_buffer variable.
189 * 237 *
190 * If the function fails an appropriate status will be returned 238 * If the function fails an appropriate status will be returned
@@ -196,25 +244,18 @@ acpi_get_possible_resources(acpi_handle device_handle,
196 struct acpi_buffer *ret_buffer) 244 struct acpi_buffer *ret_buffer)
197{ 245{
198 acpi_status status; 246 acpi_status status;
247 struct acpi_namespace_node *node;
199 248
200 ACPI_FUNCTION_TRACE(acpi_get_possible_resources); 249 ACPI_FUNCTION_TRACE(acpi_get_possible_resources);
201 250
202 /* 251 /* Validate parameters then dispatch to internal routine */
203 * Must have a valid handle and buffer, So we have to have a handle
204 * and a return buffer structure, and if there is a non-zero buffer length
205 * we also need a valid pointer in the buffer. If it's a zero buffer length,
206 * we'll be returning the needed buffer size, so keep going.
207 */
208 if (!device_handle) {
209 return_ACPI_STATUS(AE_BAD_PARAMETER);
210 }
211 252
212 status = acpi_ut_validate_buffer(ret_buffer); 253 status = acpi_rs_validate_parameters(device_handle, ret_buffer, &node);
213 if (ACPI_FAILURE(status)) { 254 if (ACPI_FAILURE(status)) {
214 return_ACPI_STATUS(status); 255 return_ACPI_STATUS(status);
215 } 256 }
216 257
217 status = acpi_rs_get_prs_method_data(device_handle, ret_buffer); 258 status = acpi_rs_get_prs_method_data(node, ret_buffer);
218 return_ACPI_STATUS(status); 259 return_ACPI_STATUS(status);
219} 260}
220 261
@@ -223,113 +264,18 @@ ACPI_EXPORT_SYMBOL(acpi_get_possible_resources)
223 264
224/******************************************************************************* 265/*******************************************************************************
225 * 266 *
226 * FUNCTION: acpi_walk_resources
227 *
228 * PARAMETERS: device_handle - Handle to the device object for the
229 * device we are querying
230 * Name - Method name of the resources we want
231 * (METHOD_NAME__CRS or METHOD_NAME__PRS)
232 * user_function - Called for each resource
233 * Context - Passed to user_function
234 *
235 * RETURN: Status
236 *
237 * DESCRIPTION: Retrieves the current or possible resource list for the
238 * specified device. The user_function is called once for
239 * each resource in the list.
240 *
241 ******************************************************************************/
242acpi_status
243acpi_walk_resources(acpi_handle device_handle,
244 char *name,
245 acpi_walk_resource_callback user_function, void *context)
246{
247 acpi_status status;
248 struct acpi_buffer buffer;
249 struct acpi_resource *resource;
250 struct acpi_resource *resource_end;
251
252 ACPI_FUNCTION_TRACE(acpi_walk_resources);
253
254 /* Parameter validation */
255
256 if (!device_handle || !user_function || !name ||
257 (!ACPI_COMPARE_NAME(name, METHOD_NAME__CRS) &&
258 !ACPI_COMPARE_NAME(name, METHOD_NAME__PRS))) {
259 return_ACPI_STATUS(AE_BAD_PARAMETER);
260 }
261
262 /* Get the _CRS or _PRS resource list */
263
264 buffer.length = ACPI_ALLOCATE_LOCAL_BUFFER;
265 status = acpi_rs_get_method_data(device_handle, name, &buffer);
266 if (ACPI_FAILURE(status)) {
267 return_ACPI_STATUS(status);
268 }
269
270 /* Buffer now contains the resource list */
271
272 resource = ACPI_CAST_PTR(struct acpi_resource, buffer.pointer);
273 resource_end =
274 ACPI_ADD_PTR(struct acpi_resource, buffer.pointer, buffer.length);
275
276 /* Walk the resource list until the end_tag is found (or buffer end) */
277
278 while (resource < resource_end) {
279
280 /* Sanity check the resource */
281
282 if (resource->type > ACPI_RESOURCE_TYPE_MAX) {
283 status = AE_AML_INVALID_RESOURCE_TYPE;
284 break;
285 }
286
287 /* Invoke the user function, abort on any error returned */
288
289 status = user_function(resource, context);
290 if (ACPI_FAILURE(status)) {
291 if (status == AE_CTRL_TERMINATE) {
292
293 /* This is an OK termination by the user function */
294
295 status = AE_OK;
296 }
297 break;
298 }
299
300 /* end_tag indicates end-of-list */
301
302 if (resource->type == ACPI_RESOURCE_TYPE_END_TAG) {
303 break;
304 }
305
306 /* Get the next resource descriptor */
307
308 resource =
309 ACPI_ADD_PTR(struct acpi_resource, resource,
310 resource->length);
311 }
312
313 ACPI_FREE(buffer.pointer);
314 return_ACPI_STATUS(status);
315}
316
317ACPI_EXPORT_SYMBOL(acpi_walk_resources)
318
319/*******************************************************************************
320 *
321 * FUNCTION: acpi_set_current_resources 267 * FUNCTION: acpi_set_current_resources
322 * 268 *
323 * PARAMETERS: device_handle - a handle to the device object for the 269 * PARAMETERS: device_handle - Handle to the device object for the
324 * device we are changing the resources of 270 * device we are setting resources
325 * in_buffer - a pointer to a buffer containing the 271 * in_buffer - Pointer to a buffer containing the
326 * resources to be set for the device 272 * resources to be set for the device
327 * 273 *
328 * RETURN: Status 274 * RETURN: Status
329 * 275 *
330 * DESCRIPTION: This function is called to set the current resources for a 276 * DESCRIPTION: This function is called to set the current resources for a
331 * specific device. The caller must first acquire a handle for 277 * specific device. The caller must first acquire a handle for
332 * the desired device. The resource data is passed to the routine 278 * the desired device. The resource data is passed to the routine
333 * the buffer pointed to by the in_buffer variable. 279 * the buffer pointed to by the in_buffer variable.
334 * 280 *
335 ******************************************************************************/ 281 ******************************************************************************/
@@ -338,17 +284,24 @@ acpi_set_current_resources(acpi_handle device_handle,
338 struct acpi_buffer *in_buffer) 284 struct acpi_buffer *in_buffer)
339{ 285{
340 acpi_status status; 286 acpi_status status;
287 struct acpi_namespace_node *node;
341 288
342 ACPI_FUNCTION_TRACE(acpi_set_current_resources); 289 ACPI_FUNCTION_TRACE(acpi_set_current_resources);
343 290
344 /* Must have a valid handle and buffer */ 291 /* Validate the buffer, don't allow zero length */
345 292
346 if ((!device_handle) || 293 if ((!in_buffer) || (!in_buffer->pointer) || (!in_buffer->length)) {
347 (!in_buffer) || (!in_buffer->pointer) || (!in_buffer->length)) {
348 return_ACPI_STATUS(AE_BAD_PARAMETER); 294 return_ACPI_STATUS(AE_BAD_PARAMETER);
349 } 295 }
350 296
351 status = acpi_rs_set_srs_method_data(device_handle, in_buffer); 297 /* Validate parameters then dispatch to internal routine */
298
299 status = acpi_rs_validate_parameters(device_handle, in_buffer, &node);
300 if (ACPI_FAILURE(status)) {
301 return_ACPI_STATUS(status);
302 }
303
304 status = acpi_rs_set_srs_method_data(node, in_buffer);
352 return_ACPI_STATUS(status); 305 return_ACPI_STATUS(status);
353} 306}
354 307
@@ -358,15 +311,14 @@ ACPI_EXPORT_SYMBOL(acpi_set_current_resources)
358 * 311 *
359 * FUNCTION: acpi_resource_to_address64 312 * FUNCTION: acpi_resource_to_address64
360 * 313 *
361 * PARAMETERS: Resource - Pointer to a resource 314 * PARAMETERS: Resource - Pointer to a resource
362 * Out - Pointer to the users's return 315 * Out - Pointer to the users's return buffer
363 * buffer (a struct 316 * (a struct acpi_resource_address64)
364 * struct acpi_resource_address64)
365 * 317 *
366 * RETURN: Status 318 * RETURN: Status
367 * 319 *
368 * DESCRIPTION: If the resource is an address16, address32, or address64, 320 * DESCRIPTION: If the resource is an address16, address32, or address64,
369 * copy it to the address64 return buffer. This saves the 321 * copy it to the address64 return buffer. This saves the
370 * caller from having to duplicate code for different-sized 322 * caller from having to duplicate code for different-sized
371 * addresses. 323 * addresses.
372 * 324 *
@@ -418,12 +370,12 @@ ACPI_EXPORT_SYMBOL(acpi_resource_to_address64)
418 * 370 *
419 * FUNCTION: acpi_get_vendor_resource 371 * FUNCTION: acpi_get_vendor_resource
420 * 372 *
421 * PARAMETERS: device_handle - Handle for the parent device object 373 * PARAMETERS: device_handle - Handle for the parent device object
422 * Name - Method name for the parent resource 374 * Name - Method name for the parent resource
423 * (METHOD_NAME__CRS or METHOD_NAME__PRS) 375 * (METHOD_NAME__CRS or METHOD_NAME__PRS)
424 * Uuid - Pointer to the UUID to be matched. 376 * Uuid - Pointer to the UUID to be matched.
425 * includes both subtype and 16-byte UUID 377 * includes both subtype and 16-byte UUID
426 * ret_buffer - Where the vendor resource is returned 378 * ret_buffer - Where the vendor resource is returned
427 * 379 *
428 * RETURN: Status 380 * RETURN: Status
429 * 381 *
@@ -525,3 +477,99 @@ acpi_rs_match_vendor_resource(struct acpi_resource *resource, void *context)
525} 477}
526 478
527ACPI_EXPORT_SYMBOL(acpi_rs_match_vendor_resource) 479ACPI_EXPORT_SYMBOL(acpi_rs_match_vendor_resource)
480
481/*******************************************************************************
482 *
483 * FUNCTION: acpi_walk_resources
484 *
485 * PARAMETERS: device_handle - Handle to the device object for the
486 * device we are querying
487 * Name - Method name of the resources we want
488 * (METHOD_NAME__CRS or METHOD_NAME__PRS)
489 * user_function - Called for each resource
490 * Context - Passed to user_function
491 *
492 * RETURN: Status
493 *
494 * DESCRIPTION: Retrieves the current or possible resource list for the
495 * specified device. The user_function is called once for
496 * each resource in the list.
497 *
498 ******************************************************************************/
499
500acpi_status
501acpi_walk_resources(acpi_handle device_handle,
502 char *name,
503 acpi_walk_resource_callback user_function, void *context)
504{
505 acpi_status status;
506 struct acpi_buffer buffer;
507 struct acpi_resource *resource;
508 struct acpi_resource *resource_end;
509
510 ACPI_FUNCTION_TRACE(acpi_walk_resources);
511
512 /* Parameter validation */
513
514 if (!device_handle || !user_function || !name ||
515 (!ACPI_COMPARE_NAME(name, METHOD_NAME__CRS) &&
516 !ACPI_COMPARE_NAME(name, METHOD_NAME__PRS))) {
517 return_ACPI_STATUS(AE_BAD_PARAMETER);
518 }
519
520 /* Get the _CRS or _PRS resource list */
521
522 buffer.length = ACPI_ALLOCATE_LOCAL_BUFFER;
523 status = acpi_rs_get_method_data(device_handle, name, &buffer);
524 if (ACPI_FAILURE(status)) {
525 return_ACPI_STATUS(status);
526 }
527
528 /* Buffer now contains the resource list */
529
530 resource = ACPI_CAST_PTR(struct acpi_resource, buffer.pointer);
531 resource_end =
532 ACPI_ADD_PTR(struct acpi_resource, buffer.pointer, buffer.length);
533
534 /* Walk the resource list until the end_tag is found (or buffer end) */
535
536 while (resource < resource_end) {
537
538 /* Sanity check the resource */
539
540 if (resource->type > ACPI_RESOURCE_TYPE_MAX) {
541 status = AE_AML_INVALID_RESOURCE_TYPE;
542 break;
543 }
544
545 /* Invoke the user function, abort on any error returned */
546
547 status = user_function(resource, context);
548 if (ACPI_FAILURE(status)) {
549 if (status == AE_CTRL_TERMINATE) {
550
551 /* This is an OK termination by the user function */
552
553 status = AE_OK;
554 }
555 break;
556 }
557
558 /* end_tag indicates end-of-list */
559
560 if (resource->type == ACPI_RESOURCE_TYPE_END_TAG) {
561 break;
562 }
563
564 /* Get the next resource descriptor */
565
566 resource =
567 ACPI_ADD_PTR(struct acpi_resource, resource,
568 resource->length);
569 }
570
571 ACPI_FREE(buffer.pointer);
572 return_ACPI_STATUS(status);
573}
574
575ACPI_EXPORT_SYMBOL(acpi_walk_resources)