From: Alex Williamson <alex.williamson@hp.com>
To: Xen Mailing List <xen-devel@lists.xensource.com>
Subject: [PATCH] add polling support for ns16550
Date: Wed, 23 Nov 2005 09:40:49 -0700 [thread overview]
Message-ID: <1132764049.18843.7.camel@tdi> (raw)
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@hp.com>
---
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";
next reply other threads:[~2005-11-23 16:40 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-11-23 16:40 Alex Williamson [this message]
2005-11-24 11:13 ` [PATCH] add polling support for ns16550 Keir Fraser
2005-11-24 14:07 ` Alex Williamson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1132764049.18843.7.camel@tdi \
--to=alex.williamson@hp.com \
--cc=xen-devel@lists.xensource.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.