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 BOOLEAN 27 NTAPI 28 InbvPortPollOnly(IN ULONG PortId) 29 { 30 UCHAR Dummy; 31 32 /* Poll a byte from the port */ 33 return CpGetByte(&Port[PortId], &Dummy, FALSE, TRUE) == CP_GET_SUCCESS; 34 } 35 36 BOOLEAN 37 NTAPI 38 InbvPortGetByte(IN ULONG PortId, 39 OUT PUCHAR Byte) 40 { 41 /* Read a byte from the port */ 42 return CpGetByte(&Port[PortId], Byte, TRUE, FALSE) == CP_GET_SUCCESS; 43 } 44 45 VOID 46 NTAPI 47 InbvPortPutByte(IN ULONG PortId, 48 IN UCHAR Byte) 49 { 50 /* Send the byte */ 51 CpPutByte(&Port[PortId], Byte); 52 } 53 54 VOID 55 NTAPI 56 InbvPortEnableFifo(IN ULONG PortId, 57 IN BOOLEAN Enable) 58 { 59 /* Set FIFO as requested */ 60 CpEnableFifo(Port[PortId].Address, Enable); 61 } 62 63 VOID 64 NTAPI 65 InbvPortTerminate(IN ULONG PortId) 66 { 67 /* The port is now available */ 68 Port[PortId].Address = NULL; 69 } 70 71 BOOLEAN 72 NTAPI 73 InbvPortInitialize(IN ULONG BaudRate, 74 IN ULONG PortNumber, 75 IN PUCHAR PortAddress, 76 OUT PULONG PortId, 77 IN BOOLEAN IsMMIODevice) 78 { 79 /* Not yet supported */ 80 ASSERT(IsMMIODevice == FALSE); 81 82 /* Set default baud rate */ 83 if (BaudRate == 0) BaudRate = 19200; 84 85 #if defined(SARCH_PC98) 86 /* Check if port or address given */ 87 if (PortNumber) 88 { 89 /* Pick correct address for port */ 90 if (!PortAddress) 91 { 92 if (PortNumber == 1) 93 { 94 PortAddress = (PUCHAR)0x30; 95 } 96 else 97 { 98 PortAddress = (PUCHAR)0x238; 99 PortNumber = 2; 100 } 101 } 102 } 103 else 104 { 105 /* Pick correct port for address */ 106 PortAddress = (PUCHAR)0x30; 107 if (CpDoesPortExist(PortAddress)) 108 { 109 PortNumber = 1; 110 } 111 else 112 { 113 PortAddress = (PUCHAR)0x238; 114 if (!CpDoesPortExist(PortAddress)) 115 return FALSE; 116 117 PortNumber = 2; 118 } 119 } 120 #else 121 /* Check if port or address given */ 122 if (PortNumber) 123 { 124 /* Pick correct address for port */ 125 if (!PortAddress) 126 { 127 switch (PortNumber) 128 { 129 case 1: 130 PortAddress = (PUCHAR)0x3F8; 131 break; 132 133 case 2: 134 PortAddress = (PUCHAR)0x2F8; 135 break; 136 137 case 3: 138 PortAddress = (PUCHAR)0x3E8; 139 break; 140 141 default: 142 PortNumber = 4; 143 PortAddress = (PUCHAR)0x2E8; 144 } 145 } 146 } 147 else 148 { 149 /* Pick correct port for address */ 150 PortAddress = (PUCHAR)0x2F8; 151 if (CpDoesPortExist(PortAddress)) 152 { 153 PortNumber = 2; 154 } 155 else 156 { 157 PortAddress = (PUCHAR)0x3F8; 158 if (!CpDoesPortExist(PortAddress)) return FALSE; 159 PortNumber = 1; 160 } 161 } 162 #endif 163 164 /* Initialize the port unless it's already up, and then return it */ 165 if (Port[PortNumber - 1].Address) return FALSE; 166 167 CpInitialize(&Port[PortNumber - 1], PortAddress, BaudRate); 168 *PortId = PortNumber - 1; 169 170 return TRUE; 171 } 172 173 /* EOF */ 174