Home | History | Annotate | Download | only in WinNtSerialIoDxe
      1 /**@file
      2 
      3 Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>
      4 This program and the accompanying materials
      5 are licensed and made available under the terms and conditions of the BSD License
      6 which accompanies this distribution.  The full text of the license may be found at
      7 http://opensource.org/licenses/bsd-license.php
      8 
      9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
     10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
     11 
     12 Module Name:
     13 
     14   WinNtSerialIo.h
     15 
     16 Abstract:
     17 
     18 
     19 **/
     20 
     21 #ifndef _WIN_NT_SERIAL_IO_
     22 #define _WIN_NT_SERIAL_IO_
     23 
     24 //
     25 // The package level header files this module uses
     26 //
     27 #include <Uefi.h>
     28 #include <WinNtDxe.h>
     29 //
     30 // The protocols, PPI and GUID defintions for this module
     31 //
     32 #include <Protocol/WinNtIo.h>
     33 #include <Protocol/ComponentName.h>
     34 #include <Protocol/SerialIo.h>
     35 #include <Protocol/DriverBinding.h>
     36 #include <Protocol/DevicePath.h>
     37 //
     38 // The Library classes this module consumes
     39 //
     40 #include <Library/DebugLib.h>
     41 #include <Library/BaseLib.h>
     42 #include <Library/UefiDriverEntryPoint.h>
     43 #include <Library/UefiLib.h>
     44 #include <Library/BaseMemoryLib.h>
     45 #include <Library/UefiBootServicesTableLib.h>
     46 #include <Library/DevicePathLib.h>
     47 #include <Library/MemoryAllocationLib.h>
     48 #include <Library/PcdLib.h>
     49 
     50 
     51 #define SERIAL_MAX_BUFFER_SIZE  256
     52 #define TIMEOUT_STALL_INTERVAL  10
     53 
     54 typedef struct {
     55   UINT32  First;
     56   UINT32  Last;
     57   UINT32  Surplus;
     58   UINT8   Data[SERIAL_MAX_BUFFER_SIZE];
     59 } SERIAL_DEV_FIFO;
     60 
     61 #define WIN_NT_SERIAL_IO_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('N', 'T', 's', 'i')
     62 typedef struct {
     63   UINT64                    Signature;
     64 
     65   //
     66   // Protocol data for the new handle we are going to add
     67   //
     68   EFI_HANDLE                Handle;
     69   EFI_SERIAL_IO_PROTOCOL    SerialIo;
     70   EFI_SERIAL_IO_MODE        SerialIoMode;
     71   EFI_DEVICE_PATH_PROTOCOL  *DevicePath;
     72 
     73   //
     74   // Private Data
     75   //
     76   EFI_HANDLE                ControllerHandle;
     77   EFI_DEVICE_PATH_PROTOCOL  *ParentDevicePath;
     78   UART_DEVICE_PATH          UartDevicePath;
     79   EFI_WIN_NT_THUNK_PROTOCOL *WinNtThunk;
     80 
     81   EFI_UNICODE_STRING_TABLE  *ControllerNameTable;
     82 
     83   //
     84   // Private NT type Data;
     85   //
     86   HANDLE                    NtHandle;
     87   DCB                       NtDCB;
     88   DWORD                     NtError;
     89   COMSTAT                   NtComStatus;
     90 
     91   BOOLEAN                   SoftwareLoopbackEnable;
     92   BOOLEAN                   HardwareFlowControl;
     93   BOOLEAN                   HardwareLoopbackEnable;
     94 
     95   SERIAL_DEV_FIFO           Fifo;
     96 
     97 } WIN_NT_SERIAL_IO_PRIVATE_DATA;
     98 
     99 #define WIN_NT_SERIAL_IO_PRIVATE_DATA_FROM_THIS(a) \
    100          CR(a, WIN_NT_SERIAL_IO_PRIVATE_DATA, SerialIo, WIN_NT_SERIAL_IO_PRIVATE_DATA_SIGNATURE)
    101 
    102 //
    103 // Global Protocol Variables
    104 //
    105 extern EFI_DRIVER_BINDING_PROTOCOL   gWinNtSerialIoDriverBinding;
    106 extern EFI_COMPONENT_NAME_PROTOCOL   gWinNtSerialIoComponentName;
    107 extern EFI_COMPONENT_NAME2_PROTOCOL  gWinNtSerialIoComponentName2;
    108 
    109 //
    110 // Macros to convert EFI serial types to NT serial types.
    111 //
    112 
    113 //
    114 // one second
    115 //
    116 #define SERIAL_TIMEOUT_DEFAULT  (1000 * 1000)
    117 #define SERIAL_BAUD_DEFAULT     115200
    118 #define SERIAL_FIFO_DEFAULT     14
    119 #define SERIAL_DATABITS_DEFAULT 8
    120 #define SERIAL_PARITY_DEFAULT   DefaultParity
    121 #define SERIAL_STOPBITS_DEFAULT DefaultStopBits
    122 
    123 #define SERIAL_CONTROL_MASK     (EFI_SERIAL_CLEAR_TO_SEND                | \
    124                                  EFI_SERIAL_DATA_SET_READY               | \
    125                                  EFI_SERIAL_RING_INDICATE                | \
    126                                  EFI_SERIAL_CARRIER_DETECT               | \
    127                                  EFI_SERIAL_REQUEST_TO_SEND              | \
    128                                  EFI_SERIAL_DATA_TERMINAL_READY          | \
    129                                  EFI_SERIAL_HARDWARE_LOOPBACK_ENABLE     | \
    130                                  EFI_SERIAL_SOFTWARE_LOOPBACK_ENABLE     | \
    131                                  EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE | \
    132                                  EFI_SERIAL_INPUT_BUFFER_EMPTY)
    133 
    134 #define ConvertBaud2Nt(x)       (DWORD) x
    135 #define ConvertData2Nt(x)       (BYTE) x
    136 
    137 #define ConvertParity2Nt(x)              \
    138     (BYTE) (                             \
    139     x == DefaultParity ? NOPARITY    :   \
    140     x == NoParity      ? NOPARITY    :   \
    141     x == EvenParity    ? EVENPARITY  :   \
    142     x == OddParity     ? ODDPARITY   :   \
    143     x == MarkParity    ? MARKPARITY  :   \
    144     x == SpaceParity   ? SPACEPARITY : 0 \
    145     )
    146 
    147 #define ConvertStop2Nt(x)                 \
    148     (BYTE) (                                \
    149     x == DefaultParity   ? ONESTOPBIT   :   \
    150     x == OneFiveStopBits ? ONE5STOPBITS :   \
    151     x == TwoStopBits     ? TWOSTOPBITS  : 0 \
    152     )
    153 
    154 #define ConvertTime2Nt(x) ((x) / 1000)
    155 
    156 //
    157 // 115400 baud with rounding errors
    158 //
    159 #define SERIAL_PORT_MAX_BAUD_RATE 115400
    160 
    161 #define SERIAL_PORT_MIN_BAUD_RATE           50
    162 #define SERIAL_PORT_MAX_RECEIVE_FIFO_DEPTH  16
    163 
    164 #define SERIAL_PORT_MIN_TIMEOUT             1         // 1 uS
    165 #define SERIAL_PORT_MAX_TIMEOUT             100000000 // 100 seconds
    166 
    167 //
    168 // Function Prototypes
    169 //
    170 EFI_STATUS
    171 EFIAPI
    172 InitializeWinNtSerialIo (
    173   IN EFI_HANDLE           ImageHandle,
    174   IN EFI_SYSTEM_TABLE     *SystemTable
    175   )
    176 /*++
    177 
    178 Routine Description:
    179 
    180   TODO: Add function description
    181 
    182 Arguments:
    183 
    184   ImageHandle - TODO: add argument description
    185   SystemTable - TODO: add argument description
    186 
    187 Returns:
    188 
    189   TODO: add return values
    190 
    191 --*/
    192 ;
    193 
    194 EFI_STATUS
    195 EFIAPI
    196 WinNtSerialIoDriverBindingSupported (
    197   IN  EFI_DRIVER_BINDING_PROTOCOL     *This,
    198   IN  EFI_HANDLE                      Handle,
    199   IN  EFI_DEVICE_PATH_PROTOCOL        *RemainingDevicePath
    200   )
    201 /*++
    202 
    203 Routine Description:
    204 
    205   TODO: Add function description
    206 
    207 Arguments:
    208 
    209   This                - TODO: add argument description
    210   Handle              - TODO: add argument description
    211   RemainingDevicePath - TODO: add argument description
    212 
    213 Returns:
    214 
    215   TODO: add return values
    216 
    217 --*/
    218 ;
    219 
    220 EFI_STATUS
    221 EFIAPI
    222 WinNtSerialIoDriverBindingStart (
    223   IN  EFI_DRIVER_BINDING_PROTOCOL     *This,
    224   IN  EFI_HANDLE                      Handle,
    225   IN  EFI_DEVICE_PATH_PROTOCOL        *RemainingDevicePath
    226   )
    227 /*++
    228 
    229 Routine Description:
    230 
    231   TODO: Add function description
    232 
    233 Arguments:
    234 
    235   This                - TODO: add argument description
    236   Handle              - TODO: add argument description
    237   RemainingDevicePath - TODO: add argument description
    238 
    239 Returns:
    240 
    241   TODO: add return values
    242 
    243 --*/
    244 ;
    245 
    246 EFI_STATUS
    247 EFIAPI
    248 WinNtSerialIoDriverBindingStop (
    249   IN  EFI_DRIVER_BINDING_PROTOCOL   *This,
    250   IN  EFI_HANDLE                    Handle,
    251   IN  UINTN                         NumberOfChildren,
    252   IN  EFI_HANDLE                    *ChildHandleBuffer
    253   )
    254 /*++
    255 
    256 Routine Description:
    257 
    258   TODO: Add function description
    259 
    260 Arguments:
    261 
    262   This              - TODO: add argument description
    263   Handle            - TODO: add argument description
    264   NumberOfChildren  - TODO: add argument description
    265   ChildHandleBuffer - TODO: add argument description
    266 
    267 Returns:
    268 
    269   TODO: add return values
    270 
    271 --*/
    272 ;
    273 
    274 EFI_STATUS
    275 EFIAPI
    276 WinNtSerialIoReset (
    277   IN EFI_SERIAL_IO_PROTOCOL *This
    278   )
    279 /*++
    280 
    281 Routine Description:
    282 
    283   TODO: Add function description
    284 
    285 Arguments:
    286 
    287   This  - TODO: add argument description
    288 
    289 Returns:
    290 
    291   TODO: add return values
    292 
    293 --*/
    294 ;
    295 
    296 EFI_STATUS
    297 EFIAPI
    298 WinNtSerialIoSetAttributes (
    299   IN EFI_SERIAL_IO_PROTOCOL *This,
    300   IN UINT64                 BaudRate,
    301   IN UINT32                 ReceiveFifoDepth,
    302   IN UINT32                 Timeout,
    303   IN EFI_PARITY_TYPE        Parity,
    304   IN UINT8                  DataBits,
    305   IN EFI_STOP_BITS_TYPE     StopBits
    306   )
    307 /*++
    308 
    309 Routine Description:
    310 
    311   TODO: Add function description
    312 
    313 Arguments:
    314 
    315   This              - TODO: add argument description
    316   BaudRate          - TODO: add argument description
    317   ReceiveFifoDepth  - TODO: add argument description
    318   Timeout           - TODO: add argument description
    319   Parity            - TODO: add argument description
    320   DataBits          - TODO: add argument description
    321   StopBits          - TODO: add argument description
    322 
    323 Returns:
    324 
    325   TODO: add return values
    326 
    327 --*/
    328 ;
    329 
    330 EFI_STATUS
    331 EFIAPI
    332 WinNtSerialIoSetControl (
    333   IN EFI_SERIAL_IO_PROTOCOL *This,
    334   IN UINT32                 Control
    335   )
    336 /*++
    337 
    338 Routine Description:
    339 
    340   TODO: Add function description
    341 
    342 Arguments:
    343 
    344   This    - TODO: add argument description
    345   Control - TODO: add argument description
    346 
    347 Returns:
    348 
    349   TODO: add return values
    350 
    351 --*/
    352 ;
    353 
    354 EFI_STATUS
    355 EFIAPI
    356 WinNtSerialIoGetControl (
    357   IN  EFI_SERIAL_IO_PROTOCOL  *This,
    358   OUT UINT32                  *Control
    359   )
    360 /*++
    361 
    362 Routine Description:
    363 
    364   TODO: Add function description
    365 
    366 Arguments:
    367 
    368   This    - TODO: add argument description
    369   Control - TODO: add argument description
    370 
    371 Returns:
    372 
    373   TODO: add return values
    374 
    375 --*/
    376 ;
    377 
    378 EFI_STATUS
    379 EFIAPI
    380 WinNtSerialIoWrite (
    381   IN EFI_SERIAL_IO_PROTOCOL   *This,
    382   IN OUT UINTN                *BufferSize,
    383   IN VOID                     *Buffer
    384   )
    385 /*++
    386 
    387 Routine Description:
    388 
    389   TODO: Add function description
    390 
    391 Arguments:
    392 
    393   This        - TODO: add argument description
    394   BufferSize  - TODO: add argument description
    395   Buffer      - TODO: add argument description
    396 
    397 Returns:
    398 
    399   TODO: add return values
    400 
    401 --*/
    402 ;
    403 
    404 EFI_STATUS
    405 EFIAPI
    406 WinNtSerialIoRead (
    407   IN  EFI_SERIAL_IO_PROTOCOL  *This,
    408   IN  OUT UINTN               *BufferSize,
    409   OUT VOID                    *Buffer
    410   )
    411 /*++
    412 
    413 Routine Description:
    414 
    415   TODO: Add function description
    416 
    417 Arguments:
    418 
    419   This        - TODO: add argument description
    420   BufferSize  - TODO: add argument description
    421   Buffer      - TODO: add argument description
    422 
    423 Returns:
    424 
    425   TODO: add return values
    426 
    427 --*/
    428 ;
    429 
    430 BOOLEAN
    431 IsaSerialFifoFull (
    432   IN SERIAL_DEV_FIFO *Fifo
    433   )
    434 /*++
    435 
    436 Routine Description:
    437 
    438   TODO: Add function description
    439 
    440 Arguments:
    441 
    442   Fifo  - TODO: add argument description
    443 
    444 Returns:
    445 
    446   TODO: add return values
    447 
    448 --*/
    449 ;
    450 
    451 BOOLEAN
    452 IsaSerialFifoEmpty (
    453   IN SERIAL_DEV_FIFO *Fifo
    454   )
    455 /*++
    456 
    457 Routine Description:
    458 
    459   TODO: Add function description
    460 
    461 Arguments:
    462 
    463   Fifo  - TODO: add argument description
    464 
    465 Returns:
    466 
    467   TODO: add return values
    468 
    469 --*/
    470 ;
    471 
    472 EFI_STATUS
    473 IsaSerialFifoAdd (
    474   IN SERIAL_DEV_FIFO *Fifo,
    475   IN UINT8           Data
    476   )
    477 /*++
    478 
    479 Routine Description:
    480 
    481   TODO: Add function description
    482 
    483 Arguments:
    484 
    485   Fifo  - TODO: add argument description
    486   Data  - TODO: add argument description
    487 
    488 Returns:
    489 
    490   TODO: add return values
    491 
    492 --*/
    493 ;
    494 
    495 EFI_STATUS
    496 IsaSerialFifoRemove (
    497   IN  SERIAL_DEV_FIFO *Fifo,
    498   OUT UINT8           *Data
    499   )
    500 /*++
    501 
    502 Routine Description:
    503 
    504   TODO: Add function description
    505 
    506 Arguments:
    507 
    508   Fifo  - TODO: add argument description
    509   Data  - TODO: add argument description
    510 
    511 Returns:
    512 
    513   TODO: add return values
    514 
    515 --*/
    516 ;
    517 
    518 EFI_STATUS
    519 IsaSerialReceiveTransmit (
    520   WIN_NT_SERIAL_IO_PRIVATE_DATA     *Private
    521   )
    522 /*++
    523 
    524 Routine Description:
    525 
    526   TODO: Add function description
    527 
    528 Arguments:
    529 
    530   Private - TODO: add argument description
    531 
    532 Returns:
    533 
    534   TODO: add return values
    535 
    536 --*/
    537 ;
    538 
    539 #endif
    540