Home | History | Annotate | Download | only in BaseIoLibIntrinsic
      1 /** @file
      2   I/O Library. This file has compiler specifics for Microsft C as there is no
      3   ANSI C standard for doing IO.
      4 
      5   MSC - uses intrinsic functions and the optimize will remove the function call
      6   overhead.
      7 
      8   We don't advocate putting compiler specifics in libraries or drivers but there
      9   is no other way to make this work.
     10 
     11   Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
     12   This program and the accompanying materials
     13   are licensed and made available under the terms and conditions of the BSD License
     14   which accompanies this distribution.  The full text of the license may be found at
     15   http://opensource.org/licenses/bsd-license.php.
     16 
     17   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
     18   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
     19 
     20 **/
     21 
     22 
     23 
     24 #include "BaseIoLibIntrinsicInternal.h"
     25 
     26 //
     27 // Microsoft Visual Studio 7.1 Function Prototypes for I/O Intrinsics.
     28 //
     29 
     30 int            _inp (unsigned short port);
     31 unsigned short _inpw (unsigned short port);
     32 unsigned long  _inpd (unsigned short port);
     33 int            _outp (unsigned short port, int databyte );
     34 unsigned short _outpw (unsigned short port, unsigned short dataword );
     35 unsigned long  _outpd (unsigned short port, unsigned long dataword );
     36 void          _ReadWriteBarrier (void);
     37 
     38 #pragma intrinsic(_inp)
     39 #pragma intrinsic(_inpw)
     40 #pragma intrinsic(_inpd)
     41 #pragma intrinsic(_outp)
     42 #pragma intrinsic(_outpw)
     43 #pragma intrinsic(_outpd)
     44 #pragma intrinsic(_ReadWriteBarrier)
     45 
     46 //
     47 // _ReadWriteBarrier() forces memory reads and writes to complete at the point
     48 // in the call. This is only a hint to the compiler and does emit code.
     49 // In past versions of the compiler, _ReadWriteBarrier was enforced only
     50 // locally and did not affect functions up the call tree. In Visual C++
     51 // 2005, _ReadWriteBarrier is enforced all the way up the call tree.
     52 //
     53 
     54 /**
     55   Reads an 8-bit I/O port.
     56 
     57   Reads the 8-bit I/O port specified by Port. The 8-bit read value is returned.
     58   This function must guarantee that all I/O read and write operations are
     59   serialized.
     60 
     61   If 8-bit I/O port operations are not supported, then ASSERT().
     62 
     63   @param  Port  The I/O port to read.
     64 
     65   @return The value read.
     66 
     67 **/
     68 UINT8
     69 EFIAPI
     70 IoRead8 (
     71   IN      UINTN                     Port
     72   )
     73 {
     74   UINT8                             Value;
     75 
     76   _ReadWriteBarrier ();
     77   Value = (UINT8)_inp ((UINT16)Port);
     78   _ReadWriteBarrier ();
     79   return Value;
     80 }
     81 
     82 /**
     83   Writes an 8-bit I/O port.
     84 
     85   Writes the 8-bit I/O port specified by Port with the value specified by Value
     86   and returns Value. This function must guarantee that all I/O read and write
     87   operations are serialized.
     88 
     89   If 8-bit I/O port operations are not supported, then ASSERT().
     90 
     91   @param  Port  The I/O port to write.
     92   @param  Value The value to write to the I/O port.
     93 
     94   @return The value written to the I/O port.
     95 
     96 **/
     97 UINT8
     98 EFIAPI
     99 IoWrite8 (
    100   IN      UINTN                     Port,
    101   IN      UINT8                     Value
    102   )
    103 {
    104   _ReadWriteBarrier ();
    105   (UINT8)_outp ((UINT16)Port, Value);
    106   _ReadWriteBarrier ();
    107   return Value;
    108 }
    109 
    110 /**
    111   Reads a 16-bit I/O port.
    112 
    113   Reads the 16-bit I/O port specified by Port. The 16-bit read value is returned.
    114   This function must guarantee that all I/O read and write operations are
    115   serialized.
    116 
    117   If 16-bit I/O port operations are not supported, then ASSERT().
    118   If Port is not aligned on a 16-bit boundary, then ASSERT().
    119 
    120   @param  Port  The I/O port to read.
    121 
    122   @return The value read.
    123 
    124 **/
    125 UINT16
    126 EFIAPI
    127 IoRead16 (
    128   IN      UINTN                     Port
    129   )
    130 {
    131   UINT16                            Value;
    132 
    133   ASSERT ((Port & 1) == 0);
    134   _ReadWriteBarrier ();
    135   Value = _inpw ((UINT16)Port);
    136   _ReadWriteBarrier ();
    137   return Value;
    138 }
    139 
    140 /**
    141   Writes a 16-bit I/O port.
    142 
    143   Writes the 16-bit I/O port specified by Port with the value specified by Value
    144   and returns Value. This function must guarantee that all I/O read and write
    145   operations are serialized.
    146 
    147   If 16-bit I/O port operations are not supported, then ASSERT().
    148   If Port is not aligned on a 16-bit boundary, then ASSERT().
    149 
    150   @param  Port  The I/O port to write.
    151   @param  Value The value to write to the I/O port.
    152 
    153   @return The value written to the I/O port.
    154 
    155 **/
    156 UINT16
    157 EFIAPI
    158 IoWrite16 (
    159   IN      UINTN                     Port,
    160   IN      UINT16                    Value
    161   )
    162 {
    163   ASSERT ((Port & 1) == 0);
    164   _ReadWriteBarrier ();
    165   _outpw ((UINT16)Port, Value);
    166   _ReadWriteBarrier ();
    167   return Value;
    168 }
    169 
    170 /**
    171   Reads a 32-bit I/O port.
    172 
    173   Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.
    174   This function must guarantee that all I/O read and write operations are
    175   serialized.
    176 
    177   If 32-bit I/O port operations are not supported, then ASSERT().
    178   If Port is not aligned on a 32-bit boundary, then ASSERT().
    179 
    180   @param  Port  The I/O port to read.
    181 
    182   @return The value read.
    183 
    184 **/
    185 UINT32
    186 EFIAPI
    187 IoRead32 (
    188   IN      UINTN                     Port
    189   )
    190 {
    191   UINT32                            Value;
    192 
    193   ASSERT ((Port & 3) == 0);
    194   _ReadWriteBarrier ();
    195   Value = _inpd ((UINT16)Port);
    196   _ReadWriteBarrier ();
    197   return Value;
    198 }
    199 
    200 /**
    201   Writes a 32-bit I/O port.
    202 
    203   Writes the 32-bit I/O port specified by Port with the value specified by Value
    204   and returns Value. This function must guarantee that all I/O read and write
    205   operations are serialized.
    206 
    207   If 32-bit I/O port operations are not supported, then ASSERT().
    208   If Port is not aligned on a 32-bit boundary, then ASSERT().
    209 
    210   @param  Port  The I/O port to write.
    211   @param  Value The value to write to the I/O port.
    212 
    213   @return The value written to the I/O port.
    214 
    215 **/
    216 UINT32
    217 EFIAPI
    218 IoWrite32 (
    219   IN      UINTN                     Port,
    220   IN      UINT32                    Value
    221   )
    222 {
    223   ASSERT ((Port & 3) == 0);
    224   _ReadWriteBarrier ();
    225   _outpd ((UINT16)Port, Value);
    226   _ReadWriteBarrier ();
    227   return Value;
    228 }
    229