Home | History | Annotate | Download | only in IsaSerialDxe
      1 /** @file
      2   Include for Serial Driver
      3 
      4 Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>
      5 This program and the accompanying materials
      6 are licensed and made available under the terms and conditions of the BSD License
      7 which accompanies this distribution.  The full text of the license may be found at
      8 http://opensource.org/licenses/bsd-license.php
      9 
     10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
     11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
     12 
     13 **/
     14 
     15 #ifndef _SERIAL_H_
     16 #define _SERIAL_H_
     17 
     18 
     19 #include <FrameworkDxe.h>
     20 
     21 #include <Protocol/IsaIo.h>
     22 #include <Protocol/SerialIo.h>
     23 #include <Protocol/DevicePath.h>
     24 
     25 #include <Library/DebugLib.h>
     26 #include <Library/UefiDriverEntryPoint.h>
     27 #include <Library/UefiLib.h>
     28 #include <Library/DevicePathLib.h>
     29 #include <Library/BaseMemoryLib.h>
     30 #include <Library/MemoryAllocationLib.h>
     31 #include <Library/UefiBootServicesTableLib.h>
     32 #include <Library/ReportStatusCodeLib.h>
     33 #include <Library/PcdLib.h>
     34 
     35 //
     36 // Driver Binding Externs
     37 //
     38 extern EFI_DRIVER_BINDING_PROTOCOL  gSerialControllerDriver;
     39 extern EFI_COMPONENT_NAME_PROTOCOL  gIsaSerialComponentName;
     40 extern EFI_COMPONENT_NAME2_PROTOCOL gIsaSerialComponentName2;
     41 
     42 //
     43 // Internal Data Structures
     44 //
     45 #define SERIAL_DEV_SIGNATURE    SIGNATURE_32 ('s', 'e', 'r', 'd')
     46 #define SERIAL_MAX_BUFFER_SIZE  16
     47 #define TIMEOUT_STALL_INTERVAL  10
     48 
     49 //
     50 //  Name:   SERIAL_DEV_FIFO
     51 //  Purpose:  To define Receive FIFO and Transmit FIFO
     52 //  Context:  Used by serial data transmit and receive
     53 //  Fields:
     54 //      First UINT32: The index of the first data in array Data[]
     55 //      Last  UINT32: The index, which you can put a new data into array Data[]
     56 //      Surplus UINT32: Identify how many data you can put into array Data[]
     57 //      Data[]  UINT8 : An array, which used to store data
     58 //
     59 typedef struct {
     60   UINT32  First;
     61   UINT32  Last;
     62   UINT32  Surplus;
     63   UINT8   Data[SERIAL_MAX_BUFFER_SIZE];
     64 } SERIAL_DEV_FIFO;
     65 
     66 typedef enum {
     67   Uart8250  = 0,
     68   Uart16450 = 1,
     69   Uart16550 = 2,
     70   Uart16550A= 3
     71 } EFI_UART_TYPE;
     72 
     73 //
     74 //  Name:   SERIAL_DEV
     75 //  Purpose:  To provide device specific information
     76 //  Context:
     77 //  Fields:
     78 //      Signature UINTN: The identity of the serial device
     79 //      SerialIo  SERIAL_IO_PROTOCOL: Serial I/O protocol interface
     80 //      SerialMode  SERIAL_IO_MODE:
     81 //      DevicePath  EFI_DEVICE_PATH_PROTOCOL *: Device path of the serial device
     82 //      Handle      EFI_HANDLE: The handle instance attached to serial device
     83 //      BaseAddress UINT16: The base address of specific serial device
     84 //      Receive     SERIAL_DEV_FIFO: The FIFO used to store data,
     85 //                  which is received by UART
     86 //      Transmit    SERIAL_DEV_FIFO: The FIFO used to store data,
     87 //                  which you want to transmit by UART
     88 //      SoftwareLoopbackEnable BOOLEAN:
     89 //      Type    EFI_UART_TYPE: Specify the UART type of certain serial device
     90 //
     91 typedef struct {
     92   UINTN                                  Signature;
     93 
     94   EFI_HANDLE                             Handle;
     95   EFI_SERIAL_IO_PROTOCOL                 SerialIo;
     96   EFI_SERIAL_IO_MODE                     SerialMode;
     97   EFI_DEVICE_PATH_PROTOCOL               *DevicePath;
     98 
     99   EFI_DEVICE_PATH_PROTOCOL               *ParentDevicePath;
    100   UART_DEVICE_PATH                       UartDevicePath;
    101   EFI_ISA_IO_PROTOCOL                    *IsaIo;
    102 
    103   UINT16                                 BaseAddress;
    104   SERIAL_DEV_FIFO                        Receive;
    105   SERIAL_DEV_FIFO                        Transmit;
    106   BOOLEAN                                SoftwareLoopbackEnable;
    107   BOOLEAN                                HardwareFlowControl;
    108   EFI_UART_TYPE                          Type;
    109   EFI_UNICODE_STRING_TABLE               *ControllerNameTable;
    110 } SERIAL_DEV;
    111 
    112 #define SERIAL_DEV_FROM_THIS(a) CR (a, SERIAL_DEV, SerialIo, SERIAL_DEV_SIGNATURE)
    113 
    114 //
    115 // Serial Driver Defaults
    116 //
    117 #define SERIAL_PORT_DEFAULT_RECEIVE_FIFO_DEPTH  1
    118 #define SERIAL_PORT_DEFAULT_TIMEOUT             1000000
    119 #define SERIAL_PORT_SUPPORT_CONTROL_MASK        (EFI_SERIAL_CLEAR_TO_SEND                | \
    120                                                  EFI_SERIAL_DATA_SET_READY               | \
    121                                                  EFI_SERIAL_RING_INDICATE                | \
    122                                                  EFI_SERIAL_CARRIER_DETECT               | \
    123                                                  EFI_SERIAL_REQUEST_TO_SEND              | \
    124                                                  EFI_SERIAL_DATA_TERMINAL_READY          | \
    125                                                  EFI_SERIAL_HARDWARE_LOOPBACK_ENABLE     | \
    126                                                  EFI_SERIAL_SOFTWARE_LOOPBACK_ENABLE     | \
    127                                                  EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE | \
    128                                                  EFI_SERIAL_OUTPUT_BUFFER_EMPTY          | \
    129                                                  EFI_SERIAL_INPUT_BUFFER_EMPTY)
    130 
    131 //
    132 // 115200 baud with rounding errors
    133 //
    134 #define SERIAL_PORT_MAX_BAUD_RATE           115400
    135 #define SERIAL_PORT_MIN_BAUD_RATE           50
    136 
    137 #define SERIAL_PORT_MAX_RECEIVE_FIFO_DEPTH  16
    138 #define SERIAL_PORT_MIN_TIMEOUT             1         // 1 uS
    139 #define SERIAL_PORT_MAX_TIMEOUT             100000000 // 100 seconds
    140 //
    141 // UART Registers
    142 //
    143 #define SERIAL_REGISTER_THR 0 // WO   Transmit Holding Register
    144 #define SERIAL_REGISTER_RBR 0 // RO   Receive Buffer Register
    145 #define SERIAL_REGISTER_DLL 0 // R/W  Divisor Latch LSB
    146 #define SERIAL_REGISTER_DLM 1 // R/W  Divisor Latch MSB
    147 #define SERIAL_REGISTER_IER 1 // R/W  Interrupt Enable Register
    148 #define SERIAL_REGISTER_IIR 2 // RO   Interrupt Identification Register
    149 #define SERIAL_REGISTER_FCR 2 // WO   FIFO Cotrol Register
    150 #define SERIAL_REGISTER_LCR 3 // R/W  Line Control Register
    151 #define SERIAL_REGISTER_MCR 4 // R/W  Modem Control Register
    152 #define SERIAL_REGISTER_LSR 5 // R/W  Line Status Register
    153 #define SERIAL_REGISTER_MSR 6 // R/W  Modem Status Register
    154 #define SERIAL_REGISTER_SCR 7 // R/W  Scratch Pad Register
    155 #pragma pack(1)
    156 //
    157 //  Name:   SERIAL_PORT_IER_BITS
    158 //  Purpose:  Define each bit in Interrupt Enable Register
    159 //  Context:
    160 //  Fields:
    161 //     Ravie  Bit0: Receiver Data Available Interrupt Enable
    162 //     Theie  Bit1: Transmistter Holding Register Empty Interrupt Enable
    163 //     Rie      Bit2: Receiver Interrupt Enable
    164 //     Mie      Bit3: Modem Interrupt Enable
    165 //     Reserved Bit4-Bit7: Reserved
    166 //
    167 typedef struct {
    168   UINT8 Ravie : 1;
    169   UINT8 Theie : 1;
    170   UINT8 Rie : 1;
    171   UINT8 Mie : 1;
    172   UINT8 Reserved : 4;
    173 } SERIAL_PORT_IER_BITS;
    174 
    175 //
    176 //  Name:   SERIAL_PORT_IER
    177 //  Purpose:
    178 //  Context:
    179 //  Fields:
    180 //      Bits    SERIAL_PORT_IER_BITS:  Bits of the IER
    181 //      Data    UINT8: the value of the IER
    182 //
    183 typedef union {
    184   SERIAL_PORT_IER_BITS  Bits;
    185   UINT8                 Data;
    186 } SERIAL_PORT_IER;
    187 
    188 //
    189 //  Name:   SERIAL_PORT_FCR_BITS
    190 //  Purpose:  Define each bit in FIFO Control Register
    191 //  Context:
    192 //  Fields:
    193 //      TrFIFOE    Bit0: Transmit and Receive FIFO Enable
    194 //      ResetRF    Bit1: Reset Reciever FIFO
    195 //      ResetTF    Bit2: Reset Transmistter FIFO
    196 //      Dms        Bit3: DMA Mode Select
    197 //      Reserved   Bit4-Bit5: Reserved
    198 //      Rtb        Bit6-Bit7: Receive Trigger Bits
    199 //
    200 typedef struct {
    201   UINT8 TrFIFOE : 1;
    202   UINT8 ResetRF : 1;
    203   UINT8 ResetTF : 1;
    204   UINT8 Dms : 1;
    205   UINT8 Reserved : 2;
    206   UINT8 Rtb : 2;
    207 } SERIAL_PORT_FCR_BITS;
    208 
    209 //
    210 //  Name:   SERIAL_PORT_FCR
    211 //  Purpose:
    212 //  Context:
    213 //  Fields:
    214 //      Bits    SERIAL_PORT_FCR_BITS:  Bits of the FCR
    215 //      Data    UINT8: the value of the FCR
    216 //
    217 typedef union {
    218   SERIAL_PORT_FCR_BITS  Bits;
    219   UINT8                 Data;
    220 } SERIAL_PORT_FCR;
    221 
    222 //
    223 //  Name:   SERIAL_PORT_LCR_BITS
    224 //  Purpose:  Define each bit in Line Control Register
    225 //  Context:
    226 //  Fields:
    227 //      SerialDB  Bit0-Bit1: Number of Serial Data Bits
    228 //      StopB     Bit2: Number of Stop Bits
    229 //      ParEn     Bit3: Parity Enable
    230 //      EvenPar   Bit4: Even Parity Select
    231 //      SticPar   Bit5: Sticky Parity
    232 //      BrCon     Bit6: Break Control
    233 //      DLab      Bit7: Divisor Latch Access Bit
    234 //
    235 typedef struct {
    236   UINT8 SerialDB : 2;
    237   UINT8 StopB : 1;
    238   UINT8 ParEn : 1;
    239   UINT8 EvenPar : 1;
    240   UINT8 SticPar : 1;
    241   UINT8 BrCon : 1;
    242   UINT8 DLab : 1;
    243 } SERIAL_PORT_LCR_BITS;
    244 
    245 //
    246 //  Name:   SERIAL_PORT_LCR
    247 //  Purpose:
    248 //  Context:
    249 //  Fields:
    250 //      Bits    SERIAL_PORT_LCR_BITS:  Bits of the LCR
    251 //      Data    UINT8: the value of the LCR
    252 //
    253 typedef union {
    254   SERIAL_PORT_LCR_BITS  Bits;
    255   UINT8                 Data;
    256 } SERIAL_PORT_LCR;
    257 
    258 //
    259 //  Name:   SERIAL_PORT_MCR_BITS
    260 //  Purpose:  Define each bit in Modem Control Register
    261 //  Context:
    262 //  Fields:
    263 //      DtrC     Bit0: Data Terminal Ready Control
    264 //      Rts      Bit1: Request To Send Control
    265 //      Out1     Bit2: Output1
    266 //      Out2     Bit3: Output2, used to disable interrupt
    267 //      Lme;     Bit4: Loopback Mode Enable
    268 //      Reserved Bit5-Bit7: Reserved
    269 //
    270 typedef struct {
    271   UINT8 DtrC : 1;
    272   UINT8 Rts : 1;
    273   UINT8 Out1 : 1;
    274   UINT8 Out2 : 1;
    275   UINT8 Lme : 1;
    276   UINT8 Reserved : 3;
    277 } SERIAL_PORT_MCR_BITS;
    278 
    279 //
    280 //  Name:   SERIAL_PORT_MCR
    281 //  Purpose:
    282 //  Context:
    283 //  Fields:
    284 //      Bits    SERIAL_PORT_MCR_BITS:  Bits of the MCR
    285 //      Data    UINT8: the value of the MCR
    286 //
    287 typedef union {
    288   SERIAL_PORT_MCR_BITS  Bits;
    289   UINT8                 Data;
    290 } SERIAL_PORT_MCR;
    291 
    292 //
    293 //  Name:   SERIAL_PORT_LSR_BITS
    294 //  Purpose:  Define each bit in Line Status Register
    295 //  Context:
    296 //  Fields:
    297 //      Dr    Bit0: Receiver Data Ready Status
    298 //      Oe    Bit1: Overrun Error Status
    299 //      Pe    Bit2: Parity Error Status
    300 //      Fe    Bit3: Framing Error Status
    301 //      Bi    Bit4: Break Interrupt Status
    302 //      Thre  Bit5: Transmistter Holding Register Status
    303 //      Temt  Bit6: Transmitter Empty Status
    304 //      FIFOe Bit7: FIFO Error Status
    305 //
    306 typedef struct {
    307   UINT8 Dr : 1;
    308   UINT8 Oe : 1;
    309   UINT8 Pe : 1;
    310   UINT8 Fe : 1;
    311   UINT8 Bi : 1;
    312   UINT8 Thre : 1;
    313   UINT8 Temt : 1;
    314   UINT8 FIFOe : 1;
    315 } SERIAL_PORT_LSR_BITS;
    316 
    317 //
    318 //  Name:   SERIAL_PORT_LSR
    319 //  Purpose:
    320 //  Context:
    321 //  Fields:
    322 //      Bits    SERIAL_PORT_LSR_BITS:  Bits of the LSR
    323 //      Data    UINT8: the value of the LSR
    324 //
    325 typedef union {
    326   SERIAL_PORT_LSR_BITS  Bits;
    327   UINT8                 Data;
    328 } SERIAL_PORT_LSR;
    329 
    330 //
    331 //  Name:   SERIAL_PORT_MSR_BITS
    332 //  Purpose:  Define each bit in Modem Status Register
    333 //  Context:
    334 //  Fields:
    335 //      DeltaCTS      Bit0: Delta Clear To Send Status
    336 //      DeltaDSR        Bit1: Delta Data Set Ready Status
    337 //      TrailingEdgeRI  Bit2: Trailing Edge of Ring Indicator Status
    338 //      DeltaDCD        Bit3: Delta Data Carrier Detect Status
    339 //      Cts             Bit4: Clear To Send Status
    340 //      Dsr             Bit5: Data Set Ready Status
    341 //      Ri              Bit6: Ring Indicator Status
    342 //      Dcd             Bit7: Data Carrier Detect Status
    343 //
    344 typedef struct {
    345   UINT8 DeltaCTS : 1;
    346   UINT8 DeltaDSR : 1;
    347   UINT8 TrailingEdgeRI : 1;
    348   UINT8 DeltaDCD : 1;
    349   UINT8 Cts : 1;
    350   UINT8 Dsr : 1;
    351   UINT8 Ri : 1;
    352   UINT8 Dcd : 1;
    353 } SERIAL_PORT_MSR_BITS;
    354 
    355 //
    356 //  Name:   SERIAL_PORT_MSR
    357 //  Purpose:
    358 //  Context:
    359 //  Fields:
    360 //      Bits    SERIAL_PORT_MSR_BITS:  Bits of the MSR
    361 //      Data    UINT8: the value of the MSR
    362 //
    363 typedef union {
    364   SERIAL_PORT_MSR_BITS  Bits;
    365   UINT8                 Data;
    366 } SERIAL_PORT_MSR;
    367 
    368 #pragma pack()
    369 //
    370 // Define serial register I/O macros
    371 //
    372 #define READ_RBR(IO, B)     IsaSerialReadPort (IO, B, SERIAL_REGISTER_RBR)
    373 #define READ_DLL(IO, B)     IsaSerialReadPort (IO, B, SERIAL_REGISTER_DLL)
    374 #define READ_DLM(IO, B)     IsaSerialReadPort (IO, B, SERIAL_REGISTER_DLM)
    375 #define READ_IER(IO, B)     IsaSerialReadPort (IO, B, SERIAL_REGISTER_IER)
    376 #define READ_IIR(IO, B)     IsaSerialReadPort (IO, B, SERIAL_REGISTER_IIR)
    377 #define READ_LCR(IO, B)     IsaSerialReadPort (IO, B, SERIAL_REGISTER_LCR)
    378 #define READ_MCR(IO, B)     IsaSerialReadPort (IO, B, SERIAL_REGISTER_MCR)
    379 #define READ_LSR(IO, B)     IsaSerialReadPort (IO, B, SERIAL_REGISTER_LSR)
    380 #define READ_MSR(IO, B)     IsaSerialReadPort (IO, B, SERIAL_REGISTER_MSR)
    381 #define READ_SCR(IO, B)     IsaSerialReadPort (IO, B, SERIAL_REGISTER_SCR)
    382 
    383 #define WRITE_THR(IO, B, D) IsaSerialWritePort (IO, B, SERIAL_REGISTER_THR, D)
    384 #define WRITE_DLL(IO, B, D) IsaSerialWritePort (IO, B, SERIAL_REGISTER_DLL, D)
    385 #define WRITE_DLM(IO, B, D) IsaSerialWritePort (IO, B, SERIAL_REGISTER_DLM, D)
    386 #define WRITE_IER(IO, B, D) IsaSerialWritePort (IO, B, SERIAL_REGISTER_IER, D)
    387 #define WRITE_FCR(IO, B, D) IsaSerialWritePort (IO, B, SERIAL_REGISTER_FCR, D)
    388 #define WRITE_LCR(IO, B, D) IsaSerialWritePort (IO, B, SERIAL_REGISTER_LCR, D)
    389 #define WRITE_MCR(IO, B, D) IsaSerialWritePort (IO, B, SERIAL_REGISTER_MCR, D)
    390 #define WRITE_LSR(IO, B, D) IsaSerialWritePort (IO, B, SERIAL_REGISTER_LSR, D)
    391 #define WRITE_MSR(IO, B, D) IsaSerialWritePort (IO, B, SERIAL_REGISTER_MSR, D)
    392 #define WRITE_SCR(IO, B, D) IsaSerialWritePort (IO, B, SERIAL_REGISTER_SCR, D)
    393 
    394 //
    395 // Prototypes
    396 // Driver model protocol interface
    397 //
    398 /**
    399   Check to see if this driver supports the given controller
    400 
    401   @param  This                 A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
    402   @param  Controller           The handle of the controller to test.
    403   @param  RemainingDevicePath  A pointer to the remaining portion of a device path.
    404 
    405   @return EFI_SUCCESS          This driver can support the given controller
    406 
    407 **/
    408 EFI_STATUS
    409 EFIAPI
    410 SerialControllerDriverSupported (
    411   IN EFI_DRIVER_BINDING_PROTOCOL    *This,
    412   IN EFI_HANDLE                     Controller,
    413   IN EFI_DEVICE_PATH_PROTOCOL       *RemainingDevicePath
    414   );
    415 
    416 /**
    417   Start to management the controller passed in
    418 
    419   @param  This                 A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
    420   @param  Controller           The handle of the controller to test.
    421   @param  RemainingDevicePath  A pointer to the remaining portion of a device path.
    422 
    423   @return EFI_SUCCESS          Driver is started successfully
    424 **/
    425 EFI_STATUS
    426 EFIAPI
    427 SerialControllerDriverStart (
    428   IN EFI_DRIVER_BINDING_PROTOCOL    *This,
    429   IN EFI_HANDLE                     Controller,
    430   IN EFI_DEVICE_PATH_PROTOCOL       *RemainingDevicePath
    431   );
    432 
    433 /**
    434   Disconnect this driver with the controller, uninstall related protocol instance
    435 
    436   @param  This                  A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
    437   @param  Controller            The handle of the controller to test.
    438   @param  NumberOfChildren      Number of child device.
    439   @param  ChildHandleBuffer     A pointer to the remaining portion of a device path.
    440 
    441   @retval EFI_SUCCESS           Operation successfully
    442   @retval EFI_DEVICE_ERROR      Cannot stop the driver successfully
    443 
    444 **/
    445 EFI_STATUS
    446 EFIAPI
    447 SerialControllerDriverStop (
    448   IN  EFI_DRIVER_BINDING_PROTOCOL   *This,
    449   IN  EFI_HANDLE                    Controller,
    450   IN  UINTN                         NumberOfChildren,
    451   IN  EFI_HANDLE                    *ChildHandleBuffer
    452   );
    453 
    454 //
    455 // Serial I/O Protocol Interface
    456 //
    457 /**
    458   Reset serial device.
    459 
    460   @param This               Pointer to EFI_SERIAL_IO_PROTOCOL
    461 
    462   @retval EFI_SUCCESS        Reset successfully
    463   @retval EFI_DEVICE_ERROR   Failed to reset
    464 
    465 **/
    466 EFI_STATUS
    467 EFIAPI
    468 IsaSerialReset (
    469   IN EFI_SERIAL_IO_PROTOCOL         *This
    470   );
    471 
    472 /**
    473   Set new attributes to a serial device.
    474 
    475   @param This                     Pointer to EFI_SERIAL_IO_PROTOCOL
    476   @param  BaudRate                 The baudrate of the serial device
    477   @param  ReceiveFifoDepth         The depth of receive FIFO buffer
    478   @param  Timeout                  The request timeout for a single char
    479   @param  Parity                   The type of parity used in serial device
    480   @param  DataBits                 Number of databits used in serial device
    481   @param  StopBits                 Number of stopbits used in serial device
    482 
    483   @retval  EFI_SUCCESS              The new attributes were set
    484   @retval  EFI_INVALID_PARAMETERS   One or more attributes have an unsupported value
    485   @retval  EFI_UNSUPPORTED          Data Bits can not set to 5 or 6
    486   @retval  EFI_DEVICE_ERROR         The serial device is not functioning correctly (no return)
    487 
    488 **/
    489 EFI_STATUS
    490 EFIAPI
    491 IsaSerialSetAttributes (
    492   IN EFI_SERIAL_IO_PROTOCOL         *This,
    493   IN UINT64                         BaudRate,
    494   IN UINT32                         ReceiveFifoDepth,
    495   IN UINT32                         Timeout,
    496   IN EFI_PARITY_TYPE                Parity,
    497   IN UINT8                          DataBits,
    498   IN EFI_STOP_BITS_TYPE             StopBits
    499   );
    500 
    501 /**
    502   Set Control Bits.
    503 
    504   @param This              Pointer to EFI_SERIAL_IO_PROTOCOL
    505   @param Control           Control bits that can be settable
    506 
    507   @retval EFI_SUCCESS       New Control bits were set successfully
    508   @retval EFI_UNSUPPORTED   The Control bits wanted to set are not supported
    509 
    510 **/
    511 EFI_STATUS
    512 EFIAPI
    513 IsaSerialSetControl (
    514   IN EFI_SERIAL_IO_PROTOCOL         *This,
    515   IN UINT32                         Control
    516   );
    517 
    518 /**
    519   Get ControlBits.
    520 
    521   @param This          Pointer to EFI_SERIAL_IO_PROTOCOL
    522   @param Control       Control signals of the serial device
    523 
    524   @retval EFI_SUCCESS   Get Control signals successfully
    525 
    526 **/
    527 EFI_STATUS
    528 EFIAPI
    529 IsaSerialGetControl (
    530   IN EFI_SERIAL_IO_PROTOCOL         *This,
    531   OUT UINT32                        *Control
    532   );
    533 
    534 /**
    535   Write the specified number of bytes to serial device.
    536 
    537   @param This                Pointer to EFI_SERIAL_IO_PROTOCOL
    538   @param  BufferSize         On input the size of Buffer, on output the amount of
    539                              data actually written
    540   @param  Buffer             The buffer of data to write
    541 
    542   @retval EFI_SUCCESS        The data were written successfully
    543   @retval EFI_DEVICE_ERROR   The device reported an error
    544   @retval EFI_TIMEOUT        The write operation was stopped due to timeout
    545 
    546 **/
    547 EFI_STATUS
    548 EFIAPI
    549 IsaSerialWrite (
    550   IN EFI_SERIAL_IO_PROTOCOL         *This,
    551   IN OUT UINTN                      *BufferSize,
    552   IN VOID                           *Buffer
    553   );
    554 
    555 /**
    556   Read the specified number of bytes from serial device.
    557 
    558   @param This               Pointer to EFI_SERIAL_IO_PROTOCOL
    559   @param BufferSize         On input the size of Buffer, on output the amount of
    560                             data returned in buffer
    561   @param Buffer             The buffer to return the data into
    562 
    563   @retval EFI_SUCCESS        The data were read successfully
    564   @retval EFI_DEVICE_ERROR   The device reported an error
    565   @retval EFI_TIMEOUT        The read operation was stopped due to timeout
    566 
    567 **/
    568 EFI_STATUS
    569 EFIAPI
    570 IsaSerialRead (
    571   IN EFI_SERIAL_IO_PROTOCOL         *This,
    572   IN OUT UINTN                      *BufferSize,
    573   OUT VOID                          *Buffer
    574   );
    575 
    576 //
    577 // Internal Functions
    578 //
    579 /**
    580   Use scratchpad register to test if this serial port is present.
    581 
    582   @param SerialDevice   Pointer to serial device structure
    583 
    584   @return if this serial port is present
    585 **/
    586 BOOLEAN
    587 IsaSerialPortPresent (
    588   IN SERIAL_DEV                     *SerialDevice
    589   );
    590 
    591 /**
    592   Detect whether specific FIFO is full or not.
    593 
    594   @param Fifo    A pointer to the Data Structure SERIAL_DEV_FIFO
    595 
    596   @return whether specific FIFO is full or not
    597 
    598 **/
    599 BOOLEAN
    600 IsaSerialFifoFull (
    601   IN SERIAL_DEV_FIFO                *Fifo
    602   );
    603 
    604 /**
    605   Detect whether specific FIFO is empty or not.
    606 
    607   @param  Fifo    A pointer to the Data Structure SERIAL_DEV_FIFO
    608 
    609   @return whether specific FIFO is empty or not
    610 
    611 **/
    612 BOOLEAN
    613 IsaSerialFifoEmpty (
    614   IN SERIAL_DEV_FIFO                *Fifo
    615   );
    616 
    617 /**
    618   Add data to specific FIFO.
    619 
    620   @param Fifo                  A pointer to the Data Structure SERIAL_DEV_FIFO
    621   @param Data                  the data added to FIFO
    622 
    623   @retval EFI_SUCCESS           Add data to specific FIFO successfully
    624   @retval EFI_OUT_OF_RESOURCE   Failed to add data because FIFO is already full
    625 
    626 **/
    627 EFI_STATUS
    628 IsaSerialFifoAdd (
    629   IN SERIAL_DEV_FIFO                *Fifo,
    630   IN UINT8                          Data
    631   );
    632 
    633 /**
    634   Remove data from specific FIFO.
    635 
    636   @param Fifo                  A pointer to the Data Structure SERIAL_DEV_FIFO
    637   @param Data                  the data removed from FIFO
    638 
    639   @retval EFI_SUCCESS           Remove data from specific FIFO successfully
    640   @retval EFI_OUT_OF_RESOURCE   Failed to remove data because FIFO is empty
    641 
    642 **/
    643 EFI_STATUS
    644 IsaSerialFifoRemove (
    645   IN  SERIAL_DEV_FIFO               *Fifo,
    646   OUT UINT8                         *Data
    647   );
    648 
    649 /**
    650   Reads and writes all avaliable data.
    651 
    652   @param SerialDevice           The device to flush
    653 
    654   @retval EFI_SUCCESS           Data was read/written successfully.
    655   @retval EFI_OUT_OF_RESOURCE   Failed because software receive FIFO is full.  Note, when
    656                                 this happens, pending writes are not done.
    657 
    658 **/
    659 EFI_STATUS
    660 IsaSerialReceiveTransmit (
    661   IN SERIAL_DEV                     *SerialDevice
    662   );
    663 
    664 /**
    665   Use IsaIo protocol to read serial port.
    666 
    667   @param IsaIo         Pointer to EFI_ISA_IO_PROTOCOL instance
    668   @param BaseAddress   Serial port register group base address
    669   @param Offset        Offset in register group
    670 
    671   @return Data read from serial port
    672 
    673 **/
    674 UINT8
    675 IsaSerialReadPort (
    676   IN EFI_ISA_IO_PROTOCOL                    *IsaIo,
    677   IN UINT16                                 BaseAddress,
    678   IN UINT32                                 Offset
    679   );
    680 
    681 /**
    682   Use IsaIo protocol to write serial port.
    683 
    684   @param  IsaIo         Pointer to EFI_ISA_IO_PROTOCOL instance
    685   @param  BaseAddress   Serial port register group base address
    686   @param  Offset        Offset in register group
    687   @param  Data          data which is to be written to some serial port register
    688 
    689 **/
    690 VOID
    691 IsaSerialWritePort (
    692   IN EFI_ISA_IO_PROTOCOL                    *IsaIo,
    693   IN UINT16                                 BaseAddress,
    694   IN UINT32                                 Offset,
    695   IN UINT8                                  Data
    696   );
    697 
    698 
    699 //
    700 // EFI Component Name Functions
    701 //
    702 /**
    703   Retrieves a Unicode string that is the user readable name of the driver.
    704 
    705   This function retrieves the user readable name of a driver in the form of a
    706   Unicode string. If the driver specified by This has a user readable name in
    707   the language specified by Language, then a pointer to the driver name is
    708   returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
    709   by This does not support the language specified by Language,
    710   then EFI_UNSUPPORTED is returned.
    711 
    712   @param  This[in]              A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
    713                                 EFI_COMPONENT_NAME_PROTOCOL instance.
    714 
    715   @param  Language[in]          A pointer to a Null-terminated ASCII string
    716                                 array indicating the language. This is the
    717                                 language of the driver name that the caller is
    718                                 requesting, and it must match one of the
    719                                 languages specified in SupportedLanguages. The
    720                                 number of languages supported by a driver is up
    721                                 to the driver writer. Language is specified
    722                                 in RFC 4646 or ISO 639-2 language code format.
    723 
    724   @param  DriverName[out]       A pointer to the Unicode string to return.
    725                                 This Unicode string is the name of the
    726                                 driver specified by This in the language
    727                                 specified by Language.
    728 
    729   @retval EFI_SUCCESS           The Unicode string for the Driver specified by
    730                                 This and the language specified by Language was
    731                                 returned in DriverName.
    732 
    733   @retval EFI_INVALID_PARAMETER Language is NULL.
    734 
    735   @retval EFI_INVALID_PARAMETER DriverName is NULL.
    736 
    737   @retval EFI_UNSUPPORTED       The driver specified by This does not support
    738                                 the language specified by Language.
    739 
    740 **/
    741 EFI_STATUS
    742 EFIAPI
    743 IsaSerialComponentNameGetDriverName (
    744   IN  EFI_COMPONENT_NAME_PROTOCOL  *This,
    745   IN  CHAR8                        *Language,
    746   OUT CHAR16                       **DriverName
    747   );
    748 
    749 
    750 /**
    751   Retrieves a Unicode string that is the user readable name of the controller
    752   that is being managed by a driver.
    753 
    754   This function retrieves the user readable name of the controller specified by
    755   ControllerHandle and ChildHandle in the form of a Unicode string. If the
    756   driver specified by This has a user readable name in the language specified by
    757   Language, then a pointer to the controller name is returned in ControllerName,
    758   and EFI_SUCCESS is returned.  If the driver specified by This is not currently
    759   managing the controller specified by ControllerHandle and ChildHandle,
    760   then EFI_UNSUPPORTED is returned.  If the driver specified by This does not
    761   support the language specified by Language, then EFI_UNSUPPORTED is returned.
    762 
    763   @param  This[in]              A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
    764                                 EFI_COMPONENT_NAME_PROTOCOL instance.
    765 
    766   @param  ControllerHandle[in]  The handle of a controller that the driver
    767                                 specified by This is managing.  This handle
    768                                 specifies the controller whose name is to be
    769                                 returned.
    770 
    771   @param  ChildHandle[in]       The handle of the child controller to retrieve
    772                                 the name of.  This is an optional parameter that
    773                                 may be NULL.  It will be NULL for device
    774                                 drivers.  It will also be NULL for a bus drivers
    775                                 that wish to retrieve the name of the bus
    776                                 controller.  It will not be NULL for a bus
    777                                 driver that wishes to retrieve the name of a
    778                                 child controller.
    779 
    780   @param  Language[in]          A pointer to a Null-terminated ASCII string
    781                                 array indicating the language.  This is the
    782                                 language of the driver name that the caller is
    783                                 requesting, and it must match one of the
    784                                 languages specified in SupportedLanguages. The
    785                                 number of languages supported by a driver is up
    786                                 to the driver writer. Language is specified in
    787                                 RFC 4646 or ISO 639-2 language code format.
    788 
    789   @param  ControllerName[out]   A pointer to the Unicode string to return.
    790                                 This Unicode string is the name of the
    791                                 controller specified by ControllerHandle and
    792                                 ChildHandle in the language specified by
    793                                 Language from the point of view of the driver
    794                                 specified by This.
    795 
    796   @retval EFI_SUCCESS           The Unicode string for the user readable name in
    797                                 the language specified by Language for the
    798                                 driver specified by This was returned in
    799                                 DriverName.
    800 
    801   @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
    802 
    803   @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
    804                                 EFI_HANDLE.
    805 
    806   @retval EFI_INVALID_PARAMETER Language is NULL.
    807 
    808   @retval EFI_INVALID_PARAMETER ControllerName is NULL.
    809 
    810   @retval EFI_UNSUPPORTED       The driver specified by This is not currently
    811                                 managing the controller specified by
    812                                 ControllerHandle and ChildHandle.
    813 
    814   @retval EFI_UNSUPPORTED       The driver specified by This does not support
    815                                 the language specified by Language.
    816 
    817 **/
    818 EFI_STATUS
    819 EFIAPI
    820 IsaSerialComponentNameGetControllerName (
    821   IN  EFI_COMPONENT_NAME_PROTOCOL                     *This,
    822   IN  EFI_HANDLE                                      ControllerHandle,
    823   IN  EFI_HANDLE                                      ChildHandle        OPTIONAL,
    824   IN  CHAR8                                           *Language,
    825   OUT CHAR16                                          **ControllerName
    826   );
    827 
    828 /**
    829   Add the component name for the serial io device
    830 
    831   @param SerialDevice     A pointer to the SERIAL_DEV instance.
    832 
    833   @param IsaIo            A pointer to the EFI_ISA_IO_PROTOCOL instance.
    834 
    835 **/
    836 VOID
    837 AddName (
    838   IN  SERIAL_DEV                                   *SerialDevice,
    839   IN  EFI_ISA_IO_PROTOCOL                          *IsaIo
    840   );
    841 
    842 #endif
    843