Improvements in COM port support
All checks were successful
ci/woodpecker/push/build Pipeline was successful
All checks were successful
ci/woodpecker/push/build Pipeline was successful
This commit is contained in:
parent
e8e7d7b905
commit
c5a7d0fe05
@ -26,13 +26,13 @@ HlComPortGetByte(IN PCPPORT Port,
|
|||||||
IN BOOLEAN Poll);
|
IN BOOLEAN Poll);
|
||||||
|
|
||||||
XTCDECL
|
XTCDECL
|
||||||
UCHAR
|
XTSTATUS
|
||||||
HlComPortReadLsr(IN PCPPORT Port,
|
HlComPortPutByte(IN PCPPORT Port,
|
||||||
IN UCHAR Byte);
|
IN UCHAR Byte);
|
||||||
|
|
||||||
XTCDECL
|
XTCDECL
|
||||||
XTSTATUS
|
UCHAR
|
||||||
HlComPortPutByte(IN PCPPORT Port,
|
HlComPortReadLsr(IN PCPPORT Port,
|
||||||
IN UCHAR Byte);
|
IN UCHAR Byte);
|
||||||
|
|
||||||
XTCDECL
|
XTCDECL
|
||||||
|
@ -88,7 +88,7 @@
|
|||||||
#define COMPORT_REG_MCR 0x04 /* Modem Control Register */
|
#define COMPORT_REG_MCR 0x04 /* Modem Control Register */
|
||||||
#define COMPORT_REG_LSR 0x05 /* Line Status Register */
|
#define COMPORT_REG_LSR 0x05 /* Line Status Register */
|
||||||
#define COMPORT_REG_MSR 0x06 /* Modem Status Register */
|
#define COMPORT_REG_MSR 0x06 /* Modem Status Register */
|
||||||
#define COMPROT_REG_SR 0x07 /* Scratch Register */
|
#define COMPORT_REG_SR 0x07 /* Scratch Register */
|
||||||
|
|
||||||
/* Serial (COM) port initial state */
|
/* Serial (COM) port initial state */
|
||||||
typedef struct _CPPORT
|
typedef struct _CPPORT
|
||||||
|
@ -73,34 +73,30 @@ BlComPortInitialize()
|
|||||||
Argument++;
|
Argument++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check for some custom COM port (COM0 means non-default one) */
|
/* Check if custom COM port address supplied */
|
||||||
if(PortNumber == 0)
|
if(PortNumber == 0 && RtlWideStringCompare(Argument, L":0x", 3) == 0)
|
||||||
{
|
{
|
||||||
/* Look for COM port address */
|
/* COM port address provided */
|
||||||
if(RtlWideStringCompare(Argument, L",0x", 3) == 0)
|
Argument += 3;
|
||||||
|
while((*Argument >= '0' && *Argument <= '9') ||
|
||||||
|
(*Argument >= 'A' && *Argument <= 'F') ||
|
||||||
|
(*Argument >= 'a' && *Argument <= 'f'))
|
||||||
{
|
{
|
||||||
/* COM port address provided */
|
/* Get port address */
|
||||||
Argument += 3;
|
PortAddress *= 16;
|
||||||
while((*Argument >= '0' && *Argument <= '9') ||
|
if(*Argument >= '0' && *Argument <= '9')
|
||||||
(*Argument >= 'A' && *Argument <= 'F') ||
|
|
||||||
(*Argument >= 'a' && *Argument <= 'f'))
|
|
||||||
{
|
{
|
||||||
/* Get port address */
|
PortAddress += *Argument - '0';
|
||||||
PortAddress *= 16;
|
|
||||||
if(*Argument >= '0' && *Argument <= '9')
|
|
||||||
{
|
|
||||||
PortAddress += *Argument - '0';
|
|
||||||
}
|
|
||||||
else if(*Argument >= 'A' && *Argument <= 'F')
|
|
||||||
{
|
|
||||||
PortAddress += *Argument - 'A' + 10;
|
|
||||||
}
|
|
||||||
else if(*Argument >= 'a' && *Argument <= 'f')
|
|
||||||
{
|
|
||||||
PortAddress += *Argument - 'a' + 10;
|
|
||||||
}
|
|
||||||
Argument++;
|
|
||||||
}
|
}
|
||||||
|
else if(*Argument >= 'A' && *Argument <= 'F')
|
||||||
|
{
|
||||||
|
PortAddress += *Argument - 'A' + 10;
|
||||||
|
}
|
||||||
|
else if(*Argument >= 'a' && *Argument <= 'f')
|
||||||
|
{
|
||||||
|
PortAddress += *Argument - 'a' + 10;
|
||||||
|
}
|
||||||
|
Argument++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,6 +124,16 @@ BlComPortInitialize()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Print debug message depending on port settings */
|
||||||
|
if(PortAddress)
|
||||||
|
{
|
||||||
|
BlEfiPrint(L"Initializing serial console at COM port address: %lx\n", PortAddress);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
BlEfiPrint(L"Initializing serial console at port COM%d\n", PortNumber);
|
||||||
|
}
|
||||||
|
|
||||||
/* Initialize COM port */
|
/* Initialize COM port */
|
||||||
Status = HlInitializeComPort(&EfiSerialPort, PortNumber, UlongToPtr(PortAddress), BaudRate);
|
Status = HlInitializeComPort(&EfiSerialPort, PortNumber, UlongToPtr(PortAddress), BaudRate);
|
||||||
if(Status != STATUS_SUCCESS)
|
if(Status != STATUS_SUCCESS)
|
||||||
|
@ -93,47 +93,6 @@ HlComPortGetByte(IN PCPPORT Port,
|
|||||||
return STATUS_NOT_FOUND;
|
return STATUS_NOT_FOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Reads LSR from specified serial port.
|
|
||||||
*
|
|
||||||
* @param Port
|
|
||||||
* Address of COM port.
|
|
||||||
*
|
|
||||||
* @param Byte
|
|
||||||
* Value expected from the port.
|
|
||||||
*
|
|
||||||
* @return Byte read from COM port.
|
|
||||||
*
|
|
||||||
* @since XT 1.0
|
|
||||||
*/
|
|
||||||
XTCDECL
|
|
||||||
UCHAR
|
|
||||||
HlComPortReadLsr(IN PCPPORT Port,
|
|
||||||
IN UCHAR Byte)
|
|
||||||
{
|
|
||||||
UCHAR Lsr, Msr;
|
|
||||||
STATIC UCHAR RingFlag;
|
|
||||||
|
|
||||||
/* Read the Line Status Register (LSR) */
|
|
||||||
Lsr = HlIoPortInByte(PtrToUshort(Port->Address + (ULONG)COMPORT_REG_LSR));
|
|
||||||
|
|
||||||
/* Check if expected byte is present */
|
|
||||||
if((Lsr & Byte) == 0)
|
|
||||||
{
|
|
||||||
/* Check Modem Status Register (MSR) for ring indicator */
|
|
||||||
Msr = HlIoPortInByte(PtrToUshort(Port->Address + (ULONG)COMPORT_REG_MSR));
|
|
||||||
RingFlag |= (Msr & COMPORT_MSR_RI) ? 1 : 2;
|
|
||||||
if(RingFlag == 3)
|
|
||||||
{
|
|
||||||
/* Ring indicator toggled, use modem control */
|
|
||||||
Port->Flags |= COMPORT_FLAG_MC;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Return byte read */
|
|
||||||
return Lsr;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This routine writes a byte to the serial port.
|
* This routine writes a byte to the serial port.
|
||||||
*
|
*
|
||||||
@ -191,6 +150,47 @@ HlComPortPutByte(IN PCPPORT Port,
|
|||||||
return STATUS_SUCCESS;
|
return STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads LSR from specified serial port.
|
||||||
|
*
|
||||||
|
* @param Port
|
||||||
|
* Address of COM port.
|
||||||
|
*
|
||||||
|
* @param Byte
|
||||||
|
* Value expected from the port.
|
||||||
|
*
|
||||||
|
* @return Byte read from COM port.
|
||||||
|
*
|
||||||
|
* @since XT 1.0
|
||||||
|
*/
|
||||||
|
XTCDECL
|
||||||
|
UCHAR
|
||||||
|
HlComPortReadLsr(IN PCPPORT Port,
|
||||||
|
IN UCHAR Byte)
|
||||||
|
{
|
||||||
|
UCHAR Lsr, Msr;
|
||||||
|
STATIC UCHAR RingFlag;
|
||||||
|
|
||||||
|
/* Read the Line Status Register (LSR) */
|
||||||
|
Lsr = HlIoPortInByte(PtrToUshort(Port->Address + (ULONG)COMPORT_REG_LSR));
|
||||||
|
|
||||||
|
/* Check if expected byte is present */
|
||||||
|
if((Lsr & Byte) == 0)
|
||||||
|
{
|
||||||
|
/* Check Modem Status Register (MSR) for ring indicator */
|
||||||
|
Msr = HlIoPortInByte(PtrToUshort(Port->Address + (ULONG)COMPORT_REG_MSR));
|
||||||
|
RingFlag |= (Msr & COMPORT_MSR_RI) ? 1 : 2;
|
||||||
|
if(RingFlag == 3)
|
||||||
|
{
|
||||||
|
/* Ring indicator toggled, use modem control */
|
||||||
|
Port->Flags |= COMPORT_FLAG_MC;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Return byte read */
|
||||||
|
return Lsr;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This routine initializes the COM port.
|
* This routine initializes the COM port.
|
||||||
*
|
*
|
||||||
@ -217,9 +217,9 @@ HlInitializeComPort(IN OUT PCPPORT Port,
|
|||||||
IN PUCHAR PortAddress,
|
IN PUCHAR PortAddress,
|
||||||
IN ULONG BaudRate)
|
IN ULONG BaudRate)
|
||||||
{
|
{
|
||||||
PUCHAR Address;
|
|
||||||
UCHAR Byte = 0;
|
|
||||||
USHORT Flags = 0;
|
USHORT Flags = 0;
|
||||||
|
UCHAR Byte = 0;
|
||||||
|
PUCHAR Address;
|
||||||
ULONG Mode;
|
ULONG Mode;
|
||||||
|
|
||||||
/* We support only a pre-defined number of ports */
|
/* We support only a pre-defined number of ports */
|
||||||
@ -266,12 +266,13 @@ HlInitializeComPort(IN OUT PCPPORT Port,
|
|||||||
do
|
do
|
||||||
{
|
{
|
||||||
/* Check whether the 16450/16550 scratch register exists */
|
/* Check whether the 16450/16550 scratch register exists */
|
||||||
HlIoPortOutByte(PtrToUshort(Address + (ULONG)COMPROT_REG_SR), Byte);
|
HlIoPortOutByte(PtrToUshort(Address + (ULONG)COMPORT_REG_SR), Byte);
|
||||||
if(HlIoPortInByte(PtrToUshort(Address + (ULONG)COMPROT_REG_SR)) != Byte)
|
if(HlIoPortInByte(PtrToUshort(Address + (ULONG)COMPORT_REG_SR)) != Byte)
|
||||||
{
|
{
|
||||||
return STATUS_NOT_FOUND;
|
return STATUS_NOT_FOUND;
|
||||||
}
|
}
|
||||||
} while(++Byte != 0);
|
}
|
||||||
|
while(++Byte != 0);
|
||||||
|
|
||||||
/* Disable interrupts */
|
/* Disable interrupts */
|
||||||
HlIoPortOutByte(PtrToUshort(Address + (ULONG)COMPORT_REG_LCR), COMPORT_LSR_DIS);
|
HlIoPortOutByte(PtrToUshort(Address + (ULONG)COMPORT_REG_LCR), COMPORT_LSR_DIS);
|
||||||
@ -297,19 +298,16 @@ HlInitializeComPort(IN OUT PCPPORT Port,
|
|||||||
HlIoPortOutByte(PtrToUshort(Address + (ULONG)COMPORT_REG_FCR),
|
HlIoPortOutByte(PtrToUshort(Address + (ULONG)COMPORT_REG_FCR),
|
||||||
COMPORT_FCR_ENABLE | COMPORT_FCR_RCVR_RESET | COMPORT_FCR_TXMT_RESET);
|
COMPORT_FCR_ENABLE | COMPORT_FCR_RCVR_RESET | COMPORT_FCR_TXMT_RESET);
|
||||||
|
|
||||||
/* Enable loopback mode and test serial port */
|
|
||||||
HlIoPortOutByte(PtrToUshort(Address + (ULONG)COMPORT_REG_MCR), COMPORT_MCR_LOOP);
|
|
||||||
HlIoPortOutByte(PtrToUshort(Address + (ULONG)COMPORT_REG_RBR), COMPORT_MSR_TST);
|
|
||||||
if(HlIoPortInByte(PtrToUshort(Address + (ULONG)COMPORT_REG_RBR)) != COMPORT_MSR_TST)
|
|
||||||
{
|
|
||||||
return STATUS_IO_DEVICE_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Mark port as fully initialized */
|
/* Mark port as fully initialized */
|
||||||
Flags |= COMPORT_FLAG_INIT;
|
Flags |= COMPORT_FLAG_INIT;
|
||||||
|
|
||||||
/* Disable loopback mode and use port normally */
|
/* Make sure port works in Normal Operation Mode (NOM) */
|
||||||
HlIoPortOutByte(PtrToUshort(Address + (ULONG)COMPORT_REG_MCR), COMPORT_MCR_NOM);
|
HlIoPortOutByte(PtrToUshort(Address + (ULONG)COMPORT_REG_MCR), COMPORT_MCR_NOM);
|
||||||
|
|
||||||
|
/* Read junk data out of the Receive Buffer Register (RBR) */
|
||||||
|
HlIoPortInByte(PtrToUshort(Port->Address + (ULONG)COMPORT_REG_RBR));
|
||||||
|
|
||||||
|
/* Store port details */
|
||||||
Port->Address = Address;
|
Port->Address = Address;
|
||||||
Port->Baud = BaudRate;
|
Port->Baud = BaudRate;
|
||||||
Port->Flags = Flags;
|
Port->Flags = Flags;
|
||||||
|
Loading…
Reference in New Issue
Block a user