2 Serial IO Abstraction for GDB stub. This allows an EFI consoles that shows up on the system
3 running GDB. One consle for error information and another console for user input/output.
5 Basic packet format is $packet-data#checksum. So every comand 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.
11 All rights reserved. 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>
27 #include <Protocol/SerialIo.h>
30 Reset the serial device.
32 @param This Protocol instance pointer.
34 @retval EFI_SUCCESS The device was reset.
35 @retval EFI_DEVICE_ERROR The serial device could not be reset.
41 IN EFI_SERIAL_IO_PROTOCOL
*This
44 SerialPortInitialize ();
50 Sets the baud rate, receive FIFO depth, transmit/receice time out, parity,
51 data buts, and stop bits on a serial device.
53 @param This Protocol instance pointer.
54 @param BaudRate The requested baud rate. A BaudRate value of 0 will use the the
55 device's default interface speed.
56 @param ReveiveFifoDepth The requested depth of the FIFO on the receive side of the
57 serial interface. A ReceiveFifoDepth value of 0 will use
58 the device's dfault FIFO depth.
59 @param Timeout The requested time out for a single character in microseconds.
60 This timeout applies to both the transmit and receive side of the
61 interface. A Timeout value of 0 will use the device's default time
63 @param Parity The type of parity to use on this serial device. A Parity value of
64 DefaultParity will use the device's default parity value.
65 @param DataBits The number of data bits to use on the serial device. A DataBits
66 vaule of 0 will use the device's default data bit setting.
67 @param StopBits The number of stop bits to use on this serial device. A StopBits
68 value of DefaultStopBits will use the device's default number of
71 @retval EFI_SUCCESS The device was reset.
72 @retval EFI_DEVICE_ERROR The serial device could not be reset.
78 IN EFI_SERIAL_IO_PROTOCOL
*This
,
80 IN UINT32 ReceiveFifoDepth
,
82 IN EFI_PARITY_TYPE Parity
,
84 IN EFI_STOP_BITS_TYPE StopBits
87 return EFI_UNSUPPORTED
;
92 Set the control bits on a serial device
94 @param This Protocol instance pointer.
95 @param Control Set the bits of Control that are settable.
97 @retval EFI_SUCCESS The new control bits were set on the serial device.
98 @retval EFI_UNSUPPORTED The serial device does not support this operation.
99 @retval EFI_DEVICE_ERROR The serial device is not functioning correctly.
105 IN EFI_SERIAL_IO_PROTOCOL
*This
,
109 return EFI_UNSUPPORTED
;
114 Retrieves the status of thecontrol bits on a serial device
116 @param This Protocol instance pointer.
117 @param Control A pointer to return the current Control signals from the serial device.
119 @retval EFI_SUCCESS The control bits were read from the serial device.
120 @retval EFI_DEVICE_ERROR The serial device is not functioning correctly.
126 IN EFI_SERIAL_IO_PROTOCOL
*This
,
130 if (SerialPortPoll ()) {
131 // If a character is pending don't set EFI_SERIAL_INPUT_BUFFER_EMPTY
132 *Control
= EFI_SERIAL_OUTPUT_BUFFER_EMPTY
;
134 *Control
= EFI_SERIAL_INPUT_BUFFER_EMPTY
| EFI_SERIAL_OUTPUT_BUFFER_EMPTY
;
141 Writes data to a serial device.
143 @param This Protocol instance pointer.
144 @param BufferSize On input, the size of the Buffer. On output, the amount of
145 data actually written.
146 @param Buffer The buffer of data to write
148 @retval EFI_SUCCESS The data was written.
149 @retval EFI_DEVICE_ERROR The device reported an error.
150 @retval EFI_TIMEOUT The data write was stopped due to a timeout.
156 IN EFI_SERIAL_IO_PROTOCOL
*This
,
157 IN OUT UINTN
*BufferSize
,
163 Count
= SerialPortWrite (Buffer
, *BufferSize
);
165 return (Count
== 0) ? EFI_DEVICE_ERROR
: EFI_SUCCESS
;
169 Writes data to a serial device.
171 @param This Protocol instance pointer.
172 @param BufferSize On input, the size of the Buffer. On output, the amount of
173 data returned in Buffer.
174 @param Buffer The buffer to return the data into.
176 @retval EFI_SUCCESS The data was read.
177 @retval EFI_DEVICE_ERROR The device reported an error.
178 @retval EFI_TIMEOUT The data write was stopped due to a timeout.
185 IN EFI_SERIAL_IO_PROTOCOL
*This
,
186 IN OUT UINTN
*BufferSize
,
192 Count
= SerialPortWrite (Buffer
, *BufferSize
);
194 return (Count
== 0) ? EFI_DEVICE_ERROR
: EFI_SUCCESS
;
198 EFI_HANDLE gHandle
= NULL
;
201 // Template used to initailize the GDB Serial IO protocols
203 EFI_SERIAL_IO_MODE gSerialIoMode
= {
207 1, // RceiveFifoDepth
214 EFI_SERIAL_IO_PROTOCOL gSerialIoTemplate
= {
215 SERIAL_IO_INTERFACE_REVISION
,
227 Initialize the state information for the Serial Io Protocol
229 @param ImageHandle of the loaded driver
230 @param SystemTable Pointer to the System Table
232 @retval EFI_SUCCESS Protocol registered
233 @retval EFI_OUT_OF_RESOURCES Cannot allocate protocol data structure
234 @retval EFI_DEVICE_ERROR Hardware problems
239 SerialDxeInitialize (
240 IN EFI_HANDLE ImageHandle
,
241 IN EFI_SYSTEM_TABLE
*SystemTable
247 // Make a new handle with Serial IO protocol and its device path on it.
248 Status
= gBS
->InstallMultipleProtocolInterfaces (
250 &gEfiSerialIoProtocolGuid
, &gSerialIoTemplate
,
251 &gEfiDevicePathProtocolGuid
, NULL
, // BugBug: Need a device path
254 ASSERT_EFI_ERROR (Status
);