ReactOS Fundraising Campaign 2012
 
€ 3,873 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

hwvalid.c
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003  *
00004  * Module Name: hwvalid - I/O request validation
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 #define __HWVALID_C__
00118 
00119 #include "acpi.h"
00120 #include "accommon.h"
00121 
00122 #define _COMPONENT          ACPI_HARDWARE
00123         ACPI_MODULE_NAME    ("hwvalid")
00124 
00125 /* Local prototypes */
00126 
00127 static ACPI_STATUS
00128 AcpiHwValidateIoRequest (
00129     ACPI_IO_ADDRESS         Address,
00130     UINT32                  BitWidth);
00131 
00132 
00133 /*
00134  * Protected I/O ports. Some ports are always illegal, and some are
00135  * conditionally illegal. This table must remain ordered by port address.
00136  *
00137  * The table is used to implement the Microsoft port access rules that
00138  * first appeared in Windows XP. Some ports are always illegal, and some
00139  * ports are only illegal if the BIOS calls _OSI with a WinXP string or
00140  * later (meaning that the BIOS itelf is post-XP.)
00141  *
00142  * This provides ACPICA with the desired port protections and
00143  * Microsoft compatibility.
00144  *
00145  * Description of port entries:
00146  *  DMA:   DMA controller
00147  *  PIC0:  Programmable Interrupt Controller (8259A)
00148  *  PIT1:  System Timer 1
00149  *  PIT2:  System Timer 2 failsafe
00150  *  RTC:   Real-time clock
00151  *  CMOS:  Extended CMOS
00152  *  DMA1:  DMA 1 page registers
00153  *  DMA1L: DMA 1 Ch 0 low page
00154  *  DMA2:  DMA 2 page registers
00155  *  DMA2L: DMA 2 low page refresh
00156  *  ARBC:  Arbitration control
00157  *  SETUP: Reserved system board setup
00158  *  POS:   POS channel select
00159  *  PIC1:  Cascaded PIC
00160  *  IDMA:  ISA DMA
00161  *  ELCR:  PIC edge/level registers
00162  *  PCI:   PCI configuration space
00163  */
00164 static const ACPI_PORT_INFO     AcpiProtectedPorts[] =
00165 {
00166     {"DMA",     0x0000, 0x000F, ACPI_OSI_WIN_XP},
00167     {"PIC0",    0x0020, 0x0021, ACPI_ALWAYS_ILLEGAL},
00168     {"PIT1",    0x0040, 0x0043, ACPI_OSI_WIN_XP},
00169     {"PIT2",    0x0048, 0x004B, ACPI_OSI_WIN_XP},
00170     {"RTC",     0x0070, 0x0071, ACPI_OSI_WIN_XP},
00171     {"CMOS",    0x0074, 0x0076, ACPI_OSI_WIN_XP},
00172     {"DMA1",    0x0081, 0x0083, ACPI_OSI_WIN_XP},
00173     {"DMA1L",   0x0087, 0x0087, ACPI_OSI_WIN_XP},
00174     {"DMA2",    0x0089, 0x008B, ACPI_OSI_WIN_XP},
00175     {"DMA2L",   0x008F, 0x008F, ACPI_OSI_WIN_XP},
00176     {"ARBC",    0x0090, 0x0091, ACPI_OSI_WIN_XP},
00177     {"SETUP",   0x0093, 0x0094, ACPI_OSI_WIN_XP},
00178     {"POS",     0x0096, 0x0097, ACPI_OSI_WIN_XP},
00179     {"PIC1",    0x00A0, 0x00A1, ACPI_ALWAYS_ILLEGAL},
00180     {"IDMA",    0x00C0, 0x00DF, ACPI_OSI_WIN_XP},
00181     {"ELCR",    0x04D0, 0x04D1, ACPI_ALWAYS_ILLEGAL},
00182     {"PCI",     0x0CF8, 0x0CFF, ACPI_OSI_WIN_XP}
00183 };
00184 
00185 #define ACPI_PORT_INFO_ENTRIES  ACPI_ARRAY_LENGTH (AcpiProtectedPorts)
00186 
00187 
00188 /******************************************************************************
00189  *
00190  * FUNCTION:    AcpiHwValidateIoRequest
00191  *
00192  * PARAMETERS:  Address             Address of I/O port/register
00193  *              BitWidth            Number of bits (8,16,32)
00194  *
00195  * RETURN:      Status
00196  *
00197  * DESCRIPTION: Validates an I/O request (address/length). Certain ports are
00198  *              always illegal and some ports are only illegal depending on
00199  *              the requests the BIOS AML code makes to the predefined
00200  *              _OSI method.
00201  *
00202  ******************************************************************************/
00203 
00204 static ACPI_STATUS
00205 AcpiHwValidateIoRequest (
00206     ACPI_IO_ADDRESS         Address,
00207     UINT32                  BitWidth)
00208 {
00209     UINT32                  i;
00210     UINT32                  ByteWidth;
00211     ACPI_IO_ADDRESS         LastAddress;
00212     const ACPI_PORT_INFO    *PortInfo;
00213 
00214 
00215     ACPI_FUNCTION_TRACE (HwValidateIoRequest);
00216 
00217 
00218     /* Supported widths are 8/16/32 */
00219 
00220     if ((BitWidth != 8) &&
00221         (BitWidth != 16) &&
00222         (BitWidth != 32))
00223     {
00224         return (AE_BAD_PARAMETER);
00225     }
00226 
00227     PortInfo = AcpiProtectedPorts;
00228     ByteWidth = ACPI_DIV_8 (BitWidth);
00229     LastAddress = Address + ByteWidth - 1;
00230 
00231     ACPI_DEBUG_PRINT ((ACPI_DB_IO, "Address %p LastAddress %p Length %X",
00232         ACPI_CAST_PTR (void, Address), ACPI_CAST_PTR (void, LastAddress),
00233         ByteWidth));
00234 
00235     /* Maximum 16-bit address in I/O space */
00236 
00237     if (LastAddress > ACPI_UINT16_MAX)
00238     {
00239         ACPI_ERROR ((AE_INFO,
00240             "Illegal I/O port address/length above 64K: %p/0x%X",
00241             ACPI_CAST_PTR (void, Address), ByteWidth));
00242         return_ACPI_STATUS (AE_LIMIT);
00243     }
00244 
00245     /* Exit if requested address is not within the protected port table */
00246 
00247     if (Address > AcpiProtectedPorts[ACPI_PORT_INFO_ENTRIES - 1].End)
00248     {
00249         return_ACPI_STATUS (AE_OK);
00250     }
00251 
00252     /* Check request against the list of protected I/O ports */
00253 
00254     for (i = 0; i < ACPI_PORT_INFO_ENTRIES; i++, PortInfo++)
00255     {
00256         /*
00257          * Check if the requested address range will write to a reserved
00258          * port. Four cases to consider:
00259          *
00260          * 1) Address range is contained completely in the port address range
00261          * 2) Address range overlaps port range at the port range start
00262          * 3) Address range overlaps port range at the port range end
00263          * 4) Address range completely encompasses the port range
00264          */
00265         if ((Address <= PortInfo->End) && (LastAddress >= PortInfo->Start))
00266         {
00267             /* Port illegality may depend on the _OSI calls made by the BIOS */
00268 
00269             if (AcpiGbl_OsiData >= PortInfo->OsiDependency)
00270             {
00271                 ACPI_DEBUG_PRINT ((ACPI_DB_IO,
00272                     "Denied AML access to port 0x%p/%X (%s 0x%.4X-0x%.4X)",
00273                     ACPI_CAST_PTR (void, Address), ByteWidth, PortInfo->Name,
00274                     PortInfo->Start, PortInfo->End));
00275 
00276                 return_ACPI_STATUS (AE_AML_ILLEGAL_ADDRESS);
00277             }
00278         }
00279 
00280         /* Finished if address range ends before the end of this port */
00281 
00282         if (LastAddress <= PortInfo->End)
00283         {
00284             break;
00285         }
00286     }
00287 
00288     return_ACPI_STATUS (AE_OK);
00289 }
00290 
00291 
00292 /******************************************************************************
00293  *
00294  * FUNCTION:    AcpiHwReadPort
00295  *
00296  * PARAMETERS:  Address             Address of I/O port/register to read
00297  *              Value               Where value is placed
00298  *              Width               Number of bits
00299  *
00300  * RETURN:      Status and value read from port
00301  *
00302  * DESCRIPTION: Read data from an I/O port or register. This is a front-end
00303  *              to AcpiOsReadPort that performs validation on both the port
00304  *              address and the length.
00305  *
00306  *****************************************************************************/
00307 
00308 ACPI_STATUS
00309 AcpiHwReadPort (
00310     ACPI_IO_ADDRESS         Address,
00311     UINT32                  *Value,
00312     UINT32                  Width)
00313 {
00314     ACPI_STATUS             Status;
00315     UINT32                  OneByte;
00316     UINT32                  i;
00317 
00318 
00319     /* Truncate address to 16 bits if requested */
00320 
00321     if (AcpiGbl_TruncateIoAddresses)
00322     {
00323         Address &= ACPI_UINT16_MAX;
00324     }
00325 
00326     /* Validate the entire request and perform the I/O */
00327 
00328     Status = AcpiHwValidateIoRequest (Address, Width);
00329     if (ACPI_SUCCESS (Status))
00330     {
00331         Status = AcpiOsReadPort (Address, Value, Width);
00332         return (Status);
00333     }
00334 
00335     if (Status != AE_AML_ILLEGAL_ADDRESS)
00336     {
00337         return (Status);
00338     }
00339 
00340     /*
00341      * There has been a protection violation within the request. Fall
00342      * back to byte granularity port I/O and ignore the failing bytes.
00343      * This provides Windows compatibility.
00344      */
00345     for (i = 0, *Value = 0; i < Width; i += 8)
00346     {
00347         /* Validate and read one byte */
00348 
00349         if (AcpiHwValidateIoRequest (Address, 8) == AE_OK)
00350         {
00351             Status = AcpiOsReadPort (Address, &OneByte, 8);
00352             if (ACPI_FAILURE (Status))
00353             {
00354                 return (Status);
00355             }
00356 
00357             *Value |= (OneByte << i);
00358         }
00359 
00360         Address++;
00361     }
00362 
00363     return (AE_OK);
00364 }
00365 
00366 
00367 /******************************************************************************
00368  *
00369  * FUNCTION:    AcpiHwWritePort
00370  *
00371  * PARAMETERS:  Address             Address of I/O port/register to write
00372  *              Value               Value to write
00373  *              Width               Number of bits
00374  *
00375  * RETURN:      Status
00376  *
00377  * DESCRIPTION: Write data to an I/O port or register. This is a front-end
00378  *              to AcpiOsWritePort that performs validation on both the port
00379  *              address and the length.
00380  *
00381  *****************************************************************************/
00382 
00383 ACPI_STATUS
00384 AcpiHwWritePort (
00385     ACPI_IO_ADDRESS         Address,
00386     UINT32                  Value,
00387     UINT32                  Width)
00388 {
00389     ACPI_STATUS             Status;
00390     UINT32                  i;
00391 
00392 
00393     /* Truncate address to 16 bits if requested */
00394 
00395     if (AcpiGbl_TruncateIoAddresses)
00396     {
00397         Address &= ACPI_UINT16_MAX;
00398     }
00399 
00400     /* Validate the entire request and perform the I/O */
00401 
00402     Status = AcpiHwValidateIoRequest (Address, Width);
00403     if (ACPI_SUCCESS (Status))
00404     {
00405         Status = AcpiOsWritePort (Address, Value, Width);
00406         return (Status);
00407     }
00408 
00409     if (Status != AE_AML_ILLEGAL_ADDRESS)
00410     {
00411         return (Status);
00412     }
00413 
00414     /*
00415      * There has been a protection violation within the request. Fall
00416      * back to byte granularity port I/O and ignore the failing bytes.
00417      * This provides Windows compatibility.
00418      */
00419     for (i = 0; i < Width; i += 8)
00420     {
00421         /* Validate and write one byte */
00422 
00423         if (AcpiHwValidateIoRequest (Address, 8) == AE_OK)
00424         {
00425             Status = AcpiOsWritePort (Address, (Value >> i) & 0xFF, 8);
00426             if (ACPI_FAILURE (Status))
00427             {
00428                 return (Status);
00429             }
00430         }
00431 
00432         Address++;
00433     }
00434 
00435     return (AE_OK);
00436 }
00437 
00438 

Generated on Sat May 19 2012 04:25:14 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.