| 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 | /* | 
|  | 8 | * Copyright (C) 2000 - 2005, R. Byron Moore | 
|  | 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 | 
|  | 50 | ACPI_MODULE_NAME    ("rsxface") | 
|  | 51 |  | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 52 | /* Local macros for 16,32-bit to 64-bit conversion */ | 
|  | 53 |  | 
|  | 54 | #define ACPI_COPY_FIELD(out, in, field)  ((out)->field = (in)->field) | 
|  | 55 | #define ACPI_COPY_ADDRESS(out, in)                      \ | 
|  | 56 | ACPI_COPY_FIELD(out, in, resource_type);             \ | 
|  | 57 | ACPI_COPY_FIELD(out, in, producer_consumer);         \ | 
|  | 58 | ACPI_COPY_FIELD(out, in, decode);                    \ | 
|  | 59 | ACPI_COPY_FIELD(out, in, min_address_fixed);         \ | 
|  | 60 | ACPI_COPY_FIELD(out, in, max_address_fixed);         \ | 
|  | 61 | ACPI_COPY_FIELD(out, in, attribute);                 \ | 
|  | 62 | ACPI_COPY_FIELD(out, in, granularity);               \ | 
|  | 63 | ACPI_COPY_FIELD(out, in, min_address_range);         \ | 
|  | 64 | ACPI_COPY_FIELD(out, in, max_address_range);         \ | 
|  | 65 | ACPI_COPY_FIELD(out, in, address_translation_offset); \ | 
|  | 66 | ACPI_COPY_FIELD(out, in, address_length);            \ | 
|  | 67 | ACPI_COPY_FIELD(out, in, resource_source); | 
|  | 68 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 |  | 
|  | 70 | /******************************************************************************* | 
|  | 71 | * | 
|  | 72 | * FUNCTION:    acpi_get_irq_routing_table | 
|  | 73 | * | 
|  | 74 | * PARAMETERS:  device_handle   - a handle to the Bus device we are querying | 
|  | 75 | *              ret_buffer      - a pointer to a buffer to receive the | 
|  | 76 | *                                current resources for the device | 
|  | 77 | * | 
|  | 78 | * RETURN:      Status | 
|  | 79 | * | 
|  | 80 | * DESCRIPTION: This function is called to get the IRQ routing table for a | 
|  | 81 | *              specific bus.  The caller must first acquire a handle for the | 
|  | 82 | *              desired bus.  The routine table is placed in the buffer pointed | 
|  | 83 | *              to by the ret_buffer variable parameter. | 
|  | 84 | * | 
|  | 85 | *              If the function fails an appropriate status will be returned | 
|  | 86 | *              and the value of ret_buffer is undefined. | 
|  | 87 | * | 
|  | 88 | *              This function attempts to execute the _PRT method contained in | 
|  | 89 | *              the object indicated by the passed device_handle. | 
|  | 90 | * | 
|  | 91 | ******************************************************************************/ | 
|  | 92 |  | 
|  | 93 | acpi_status | 
|  | 94 | acpi_get_irq_routing_table ( | 
|  | 95 | acpi_handle                     device_handle, | 
|  | 96 | struct acpi_buffer              *ret_buffer) | 
|  | 97 | { | 
|  | 98 | acpi_status                     status; | 
|  | 99 |  | 
|  | 100 |  | 
|  | 101 | ACPI_FUNCTION_TRACE ("acpi_get_irq_routing_table "); | 
|  | 102 |  | 
|  | 103 |  | 
|  | 104 | /* | 
|  | 105 | * Must have a valid handle and buffer, So we have to have a handle | 
|  | 106 | * and a return buffer structure, and if there is a non-zero buffer length | 
|  | 107 | * we also need a valid pointer in the buffer. If it's a zero buffer length, | 
|  | 108 | * we'll be returning the needed buffer size, so keep going. | 
|  | 109 | */ | 
|  | 110 | if (!device_handle) { | 
|  | 111 | return_ACPI_STATUS (AE_BAD_PARAMETER); | 
|  | 112 | } | 
|  | 113 |  | 
|  | 114 | status = acpi_ut_validate_buffer (ret_buffer); | 
|  | 115 | if (ACPI_FAILURE (status)) { | 
|  | 116 | return_ACPI_STATUS (status); | 
|  | 117 | } | 
|  | 118 |  | 
|  | 119 | status = acpi_rs_get_prt_method_data (device_handle, ret_buffer); | 
|  | 120 | return_ACPI_STATUS (status); | 
|  | 121 | } | 
|  | 122 |  | 
|  | 123 |  | 
|  | 124 | /******************************************************************************* | 
|  | 125 | * | 
|  | 126 | * FUNCTION:    acpi_get_current_resources | 
|  | 127 | * | 
|  | 128 | * PARAMETERS:  device_handle   - a handle to the device object for the | 
|  | 129 | *                                device we are querying | 
|  | 130 | *              ret_buffer      - a pointer to a buffer to receive the | 
|  | 131 | *                                current resources for the device | 
|  | 132 | * | 
|  | 133 | * RETURN:      Status | 
|  | 134 | * | 
|  | 135 | * DESCRIPTION: This function is called to get the current resources for a | 
|  | 136 | *              specific device.  The caller must first acquire a handle for | 
|  | 137 | *              the desired device.  The resource data is placed in the buffer | 
|  | 138 | *              pointed to by the ret_buffer variable parameter. | 
|  | 139 | * | 
|  | 140 | *              If the function fails an appropriate status will be returned | 
|  | 141 | *              and the value of ret_buffer is undefined. | 
|  | 142 | * | 
|  | 143 | *              This function attempts to execute the _CRS method contained in | 
|  | 144 | *              the object indicated by the passed device_handle. | 
|  | 145 | * | 
|  | 146 | ******************************************************************************/ | 
|  | 147 |  | 
|  | 148 | acpi_status | 
|  | 149 | acpi_get_current_resources ( | 
|  | 150 | acpi_handle                     device_handle, | 
|  | 151 | struct acpi_buffer              *ret_buffer) | 
|  | 152 | { | 
|  | 153 | acpi_status                     status; | 
|  | 154 |  | 
|  | 155 |  | 
|  | 156 | ACPI_FUNCTION_TRACE ("acpi_get_current_resources"); | 
|  | 157 |  | 
|  | 158 |  | 
|  | 159 | /* | 
|  | 160 | * Must have a valid handle and buffer, So we have to have a handle | 
|  | 161 | * and a return buffer structure, and if there is a non-zero buffer length | 
|  | 162 | * we also need a valid pointer in the buffer. If it's a zero buffer length, | 
|  | 163 | * we'll be returning the needed buffer size, so keep going. | 
|  | 164 | */ | 
|  | 165 | if (!device_handle) { | 
|  | 166 | return_ACPI_STATUS (AE_BAD_PARAMETER); | 
|  | 167 | } | 
|  | 168 |  | 
|  | 169 | status = acpi_ut_validate_buffer (ret_buffer); | 
|  | 170 | if (ACPI_FAILURE (status)) { | 
|  | 171 | return_ACPI_STATUS (status); | 
|  | 172 | } | 
|  | 173 |  | 
|  | 174 | status = acpi_rs_get_crs_method_data (device_handle, ret_buffer); | 
|  | 175 | return_ACPI_STATUS (status); | 
|  | 176 | } | 
|  | 177 | EXPORT_SYMBOL(acpi_get_current_resources); | 
|  | 178 |  | 
|  | 179 |  | 
|  | 180 | /******************************************************************************* | 
|  | 181 | * | 
|  | 182 | * FUNCTION:    acpi_get_possible_resources | 
|  | 183 | * | 
|  | 184 | * PARAMETERS:  device_handle   - a handle to the device object for the | 
|  | 185 | *                                device we are querying | 
|  | 186 | *              ret_buffer      - a pointer to a buffer to receive the | 
|  | 187 | *                                resources for the device | 
|  | 188 | * | 
|  | 189 | * RETURN:      Status | 
|  | 190 | * | 
|  | 191 | * DESCRIPTION: This function is called to get a list of the possible resources | 
|  | 192 | *              for a specific device.  The caller must first acquire a handle | 
|  | 193 | *              for the desired device.  The resource data is placed in the | 
|  | 194 | *              buffer pointed to by the ret_buffer variable. | 
|  | 195 | * | 
|  | 196 | *              If the function fails an appropriate status will be returned | 
|  | 197 | *              and the value of ret_buffer is undefined. | 
|  | 198 | * | 
|  | 199 | ******************************************************************************/ | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 200 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | #ifdef ACPI_FUTURE_USAGE | 
|  | 202 | acpi_status | 
|  | 203 | acpi_get_possible_resources ( | 
|  | 204 | acpi_handle                     device_handle, | 
|  | 205 | struct acpi_buffer              *ret_buffer) | 
|  | 206 | { | 
|  | 207 | acpi_status                     status; | 
|  | 208 |  | 
|  | 209 |  | 
|  | 210 | ACPI_FUNCTION_TRACE ("acpi_get_possible_resources"); | 
|  | 211 |  | 
|  | 212 |  | 
|  | 213 | /* | 
|  | 214 | * Must have a valid handle and buffer, So we have to have a handle | 
|  | 215 | * and a return buffer structure, and if there is a non-zero buffer length | 
|  | 216 | * we also need a valid pointer in the buffer. If it's a zero buffer length, | 
|  | 217 | * we'll be returning the needed buffer size, so keep going. | 
|  | 218 | */ | 
|  | 219 | if (!device_handle) { | 
|  | 220 | return_ACPI_STATUS (AE_BAD_PARAMETER); | 
|  | 221 | } | 
|  | 222 |  | 
|  | 223 | status = acpi_ut_validate_buffer (ret_buffer); | 
|  | 224 | if (ACPI_FAILURE (status)) { | 
|  | 225 | return_ACPI_STATUS (status); | 
|  | 226 | } | 
|  | 227 |  | 
|  | 228 | status = acpi_rs_get_prs_method_data (device_handle, ret_buffer); | 
|  | 229 | return_ACPI_STATUS (status); | 
|  | 230 | } | 
|  | 231 | EXPORT_SYMBOL(acpi_get_possible_resources); | 
|  | 232 | #endif  /*  ACPI_FUTURE_USAGE  */ | 
|  | 233 |  | 
|  | 234 |  | 
|  | 235 | /******************************************************************************* | 
|  | 236 | * | 
|  | 237 | * FUNCTION:    acpi_walk_resources | 
|  | 238 | * | 
|  | 239 | * PARAMETERS:  device_handle   - a handle to the device object for the | 
|  | 240 | *                                device we are querying | 
|  | 241 | *              Path            - method name of the resources we want | 
|  | 242 | *                                (METHOD_NAME__CRS or METHOD_NAME__PRS) | 
|  | 243 | *              user_function   - called for each resource | 
|  | 244 | *              Context         - passed to user_function | 
|  | 245 | * | 
|  | 246 | * RETURN:      Status | 
|  | 247 | * | 
|  | 248 | * DESCRIPTION: Retrieves the current or possible resource list for the | 
|  | 249 | *              specified device.  The user_function is called once for | 
|  | 250 | *              each resource in the list. | 
|  | 251 | * | 
|  | 252 | ******************************************************************************/ | 
|  | 253 |  | 
|  | 254 | acpi_status | 
|  | 255 | acpi_walk_resources ( | 
|  | 256 | acpi_handle                             device_handle, | 
|  | 257 | char                                    *path, | 
|  | 258 | ACPI_WALK_RESOURCE_CALLBACK     user_function, | 
|  | 259 | void                                    *context) | 
|  | 260 | { | 
|  | 261 | acpi_status                         status; | 
|  | 262 | struct acpi_buffer                  buffer = {ACPI_ALLOCATE_BUFFER, NULL}; | 
|  | 263 | struct acpi_resource                *resource; | 
|  | 264 | struct acpi_resource                *buffer_end; | 
|  | 265 |  | 
|  | 266 |  | 
|  | 267 | ACPI_FUNCTION_TRACE ("acpi_walk_resources"); | 
|  | 268 |  | 
|  | 269 |  | 
|  | 270 | if (!device_handle || | 
|  | 271 | (ACPI_STRNCMP (path, METHOD_NAME__CRS, sizeof (METHOD_NAME__CRS)) && | 
|  | 272 | ACPI_STRNCMP (path, METHOD_NAME__PRS, sizeof (METHOD_NAME__PRS)))) { | 
|  | 273 | return_ACPI_STATUS (AE_BAD_PARAMETER); | 
|  | 274 | } | 
|  | 275 |  | 
|  | 276 | status = acpi_rs_get_method_data (device_handle, path, &buffer); | 
|  | 277 | if (ACPI_FAILURE (status)) { | 
|  | 278 | return_ACPI_STATUS (status); | 
|  | 279 | } | 
|  | 280 |  | 
|  | 281 | /* Setup pointers */ | 
|  | 282 |  | 
|  | 283 | resource  = (struct acpi_resource *) buffer.pointer; | 
|  | 284 | buffer_end = ACPI_CAST_PTR (struct acpi_resource, | 
|  | 285 | ((u8 *) buffer.pointer + buffer.length)); | 
|  | 286 |  | 
|  | 287 | /* Walk the resource list */ | 
|  | 288 |  | 
|  | 289 | for (;;) { | 
|  | 290 | if (!resource || resource->id == ACPI_RSTYPE_END_TAG) { | 
|  | 291 | break; | 
|  | 292 | } | 
|  | 293 |  | 
|  | 294 | status = user_function (resource, context); | 
|  | 295 |  | 
|  | 296 | switch (status) { | 
|  | 297 | case AE_OK: | 
|  | 298 | case AE_CTRL_DEPTH: | 
|  | 299 |  | 
|  | 300 | /* Just keep going */ | 
|  | 301 |  | 
|  | 302 | status = AE_OK; | 
|  | 303 | break; | 
|  | 304 |  | 
|  | 305 | case AE_CTRL_TERMINATE: | 
|  | 306 |  | 
|  | 307 | /* Exit now, with OK stats */ | 
|  | 308 |  | 
|  | 309 | status = AE_OK; | 
|  | 310 | goto cleanup; | 
|  | 311 |  | 
|  | 312 | default: | 
|  | 313 |  | 
|  | 314 | /* All others are valid exceptions */ | 
|  | 315 |  | 
|  | 316 | goto cleanup; | 
|  | 317 | } | 
|  | 318 |  | 
|  | 319 | /* Get the next resource descriptor */ | 
|  | 320 |  | 
|  | 321 | resource = ACPI_NEXT_RESOURCE (resource); | 
|  | 322 |  | 
|  | 323 | /* Check for end-of-buffer */ | 
|  | 324 |  | 
|  | 325 | if (resource >= buffer_end) { | 
|  | 326 | goto cleanup; | 
|  | 327 | } | 
|  | 328 | } | 
|  | 329 |  | 
|  | 330 | cleanup: | 
|  | 331 |  | 
|  | 332 | acpi_os_free (buffer.pointer); | 
|  | 333 | return_ACPI_STATUS (status); | 
|  | 334 | } | 
|  | 335 | EXPORT_SYMBOL(acpi_walk_resources); | 
|  | 336 |  | 
|  | 337 |  | 
|  | 338 | /******************************************************************************* | 
|  | 339 | * | 
|  | 340 | * FUNCTION:    acpi_set_current_resources | 
|  | 341 | * | 
|  | 342 | * PARAMETERS:  device_handle   - a handle to the device object for the | 
|  | 343 | *                                device we are changing the resources of | 
|  | 344 | *              in_buffer       - a pointer to a buffer containing the | 
|  | 345 | *                                resources to be set for the device | 
|  | 346 | * | 
|  | 347 | * RETURN:      Status | 
|  | 348 | * | 
|  | 349 | * DESCRIPTION: This function is called to set the current resources for a | 
|  | 350 | *              specific device.  The caller must first acquire a handle for | 
|  | 351 | *              the desired device.  The resource data is passed to the routine | 
|  | 352 | *              the buffer pointed to by the in_buffer variable. | 
|  | 353 | * | 
|  | 354 | ******************************************************************************/ | 
|  | 355 |  | 
|  | 356 | acpi_status | 
|  | 357 | acpi_set_current_resources ( | 
|  | 358 | acpi_handle                     device_handle, | 
|  | 359 | struct acpi_buffer              *in_buffer) | 
|  | 360 | { | 
|  | 361 | acpi_status                     status; | 
|  | 362 |  | 
|  | 363 |  | 
|  | 364 | ACPI_FUNCTION_TRACE ("acpi_set_current_resources"); | 
|  | 365 |  | 
|  | 366 |  | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 367 | /* Must have a valid handle and buffer */ | 
|  | 368 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | if ((!device_handle)      || | 
|  | 370 | (!in_buffer)          || | 
|  | 371 | (!in_buffer->pointer) || | 
|  | 372 | (!in_buffer->length)) { | 
|  | 373 | return_ACPI_STATUS (AE_BAD_PARAMETER); | 
|  | 374 | } | 
|  | 375 |  | 
|  | 376 | status = acpi_rs_set_srs_method_data (device_handle, in_buffer); | 
|  | 377 | return_ACPI_STATUS (status); | 
|  | 378 | } | 
|  | 379 | EXPORT_SYMBOL(acpi_set_current_resources); | 
|  | 380 |  | 
|  | 381 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | /****************************************************************************** | 
|  | 383 | * | 
|  | 384 | * FUNCTION:    acpi_resource_to_address64 | 
|  | 385 | * | 
|  | 386 | * PARAMETERS:  resource                - Pointer to a resource | 
|  | 387 | *              out                     - Pointer to the users's return | 
|  | 388 | *                                        buffer (a struct | 
|  | 389 | *                                        struct acpi_resource_address64) | 
|  | 390 | * | 
|  | 391 | * RETURN:      Status | 
|  | 392 | * | 
|  | 393 | * DESCRIPTION: If the resource is an address16, address32, or address64, | 
|  | 394 | *              copy it to the address64 return buffer.  This saves the | 
|  | 395 | *              caller from having to duplicate code for different-sized | 
|  | 396 | *              addresses. | 
|  | 397 | * | 
|  | 398 | ******************************************************************************/ | 
|  | 399 |  | 
|  | 400 | acpi_status | 
|  | 401 | acpi_resource_to_address64 ( | 
|  | 402 | struct acpi_resource                *resource, | 
|  | 403 | struct acpi_resource_address64      *out) | 
|  | 404 | { | 
|  | 405 | struct acpi_resource_address16      *address16; | 
|  | 406 | struct acpi_resource_address32      *address32; | 
|  | 407 |  | 
|  | 408 |  | 
|  | 409 | switch (resource->id) { | 
|  | 410 | case ACPI_RSTYPE_ADDRESS16: | 
|  | 411 |  | 
|  | 412 | address16 = (struct acpi_resource_address16 *) &resource->data; | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 413 | ACPI_COPY_ADDRESS (out, address16); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | break; | 
|  | 415 |  | 
|  | 416 |  | 
|  | 417 | case ACPI_RSTYPE_ADDRESS32: | 
|  | 418 |  | 
|  | 419 | address32 = (struct acpi_resource_address32 *) &resource->data; | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 420 | ACPI_COPY_ADDRESS (out, address32); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | break; | 
|  | 422 |  | 
|  | 423 |  | 
|  | 424 | case ACPI_RSTYPE_ADDRESS64: | 
|  | 425 |  | 
|  | 426 | /* Simple copy for 64 bit source */ | 
|  | 427 |  | 
|  | 428 | ACPI_MEMCPY (out, &resource->data, sizeof (struct acpi_resource_address64)); | 
|  | 429 | break; | 
|  | 430 |  | 
|  | 431 |  | 
|  | 432 | default: | 
|  | 433 | return (AE_BAD_PARAMETER); | 
|  | 434 | } | 
|  | 435 |  | 
|  | 436 | return (AE_OK); | 
|  | 437 | } | 
|  | 438 | EXPORT_SYMBOL(acpi_resource_to_address64); |