Synchronize up to trunk's revision r57784.
[reactos.git] / ntoskrnl / inbv / inbvport.c
1 /*
2 * PROJECT: ReactOS Kernel
3 * LICENSE: BSD - See COPYING.ARM in the top level directory
4 * FILE: ntoskrnl/inbv/inbvport.c
5 * PURPOSE: Serial Port Boot Driver for Headless Terminal Support
6 * PROGRAMMERS: ReactOS Portable Systems Group
7 */
8
9 /* INCLUDES ******************************************************************/
10
11 #include <ntoskrnl.h>
12 #include <debug.h>
13
14 /* GLOBALS *******************************************************************/
15
16 CPPORT Port[4] =
17 {
18 {NULL, 0, TRUE},
19 {NULL, 0, TRUE},
20 {NULL, 0, TRUE},
21 {NULL, 0, TRUE}
22 };
23
24 /* FUNCTIONS *****************************************************************/
25
26 VOID
27 NTAPI
28 InbvPortEnableFifo(IN ULONG PortId,
29 IN BOOLEAN Enable)
30 {
31 /* Set FIFO as requested */
32 CpEnableFifo(Port[PortId].Address, Enable);
33 }
34
35 VOID
36 NTAPI
37 InbvPortPutByte(IN ULONG PortId,
38 IN BOOLEAN Output)
39 {
40 /* Send the byte */
41 CpPutByte(&Port[PortId], Output);
42 }
43
44 VOID
45 NTAPI
46 InbvPortTerminate(IN ULONG PortId)
47 {
48 /* The port is now available */
49 Port[PortId].Address = NULL;
50 }
51
52 BOOLEAN
53 NTAPI
54 InbvPortInitialize(IN ULONG BaudRate,
55 IN ULONG PortNumber,
56 IN PUCHAR PortAddress,
57 OUT PULONG PortId,
58 IN BOOLEAN IsMMIODevice)
59 {
60 /* Not yet supported */
61 ASSERT(IsMMIODevice == FALSE);
62
63 /* Set default baud rate */
64 if (BaudRate == 0) BaudRate = 19200;
65
66 /* Check if port or address given */
67 if (PortNumber)
68 {
69 /* Pick correct address for port */
70 if (!PortAddress)
71 {
72 switch (PortNumber)
73 {
74 case 1:
75 PortAddress = (PUCHAR)0x3F8;
76 break;
77
78 case 2:
79 PortAddress = (PUCHAR)0x2F8;
80 break;
81
82 case 3:
83 PortAddress = (PUCHAR)0x3E8;
84 break;
85
86 default:
87 PortNumber = 4;
88 PortAddress = (PUCHAR)0x2E8;
89 }
90 }
91 }
92 else
93 {
94 /* Pick correct port for address */
95 PortAddress = (PUCHAR)0x2F8;
96 if (CpDoesPortExist(PortAddress))
97 {
98 PortNumber = 2;
99 }
100 else
101 {
102 PortAddress = (PUCHAR)0x3F8;
103 if (!CpDoesPortExist(PortAddress)) return FALSE;
104 PortNumber = 1;
105 }
106 }
107
108 /* Initialize the port unless it's already up, and then return it */
109 if (Port[PortNumber - 1].Address) return FALSE;
110
111 CpInitialize(&Port[PortNumber - 1], PortAddress, BaudRate);
112 *PortId = PortNumber - 1;
113
114 return TRUE;
115 }
116
117 /* EOF */