]> git.proxmox.com Git - mirror_edk2.git/blame - EmbeddedPkg/Library/GdbSerialDebugPortLib/GdbSerialDebugPortLib.c
EmbeddedPkg/GdbSerialDebugPortLib: fix compile warning
[mirror_edk2.git] / EmbeddedPkg / Library / GdbSerialDebugPortLib / GdbSerialDebugPortLib.c
CommitLineData
2ef2b01e 1/** @file\r
c6a72cd7 2 Basic serial IO abstraction for GDB\r
2ef2b01e 3\r
60274cca 4 Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
3402aac7 5\r
878b807a 6 SPDX-License-Identifier: BSD-2-Clause-Patent\r
2ef2b01e
A
7\r
8**/\r
9\r
10#include <Uefi.h>\r
11#include <Library/GdbSerialLib.h>\r
12#include <Library/PcdLib.h>\r
13#include <Library/IoLib.h>\r
14#include <Library/DebugLib.h>\r
15#include <Library/UefiBootServicesTableLib.h>\r
16\r
17#include <Protocol/DebugPort.h>\r
18\r
2ef2b01e 19EFI_DEBUGPORT_PROTOCOL *gDebugPort = NULL;\r
c05a218a 20UINT32 gTimeOut = 0;\r
2ef2b01e
A
21\r
22/**\r
23 The constructor function initializes the UART.\r
3402aac7 24\r
2ef2b01e
A
25 @param ImageHandle The firmware allocated handle for the EFI image.\r
26 @param SystemTable A pointer to the EFI System Table.\r
3402aac7 27\r
2ef2b01e
A
28 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.\r
29\r
30**/\r
31RETURN_STATUS\r
32EFIAPI\r
33GdbSerialLibDebugPortConstructor (\r
34 IN EFI_HANDLE ImageHandle,\r
35 IN EFI_SYSTEM_TABLE *SystemTable\r
36 )\r
37{\r
e7108d0e 38 EFI_STATUS Status;\r
3402aac7 39\r
2ef2b01e
A
40 Status = gBS->LocateProtocol (&gEfiDebugPortProtocolGuid, NULL, (VOID **)&gDebugPort);\r
41 if (!EFI_ERROR (Status)) {\r
42 gTimeOut = PcdGet32 (PcdGdbMaxPacketRetryCount);\r
43 gDebugPort->Reset (gDebugPort);\r
44 }\r
3402aac7 45\r
2ef2b01e
A
46 return Status;\r
47}\r
48\r
2ef2b01e 49/**\r
c6a72cd7 50 Sets the baud rate, receive FIFO depth, transmit/receive time out, parity,\r
2ef2b01e
A
51 data buts, and stop bits on a serial device. This call is optional as the serial\r
52 port will be set up with defaults base on PCD values.\r
53\r
a4037690 54 @param BaudRate The requested baud rate. A BaudRate value of 0 will use the\r
2ef2b01e
A
55 device's default interface speed.\r
56 @param Parity The type of parity to use on this serial device. A Parity value of\r
57 DefaultParity will use the device's default parity value.\r
58 @param DataBits The number of data bits to use on the serial device. A DataBits\r
c6a72cd7 59 value of 0 will use the device's default data bit setting.\r
2ef2b01e
A
60 @param StopBits The number of stop bits to use on this serial device. A StopBits\r
61 value of DefaultStopBits will use the device's default number of\r
62 stop bits.\r
63\r
64 @retval EFI_SUCCESS The device was configured.\r
c6a72cd7 65 @retval EFI_DEVICE_ERROR The serial device could not be configured.\r
2ef2b01e
A
66\r
67**/\r
68RETURN_STATUS\r
69EFIAPI\r
70GdbSerialInit (\r
e7108d0e
MK
71 IN UINT64 BaudRate,\r
72 IN UINT8 Parity,\r
73 IN UINT8 DataBits,\r
74 IN UINT8 StopBits\r
2ef2b01e
A
75 )\r
76{\r
77 EFI_STATUS Status;\r
3402aac7 78\r
2ef2b01e
A
79 Status = gDebugPort->Reset (gDebugPort);\r
80 return Status;\r
81}\r
82\r
2ef2b01e
A
83/**\r
84 Check to see if a character is available from GDB. Do not read the character as that is\r
85 done via GdbGetChar().\r
86\r
4f0624e8
GL
87 @return TRUE - Character available\r
88 @return FALSE - Character not available\r
3402aac7 89\r
2ef2b01e
A
90**/\r
91BOOLEAN\r
92EFIAPI\r
93GdbIsCharAvailable (\r
94 VOID\r
3402aac7 95 )\r
2ef2b01e
A
96{\r
97 EFI_STATUS Status;\r
3402aac7 98\r
2ef2b01e 99 Status = gDebugPort->Poll (gDebugPort);\r
3402aac7 100\r
2ef2b01e
A
101 return (Status == EFI_SUCCESS ? TRUE : FALSE);\r
102}\r
103\r
2ef2b01e
A
104/**\r
105 Get a character from GDB. This function must be able to run in interrupt context.\r
106\r
107 @return A character from GDB\r
3402aac7 108\r
2ef2b01e
A
109**/\r
110CHAR8\r
111EFIAPI\r
112GdbGetChar (\r
113 VOID\r
114 )\r
115{\r
116 EFI_STATUS Status;\r
117 CHAR8 Char;\r
118 UINTN BufferSize;\r
3402aac7 119\r
2ef2b01e
A
120 do {\r
121 BufferSize = sizeof (Char);\r
e7108d0e 122 Status = gDebugPort->Read (gDebugPort, gTimeOut, &BufferSize, &Char);\r
2ef2b01e 123 } while (EFI_ERROR (Status) || BufferSize != sizeof (Char));\r
3402aac7 124\r
2ef2b01e
A
125 return Char;\r
126}\r
127\r
2ef2b01e
A
128/**\r
129 Send a character to GDB. This function must be able to run in interrupt context.\r
130\r
131\r
132 @param Char Send a character to GDB\r
133\r
134**/\r
2ef2b01e
A
135VOID\r
136EFIAPI\r
137GdbPutChar (\r
e7108d0e 138 IN CHAR8 Char\r
2ef2b01e
A
139 )\r
140{\r
141 EFI_STATUS Status;\r
142 UINTN BufferSize;\r
3402aac7 143\r
2ef2b01e
A
144 do {\r
145 BufferSize = sizeof (Char);\r
e7108d0e 146 Status = gDebugPort->Write (gDebugPort, gTimeOut, &BufferSize, &Char);\r
2ef2b01e 147 } while (EFI_ERROR (Status) || BufferSize != sizeof (Char));\r
3402aac7 148\r
2ef2b01e
A
149 return;\r
150}\r
151\r
152/**\r
153 Send an ASCII string to GDB. This function must be able to run in interrupt context.\r
154\r
155\r
156 @param String Send a string to GDB\r
157\r
158**/\r
2ef2b01e
A
159VOID\r
160GdbPutString (\r
161 IN CHAR8 *String\r
162 )\r
163{\r
e7108d0e 164 // We could performance enhance this function by calling gDebugPort->Write ()\r
2ef2b01e
A
165 while (*String != '\0') {\r
166 GdbPutChar (*String);\r
167 String++;\r
168 }\r
169}\r