- Update to r53061
[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(
29 IN ULONG PortId,
30 IN BOOLEAN Enable
31 )
32 {
33 /* Set FIFO as requested */
34 CpEnableFifo(Port[PortId].Address, Enable);
35 }
36
37 VOID
38 NTAPI
39 InbvPortPutByte(
40 IN ULONG PortId,
41 IN BOOLEAN Output
42 )
43 {
44 /* Send the byte */
45 CpPutByte(&Port[PortId], Output);
46 }
47
48 VOID
49 NTAPI
50 InbvPortTerminate(
51 IN ULONG PortId
52 )
53 {
54 /* The port is now available */
55 Port[PortId].Address = NULL;
56 }
57
58 BOOLEAN
59 NTAPI
60 InbvPortInitialize(
61 IN ULONG BaudRate,
62 IN ULONG PortNumber,
63 IN PUCHAR PortAddress,
64 OUT PULONG PortId,
65 IN BOOLEAN IsMMIODevice
66 )
67 {
68 /* Not yet supported */
69 ASSERT(IsMMIODevice == FALSE);
70
71 /* Set default baud rate */
72 if (BaudRate == 0) BaudRate = 19200;
73
74 /* Check if port or address given */
75 if (PortNumber)
76 {
77 /* Pick correct address for port */
78 if (!PortAddress)
79 {
80 switch (PortNumber)
81 {
82 case 1:
83 PortAddress = (PUCHAR)0x3F8;
84 break;
85
86 case 2:
87 PortAddress = (PUCHAR)0x2F8;
88 break;
89
90 case 3:
91 PortAddress = (PUCHAR)0x3E8;
92 break;
93
94 default:
95 PortNumber = 4;
96 PortAddress = (PUCHAR)0x2E8;
97 }
98 }
99 }
100 else
101 {
102 /* Pick correct port for address */
103 PortAddress = (PUCHAR)0x2F8;
104 if (CpDoesPortExist(PortAddress))
105 {
106 PortNumber = 2;
107 }
108 else
109 {
110 PortAddress = (PUCHAR)0x3F8;
111 if (!CpDoesPortExist(PortAddress)) return FALSE;
112 PortNumber = 1;
113 }
114 }
115
116 /* Initialize the port unless it's already up, and then return it */
117 if (Port[PortNumber - 1].Address) return FALSE;
118 CpInitialize(&Port[PortNumber - 1], PortAddress, BaudRate);
119 *PortId = PortNumber - 1;
120 return TRUE;
121 }