x86/boot: Rename overlapping memcpy() to memmove()
[linux/fpc-iii.git] / drivers / acpi / acpica / rsxface.c
blob900933be99093de9bd9bb5ec5ff786451f178d54
1 /*******************************************************************************
3 * Module Name: rsxface - Public interfaces to the resource manager
5 ******************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2016, Intel Corp.
9 * All rights reserved.
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.
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.
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.
44 #define EXPORT_ACPI_INTERFACES
46 #include <acpi/acpi.h>
47 #include "accommon.h"
48 #include "acresrc.h"
49 #include "acnamesp.h"
51 #define _COMPONENT ACPI_RESOURCES
52 ACPI_MODULE_NAME("rsxface")
54 /* Local macros for 16,32-bit to 64-bit conversion */
55 #define ACPI_COPY_FIELD(out, in, field) ((out)->field = (in)->field)
56 #define ACPI_COPY_ADDRESS(out, in) \
57 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); \
62 ACPI_COPY_FIELD(out, in, info); \
63 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); \
68 ACPI_COPY_FIELD(out, in, resource_source);
69 /* Local prototypes */
70 static acpi_status
71 acpi_rs_match_vendor_resource(struct acpi_resource *resource, void *context);
73 static acpi_status
74 acpi_rs_validate_parameters(acpi_handle device_handle,
75 struct acpi_buffer *buffer,
76 struct acpi_namespace_node **return_node);
78 /*******************************************************************************
80 * FUNCTION: acpi_rs_validate_parameters
82 * PARAMETERS: device_handle - Handle to a device
83 * buffer - Pointer to a data buffer
84 * return_node - Pointer to where the device node is returned
86 * RETURN: Status
88 * DESCRIPTION: Common parameter validation for resource interfaces
90 ******************************************************************************/
92 static acpi_status
93 acpi_rs_validate_parameters(acpi_handle device_handle,
94 struct acpi_buffer *buffer,
95 struct acpi_namespace_node **return_node)
97 acpi_status status;
98 struct acpi_namespace_node *node;
100 ACPI_FUNCTION_TRACE(rs_validate_parameters);
103 * Must have a valid handle to an ACPI device
105 if (!device_handle) {
106 return_ACPI_STATUS(AE_BAD_PARAMETER);
109 node = acpi_ns_validate_handle(device_handle);
110 if (!node) {
111 return_ACPI_STATUS(AE_BAD_PARAMETER);
114 if (node->type != ACPI_TYPE_DEVICE) {
115 return_ACPI_STATUS(AE_TYPE);
119 * Validate the user buffer object
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.
125 status = acpi_ut_validate_buffer(buffer);
126 if (ACPI_FAILURE(status)) {
127 return_ACPI_STATUS(status);
130 *return_node = node;
131 return_ACPI_STATUS(AE_OK);
134 /*******************************************************************************
136 * FUNCTION: acpi_get_irq_routing_table
138 * PARAMETERS: device_handle - Handle to the Bus device we are querying
139 * ret_buffer - Pointer to a buffer to receive the
140 * current resources for the device
142 * RETURN: Status
144 * DESCRIPTION: This function is called to get the IRQ routing table for a
145 * specific bus. The caller must first acquire a handle for the
146 * desired bus. The routine table is placed in the buffer pointed
147 * to by the ret_buffer variable parameter.
149 * If the function fails an appropriate status will be returned
150 * and the value of ret_buffer is undefined.
152 * This function attempts to execute the _PRT method contained in
153 * the object indicated by the passed device_handle.
155 ******************************************************************************/
157 acpi_status
158 acpi_get_irq_routing_table(acpi_handle device_handle,
159 struct acpi_buffer *ret_buffer)
161 acpi_status status;
162 struct acpi_namespace_node *node;
164 ACPI_FUNCTION_TRACE(acpi_get_irq_routing_table);
166 /* Validate parameters then dispatch to internal routine */
168 status = acpi_rs_validate_parameters(device_handle, ret_buffer, &node);
169 if (ACPI_FAILURE(status)) {
170 return_ACPI_STATUS(status);
173 status = acpi_rs_get_prt_method_data(node, ret_buffer);
174 return_ACPI_STATUS(status);
177 ACPI_EXPORT_SYMBOL(acpi_get_irq_routing_table)
179 /*******************************************************************************
181 * FUNCTION: acpi_get_current_resources
183 * PARAMETERS: device_handle - Handle to the device object for the
184 * device we are querying
185 * ret_buffer - Pointer to a buffer to receive the
186 * current resources for the device
188 * RETURN: Status
190 * DESCRIPTION: This function is called to get the current resources for a
191 * specific device. The caller must first acquire a handle for
192 * the desired device. The resource data is placed in the buffer
193 * pointed to by the ret_buffer variable parameter.
195 * If the function fails an appropriate status will be returned
196 * and the value of ret_buffer is undefined.
198 * This function attempts to execute the _CRS method contained in
199 * the object indicated by the passed device_handle.
201 ******************************************************************************/
202 acpi_status
203 acpi_get_current_resources(acpi_handle device_handle,
204 struct acpi_buffer *ret_buffer)
206 acpi_status status;
207 struct acpi_namespace_node *node;
209 ACPI_FUNCTION_TRACE(acpi_get_current_resources);
211 /* Validate parameters then dispatch to internal routine */
213 status = acpi_rs_validate_parameters(device_handle, ret_buffer, &node);
214 if (ACPI_FAILURE(status)) {
215 return_ACPI_STATUS(status);
218 status = acpi_rs_get_crs_method_data(node, ret_buffer);
219 return_ACPI_STATUS(status);
222 ACPI_EXPORT_SYMBOL(acpi_get_current_resources)
224 /*******************************************************************************
226 * FUNCTION: acpi_get_possible_resources
228 * PARAMETERS: device_handle - Handle to the device object for the
229 * device we are querying
230 * ret_buffer - Pointer to a buffer to receive the
231 * resources for the device
233 * RETURN: Status
235 * DESCRIPTION: This function is called to get a list of the possible resources
236 * for a specific device. The caller must first acquire a handle
237 * for the desired device. The resource data is placed in the
238 * buffer pointed to by the ret_buffer variable.
240 * If the function fails an appropriate status will be returned
241 * and the value of ret_buffer is undefined.
243 ******************************************************************************/
244 acpi_status
245 acpi_get_possible_resources(acpi_handle device_handle,
246 struct acpi_buffer *ret_buffer)
248 acpi_status status;
249 struct acpi_namespace_node *node;
251 ACPI_FUNCTION_TRACE(acpi_get_possible_resources);
253 /* Validate parameters then dispatch to internal routine */
255 status = acpi_rs_validate_parameters(device_handle, ret_buffer, &node);
256 if (ACPI_FAILURE(status)) {
257 return_ACPI_STATUS(status);
260 status = acpi_rs_get_prs_method_data(node, ret_buffer);
261 return_ACPI_STATUS(status);
264 ACPI_EXPORT_SYMBOL(acpi_get_possible_resources)
266 /*******************************************************************************
268 * FUNCTION: acpi_set_current_resources
270 * 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
273 * resources to be set for the device
275 * RETURN: Status
277 * DESCRIPTION: This function is called to set the current resources for a
278 * specific device. The caller must first acquire a handle for
279 * the desired device. The resource data is passed to the routine
280 * the buffer pointed to by the in_buffer variable.
282 ******************************************************************************/
283 acpi_status
284 acpi_set_current_resources(acpi_handle device_handle,
285 struct acpi_buffer *in_buffer)
287 acpi_status status;
288 struct acpi_namespace_node *node;
290 ACPI_FUNCTION_TRACE(acpi_set_current_resources);
292 /* Validate the buffer, don't allow zero length */
294 if ((!in_buffer) || (!in_buffer->pointer) || (!in_buffer->length)) {
295 return_ACPI_STATUS(AE_BAD_PARAMETER);
298 /* Validate parameters then dispatch to internal routine */
300 status = acpi_rs_validate_parameters(device_handle, in_buffer, &node);
301 if (ACPI_FAILURE(status)) {
302 return_ACPI_STATUS(status);
305 status = acpi_rs_set_srs_method_data(node, in_buffer);
306 return_ACPI_STATUS(status);
309 ACPI_EXPORT_SYMBOL(acpi_set_current_resources)
311 /*******************************************************************************
313 * FUNCTION: acpi_get_event_resources
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
320 * RETURN: Status
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.
328 ******************************************************************************/
329 acpi_status
330 acpi_get_event_resources(acpi_handle device_handle,
331 struct acpi_buffer *ret_buffer)
333 acpi_status status;
334 struct acpi_namespace_node *node;
336 ACPI_FUNCTION_TRACE(acpi_get_event_resources);
338 /* Validate parameters then dispatch to internal routine */
340 status = acpi_rs_validate_parameters(device_handle, ret_buffer, &node);
341 if (ACPI_FAILURE(status)) {
342 return_ACPI_STATUS(status);
345 status = acpi_rs_get_aei_method_data(node, ret_buffer);
346 return_ACPI_STATUS(status);
349 ACPI_EXPORT_SYMBOL(acpi_get_event_resources)
351 /******************************************************************************
353 * FUNCTION: acpi_resource_to_address64
355 * PARAMETERS: resource - Pointer to a resource
356 * out - Pointer to the users's return buffer
357 * (a struct acpi_resource_address64)
359 * RETURN: Status
361 * DESCRIPTION: If the resource is an address16, address32, or address64,
362 * copy it to the address64 return buffer. This saves the
363 * caller from having to duplicate code for different-sized
364 * addresses.
366 ******************************************************************************/
367 acpi_status
368 acpi_resource_to_address64(struct acpi_resource *resource,
369 struct acpi_resource_address64 *out)
371 struct acpi_resource_address16 *address16;
372 struct acpi_resource_address32 *address32;
374 if (!resource || !out) {
375 return (AE_BAD_PARAMETER);
378 /* Convert 16 or 32 address descriptor to 64 */
380 switch (resource->type) {
381 case ACPI_RESOURCE_TYPE_ADDRESS16:
383 address16 =
384 ACPI_CAST_PTR(struct acpi_resource_address16,
385 &resource->data);
386 ACPI_COPY_ADDRESS(out, address16);
387 break;
389 case ACPI_RESOURCE_TYPE_ADDRESS32:
391 address32 =
392 ACPI_CAST_PTR(struct acpi_resource_address32,
393 &resource->data);
394 ACPI_COPY_ADDRESS(out, address32);
395 break;
397 case ACPI_RESOURCE_TYPE_ADDRESS64:
399 /* Simple copy for 64 bit source */
401 memcpy(out, &resource->data,
402 sizeof(struct acpi_resource_address64));
403 break;
405 default:
407 return (AE_BAD_PARAMETER);
410 return (AE_OK);
413 ACPI_EXPORT_SYMBOL(acpi_resource_to_address64)
415 /*******************************************************************************
417 * FUNCTION: acpi_get_vendor_resource
419 * PARAMETERS: device_handle - Handle for the parent device object
420 * name - Method name for the parent resource
421 * (METHOD_NAME__CRS or METHOD_NAME__PRS)
422 * uuid - Pointer to the UUID to be matched.
423 * includes both subtype and 16-byte UUID
424 * ret_buffer - Where the vendor resource is returned
426 * RETURN: Status
428 * DESCRIPTION: Walk a resource template for the specified device to find a
429 * vendor-defined resource that matches the supplied UUID and
430 * UUID subtype. Returns a struct acpi_resource of type Vendor.
432 ******************************************************************************/
433 acpi_status
434 acpi_get_vendor_resource(acpi_handle device_handle,
435 char *name,
436 struct acpi_vendor_uuid * uuid,
437 struct acpi_buffer * ret_buffer)
439 struct acpi_vendor_walk_info info;
440 acpi_status status;
442 /* Other parameters are validated by acpi_walk_resources */
444 if (!uuid || !ret_buffer) {
445 return (AE_BAD_PARAMETER);
448 info.uuid = uuid;
449 info.buffer = ret_buffer;
450 info.status = AE_NOT_EXIST;
452 /* Walk the _CRS or _PRS resource list for this device */
454 status =
455 acpi_walk_resources(device_handle, name,
456 acpi_rs_match_vendor_resource, &info);
457 if (ACPI_FAILURE(status)) {
458 return (status);
461 return (info.status);
464 ACPI_EXPORT_SYMBOL(acpi_get_vendor_resource)
466 /*******************************************************************************
468 * FUNCTION: acpi_rs_match_vendor_resource
470 * PARAMETERS: acpi_walk_resource_callback
472 * RETURN: Status
474 * DESCRIPTION: Match a vendor resource via the ACPI 3.0 UUID
476 ******************************************************************************/
477 static acpi_status
478 acpi_rs_match_vendor_resource(struct acpi_resource *resource, void *context)
480 struct acpi_vendor_walk_info *info = context;
481 struct acpi_resource_vendor_typed *vendor;
482 struct acpi_buffer *buffer;
483 acpi_status status;
485 /* Ignore all descriptors except Vendor */
487 if (resource->type != ACPI_RESOURCE_TYPE_VENDOR) {
488 return (AE_OK);
491 vendor = &resource->data.vendor_typed;
494 * For a valid match, these conditions must hold:
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
500 if ((vendor->byte_length < (ACPI_UUID_LENGTH + 1)) ||
501 (vendor->uuid_subtype != info->uuid->subtype) ||
502 (memcmp(vendor->uuid, info->uuid->data, ACPI_UUID_LENGTH))) {
503 return (AE_OK);
506 /* Validate/Allocate/Clear caller buffer */
508 buffer = info->buffer;
509 status = acpi_ut_initialize_buffer(buffer, resource->length);
510 if (ACPI_FAILURE(status)) {
511 return (status);
514 /* Found the correct resource, copy and return it */
516 memcpy(buffer->pointer, resource, resource->length);
517 buffer->length = resource->length;
519 /* Found the desired descriptor, terminate resource walk */
521 info->status = AE_OK;
522 return (AE_CTRL_TERMINATE);
525 /*******************************************************************************
527 * FUNCTION: acpi_walk_resource_buffer
529 * PARAMETERS: buffer - Formatted buffer returned by one of the
530 * various Get*Resource functions
531 * user_function - Called for each resource
532 * context - Passed to user_function
534 * RETURN: Status
536 * DESCRIPTION: Walks the input resource template. The user_function is called
537 * once for each resource in the list.
539 ******************************************************************************/
541 acpi_status
542 acpi_walk_resource_buffer(struct acpi_buffer * buffer,
543 acpi_walk_resource_callback user_function,
544 void *context)
546 acpi_status status = AE_OK;
547 struct acpi_resource *resource;
548 struct acpi_resource *resource_end;
550 ACPI_FUNCTION_TRACE(acpi_walk_resource_buffer);
552 /* Parameter validation */
554 if (!buffer || !buffer->pointer || !user_function) {
555 return_ACPI_STATUS(AE_BAD_PARAMETER);
558 /* Buffer contains the resource list and length */
560 resource = ACPI_CAST_PTR(struct acpi_resource, buffer->pointer);
561 resource_end =
562 ACPI_ADD_PTR(struct acpi_resource, buffer->pointer, buffer->length);
564 /* Walk the resource list until the end_tag is found (or buffer end) */
566 while (resource < resource_end) {
568 /* Sanity check the resource type */
570 if (resource->type > ACPI_RESOURCE_TYPE_MAX) {
571 status = AE_AML_INVALID_RESOURCE_TYPE;
572 break;
575 /* Sanity check the length. It must not be zero, or we loop forever */
577 if (!resource->length) {
578 return_ACPI_STATUS(AE_AML_BAD_RESOURCE_LENGTH);
581 /* Invoke the user function, abort on any error returned */
583 status = user_function(resource, context);
584 if (ACPI_FAILURE(status)) {
585 if (status == AE_CTRL_TERMINATE) {
587 /* This is an OK termination by the user function */
589 status = AE_OK;
591 break;
594 /* end_tag indicates end-of-list */
596 if (resource->type == ACPI_RESOURCE_TYPE_END_TAG) {
597 break;
600 /* Get the next resource descriptor */
602 resource = ACPI_NEXT_RESOURCE(resource);
605 return_ACPI_STATUS(status);
608 ACPI_EXPORT_SYMBOL(acpi_walk_resource_buffer)
610 /*******************************************************************************
612 * FUNCTION: acpi_walk_resources
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
622 * RETURN: Status
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.
628 ******************************************************************************/
629 acpi_status
630 acpi_walk_resources(acpi_handle device_handle,
631 char *name,
632 acpi_walk_resource_callback user_function, void *context)
634 acpi_status status;
635 struct acpi_buffer buffer;
637 ACPI_FUNCTION_TRACE(acpi_walk_resources);
639 /* Parameter validation */
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);
648 /* Get the _CRS/_PRS/_AEI resource list */
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);
656 /* Walk the resource list and cleanup */
658 status = acpi_walk_resource_buffer(&buffer, user_function, context);
659 ACPI_FREE(buffer.pointer);
660 return_ACPI_STATUS(status);
663 ACPI_EXPORT_SYMBOL(acpi_walk_resources)