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