3 Copyright (c) 2006 - 2008, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
21 #ifndef _UNIXPKG_SERIAL_IO_
22 #define _UNIXPKG_SERIAL_IO_
23 #include <sys/types.h>
32 #include <Protocol/SerialIo.h>
33 #include <Protocol/DevicePath.h>
35 #include <Library/DebugLib.h>
36 #include <Library/BaseLib.h>
37 #include <Library/UefiDriverEntryPoint.h>
38 #include <Library/UefiLib.h>
39 #include <Library/BaseMemoryLib.h>
40 #include <Library/UefiBootServicesTableLib.h>
41 #include <Library/DevicePathLib.h>
42 #include <Library/MemoryAllocationLib.h>
45 extern EFI_DRIVER_BINDING_PROTOCOL gUnixSerialIoDriverBinding
;
46 extern EFI_COMPONENT_NAME_PROTOCOL gUnixSerialIoComponentName
;
48 #define SERIAL_MAX_BUFFER_SIZE 256
49 #define TIMEOUT_STALL_INTERVAL 10
55 UINT8 Data
[SERIAL_MAX_BUFFER_SIZE
];
58 #define UNIX_SERIAL_IO_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('U', 'N', 's', 'i')
63 // Protocol data for the new handle we are going to add
66 EFI_SERIAL_IO_PROTOCOL SerialIo
;
67 EFI_SERIAL_IO_MODE SerialIoMode
;
68 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
73 EFI_HANDLE ControllerHandle
;
74 EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
;
75 UART_DEVICE_PATH UartDevicePath
;
76 EFI_UNIX_THUNK_PROTOCOL
*UnixThunk
;
78 EFI_UNICODE_STRING_TABLE
*ControllerNameTable
;
81 // Private NT type Data;
84 struct termios UnixTermios
;
86 BOOLEAN SoftwareLoopbackEnable
;
87 BOOLEAN HardwareFlowControl
;
88 BOOLEAN HardwareLoopbackEnable
;
92 } UNIX_SERIAL_IO_PRIVATE_DATA
;
94 #define UNIX_SERIAL_IO_PRIVATE_DATA_FROM_THIS(a) \
95 CR(a, UNIX_SERIAL_IO_PRIVATE_DATA, SerialIo, UNIX_SERIAL_IO_PRIVATE_DATA_SIGNATURE)
98 // Global Protocol Variables
100 extern EFI_DRIVER_BINDING_PROTOCOL gUnixSerialIoDriverBinding
;
101 extern EFI_COMPONENT_NAME_PROTOCOL gUnixSerialIoComponentName
;
104 // Macros to convert EFI serial types to NT serial types.
110 #define SERIAL_TIMEOUT_DEFAULT (1000 * 1000)
111 #define SERIAL_BAUD_DEFAULT 115200
112 #define SERIAL_FIFO_DEFAULT 14
113 #define SERIAL_DATABITS_DEFAULT 8
114 #define SERIAL_PARITY_DEFAULT DefaultParity
115 #define SERIAL_STOPBITS_DEFAULT DefaultStopBits
117 #define SERIAL_CONTROL_MASK (EFI_SERIAL_CLEAR_TO_SEND | \
118 EFI_SERIAL_DATA_SET_READY | \
119 EFI_SERIAL_RING_INDICATE | \
120 EFI_SERIAL_CARRIER_DETECT | \
121 EFI_SERIAL_REQUEST_TO_SEND | \
122 EFI_SERIAL_DATA_TERMINAL_READY | \
123 EFI_SERIAL_INPUT_BUFFER_EMPTY)
125 #define ConvertBaud2Nt(x) (DWORD) x
126 #define ConvertData2Nt(x) (BYTE) x
128 #define ConvertParity2Nt(x) \
130 x == DefaultParity ? NOPARITY : \
131 x == NoParity ? NOPARITY : \
132 x == EvenParity ? EVENPARITY : \
133 x == OddParity ? ODDPARITY : \
134 x == MarkParity ? MARKPARITY : \
135 x == SpaceParity ? SPACEPARITY : 0 \
138 #define ConvertStop2Nt(x) \
140 x == DefaultParity ? ONESTOPBIT : \
141 x == OneFiveStopBits ? ONE5STOPBITS : \
142 x == TwoStopBits ? TWOSTOPBITS : 0 \
145 #define ConvertTime2Nt(x) ((x) / 1000)
148 // 115400 baud with rounding errors
150 #define SERIAL_PORT_MAX_BAUD_RATE 115400
153 // Fix the differences issue of linux header files termios.h
156 #define B460800 0010004
159 #define B500000 0010005
162 #define B576000 0010006
165 #define B921600 0010007
168 #define B1000000 0010010
171 #define B1152000 0010011
174 #define B1500000 0010012
177 #define B2000000 0010013
180 #define B2500000 0010014
183 #define B3000000 0010015
186 #define B3500000 0010016
189 #define B4000000 0010017
192 #define __MAX_BAUD B4000000
195 #define CMSPAR 010000000000 /* mark or space (stick) parity */
198 #define FIONREAD 0x541B
201 // Function Prototypes
205 InitializeUnixSerialIo (
206 IN EFI_HANDLE ImageHandle
,
207 IN EFI_SYSTEM_TABLE
*SystemTable
213 TODO: Add function description
217 ImageHandle - TODO: add argument description
218 SystemTable - TODO: add argument description
222 TODO: add return values
229 UnixSerialIoDriverBindingSupported (
230 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
231 IN EFI_HANDLE Handle
,
232 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
238 TODO: Add function description
242 This - TODO: add argument description
243 Handle - TODO: add argument description
244 RemainingDevicePath - TODO: add argument description
248 TODO: add return values
255 UnixSerialIoDriverBindingStart (
256 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
257 IN EFI_HANDLE Handle
,
258 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
264 TODO: Add function description
268 This - TODO: add argument description
269 Handle - TODO: add argument description
270 RemainingDevicePath - TODO: add argument description
274 TODO: add return values
281 UnixSerialIoDriverBindingStop (
282 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
283 IN EFI_HANDLE Handle
,
284 IN UINTN NumberOfChildren
,
285 IN EFI_HANDLE
*ChildHandleBuffer
291 TODO: Add function description
295 This - TODO: add argument description
296 Handle - TODO: add argument description
297 NumberOfChildren - TODO: add argument description
298 ChildHandleBuffer - TODO: add argument description
302 TODO: add return values
310 IN EFI_SERIAL_IO_PROTOCOL
*This
316 TODO: Add function description
320 This - TODO: add argument description
324 TODO: add return values
331 UnixSerialIoSetAttributes (
332 IN EFI_SERIAL_IO_PROTOCOL
*This
,
334 IN UINT32 ReceiveFifoDepth
,
336 IN EFI_PARITY_TYPE Parity
,
338 IN EFI_STOP_BITS_TYPE StopBits
344 TODO: Add function description
348 This - TODO: add argument description
349 BaudRate - TODO: add argument description
350 ReceiveFifoDepth - TODO: add argument description
351 Timeout - TODO: add argument description
352 Parity - TODO: add argument description
353 DataBits - TODO: add argument description
354 StopBits - TODO: add argument description
358 TODO: add return values
365 UnixSerialIoSetControl (
366 IN EFI_SERIAL_IO_PROTOCOL
*This
,
373 TODO: Add function description
377 This - TODO: add argument description
378 Control - TODO: add argument description
382 TODO: add return values
389 UnixSerialIoGetControl (
390 IN EFI_SERIAL_IO_PROTOCOL
*This
,
397 TODO: Add function description
401 This - TODO: add argument description
402 Control - TODO: add argument description
406 TODO: add return values
414 IN EFI_SERIAL_IO_PROTOCOL
*This
,
415 IN OUT UINTN
*BufferSize
,
422 TODO: Add function description
426 This - TODO: add argument description
427 BufferSize - TODO: add argument description
428 Buffer - TODO: add argument description
432 TODO: add return values
440 IN EFI_SERIAL_IO_PROTOCOL
*This
,
441 IN OUT UINTN
*BufferSize
,
448 TODO: Add function description
452 This - TODO: add argument description
453 BufferSize - TODO: add argument description
454 Buffer - TODO: add argument description
458 TODO: add return values
465 IN SERIAL_DEV_FIFO
*Fifo
471 TODO: Add function description
475 Fifo - TODO: add argument description
479 TODO: add return values
486 IN SERIAL_DEV_FIFO
*Fifo
492 TODO: Add function description
496 Fifo - TODO: add argument description
500 TODO: add return values
507 IN SERIAL_DEV_FIFO
*Fifo
,
514 TODO: Add function description
518 Fifo - TODO: add argument description
519 Data - TODO: add argument description
523 TODO: add return values
529 IsaSerialFifoRemove (
530 IN SERIAL_DEV_FIFO
*Fifo
,
537 TODO: Add function description
541 Fifo - TODO: add argument description
542 Data - TODO: add argument description
546 TODO: add return values
552 IsaSerialReceiveTransmit (
553 UNIX_SERIAL_IO_PRIVATE_DATA
*Private
559 TODO: Add function description
563 Private - TODO: add argument description
567 TODO: add return values