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