3 Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>
4 Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
5 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_
25 #include <Common/UnixInclude.h>
28 #include <Protocol/SerialIo.h>
29 #include <Protocol/DevicePath.h>
31 #include <Library/DebugLib.h>
32 #include <Library/BaseLib.h>
33 #include <Library/UefiDriverEntryPoint.h>
34 #include <Library/UefiLib.h>
35 #include <Library/BaseMemoryLib.h>
36 #include <Library/UefiBootServicesTableLib.h>
37 #include <Library/DevicePathLib.h>
38 #include <Library/MemoryAllocationLib.h>
41 extern EFI_DRIVER_BINDING_PROTOCOL gUnixSerialIoDriverBinding
;
42 extern EFI_COMPONENT_NAME_PROTOCOL gUnixSerialIoComponentName
;
44 #define SERIAL_MAX_BUFFER_SIZE 256
45 #define TIMEOUT_STALL_INTERVAL 10
51 UINT8 Data
[SERIAL_MAX_BUFFER_SIZE
];
54 #define UNIX_SERIAL_IO_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('U', 'N', 's', 'i')
59 // Protocol data for the new handle we are going to add
62 EFI_SERIAL_IO_PROTOCOL SerialIo
;
63 EFI_SERIAL_IO_MODE SerialIoMode
;
64 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
69 EFI_HANDLE ControllerHandle
;
70 EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
;
71 UART_DEVICE_PATH UartDevicePath
;
72 EFI_UNIX_THUNK_PROTOCOL
*UnixThunk
;
74 EFI_UNICODE_STRING_TABLE
*ControllerNameTable
;
77 // Private NT type Data;
80 struct termios UnixTermios
;
82 BOOLEAN SoftwareLoopbackEnable
;
83 BOOLEAN HardwareFlowControl
;
84 BOOLEAN HardwareLoopbackEnable
;
88 } UNIX_SERIAL_IO_PRIVATE_DATA
;
90 #define UNIX_SERIAL_IO_PRIVATE_DATA_FROM_THIS(a) \
91 CR(a, UNIX_SERIAL_IO_PRIVATE_DATA, SerialIo, UNIX_SERIAL_IO_PRIVATE_DATA_SIGNATURE)
94 // Global Protocol Variables
96 extern EFI_DRIVER_BINDING_PROTOCOL gUnixSerialIoDriverBinding
;
97 extern EFI_COMPONENT_NAME_PROTOCOL gUnixSerialIoComponentName
;
100 // Macros to convert EFI serial types to NT serial types.
106 #define SERIAL_TIMEOUT_DEFAULT (1000 * 1000)
107 #define SERIAL_BAUD_DEFAULT 115200
108 #define SERIAL_FIFO_DEFAULT 14
109 #define SERIAL_DATABITS_DEFAULT 8
110 #define SERIAL_PARITY_DEFAULT DefaultParity
111 #define SERIAL_STOPBITS_DEFAULT DefaultStopBits
113 #define SERIAL_CONTROL_MASK (EFI_SERIAL_CLEAR_TO_SEND | \
114 EFI_SERIAL_DATA_SET_READY | \
115 EFI_SERIAL_RING_INDICATE | \
116 EFI_SERIAL_CARRIER_DETECT | \
117 EFI_SERIAL_REQUEST_TO_SEND | \
118 EFI_SERIAL_DATA_TERMINAL_READY | \
119 EFI_SERIAL_HARDWARE_LOOPBACK_ENABLE | \
120 EFI_SERIAL_SOFTWARE_LOOPBACK_ENABLE | \
121 EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE | \
122 EFI_SERIAL_INPUT_BUFFER_EMPTY)
124 #define ConvertBaud2Nt(x) (DWORD) x
125 #define ConvertData2Nt(x) (BYTE) x
127 #define ConvertParity2Nt(x) \
129 x == DefaultParity ? NOPARITY : \
130 x == NoParity ? NOPARITY : \
131 x == EvenParity ? EVENPARITY : \
132 x == OddParity ? ODDPARITY : \
133 x == MarkParity ? MARKPARITY : \
134 x == SpaceParity ? SPACEPARITY : 0 \
137 #define ConvertStop2Nt(x) \
139 x == DefaultParity ? ONESTOPBIT : \
140 x == OneFiveStopBits ? ONE5STOPBITS : \
141 x == TwoStopBits ? TWOSTOPBITS : 0 \
144 #define ConvertTime2Nt(x) ((x) / 1000)
147 // 115400 baud with rounding errors
149 #define SERIAL_PORT_MAX_BAUD_RATE 115400
152 // Fix the differences issue of linux header files termios.h
155 #define B460800 0010004
158 #define B500000 0010005
161 #define B576000 0010006
164 #define B921600 0010007
167 #define B1000000 0010010
170 #define B1152000 0010011
173 #define B1500000 0010012
176 #define B2000000 0010013
179 #define B2500000 0010014
182 #define B3000000 0010015
185 #define B3500000 0010016
188 #define B4000000 0010017
191 #define __MAX_BAUD B4000000
194 #define CMSPAR 010000000000 /* mark or space (stick) parity */
197 #define FIONREAD 0x541B
200 // Function Prototypes
204 InitializeUnixSerialIo (
205 IN EFI_HANDLE ImageHandle
,
206 IN EFI_SYSTEM_TABLE
*SystemTable
212 TODO: Add function description
216 ImageHandle - TODO: add argument description
217 SystemTable - TODO: add argument description
221 TODO: add return values
228 UnixSerialIoDriverBindingSupported (
229 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
230 IN EFI_HANDLE Handle
,
231 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
237 TODO: Add function description
241 This - TODO: add argument description
242 Handle - TODO: add argument description
243 RemainingDevicePath - TODO: add argument description
247 TODO: add return values
254 UnixSerialIoDriverBindingStart (
255 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
256 IN EFI_HANDLE Handle
,
257 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
263 TODO: Add function description
267 This - TODO: add argument description
268 Handle - TODO: add argument description
269 RemainingDevicePath - TODO: add argument description
273 TODO: add return values
280 UnixSerialIoDriverBindingStop (
281 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
282 IN EFI_HANDLE Handle
,
283 IN UINTN NumberOfChildren
,
284 IN EFI_HANDLE
*ChildHandleBuffer
290 TODO: Add function description
294 This - TODO: add argument description
295 Handle - TODO: add argument description
296 NumberOfChildren - TODO: add argument description
297 ChildHandleBuffer - TODO: add argument description
301 TODO: add return values
309 IN EFI_SERIAL_IO_PROTOCOL
*This
315 TODO: Add function description
319 This - TODO: add argument description
323 TODO: add return values
330 UnixSerialIoSetAttributes (
331 IN EFI_SERIAL_IO_PROTOCOL
*This
,
333 IN UINT32 ReceiveFifoDepth
,
335 IN EFI_PARITY_TYPE Parity
,
337 IN EFI_STOP_BITS_TYPE StopBits
343 TODO: Add function description
347 This - TODO: add argument description
348 BaudRate - TODO: add argument description
349 ReceiveFifoDepth - TODO: add argument description
350 Timeout - TODO: add argument description
351 Parity - TODO: add argument description
352 DataBits - TODO: add argument description
353 StopBits - TODO: add argument description
357 TODO: add return values
364 UnixSerialIoSetControl (
365 IN EFI_SERIAL_IO_PROTOCOL
*This
,
372 TODO: Add function description
376 This - TODO: add argument description
377 Control - TODO: add argument description
381 TODO: add return values
388 UnixSerialIoGetControl (
389 IN EFI_SERIAL_IO_PROTOCOL
*This
,
396 TODO: Add function description
400 This - TODO: add argument description
401 Control - TODO: add argument description
405 TODO: add return values
413 IN EFI_SERIAL_IO_PROTOCOL
*This
,
414 IN OUT UINTN
*BufferSize
,
421 TODO: Add function description
425 This - TODO: add argument description
426 BufferSize - TODO: add argument description
427 Buffer - TODO: add argument description
431 TODO: add return values
439 IN EFI_SERIAL_IO_PROTOCOL
*This
,
440 IN OUT UINTN
*BufferSize
,
447 TODO: Add function description
451 This - TODO: add argument description
452 BufferSize - TODO: add argument description
453 Buffer - TODO: add argument description
457 TODO: add return values
464 IN SERIAL_DEV_FIFO
*Fifo
470 TODO: Add function description
474 Fifo - TODO: add argument description
478 TODO: add return values
485 IN SERIAL_DEV_FIFO
*Fifo
491 TODO: Add function description
495 Fifo - TODO: add argument description
499 TODO: add return values
506 IN SERIAL_DEV_FIFO
*Fifo
,
513 TODO: Add function description
517 Fifo - TODO: add argument description
518 Data - TODO: add argument description
522 TODO: add return values
528 IsaSerialFifoRemove (
529 IN SERIAL_DEV_FIFO
*Fifo
,
536 TODO: Add function description
540 Fifo - TODO: add argument description
541 Data - TODO: add argument description
545 TODO: add return values
551 IsaSerialReceiveTransmit (
552 UNIX_SERIAL_IO_PRIVATE_DATA
*Private
558 TODO: Add function description
562 Private - TODO: add argument description
566 TODO: add return values