xref: /reactos/ntoskrnl/inbv/inbvport.c (revision 4501bbac)
1c2c66affSColin Finck /*
2c2c66affSColin Finck  * PROJECT:         ReactOS Kernel
3c2c66affSColin Finck  * LICENSE:         BSD - See COPYING.ARM in the top level directory
4c2c66affSColin Finck  * FILE:            ntoskrnl/inbv/inbvport.c
5c2c66affSColin Finck  * PURPOSE:         Serial Port Boot Driver for Headless Terminal Support
6c2c66affSColin Finck  * PROGRAMMERS:     ReactOS Portable Systems Group
7c2c66affSColin Finck  */
8c2c66affSColin Finck 
9c2c66affSColin Finck /* INCLUDES ******************************************************************/
10c2c66affSColin Finck 
11c2c66affSColin Finck #include <ntoskrnl.h>
12c2c66affSColin Finck #include <debug.h>
13c2c66affSColin Finck 
14c2c66affSColin Finck /* GLOBALS *******************************************************************/
15c2c66affSColin Finck 
16c2c66affSColin Finck CPPORT Port[4] =
17c2c66affSColin Finck {
18c2c66affSColin Finck     {NULL, 0, TRUE},
19c2c66affSColin Finck     {NULL, 0, TRUE},
20c2c66affSColin Finck     {NULL, 0, TRUE},
21c2c66affSColin Finck     {NULL, 0, TRUE}
22c2c66affSColin Finck };
23c2c66affSColin Finck 
24c2c66affSColin Finck /* FUNCTIONS *****************************************************************/
25c2c66affSColin Finck 
26c2c66affSColin Finck BOOLEAN
27c2c66affSColin Finck NTAPI
InbvPortPollOnly(IN ULONG PortId)28c2c66affSColin Finck InbvPortPollOnly(IN ULONG PortId)
29c2c66affSColin Finck {
30c2c66affSColin Finck     UCHAR Dummy;
31c2c66affSColin Finck 
32c2c66affSColin Finck     /* Poll a byte from the port */
33c2c66affSColin Finck     return CpGetByte(&Port[PortId], &Dummy, FALSE, TRUE) == CP_GET_SUCCESS;
34c2c66affSColin Finck }
35c2c66affSColin Finck 
36c2c66affSColin Finck BOOLEAN
37c2c66affSColin Finck NTAPI
InbvPortGetByte(IN ULONG PortId,OUT PUCHAR Byte)38c2c66affSColin Finck InbvPortGetByte(IN  ULONG  PortId,
39c2c66affSColin Finck                 OUT PUCHAR Byte)
40c2c66affSColin Finck {
41c2c66affSColin Finck     /* Read a byte from the port */
42c2c66affSColin Finck     return CpGetByte(&Port[PortId], Byte, TRUE, FALSE) == CP_GET_SUCCESS;
43c2c66affSColin Finck }
44c2c66affSColin Finck 
45c2c66affSColin Finck VOID
46c2c66affSColin Finck NTAPI
InbvPortPutByte(IN ULONG PortId,IN UCHAR Byte)47c2c66affSColin Finck InbvPortPutByte(IN ULONG PortId,
48c2c66affSColin Finck                 IN UCHAR Byte)
49c2c66affSColin Finck {
50c2c66affSColin Finck     /* Send the byte */
51c2c66affSColin Finck     CpPutByte(&Port[PortId], Byte);
52c2c66affSColin Finck }
53c2c66affSColin Finck 
54c2c66affSColin Finck VOID
55c2c66affSColin Finck NTAPI
InbvPortEnableFifo(IN ULONG PortId,IN BOOLEAN Enable)56c2c66affSColin Finck InbvPortEnableFifo(IN ULONG   PortId,
57c2c66affSColin Finck                    IN BOOLEAN Enable)
58c2c66affSColin Finck {
59c2c66affSColin Finck     /* Set FIFO as requested */
60c2c66affSColin Finck     CpEnableFifo(Port[PortId].Address, Enable);
61c2c66affSColin Finck }
62c2c66affSColin Finck 
63c2c66affSColin Finck VOID
64c2c66affSColin Finck NTAPI
InbvPortTerminate(IN ULONG PortId)65c2c66affSColin Finck InbvPortTerminate(IN ULONG PortId)
66c2c66affSColin Finck {
67c2c66affSColin Finck     /* The port is now available */
68c2c66affSColin Finck     Port[PortId].Address = NULL;
69c2c66affSColin Finck }
70c2c66affSColin Finck 
71c2c66affSColin Finck BOOLEAN
72c2c66affSColin Finck NTAPI
InbvPortInitialize(IN ULONG BaudRate,IN ULONG PortNumber,IN PUCHAR PortAddress,OUT PULONG PortId,IN BOOLEAN IsMMIODevice)73c2c66affSColin Finck InbvPortInitialize(IN  ULONG   BaudRate,
74c2c66affSColin Finck                    IN  ULONG   PortNumber,
75c2c66affSColin Finck                    IN  PUCHAR  PortAddress,
76c2c66affSColin Finck                    OUT PULONG  PortId,
77c2c66affSColin Finck                    IN  BOOLEAN IsMMIODevice)
78c2c66affSColin Finck {
79c2c66affSColin Finck     /* Not yet supported */
80c2c66affSColin Finck     ASSERT(IsMMIODevice == FALSE);
81c2c66affSColin Finck 
82222e7923SDmitry Borisov #if defined(SARCH_PC98)
83*4501bbacSDmitry Borisov     /* Set default baud rate */
84*4501bbacSDmitry Borisov     if (BaudRate == 0) BaudRate = 9600;
85*4501bbacSDmitry Borisov 
86222e7923SDmitry Borisov     /* Check if port or address given */
87222e7923SDmitry Borisov     if (PortNumber)
88222e7923SDmitry Borisov     {
89222e7923SDmitry Borisov         /* Pick correct address for port */
90222e7923SDmitry Borisov         if (!PortAddress)
91222e7923SDmitry Borisov         {
92222e7923SDmitry Borisov             if (PortNumber == 1)
93222e7923SDmitry Borisov             {
94222e7923SDmitry Borisov                 PortAddress = (PUCHAR)0x30;
95222e7923SDmitry Borisov             }
96222e7923SDmitry Borisov             else
97222e7923SDmitry Borisov             {
98222e7923SDmitry Borisov                 PortAddress = (PUCHAR)0x238;
99222e7923SDmitry Borisov                 PortNumber = 2;
100222e7923SDmitry Borisov             }
101222e7923SDmitry Borisov         }
102222e7923SDmitry Borisov     }
103222e7923SDmitry Borisov     else
104222e7923SDmitry Borisov     {
105222e7923SDmitry Borisov         /* Pick correct port for address */
106222e7923SDmitry Borisov         PortAddress = (PUCHAR)0x30;
107222e7923SDmitry Borisov         if (CpDoesPortExist(PortAddress))
108222e7923SDmitry Borisov         {
109222e7923SDmitry Borisov             PortNumber = 1;
110222e7923SDmitry Borisov         }
111222e7923SDmitry Borisov         else
112222e7923SDmitry Borisov         {
113222e7923SDmitry Borisov             PortAddress = (PUCHAR)0x238;
114222e7923SDmitry Borisov             if (!CpDoesPortExist(PortAddress))
115222e7923SDmitry Borisov                 return FALSE;
116222e7923SDmitry Borisov 
117222e7923SDmitry Borisov             PortNumber = 2;
118222e7923SDmitry Borisov         }
119222e7923SDmitry Borisov     }
120222e7923SDmitry Borisov #else
121*4501bbacSDmitry Borisov     /* Set default baud rate */
122*4501bbacSDmitry Borisov     if (BaudRate == 0) BaudRate = 19200;
123*4501bbacSDmitry Borisov 
124c2c66affSColin Finck     /* Check if port or address given */
125c2c66affSColin Finck     if (PortNumber)
126c2c66affSColin Finck     {
127c2c66affSColin Finck         /* Pick correct address for port */
128c2c66affSColin Finck         if (!PortAddress)
129c2c66affSColin Finck         {
130c2c66affSColin Finck             switch (PortNumber)
131c2c66affSColin Finck             {
132c2c66affSColin Finck                 case 1:
133c2c66affSColin Finck                     PortAddress = (PUCHAR)0x3F8;
134c2c66affSColin Finck                     break;
135c2c66affSColin Finck 
136c2c66affSColin Finck                 case 2:
137c2c66affSColin Finck                     PortAddress = (PUCHAR)0x2F8;
138c2c66affSColin Finck                     break;
139c2c66affSColin Finck 
140c2c66affSColin Finck                 case 3:
141c2c66affSColin Finck                     PortAddress = (PUCHAR)0x3E8;
142c2c66affSColin Finck                     break;
143c2c66affSColin Finck 
144c2c66affSColin Finck                 default:
145c2c66affSColin Finck                     PortNumber = 4;
146c2c66affSColin Finck                     PortAddress = (PUCHAR)0x2E8;
147c2c66affSColin Finck             }
148c2c66affSColin Finck         }
149c2c66affSColin Finck     }
150c2c66affSColin Finck     else
151c2c66affSColin Finck     {
152c2c66affSColin Finck         /* Pick correct port for address */
153c2c66affSColin Finck         PortAddress = (PUCHAR)0x2F8;
154c2c66affSColin Finck         if (CpDoesPortExist(PortAddress))
155c2c66affSColin Finck         {
156c2c66affSColin Finck             PortNumber = 2;
157c2c66affSColin Finck         }
158c2c66affSColin Finck         else
159c2c66affSColin Finck         {
160c2c66affSColin Finck             PortAddress = (PUCHAR)0x3F8;
161c2c66affSColin Finck             if (!CpDoesPortExist(PortAddress)) return FALSE;
162c2c66affSColin Finck             PortNumber = 1;
163c2c66affSColin Finck         }
164c2c66affSColin Finck     }
165222e7923SDmitry Borisov #endif
166c2c66affSColin Finck 
167c2c66affSColin Finck     /* Initialize the port unless it's already up, and then return it */
168c2c66affSColin Finck     if (Port[PortNumber - 1].Address) return FALSE;
169c2c66affSColin Finck 
170c2c66affSColin Finck     CpInitialize(&Port[PortNumber - 1], PortAddress, BaudRate);
171c2c66affSColin Finck     *PortId = PortNumber - 1;
172c2c66affSColin Finck 
173c2c66affSColin Finck     return TRUE;
174c2c66affSColin Finck }
175c2c66affSColin Finck 
176c2c66affSColin Finck /* EOF */
177