refine comments for EFI_CONSOLE_CONTROL_PROTOCOL
[edk2.git] / UnixPkg / UnixSerialIoDxe / UnixSerialIo.h
blob2a63f24d4836fc1a8d853f192b478caea8791826
1 /*++
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.
12 Module Name:
14 UnixSerialIo.h
16 Abstract:
19 --*/
21 #ifndef _UNIXPKG_SERIAL_IO_
22 #define _UNIXPKG_SERIAL_IO_
23 #include <sys/types.h>
24 #include <sys/stat.h>
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <termio.h>
28 #include <fcntl.h>
29 #include <errno.h>
31 #include "PiDxe.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>
43 #include "UnixDxe.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
51 typedef struct {
52 UINT32 First;
53 UINT32 Last;
54 UINT32 Surplus;
55 UINT8 Data[SERIAL_MAX_BUFFER_SIZE];
56 } SERIAL_DEV_FIFO;
58 #define UNIX_SERIAL_IO_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('U', 'N', 's', 'i')
59 typedef struct {
60 UINT64 Signature;
63 // Protocol data for the new handle we are going to add
65 EFI_HANDLE Handle;
66 EFI_SERIAL_IO_PROTOCOL SerialIo;
67 EFI_SERIAL_IO_MODE SerialIoMode;
68 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
71 // Private Data
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;
83 UINTN UnixHandle;
84 struct termios UnixTermios;
86 BOOLEAN SoftwareLoopbackEnable;
87 BOOLEAN HardwareFlowControl;
88 BOOLEAN HardwareLoopbackEnable;
90 SERIAL_DEV_FIFO Fifo;
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.
108 // one second
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) \
129 (BYTE) ( \
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) \
139 (BYTE) ( \
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
155 #ifndef B460800
156 #define B460800 0010004
157 #endif
158 #ifndef B500000
159 #define B500000 0010005
160 #endif
161 #ifndef B576000
162 #define B576000 0010006
163 #endif
164 #ifndef B921600
165 #define B921600 0010007
166 #endif
167 #ifndef B1000000
168 #define B1000000 0010010
169 #endif
170 #ifndef B1152000
171 #define B1152000 0010011
172 #endif
173 #ifndef B1500000
174 #define B1500000 0010012
175 #endif
176 #ifndef B2000000
177 #define B2000000 0010013
178 #endif
179 #ifndef B2500000
180 #define B2500000 0010014
181 #endif
182 #ifndef B3000000
183 #define B3000000 0010015
184 #endif
185 #ifndef B3500000
186 #define B3500000 0010016
187 #endif
188 #ifndef B4000000
189 #define B4000000 0010017
190 #endif
191 #ifndef __MAX_BAUD
192 #define __MAX_BAUD B4000000
193 #endif
194 #ifndef CMSPAR
195 #define CMSPAR 010000000000 /* mark or space (stick) parity */
196 #endif
197 #ifndef FIONREAD
198 #define FIONREAD 0x541B
199 #endif
201 // Function Prototypes
203 EFI_STATUS
204 EFIAPI
205 InitializeUnixSerialIo (
206 IN EFI_HANDLE ImageHandle,
207 IN EFI_SYSTEM_TABLE *SystemTable
209 /*++
211 Routine Description:
213 TODO: Add function description
215 Arguments:
217 ImageHandle - TODO: add argument description
218 SystemTable - TODO: add argument description
220 Returns:
222 TODO: add return values
224 --*/
227 EFI_STATUS
228 EFIAPI
229 UnixSerialIoDriverBindingSupported (
230 IN EFI_DRIVER_BINDING_PROTOCOL *This,
231 IN EFI_HANDLE Handle,
232 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
234 /*++
236 Routine Description:
238 TODO: Add function description
240 Arguments:
242 This - TODO: add argument description
243 Handle - TODO: add argument description
244 RemainingDevicePath - TODO: add argument description
246 Returns:
248 TODO: add return values
250 --*/
253 EFI_STATUS
254 EFIAPI
255 UnixSerialIoDriverBindingStart (
256 IN EFI_DRIVER_BINDING_PROTOCOL *This,
257 IN EFI_HANDLE Handle,
258 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
260 /*++
262 Routine Description:
264 TODO: Add function description
266 Arguments:
268 This - TODO: add argument description
269 Handle - TODO: add argument description
270 RemainingDevicePath - TODO: add argument description
272 Returns:
274 TODO: add return values
276 --*/
279 EFI_STATUS
280 EFIAPI
281 UnixSerialIoDriverBindingStop (
282 IN EFI_DRIVER_BINDING_PROTOCOL *This,
283 IN EFI_HANDLE Handle,
284 IN UINTN NumberOfChildren,
285 IN EFI_HANDLE *ChildHandleBuffer
287 /*++
289 Routine Description:
291 TODO: Add function description
293 Arguments:
295 This - TODO: add argument description
296 Handle - TODO: add argument description
297 NumberOfChildren - TODO: add argument description
298 ChildHandleBuffer - TODO: add argument description
300 Returns:
302 TODO: add return values
304 --*/
307 EFI_STATUS
308 EFIAPI
309 UnixSerialIoReset (
310 IN EFI_SERIAL_IO_PROTOCOL *This
312 /*++
314 Routine Description:
316 TODO: Add function description
318 Arguments:
320 This - TODO: add argument description
322 Returns:
324 TODO: add return values
326 --*/
329 EFI_STATUS
330 EFIAPI
331 UnixSerialIoSetAttributes (
332 IN EFI_SERIAL_IO_PROTOCOL *This,
333 IN UINT64 BaudRate,
334 IN UINT32 ReceiveFifoDepth,
335 IN UINT32 Timeout,
336 IN EFI_PARITY_TYPE Parity,
337 IN UINT8 DataBits,
338 IN EFI_STOP_BITS_TYPE StopBits
340 /*++
342 Routine Description:
344 TODO: Add function description
346 Arguments:
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
356 Returns:
358 TODO: add return values
360 --*/
363 EFI_STATUS
364 EFIAPI
365 UnixSerialIoSetControl (
366 IN EFI_SERIAL_IO_PROTOCOL *This,
367 IN UINT32 Control
369 /*++
371 Routine Description:
373 TODO: Add function description
375 Arguments:
377 This - TODO: add argument description
378 Control - TODO: add argument description
380 Returns:
382 TODO: add return values
384 --*/
387 EFI_STATUS
388 EFIAPI
389 UnixSerialIoGetControl (
390 IN EFI_SERIAL_IO_PROTOCOL *This,
391 OUT UINT32 *Control
393 /*++
395 Routine Description:
397 TODO: Add function description
399 Arguments:
401 This - TODO: add argument description
402 Control - TODO: add argument description
404 Returns:
406 TODO: add return values
408 --*/
411 EFI_STATUS
412 EFIAPI
413 UnixSerialIoWrite (
414 IN EFI_SERIAL_IO_PROTOCOL *This,
415 IN OUT UINTN *BufferSize,
416 IN VOID *Buffer
418 /*++
420 Routine Description:
422 TODO: Add function description
424 Arguments:
426 This - TODO: add argument description
427 BufferSize - TODO: add argument description
428 Buffer - TODO: add argument description
430 Returns:
432 TODO: add return values
434 --*/
437 EFI_STATUS
438 EFIAPI
439 UnixSerialIoRead (
440 IN EFI_SERIAL_IO_PROTOCOL *This,
441 IN OUT UINTN *BufferSize,
442 OUT VOID *Buffer
444 /*++
446 Routine Description:
448 TODO: Add function description
450 Arguments:
452 This - TODO: add argument description
453 BufferSize - TODO: add argument description
454 Buffer - TODO: add argument description
456 Returns:
458 TODO: add return values
460 --*/
463 BOOLEAN
464 IsaSerialFifoFull (
465 IN SERIAL_DEV_FIFO *Fifo
467 /*++
469 Routine Description:
471 TODO: Add function description
473 Arguments:
475 Fifo - TODO: add argument description
477 Returns:
479 TODO: add return values
481 --*/
484 BOOLEAN
485 IsaSerialFifoEmpty (
486 IN SERIAL_DEV_FIFO *Fifo
488 /*++
490 Routine Description:
492 TODO: Add function description
494 Arguments:
496 Fifo - TODO: add argument description
498 Returns:
500 TODO: add return values
502 --*/
505 EFI_STATUS
506 IsaSerialFifoAdd (
507 IN SERIAL_DEV_FIFO *Fifo,
508 IN UINT8 Data
510 /*++
512 Routine Description:
514 TODO: Add function description
516 Arguments:
518 Fifo - TODO: add argument description
519 Data - TODO: add argument description
521 Returns:
523 TODO: add return values
525 --*/
528 EFI_STATUS
529 IsaSerialFifoRemove (
530 IN SERIAL_DEV_FIFO *Fifo,
531 OUT UINT8 *Data
533 /*++
535 Routine Description:
537 TODO: Add function description
539 Arguments:
541 Fifo - TODO: add argument description
542 Data - TODO: add argument description
544 Returns:
546 TODO: add return values
548 --*/
551 EFI_STATUS
552 IsaSerialReceiveTransmit (
553 UNIX_SERIAL_IO_PRIVATE_DATA *Private
555 /*++
557 Routine Description:
559 TODO: Add function description
561 Arguments:
563 Private - TODO: add argument description
565 Returns:
567 TODO: add return values
569 --*/
572 #endif