]> git.proxmox.com Git - mirror_edk2.git/blob - UnixPkg/UnixSerialIoDxe/UnixSerialIo.h
Integrate patch from Andrew Fish to make it run on OS X.
[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_INPUT_BUFFER_EMPTY)
130
131 #define ConvertBaud2Nt(x) (DWORD) x
132 #define ConvertData2Nt(x) (BYTE) x
133
134 #define ConvertParity2Nt(x) \
135 (BYTE) ( \
136 x == DefaultParity ? NOPARITY : \
137 x == NoParity ? NOPARITY : \
138 x == EvenParity ? EVENPARITY : \
139 x == OddParity ? ODDPARITY : \
140 x == MarkParity ? MARKPARITY : \
141 x == SpaceParity ? SPACEPARITY : 0 \
142 )
143
144 #define ConvertStop2Nt(x) \
145 (BYTE) ( \
146 x == DefaultParity ? ONESTOPBIT : \
147 x == OneFiveStopBits ? ONE5STOPBITS : \
148 x == TwoStopBits ? TWOSTOPBITS : 0 \
149 )
150
151 #define ConvertTime2Nt(x) ((x) / 1000)
152
153 //
154 // 115400 baud with rounding errors
155 //
156 #define SERIAL_PORT_MAX_BAUD_RATE 115400
157
158 //
159 // Fix the differences issue of linux header files termios.h
160 //
161 #ifndef B460800
162 #define B460800 0010004
163 #endif
164 #ifndef B500000
165 #define B500000 0010005
166 #endif
167 #ifndef B576000
168 #define B576000 0010006
169 #endif
170 #ifndef B921600
171 #define B921600 0010007
172 #endif
173 #ifndef B1000000
174 #define B1000000 0010010
175 #endif
176 #ifndef B1152000
177 #define B1152000 0010011
178 #endif
179 #ifndef B1500000
180 #define B1500000 0010012
181 #endif
182 #ifndef B2000000
183 #define B2000000 0010013
184 #endif
185 #ifndef B2500000
186 #define B2500000 0010014
187 #endif
188 #ifndef B3000000
189 #define B3000000 0010015
190 #endif
191 #ifndef B3500000
192 #define B3500000 0010016
193 #endif
194 #ifndef B4000000
195 #define B4000000 0010017
196 #endif
197 #ifndef __MAX_BAUD
198 #define __MAX_BAUD B4000000
199 #endif
200 #ifndef CMSPAR
201 #define CMSPAR 010000000000 /* mark or space (stick) parity */
202 #endif
203 #ifndef FIONREAD
204 #define FIONREAD 0x541B
205 #endif
206 //
207 // Function Prototypes
208 //
209 EFI_STATUS
210 EFIAPI
211 InitializeUnixSerialIo (
212 IN EFI_HANDLE ImageHandle,
213 IN EFI_SYSTEM_TABLE *SystemTable
214 )
215 /*++
216
217 Routine Description:
218
219 TODO: Add function description
220
221 Arguments:
222
223 ImageHandle - TODO: add argument description
224 SystemTable - TODO: add argument description
225
226 Returns:
227
228 TODO: add return values
229
230 --*/
231 ;
232
233 EFI_STATUS
234 EFIAPI
235 UnixSerialIoDriverBindingSupported (
236 IN EFI_DRIVER_BINDING_PROTOCOL *This,
237 IN EFI_HANDLE Handle,
238 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
239 )
240 /*++
241
242 Routine Description:
243
244 TODO: Add function description
245
246 Arguments:
247
248 This - TODO: add argument description
249 Handle - TODO: add argument description
250 RemainingDevicePath - TODO: add argument description
251
252 Returns:
253
254 TODO: add return values
255
256 --*/
257 ;
258
259 EFI_STATUS
260 EFIAPI
261 UnixSerialIoDriverBindingStart (
262 IN EFI_DRIVER_BINDING_PROTOCOL *This,
263 IN EFI_HANDLE Handle,
264 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
265 )
266 /*++
267
268 Routine Description:
269
270 TODO: Add function description
271
272 Arguments:
273
274 This - TODO: add argument description
275 Handle - TODO: add argument description
276 RemainingDevicePath - TODO: add argument description
277
278 Returns:
279
280 TODO: add return values
281
282 --*/
283 ;
284
285 EFI_STATUS
286 EFIAPI
287 UnixSerialIoDriverBindingStop (
288 IN EFI_DRIVER_BINDING_PROTOCOL *This,
289 IN EFI_HANDLE Handle,
290 IN UINTN NumberOfChildren,
291 IN EFI_HANDLE *ChildHandleBuffer
292 )
293 /*++
294
295 Routine Description:
296
297 TODO: Add function description
298
299 Arguments:
300
301 This - TODO: add argument description
302 Handle - TODO: add argument description
303 NumberOfChildren - TODO: add argument description
304 ChildHandleBuffer - TODO: add argument description
305
306 Returns:
307
308 TODO: add return values
309
310 --*/
311 ;
312
313 EFI_STATUS
314 EFIAPI
315 UnixSerialIoReset (
316 IN EFI_SERIAL_IO_PROTOCOL *This
317 )
318 /*++
319
320 Routine Description:
321
322 TODO: Add function description
323
324 Arguments:
325
326 This - TODO: add argument description
327
328 Returns:
329
330 TODO: add return values
331
332 --*/
333 ;
334
335 EFI_STATUS
336 EFIAPI
337 UnixSerialIoSetAttributes (
338 IN EFI_SERIAL_IO_PROTOCOL *This,
339 IN UINT64 BaudRate,
340 IN UINT32 ReceiveFifoDepth,
341 IN UINT32 Timeout,
342 IN EFI_PARITY_TYPE Parity,
343 IN UINT8 DataBits,
344 IN EFI_STOP_BITS_TYPE StopBits
345 )
346 /*++
347
348 Routine Description:
349
350 TODO: Add function description
351
352 Arguments:
353
354 This - TODO: add argument description
355 BaudRate - TODO: add argument description
356 ReceiveFifoDepth - TODO: add argument description
357 Timeout - TODO: add argument description
358 Parity - TODO: add argument description
359 DataBits - TODO: add argument description
360 StopBits - TODO: add argument description
361
362 Returns:
363
364 TODO: add return values
365
366 --*/
367 ;
368
369 EFI_STATUS
370 EFIAPI
371 UnixSerialIoSetControl (
372 IN EFI_SERIAL_IO_PROTOCOL *This,
373 IN UINT32 Control
374 )
375 /*++
376
377 Routine Description:
378
379 TODO: Add function description
380
381 Arguments:
382
383 This - TODO: add argument description
384 Control - TODO: add argument description
385
386 Returns:
387
388 TODO: add return values
389
390 --*/
391 ;
392
393 EFI_STATUS
394 EFIAPI
395 UnixSerialIoGetControl (
396 IN EFI_SERIAL_IO_PROTOCOL *This,
397 OUT UINT32 *Control
398 )
399 /*++
400
401 Routine Description:
402
403 TODO: Add function description
404
405 Arguments:
406
407 This - TODO: add argument description
408 Control - TODO: add argument description
409
410 Returns:
411
412 TODO: add return values
413
414 --*/
415 ;
416
417 EFI_STATUS
418 EFIAPI
419 UnixSerialIoWrite (
420 IN EFI_SERIAL_IO_PROTOCOL *This,
421 IN OUT UINTN *BufferSize,
422 IN VOID *Buffer
423 )
424 /*++
425
426 Routine Description:
427
428 TODO: Add function description
429
430 Arguments:
431
432 This - TODO: add argument description
433 BufferSize - TODO: add argument description
434 Buffer - TODO: add argument description
435
436 Returns:
437
438 TODO: add return values
439
440 --*/
441 ;
442
443 EFI_STATUS
444 EFIAPI
445 UnixSerialIoRead (
446 IN EFI_SERIAL_IO_PROTOCOL *This,
447 IN OUT UINTN *BufferSize,
448 OUT VOID *Buffer
449 )
450 /*++
451
452 Routine Description:
453
454 TODO: Add function description
455
456 Arguments:
457
458 This - TODO: add argument description
459 BufferSize - TODO: add argument description
460 Buffer - TODO: add argument description
461
462 Returns:
463
464 TODO: add return values
465
466 --*/
467 ;
468
469 BOOLEAN
470 IsaSerialFifoFull (
471 IN SERIAL_DEV_FIFO *Fifo
472 )
473 /*++
474
475 Routine Description:
476
477 TODO: Add function description
478
479 Arguments:
480
481 Fifo - TODO: add argument description
482
483 Returns:
484
485 TODO: add return values
486
487 --*/
488 ;
489
490 BOOLEAN
491 IsaSerialFifoEmpty (
492 IN SERIAL_DEV_FIFO *Fifo
493 )
494 /*++
495
496 Routine Description:
497
498 TODO: Add function description
499
500 Arguments:
501
502 Fifo - TODO: add argument description
503
504 Returns:
505
506 TODO: add return values
507
508 --*/
509 ;
510
511 EFI_STATUS
512 IsaSerialFifoAdd (
513 IN SERIAL_DEV_FIFO *Fifo,
514 IN 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 IsaSerialFifoRemove (
536 IN SERIAL_DEV_FIFO *Fifo,
537 OUT UINT8 *Data
538 )
539 /*++
540
541 Routine Description:
542
543 TODO: Add function description
544
545 Arguments:
546
547 Fifo - TODO: add argument description
548 Data - TODO: add argument description
549
550 Returns:
551
552 TODO: add return values
553
554 --*/
555 ;
556
557 EFI_STATUS
558 IsaSerialReceiveTransmit (
559 UNIX_SERIAL_IO_PRIVATE_DATA *Private
560 )
561 /*++
562
563 Routine Description:
564
565 TODO: Add function description
566
567 Arguments:
568
569 Private - TODO: add argument description
570
571 Returns:
572
573 TODO: add return values
574
575 --*/
576 ;
577
578 #endif