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