]> git.proxmox.com Git - mirror_edk2.git/blob - EdkUnixPkg/Dxe/UnixThunk/Bus/SerialIo/UnixSerialIo.h
Fix the definition differences issue of termios.h in different version of kernel...
[mirror_edk2.git] / EdkUnixPkg / Dxe / UnixThunk / Bus / SerialIo / UnixSerialIo.h
1 /*++
2
3 Copyright (c) 2006, 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
8
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.
11
12 Module Name:
13
14 UnixSerialIo.h
15
16 Abstract:
17
18
19 --*/
20
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>
30
31 #define SERIAL_MAX_BUFFER_SIZE 256
32 #define TIMEOUT_STALL_INTERVAL 10
33
34 typedef struct {
35 UINT32 First;
36 UINT32 Last;
37 UINT32 Surplus;
38 UINT8 Data[SERIAL_MAX_BUFFER_SIZE];
39 } SERIAL_DEV_FIFO;
40
41 #define UNIX_SERIAL_IO_PRIVATE_DATA_SIGNATURE EFI_SIGNATURE_32 ('U', 'N', 's', 'i')
42 typedef struct {
43 UINT64 Signature;
44
45 //
46 // Protocol data for the new handle we are going to add
47 //
48 EFI_HANDLE Handle;
49 EFI_SERIAL_IO_PROTOCOL SerialIo;
50 EFI_SERIAL_IO_MODE SerialIoMode;
51 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
52
53 //
54 // Private Data
55 //
56 EFI_HANDLE ControllerHandle;
57 EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;
58 UART_DEVICE_PATH UartDevicePath;
59 EFI_UNIX_THUNK_PROTOCOL *UnixThunk;
60
61 EFI_UNICODE_STRING_TABLE *ControllerNameTable;
62
63 //
64 // Private NT type Data;
65 //
66 UINTN UnixHandle;
67 struct termios UnixTermios;
68
69 BOOLEAN SoftwareLoopbackEnable;
70 BOOLEAN HardwareFlowControl;
71 BOOLEAN HardwareLoopbackEnable;
72
73 SERIAL_DEV_FIFO Fifo;
74
75 } UNIX_SERIAL_IO_PRIVATE_DATA;
76
77 #define UNIX_SERIAL_IO_PRIVATE_DATA_FROM_THIS(a) \
78 CR(a, UNIX_SERIAL_IO_PRIVATE_DATA, SerialIo, UNIX_SERIAL_IO_PRIVATE_DATA_SIGNATURE)
79
80 //
81 // Global Protocol Variables
82 //
83 extern EFI_DRIVER_BINDING_PROTOCOL gUnixSerialIoDriverBinding;
84 extern EFI_COMPONENT_NAME_PROTOCOL gUnixSerialIoComponentName;
85
86 //
87 // Macros to convert EFI serial types to NT serial types.
88 //
89
90 //
91 // one second
92 //
93 #define SERIAL_TIMEOUT_DEFAULT (1000 * 1000)
94 #define SERIAL_BAUD_DEFAULT 115200
95 #define SERIAL_FIFO_DEFAULT 14
96 #define SERIAL_DATABITS_DEFAULT 8
97 #define SERIAL_PARITY_DEFAULT DefaultParity
98 #define SERIAL_STOPBITS_DEFAULT DefaultStopBits
99
100 #define SERIAL_CONTROL_MASK (EFI_SERIAL_CLEAR_TO_SEND | \
101 EFI_SERIAL_DATA_SET_READY | \
102 EFI_SERIAL_RING_INDICATE | \
103 EFI_SERIAL_CARRIER_DETECT | \
104 EFI_SERIAL_REQUEST_TO_SEND | \
105 EFI_SERIAL_DATA_TERMINAL_READY | \
106 EFI_SERIAL_INPUT_BUFFER_EMPTY)
107
108 #define ConvertBaud2Nt(x) (DWORD) x
109 #define ConvertData2Nt(x) (BYTE) x
110
111 #define ConvertParity2Nt(x) \
112 (BYTE) ( \
113 x == DefaultParity ? NOPARITY : \
114 x == NoParity ? NOPARITY : \
115 x == EvenParity ? EVENPARITY : \
116 x == OddParity ? ODDPARITY : \
117 x == MarkParity ? MARKPARITY : \
118 x == SpaceParity ? SPACEPARITY : 0 \
119 )
120
121 #define ConvertStop2Nt(x) \
122 (BYTE) ( \
123 x == DefaultParity ? ONESTOPBIT : \
124 x == OneFiveStopBits ? ONE5STOPBITS : \
125 x == TwoStopBits ? TWOSTOPBITS : 0 \
126 )
127
128 #define ConvertTime2Nt(x) ((x) / 1000)
129
130 //
131 // 115400 baud with rounding errors
132 //
133 #define SERIAL_PORT_MAX_BAUD_RATE 115400
134
135 //
136 // Fix the differences issue of linux header files termios.h
137 //
138 #ifndef B460800
139 #define B460800 0010004
140 #endif
141 #ifndef B500000
142 #define B500000 0010005
143 #endif
144 #ifndef B576000
145 #define B576000 0010006
146 #endif
147 #ifndef B921600
148 #define B921600 0010007
149 #endif
150 #ifndef B1000000
151 #define B1000000 0010010
152 #endif
153 #ifndef B1152000
154 #define B1152000 0010011
155 #endif
156 #ifndef B1500000
157 #define B1500000 0010012
158 #endif
159 #ifndef B2000000
160 #define B2000000 0010013
161 #endif
162 #ifndef B2500000
163 #define B2500000 0010014
164 #endif
165 #ifndef B3000000
166 #define B3000000 0010015
167 #endif
168 #ifndef B3500000
169 #define B3500000 0010016
170 #endif
171 #ifndef B4000000
172 #define B4000000 0010017
173 #endif
174 #ifndef __MAX_BAUD
175 #define __MAX_BAUD B4000000
176 #endif
177 #ifndef CMSPAR
178 #define CMSPAR 010000000000 /* mark or space (stick) parity */
179 #endif
180 #ifndef FIONREAD
181 #define FIONREAD 0x541B
182 #endif
183 //
184 // Function Prototypes
185 //
186 EFI_STATUS
187 EFIAPI
188 InitializeUnixSerialIo (
189 IN EFI_HANDLE ImageHandle,
190 IN EFI_SYSTEM_TABLE *SystemTable
191 )
192 /*++
193
194 Routine Description:
195
196 TODO: Add function description
197
198 Arguments:
199
200 ImageHandle - TODO: add argument description
201 SystemTable - TODO: add argument description
202
203 Returns:
204
205 TODO: add return values
206
207 --*/
208 ;
209
210 EFI_STATUS
211 EFIAPI
212 UnixSerialIoDriverBindingSupported (
213 IN EFI_DRIVER_BINDING_PROTOCOL *This,
214 IN EFI_HANDLE Handle,
215 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
216 )
217 /*++
218
219 Routine Description:
220
221 TODO: Add function description
222
223 Arguments:
224
225 This - TODO: add argument description
226 Handle - TODO: add argument description
227 RemainingDevicePath - TODO: add argument description
228
229 Returns:
230
231 TODO: add return values
232
233 --*/
234 ;
235
236 EFI_STATUS
237 EFIAPI
238 UnixSerialIoDriverBindingStart (
239 IN EFI_DRIVER_BINDING_PROTOCOL *This,
240 IN EFI_HANDLE Handle,
241 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
242 )
243 /*++
244
245 Routine Description:
246
247 TODO: Add function description
248
249 Arguments:
250
251 This - TODO: add argument description
252 Handle - TODO: add argument description
253 RemainingDevicePath - TODO: add argument description
254
255 Returns:
256
257 TODO: add return values
258
259 --*/
260 ;
261
262 EFI_STATUS
263 EFIAPI
264 UnixSerialIoDriverBindingStop (
265 IN EFI_DRIVER_BINDING_PROTOCOL *This,
266 IN EFI_HANDLE Handle,
267 IN UINTN NumberOfChildren,
268 IN EFI_HANDLE *ChildHandleBuffer
269 )
270 /*++
271
272 Routine Description:
273
274 TODO: Add function description
275
276 Arguments:
277
278 This - TODO: add argument description
279 Handle - TODO: add argument description
280 NumberOfChildren - TODO: add argument description
281 ChildHandleBuffer - TODO: add argument description
282
283 Returns:
284
285 TODO: add return values
286
287 --*/
288 ;
289
290 EFI_STATUS
291 EFIAPI
292 UnixSerialIoReset (
293 IN EFI_SERIAL_IO_PROTOCOL *This
294 )
295 /*++
296
297 Routine Description:
298
299 TODO: Add function description
300
301 Arguments:
302
303 This - TODO: add argument description
304
305 Returns:
306
307 TODO: add return values
308
309 --*/
310 ;
311
312 EFI_STATUS
313 EFIAPI
314 UnixSerialIoSetAttributes (
315 IN EFI_SERIAL_IO_PROTOCOL *This,
316 IN UINT64 BaudRate,
317 IN UINT32 ReceiveFifoDepth,
318 IN UINT32 Timeout,
319 IN EFI_PARITY_TYPE Parity,
320 IN UINT8 DataBits,
321 IN EFI_STOP_BITS_TYPE StopBits
322 )
323 /*++
324
325 Routine Description:
326
327 TODO: Add function description
328
329 Arguments:
330
331 This - TODO: add argument description
332 BaudRate - TODO: add argument description
333 ReceiveFifoDepth - TODO: add argument description
334 Timeout - TODO: add argument description
335 Parity - TODO: add argument description
336 DataBits - TODO: add argument description
337 StopBits - TODO: add argument description
338
339 Returns:
340
341 TODO: add return values
342
343 --*/
344 ;
345
346 EFI_STATUS
347 EFIAPI
348 UnixSerialIoSetControl (
349 IN EFI_SERIAL_IO_PROTOCOL *This,
350 IN UINT32 Control
351 )
352 /*++
353
354 Routine Description:
355
356 TODO: Add function description
357
358 Arguments:
359
360 This - TODO: add argument description
361 Control - TODO: add argument description
362
363 Returns:
364
365 TODO: add return values
366
367 --*/
368 ;
369
370 EFI_STATUS
371 EFIAPI
372 UnixSerialIoGetControl (
373 IN EFI_SERIAL_IO_PROTOCOL *This,
374 OUT UINT32 *Control
375 )
376 /*++
377
378 Routine Description:
379
380 TODO: Add function description
381
382 Arguments:
383
384 This - TODO: add argument description
385 Control - TODO: add argument description
386
387 Returns:
388
389 TODO: add return values
390
391 --*/
392 ;
393
394 EFI_STATUS
395 EFIAPI
396 UnixSerialIoWrite (
397 IN EFI_SERIAL_IO_PROTOCOL *This,
398 IN OUT UINTN *BufferSize,
399 IN VOID *Buffer
400 )
401 /*++
402
403 Routine Description:
404
405 TODO: Add function description
406
407 Arguments:
408
409 This - TODO: add argument description
410 BufferSize - TODO: add argument description
411 Buffer - TODO: add argument description
412
413 Returns:
414
415 TODO: add return values
416
417 --*/
418 ;
419
420 EFI_STATUS
421 EFIAPI
422 UnixSerialIoRead (
423 IN EFI_SERIAL_IO_PROTOCOL *This,
424 IN OUT UINTN *BufferSize,
425 OUT VOID *Buffer
426 )
427 /*++
428
429 Routine Description:
430
431 TODO: Add function description
432
433 Arguments:
434
435 This - TODO: add argument description
436 BufferSize - TODO: add argument description
437 Buffer - TODO: add argument description
438
439 Returns:
440
441 TODO: add return values
442
443 --*/
444 ;
445
446 BOOLEAN
447 IsaSerialFifoFull (
448 IN SERIAL_DEV_FIFO *Fifo
449 )
450 /*++
451
452 Routine Description:
453
454 TODO: Add function description
455
456 Arguments:
457
458 Fifo - TODO: add argument description
459
460 Returns:
461
462 TODO: add return values
463
464 --*/
465 ;
466
467 BOOLEAN
468 IsaSerialFifoEmpty (
469 IN SERIAL_DEV_FIFO *Fifo
470 )
471 /*++
472
473 Routine Description:
474
475 TODO: Add function description
476
477 Arguments:
478
479 Fifo - TODO: add argument description
480
481 Returns:
482
483 TODO: add return values
484
485 --*/
486 ;
487
488 EFI_STATUS
489 IsaSerialFifoAdd (
490 IN SERIAL_DEV_FIFO *Fifo,
491 IN UINT8 Data
492 )
493 /*++
494
495 Routine Description:
496
497 TODO: Add function description
498
499 Arguments:
500
501 Fifo - TODO: add argument description
502 Data - TODO: add argument description
503
504 Returns:
505
506 TODO: add return values
507
508 --*/
509 ;
510
511 EFI_STATUS
512 IsaSerialFifoRemove (
513 IN SERIAL_DEV_FIFO *Fifo,
514 OUT UINT8 *Data
515 )
516 /*++
517
518 Routine Description:
519
520 TODO: Add function description
521
522 Arguments:
523
524 Fifo - TODO: add argument description
525 Data - TODO: add argument description
526
527 Returns:
528
529 TODO: add return values
530
531 --*/
532 ;
533
534 EFI_STATUS
535 IsaSerialReceiveTransmit (
536 UNIX_SERIAL_IO_PRIVATE_DATA *Private
537 )
538 /*++
539
540 Routine Description:
541
542 TODO: Add function description
543
544 Arguments:
545
546 Private - TODO: add argument description
547
548 Returns:
549
550 TODO: add return values
551
552 --*/
553 ;
554
555 #endif