Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenexregion.c
Go to the documentation of this file.
00001 00002 /****************************************************************************** 00003 * 00004 * Module Name: exregion - ACPI default OpRegion (address space) handlers 00005 * 00006 *****************************************************************************/ 00007 00008 /****************************************************************************** 00009 * 00010 * 1. Copyright Notice 00011 * 00012 * Some or all of this work - Copyright (c) 1999 - 2011, Intel Corp. 00013 * All rights reserved. 00014 * 00015 * 2. License 00016 * 00017 * 2.1. This is your license from Intel Corp. under its intellectual property 00018 * rights. You may have additional license terms from the party that provided 00019 * you this software, covering your right to use that party's intellectual 00020 * property rights. 00021 * 00022 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 00023 * copy of the source code appearing in this file ("Covered Code") an 00024 * irrevocable, perpetual, worldwide license under Intel's copyrights in the 00025 * base code distributed originally by Intel ("Original Intel Code") to copy, 00026 * make derivatives, distribute, use and display any portion of the Covered 00027 * Code in any form, with the right to sublicense such rights; and 00028 * 00029 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 00030 * license (with the right to sublicense), under only those claims of Intel 00031 * patents that are infringed by the Original Intel Code, to make, use, sell, 00032 * offer to sell, and import the Covered Code and derivative works thereof 00033 * solely to the minimum extent necessary to exercise the above copyright 00034 * license, and in no event shall the patent license extend to any additions 00035 * to or modifications of the Original Intel Code. No other license or right 00036 * is granted directly or by implication, estoppel or otherwise; 00037 * 00038 * The above copyright and patent license is granted only if the following 00039 * conditions are met: 00040 * 00041 * 3. Conditions 00042 * 00043 * 3.1. Redistribution of Source with Rights to Further Distribute Source. 00044 * Redistribution of source code of any substantial portion of the Covered 00045 * Code or modification with rights to further distribute source must include 00046 * the above Copyright Notice, the above License, this list of Conditions, 00047 * and the following Disclaimer and Export Compliance provision. In addition, 00048 * Licensee must cause all Covered Code to which Licensee contributes to 00049 * contain a file documenting the changes Licensee made to create that Covered 00050 * Code and the date of any change. Licensee must include in that file the 00051 * documentation of any changes made by any predecessor Licensee. Licensee 00052 * must include a prominent statement that the modification is derived, 00053 * directly or indirectly, from Original Intel Code. 00054 * 00055 * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 00056 * Redistribution of source code of any substantial portion of the Covered 00057 * Code or modification without rights to further distribute source must 00058 * include the following Disclaimer and Export Compliance provision in the 00059 * documentation and/or other materials provided with distribution. In 00060 * addition, Licensee may not authorize further sublicense of source of any 00061 * portion of the Covered Code, and must include terms to the effect that the 00062 * license from Licensee to its licensee is limited to the intellectual 00063 * property embodied in the software Licensee provides to its licensee, and 00064 * not to intellectual property embodied in modifications its licensee may 00065 * make. 00066 * 00067 * 3.3. Redistribution of Executable. Redistribution in executable form of any 00068 * substantial portion of the Covered Code or modification must reproduce the 00069 * above Copyright Notice, and the following Disclaimer and Export Compliance 00070 * provision in the documentation and/or other materials provided with the 00071 * distribution. 00072 * 00073 * 3.4. Intel retains all right, title, and interest in and to the Original 00074 * Intel Code. 00075 * 00076 * 3.5. Neither the name Intel nor any other trademark owned or controlled by 00077 * Intel shall be used in advertising or otherwise to promote the sale, use or 00078 * other dealings in products derived from or relating to the Covered Code 00079 * without prior written authorization from Intel. 00080 * 00081 * 4. Disclaimer and Export Compliance 00082 * 00083 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 00084 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 00085 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 00086 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 00087 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 00088 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 00089 * PARTICULAR PURPOSE. 00090 * 00091 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 00092 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 00093 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 00094 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 00095 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 00096 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 00097 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 00098 * LIMITED REMEDY. 00099 * 00100 * 4.3. Licensee shall not export, either directly or indirectly, any of this 00101 * software or system incorporating such software without first obtaining any 00102 * required license or other approval from the U. S. Department of Commerce or 00103 * any other agency or department of the United States Government. In the 00104 * event Licensee exports any such software from the United States or 00105 * re-exports any such software from a foreign destination, Licensee shall 00106 * ensure that the distribution and export/re-export of the software is in 00107 * compliance with all laws, regulations, orders, or other restrictions of the 00108 * U.S. Export Administration Regulations. Licensee agrees that neither it nor 00109 * any of its subsidiaries will export/re-export any technical data, process, 00110 * software, or service, directly or indirectly, to any country for which the 00111 * United States government or any agency thereof requires an export license, 00112 * other governmental approval, or letter of assurance, without first obtaining 00113 * such license, approval or letter. 00114 * 00115 *****************************************************************************/ 00116 00117 00118 #define __EXREGION_C__ 00119 00120 #include "acpi.h" 00121 #include "accommon.h" 00122 #include "acinterp.h" 00123 00124 00125 #define _COMPONENT ACPI_EXECUTER 00126 ACPI_MODULE_NAME ("exregion") 00127 00128 00129 /******************************************************************************* 00130 * 00131 * FUNCTION: AcpiExSystemMemorySpaceHandler 00132 * 00133 * PARAMETERS: Function - Read or Write operation 00134 * Address - Where in the space to read or write 00135 * BitWidth - Field width in bits (8, 16, or 32) 00136 * Value - Pointer to in or out value 00137 * HandlerContext - Pointer to Handler's context 00138 * RegionContext - Pointer to context specific to the 00139 * accessed region 00140 * 00141 * RETURN: Status 00142 * 00143 * DESCRIPTION: Handler for the System Memory address space (Op Region) 00144 * 00145 ******************************************************************************/ 00146 00147 ACPI_STATUS 00148 AcpiExSystemMemorySpaceHandler ( 00149 UINT32 Function, 00150 ACPI_PHYSICAL_ADDRESS Address, 00151 UINT32 BitWidth, 00152 UINT64 *Value, 00153 void *HandlerContext, 00154 void *RegionContext) 00155 { 00156 ACPI_STATUS Status = AE_OK; 00157 void *LogicalAddrPtr = NULL; 00158 ACPI_MEM_SPACE_CONTEXT *MemInfo = RegionContext; 00159 UINT32 Length; 00160 ACPI_SIZE MapLength; 00161 ACPI_SIZE PageBoundaryMapLength; 00162 #ifdef ACPI_MISALIGNMENT_NOT_SUPPORTED 00163 UINT32 Remainder; 00164 #endif 00165 00166 00167 ACPI_FUNCTION_TRACE (ExSystemMemorySpaceHandler); 00168 00169 00170 /* Validate and translate the bit width */ 00171 00172 switch (BitWidth) 00173 { 00174 case 8: 00175 Length = 1; 00176 break; 00177 00178 case 16: 00179 Length = 2; 00180 break; 00181 00182 case 32: 00183 Length = 4; 00184 break; 00185 00186 case 64: 00187 Length = 8; 00188 break; 00189 00190 default: 00191 ACPI_ERROR ((AE_INFO, "Invalid SystemMemory width %u", 00192 BitWidth)); 00193 return_ACPI_STATUS (AE_AML_OPERAND_VALUE); 00194 } 00195 00196 #ifdef ACPI_MISALIGNMENT_NOT_SUPPORTED 00197 /* 00198 * Hardware does not support non-aligned data transfers, we must verify 00199 * the request. 00200 */ 00201 (void) AcpiUtShortDivide ((UINT64) Address, Length, NULL, &Remainder); 00202 if (Remainder != 0) 00203 { 00204 return_ACPI_STATUS (AE_AML_ALIGNMENT); 00205 } 00206 #endif 00207 00208 /* 00209 * Does the request fit into the cached memory mapping? 00210 * Is 1) Address below the current mapping? OR 00211 * 2) Address beyond the current mapping? 00212 */ 00213 if ((Address < MemInfo->MappedPhysicalAddress) || 00214 (((UINT64) Address + Length) > 00215 ((UINT64) 00216 MemInfo->MappedPhysicalAddress + MemInfo->MappedLength))) 00217 { 00218 /* 00219 * The request cannot be resolved by the current memory mapping; 00220 * Delete the existing mapping and create a new one. 00221 */ 00222 if (MemInfo->MappedLength) 00223 { 00224 /* Valid mapping, delete it */ 00225 00226 AcpiOsUnmapMemory (MemInfo->MappedLogicalAddress, 00227 MemInfo->MappedLength); 00228 } 00229 00230 /* 00231 * October 2009: Attempt to map from the requested address to the 00232 * end of the region. However, we will never map more than one 00233 * page, nor will we cross a page boundary. 00234 */ 00235 MapLength = (ACPI_SIZE) 00236 ((MemInfo->Address + MemInfo->Length) - Address); 00237 00238 /* 00239 * If mapping the entire remaining portion of the region will cross 00240 * a page boundary, just map up to the page boundary, do not cross. 00241 * On some systems, crossing a page boundary while mapping regions 00242 * can cause warnings if the pages have different attributes 00243 * due to resource management. 00244 * 00245 * This has the added benefit of constraining a single mapping to 00246 * one page, which is similar to the original code that used a 4k 00247 * maximum window. 00248 */ 00249 PageBoundaryMapLength = 00250 ACPI_ROUND_UP (Address, ACPI_DEFAULT_PAGE_SIZE) - Address; 00251 if (PageBoundaryMapLength == 0) 00252 { 00253 PageBoundaryMapLength = ACPI_DEFAULT_PAGE_SIZE; 00254 } 00255 00256 if (MapLength > PageBoundaryMapLength) 00257 { 00258 MapLength = PageBoundaryMapLength; 00259 } 00260 00261 /* Create a new mapping starting at the address given */ 00262 00263 MemInfo->MappedLogicalAddress = AcpiOsMapMemory ( 00264 (ACPI_PHYSICAL_ADDRESS) Address, MapLength); 00265 if (!MemInfo->MappedLogicalAddress) 00266 { 00267 ACPI_ERROR ((AE_INFO, 00268 "Could not map memory at 0x%8.8X%8.8X, size %u", 00269 ACPI_FORMAT_NATIVE_UINT (Address), (UINT32) MapLength)); 00270 MemInfo->MappedLength = 0; 00271 return_ACPI_STATUS (AE_NO_MEMORY); 00272 } 00273 00274 /* Save the physical address and mapping size */ 00275 00276 MemInfo->MappedPhysicalAddress = Address; 00277 MemInfo->MappedLength = MapLength; 00278 } 00279 00280 /* 00281 * Generate a logical pointer corresponding to the address we want to 00282 * access 00283 */ 00284 LogicalAddrPtr = MemInfo->MappedLogicalAddress + 00285 ((UINT64) Address - (UINT64) MemInfo->MappedPhysicalAddress); 00286 00287 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, 00288 "System-Memory (width %u) R/W %u Address=%8.8X%8.8X\n", 00289 BitWidth, Function, ACPI_FORMAT_NATIVE_UINT (Address))); 00290 00291 /* 00292 * Perform the memory read or write 00293 * 00294 * Note: For machines that do not support non-aligned transfers, the target 00295 * address was checked for alignment above. We do not attempt to break the 00296 * transfer up into smaller (byte-size) chunks because the AML specifically 00297 * asked for a transfer width that the hardware may require. 00298 */ 00299 switch (Function) 00300 { 00301 case ACPI_READ: 00302 00303 *Value = 0; 00304 switch (BitWidth) 00305 { 00306 case 8: 00307 *Value = (UINT64) ACPI_GET8 (LogicalAddrPtr); 00308 break; 00309 00310 case 16: 00311 *Value = (UINT64) ACPI_GET16 (LogicalAddrPtr); 00312 break; 00313 00314 case 32: 00315 *Value = (UINT64) ACPI_GET32 (LogicalAddrPtr); 00316 break; 00317 00318 case 64: 00319 *Value = (UINT64) ACPI_GET64 (LogicalAddrPtr); 00320 break; 00321 00322 default: 00323 /* BitWidth was already validated */ 00324 break; 00325 } 00326 break; 00327 00328 case ACPI_WRITE: 00329 00330 switch (BitWidth) 00331 { 00332 case 8: 00333 ACPI_SET8 (LogicalAddrPtr) = (UINT8) *Value; 00334 break; 00335 00336 case 16: 00337 ACPI_SET16 (LogicalAddrPtr) = (UINT16) *Value; 00338 break; 00339 00340 case 32: 00341 ACPI_SET32 ( LogicalAddrPtr) = (UINT32) *Value; 00342 break; 00343 00344 case 64: 00345 ACPI_SET64 (LogicalAddrPtr) = (UINT64) *Value; 00346 break; 00347 00348 default: 00349 /* BitWidth was already validated */ 00350 break; 00351 } 00352 break; 00353 00354 default: 00355 Status = AE_BAD_PARAMETER; 00356 break; 00357 } 00358 00359 return_ACPI_STATUS (Status); 00360 } 00361 00362 00363 /******************************************************************************* 00364 * 00365 * FUNCTION: AcpiExSystemIoSpaceHandler 00366 * 00367 * PARAMETERS: Function - Read or Write operation 00368 * Address - Where in the space to read or write 00369 * BitWidth - Field width in bits (8, 16, or 32) 00370 * Value - Pointer to in or out value 00371 * HandlerContext - Pointer to Handler's context 00372 * RegionContext - Pointer to context specific to the 00373 * accessed region 00374 * 00375 * RETURN: Status 00376 * 00377 * DESCRIPTION: Handler for the System IO address space (Op Region) 00378 * 00379 ******************************************************************************/ 00380 00381 ACPI_STATUS 00382 AcpiExSystemIoSpaceHandler ( 00383 UINT32 Function, 00384 ACPI_PHYSICAL_ADDRESS Address, 00385 UINT32 BitWidth, 00386 UINT64 *Value, 00387 void *HandlerContext, 00388 void *RegionContext) 00389 { 00390 ACPI_STATUS Status = AE_OK; 00391 UINT32 Value32; 00392 00393 00394 ACPI_FUNCTION_TRACE (ExSystemIoSpaceHandler); 00395 00396 00397 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, 00398 "System-IO (width %u) R/W %u Address=%8.8X%8.8X\n", 00399 BitWidth, Function, ACPI_FORMAT_NATIVE_UINT (Address))); 00400 00401 /* Decode the function parameter */ 00402 00403 switch (Function) 00404 { 00405 case ACPI_READ: 00406 00407 Status = AcpiHwReadPort ((ACPI_IO_ADDRESS) Address, 00408 &Value32, BitWidth); 00409 *Value = Value32; 00410 break; 00411 00412 case ACPI_WRITE: 00413 00414 Status = AcpiHwWritePort ((ACPI_IO_ADDRESS) Address, 00415 (UINT32) *Value, BitWidth); 00416 break; 00417 00418 default: 00419 Status = AE_BAD_PARAMETER; 00420 break; 00421 } 00422 00423 return_ACPI_STATUS (Status); 00424 } 00425 00426 00427 /******************************************************************************* 00428 * 00429 * FUNCTION: AcpiExPciConfigSpaceHandler 00430 * 00431 * PARAMETERS: Function - Read or Write operation 00432 * Address - Where in the space to read or write 00433 * BitWidth - Field width in bits (8, 16, or 32) 00434 * Value - Pointer to in or out value 00435 * HandlerContext - Pointer to Handler's context 00436 * RegionContext - Pointer to context specific to the 00437 * accessed region 00438 * 00439 * RETURN: Status 00440 * 00441 * DESCRIPTION: Handler for the PCI Config address space (Op Region) 00442 * 00443 ******************************************************************************/ 00444 00445 ACPI_STATUS 00446 AcpiExPciConfigSpaceHandler ( 00447 UINT32 Function, 00448 ACPI_PHYSICAL_ADDRESS Address, 00449 UINT32 BitWidth, 00450 UINT64 *Value, 00451 void *HandlerContext, 00452 void *RegionContext) 00453 { 00454 ACPI_STATUS Status = AE_OK; 00455 ACPI_PCI_ID *PciId; 00456 UINT16 PciRegister; 00457 00458 00459 ACPI_FUNCTION_TRACE (ExPciConfigSpaceHandler); 00460 00461 00462 /* 00463 * The arguments to AcpiOs(Read|Write)PciConfiguration are: 00464 * 00465 * PciSegment is the PCI bus segment range 0-31 00466 * PciBus is the PCI bus number range 0-255 00467 * PciDevice is the PCI device number range 0-31 00468 * PciFunction is the PCI device function number 00469 * PciRegister is the Config space register range 0-255 bytes 00470 * 00471 * Value - input value for write, output address for read 00472 * 00473 */ 00474 PciId = (ACPI_PCI_ID *) RegionContext; 00475 PciRegister = (UINT16) (UINT32) Address; 00476 00477 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, 00478 "Pci-Config %u (%u) Seg(%04x) Bus(%04x) Dev(%04x) Func(%04x) Reg(%04x)\n", 00479 Function, BitWidth, PciId->Segment, PciId->Bus, PciId->Device, 00480 PciId->Function, PciRegister)); 00481 00482 switch (Function) 00483 { 00484 case ACPI_READ: 00485 00486 *Value = 0; 00487 Status = AcpiOsReadPciConfiguration (PciId, PciRegister, 00488 Value, BitWidth); 00489 break; 00490 00491 case ACPI_WRITE: 00492 00493 Status = AcpiOsWritePciConfiguration (PciId, PciRegister, 00494 *Value, BitWidth); 00495 break; 00496 00497 default: 00498 00499 Status = AE_BAD_PARAMETER; 00500 break; 00501 } 00502 00503 return_ACPI_STATUS (Status); 00504 } 00505 00506 00507 /******************************************************************************* 00508 * 00509 * FUNCTION: AcpiExCmosSpaceHandler 00510 * 00511 * PARAMETERS: Function - Read or Write operation 00512 * Address - Where in the space to read or write 00513 * BitWidth - Field width in bits (8, 16, or 32) 00514 * Value - Pointer to in or out value 00515 * HandlerContext - Pointer to Handler's context 00516 * RegionContext - Pointer to context specific to the 00517 * accessed region 00518 * 00519 * RETURN: Status 00520 * 00521 * DESCRIPTION: Handler for the CMOS address space (Op Region) 00522 * 00523 ******************************************************************************/ 00524 00525 ACPI_STATUS 00526 AcpiExCmosSpaceHandler ( 00527 UINT32 Function, 00528 ACPI_PHYSICAL_ADDRESS Address, 00529 UINT32 BitWidth, 00530 UINT64 *Value, 00531 void *HandlerContext, 00532 void *RegionContext) 00533 { 00534 ACPI_STATUS Status = AE_OK; 00535 00536 00537 ACPI_FUNCTION_TRACE (ExCmosSpaceHandler); 00538 00539 00540 return_ACPI_STATUS (Status); 00541 } 00542 00543 00544 /******************************************************************************* 00545 * 00546 * FUNCTION: AcpiExPciBarSpaceHandler 00547 * 00548 * PARAMETERS: Function - Read or Write operation 00549 * Address - Where in the space to read or write 00550 * BitWidth - Field width in bits (8, 16, or 32) 00551 * Value - Pointer to in or out value 00552 * HandlerContext - Pointer to Handler's context 00553 * RegionContext - Pointer to context specific to the 00554 * accessed region 00555 * 00556 * RETURN: Status 00557 * 00558 * DESCRIPTION: Handler for the PCI BarTarget address space (Op Region) 00559 * 00560 ******************************************************************************/ 00561 00562 ACPI_STATUS 00563 AcpiExPciBarSpaceHandler ( 00564 UINT32 Function, 00565 ACPI_PHYSICAL_ADDRESS Address, 00566 UINT32 BitWidth, 00567 UINT64 *Value, 00568 void *HandlerContext, 00569 void *RegionContext) 00570 { 00571 ACPI_STATUS Status = AE_OK; 00572 00573 00574 ACPI_FUNCTION_TRACE (ExPciBarSpaceHandler); 00575 00576 00577 return_ACPI_STATUS (Status); 00578 } 00579 00580 00581 /******************************************************************************* 00582 * 00583 * FUNCTION: AcpiExDataTableSpaceHandler 00584 * 00585 * PARAMETERS: Function - Read or Write operation 00586 * Address - Where in the space to read or write 00587 * BitWidth - Field width in bits (8, 16, or 32) 00588 * Value - Pointer to in or out value 00589 * HandlerContext - Pointer to Handler's context 00590 * RegionContext - Pointer to context specific to the 00591 * accessed region 00592 * 00593 * RETURN: Status 00594 * 00595 * DESCRIPTION: Handler for the Data Table address space (Op Region) 00596 * 00597 ******************************************************************************/ 00598 00599 ACPI_STATUS 00600 AcpiExDataTableSpaceHandler ( 00601 UINT32 Function, 00602 ACPI_PHYSICAL_ADDRESS Address, 00603 UINT32 BitWidth, 00604 UINT64 *Value, 00605 void *HandlerContext, 00606 void *RegionContext) 00607 { 00608 ACPI_FUNCTION_TRACE (ExDataTableSpaceHandler); 00609 00610 00611 /* 00612 * Perform the memory read or write. The BitWidth was already 00613 * validated. 00614 */ 00615 switch (Function) 00616 { 00617 case ACPI_READ: 00618 00619 ACPI_MEMCPY (ACPI_CAST_PTR (char, Value), ACPI_PHYSADDR_TO_PTR (Address), 00620 ACPI_DIV_8 (BitWidth)); 00621 break; 00622 00623 case ACPI_WRITE: 00624 00625 ACPI_MEMCPY (ACPI_PHYSADDR_TO_PTR (Address), ACPI_CAST_PTR (char, Value), 00626 ACPI_DIV_8 (BitWidth)); 00627 break; 00628 00629 default: 00630 00631 return_ACPI_STATUS (AE_BAD_PARAMETER); 00632 } 00633 00634 return_ACPI_STATUS (AE_OK); 00635 } 00636 00637 Generated on Sun May 27 2012 04:27:17 for ReactOS by
1.7.6.1
|