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