WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [PATCH] add polling support for ns16550

To: Xen Mailing List <xen-devel@xxxxxxxxxxxxxxxxxxx>
Subject: [Xen-devel] [PATCH] add polling support for ns16550
From: Alex Williamson <alex.williamson@xxxxxx>
Date: Wed, 23 Nov 2005 09:40:49 -0700
Delivery-date: Wed, 23 Nov 2005 16:39:05 +0000
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Organization: LOSL
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
   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

<Prev in Thread] Current Thread [Next in Thread>