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