]> git.proxmox.com Git - mirror_edk2.git/blob - UnixPkg/UnixSerialIoDxe/UnixSerialIo.h
UnixSerialIo driver was changed to produce the flow control device path node when...
[mirror_edk2.git] / UnixPkg / UnixSerialIoDxe / UnixSerialIo.h
1 /*++
2
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
9
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.
12
13 Module Name:
14
15 UnixSerialIo.h
16
17 Abstract:
18
19
20 --*/
21
22 #ifndef _UNIXPKG_SERIAL_IO_
23 #define _UNIXPKG_SERIAL_IO_
24 #include <sys/types.h>
25 #include <sys/stat.h>
26 #include <stdio.h>
27
28 #ifdef __APPLE__
29 #else
30 #include <stdlib.h>
31 #include <termio.h>
32 #endif
33
34 #include <fcntl.h>
35 #include <errno.h>
36
37 #include "Uefi.h"
38 #include <Protocol/SerialIo.h>
39 #include <Protocol/DevicePath.h>
40
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>
49 #include "UnixDxe.h"
50
51 extern EFI_DRIVER_BINDING_PROTOCOL gUnixSerialIoDriverBinding;
52 extern EFI_COMPONENT_NAME_PROTOCOL gUnixSerialIoComponentName;
53
54 #define SERIAL_MAX_BUFFER_SIZE 256
55 #define TIMEOUT_STALL_INTERVAL 10
56
57 typedef struct {
58 UINT32 First;
59 UINT32 Last;
60 UINT32 Surplus;
61 UINT8 Data[SERIAL_MAX_BUFFER_SIZE];
62 } SERIAL_DEV_FIFO;
63
64 #define UNIX_SERIAL_IO_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('U', 'N', 's', 'i')
65 typedef struct {
66 UINT64 Signature;
67
68 //
69 // Protocol data for the new handle we are going to add
70 //
71 EFI_HANDLE Handle;
72 EFI_SERIAL_IO_PROTOCOL SerialIo;
73 EFI_SERIAL_IO_MODE SerialIoMode;
74 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
75
76 //
77 // Private Data
78 //
79 EFI_HANDLE ControllerHandle;
80 EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;
81 UART_DEVICE_PATH UartDevicePath;
82 EFI_UNIX_THUNK_PROTOCOL *UnixThunk;
83
84 EFI_UNICODE_STRING_TABLE *ControllerNameTable;
85
86 //
87 // Private NT type Data;
88 //
89 UINTN UnixHandle;
90 struct termios UnixTermios;
91
92 BOOLEAN SoftwareLoopbackEnable;
93 BOOLEAN HardwareFlowControl;
94 BOOLEAN HardwareLoopbackEnable;
95
96 SERIAL_DEV_FIFO Fifo;
97
98 } UNIX_SERIAL_IO_PRIVATE_DATA;
99
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)
102
103 //
104 // Global Protocol Variables
105 //
106 extern EFI_DRIVER_BINDING_PROTOCOL gUnixSerialIoDriverBinding;
107 extern EFI_COMPONENT_NAME_PROTOCOL gUnixSerialIoComponentName;
108
109 //
110 // Macros to convert EFI serial types to NT serial types.
111 //
112
113 //
114 // one second
115 //
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
122
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)
133
134 #define ConvertBaud2Nt(x) (DWORD) x
135 #define ConvertData2Nt(x) (BYTE) x
136
137 #define ConvertParity2Nt(x) \
138 (BYTE) ( \
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 \
145 )
146
147 #define ConvertStop2Nt(x) \
148 (BYTE) ( \
149 x == DefaultParity ? ONESTOPBIT : \
150 x == OneFiveStopBits ? ONE5STOPBITS : \
151 x == TwoStopBits ? TWOSTOPBITS : 0 \
152 )
153
154 #define ConvertTime2Nt(x) ((x) / 1000)
155
156 //
157 // 115400 baud with rounding errors
158 //
159 #define SERIAL_PORT_MAX_BAUD_RATE 115400
160
161 //
162 // Fix the differences issue of linux header files termios.h
163 //
164 #ifndef B460800
165 #define B460800 0010004
166 #endif
167 #ifndef B500000
168 #define B500000 0010005
169 #endif
170 #ifndef B576000
171 #define B576000 0010006
172 #endif
173 #ifndef B921600
174 #define B921600 0010007
175 #endif
176 #ifndef B1000000
177 #define B1000000 0010010
178 #endif
179 #ifndef B1152000
180 #define B1152000 0010011
181 #endif
182 #ifndef B1500000
183 #define B1500000 0010012
184 #endif
185 #ifndef B2000000
186 #define B2000000 0010013
187 #endif
188 #ifndef B2500000
189 #define B2500000 0010014
190 #endif
191 #ifndef B3000000
192 #define B3000000 0010015
193 #endif
194 #ifndef B3500000
195 #define B3500000 0010016
196 #endif
197 #ifndef B4000000
198 #define B4000000 0010017
199 #endif
200 #ifndef __MAX_BAUD
201 #define __MAX_BAUD B4000000
202 #endif
203 #ifndef CMSPAR
204 #define CMSPAR 010000000000 /* mark or space (stick) parity */
205 #endif
206 #ifndef FIONREAD
207 #define FIONREAD 0x541B
208 #endif
209 //
210 // Function Prototypes
211 //
212 EFI_STATUS
213 EFIAPI
214 InitializeUnixSerialIo (
215 IN EFI_HANDLE ImageHandle,
216 IN EFI_SYSTEM_TABLE *SystemTable
217 )
218 /*++
219
220 Routine Description:
221
222 TODO: Add function description
223
224 Arguments:
225
226 ImageHandle - TODO: add argument description
227 SystemTable - TODO: add argument description
228
229 Returns:
230
231 TODO: add return values
232
233 --*/
234 ;
235
236 EFI_STATUS
237 EFIAPI
238 UnixSerialIoDriverBindingSupported (
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 UnixSerialIoDriverBindingStart (
265 IN EFI_DRIVER_BINDING_PROTOCOL *This,
266 IN EFI_HANDLE Handle,
267 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
268 )
269 /*++
270
271 Routine Description:
272
273 TODO: Add function description
274
275 Arguments:
276
277 This - TODO: add argument description
278 Handle - TODO: add argument description
279 RemainingDevicePath - TODO: add argument description
280
281 Returns:
282
283 TODO: add return values
284
285 --*/
286 ;
287
288 EFI_STATUS
289 EFIAPI
290 UnixSerialIoDriverBindingStop (
291 IN EFI_DRIVER_BINDING_PROTOCOL *This,
292 IN EFI_HANDLE Handle,
293 IN UINTN NumberOfChildren,
294 IN EFI_HANDLE *ChildHandleBuffer
295 )
296 /*++
297
298 Routine Description:
299
300 TODO: Add function description
301
302 Arguments:
303
304 This - TODO: add argument description
305 Handle - TODO: add argument description
306 NumberOfChildren - TODO: add argument description
307 ChildHandleBuffer - TODO: add argument description
308
309 Returns:
310
311 TODO: add return values
312
313 --*/
314 ;
315
316 EFI_STATUS
317 EFIAPI
318 UnixSerialIoReset (
319 IN EFI_SERIAL_IO_PROTOCOL *This
320 )
321 /*++
322
323 Routine Description:
324
325 TODO: Add function description
326
327 Arguments:
328
329 This - TODO: add argument description
330
331 Returns:
332
333 TODO: add return values
334
335 --*/
336 ;
337
338 EFI_STATUS
339 EFIAPI
340 UnixSerialIoSetAttributes (
341 IN EFI_SERIAL_IO_PROTOCOL *This,
342 IN UINT64 BaudRate,
343 IN UINT32 ReceiveFifoDepth,
344 IN UINT32 Timeout,
345 IN EFI_PARITY_TYPE Parity,
346 IN UINT8 DataBits,
347 IN EFI_STOP_BITS_TYPE StopBits
348 )
349 /*++
350
351 Routine Description:
352
353 TODO: Add function description
354
355 Arguments:
356
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
364
365 Returns:
366
367 TODO: add return values
368
369 --*/
370 ;
371
372 EFI_STATUS
373 EFIAPI
374 UnixSerialIoSetControl (
375 IN EFI_SERIAL_IO_PROTOCOL *This,
376 IN UINT32 Control
377 )
378 /*++
379
380 Routine Description:
381
382 TODO: Add function description
383
384 Arguments:
385
386 This - TODO: add argument description
387 Control - TODO: add argument description
388
389 Returns:
390
391 TODO: add return values
392
393 --*/
394 ;
395
396 EFI_STATUS
397 EFIAPI
398 UnixSerialIoGetControl (
399 IN EFI_SERIAL_IO_PROTOCOL *This,
400 OUT UINT32 *Control
401 )
402 /*++
403
404 Routine Description:
405
406 TODO: Add function description
407
408 Arguments:
409
410 This - TODO: add argument description
411 Control - TODO: add argument description
412
413 Returns:
414
415 TODO: add return values
416
417 --*/
418 ;
419
420 EFI_STATUS
421 EFIAPI
422 UnixSerialIoWrite (
423 IN EFI_SERIAL_IO_PROTOCOL *This,
424 IN OUT UINTN *BufferSize,
425 IN 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 EFI_STATUS
447 EFIAPI
448 UnixSerialIoRead (
449 IN EFI_SERIAL_IO_PROTOCOL *This,
450 IN OUT UINTN *BufferSize,
451 OUT VOID *Buffer
452 )
453 /*++
454
455 Routine Description:
456
457 TODO: Add function description
458
459 Arguments:
460
461 This - TODO: add argument description
462 BufferSize - TODO: add argument description
463 Buffer - TODO: add argument description
464
465 Returns:
466
467 TODO: add return values
468
469 --*/
470 ;
471
472 BOOLEAN
473 IsaSerialFifoFull (
474 IN SERIAL_DEV_FIFO *Fifo
475 )
476 /*++
477
478 Routine Description:
479
480 TODO: Add function description
481
482 Arguments:
483
484 Fifo - TODO: add argument description
485
486 Returns:
487
488 TODO: add return values
489
490 --*/
491 ;
492
493 BOOLEAN
494 IsaSerialFifoEmpty (
495 IN SERIAL_DEV_FIFO *Fifo
496 )
497 /*++
498
499 Routine Description:
500
501 TODO: Add function description
502
503 Arguments:
504
505 Fifo - TODO: add argument description
506
507 Returns:
508
509 TODO: add return values
510
511 --*/
512 ;
513
514 EFI_STATUS
515 IsaSerialFifoAdd (
516 IN SERIAL_DEV_FIFO *Fifo,
517 IN UINT8 Data
518 )
519 /*++
520
521 Routine Description:
522
523 TODO: Add function description
524
525 Arguments:
526
527 Fifo - TODO: add argument description
528 Data - TODO: add argument description
529
530 Returns:
531
532 TODO: add return values
533
534 --*/
535 ;
536
537 EFI_STATUS
538 IsaSerialFifoRemove (
539 IN SERIAL_DEV_FIFO *Fifo,
540 OUT UINT8 *Data
541 )
542 /*++
543
544 Routine Description:
545
546 TODO: Add function description
547
548 Arguments:
549
550 Fifo - TODO: add argument description
551 Data - TODO: add argument description
552
553 Returns:
554
555 TODO: add return values
556
557 --*/
558 ;
559
560 EFI_STATUS
561 IsaSerialReceiveTransmit (
562 UNIX_SERIAL_IO_PRIVATE_DATA *Private
563 )
564 /*++
565
566 Routine Description:
567
568 TODO: Add function description
569
570 Arguments:
571
572 Private - TODO: add argument description
573
574 Returns:
575
576 TODO: add return values
577
578 --*/
579 ;
580
581 #endif