2010-09-15 07:46:28 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: ReactOS Kernel
|
|
|
|
* LICENSE: BSD - See COPYING.ARM in the top level directory
|
|
|
|
* FILE: ntoskrnl/inbv/inbvport.c
|
|
|
|
* PURPOSE: Serial Port Boot Driver for Headless Terminal Support
|
|
|
|
* PROGRAMMERS: ReactOS Portable Systems Group
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* INCLUDES ******************************************************************/
|
|
|
|
|
|
|
|
#include <ntoskrnl.h>
|
|
|
|
#include <debug.h>
|
|
|
|
|
|
|
|
/* GLOBALS *******************************************************************/
|
|
|
|
|
|
|
|
CPPORT Port[4] =
|
|
|
|
{
|
2012-11-24 19:50:31 +00:00
|
|
|
{NULL, 0, TRUE},
|
|
|
|
{NULL, 0, TRUE},
|
|
|
|
{NULL, 0, TRUE},
|
|
|
|
{NULL, 0, TRUE}
|
2010-09-15 07:46:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* FUNCTIONS *****************************************************************/
|
|
|
|
|
2013-08-18 17:47:19 +00:00
|
|
|
BOOLEAN
|
|
|
|
NTAPI
|
|
|
|
InbvPortPollOnly(IN ULONG PortId)
|
|
|
|
{
|
|
|
|
UCHAR Dummy;
|
|
|
|
|
|
|
|
/* Poll a byte from the port */
|
|
|
|
return CpGetByte(&Port[PortId], &Dummy, FALSE, TRUE) == CP_GET_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOLEAN
|
|
|
|
NTAPI
|
2013-10-14 20:50:44 +00:00
|
|
|
InbvPortGetByte(IN ULONG PortId,
|
|
|
|
OUT PUCHAR Byte)
|
2013-08-18 17:47:19 +00:00
|
|
|
{
|
|
|
|
/* Read a byte from the port */
|
2013-10-14 20:50:44 +00:00
|
|
|
return CpGetByte(&Port[PortId], Byte, TRUE, FALSE) == CP_GET_SUCCESS;
|
2013-08-18 17:47:19 +00:00
|
|
|
}
|
|
|
|
|
2010-09-15 07:46:28 +00:00
|
|
|
VOID
|
|
|
|
NTAPI
|
2013-10-14 20:50:44 +00:00
|
|
|
InbvPortPutByte(IN ULONG PortId,
|
|
|
|
IN UCHAR Byte)
|
2010-09-15 07:46:28 +00:00
|
|
|
{
|
2013-10-14 20:50:44 +00:00
|
|
|
/* Send the byte */
|
|
|
|
CpPutByte(&Port[PortId], Byte);
|
2010-09-15 07:46:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VOID
|
|
|
|
NTAPI
|
2013-10-14 20:50:44 +00:00
|
|
|
InbvPortEnableFifo(IN ULONG PortId,
|
|
|
|
IN BOOLEAN Enable)
|
2010-09-15 07:46:28 +00:00
|
|
|
{
|
2013-10-14 20:50:44 +00:00
|
|
|
/* Set FIFO as requested */
|
|
|
|
CpEnableFifo(Port[PortId].Address, Enable);
|
2010-09-15 07:46:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VOID
|
|
|
|
NTAPI
|
2012-11-24 19:50:31 +00:00
|
|
|
InbvPortTerminate(IN ULONG PortId)
|
2010-09-15 07:46:28 +00:00
|
|
|
{
|
2012-11-24 19:50:31 +00:00
|
|
|
/* The port is now available */
|
|
|
|
Port[PortId].Address = NULL;
|
2010-09-15 07:46:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOLEAN
|
|
|
|
NTAPI
|
2012-11-24 19:50:31 +00:00
|
|
|
InbvPortInitialize(IN ULONG BaudRate,
|
|
|
|
IN ULONG PortNumber,
|
|
|
|
IN PUCHAR PortAddress,
|
|
|
|
OUT PULONG PortId,
|
|
|
|
IN BOOLEAN IsMMIODevice)
|
2010-09-15 07:46:28 +00:00
|
|
|
{
|
2012-11-24 19:50:31 +00:00
|
|
|
/* Not yet supported */
|
|
|
|
ASSERT(IsMMIODevice == FALSE);
|
2010-09-15 07:46:28 +00:00
|
|
|
|
2020-04-21 20:22:42 +00:00
|
|
|
#if defined(SARCH_PC98)
|
2012-11-24 19:50:31 +00:00
|
|
|
/* Set default baud rate */
|
2020-04-21 20:22:42 +00:00
|
|
|
if (BaudRate == 0) BaudRate = 9600;
|
2010-09-15 07:46:28 +00:00
|
|
|
|
2020-03-06 18:50:31 +00:00
|
|
|
/* Check if port or address given */
|
|
|
|
if (PortNumber)
|
|
|
|
{
|
|
|
|
/* Pick correct address for port */
|
|
|
|
if (!PortAddress)
|
|
|
|
{
|
|
|
|
if (PortNumber == 1)
|
|
|
|
{
|
|
|
|
PortAddress = (PUCHAR)0x30;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PortAddress = (PUCHAR)0x238;
|
|
|
|
PortNumber = 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Pick correct port for address */
|
|
|
|
PortAddress = (PUCHAR)0x30;
|
|
|
|
if (CpDoesPortExist(PortAddress))
|
|
|
|
{
|
|
|
|
PortNumber = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PortAddress = (PUCHAR)0x238;
|
|
|
|
if (!CpDoesPortExist(PortAddress))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
PortNumber = 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
2020-04-21 20:22:42 +00:00
|
|
|
/* Set default baud rate */
|
|
|
|
if (BaudRate == 0) BaudRate = 19200;
|
|
|
|
|
2012-11-24 19:50:31 +00:00
|
|
|
/* Check if port or address given */
|
|
|
|
if (PortNumber)
|
|
|
|
{
|
|
|
|
/* Pick correct address for port */
|
|
|
|
if (!PortAddress)
|
|
|
|
{
|
2010-09-15 07:46:28 +00:00
|
|
|
switch (PortNumber)
|
2012-11-24 19:50:31 +00:00
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
PortAddress = (PUCHAR)0x3F8;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
PortAddress = (PUCHAR)0x2F8;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
PortAddress = (PUCHAR)0x3E8;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
PortNumber = 4;
|
|
|
|
PortAddress = (PUCHAR)0x2E8;
|
|
|
|
}
|
|
|
|
}
|
2010-09-15 07:46:28 +00:00
|
|
|
}
|
2012-11-24 19:50:31 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Pick correct port for address */
|
|
|
|
PortAddress = (PUCHAR)0x2F8;
|
|
|
|
if (CpDoesPortExist(PortAddress))
|
|
|
|
{
|
|
|
|
PortNumber = 2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PortAddress = (PUCHAR)0x3F8;
|
|
|
|
if (!CpDoesPortExist(PortAddress)) return FALSE;
|
|
|
|
PortNumber = 1;
|
2010-09-15 07:46:28 +00:00
|
|
|
}
|
2012-11-24 19:50:31 +00:00
|
|
|
}
|
2020-03-06 18:50:31 +00:00
|
|
|
#endif
|
2012-11-24 19:50:31 +00:00
|
|
|
|
|
|
|
/* Initialize the port unless it's already up, and then return it */
|
|
|
|
if (Port[PortNumber - 1].Address) return FALSE;
|
|
|
|
|
|
|
|
CpInitialize(&Port[PortNumber - 1], PortAddress, BaudRate);
|
|
|
|
*PortId = PortNumber - 1;
|
|
|
|
|
|
|
|
return TRUE;
|
2010-09-15 07:46:28 +00:00
|
|
|
}
|
2012-11-24 19:50:31 +00:00
|
|
|
|
|
|
|
/* EOF */
|