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