]> git.proxmox.com Git - mirror_edk2.git/blob - UnixPkg/UnixSerialIoDxe/UnixSerialIo.h
3a6c11ac3799313bf321a86790a63a7a8f920e7a
[mirror_edk2.git] / UnixPkg / UnixSerialIoDxe / UnixSerialIo.h
1 /*++
2
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
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 #include "Uefi.h"
32 #include <Protocol/SerialIo.h>
33 #include <Protocol/DevicePath.h>
34
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"
44
45 extern EFI_DRIVER_BINDING_PROTOCOL gUnixSerialIoDriverBinding;
46 extern EFI_COMPONENT_NAME_PROTOCOL gUnixSerialIoComponentName;
47
48 #define SERIAL_MAX_BUFFER_SIZE 256
49 #define TIMEOUT_STALL_INTERVAL 10
50
51 typedef struct {
52 UINT32 First;
53 UINT32 Last;
54 UINT32 Surplus;
55 UINT8 Data[SERIAL_MAX_BUFFER_SIZE];
56 } SERIAL_DEV_FIFO;
57
58 #define UNIX_SERIAL_IO_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('U', 'N', 's', 'i')
59 typedef struct {
60 UINT64 Signature;
61
62 //
63 // Protocol data for the new handle we are going to add
64 //
65 EFI_HANDLE Handle;
66 EFI_SERIAL_IO_PROTOCOL SerialIo;
67 EFI_SERIAL_IO_MODE SerialIoMode;
68 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
69
70 //
71 // Private Data
72 //
73 EFI_HANDLE ControllerHandle;
74 EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;
75 UART_DEVICE_PATH UartDevicePath;
76 EFI_UNIX_THUNK_PROTOCOL *UnixThunk;
77
78 EFI_UNICODE_STRING_TABLE *ControllerNameTable;
79
80 //
81 // Private NT type Data;
82 //
83 UINTN UnixHandle;
84 struct termios UnixTermios;
85
86 BOOLEAN SoftwareLoopbackEnable;
87 BOOLEAN HardwareFlowControl;
88 BOOLEAN HardwareLoopbackEnable;
89
90 SERIAL_DEV_FIFO Fifo;
91
92 } UNIX_SERIAL_IO_PRIVATE_DATA;
93
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)
96
97 //
98 // Global Protocol Variables
99 //
100 extern EFI_DRIVER_BINDING_PROTOCOL gUnixSerialIoDriverBinding;
101 extern EFI_COMPONENT_NAME_PROTOCOL gUnixSerialIoComponentName;
102
103 //
104 // Macros to convert EFI serial types to NT serial types.
105 //
106
107 //
108 // one second
109 //
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
116
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)
124
125 #define ConvertBaud2Nt(x) (DWORD) x
126 #define ConvertData2Nt(x) (BYTE) x
127
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 \
136 )
137
138 #define ConvertStop2Nt(x) \
139 (BYTE) ( \
140 x == DefaultParity ? ONESTOPBIT : \
141 x == OneFiveStopBits ? ONE5STOPBITS : \
142 x == TwoStopBits ? TWOSTOPBITS : 0 \
143 )
144
145 #define ConvertTime2Nt(x) ((x) / 1000)
146
147 //
148 // 115400 baud with rounding errors
149 //
150 #define SERIAL_PORT_MAX_BAUD_RATE 115400
151
152 //
153 // Fix the differences issue of linux header files termios.h
154 //
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
200 //
201 // Function Prototypes
202 //
203 EFI_STATUS
204 EFIAPI
205 InitializeUnixSerialIo (
206 IN EFI_HANDLE ImageHandle,
207 IN EFI_SYSTEM_TABLE *SystemTable
208 )
209 /*++
210
211 Routine Description:
212
213 TODO: Add function description
214
215 Arguments:
216
217 ImageHandle - TODO: add argument description
218 SystemTable - TODO: add argument description
219
220 Returns:
221
222 TODO: add return values
223
224 --*/
225 ;
226
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
233 )
234 /*++
235
236 Routine Description:
237
238 TODO: Add function description
239
240 Arguments:
241
242 This - TODO: add argument description
243 Handle - TODO: add argument description
244 RemainingDevicePath - TODO: add argument description
245
246 Returns:
247
248 TODO: add return values
249
250 --*/
251 ;
252
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
259 )
260 /*++
261
262 Routine Description:
263
264 TODO: Add function description
265
266 Arguments:
267
268 This - TODO: add argument description
269 Handle - TODO: add argument description
270 RemainingDevicePath - TODO: add argument description
271
272 Returns:
273
274 TODO: add return values
275
276 --*/
277 ;
278
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
286 )
287 /*++
288
289 Routine Description:
290
291 TODO: Add function description
292
293 Arguments:
294
295 This - TODO: add argument description
296 Handle - TODO: add argument description
297 NumberOfChildren - TODO: add argument description
298 ChildHandleBuffer - TODO: add argument description
299
300 Returns:
301
302 TODO: add return values
303
304 --*/
305 ;
306
307 EFI_STATUS
308 EFIAPI
309 UnixSerialIoReset (
310 IN EFI_SERIAL_IO_PROTOCOL *This
311 )
312 /*++
313
314 Routine Description:
315
316 TODO: Add function description
317
318 Arguments:
319
320 This - TODO: add argument description
321
322 Returns:
323
324 TODO: add return values
325
326 --*/
327 ;
328
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
339 )
340 /*++
341
342 Routine Description:
343
344 TODO: Add function description
345
346 Arguments:
347
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
355
356 Returns:
357
358 TODO: add return values
359
360 --*/
361 ;
362
363 EFI_STATUS
364 EFIAPI
365 UnixSerialIoSetControl (
366 IN EFI_SERIAL_IO_PROTOCOL *This,
367 IN UINT32 Control
368 )
369 /*++
370
371 Routine Description:
372
373 TODO: Add function description
374
375 Arguments:
376
377 This - TODO: add argument description
378 Control - TODO: add argument description
379
380 Returns:
381
382 TODO: add return values
383
384 --*/
385 ;
386
387 EFI_STATUS
388 EFIAPI
389 UnixSerialIoGetControl (
390 IN EFI_SERIAL_IO_PROTOCOL *This,
391 OUT UINT32 *Control
392 )
393 /*++
394
395 Routine Description:
396
397 TODO: Add function description
398
399 Arguments:
400
401 This - TODO: add argument description
402 Control - TODO: add argument description
403
404 Returns:
405
406 TODO: add return values
407
408 --*/
409 ;
410
411 EFI_STATUS
412 EFIAPI
413 UnixSerialIoWrite (
414 IN EFI_SERIAL_IO_PROTOCOL *This,
415 IN OUT UINTN *BufferSize,
416 IN VOID *Buffer
417 )
418 /*++
419
420 Routine Description:
421
422 TODO: Add function description
423
424 Arguments:
425
426 This - TODO: add argument description
427 BufferSize - TODO: add argument description
428 Buffer - TODO: add argument description
429
430 Returns:
431
432 TODO: add return values
433
434 --*/
435 ;
436
437 EFI_STATUS
438 EFIAPI
439 UnixSerialIoRead (
440 IN EFI_SERIAL_IO_PROTOCOL *This,
441 IN OUT UINTN *BufferSize,
442 OUT VOID *Buffer
443 )
444 /*++
445
446 Routine Description:
447
448 TODO: Add function description
449
450 Arguments:
451
452 This - TODO: add argument description
453 BufferSize - TODO: add argument description
454 Buffer - TODO: add argument description
455
456 Returns:
457
458 TODO: add return values
459
460 --*/
461 ;
462
463 BOOLEAN
464 IsaSerialFifoFull (
465 IN SERIAL_DEV_FIFO *Fifo
466 )
467 /*++
468
469 Routine Description:
470
471 TODO: Add function description
472
473 Arguments:
474
475 Fifo - TODO: add argument description
476
477 Returns:
478
479 TODO: add return values
480
481 --*/
482 ;
483
484 BOOLEAN
485 IsaSerialFifoEmpty (
486 IN SERIAL_DEV_FIFO *Fifo
487 )
488 /*++
489
490 Routine Description:
491
492 TODO: Add function description
493
494 Arguments:
495
496 Fifo - TODO: add argument description
497
498 Returns:
499
500 TODO: add return values
501
502 --*/
503 ;
504
505 EFI_STATUS
506 IsaSerialFifoAdd (
507 IN SERIAL_DEV_FIFO *Fifo,
508 IN UINT8 Data
509 )
510 /*++
511
512 Routine Description:
513
514 TODO: Add function description
515
516 Arguments:
517
518 Fifo - TODO: add argument description
519 Data - TODO: add argument description
520
521 Returns:
522
523 TODO: add return values
524
525 --*/
526 ;
527
528 EFI_STATUS
529 IsaSerialFifoRemove (
530 IN SERIAL_DEV_FIFO *Fifo,
531 OUT UINT8 *Data
532 )
533 /*++
534
535 Routine Description:
536
537 TODO: Add function description
538
539 Arguments:
540
541 Fifo - TODO: add argument description
542 Data - TODO: add argument description
543
544 Returns:
545
546 TODO: add return values
547
548 --*/
549 ;
550
551 EFI_STATUS
552 IsaSerialReceiveTransmit (
553 UNIX_SERIAL_IO_PRIVATE_DATA *Private
554 )
555 /*++
556
557 Routine Description:
558
559 TODO: Add function description
560
561 Arguments:
562
563 Private - TODO: add argument description
564
565 Returns:
566
567 TODO: add return values
568
569 --*/
570 ;
571
572 #endif