Blame view
drivers/acpi/acpica/exregion.c
15 KB
1da177e4c
|
1 2 3 4 5 6 7 8 |
/****************************************************************************** * * Module Name: exregion - ACPI default op_region (address space) handlers * *****************************************************************************/ /* |
75a44ce00
|
9 |
* Copyright (C) 2000 - 2008, Intel Corp. |
1da177e4c
|
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
* All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions, and the following disclaimer, * without modification. * 2. Redistributions in binary form must reproduce at minimum a disclaimer * substantially similar to the "NO WARRANTY" disclaimer below * ("Disclaimer") and any redistribution must be conditioned upon * including a substantially similar Disclaimer requirement for further * binary redistribution. * 3. Neither the names of the above-listed copyright holders nor the names * of any contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * Alternatively, this software may be distributed under the terms of the * GNU General Public License ("GPL") version 2 as published by the Free * Software Foundation. * * NO WARRANTY * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGES. */ |
1da177e4c
|
44 |
#include <acpi/acpi.h> |
e2f7a7772
|
45 46 |
#include "accommon.h" #include "acinterp.h" |
1da177e4c
|
47 |
|
1da177e4c
|
48 |
#define _COMPONENT ACPI_EXECUTER |
4be44fcd3
|
49 |
ACPI_MODULE_NAME("exregion") |
1da177e4c
|
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
/******************************************************************************* * * FUNCTION: acpi_ex_system_memory_space_handler * * PARAMETERS: Function - Read or Write operation * Address - Where in the space to read or write * bit_width - Field width in bits (8, 16, or 32) * Value - Pointer to in or out value * handler_context - Pointer to Handler's context * region_context - Pointer to context specific to the * accessed region * * RETURN: Status * * DESCRIPTION: Handler for the System Memory address space (Op Region) * ******************************************************************************/ |
1da177e4c
|
68 |
acpi_status |
4be44fcd3
|
69 70 71 72 73 |
acpi_ex_system_memory_space_handler(u32 function, acpi_physical_address address, u32 bit_width, acpi_integer * value, void *handler_context, void *region_context) |
1da177e4c
|
74 |
{ |
4be44fcd3
|
75 76 77 78 |
acpi_status status = AE_OK; void *logical_addr_ptr = NULL; struct acpi_mem_space_context *mem_info = region_context; u32 length; |
d410ee510
|
79 80 |
acpi_size map_length; acpi_size page_boundary_map_length; |
0897831bb
|
81 |
#ifdef ACPI_MISALIGNMENT_NOT_SUPPORTED |
4be44fcd3
|
82 |
u32 remainder; |
1da177e4c
|
83 |
#endif |
b229cf92e
|
84 |
ACPI_FUNCTION_TRACE(ex_system_memory_space_handler); |
1da177e4c
|
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
/* Validate and translate the bit width */ switch (bit_width) { case 8: length = 1; break; case 16: length = 2; break; case 32: length = 4; break; case 64: length = 8; break; default: |
b229cf92e
|
106 |
ACPI_ERROR((AE_INFO, "Invalid SystemMemory width %d", |
b8e4d8935
|
107 |
bit_width)); |
4be44fcd3
|
108 |
return_ACPI_STATUS(AE_AML_OPERAND_VALUE); |
1da177e4c
|
109 |
} |
0897831bb
|
110 |
#ifdef ACPI_MISALIGNMENT_NOT_SUPPORTED |
1da177e4c
|
111 112 113 114 |
/* * Hardware does not support non-aligned data transfers, we must verify * the request. */ |
4be44fcd3
|
115 116 |
(void)acpi_ut_short_divide((acpi_integer) address, length, NULL, &remainder); |
1da177e4c
|
117 |
if (remainder != 0) { |
4be44fcd3
|
118 |
return_ACPI_STATUS(AE_AML_ALIGNMENT); |
1da177e4c
|
119 120 121 122 123 124 125 126 127 |
} #endif /* * Does the request fit into the cached memory mapping? * Is 1) Address below the current mapping? OR * 2) Address beyond the current mapping? */ if ((address < mem_info->mapped_physical_address) || |
4be44fcd3
|
128 129 130 131 |
(((acpi_integer) address + length) > ((acpi_integer) mem_info-> mapped_physical_address + mem_info->mapped_length))) { |
1da177e4c
|
132 133 134 135 136 |
/* * The request cannot be resolved by the current memory mapping; * Delete the existing mapping and create a new one. */ if (mem_info->mapped_length) { |
52fc0b026
|
137 |
|
1da177e4c
|
138 |
/* Valid mapping, delete it */ |
4be44fcd3
|
139 140 |
acpi_os_unmap_memory(mem_info->mapped_logical_address, mem_info->mapped_length); |
1da177e4c
|
141 142 143 |
} /* |
d410ee510
|
144 145 146 |
* Attempt to map from the requested address to the end of the region. * However, we will never map more than one page, nor will we cross * a page boundary. |
1da177e4c
|
147 |
*/ |
d410ee510
|
148 |
map_length = (acpi_size) |
4be44fcd3
|
149 |
((mem_info->address + mem_info->length) - address); |
44f6c0124
|
150 |
|
d410ee510
|
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
/* * If mapping the entire remaining portion of the region will cross * a page boundary, just map up to the page boundary, do not cross. * On some systems, crossing a page boundary while mapping regions * can cause warnings if the pages have different attributes * due to resource management */ page_boundary_map_length = ACPI_ROUND_UP(address, ACPI_DEFAULT_PAGE_SIZE) - address; if (!page_boundary_map_length) { page_boundary_map_length = ACPI_DEFAULT_PAGE_SIZE; } if (map_length > page_boundary_map_length) { map_length = page_boundary_map_length; |
1da177e4c
|
167 168 169 |
} /* Create a new mapping starting at the address given */ |
d410ee510
|
170 |
mem_info->mapped_logical_address = acpi_os_map_memory((acpi_physical_address) address, map_length); |
f3d2e7865
|
171 |
if (!mem_info->mapped_logical_address) { |
b8e4d8935
|
172 173 |
ACPI_ERROR((AE_INFO, "Could not map memory at %8.8X%8.8X, size %X", |
b7f9f0422
|
174 |
ACPI_FORMAT_NATIVE_UINT(address), |
d410ee510
|
175 |
(u32) map_length)); |
1da177e4c
|
176 |
mem_info->mapped_length = 0; |
f3d2e7865
|
177 |
return_ACPI_STATUS(AE_NO_MEMORY); |
1da177e4c
|
178 179 180 181 182 |
} /* Save the physical address and mapping size */ mem_info->mapped_physical_address = address; |
d410ee510
|
183 |
mem_info->mapped_length = map_length; |
1da177e4c
|
184 185 186 187 188 189 190 |
} /* * Generate a logical pointer corresponding to the address we want to * access */ logical_addr_ptr = mem_info->mapped_logical_address + |
4be44fcd3
|
191 192 193 194 |
((acpi_integer) address - (acpi_integer) mem_info->mapped_physical_address); ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
8313524a0
|
195 196 |
"System-Memory (width %d) R/W %d Address=%8.8X%8.8X ", |
b7f9f0422
|
197 198 |
bit_width, function, ACPI_FORMAT_NATIVE_UINT(address))); |
4be44fcd3
|
199 200 201 202 203 204 205 206 207 |
/* * Perform the memory read or write * * Note: For machines that do not support non-aligned transfers, the target * address was checked for alignment above. We do not attempt to break the * transfer up into smaller (byte-size) chunks because the AML specifically * asked for a transfer width that the hardware may require. */ |
1da177e4c
|
208 209 210 211 212 213 |
switch (function) { case ACPI_READ: *value = 0; switch (bit_width) { case 8: |
c51a4de85
|
214 |
*value = (acpi_integer) ACPI_GET8(logical_addr_ptr); |
1da177e4c
|
215 216 217 |
break; case 16: |
c51a4de85
|
218 |
*value = (acpi_integer) ACPI_GET16(logical_addr_ptr); |
1da177e4c
|
219 220 221 |
break; case 32: |
c51a4de85
|
222 |
*value = (acpi_integer) ACPI_GET32(logical_addr_ptr); |
1da177e4c
|
223 |
break; |
1da177e4c
|
224 |
case 64: |
c51a4de85
|
225 |
*value = (acpi_integer) ACPI_GET64(logical_addr_ptr); |
1da177e4c
|
226 |
break; |
59fa85057
|
227 |
|
1da177e4c
|
228 229 230 231 232 233 234 235 236 237 |
default: /* bit_width was already validated */ break; } break; case ACPI_WRITE: switch (bit_width) { case 8: |
c51a4de85
|
238 |
ACPI_SET8(logical_addr_ptr) = (u8) * value; |
1da177e4c
|
239 240 241 |
break; case 16: |
c51a4de85
|
242 |
ACPI_SET16(logical_addr_ptr) = (u16) * value; |
1da177e4c
|
243 244 245 |
break; case 32: |
c51a4de85
|
246 |
ACPI_SET32(logical_addr_ptr) = (u32) * value; |
1da177e4c
|
247 |
break; |
1da177e4c
|
248 |
case 64: |
c51a4de85
|
249 |
ACPI_SET64(logical_addr_ptr) = (u64) * value; |
1da177e4c
|
250 |
break; |
1da177e4c
|
251 252 253 254 255 256 257 258 259 260 261 |
default: /* bit_width was already validated */ break; } break; default: status = AE_BAD_PARAMETER; break; } |
4be44fcd3
|
262 |
return_ACPI_STATUS(status); |
1da177e4c
|
263 |
} |
1da177e4c
|
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 |
/******************************************************************************* * * FUNCTION: acpi_ex_system_io_space_handler * * PARAMETERS: Function - Read or Write operation * Address - Where in the space to read or write * bit_width - Field width in bits (8, 16, or 32) * Value - Pointer to in or out value * handler_context - Pointer to Handler's context * region_context - Pointer to context specific to the * accessed region * * RETURN: Status * * DESCRIPTION: Handler for the System IO address space (Op Region) * ******************************************************************************/ acpi_status |
4be44fcd3
|
283 284 285 286 287 |
acpi_ex_system_io_space_handler(u32 function, acpi_physical_address address, u32 bit_width, acpi_integer * value, void *handler_context, void *region_context) |
1da177e4c
|
288 |
{ |
4be44fcd3
|
289 290 |
acpi_status status = AE_OK; u32 value32; |
1da177e4c
|
291 |
|
b229cf92e
|
292 |
ACPI_FUNCTION_TRACE(ex_system_io_space_handler); |
1da177e4c
|
293 |
|
4be44fcd3
|
294 |
ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
8313524a0
|
295 296 |
"System-IO (width %d) R/W %d Address=%8.8X%8.8X ", |
b7f9f0422
|
297 298 |
bit_width, function, ACPI_FORMAT_NATIVE_UINT(address))); |
1da177e4c
|
299 300 301 302 303 |
/* Decode the function parameter */ switch (function) { case ACPI_READ: |
7f0719039
|
304 |
status = acpi_hw_read_port((acpi_io_address) address, |
4be44fcd3
|
305 |
&value32, bit_width); |
1da177e4c
|
306 307 308 309 |
*value = value32; break; case ACPI_WRITE: |
7f0719039
|
310 |
status = acpi_hw_write_port((acpi_io_address) address, |
4be44fcd3
|
311 |
(u32) * value, bit_width); |
1da177e4c
|
312 313 314 315 316 317 |
break; default: status = AE_BAD_PARAMETER; break; } |
4be44fcd3
|
318 |
return_ACPI_STATUS(status); |
1da177e4c
|
319 |
} |
1da177e4c
|
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 |
/******************************************************************************* * * FUNCTION: acpi_ex_pci_config_space_handler * * PARAMETERS: Function - Read or Write operation * Address - Where in the space to read or write * bit_width - Field width in bits (8, 16, or 32) * Value - Pointer to in or out value * handler_context - Pointer to Handler's context * region_context - Pointer to context specific to the * accessed region * * RETURN: Status * * DESCRIPTION: Handler for the PCI Config address space (Op Region) * ******************************************************************************/ acpi_status |
4be44fcd3
|
339 340 341 342 343 |
acpi_ex_pci_config_space_handler(u32 function, acpi_physical_address address, u32 bit_width, acpi_integer * value, void *handler_context, void *region_context) |
1da177e4c
|
344 |
{ |
4be44fcd3
|
345 346 347 |
acpi_status status = AE_OK; struct acpi_pci_id *pci_id; u16 pci_register; |
1186974f3
|
348 |
u32 value32; |
1da177e4c
|
349 |
|
b229cf92e
|
350 |
ACPI_FUNCTION_TRACE(ex_pci_config_space_handler); |
1da177e4c
|
351 352 353 354 355 356 357 358 359 360 361 362 363 |
/* * The arguments to acpi_os(Read|Write)pci_configuration are: * * pci_segment is the PCI bus segment range 0-31 * pci_bus is the PCI bus number range 0-255 * pci_device is the PCI device number range 0-31 * pci_function is the PCI device function number * pci_register is the Config space register range 0-255 bytes * * Value - input value for write, output address for read * */ |
4be44fcd3
|
364 |
pci_id = (struct acpi_pci_id *)region_context; |
1da177e4c
|
365 |
pci_register = (u16) (u32) address; |
4be44fcd3
|
366 |
ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
8313524a0
|
367 368 |
"Pci-Config %d (%d) Seg(%04x) Bus(%04x) Dev(%04x) Func(%04x) Reg(%04x) ", |
4be44fcd3
|
369 370 |
function, bit_width, pci_id->segment, pci_id->bus, pci_id->device, pci_id->function, pci_register)); |
1da177e4c
|
371 372 373 |
switch (function) { case ACPI_READ: |
4be44fcd3
|
374 |
status = acpi_os_read_pci_configuration(pci_id, pci_register, |
1186974f3
|
375 376 |
&value32, bit_width); *value = value32; |
1da177e4c
|
377 378 379 |
break; case ACPI_WRITE: |
4be44fcd3
|
380 381 |
status = acpi_os_write_pci_configuration(pci_id, pci_register, *value, bit_width); |
1da177e4c
|
382 383 384 385 386 387 388 |
break; default: status = AE_BAD_PARAMETER; break; } |
4be44fcd3
|
389 |
return_ACPI_STATUS(status); |
1da177e4c
|
390 |
} |
1da177e4c
|
391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 |
/******************************************************************************* * * FUNCTION: acpi_ex_cmos_space_handler * * PARAMETERS: Function - Read or Write operation * Address - Where in the space to read or write * bit_width - Field width in bits (8, 16, or 32) * Value - Pointer to in or out value * handler_context - Pointer to Handler's context * region_context - Pointer to context specific to the * accessed region * * RETURN: Status * * DESCRIPTION: Handler for the CMOS address space (Op Region) * ******************************************************************************/ acpi_status |
4be44fcd3
|
410 411 412 413 414 |
acpi_ex_cmos_space_handler(u32 function, acpi_physical_address address, u32 bit_width, acpi_integer * value, void *handler_context, void *region_context) |
1da177e4c
|
415 |
{ |
4be44fcd3
|
416 |
acpi_status status = AE_OK; |
1da177e4c
|
417 |
|
b229cf92e
|
418 |
ACPI_FUNCTION_TRACE(ex_cmos_space_handler); |
1da177e4c
|
419 |
|
4be44fcd3
|
420 |
return_ACPI_STATUS(status); |
1da177e4c
|
421 |
} |
1da177e4c
|
422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 |
/******************************************************************************* * * FUNCTION: acpi_ex_pci_bar_space_handler * * PARAMETERS: Function - Read or Write operation * Address - Where in the space to read or write * bit_width - Field width in bits (8, 16, or 32) * Value - Pointer to in or out value * handler_context - Pointer to Handler's context * region_context - Pointer to context specific to the * accessed region * * RETURN: Status * * DESCRIPTION: Handler for the PCI bar_target address space (Op Region) * ******************************************************************************/ acpi_status |
4be44fcd3
|
441 442 443 444 445 |
acpi_ex_pci_bar_space_handler(u32 function, acpi_physical_address address, u32 bit_width, acpi_integer * value, void *handler_context, void *region_context) |
1da177e4c
|
446 |
{ |
4be44fcd3
|
447 |
acpi_status status = AE_OK; |
1da177e4c
|
448 |
|
b229cf92e
|
449 |
ACPI_FUNCTION_TRACE(ex_pci_bar_space_handler); |
1da177e4c
|
450 |
|
4be44fcd3
|
451 |
return_ACPI_STATUS(status); |
1da177e4c
|
452 |
} |
1da177e4c
|
453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 |
/******************************************************************************* * * FUNCTION: acpi_ex_data_table_space_handler * * PARAMETERS: Function - Read or Write operation * Address - Where in the space to read or write * bit_width - Field width in bits (8, 16, or 32) * Value - Pointer to in or out value * handler_context - Pointer to Handler's context * region_context - Pointer to context specific to the * accessed region * * RETURN: Status * * DESCRIPTION: Handler for the Data Table address space (Op Region) * ******************************************************************************/ acpi_status |
4be44fcd3
|
472 473 474 475 476 |
acpi_ex_data_table_space_handler(u32 function, acpi_physical_address address, u32 bit_width, acpi_integer * value, void *handler_context, void *region_context) |
1da177e4c
|
477 |
{ |
b229cf92e
|
478 |
ACPI_FUNCTION_TRACE(ex_data_table_space_handler); |
1da177e4c
|
479 |
|
44f6c0124
|
480 |
/* Perform the memory read or write */ |
1da177e4c
|
481 482 483 |
switch (function) { case ACPI_READ: |
4119532c9
|
484 485 486 |
ACPI_MEMCPY(ACPI_CAST_PTR(char, value), ACPI_PHYSADDR_TO_PTR(address), ACPI_DIV_8(bit_width)); |
1da177e4c
|
487 488 489 490 |
break; case ACPI_WRITE: default: |
4be44fcd3
|
491 |
return_ACPI_STATUS(AE_SUPPORT); |
1da177e4c
|
492 |
} |
4119532c9
|
493 |
return_ACPI_STATUS(AE_OK); |
1da177e4c
|
494 |
} |