3 Copyright (c) 2006 - 2009, Intel Corporation
4 Portions copyright (c) 2008-2009 Apple Inc.
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
22 #ifndef _UNIXPKG_SERIAL_IO_
23 #define _UNIXPKG_SERIAL_IO_
24 #include <sys/types.h>
38 #include <Protocol/SerialIo.h>
39 #include <Protocol/DevicePath.h>
41 #include <Library/DebugLib.h>
42 #include <Library/BaseLib.h>
43 #include <Library/UefiDriverEntryPoint.h>
44 #include <Library/UefiLib.h>
45 #include <Library/BaseMemoryLib.h>
46 #include <Library/UefiBootServicesTableLib.h>
47 #include <Library/DevicePathLib.h>
48 #include <Library/MemoryAllocationLib.h>
51 extern EFI_DRIVER_BINDING_PROTOCOL gUnixSerialIoDriverBinding
;
52 extern EFI_COMPONENT_NAME_PROTOCOL gUnixSerialIoComponentName
;
54 #define SERIAL_MAX_BUFFER_SIZE 256
55 #define TIMEOUT_STALL_INTERVAL 10
61 UINT8 Data
[SERIAL_MAX_BUFFER_SIZE
];
64 #define UNIX_SERIAL_IO_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('U', 'N', 's', 'i')
69 // Protocol data for the new handle we are going to add
72 EFI_SERIAL_IO_PROTOCOL SerialIo
;
73 EFI_SERIAL_IO_MODE SerialIoMode
;
74 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
79 EFI_HANDLE ControllerHandle
;
80 EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
;
81 UART_DEVICE_PATH UartDevicePath
;
82 EFI_UNIX_THUNK_PROTOCOL
*UnixThunk
;
84 EFI_UNICODE_STRING_TABLE
*ControllerNameTable
;
87 // Private NT type Data;
90 struct termios UnixTermios
;
92 BOOLEAN SoftwareLoopbackEnable
;
93 BOOLEAN HardwareFlowControl
;
94 BOOLEAN HardwareLoopbackEnable
;
98 } UNIX_SERIAL_IO_PRIVATE_DATA
;
100 #define UNIX_SERIAL_IO_PRIVATE_DATA_FROM_THIS(a) \
101 CR(a, UNIX_SERIAL_IO_PRIVATE_DATA, SerialIo, UNIX_SERIAL_IO_PRIVATE_DATA_SIGNATURE)
104 // Global Protocol Variables
106 extern EFI_DRIVER_BINDING_PROTOCOL gUnixSerialIoDriverBinding
;
107 extern EFI_COMPONENT_NAME_PROTOCOL gUnixSerialIoComponentName
;
110 // Macros to convert EFI serial types to NT serial types.
116 #define SERIAL_TIMEOUT_DEFAULT (1000 * 1000)
117 #define SERIAL_BAUD_DEFAULT 115200
118 #define SERIAL_FIFO_DEFAULT 14
119 #define SERIAL_DATABITS_DEFAULT 8
120 #define SERIAL_PARITY_DEFAULT DefaultParity
121 #define SERIAL_STOPBITS_DEFAULT DefaultStopBits
123 #define SERIAL_CONTROL_MASK (EFI_SERIAL_CLEAR_TO_SEND | \
124 EFI_SERIAL_DATA_SET_READY | \
125 EFI_SERIAL_RING_INDICATE | \
126 EFI_SERIAL_CARRIER_DETECT | \
127 EFI_SERIAL_REQUEST_TO_SEND | \
128 EFI_SERIAL_DATA_TERMINAL_READY | \
129 EFI_SERIAL_HARDWARE_LOOPBACK_ENABLE | \
130 EFI_SERIAL_SOFTWARE_LOOPBACK_ENABLE | \
131 EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE | \
132 EFI_SERIAL_INPUT_BUFFER_EMPTY)
134 #define ConvertBaud2Nt(x) (DWORD) x
135 #define ConvertData2Nt(x) (BYTE) x
137 #define ConvertParity2Nt(x) \
139 x == DefaultParity ? NOPARITY : \
140 x == NoParity ? NOPARITY : \
141 x == EvenParity ? EVENPARITY : \
142 x == OddParity ? ODDPARITY : \
143 x == MarkParity ? MARKPARITY : \
144 x == SpaceParity ? SPACEPARITY : 0 \
147 #define ConvertStop2Nt(x) \
149 x == DefaultParity ? ONESTOPBIT : \
150 x == OneFiveStopBits ? ONE5STOPBITS : \
151 x == TwoStopBits ? TWOSTOPBITS : 0 \
154 #define ConvertTime2Nt(x) ((x) / 1000)
157 // 115400 baud with rounding errors
159 #define SERIAL_PORT_MAX_BAUD_RATE 115400
162 // Fix the differences issue of linux header files termios.h
165 #define B460800 0010004
168 #define B500000 0010005
171 #define B576000 0010006
174 #define B921600 0010007
177 #define B1000000 0010010
180 #define B1152000 0010011
183 #define B1500000 0010012
186 #define B2000000 0010013
189 #define B2500000 0010014
192 #define B3000000 0010015
195 #define B3500000 0010016
198 #define B4000000 0010017
201 #define __MAX_BAUD B4000000
204 #define CMSPAR 010000000000 /* mark or space (stick) parity */
207 #define FIONREAD 0x541B
210 // Function Prototypes
214 InitializeUnixSerialIo (
215 IN EFI_HANDLE ImageHandle
,
216 IN EFI_SYSTEM_TABLE
*SystemTable
222 TODO: Add function description
226 ImageHandle - TODO: add argument description
227 SystemTable - TODO: add argument description
231 TODO: add return values
238 UnixSerialIoDriverBindingSupported (
239 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
240 IN EFI_HANDLE Handle
,
241 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
247 TODO: Add function description
251 This - TODO: add argument description
252 Handle - TODO: add argument description
253 RemainingDevicePath - TODO: add argument description
257 TODO: add return values
264 UnixSerialIoDriverBindingStart (
265 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
266 IN EFI_HANDLE Handle
,
267 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
273 TODO: Add function description
277 This - TODO: add argument description
278 Handle - TODO: add argument description
279 RemainingDevicePath - TODO: add argument description
283 TODO: add return values
290 UnixSerialIoDriverBindingStop (
291 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
292 IN EFI_HANDLE Handle
,
293 IN UINTN NumberOfChildren
,
294 IN EFI_HANDLE
*ChildHandleBuffer
300 TODO: Add function description
304 This - TODO: add argument description
305 Handle - TODO: add argument description
306 NumberOfChildren - TODO: add argument description
307 ChildHandleBuffer - TODO: add argument description
311 TODO: add return values
319 IN EFI_SERIAL_IO_PROTOCOL
*This
325 TODO: Add function description
329 This - TODO: add argument description
333 TODO: add return values
340 UnixSerialIoSetAttributes (
341 IN EFI_SERIAL_IO_PROTOCOL
*This
,
343 IN UINT32 ReceiveFifoDepth
,
345 IN EFI_PARITY_TYPE Parity
,
347 IN EFI_STOP_BITS_TYPE StopBits
353 TODO: Add function description
357 This - TODO: add argument description
358 BaudRate - TODO: add argument description
359 ReceiveFifoDepth - TODO: add argument description
360 Timeout - TODO: add argument description
361 Parity - TODO: add argument description
362 DataBits - TODO: add argument description
363 StopBits - TODO: add argument description
367 TODO: add return values
374 UnixSerialIoSetControl (
375 IN EFI_SERIAL_IO_PROTOCOL
*This
,
382 TODO: Add function description
386 This - TODO: add argument description
387 Control - TODO: add argument description
391 TODO: add return values
398 UnixSerialIoGetControl (
399 IN EFI_SERIAL_IO_PROTOCOL
*This
,
406 TODO: Add function description
410 This - TODO: add argument description
411 Control - TODO: add argument description
415 TODO: add return values
423 IN EFI_SERIAL_IO_PROTOCOL
*This
,
424 IN OUT UINTN
*BufferSize
,
431 TODO: Add function description
435 This - TODO: add argument description
436 BufferSize - TODO: add argument description
437 Buffer - TODO: add argument description
441 TODO: add return values
449 IN EFI_SERIAL_IO_PROTOCOL
*This
,
450 IN OUT UINTN
*BufferSize
,
457 TODO: Add function description
461 This - TODO: add argument description
462 BufferSize - TODO: add argument description
463 Buffer - TODO: add argument description
467 TODO: add return values
474 IN SERIAL_DEV_FIFO
*Fifo
480 TODO: Add function description
484 Fifo - TODO: add argument description
488 TODO: add return values
495 IN SERIAL_DEV_FIFO
*Fifo
501 TODO: Add function description
505 Fifo - TODO: add argument description
509 TODO: add return values
516 IN SERIAL_DEV_FIFO
*Fifo
,
523 TODO: Add function description
527 Fifo - TODO: add argument description
528 Data - TODO: add argument description
532 TODO: add return values
538 IsaSerialFifoRemove (
539 IN SERIAL_DEV_FIFO
*Fifo
,
546 TODO: Add function description
550 Fifo - TODO: add argument description
551 Data - TODO: add argument description
555 TODO: add return values
561 IsaSerialReceiveTransmit (
562 UNIX_SERIAL_IO_PRIVATE_DATA
*Private
568 TODO: Add function description
572 Private - TODO: add argument description
576 TODO: add return values