Add UnixSerialIo device driver
[mirror_edk2.git] / EdkNt32Pkg / Dxe / WinNtThunk / Bus / SerialIo / UnixSerialIo.h
CommitLineData
d84d8834 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
135//\r
136// Function Prototypes\r
137//\r
138EFI_STATUS\r
139EFIAPI\r
140InitializeUnixSerialIo (\r
141 IN EFI_HANDLE ImageHandle,\r
142 IN EFI_SYSTEM_TABLE *SystemTable\r
143 )\r
144/*++\r
145\r
146Routine Description:\r
147\r
148 TODO: Add function description\r
149\r
150Arguments:\r
151\r
152 ImageHandle - TODO: add argument description\r
153 SystemTable - TODO: add argument description\r
154\r
155Returns:\r
156\r
157 TODO: add return values\r
158\r
159--*/\r
160;\r
161\r
162EFI_STATUS\r
163EFIAPI\r
164UnixSerialIoDriverBindingSupported (\r
165 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
166 IN EFI_HANDLE Handle,\r
167 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
168 )\r
169/*++\r
170\r
171Routine Description:\r
172\r
173 TODO: Add function description\r
174\r
175Arguments:\r
176\r
177 This - TODO: add argument description\r
178 Handle - TODO: add argument description\r
179 RemainingDevicePath - TODO: add argument description\r
180\r
181Returns:\r
182\r
183 TODO: add return values\r
184\r
185--*/\r
186;\r
187\r
188EFI_STATUS\r
189EFIAPI\r
190UnixSerialIoDriverBindingStart (\r
191 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
192 IN EFI_HANDLE Handle,\r
193 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
194 )\r
195/*++\r
196\r
197Routine Description:\r
198\r
199 TODO: Add function description\r
200\r
201Arguments:\r
202\r
203 This - TODO: add argument description\r
204 Handle - TODO: add argument description\r
205 RemainingDevicePath - TODO: add argument description\r
206\r
207Returns:\r
208\r
209 TODO: add return values\r
210\r
211--*/\r
212;\r
213\r
214EFI_STATUS\r
215EFIAPI\r
216UnixSerialIoDriverBindingStop (\r
217 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
218 IN EFI_HANDLE Handle,\r
219 IN UINTN NumberOfChildren,\r
220 IN EFI_HANDLE *ChildHandleBuffer\r
221 )\r
222/*++\r
223\r
224Routine Description:\r
225\r
226 TODO: Add function description\r
227\r
228Arguments:\r
229\r
230 This - TODO: add argument description\r
231 Handle - TODO: add argument description\r
232 NumberOfChildren - TODO: add argument description\r
233 ChildHandleBuffer - TODO: add argument description\r
234\r
235Returns:\r
236\r
237 TODO: add return values\r
238\r
239--*/\r
240;\r
241\r
242EFI_STATUS\r
243EFIAPI\r
244UnixSerialIoReset (\r
245 IN EFI_SERIAL_IO_PROTOCOL *This\r
246 )\r
247/*++\r
248\r
249Routine Description:\r
250\r
251 TODO: Add function description\r
252\r
253Arguments:\r
254\r
255 This - TODO: add argument description\r
256\r
257Returns:\r
258\r
259 TODO: add return values\r
260\r
261--*/\r
262;\r
263\r
264EFI_STATUS\r
265EFIAPI\r
266UnixSerialIoSetAttributes (\r
267 IN EFI_SERIAL_IO_PROTOCOL *This,\r
268 IN UINT64 BaudRate,\r
269 IN UINT32 ReceiveFifoDepth,\r
270 IN UINT32 Timeout,\r
271 IN EFI_PARITY_TYPE Parity,\r
272 IN UINT8 DataBits,\r
273 IN EFI_STOP_BITS_TYPE StopBits\r
274 )\r
275/*++\r
276\r
277Routine Description:\r
278\r
279 TODO: Add function description\r
280\r
281Arguments:\r
282\r
283 This - TODO: add argument description\r
284 BaudRate - TODO: add argument description\r
285 ReceiveFifoDepth - TODO: add argument description\r
286 Timeout - TODO: add argument description\r
287 Parity - TODO: add argument description\r
288 DataBits - TODO: add argument description\r
289 StopBits - TODO: add argument description\r
290\r
291Returns:\r
292\r
293 TODO: add return values\r
294\r
295--*/\r
296;\r
297\r
298EFI_STATUS\r
299EFIAPI\r
300UnixSerialIoSetControl (\r
301 IN EFI_SERIAL_IO_PROTOCOL *This,\r
302 IN UINT32 Control\r
303 )\r
304/*++\r
305\r
306Routine Description:\r
307\r
308 TODO: Add function description\r
309\r
310Arguments:\r
311\r
312 This - TODO: add argument description\r
313 Control - TODO: add argument description\r
314\r
315Returns:\r
316\r
317 TODO: add return values\r
318\r
319--*/\r
320;\r
321\r
322EFI_STATUS\r
323EFIAPI\r
324UnixSerialIoGetControl (\r
325 IN EFI_SERIAL_IO_PROTOCOL *This,\r
326 OUT UINT32 *Control\r
327 )\r
328/*++\r
329\r
330Routine Description:\r
331\r
332 TODO: Add function description\r
333\r
334Arguments:\r
335\r
336 This - TODO: add argument description\r
337 Control - 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
348UnixSerialIoWrite (\r
349 IN EFI_SERIAL_IO_PROTOCOL *This,\r
350 IN OUT UINTN *BufferSize,\r
351 IN VOID *Buffer\r
352 )\r
353/*++\r
354\r
355Routine Description:\r
356\r
357 TODO: Add function description\r
358\r
359Arguments:\r
360\r
361 This - TODO: add argument description\r
362 BufferSize - TODO: add argument description\r
363 Buffer - TODO: add argument description\r
364\r
365Returns:\r
366\r
367 TODO: add return values\r
368\r
369--*/\r
370;\r
371\r
372EFI_STATUS\r
373EFIAPI\r
374UnixSerialIoRead (\r
375 IN EFI_SERIAL_IO_PROTOCOL *This,\r
376 IN OUT UINTN *BufferSize,\r
377 OUT VOID *Buffer\r
378 )\r
379/*++\r
380\r
381Routine Description:\r
382\r
383 TODO: Add function description\r
384\r
385Arguments:\r
386\r
387 This - TODO: add argument description\r
388 BufferSize - TODO: add argument description\r
389 Buffer - TODO: add argument description\r
390\r
391Returns:\r
392\r
393 TODO: add return values\r
394\r
395--*/\r
396;\r
397\r
398BOOLEAN\r
399IsaSerialFifoFull (\r
400 IN SERIAL_DEV_FIFO *Fifo\r
401 )\r
402/*++\r
403\r
404Routine Description:\r
405\r
406 TODO: Add function description\r
407\r
408Arguments:\r
409\r
410 Fifo - TODO: add argument description\r
411\r
412Returns:\r
413\r
414 TODO: add return values\r
415\r
416--*/\r
417;\r
418\r
419BOOLEAN\r
420IsaSerialFifoEmpty (\r
421 IN SERIAL_DEV_FIFO *Fifo\r
422 )\r
423/*++\r
424\r
425Routine Description:\r
426\r
427 TODO: Add function description\r
428\r
429Arguments:\r
430\r
431 Fifo - TODO: add argument description\r
432\r
433Returns:\r
434\r
435 TODO: add return values\r
436\r
437--*/\r
438;\r
439\r
440EFI_STATUS\r
441IsaSerialFifoAdd (\r
442 IN SERIAL_DEV_FIFO *Fifo,\r
443 IN UINT8 Data\r
444 )\r
445/*++\r
446\r
447Routine Description:\r
448\r
449 TODO: Add function description\r
450\r
451Arguments:\r
452\r
453 Fifo - TODO: add argument description\r
454 Data - TODO: add argument description\r
455\r
456Returns:\r
457\r
458 TODO: add return values\r
459\r
460--*/\r
461;\r
462\r
463EFI_STATUS\r
464IsaSerialFifoRemove (\r
465 IN SERIAL_DEV_FIFO *Fifo,\r
466 OUT UINT8 *Data\r
467 )\r
468/*++\r
469\r
470Routine Description:\r
471\r
472 TODO: Add function description\r
473\r
474Arguments:\r
475\r
476 Fifo - TODO: add argument description\r
477 Data - TODO: add argument description\r
478\r
479Returns:\r
480\r
481 TODO: add return values\r
482\r
483--*/\r
484;\r
485\r
486EFI_STATUS\r
487IsaSerialReceiveTransmit (\r
488 UNIX_SERIAL_IO_PRIVATE_DATA *Private\r
489 )\r
490/*++\r
491\r
492Routine Description:\r
493\r
494 TODO: Add function description\r
495\r
496Arguments:\r
497\r
498 Private - TODO: add argument description\r
499\r
500Returns:\r
501\r
502 TODO: add return values\r
503\r
504--*/\r
505;\r
506\r
507#endif\r