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.<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/receice 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 ReveiveFifoDepth 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 dfault 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 vaule 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 thecontrol 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 Writes data to 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 Count
= SerialPortRead (Buffer
, *BufferSize
);
195 return (Count
== 0) ? EFI_DEVICE_ERROR
: EFI_SUCCESS
;
199 EFI_HANDLE gHandle
= NULL
;
202 // Template used to initailize the GDB Serial IO protocols
204 EFI_SERIAL_IO_MODE gSerialIoMode
= {
207 FixedPcdGet64 (PcdUartDefaultBaudRate
), // BaudRate
208 1, // RceiveFifoDepth
209 FixedPcdGet8 (PcdUartDefaultDataBits
), // DataBits
210 FixedPcdGet8 (PcdUartDefaultParity
), // Parity
211 FixedPcdGet8 (PcdUartDefaultStopBits
) // StopBits
215 EFI_SERIAL_IO_PROTOCOL gSerialIoTemplate
= {
216 SERIAL_IO_INTERFACE_REVISION
,
227 VENDOR_DEVICE_PATH Guid
;
228 UART_DEVICE_PATH Uart
;
229 EFI_DEVICE_PATH_PROTOCOL End
;
230 } SIMPLE_TEXT_OUT_DEVICE_PATH
;
232 SIMPLE_TEXT_OUT_DEVICE_PATH mDevicePath
= {
234 { HARDWARE_DEVICE_PATH
, HW_VENDOR_DP
, sizeof (VENDOR_DEVICE_PATH
), 0},
235 EFI_CALLER_ID_GUID
// Use the drivers GUID
238 { END_DEVICE_PATH_TYPE
, END_ENTIRE_DEVICE_PATH_SUBTYPE
, sizeof (UART_DEVICE_PATH
), 0},
240 FixedPcdGet64 (PcdUartDefaultBaudRate
), // BaudRate
241 FixedPcdGet8 (PcdUartDefaultDataBits
), // DataBits
242 FixedPcdGet8 (PcdUartDefaultParity
), // Parity (N)
243 FixedPcdGet8 (PcdUartDefaultStopBits
) // StopBits
245 { END_DEVICE_PATH_TYPE
, END_ENTIRE_DEVICE_PATH_SUBTYPE
, sizeof (EFI_DEVICE_PATH_PROTOCOL
), 0}
250 Initialize the state information for the Serial Io Protocol
252 @param ImageHandle of the loaded driver
253 @param SystemTable Pointer to the System Table
255 @retval EFI_SUCCESS Protocol registered
256 @retval EFI_OUT_OF_RESOURCES Cannot allocate protocol data structure
257 @retval EFI_DEVICE_ERROR Hardware problems
262 SerialDxeInitialize (
263 IN EFI_HANDLE ImageHandle
,
264 IN EFI_SYSTEM_TABLE
*SystemTable
270 // Make a new handle with Serial IO protocol and its device path on it.
271 Status
= gBS
->InstallMultipleProtocolInterfaces (
273 &gEfiSerialIoProtocolGuid
, &gSerialIoTemplate
,
274 &gEfiDevicePathProtocolGuid
, &mDevicePath
,
277 ASSERT_EFI_ERROR (Status
);