Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | * |
| 3 | * Module Name: rsxface - Public interfaces to the resource manager |
| 4 | * |
| 5 | ******************************************************************************/ |
| 6 | |
| 7 | /* |
Bob Moore | 4a90c7e | 2006-01-13 16:22:00 -0500 | [diff] [blame] | 8 | * Copyright (C) 2000 - 2006, R. Byron Moore |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | * 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 | |
| 44 | #include <linux/module.h> |
| 45 | |
| 46 | #include <acpi/acpi.h> |
| 47 | #include <acpi/acresrc.h> |
| 48 | |
| 49 | #define _COMPONENT ACPI_RESOURCES |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 50 | ACPI_MODULE_NAME("rsxface") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 52 | /* Local macros for 16,32-bit to 64-bit conversion */ |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 53 | #define ACPI_COPY_FIELD(out, in, field) ((out)->field = (in)->field) |
| 54 | #define ACPI_COPY_ADDRESS(out, in) \ |
| 55 | ACPI_COPY_FIELD(out, in, resource_type); \ |
| 56 | ACPI_COPY_FIELD(out, in, producer_consumer); \ |
| 57 | ACPI_COPY_FIELD(out, in, decode); \ |
| 58 | ACPI_COPY_FIELD(out, in, min_address_fixed); \ |
| 59 | ACPI_COPY_FIELD(out, in, max_address_fixed); \ |
Bob Moore | 0897831 | 2005-10-21 00:00:00 -0400 | [diff] [blame] | 60 | ACPI_COPY_FIELD(out, in, info); \ |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 61 | ACPI_COPY_FIELD(out, in, granularity); \ |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 62 | ACPI_COPY_FIELD(out, in, minimum); \ |
| 63 | ACPI_COPY_FIELD(out, in, maximum); \ |
| 64 | ACPI_COPY_FIELD(out, in, translation_offset); \ |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 65 | ACPI_COPY_FIELD(out, in, address_length); \ |
| 66 | ACPI_COPY_FIELD(out, in, resource_source); |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 67 | /* Local prototypes */ |
| 68 | static acpi_status |
| 69 | acpi_rs_match_vendor_resource(struct acpi_resource *resource, void *context); |
| 70 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | /******************************************************************************* |
| 72 | * |
| 73 | * FUNCTION: acpi_get_irq_routing_table |
| 74 | * |
| 75 | * PARAMETERS: device_handle - a handle to the Bus device we are querying |
| 76 | * ret_buffer - a pointer to a buffer to receive the |
| 77 | * current resources for the device |
| 78 | * |
| 79 | * RETURN: Status |
| 80 | * |
| 81 | * DESCRIPTION: This function is called to get the IRQ routing table for a |
| 82 | * specific bus. The caller must first acquire a handle for the |
| 83 | * desired bus. The routine table is placed in the buffer pointed |
| 84 | * to by the ret_buffer variable parameter. |
| 85 | * |
| 86 | * If the function fails an appropriate status will be returned |
| 87 | * and the value of ret_buffer is undefined. |
| 88 | * |
| 89 | * This function attempts to execute the _PRT method contained in |
| 90 | * the object indicated by the passed device_handle. |
| 91 | * |
| 92 | ******************************************************************************/ |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 93 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 95 | acpi_get_irq_routing_table(acpi_handle device_handle, |
| 96 | struct acpi_buffer *ret_buffer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 98 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 100 | ACPI_FUNCTION_TRACE("acpi_get_irq_routing_table "); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | |
| 102 | /* |
| 103 | * Must have a valid handle and buffer, So we have to have a handle |
| 104 | * and a return buffer structure, and if there is a non-zero buffer length |
| 105 | * we also need a valid pointer in the buffer. If it's a zero buffer length, |
| 106 | * we'll be returning the needed buffer size, so keep going. |
| 107 | */ |
| 108 | if (!device_handle) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 109 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | } |
| 111 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 112 | status = acpi_ut_validate_buffer(ret_buffer); |
| 113 | if (ACPI_FAILURE(status)) { |
| 114 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | } |
| 116 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 117 | status = acpi_rs_get_prt_method_data(device_handle, ret_buffer); |
| 118 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | } |
| 120 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | /******************************************************************************* |
| 122 | * |
| 123 | * FUNCTION: acpi_get_current_resources |
| 124 | * |
| 125 | * PARAMETERS: device_handle - a handle to the device object for the |
| 126 | * device we are querying |
| 127 | * ret_buffer - a pointer to a buffer to receive the |
| 128 | * current resources for the device |
| 129 | * |
| 130 | * RETURN: Status |
| 131 | * |
| 132 | * DESCRIPTION: This function is called to get the current resources for a |
| 133 | * specific device. The caller must first acquire a handle for |
| 134 | * the desired device. The resource data is placed in the buffer |
| 135 | * pointed to by the ret_buffer variable parameter. |
| 136 | * |
| 137 | * If the function fails an appropriate status will be returned |
| 138 | * and the value of ret_buffer is undefined. |
| 139 | * |
| 140 | * This function attempts to execute the _CRS method contained in |
| 141 | * the object indicated by the passed device_handle. |
| 142 | * |
| 143 | ******************************************************************************/ |
| 144 | |
| 145 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 146 | acpi_get_current_resources(acpi_handle device_handle, |
| 147 | struct acpi_buffer *ret_buffer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 149 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 151 | ACPI_FUNCTION_TRACE("acpi_get_current_resources"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | |
| 153 | /* |
| 154 | * Must have a valid handle and buffer, So we have to have a handle |
| 155 | * and a return buffer structure, and if there is a non-zero buffer length |
| 156 | * we also need a valid pointer in the buffer. If it's a zero buffer length, |
| 157 | * we'll be returning the needed buffer size, so keep going. |
| 158 | */ |
| 159 | if (!device_handle) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 160 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | } |
| 162 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 163 | status = acpi_ut_validate_buffer(ret_buffer); |
| 164 | if (ACPI_FAILURE(status)) { |
| 165 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | } |
| 167 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 168 | status = acpi_rs_get_crs_method_data(device_handle, ret_buffer); |
| 169 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 172 | EXPORT_SYMBOL(acpi_get_current_resources); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | |
| 174 | /******************************************************************************* |
| 175 | * |
| 176 | * FUNCTION: acpi_get_possible_resources |
| 177 | * |
| 178 | * PARAMETERS: device_handle - a handle to the device object for the |
| 179 | * device we are querying |
| 180 | * ret_buffer - a pointer to a buffer to receive the |
| 181 | * resources for the device |
| 182 | * |
| 183 | * RETURN: Status |
| 184 | * |
| 185 | * 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 |
| 187 | * for the desired device. The resource data is placed in the |
| 188 | * buffer pointed to by the ret_buffer variable. |
| 189 | * |
| 190 | * If the function fails an appropriate status will be returned |
| 191 | * and the value of ret_buffer is undefined. |
| 192 | * |
| 193 | ******************************************************************************/ |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 194 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | #ifdef ACPI_FUTURE_USAGE |
| 196 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 197 | acpi_get_possible_resources(acpi_handle device_handle, |
| 198 | struct acpi_buffer *ret_buffer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 200 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 202 | ACPI_FUNCTION_TRACE("acpi_get_possible_resources"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | |
| 204 | /* |
| 205 | * Must have a valid handle and buffer, So we have to have a handle |
| 206 | * and a return buffer structure, and if there is a non-zero buffer length |
| 207 | * we also need a valid pointer in the buffer. If it's a zero buffer length, |
| 208 | * we'll be returning the needed buffer size, so keep going. |
| 209 | */ |
| 210 | if (!device_handle) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 211 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | } |
| 213 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 214 | status = acpi_ut_validate_buffer(ret_buffer); |
| 215 | if (ACPI_FAILURE(status)) { |
| 216 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | } |
| 218 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 219 | status = acpi_rs_get_prs_method_data(device_handle, ret_buffer); |
| 220 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 223 | EXPORT_SYMBOL(acpi_get_possible_resources); |
| 224 | #endif /* ACPI_FUTURE_USAGE */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | |
| 226 | /******************************************************************************* |
| 227 | * |
| 228 | * FUNCTION: acpi_walk_resources |
| 229 | * |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 230 | * PARAMETERS: device_handle - Handle to the device object for the |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | * device we are querying |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 232 | * Name - Method name of the resources we want |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | * (METHOD_NAME__CRS or METHOD_NAME__PRS) |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 234 | * user_function - Called for each resource |
| 235 | * Context - Passed to user_function |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | * |
| 237 | * RETURN: Status |
| 238 | * |
| 239 | * DESCRIPTION: Retrieves the current or possible resource list for the |
| 240 | * specified device. The user_function is called once for |
| 241 | * each resource in the list. |
| 242 | * |
| 243 | ******************************************************************************/ |
| 244 | |
| 245 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 246 | acpi_walk_resources(acpi_handle device_handle, |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 247 | char *name, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 248 | ACPI_WALK_RESOURCE_CALLBACK user_function, void *context) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 250 | acpi_status status; |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 251 | struct acpi_buffer buffer; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 252 | struct acpi_resource *resource; |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 253 | struct acpi_resource *resource_end; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 255 | ACPI_FUNCTION_TRACE("acpi_walk_resources"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 257 | /* Parameter validation */ |
| 258 | |
| 259 | if (!device_handle || !user_function || !name || |
| 260 | (ACPI_STRNCMP(name, METHOD_NAME__CRS, sizeof(METHOD_NAME__CRS)) && |
| 261 | ACPI_STRNCMP(name, METHOD_NAME__PRS, sizeof(METHOD_NAME__PRS)))) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 262 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | } |
| 264 | |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 265 | /* Get the _CRS or _PRS resource list */ |
| 266 | |
| 267 | buffer.length = ACPI_ALLOCATE_LOCAL_BUFFER; |
| 268 | status = acpi_rs_get_method_data(device_handle, name, &buffer); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 269 | if (ACPI_FAILURE(status)) { |
| 270 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | } |
| 272 | |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 273 | /* Buffer now contains the resource list */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 275 | resource = ACPI_CAST_PTR(struct acpi_resource, buffer.pointer); |
| 276 | resource_end = |
| 277 | ACPI_ADD_PTR(struct acpi_resource, buffer.pointer, buffer.length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 279 | /* Walk the resource list until the end_tag is found (or buffer end) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 281 | while (resource < resource_end) { |
| 282 | /* Sanity check the resource */ |
| 283 | |
| 284 | if (resource->type > ACPI_RESOURCE_TYPE_MAX) { |
| 285 | status = AE_AML_INVALID_RESOURCE_TYPE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | break; |
| 287 | } |
| 288 | |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 289 | /* Invoke the user function, abort on any error returned */ |
| 290 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 291 | status = user_function(resource, context); |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 292 | if (ACPI_FAILURE(status)) { |
| 293 | if (status == AE_CTRL_TERMINATE) { |
| 294 | /* This is an OK termination by the user function */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 296 | status = AE_OK; |
| 297 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | break; |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 299 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | |
Len Brown | 2ae4117 | 2006-01-16 15:22:45 -0500 | [diff] [blame] | 301 | /* end_tag indicates end-of-list */ |
| 302 | |
| 303 | if (resource->type == ACPI_RESOURCE_TYPE_END_TAG) { |
| 304 | break; |
| 305 | } |
| 306 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | /* Get the next resource descriptor */ |
| 308 | |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 309 | resource = |
| 310 | ACPI_ADD_PTR(struct acpi_resource, resource, |
| 311 | resource->length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | } |
| 313 | |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 314 | ACPI_MEM_FREE(buffer.pointer); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 315 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 318 | EXPORT_SYMBOL(acpi_walk_resources); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | |
| 320 | /******************************************************************************* |
| 321 | * |
| 322 | * FUNCTION: acpi_set_current_resources |
| 323 | * |
| 324 | * PARAMETERS: device_handle - a handle to the device object for the |
| 325 | * device we are changing the resources of |
| 326 | * in_buffer - a pointer to a buffer containing the |
| 327 | * resources to be set for the device |
| 328 | * |
| 329 | * RETURN: Status |
| 330 | * |
| 331 | * DESCRIPTION: This function is called to set the current resources for a |
| 332 | * specific device. The caller must first acquire a handle for |
| 333 | * the desired device. The resource data is passed to the routine |
| 334 | * the buffer pointed to by the in_buffer variable. |
| 335 | * |
| 336 | ******************************************************************************/ |
| 337 | |
| 338 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 339 | acpi_set_current_resources(acpi_handle device_handle, |
| 340 | struct acpi_buffer *in_buffer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 342 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 344 | ACPI_FUNCTION_TRACE("acpi_set_current_resources"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 346 | /* Must have a valid handle and buffer */ |
| 347 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 348 | if ((!device_handle) || |
| 349 | (!in_buffer) || (!in_buffer->pointer) || (!in_buffer->length)) { |
| 350 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | } |
| 352 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 353 | status = acpi_rs_set_srs_method_data(device_handle, in_buffer); |
| 354 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 357 | EXPORT_SYMBOL(acpi_set_current_resources); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | /****************************************************************************** |
| 360 | * |
| 361 | * FUNCTION: acpi_resource_to_address64 |
| 362 | * |
Robert Moore | bda663d | 2005-09-16 16:51:15 -0400 | [diff] [blame] | 363 | * PARAMETERS: Resource - Pointer to a resource |
| 364 | * Out - Pointer to the users's return |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | * buffer (a struct |
| 366 | * struct acpi_resource_address64) |
| 367 | * |
| 368 | * RETURN: Status |
| 369 | * |
| 370 | * DESCRIPTION: If the resource is an address16, address32, or address64, |
| 371 | * copy it to the address64 return buffer. This saves the |
| 372 | * caller from having to duplicate code for different-sized |
| 373 | * addresses. |
| 374 | * |
| 375 | ******************************************************************************/ |
| 376 | |
| 377 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 378 | acpi_resource_to_address64(struct acpi_resource *resource, |
| 379 | struct acpi_resource_address64 *out) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 381 | struct acpi_resource_address16 *address16; |
| 382 | struct acpi_resource_address32 *address32; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 384 | if (!resource || !out) { |
| 385 | return (AE_BAD_PARAMETER); |
| 386 | } |
| 387 | |
| 388 | /* Convert 16 or 32 address descriptor to 64 */ |
| 389 | |
Robert Moore | bda663d | 2005-09-16 16:51:15 -0400 | [diff] [blame] | 390 | switch (resource->type) { |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 391 | case ACPI_RESOURCE_TYPE_ADDRESS16: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 393 | address16 = (struct acpi_resource_address16 *)&resource->data; |
| 394 | ACPI_COPY_ADDRESS(out, address16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | break; |
| 396 | |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 397 | case ACPI_RESOURCE_TYPE_ADDRESS32: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 399 | address32 = (struct acpi_resource_address32 *)&resource->data; |
| 400 | ACPI_COPY_ADDRESS(out, address32); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | break; |
| 402 | |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 403 | case ACPI_RESOURCE_TYPE_ADDRESS64: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | |
| 405 | /* Simple copy for 64 bit source */ |
| 406 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 407 | ACPI_MEMCPY(out, &resource->data, |
| 408 | sizeof(struct acpi_resource_address64)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | break; |
| 410 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | default: |
| 412 | return (AE_BAD_PARAMETER); |
| 413 | } |
| 414 | |
| 415 | return (AE_OK); |
| 416 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 417 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | EXPORT_SYMBOL(acpi_resource_to_address64); |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 419 | |
| 420 | /******************************************************************************* |
| 421 | * |
| 422 | * FUNCTION: acpi_get_vendor_resource |
| 423 | * |
| 424 | * PARAMETERS: device_handle - Handle for the parent device object |
| 425 | * Name - Method name for the parent resource |
| 426 | * (METHOD_NAME__CRS or METHOD_NAME__PRS) |
| 427 | * Uuid - Pointer to the UUID to be matched. |
| 428 | * includes both subtype and 16-byte UUID |
| 429 | * ret_buffer - Where the vendor resource is returned |
| 430 | * |
| 431 | * RETURN: Status |
| 432 | * |
| 433 | * DESCRIPTION: Walk a resource template for the specified evice to find a |
| 434 | * vendor-defined resource that matches the supplied UUID and |
| 435 | * UUID subtype. Returns a struct acpi_resource of type Vendor. |
| 436 | * |
| 437 | ******************************************************************************/ |
| 438 | |
| 439 | acpi_status |
| 440 | acpi_get_vendor_resource(acpi_handle device_handle, |
| 441 | char *name, |
| 442 | struct acpi_vendor_uuid * uuid, |
| 443 | struct acpi_buffer * ret_buffer) |
| 444 | { |
| 445 | struct acpi_vendor_walk_info info; |
| 446 | acpi_status status; |
| 447 | |
| 448 | /* Other parameters are validated by acpi_walk_resources */ |
| 449 | |
| 450 | if (!uuid || !ret_buffer) { |
| 451 | return (AE_BAD_PARAMETER); |
| 452 | } |
| 453 | |
| 454 | info.uuid = uuid; |
| 455 | info.buffer = ret_buffer; |
| 456 | info.status = AE_NOT_EXIST; |
| 457 | |
| 458 | /* Walk the _CRS or _PRS resource list for this device */ |
| 459 | |
| 460 | status = |
| 461 | acpi_walk_resources(device_handle, name, |
| 462 | acpi_rs_match_vendor_resource, &info); |
| 463 | if (ACPI_FAILURE(status)) { |
| 464 | return (status); |
| 465 | } |
| 466 | |
| 467 | return (info.status); |
| 468 | } |
| 469 | |
| 470 | /******************************************************************************* |
| 471 | * |
| 472 | * FUNCTION: acpi_rs_match_vendor_resource |
| 473 | * |
| 474 | * PARAMETERS: ACPI_WALK_RESOURCE_CALLBACK |
| 475 | * |
| 476 | * RETURN: Status |
| 477 | * |
| 478 | * DESCRIPTION: Match a vendor resource via the ACPI 3.0 UUID |
| 479 | * |
| 480 | ******************************************************************************/ |
| 481 | |
| 482 | static acpi_status |
| 483 | acpi_rs_match_vendor_resource(struct acpi_resource *resource, void *context) |
| 484 | { |
| 485 | struct acpi_vendor_walk_info *info = context; |
| 486 | struct acpi_resource_vendor_typed *vendor; |
| 487 | struct acpi_buffer *buffer; |
| 488 | acpi_status status; |
| 489 | |
| 490 | /* Ignore all descriptors except Vendor */ |
| 491 | |
| 492 | if (resource->type != ACPI_RESOURCE_TYPE_VENDOR) { |
| 493 | return (AE_OK); |
| 494 | } |
| 495 | |
| 496 | vendor = &resource->data.vendor_typed; |
| 497 | |
| 498 | /* |
| 499 | * For a valid match, these conditions must hold: |
| 500 | * |
| 501 | * 1) Length of descriptor data must be at least as long as a UUID struct |
| 502 | * 2) The UUID subtypes must match |
| 503 | * 3) The UUID data must match |
| 504 | */ |
| 505 | if ((vendor->byte_length < (ACPI_UUID_LENGTH + 1)) || |
| 506 | (vendor->uuid_subtype != info->uuid->subtype) || |
| 507 | (ACPI_MEMCMP(vendor->uuid, info->uuid->data, ACPI_UUID_LENGTH))) { |
| 508 | return (AE_OK); |
| 509 | } |
| 510 | |
| 511 | /* Validate/Allocate/Clear caller buffer */ |
| 512 | |
| 513 | buffer = info->buffer; |
| 514 | status = acpi_ut_initialize_buffer(buffer, resource->length); |
| 515 | if (ACPI_FAILURE(status)) { |
| 516 | return (status); |
| 517 | } |
| 518 | |
| 519 | /* Found the correct resource, copy and return it */ |
| 520 | |
| 521 | ACPI_MEMCPY(buffer->pointer, resource, resource->length); |
| 522 | buffer->length = resource->length; |
| 523 | |
| 524 | /* Found the desired descriptor, terminate resource walk */ |
| 525 | |
| 526 | info->status = AE_OK; |
| 527 | return (AE_CTRL_TERMINATE); |
| 528 | } |