2 Serial IO Abstraction for GDB stub. This allows an EFI consoles that shows up on the system
3 running GDB. One console for error information and another console for user input/output.
5 Basic packet format is $packet-data#checksum. So every command has 4 bytes of overhead: $,
6 #, 0, 0. The 0 and 0 are the ascii characters for the checksum.
9 Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
11 This program and the accompanying materials
12 are licensed and made available under the terms and conditions of the BSD License
13 which accompanies this distribution. The full text of the license may be found at
14 http://opensource.org/licenses/bsd-license.php
16 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
17 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
22 #include <Library/UefiLib.h>
23 #include <Library/UefiBootServicesTableLib.h>
24 #include <Library/DebugLib.h>
25 #include <Library/SerialPortLib.h>
26 #include <Library/PcdLib.h>
28 #include <Protocol/SerialIo.h>
31 Reset the serial device.
33 @param This Protocol instance pointer.
35 @retval EFI_SUCCESS The device was reset.
36 @retval EFI_DEVICE_ERROR The serial device could not be reset.
42 IN EFI_SERIAL_IO_PROTOCOL
*This
45 SerialPortInitialize ();
51 Sets the baud rate, receive FIFO depth, transmit/receive time out, parity,
52 data buts, and stop bits on a serial device.
54 @param This Protocol instance pointer.
55 @param BaudRate The requested baud rate. A BaudRate value of 0 will use the the
56 device's default interface speed.
57 @param ReceiveFifoDepth The requested depth of the FIFO on the receive side of the
58 serial interface. A ReceiveFifoDepth value of 0 will use
59 the device's default FIFO depth.
60 @param Timeout The requested time out for a single character in microseconds.
61 This timeout applies to both the transmit and receive side of the
62 interface. A Timeout value of 0 will use the device's default time
64 @param Parity The type of parity to use on this serial device. A Parity value of
65 DefaultParity will use the device's default parity value.
66 @param DataBits The number of data bits to use on the serial device. A DataBits
67 value of 0 will use the device's default data bit setting.
68 @param StopBits The number of stop bits to use on this serial device. A StopBits
69 value of DefaultStopBits will use the device's default number of
72 @retval EFI_SUCCESS The device was reset.
73 @retval EFI_DEVICE_ERROR The serial device could not be reset.
79 IN EFI_SERIAL_IO_PROTOCOL
*This
,
81 IN UINT32 ReceiveFifoDepth
,
83 IN EFI_PARITY_TYPE Parity
,
85 IN EFI_STOP_BITS_TYPE StopBits
88 return EFI_UNSUPPORTED
;
93 Set the control bits on a serial device
95 @param This Protocol instance pointer.
96 @param Control Set the bits of Control that are settable.
98 @retval EFI_SUCCESS The new control bits were set on the serial device.
99 @retval EFI_UNSUPPORTED The serial device does not support this operation.
100 @retval EFI_DEVICE_ERROR The serial device is not functioning correctly.
106 IN EFI_SERIAL_IO_PROTOCOL
*This
,
110 return EFI_UNSUPPORTED
;
115 Retrieves the status of the control bits on a serial device
117 @param This Protocol instance pointer.
118 @param Control A pointer to return the current Control signals from the serial device.
120 @retval EFI_SUCCESS The control bits were read from the serial device.
121 @retval EFI_DEVICE_ERROR The serial device is not functioning correctly.
127 IN EFI_SERIAL_IO_PROTOCOL
*This
,
131 if (SerialPortPoll ()) {
132 // If a character is pending don't set EFI_SERIAL_INPUT_BUFFER_EMPTY
133 *Control
= EFI_SERIAL_OUTPUT_BUFFER_EMPTY
;
135 *Control
= EFI_SERIAL_INPUT_BUFFER_EMPTY
| EFI_SERIAL_OUTPUT_BUFFER_EMPTY
;
142 Writes data to a serial device.
144 @param This Protocol instance pointer.
145 @param BufferSize On input, the size of the Buffer. On output, the amount of
146 data actually written.
147 @param Buffer The buffer of data to write
149 @retval EFI_SUCCESS The data was written.
150 @retval EFI_DEVICE_ERROR The device reported an error.
151 @retval EFI_TIMEOUT The data write was stopped due to a timeout.
157 IN EFI_SERIAL_IO_PROTOCOL
*This
,
158 IN OUT UINTN
*BufferSize
,
164 Count
= SerialPortWrite (Buffer
, *BufferSize
);
166 return (Count
== 0) ? EFI_DEVICE_ERROR
: EFI_SUCCESS
;
170 Reads data from a serial device.
172 @param This Protocol instance pointer.
173 @param BufferSize On input, the size of the Buffer. On output, the amount of
174 data returned in Buffer.
175 @param Buffer The buffer to return the data into.
177 @retval EFI_SUCCESS The data was read.
178 @retval EFI_DEVICE_ERROR The device reported an error.
179 @retval EFI_TIMEOUT The data write was stopped due to a timeout.
186 IN EFI_SERIAL_IO_PROTOCOL
*This
,
187 IN OUT UINTN
*BufferSize
,
193 if (SerialPortPoll()) {
194 Count
= SerialPortRead (Buffer
, *BufferSize
);
197 if (Count
!= *BufferSize
) {
206 EFI_HANDLE gHandle
= NULL
;
209 // Template used to initialize the GDB Serial IO protocols
211 EFI_SERIAL_IO_MODE gSerialIoMode
= {
214 FixedPcdGet64 (PcdUartDefaultBaudRate
), // BaudRate
215 1, // ReceiveFifoDepth
216 FixedPcdGet8 (PcdUartDefaultDataBits
), // DataBits
217 FixedPcdGet8 (PcdUartDefaultParity
), // Parity
218 FixedPcdGet8 (PcdUartDefaultStopBits
) // StopBits
222 EFI_SERIAL_IO_PROTOCOL gSerialIoTemplate
= {
223 SERIAL_IO_INTERFACE_REVISION
,
234 VENDOR_DEVICE_PATH Guid
;
235 UART_DEVICE_PATH Uart
;
236 EFI_DEVICE_PATH_PROTOCOL End
;
237 } SIMPLE_TEXT_OUT_DEVICE_PATH
;
239 SIMPLE_TEXT_OUT_DEVICE_PATH mDevicePath
= {
241 { HARDWARE_DEVICE_PATH
, HW_VENDOR_DP
, sizeof (VENDOR_DEVICE_PATH
), 0},
242 EFI_CALLER_ID_GUID
// Use the drivers GUID
245 { MESSAGING_DEVICE_PATH
, MSG_UART_DP
, sizeof (UART_DEVICE_PATH
), 0},
247 FixedPcdGet64 (PcdUartDefaultBaudRate
), // BaudRate
248 FixedPcdGet8 (PcdUartDefaultDataBits
), // DataBits
249 FixedPcdGet8 (PcdUartDefaultParity
), // Parity (N)
250 FixedPcdGet8 (PcdUartDefaultStopBits
) // StopBits
252 { END_DEVICE_PATH_TYPE
, END_ENTIRE_DEVICE_PATH_SUBTYPE
, sizeof (EFI_DEVICE_PATH_PROTOCOL
), 0}
257 Initialize the state information for the Serial Io Protocol
259 @param ImageHandle of the loaded driver
260 @param SystemTable Pointer to the System Table
262 @retval EFI_SUCCESS Protocol registered
263 @retval EFI_OUT_OF_RESOURCES Cannot allocate protocol data structure
264 @retval EFI_DEVICE_ERROR Hardware problems
269 SerialDxeInitialize (
270 IN EFI_HANDLE ImageHandle
,
271 IN EFI_SYSTEM_TABLE
*SystemTable
277 // Make a new handle with Serial IO protocol and its device path on it.
278 Status
= gBS
->InstallMultipleProtocolInterfaces (
280 &gEfiSerialIoProtocolGuid
, &gSerialIoTemplate
,
281 &gEfiDevicePathProtocolGuid
, &mDevicePath
,
284 ASSERT_EFI_ERROR (Status
);