26 #include <linux/module.h>
28 #include <linux/slab.h>
32 #include <linux/poll.h>
38 #include <linux/tty.h>
66 static unsigned int stdout_bc;
69 static unsigned int stdout_irq;
113 static int find_console_handle(
void)
116 const char *sprop =
NULL;
145 pr_warning(
"ehv-bc: stdout node '%s' does not exist\n", sprop);
156 if (stdout_irq ==
NO_IRQ) {
157 pr_err(
"ehv-bc: no 'interrupts' property in %s node\n", sprop);
167 pr_err(
"ehv-bc: no 'hv-handle' property in %s node\n",
180 #ifdef CONFIG_PPC_EARLY_DEBUG_EHV_BC
190 static void byte_channel_spin_send(
const char data)
196 ret = ev_byte_channel_send(CONFIG_PPC_EARLY_DEBUG_EHV_BC_HANDLE,
205 static void ehv_bc_udbg_putc(
char c)
208 byte_channel_spin_send(
'\r');
210 byte_channel_spin_send(c);
224 void __init udbg_init_ehv_bc(
void)
226 unsigned int rx_count, tx_count;
230 ret = ev_byte_channel_poll(CONFIG_PPC_EARLY_DEBUG_EHV_BC_HANDLE,
231 &rx_count, &tx_count);
238 udbg_printf(
"ehv-bc: early console using byte channel handle %u\n",
239 CONFIG_PPC_EARLY_DEBUG_EHV_BC_HANDLE);
254 static int ehv_bc_console_byte_channel_send(
unsigned int handle,
const char *
s,
263 ret = ev_byte_channel_send(handle, &len, s);
282 static void ehv_bc_console_write(
struct console *co,
const char *s,
286 unsigned int i,
j = 0;
289 for (i = 0; i <
count; i++) {
297 if (ehv_bc_console_byte_channel_send(stdout_bc, s2, j))
304 ehv_bc_console_byte_channel_send(stdout_bc, s2, j);
316 return ehv_bc_driver;
319 static struct console ehv_bc_console = {
321 .write = ehv_bc_console_write,
322 .device = ehv_bc_console_device,
334 static int __init ehv_bc_console_init(
void)
336 if (!find_console_handle()) {
337 pr_debug(
"ehv-bc: stdout is not a byte channel\n");
341 #ifdef CONFIG_PPC_EARLY_DEBUG_EHV_BC
345 if (stdout_bc != CONFIG_PPC_EARLY_DEBUG_EHV_BC_HANDLE)
346 pr_warning(
"ehv-bc: udbg handle %u is not the stdout handle\n",
347 CONFIG_PPC_EARLY_DEBUG_EHV_BC_HANDLE);
357 pr_info(
"ehv-bc: registered console driver for byte channel %u\n",
371 static irqreturn_t ehv_bc_tty_rx_isr(
int irq,
void *data)
375 unsigned int rx_count, tx_count, len;
388 ev_byte_channel_poll(bc->
handle, &rx_count, &tx_count);
398 len =
min_t(
unsigned int, count,
sizeof(buffer));
403 ev_byte_channel_receive(bc->
handle, &len, buffer);
410 ret = tty_insert_flip_string(ttys, buffer, len);
438 static void ehv_bc_tx_dequeue(
struct ehv_bc_data *bc)
441 unsigned int len,
ret;
446 len =
min_t(
unsigned int,
450 ret = ev_byte_channel_send(bc->
handle, &len, bc->
buf + bc->
tail);
457 spin_unlock_irqrestore(&bc->
lock, flags);
458 }
while (count && !ret);
467 enable_tx_interrupt(bc);
469 disable_tx_interrupt(bc);
470 spin_unlock_irqrestore(&bc->
lock, flags);
479 static irqreturn_t ehv_bc_tty_tx_isr(
int irq,
void *data)
484 ehv_bc_tx_dequeue(bc);
504 static int ehv_bc_tty_write(
struct tty_struct *ttys,
const unsigned char *s,
510 unsigned int written = 0;
521 spin_unlock_irqrestore(&bc->
lock, flags);
530 ehv_bc_tx_dequeue(bc);
544 static int ehv_bc_tty_open(
struct tty_struct *ttys,
struct file *filp)
559 static void ehv_bc_tty_close(
struct tty_struct *ttys,
struct file *filp)
574 static int ehv_bc_tty_write_room(
struct tty_struct *ttys)
582 spin_unlock_irqrestore(&bc->
lock, flags);
599 static void ehv_bc_tty_throttle(
struct tty_struct *ttys)
613 static void ehv_bc_tty_unthrottle(
struct tty_struct *ttys)
623 static void ehv_bc_tty_hangup(
struct tty_struct *ttys)
627 ehv_bc_tx_dequeue(bc);
639 .open = ehv_bc_tty_open,
640 .close = ehv_bc_tty_close,
641 .write = ehv_bc_tty_write,
642 .write_room = ehv_bc_tty_write_room,
643 .throttle = ehv_bc_tty_throttle,
644 .unthrottle = ehv_bc_tty_unthrottle,
645 .hangup = ehv_bc_tty_hangup,
655 static int ehv_bc_tty_port_activate(
struct tty_port *
port,
665 dev_err(bc->
dev,
"could not request rx irq %u (ret=%i)\n",
675 dev_err(bc->
dev,
"could not request tx irq %u (ret=%i)\n",
684 disable_tx_interrupt(bc);
689 static void ehv_bc_tty_port_shutdown(
struct tty_port *port)
698 .activate = ehv_bc_tty_port_activate,
699 .shutdown = ehv_bc_tty_port_shutdown,
709 static unsigned int index = 1;
714 dev_err(&pdev->
dev,
"no 'hv-handle' property in %s node\n",
724 i = (handle == stdout_bc) ? 0 : index++;
735 dev_err(&pdev->
dev,
"no 'interrupts' property in %s node\n",
742 bc->
port.ops = &ehv_bc_tty_port_ops;
746 if (IS_ERR(bc->
dev)) {
747 ret = PTR_ERR(bc->
dev);
748 dev_err(&pdev->
dev,
"could not register tty (ret=%i)\n", ret);
754 dev_info(&pdev->
dev,
"registered /dev/%s%u for byte channel %u\n",
779 static const struct of_device_id ehv_bc_tty_of_ids[] = {
780 { .compatible =
"epapr,hv-byte-channel" },
788 .of_match_table = ehv_bc_tty_of_ids,
790 .probe = ehv_bc_tty_probe,
791 .remove = ehv_bc_tty_remove,
799 static int __init ehv_bc_init(
void)
802 unsigned int count = 0;
805 pr_info(
"ePAPR hypervisor byte channel driver\n");
808 for_each_compatible_node(np,
NULL,
"epapr,hv-byte-channel")
823 ehv_bc_driver = alloc_tty_driver(count);
824 if (!ehv_bc_driver) {
830 ehv_bc_driver->
name = ehv_bc_console.
name;
839 pr_err(
"ehv-bc: could not register tty driver (ret=%i)\n", ret);
845 pr_err(
"ehv-bc: could not register platform driver (ret=%i)\n",
869 static void __exit ehv_bc_exit(
void)