Skip to content

Commit

Permalink
uart: Don't change settings or throttle putc for Hyper-V
Browse files Browse the repository at this point in the history
Azure setup does not like it when FreeBSD overrides the settings of the
UART device. When Hyper-V is detected, don't do this and also don't
throttle putc() output. This is a workaround for the early boot hang
of FreeBSD on Azure.

Tested on Azure, ESXi (VM with serial port), and SG-8200

PR:		264267
Reviewed by:	kevans, whu
Tested by:	whu
Obtained from:	Rubicon Communications, LLC (Netgate)
MFC after:	2 weeks
Sponsored by:	Rubicon Communications, LLC (Netgate)
  • Loading branch information
Wei Hu authored and Wei Hu committed Mar 18, 2023
1 parent 927358d commit 8ea7fa1
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions sys/dev/uart/uart_dev_ns8250.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,10 @@ ns8250_param(struct uart_bas *bas, int baudrate, int databits, int stopbits,
int divisor;
uint8_t lcr;

/* Don't change settings when running on Hyper-V */
if (vm_guest == VM_GUEST_HV)
return (0);

lcr = 0;
if (databits >= 8)
lcr |= LCR_8BITS;
Expand Down Expand Up @@ -374,9 +378,11 @@ ns8250_putc(struct uart_bas *bas, int c)
{
int limit;

limit = 250000;
while ((uart_getreg(bas, REG_LSR) & LSR_THRE) == 0 && --limit)
DELAY(4);
if (vm_guest != VM_GUEST_HV) {
limit = 250000;
while ((uart_getreg(bas, REG_LSR) & LSR_THRE) == 0 && --limit)
DELAY(4);
}
uart_setreg(bas, REG_DATA, c);
uart_barrier(bas);
}
Expand Down Expand Up @@ -532,15 +538,15 @@ ns8250_bus_attach(struct uart_softc *sc)
#endif
if (!resource_int_value("uart", device_get_unit(sc->sc_dev), "flags",
&ivar)) {
if (UART_FLAGS_FCR_RX_LOW(ivar))
if (UART_FLAGS_FCR_RX_LOW(ivar))
ns8250->fcr |= FCR_RX_LOW;
else if (UART_FLAGS_FCR_RX_MEDL(ivar))
else if (UART_FLAGS_FCR_RX_MEDL(ivar))
ns8250->fcr |= FCR_RX_MEDL;
else if (UART_FLAGS_FCR_RX_HIGH(ivar))
else if (UART_FLAGS_FCR_RX_HIGH(ivar))
ns8250->fcr |= FCR_RX_HIGH;
else
ns8250->fcr |= FCR_RX_MEDH;
} else
} else
ns8250->fcr |= FCR_RX_MEDH;

/* Get IER mask */
Expand Down

0 comments on commit 8ea7fa1

Please sign in to comment.