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