The patch below adds ac_timer based polling to the ns16550 UART
driver. This is useful when the interrupt line is not connected in
hardware or the mechanism to enable it is not readily available in the
hypervisor. Polling is only enabled when the UART IRQ is set to zero.
Thanks,
Alex
Signed-off-by: Alex Williamson <alex.williamson@xxxxxx>
---
diff -r 378e1c58bcd2 xen/drivers/char/ns16550.c
--- a/xen/drivers/char/ns16550.c Fri Nov 18 16:54:23 2005
+++ b/xen/drivers/char/ns16550.c Wed Nov 23 09:09:58 2005
@@ -30,6 +30,8 @@
unsigned long io_base; /* I/O port or memory-mapped I/O address. */
char *remapped_io_base; /* Remapped virtual address of mmap I/O. */
struct irqaction irqaction;
+ struct ac_timer timer;
+ unsigned int timeout;
} ns16550_com[2] = { { 0 } };
/* Register offsets */
@@ -121,6 +123,34 @@
}
}
+static void ns16550_timeout(void *data)
+{
+ struct serial_port *port = (struct serial_port *)data;
+ struct ns16550 *uart = port->uart;
+ struct cpu_user_regs *regs = guest_cpu_user_regs();
+ char lsr, ier;
+ int rx_cnt = port->tx_fifo_size;
+
+ /* interrupts must be disabled, this is likely to generate some */
+ ier = ns_read_reg(uart, IER);
+ if ( ier )
+ ns_write_reg(uart, IER, 0);
+
+ lsr = ns_read_reg(uart, LSR);
+
+ while ( (lsr & LSR_DR) && rx_cnt-- ) {
+ serial_rx_interrupt(port, regs);
+ lsr = ns_read_reg(uart, LSR);
+ }
+ if ( lsr & LSR_THRE )
+ serial_tx_interrupt(port, regs);
+
+ if ( ier )
+ ns_write_reg(uart, IER, ier);
+
+ set_ac_timer(&uart->timer, NOW() + MILLISECS(uart->timeout));
+}
+
static int ns16550_tx_empty(struct serial_port *port)
{
struct ns16550 *uart = port->uart;
@@ -178,15 +208,38 @@
port->tx_fifo_size = 16;
}
+static void ns16550_set_timeout(struct serial_port *port)
+{
+ struct ns16550 *uart = port->uart;
+ unsigned int bits;
+
+ bits = uart->data_bits + uart->stop_bits;
+
+ if ( uart->parity != PARITY_NONE )
+ bits++;
+
+ bits = bits * port->tx_fifo_size;
+
+ /* uart timeout in ms */
+ uart->timeout = (1000 * bits) / uart->baud;
+}
+
static void ns16550_init_postirq(struct serial_port *port)
{
struct ns16550 *uart = port->uart;
int rc;
- if ( uart->irq <= 0 )
+ if ( uart->irq < 0 )
return;
serial_async_transmit(port);
+
+ if ( uart->irq == 0 ) {
+ ns16550_set_timeout(port);
+ init_ac_timer(&uart->timer, ns16550_timeout, port, smp_processor_id());
+ set_ac_timer(&uart->timer, NOW() + MILLISECS(uart->timeout));
+ return;
+ }
uart->irqaction.handler = ns16550_interrupt;
uart->irqaction.name = "ns16550";
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel
|