Erik Schmauss | 9585763 | 2018-03-14 16:13:07 -0700 | [diff] [blame^] | 1 | // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /******************************************************************************* |
| 3 | * |
| 4 | * Module Name: rsxface - Public interfaces to the resource manager |
| 5 | * |
| 6 | ******************************************************************************/ |
| 7 | |
Lv Zheng | 839e928 | 2013-10-29 09:29:51 +0800 | [diff] [blame] | 8 | #define EXPORT_ACPI_INTERFACES |
| 9 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include <acpi/acpi.h> |
Len Brown | e2f7a77 | 2009-01-09 00:30:03 -0500 | [diff] [blame] | 11 | #include "accommon.h" |
| 12 | #include "acresrc.h" |
| 13 | #include "acnamesp.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | |
| 15 | #define _COMPONENT ACPI_RESOURCES |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 16 | ACPI_MODULE_NAME("rsxface") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 18 | /* Local macros for 16,32-bit to 64-bit conversion */ |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 19 | #define ACPI_COPY_FIELD(out, in, field) ((out)->field = (in)->field) |
Bob Moore | 1fad873 | 2015-12-29 13:54:36 +0800 | [diff] [blame] | 20 | #define ACPI_COPY_ADDRESS(out, in) \ |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 21 | ACPI_COPY_FIELD(out, in, resource_type); \ |
| 22 | ACPI_COPY_FIELD(out, in, producer_consumer); \ |
| 23 | ACPI_COPY_FIELD(out, in, decode); \ |
| 24 | ACPI_COPY_FIELD(out, in, min_address_fixed); \ |
| 25 | ACPI_COPY_FIELD(out, in, max_address_fixed); \ |
Bob Moore | 0897831 | 2005-10-21 00:00:00 -0400 | [diff] [blame] | 26 | ACPI_COPY_FIELD(out, in, info); \ |
Lv Zheng | a45de93 | 2015-01-26 16:58:56 +0800 | [diff] [blame] | 27 | ACPI_COPY_FIELD(out, in, address.granularity); \ |
| 28 | ACPI_COPY_FIELD(out, in, address.minimum); \ |
| 29 | ACPI_COPY_FIELD(out, in, address.maximum); \ |
| 30 | ACPI_COPY_FIELD(out, in, address.translation_offset); \ |
| 31 | ACPI_COPY_FIELD(out, in, address.address_length); \ |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 32 | ACPI_COPY_FIELD(out, in, resource_source); |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 33 | /* Local prototypes */ |
| 34 | static acpi_status |
| 35 | acpi_rs_match_vendor_resource(struct acpi_resource *resource, void *context); |
| 36 | |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 37 | static acpi_status |
| 38 | acpi_rs_validate_parameters(acpi_handle device_handle, |
| 39 | struct acpi_buffer *buffer, |
| 40 | struct acpi_namespace_node **return_node); |
| 41 | |
| 42 | /******************************************************************************* |
| 43 | * |
| 44 | * FUNCTION: acpi_rs_validate_parameters |
| 45 | * |
| 46 | * PARAMETERS: device_handle - Handle to a device |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 47 | * buffer - Pointer to a data buffer |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 48 | * return_node - Pointer to where the device node is returned |
| 49 | * |
| 50 | * RETURN: Status |
| 51 | * |
| 52 | * DESCRIPTION: Common parameter validation for resource interfaces |
| 53 | * |
| 54 | ******************************************************************************/ |
| 55 | |
| 56 | static acpi_status |
| 57 | acpi_rs_validate_parameters(acpi_handle device_handle, |
| 58 | struct acpi_buffer *buffer, |
| 59 | struct acpi_namespace_node **return_node) |
| 60 | { |
| 61 | acpi_status status; |
| 62 | struct acpi_namespace_node *node; |
| 63 | |
| 64 | ACPI_FUNCTION_TRACE(rs_validate_parameters); |
| 65 | |
| 66 | /* |
| 67 | * Must have a valid handle to an ACPI device |
| 68 | */ |
| 69 | if (!device_handle) { |
| 70 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
| 71 | } |
| 72 | |
Bob Moore | f24b664 | 2009-12-11 14:57:00 +0800 | [diff] [blame] | 73 | node = acpi_ns_validate_handle(device_handle); |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 74 | if (!node) { |
| 75 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
| 76 | } |
| 77 | |
| 78 | if (node->type != ACPI_TYPE_DEVICE) { |
| 79 | return_ACPI_STATUS(AE_TYPE); |
| 80 | } |
| 81 | |
| 82 | /* |
| 83 | * Validate the user buffer object |
| 84 | * |
| 85 | * if there is a non-zero buffer length we also need a valid pointer in |
| 86 | * the buffer. If it's a zero buffer length, we'll be returning the |
| 87 | * needed buffer size (later), so keep going. |
| 88 | */ |
| 89 | status = acpi_ut_validate_buffer(buffer); |
| 90 | if (ACPI_FAILURE(status)) { |
| 91 | return_ACPI_STATUS(status); |
| 92 | } |
| 93 | |
| 94 | *return_node = node; |
| 95 | return_ACPI_STATUS(AE_OK); |
| 96 | } |
| 97 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | /******************************************************************************* |
| 99 | * |
| 100 | * FUNCTION: acpi_get_irq_routing_table |
| 101 | * |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 102 | * PARAMETERS: device_handle - Handle to the Bus device we are querying |
| 103 | * ret_buffer - Pointer to a buffer to receive the |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | * current resources for the device |
| 105 | * |
| 106 | * RETURN: Status |
| 107 | * |
| 108 | * DESCRIPTION: This function is called to get the IRQ routing table for a |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 109 | * specific bus. The caller must first acquire a handle for the |
| 110 | * desired bus. The routine table is placed in the buffer pointed |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | * to by the ret_buffer variable parameter. |
| 112 | * |
| 113 | * If the function fails an appropriate status will be returned |
| 114 | * and the value of ret_buffer is undefined. |
| 115 | * |
| 116 | * This function attempts to execute the _PRT method contained in |
| 117 | * the object indicated by the passed device_handle. |
| 118 | * |
| 119 | ******************************************************************************/ |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 120 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 122 | acpi_get_irq_routing_table(acpi_handle device_handle, |
| 123 | struct acpi_buffer *ret_buffer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 125 | acpi_status status; |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 126 | struct acpi_namespace_node *node; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 128 | ACPI_FUNCTION_TRACE(acpi_get_irq_routing_table); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 130 | /* Validate parameters then dispatch to internal routine */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 132 | status = acpi_rs_validate_parameters(device_handle, ret_buffer, &node); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 133 | if (ACPI_FAILURE(status)) { |
| 134 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | } |
| 136 | |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 137 | status = acpi_rs_get_prt_method_data(node, ret_buffer); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 138 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | } |
| 140 | |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 141 | ACPI_EXPORT_SYMBOL(acpi_get_irq_routing_table) |
| 142 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | /******************************************************************************* |
| 144 | * |
| 145 | * FUNCTION: acpi_get_current_resources |
| 146 | * |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 147 | * PARAMETERS: device_handle - Handle to the device object for the |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | * device we are querying |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 149 | * ret_buffer - Pointer to a buffer to receive the |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | * current resources for the device |
| 151 | * |
| 152 | * RETURN: Status |
| 153 | * |
| 154 | * DESCRIPTION: This function is called to get the current resources for a |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 155 | * specific device. The caller must first acquire a handle for |
| 156 | * the desired device. The resource data is placed in the buffer |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | * pointed to by the ret_buffer variable parameter. |
| 158 | * |
| 159 | * If the function fails an appropriate status will be returned |
| 160 | * and the value of ret_buffer is undefined. |
| 161 | * |
| 162 | * This function attempts to execute the _CRS method contained in |
| 163 | * the object indicated by the passed device_handle. |
| 164 | * |
| 165 | ******************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 167 | acpi_get_current_resources(acpi_handle device_handle, |
| 168 | struct acpi_buffer *ret_buffer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 170 | acpi_status status; |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 171 | struct acpi_namespace_node *node; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 173 | ACPI_FUNCTION_TRACE(acpi_get_current_resources); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 175 | /* Validate parameters then dispatch to internal routine */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 177 | status = acpi_rs_validate_parameters(device_handle, ret_buffer, &node); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 178 | if (ACPI_FAILURE(status)) { |
| 179 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | } |
| 181 | |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 182 | status = acpi_rs_get_crs_method_data(node, ret_buffer); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 183 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 186 | ACPI_EXPORT_SYMBOL(acpi_get_current_resources) |
Lv Zheng | 4d946f7 | 2015-10-19 10:25:56 +0800 | [diff] [blame] | 187 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | /******************************************************************************* |
| 189 | * |
| 190 | * FUNCTION: acpi_get_possible_resources |
| 191 | * |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 192 | * PARAMETERS: device_handle - Handle to the device object for the |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | * device we are querying |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 194 | * ret_buffer - Pointer to a buffer to receive the |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | * resources for the device |
| 196 | * |
| 197 | * RETURN: Status |
| 198 | * |
| 199 | * DESCRIPTION: This function is called to get a list of the possible resources |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 200 | * for a specific device. The caller must first acquire a handle |
| 201 | * for the desired device. The resource data is placed in the |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | * buffer pointed to by the ret_buffer variable. |
| 203 | * |
| 204 | * If the function fails an appropriate status will be returned |
| 205 | * and the value of ret_buffer is undefined. |
| 206 | * |
| 207 | ******************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 209 | acpi_get_possible_resources(acpi_handle device_handle, |
| 210 | struct acpi_buffer *ret_buffer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 212 | acpi_status status; |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 213 | struct acpi_namespace_node *node; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 215 | ACPI_FUNCTION_TRACE(acpi_get_possible_resources); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 217 | /* Validate parameters then dispatch to internal routine */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 219 | status = acpi_rs_validate_parameters(device_handle, ret_buffer, &node); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 220 | if (ACPI_FAILURE(status)) { |
| 221 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | } |
| 223 | |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 224 | status = acpi_rs_get_prs_method_data(node, ret_buffer); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 225 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 228 | ACPI_EXPORT_SYMBOL(acpi_get_possible_resources) |
Lv Zheng | 4d946f7 | 2015-10-19 10:25:56 +0800 | [diff] [blame] | 229 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | /******************************************************************************* |
| 231 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | * FUNCTION: acpi_set_current_resources |
| 233 | * |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 234 | * PARAMETERS: device_handle - Handle to the device object for the |
| 235 | * device we are setting resources |
| 236 | * in_buffer - Pointer to a buffer containing the |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | * resources to be set for the device |
| 238 | * |
| 239 | * RETURN: Status |
| 240 | * |
| 241 | * DESCRIPTION: This function is called to set the current resources for a |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 242 | * specific device. The caller must first acquire a handle for |
| 243 | * the desired device. The resource data is passed to the routine |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | * the buffer pointed to by the in_buffer variable. |
| 245 | * |
| 246 | ******************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 248 | acpi_set_current_resources(acpi_handle device_handle, |
| 249 | struct acpi_buffer *in_buffer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 251 | acpi_status status; |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 252 | struct acpi_namespace_node *node; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 254 | ACPI_FUNCTION_TRACE(acpi_set_current_resources); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 256 | /* Validate the buffer, don't allow zero length */ |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 257 | |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 258 | if ((!in_buffer) || (!in_buffer->pointer) || (!in_buffer->length)) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 259 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | } |
| 261 | |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 262 | /* Validate parameters then dispatch to internal routine */ |
| 263 | |
| 264 | status = acpi_rs_validate_parameters(device_handle, in_buffer, &node); |
| 265 | if (ACPI_FAILURE(status)) { |
| 266 | return_ACPI_STATUS(status); |
| 267 | } |
| 268 | |
| 269 | status = acpi_rs_set_srs_method_data(node, in_buffer); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 270 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 273 | ACPI_EXPORT_SYMBOL(acpi_set_current_resources) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | |
Bob Moore | a91cdde | 2011-11-16 14:46:57 +0800 | [diff] [blame] | 275 | /******************************************************************************* |
| 276 | * |
| 277 | * FUNCTION: acpi_get_event_resources |
| 278 | * |
| 279 | * PARAMETERS: device_handle - Handle to the device object for the |
| 280 | * device we are getting resources |
| 281 | * in_buffer - Pointer to a buffer containing the |
| 282 | * resources to be set for the device |
| 283 | * |
| 284 | * RETURN: Status |
| 285 | * |
| 286 | * DESCRIPTION: This function is called to get the event resources for a |
| 287 | * specific device. The caller must first acquire a handle for |
| 288 | * the desired device. The resource data is passed to the routine |
| 289 | * the buffer pointed to by the in_buffer variable. Uses the |
| 290 | * _AEI method. |
| 291 | * |
| 292 | ******************************************************************************/ |
| 293 | acpi_status |
| 294 | acpi_get_event_resources(acpi_handle device_handle, |
| 295 | struct acpi_buffer *ret_buffer) |
| 296 | { |
| 297 | acpi_status status; |
| 298 | struct acpi_namespace_node *node; |
| 299 | |
| 300 | ACPI_FUNCTION_TRACE(acpi_get_event_resources); |
| 301 | |
| 302 | /* Validate parameters then dispatch to internal routine */ |
| 303 | |
| 304 | status = acpi_rs_validate_parameters(device_handle, ret_buffer, &node); |
| 305 | if (ACPI_FAILURE(status)) { |
| 306 | return_ACPI_STATUS(status); |
| 307 | } |
| 308 | |
| 309 | status = acpi_rs_get_aei_method_data(node, ret_buffer); |
| 310 | return_ACPI_STATUS(status); |
| 311 | } |
| 312 | |
| 313 | ACPI_EXPORT_SYMBOL(acpi_get_event_resources) |
| 314 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | /****************************************************************************** |
| 316 | * |
| 317 | * FUNCTION: acpi_resource_to_address64 |
| 318 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 319 | * PARAMETERS: resource - Pointer to a resource |
| 320 | * out - Pointer to the users's return buffer |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 321 | * (a struct acpi_resource_address64) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | * |
| 323 | * RETURN: Status |
| 324 | * |
| 325 | * DESCRIPTION: If the resource is an address16, address32, or address64, |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 326 | * copy it to the address64 return buffer. This saves the |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | * caller from having to duplicate code for different-sized |
| 328 | * addresses. |
| 329 | * |
| 330 | ******************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 332 | acpi_resource_to_address64(struct acpi_resource *resource, |
| 333 | struct acpi_resource_address64 *out) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 335 | struct acpi_resource_address16 *address16; |
| 336 | struct acpi_resource_address32 *address32; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 338 | if (!resource || !out) { |
| 339 | return (AE_BAD_PARAMETER); |
| 340 | } |
| 341 | |
| 342 | /* Convert 16 or 32 address descriptor to 64 */ |
| 343 | |
Robert Moore | bda663d | 2005-09-16 16:51:15 -0400 | [diff] [blame] | 344 | switch (resource->type) { |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 345 | case ACPI_RESOURCE_TYPE_ADDRESS16: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | |
Bob Moore | ba9c3f5 | 2009-04-22 13:13:48 +0800 | [diff] [blame] | 347 | address16 = |
| 348 | ACPI_CAST_PTR(struct acpi_resource_address16, |
| 349 | &resource->data); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 350 | ACPI_COPY_ADDRESS(out, address16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | break; |
| 352 | |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 353 | case ACPI_RESOURCE_TYPE_ADDRESS32: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | |
Bob Moore | ba9c3f5 | 2009-04-22 13:13:48 +0800 | [diff] [blame] | 355 | address32 = |
| 356 | ACPI_CAST_PTR(struct acpi_resource_address32, |
| 357 | &resource->data); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 358 | ACPI_COPY_ADDRESS(out, address32); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | break; |
| 360 | |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 361 | case ACPI_RESOURCE_TYPE_ADDRESS64: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | |
| 363 | /* Simple copy for 64 bit source */ |
| 364 | |
Bob Moore | 4fa4616 | 2015-07-01 14:45:11 +0800 | [diff] [blame] | 365 | memcpy(out, &resource->data, |
| 366 | sizeof(struct acpi_resource_address64)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | break; |
| 368 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | default: |
Chao Guan | 1d1ea1b | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 370 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | return (AE_BAD_PARAMETER); |
| 372 | } |
| 373 | |
| 374 | return (AE_OK); |
| 375 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 376 | |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 377 | ACPI_EXPORT_SYMBOL(acpi_resource_to_address64) |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 378 | |
| 379 | /******************************************************************************* |
| 380 | * |
| 381 | * FUNCTION: acpi_get_vendor_resource |
| 382 | * |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 383 | * PARAMETERS: device_handle - Handle for the parent device object |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 384 | * name - Method name for the parent resource |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 385 | * (METHOD_NAME__CRS or METHOD_NAME__PRS) |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 386 | * uuid - Pointer to the UUID to be matched. |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 387 | * includes both subtype and 16-byte UUID |
| 388 | * ret_buffer - Where the vendor resource is returned |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 389 | * |
| 390 | * RETURN: Status |
| 391 | * |
Bob Moore | afb1bbe | 2012-12-31 00:03:58 +0000 | [diff] [blame] | 392 | * DESCRIPTION: Walk a resource template for the specified device to find a |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 393 | * vendor-defined resource that matches the supplied UUID and |
| 394 | * UUID subtype. Returns a struct acpi_resource of type Vendor. |
| 395 | * |
| 396 | ******************************************************************************/ |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 397 | acpi_status |
| 398 | acpi_get_vendor_resource(acpi_handle device_handle, |
| 399 | char *name, |
Lv Zheng | f5c1e1c | 2016-05-05 12:57:53 +0800 | [diff] [blame] | 400 | struct acpi_vendor_uuid *uuid, |
| 401 | struct acpi_buffer *ret_buffer) |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 402 | { |
| 403 | struct acpi_vendor_walk_info info; |
| 404 | acpi_status status; |
| 405 | |
| 406 | /* Other parameters are validated by acpi_walk_resources */ |
| 407 | |
| 408 | if (!uuid || !ret_buffer) { |
| 409 | return (AE_BAD_PARAMETER); |
| 410 | } |
| 411 | |
| 412 | info.uuid = uuid; |
| 413 | info.buffer = ret_buffer; |
| 414 | info.status = AE_NOT_EXIST; |
| 415 | |
| 416 | /* Walk the _CRS or _PRS resource list for this device */ |
| 417 | |
| 418 | status = |
| 419 | acpi_walk_resources(device_handle, name, |
| 420 | acpi_rs_match_vendor_resource, &info); |
| 421 | if (ACPI_FAILURE(status)) { |
| 422 | return (status); |
| 423 | } |
| 424 | |
| 425 | return (info.status); |
| 426 | } |
| 427 | |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 428 | ACPI_EXPORT_SYMBOL(acpi_get_vendor_resource) |
| 429 | |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 430 | /******************************************************************************* |
| 431 | * |
| 432 | * FUNCTION: acpi_rs_match_vendor_resource |
| 433 | * |
Bob Moore | 61686124 | 2006-03-17 16:44:00 -0500 | [diff] [blame] | 434 | * PARAMETERS: acpi_walk_resource_callback |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 435 | * |
| 436 | * RETURN: Status |
| 437 | * |
| 438 | * DESCRIPTION: Match a vendor resource via the ACPI 3.0 UUID |
| 439 | * |
| 440 | ******************************************************************************/ |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 441 | static acpi_status |
| 442 | acpi_rs_match_vendor_resource(struct acpi_resource *resource, void *context) |
| 443 | { |
| 444 | struct acpi_vendor_walk_info *info = context; |
| 445 | struct acpi_resource_vendor_typed *vendor; |
| 446 | struct acpi_buffer *buffer; |
| 447 | acpi_status status; |
| 448 | |
| 449 | /* Ignore all descriptors except Vendor */ |
| 450 | |
| 451 | if (resource->type != ACPI_RESOURCE_TYPE_VENDOR) { |
| 452 | return (AE_OK); |
| 453 | } |
| 454 | |
| 455 | vendor = &resource->data.vendor_typed; |
| 456 | |
| 457 | /* |
| 458 | * For a valid match, these conditions must hold: |
| 459 | * |
| 460 | * 1) Length of descriptor data must be at least as long as a UUID struct |
| 461 | * 2) The UUID subtypes must match |
| 462 | * 3) The UUID data must match |
| 463 | */ |
| 464 | if ((vendor->byte_length < (ACPI_UUID_LENGTH + 1)) || |
| 465 | (vendor->uuid_subtype != info->uuid->subtype) || |
Bob Moore | 4fa4616 | 2015-07-01 14:45:11 +0800 | [diff] [blame] | 466 | (memcmp(vendor->uuid, info->uuid->data, ACPI_UUID_LENGTH))) { |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 467 | return (AE_OK); |
| 468 | } |
| 469 | |
| 470 | /* Validate/Allocate/Clear caller buffer */ |
| 471 | |
| 472 | buffer = info->buffer; |
| 473 | status = acpi_ut_initialize_buffer(buffer, resource->length); |
| 474 | if (ACPI_FAILURE(status)) { |
| 475 | return (status); |
| 476 | } |
| 477 | |
| 478 | /* Found the correct resource, copy and return it */ |
| 479 | |
Bob Moore | 4fa4616 | 2015-07-01 14:45:11 +0800 | [diff] [blame] | 480 | memcpy(buffer->pointer, resource, resource->length); |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 481 | buffer->length = resource->length; |
| 482 | |
| 483 | /* Found the desired descriptor, terminate resource walk */ |
| 484 | |
| 485 | info->status = AE_OK; |
| 486 | return (AE_CTRL_TERMINATE); |
| 487 | } |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 488 | |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 489 | /******************************************************************************* |
| 490 | * |
Bob Moore | afb1bbe | 2012-12-31 00:03:58 +0000 | [diff] [blame] | 491 | * FUNCTION: acpi_walk_resource_buffer |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 492 | * |
Bob Moore | afb1bbe | 2012-12-31 00:03:58 +0000 | [diff] [blame] | 493 | * PARAMETERS: buffer - Formatted buffer returned by one of the |
| 494 | * various Get*Resource functions |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 495 | * user_function - Called for each resource |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 496 | * context - Passed to user_function |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 497 | * |
| 498 | * RETURN: Status |
| 499 | * |
Bob Moore | afb1bbe | 2012-12-31 00:03:58 +0000 | [diff] [blame] | 500 | * DESCRIPTION: Walks the input resource template. The user_function is called |
| 501 | * once for each resource in the list. |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 502 | * |
| 503 | ******************************************************************************/ |
Bob Moore | afb1bbe | 2012-12-31 00:03:58 +0000 | [diff] [blame] | 504 | |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 505 | acpi_status |
Lv Zheng | f5c1e1c | 2016-05-05 12:57:53 +0800 | [diff] [blame] | 506 | acpi_walk_resource_buffer(struct acpi_buffer *buffer, |
Bob Moore | afb1bbe | 2012-12-31 00:03:58 +0000 | [diff] [blame] | 507 | acpi_walk_resource_callback user_function, |
| 508 | void *context) |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 509 | { |
Bob Moore | afb1bbe | 2012-12-31 00:03:58 +0000 | [diff] [blame] | 510 | acpi_status status = AE_OK; |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 511 | struct acpi_resource *resource; |
| 512 | struct acpi_resource *resource_end; |
| 513 | |
Bob Moore | afb1bbe | 2012-12-31 00:03:58 +0000 | [diff] [blame] | 514 | ACPI_FUNCTION_TRACE(acpi_walk_resource_buffer); |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 515 | |
| 516 | /* Parameter validation */ |
| 517 | |
Bob Moore | afb1bbe | 2012-12-31 00:03:58 +0000 | [diff] [blame] | 518 | if (!buffer || !buffer->pointer || !user_function) { |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 519 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
| 520 | } |
| 521 | |
Bob Moore | afb1bbe | 2012-12-31 00:03:58 +0000 | [diff] [blame] | 522 | /* Buffer contains the resource list and length */ |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 523 | |
Bob Moore | afb1bbe | 2012-12-31 00:03:58 +0000 | [diff] [blame] | 524 | resource = ACPI_CAST_PTR(struct acpi_resource, buffer->pointer); |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 525 | resource_end = |
Bob Moore | afb1bbe | 2012-12-31 00:03:58 +0000 | [diff] [blame] | 526 | ACPI_ADD_PTR(struct acpi_resource, buffer->pointer, buffer->length); |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 527 | |
| 528 | /* Walk the resource list until the end_tag is found (or buffer end) */ |
| 529 | |
| 530 | while (resource < resource_end) { |
| 531 | |
Bob Moore | c13085e | 2013-03-08 09:19:38 +0000 | [diff] [blame] | 532 | /* Sanity check the resource type */ |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 533 | |
| 534 | if (resource->type > ACPI_RESOURCE_TYPE_MAX) { |
| 535 | status = AE_AML_INVALID_RESOURCE_TYPE; |
| 536 | break; |
| 537 | } |
| 538 | |
Bob Moore | c13085e | 2013-03-08 09:19:38 +0000 | [diff] [blame] | 539 | /* Sanity check the length. It must not be zero, or we loop forever */ |
| 540 | |
| 541 | if (!resource->length) { |
| 542 | return_ACPI_STATUS(AE_AML_BAD_RESOURCE_LENGTH); |
| 543 | } |
| 544 | |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 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 | |
Lv Zheng | fb4e502 | 2012-12-19 05:38:31 +0000 | [diff] [blame] | 566 | resource = ACPI_NEXT_RESOURCE(resource); |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 567 | } |
| 568 | |
Bob Moore | afb1bbe | 2012-12-31 00:03:58 +0000 | [diff] [blame] | 569 | return_ACPI_STATUS(status); |
| 570 | } |
| 571 | |
| 572 | ACPI_EXPORT_SYMBOL(acpi_walk_resource_buffer) |
| 573 | |
| 574 | /******************************************************************************* |
| 575 | * |
| 576 | * FUNCTION: acpi_walk_resources |
| 577 | * |
| 578 | * PARAMETERS: device_handle - Handle to the device object for the |
| 579 | * device we are querying |
| 580 | * name - Method name of the resources we want. |
| 581 | * (METHOD_NAME__CRS, METHOD_NAME__PRS, or |
Bob Moore | 137c783 | 2017-08-03 14:27:35 +0800 | [diff] [blame] | 582 | * METHOD_NAME__AEI or METHOD_NAME__DMA) |
Bob Moore | afb1bbe | 2012-12-31 00:03:58 +0000 | [diff] [blame] | 583 | * user_function - Called for each resource |
| 584 | * context - Passed to user_function |
| 585 | * |
| 586 | * RETURN: Status |
| 587 | * |
| 588 | * DESCRIPTION: Retrieves the current or possible resource list for the |
| 589 | * specified device. The user_function is called once for |
| 590 | * each resource in the list. |
| 591 | * |
| 592 | ******************************************************************************/ |
| 593 | acpi_status |
| 594 | acpi_walk_resources(acpi_handle device_handle, |
| 595 | char *name, |
| 596 | acpi_walk_resource_callback user_function, void *context) |
| 597 | { |
| 598 | acpi_status status; |
| 599 | struct acpi_buffer buffer; |
| 600 | |
| 601 | ACPI_FUNCTION_TRACE(acpi_walk_resources); |
| 602 | |
| 603 | /* Parameter validation */ |
| 604 | |
| 605 | if (!device_handle || !user_function || !name || |
| 606 | (!ACPI_COMPARE_NAME(name, METHOD_NAME__CRS) && |
| 607 | !ACPI_COMPARE_NAME(name, METHOD_NAME__PRS) && |
Bob Moore | 137c783 | 2017-08-03 14:27:35 +0800 | [diff] [blame] | 608 | !ACPI_COMPARE_NAME(name, METHOD_NAME__AEI) && |
| 609 | !ACPI_COMPARE_NAME(name, METHOD_NAME__DMA))) { |
Bob Moore | afb1bbe | 2012-12-31 00:03:58 +0000 | [diff] [blame] | 610 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
| 611 | } |
| 612 | |
Bob Moore | 137c783 | 2017-08-03 14:27:35 +0800 | [diff] [blame] | 613 | /* Get the _CRS/_PRS/_AEI/_DMA resource list */ |
Bob Moore | afb1bbe | 2012-12-31 00:03:58 +0000 | [diff] [blame] | 614 | |
| 615 | buffer.length = ACPI_ALLOCATE_LOCAL_BUFFER; |
| 616 | status = acpi_rs_get_method_data(device_handle, name, &buffer); |
| 617 | if (ACPI_FAILURE(status)) { |
| 618 | return_ACPI_STATUS(status); |
| 619 | } |
| 620 | |
| 621 | /* Walk the resource list and cleanup */ |
| 622 | |
| 623 | status = acpi_walk_resource_buffer(&buffer, user_function, context); |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 624 | ACPI_FREE(buffer.pointer); |
| 625 | return_ACPI_STATUS(status); |
| 626 | } |
| 627 | |
| 628 | ACPI_EXPORT_SYMBOL(acpi_walk_resources) |