#include <asm/hypervisor.h>
#include <asm/spitfire.h>
+#include <asm/vdev.h>
+#include <asm/oplib.h>
+#include <asm/irq.h>
#if defined(CONFIG_MAGIC_SYSRQ)
#define SUPPORT_SYSRQ
break;
if (c == CON_BREAK) {
+ if (uart_handle_break(port))
+ continue;
saw_console_brk = 1;
c = 0;
}
static void transmit_chars(struct uart_port *port)
{
- struct circ_buf *xmit = &port->info->xmit;
+ struct circ_buf *xmit;
+ if (!port->info)
+ return;
+
+ xmit = &port->info->xmit;
if (uart_circ_empty(xmit) || uart_tx_stopped(port))
return;
static void sunhv_start_tx(struct uart_port *port)
{
struct circ_buf *xmit = &port->info->xmit;
- unsigned long flags;
-
- spin_lock_irqsave(&port->lock, flags);
while (!uart_circ_empty(xmit)) {
long status = hypervisor_con_putchar(xmit->buf[xmit->tail]);
xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
port->icount.tx++;
}
-
- spin_unlock_irqrestore(&port->lock, flags);
}
/* port->lock is not held. */
{
if (break_state) {
unsigned long flags;
- int limit = 10000;
+ int limit = 1000000;
spin_lock_irqsave(&port->lock, flags);
long status = hypervisor_con_putchar(CON_BREAK);
if (status == HV_EOK)
break;
+ udelay(2);
}
spin_unlock_irqrestore(&port->lock, flags);
static inline void sunhv_console_putchar(struct uart_port *port, char c)
{
unsigned long flags;
- int limit = 10000;
+ int limit = 1000000;
spin_lock_irqsave(&port->lock, flags);
long status = hypervisor_con_putchar(c);
if (status == HV_EOK)
break;
+ udelay(2);
}
spin_unlock_irqrestore(&port->lock, flags);
}
}
-static int sunhv_console_setup(struct console *con, char *options)
-{
- return 0;
-}
-
static struct console sunhv_console = {
- .name = "ttyS",
+ .name = "ttyHV",
.write = sunhv_console_write,
.device = uart_console_device,
- .setup = sunhv_console_setup,
.flags = CON_PRINTBUFFER,
.index = -1,
.data = &sunhv_reg,
};
-static void __init sunhv_console_init(void)
+static inline struct console *SUNHV_CONSOLE(void)
{
if (con_is_present())
- return;
+ return NULL;
sunhv_console.index = 0;
- register_console(&sunhv_console);
+
+ return &sunhv_console;
+}
+
+static int __init hv_console_compatible(char *buf, int len)
+{
+ while (len) {
+ int this_len;
+
+ if (!strcmp(buf, "qcn"))
+ return 1;
+
+ this_len = strlen(buf) + 1;
+
+ buf += this_len;
+ len -= this_len;
+ }
+
+ return 0;
+}
+
+static unsigned int __init get_interrupt(void)
+{
+ const char *cons_str = "console";
+ const char *compat_str = "compatible";
+ int node = prom_getchild(sun4v_vdev_root);
+ char buf[64];
+ int err, len;
+
+ node = prom_searchsiblings(node, cons_str);
+ if (!node)
+ return 0;
+
+ len = prom_getproplen(node, compat_str);
+ if (len == 0 || len == -1)
+ return 0;
+
+ err = prom_getproperty(node, compat_str, buf, 64);
+ if (err == -1)
+ return 0;
+
+ if (!hv_console_compatible(buf, len))
+ return 0;
+
+ /* Ok, the this is the OBP node for the sun4v hypervisor
+ * console device. Decode the interrupt.
+ */
+ return sun4v_vdev_device_interrupt(node);
}
static int __init sunhv_init(void)
if (unlikely(!port))
return -ENOMEM;
+ memset(port, 0, sizeof(struct uart_port));
+
port->line = 0;
port->ops = &sunhv_pops;
port->type = PORT_SUNHV;
port->uartclk = ( 29491200 / 16 ); /* arbitrary */
- /* XXX Get interrupt. XXX */
- if (request_irq(0 /* XXX */, sunhv_interrupt,
- SA_SHIRQ, "serial(sunhv)", port)) {
- printk("sunhv: Cannot get IRQ %x\n",
- 0 /* XXX */);
+ /* Set this just to make uart_configure_port() happy. */
+ port->membase = (unsigned char __iomem *) __pa(port);
+
+ port->irq = get_interrupt();
+ if (!port->irq) {
kfree(port);
return -ENODEV;
}
sunhv_reg.minor = sunserial_current_minor;
sunhv_reg.nr = 1;
- sunhv_reg.cons = &sunhv_console;
ret = uart_register_driver(&sunhv_reg);
if (ret < 0) {
- free_irq(0 /* XXX */, up);
+ printk(KERN_ERR "SUNHV: uart_register_driver() failed %d\n",
+ ret);
kfree(port);
return ret;
}
- sunhv_port = port;
-
+ sunhv_reg.tty_driver->name_base = sunhv_reg.minor - 64;
sunserial_current_minor += 1;
- sunhv_console_init();
+ sunhv_reg.cons = SUNHV_CONSOLE();
- uart_add_one_port(&sunhv_reg, port);
+ sunhv_port = port;
+
+ ret = uart_add_one_port(&sunhv_reg, port);
+ if (ret < 0) {
+ printk(KERN_ERR "SUNHV: uart_add_one_port() failed %d\n", ret);
+ sunserial_current_minor -= 1;
+ uart_unregister_driver(&sunhv_reg);
+ kfree(port);
+ sunhv_port = NULL;
+ return -ENODEV;
+ }
+
+ if (request_irq(port->irq, sunhv_interrupt,
+ SA_SHIRQ, "serial(sunhv)", port)) {
+ printk(KERN_ERR "sunhv: Cannot register IRQ\n");
+ uart_remove_one_port(&sunhv_reg, port);
+ sunserial_current_minor -= 1;
+ uart_unregister_driver(&sunhv_reg);
+ kfree(port);
+ sunhv_port = NULL;
+ return -ENODEV;
+ }
return 0;
}
BUG_ON(!port);
- uart_remove_one_port(&sunhv_reg, port);
- free_irq(0 /* XXX */, port);
+ free_irq(port->irq, port);
+ uart_remove_one_port(&sunhv_reg, port);
sunserial_current_minor -= 1;
uart_unregister_driver(&sunhv_reg);