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