Back to home page

Quest Cross Reference

 
 

    


Warning, cross-references for /kernel/drivers/acpica/exregion.c need to be fixed.

0001 
0002 /******************************************************************************
0003  *
0004  * Module Name: exregion - ACPI default OpRegion (address space) handlers
0005  *
0006  *****************************************************************************/
0007 
0008 /******************************************************************************
0009  *
0010  * 1. Copyright Notice
0011  *
0012  * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp.
0013  * All rights reserved.
0014  *
0015  * 2. License
0016  *
0017  * 2.1. This is your license from Intel Corp. under its intellectual property
0018  * rights.  You may have additional license terms from the party that provided
0019  * you this software, covering your right to use that party's intellectual
0020  * property rights.
0021  *
0022  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
0023  * copy of the source code appearing in this file ("Covered Code") an
0024  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
0025  * base code distributed originally by Intel ("Original Intel Code") to copy,
0026  * make derivatives, distribute, use and display any portion of the Covered
0027  * Code in any form, with the right to sublicense such rights; and
0028  *
0029  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
0030  * license (with the right to sublicense), under only those claims of Intel
0031  * patents that are infringed by the Original Intel Code, to make, use, sell,
0032  * offer to sell, and import the Covered Code and derivative works thereof
0033  * solely to the minimum extent necessary to exercise the above copyright
0034  * license, and in no event shall the patent license extend to any additions
0035  * to or modifications of the Original Intel Code.  No other license or right
0036  * is granted directly or by implication, estoppel or otherwise;
0037  *
0038  * The above copyright and patent license is granted only if the following
0039  * conditions are met:
0040  *
0041  * 3. Conditions
0042  *
0043  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
0044  * Redistribution of source code of any substantial portion of the Covered
0045  * Code or modification with rights to further distribute source must include
0046  * the above Copyright Notice, the above License, this list of Conditions,
0047  * and the following Disclaimer and Export Compliance provision.  In addition,
0048  * Licensee must cause all Covered Code to which Licensee contributes to
0049  * contain a file documenting the changes Licensee made to create that Covered
0050  * Code and the date of any change.  Licensee must include in that file the
0051  * documentation of any changes made by any predecessor Licensee.  Licensee
0052  * must include a prominent statement that the modification is derived,
0053  * directly or indirectly, from Original Intel Code.
0054  *
0055  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
0056  * Redistribution of source code of any substantial portion of the Covered
0057  * Code or modification without rights to further distribute source must
0058  * include the following Disclaimer and Export Compliance provision in the
0059  * documentation and/or other materials provided with distribution.  In
0060  * addition, Licensee may not authorize further sublicense of source of any
0061  * portion of the Covered Code, and must include terms to the effect that the
0062  * license from Licensee to its licensee is limited to the intellectual
0063  * property embodied in the software Licensee provides to its licensee, and
0064  * not to intellectual property embodied in modifications its licensee may
0065  * make.
0066  *
0067  * 3.3. Redistribution of Executable. Redistribution in executable form of any
0068  * substantial portion of the Covered Code or modification must reproduce the
0069  * above Copyright Notice, and the following Disclaimer and Export Compliance
0070  * provision in the documentation and/or other materials provided with the
0071  * distribution.
0072  *
0073  * 3.4. Intel retains all right, title, and interest in and to the Original
0074  * Intel Code.
0075  *
0076  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
0077  * Intel shall be used in advertising or otherwise to promote the sale, use or
0078  * other dealings in products derived from or relating to the Covered Code
0079  * without prior written authorization from Intel.
0080  *
0081  * 4. Disclaimer and Export Compliance
0082  *
0083  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
0084  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
0085  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
0086  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
0087  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
0088  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
0089  * PARTICULAR PURPOSE.
0090  *
0091  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
0092  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
0093  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
0094  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
0095  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
0096  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
0097  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
0098  * LIMITED REMEDY.
0099  *
0100  * 4.3. Licensee shall not export, either directly or indirectly, any of this
0101  * software or system incorporating such software without first obtaining any
0102  * required license or other approval from the U. S. Department of Commerce or
0103  * any other agency or department of the United States Government.  In the
0104  * event Licensee exports any such software from the United States or
0105  * re-exports any such software from a foreign destination, Licensee shall
0106  * ensure that the distribution and export/re-export of the software is in
0107  * compliance with all laws, regulations, orders, or other restrictions of the
0108  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
0109  * any of its subsidiaries will export/re-export any technical data, process,
0110  * software, or service, directly or indirectly, to any country for which the
0111  * United States government or any agency thereof requires an export license,
0112  * other governmental approval, or letter of assurance, without first obtaining
0113  * such license, approval or letter.
0114  *
0115  *****************************************************************************/
0116 
0117 
0118 #define __EXREGION_C__
0119 
0120 #include "acpi.h"
0121 #include "accommon.h"
0122 #include "acinterp.h"
0123 
0124 
0125 #define _COMPONENT          ACPI_EXECUTER
0126         ACPI_MODULE_NAME    ("exregion")
0127 
0128 
0129 /*******************************************************************************
0130  *
0131  * FUNCTION:    AcpiExSystemMemorySpaceHandler
0132  *
0133  * PARAMETERS:  Function            - Read or Write operation
0134  *              Address             - Where in the space to read or write
0135  *              BitWidth            - Field width in bits (8, 16, or 32)
0136  *              Value               - Pointer to in or out value
0137  *              HandlerContext      - Pointer to Handler's context
0138  *              RegionContext       - Pointer to context specific to the
0139  *                                    accessed region
0140  *
0141  * RETURN:      Status
0142  *
0143  * DESCRIPTION: Handler for the System Memory address space (Op Region)
0144  *
0145  ******************************************************************************/
0146 
0147 ACPI_STATUS
0148 AcpiExSystemMemorySpaceHandler (
0149     UINT32                  Function,
0150     ACPI_PHYSICAL_ADDRESS   Address,
0151     UINT32                  BitWidth,
0152     ACPI_INTEGER            *Value,
0153     void                    *HandlerContext,
0154     void                    *RegionContext)
0155 {
0156     ACPI_STATUS             Status = AE_OK;
0157     void                    *LogicalAddrPtr = NULL;
0158     ACPI_MEM_SPACE_CONTEXT  *MemInfo = RegionContext;
0159     UINT32                  Length;
0160     ACPI_SIZE               WindowSize;
0161 #ifdef ACPI_MISALIGNMENT_NOT_SUPPORTED
0162     UINT32                  Remainder;
0163 #endif
0164 
0165 
0166     ACPI_FUNCTION_TRACE (ExSystemMemorySpaceHandler);
0167 
0168 
0169     /* Validate and translate the bit width */
0170 
0171     switch (BitWidth)
0172     {
0173     case 8:
0174         Length = 1;
0175         break;
0176 
0177     case 16:
0178         Length = 2;
0179         break;
0180 
0181     case 32:
0182         Length = 4;
0183         break;
0184 
0185     case 64:
0186         Length = 8;
0187         break;
0188 
0189     default:
0190         ACPI_ERROR ((AE_INFO, "Invalid SystemMemory width %d",
0191             BitWidth));
0192         return_ACPI_STATUS (AE_AML_OPERAND_VALUE);
0193     }
0194 
0195 #ifdef ACPI_MISALIGNMENT_NOT_SUPPORTED
0196     /*
0197      * Hardware does not support non-aligned data transfers, we must verify
0198      * the request.
0199      */
0200     (void) AcpiUtShortDivide ((ACPI_INTEGER) Address, Length, NULL, &Remainder);
0201     if (Remainder != 0)
0202     {
0203         return_ACPI_STATUS (AE_AML_ALIGNMENT);
0204     }
0205 #endif
0206 
0207     /*
0208      * Does the request fit into the cached memory mapping?
0209      * Is 1) Address below the current mapping? OR
0210      *    2) Address beyond the current mapping?
0211      */
0212     if ((Address < MemInfo->MappedPhysicalAddress) ||
0213         (((ACPI_INTEGER) Address + Length) >
0214             ((ACPI_INTEGER)
0215             MemInfo->MappedPhysicalAddress + MemInfo->MappedLength)))
0216     {
0217         /*
0218          * The request cannot be resolved by the current memory mapping;
0219          * Delete the existing mapping and create a new one.
0220          */
0221         if (MemInfo->MappedLength)
0222         {
0223             /* Valid mapping, delete it */
0224 
0225             AcpiOsUnmapMemory (MemInfo->MappedLogicalAddress,
0226                 MemInfo->MappedLength);
0227         }
0228 
0229         /*
0230          * Don't attempt to map memory beyond the end of the region, and
0231          * constrain the maximum mapping size to something reasonable.
0232          */
0233         WindowSize = (ACPI_SIZE)
0234             ((MemInfo->Address + MemInfo->Length) - Address);
0235 
0236         if (WindowSize > ACPI_SYSMEM_REGION_WINDOW_SIZE)
0237         {
0238             WindowSize = ACPI_SYSMEM_REGION_WINDOW_SIZE;
0239         }
0240 
0241         /* Create a new mapping starting at the address given */
0242 
0243         MemInfo->MappedLogicalAddress = AcpiOsMapMemory (
0244             (ACPI_PHYSICAL_ADDRESS) Address, WindowSize);
0245         if (!MemInfo->MappedLogicalAddress)
0246         {
0247             ACPI_ERROR ((AE_INFO,
0248                 "Could not map memory at %8.8X%8.8X, size %X",
0249                 ACPI_FORMAT_NATIVE_UINT (Address), (UINT32) WindowSize));
0250             MemInfo->MappedLength = 0;
0251             return_ACPI_STATUS (AE_NO_MEMORY);
0252         }
0253 
0254         /* Save the physical address and mapping size */
0255 
0256         MemInfo->MappedPhysicalAddress = Address;
0257         MemInfo->MappedLength = WindowSize;
0258     }
0259 
0260     /*
0261      * Generate a logical pointer corresponding to the address we want to
0262      * access
0263      */
0264     LogicalAddrPtr = MemInfo->MappedLogicalAddress +
0265         ((ACPI_INTEGER) Address - (ACPI_INTEGER) MemInfo->MappedPhysicalAddress);
0266 
0267     ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
0268         "System-Memory (width %d) R/W %d Address=%8.8X%8.8X\n",
0269         BitWidth, Function, ACPI_FORMAT_NATIVE_UINT (Address)));
0270 
0271     /*
0272      * Perform the memory read or write
0273      *
0274      * Note: For machines that do not support non-aligned transfers, the target
0275      * address was checked for alignment above.  We do not attempt to break the
0276      * transfer up into smaller (byte-size) chunks because the AML specifically
0277      * asked for a transfer width that the hardware may require.
0278      */
0279     switch (Function)
0280     {
0281     case ACPI_READ:
0282 
0283         *Value = 0;
0284         switch (BitWidth)
0285         {
0286         case 8:
0287             *Value = (ACPI_INTEGER) ACPI_GET8 (LogicalAddrPtr);
0288             break;
0289 
0290         case 16:
0291             *Value = (ACPI_INTEGER) ACPI_GET16 (LogicalAddrPtr);
0292             break;
0293 
0294         case 32:
0295             *Value = (ACPI_INTEGER) ACPI_GET32 (LogicalAddrPtr);
0296             break;
0297 
0298         case 64:
0299             *Value = (ACPI_INTEGER) ACPI_GET64 (LogicalAddrPtr);
0300             break;
0301 
0302         default:
0303             /* BitWidth was already validated */
0304             break;
0305         }
0306         break;
0307 
0308     case ACPI_WRITE:
0309 
0310         switch (BitWidth)
0311         {
0312         case 8:
0313             ACPI_SET8 (LogicalAddrPtr) = (UINT8) *Value;
0314             break;
0315 
0316         case 16:
0317             ACPI_SET16 (LogicalAddrPtr) = (UINT16) *Value;
0318             break;
0319 
0320         case 32:
0321             ACPI_SET32 ( LogicalAddrPtr) = (UINT32) *Value;
0322             break;
0323 
0324         case 64:
0325             ACPI_SET64 (LogicalAddrPtr) = (UINT64) *Value;
0326             break;
0327 
0328         default:
0329             /* BitWidth was already validated */
0330             break;
0331         }
0332         break;
0333 
0334     default:
0335         Status = AE_BAD_PARAMETER;
0336         break;
0337     }
0338 
0339     return_ACPI_STATUS (Status);
0340 }
0341 
0342 
0343 /*******************************************************************************
0344  *
0345  * FUNCTION:    AcpiExSystemIoSpaceHandler
0346  *
0347  * PARAMETERS:  Function            - Read or Write operation
0348  *              Address             - Where in the space to read or write
0349  *              BitWidth            - Field width in bits (8, 16, or 32)
0350  *              Value               - Pointer to in or out value
0351  *              HandlerContext      - Pointer to Handler's context
0352  *              RegionContext       - Pointer to context specific to the
0353  *                                    accessed region
0354  *
0355  * RETURN:      Status
0356  *
0357  * DESCRIPTION: Handler for the System IO address space (Op Region)
0358  *
0359  ******************************************************************************/
0360 
0361 ACPI_STATUS
0362 AcpiExSystemIoSpaceHandler (
0363     UINT32                  Function,
0364     ACPI_PHYSICAL_ADDRESS   Address,
0365     UINT32                  BitWidth,
0366     ACPI_INTEGER            *Value,
0367     void                    *HandlerContext,
0368     void                    *RegionContext)
0369 {
0370     ACPI_STATUS             Status = AE_OK;
0371     UINT32                  Value32;
0372 
0373 
0374     ACPI_FUNCTION_TRACE (ExSystemIoSpaceHandler);
0375 
0376 
0377     ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
0378         "System-IO (width %d) R/W %d Address=%8.8X%8.8X\n",
0379         BitWidth, Function, ACPI_FORMAT_NATIVE_UINT (Address)));
0380 
0381     /* Decode the function parameter */
0382 
0383     switch (Function)
0384     {
0385     case ACPI_READ:
0386 
0387         Status = AcpiHwReadPort ((ACPI_IO_ADDRESS) Address,
0388                     &Value32, BitWidth);
0389         *Value = Value32;
0390         break;
0391 
0392     case ACPI_WRITE:
0393 
0394         Status = AcpiHwWritePort ((ACPI_IO_ADDRESS) Address,
0395                     (UINT32) *Value, BitWidth);
0396         break;
0397 
0398     default:
0399         Status = AE_BAD_PARAMETER;
0400         break;
0401     }
0402 
0403     return_ACPI_STATUS (Status);
0404 }
0405 
0406 
0407 /*******************************************************************************
0408  *
0409  * FUNCTION:    AcpiExPciConfigSpaceHandler
0410  *
0411  * PARAMETERS:  Function            - Read or Write operation
0412  *              Address             - Where in the space to read or write
0413  *              BitWidth            - Field width in bits (8, 16, or 32)
0414  *              Value               - Pointer to in or out value
0415  *              HandlerContext      - Pointer to Handler's context
0416  *              RegionContext       - Pointer to context specific to the
0417  *                                    accessed region
0418  *
0419  * RETURN:      Status
0420  *
0421  * DESCRIPTION: Handler for the PCI Config address space (Op Region)
0422  *
0423  ******************************************************************************/
0424 
0425 ACPI_STATUS
0426 AcpiExPciConfigSpaceHandler (
0427     UINT32                  Function,
0428     ACPI_PHYSICAL_ADDRESS   Address,
0429     UINT32                  BitWidth,
0430     ACPI_INTEGER            *Value,
0431     void                    *HandlerContext,
0432     void                    *RegionContext)
0433 {
0434     ACPI_STATUS             Status = AE_OK;
0435     ACPI_PCI_ID             *PciId;
0436     UINT16                  PciRegister;
0437 
0438 
0439     ACPI_FUNCTION_TRACE (ExPciConfigSpaceHandler);
0440 
0441 
0442     /*
0443      *  The arguments to AcpiOs(Read|Write)PciConfiguration are:
0444      *
0445      *  PciSegment  is the PCI bus segment range 0-31
0446      *  PciBus      is the PCI bus number range 0-255
0447      *  PciDevice   is the PCI device number range 0-31
0448      *  PciFunction is the PCI device function number
0449      *  PciRegister is the Config space register range 0-255 bytes
0450      *
0451      *  Value - input value for write, output address for read
0452      *
0453      */
0454     PciId       = (ACPI_PCI_ID *) RegionContext;
0455     PciRegister = (UINT16) (UINT32) Address;
0456 
0457     ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
0458         "Pci-Config %d (%d) Seg(%04x) Bus(%04x) Dev(%04x) Func(%04x) Reg(%04x)\n",
0459         Function, BitWidth, PciId->Segment, PciId->Bus, PciId->Device,
0460         PciId->Function, PciRegister));
0461 
0462     switch (Function)
0463     {
0464     case ACPI_READ:
0465 
0466         *Value = 0;
0467         Status = AcpiOsReadPciConfiguration (PciId, PciRegister,
0468                     Value, BitWidth);
0469         break;
0470 
0471     case ACPI_WRITE:
0472 
0473         Status = AcpiOsWritePciConfiguration (PciId, PciRegister,
0474                     *Value, BitWidth);
0475         break;
0476 
0477     default:
0478 
0479         Status = AE_BAD_PARAMETER;
0480         break;
0481     }
0482 
0483     return_ACPI_STATUS (Status);
0484 }
0485 
0486 
0487 /*******************************************************************************
0488  *
0489  * FUNCTION:    AcpiExCmosSpaceHandler
0490  *
0491  * PARAMETERS:  Function            - Read or Write operation
0492  *              Address             - Where in the space to read or write
0493  *              BitWidth            - Field width in bits (8, 16, or 32)
0494  *              Value               - Pointer to in or out value
0495  *              HandlerContext      - Pointer to Handler's context
0496  *              RegionContext       - Pointer to context specific to the
0497  *                                    accessed region
0498  *
0499  * RETURN:      Status
0500  *
0501  * DESCRIPTION: Handler for the CMOS address space (Op Region)
0502  *
0503  ******************************************************************************/
0504 
0505 ACPI_STATUS
0506 AcpiExCmosSpaceHandler (
0507     UINT32                  Function,
0508     ACPI_PHYSICAL_ADDRESS   Address,
0509     UINT32                  BitWidth,
0510     ACPI_INTEGER            *Value,
0511     void                    *HandlerContext,
0512     void                    *RegionContext)
0513 {
0514     ACPI_STATUS             Status = AE_OK;
0515 
0516 
0517     ACPI_FUNCTION_TRACE (ExCmosSpaceHandler);
0518 
0519 
0520     return_ACPI_STATUS (Status);
0521 }
0522 
0523 
0524 /*******************************************************************************
0525  *
0526  * FUNCTION:    AcpiExPciBarSpaceHandler
0527  *
0528  * PARAMETERS:  Function            - Read or Write operation
0529  *              Address             - Where in the space to read or write
0530  *              BitWidth            - Field width in bits (8, 16, or 32)
0531  *              Value               - Pointer to in or out value
0532  *              HandlerContext      - Pointer to Handler's context
0533  *              RegionContext       - Pointer to context specific to the
0534  *                                    accessed region
0535  *
0536  * RETURN:      Status
0537  *
0538  * DESCRIPTION: Handler for the PCI BarTarget address space (Op Region)
0539  *
0540  ******************************************************************************/
0541 
0542 ACPI_STATUS
0543 AcpiExPciBarSpaceHandler (
0544     UINT32                  Function,
0545     ACPI_PHYSICAL_ADDRESS   Address,
0546     UINT32                  BitWidth,
0547     ACPI_INTEGER            *Value,
0548     void                    *HandlerContext,
0549     void                    *RegionContext)
0550 {
0551     ACPI_STATUS             Status = AE_OK;
0552 
0553 
0554     ACPI_FUNCTION_TRACE (ExPciBarSpaceHandler);
0555 
0556 
0557     return_ACPI_STATUS (Status);
0558 }
0559 
0560 
0561 /*******************************************************************************
0562  *
0563  * FUNCTION:    AcpiExDataTableSpaceHandler
0564  *
0565  * PARAMETERS:  Function            - Read or Write operation
0566  *              Address             - Where in the space to read or write
0567  *              BitWidth            - Field width in bits (8, 16, or 32)
0568  *              Value               - Pointer to in or out value
0569  *              HandlerContext      - Pointer to Handler's context
0570  *              RegionContext       - Pointer to context specific to the
0571  *                                    accessed region
0572  *
0573  * RETURN:      Status
0574  *
0575  * DESCRIPTION: Handler for the Data Table address space (Op Region)
0576  *
0577  ******************************************************************************/
0578 
0579 ACPI_STATUS
0580 AcpiExDataTableSpaceHandler (
0581     UINT32                  Function,
0582     ACPI_PHYSICAL_ADDRESS   Address,
0583     UINT32                  BitWidth,
0584     ACPI_INTEGER            *Value,
0585     void                    *HandlerContext,
0586     void                    *RegionContext)
0587 {
0588     ACPI_FUNCTION_TRACE (ExDataTableSpaceHandler);
0589 
0590 
0591     /* Perform the memory read or write */
0592 
0593     switch (Function)
0594     {
0595     case ACPI_READ:
0596 
0597         ACPI_MEMCPY (ACPI_CAST_PTR (char, Value), ACPI_PHYSADDR_TO_PTR (Address),
0598             ACPI_DIV_8 (BitWidth));
0599         break;
0600 
0601     case ACPI_WRITE:
0602     default:
0603 
0604         return_ACPI_STATUS (AE_SUPPORT);
0605     }
0606 
0607     return_ACPI_STATUS (AE_OK);
0608 }
0609 
0610