2 * C-Brick Serial Port (and console) driver for SGI Altix machines.
4 * This driver is NOT suitable for talking to the l1-controller for
5 * anything other than 'console activities' --- please use the l1
8 * This file is subject to the terms and conditions of the GNU General Public
9 * License. See the file "COPYING" in the main directory of this archive
12 * Copyright (C) 2003 Silicon Graphics, Inc. All rights reserved.
15 #include <linux/config.h>
16 #include <linux/interrupt.h>
17 #include <linux/tty.h>
18 #include <linux/serial.h>
19 #include <linux/console.h>
20 #include <linux/module.h>
21 #include <linux/sysrq.h>
22 #include <linux/circ_buf.h>
23 #include <linux/serial_reg.h>
24 #include <asm/uaccess.h>
25 #include <asm/sn/sgi.h>
26 #include <asm/sn/sn_sal.h>
27 #include <asm/sn/pci/pciio.h>
28 #include <asm/sn/simulator.h>
29 #include <asm/sn/sn2/sn_private.h>
31 #if defined(CONFIG_SGI_L1_SERIAL_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
32 static char sysrq_serial_str[] = "\eSYS";
33 static char *sysrq_serial_ptr = sysrq_serial_str;
34 static unsigned long sysrq_requested;
35 #endif /* CONFIG_SGI_L1_SERIAL_CONSOLE && CONFIG_MAGIC_SYSRQ */
37 /* minor device number */
38 #define SN_SAL_MINOR 64
40 /* number of characters left in xmit buffer before we ask for more */
41 #define WAKEUP_CHARS 128
43 /* number of characters we can transmit to the SAL console at a time */
44 #define SN_SAL_MAX_CHARS 120
46 #define SN_SAL_EVENT_WRITE_WAKEUP 0
48 /* 64K, when we're asynch, it must be at least printk's LOG_BUF_LEN to
49 * avoid losing chars, (always has to be a power of 2) */
50 #define SN_SAL_BUFFER_SIZE (64 * (1 << 10))
52 #define SN_SAL_UART_FIFO_DEPTH 16
53 #define SN_SAL_UART_FIFO_SPEED_CPS 9600/10
55 /* we don't kmalloc/get_free_page these as we want them available
56 * before either of those are initialized */
57 static char sn_xmit_buff_mem[SN_SAL_BUFFER_SIZE];
59 struct volatile_circ_buf {
65 static struct volatile_circ_buf xmit = { .cb_buf = sn_xmit_buff_mem };
66 static char sn_tmp_buffer[SN_SAL_BUFFER_SIZE];
68 static struct tty_struct *sn_sal_tty;
70 static struct timer_list sn_sal_timer;
71 static int sn_sal_event; /* event type for task queue */
73 static int sn_sal_is_asynch;
74 static int sn_sal_irq;
75 static spinlock_t sn_sal_lock = SPIN_LOCK_UNLOCKED;
76 static int sn_total_tx_count;
77 static int sn_total_rx_count;
79 static void sn_sal_tasklet_action(unsigned long data);
80 static DECLARE_TASKLET(sn_sal_tasklet, sn_sal_tasklet_action, 0);
82 static unsigned long sn_interrupt_timeout;
84 extern u64 master_node_bedrock_address;
88 static int sn_debug_printf(const char *fmt, ...);
89 #define DPRINTF(x...) sn_debug_printf(x)
91 #define DPRINTF(x...) do { } while (0)
95 int (*sal_puts)(const char *s, int len);
96 int (*sal_getc)(void);
97 int (*sal_input_pending)(void);
98 void (*sal_wakeup_transmit)(void);
101 /* This is the pointer used. It is assigned to point to one of
104 static struct sn_sal_ops *sn_func;
107 static int snt_hw_puts(const char *, int);
108 static int snt_poll_getc(void);
109 static int snt_poll_input_pending(void);
110 static int snt_sim_puts(const char *, int);
111 static int snt_sim_getc(void);
112 static int snt_sim_input_pending(void);
113 static int snt_intr_getc(void);
114 static int snt_intr_input_pending(void);
115 static void sn_intr_transmit_chars(void);
117 /* A table for polling */
118 static struct sn_sal_ops poll_ops = {
119 .sal_puts = snt_hw_puts,
120 .sal_getc = snt_poll_getc,
121 .sal_input_pending = snt_poll_input_pending
124 /* A table for the simulator */
125 static struct sn_sal_ops sim_ops = {
126 .sal_puts = snt_sim_puts,
127 .sal_getc = snt_sim_getc,
128 .sal_input_pending = snt_sim_input_pending
131 /* A table for interrupts enabled */
132 static struct sn_sal_ops intr_ops = {
133 .sal_puts = snt_hw_puts,
134 .sal_getc = snt_intr_getc,
135 .sal_input_pending = snt_intr_input_pending,
136 .sal_wakeup_transmit = sn_intr_transmit_chars
140 /* the console does output in two distinctly different ways:
141 * synchronous and asynchronous (buffered). initally, early_printk
142 * does synchronous output. any data written goes directly to the SAL
143 * to be output (incidentally, it is internally buffered by the SAL)
144 * after interrupts and timers are initialized and available for use,
145 * the console init code switches to asynchronous output. this is
146 * also the earliest opportunity to begin polling for console input.
147 * after console initialization, console output and tty (serial port)
148 * output is buffered and sent to the SAL asynchronously (either by
149 * timer callback or by UART interrupt) */
152 /* routines for running the console in polling mode */
155 snt_hw_puts(const char *s, int len)
157 /* looking at the PROM source code, putb calls the flush
158 * routine, so if we send characters in FIFO sized chunks, it
159 * should go out by the next time the timer gets called */
160 return ia64_sn_console_putb(s, len);
167 ia64_sn_console_getc(&ch);
172 snt_poll_input_pending(void)
176 status = ia64_sn_console_check(&input);
177 return !status && input;
181 /* routines for running the console on the simulator */
184 snt_sim_puts(const char *str, int count)
188 #ifdef FLAG_DIRECT_CONSOLE_WRITES
189 /* This is an easy way to pre-pend the output to know whether the output
190 * was done via sal or directly */
191 writeb('[', master_node_bedrock_address + (UART_TX << 3));
192 writeb('+', master_node_bedrock_address + (UART_TX << 3));
193 writeb(']', master_node_bedrock_address + (UART_TX << 3));
194 writeb(' ', master_node_bedrock_address + (UART_TX << 3));
195 #endif /* FLAG_DIRECT_CONSOLE_WRITES */
196 while (counter > 0) {
197 writeb(*str, master_node_bedrock_address + (UART_TX << 3));
208 return readb(master_node_bedrock_address + (UART_RX << 3));
212 snt_sim_input_pending(void)
214 return readb(master_node_bedrock_address + (UART_LSR << 3)) & UART_LSR_DR;
218 /* routines for an interrupt driven console (normal) */
223 return ia64_sn_console_readc();
227 snt_intr_input_pending(void)
229 return ia64_sn_console_intr_status() & SAL_CONSOLE_INTR_RECV;
232 /* The early printk (possible setup) and function call */
235 early_printk_sn_sal(const char *s, unsigned count)
237 extern void early_sn_setup(void);
240 if (IS_RUNNING_ON_SIMULATOR())
247 sn_func->sal_puts(s, count);
251 /* this is as "close to the metal" as we can get, used when the driver
252 * itself may be broken */
254 sn_debug_printf(const char *fmt, ...)
256 static char printk_buf[1024];
261 printed_len = vscnprintf(printk_buf, sizeof(printk_buf), fmt, args);
262 early_printk_sn_sal(printk_buf, printed_len);
269 * Interrupt handling routines.
273 sn_sal_sched_event(int event)
275 sn_sal_event |= (1 << event);
276 tasklet_schedule(&sn_sal_tasklet);
279 /* sn_receive_chars can be called before sn_sal_tty is initialized. in
280 * that case, its only use is to trigger sysrq and kdb */
282 sn_receive_chars(struct pt_regs *regs, unsigned long *flags)
286 while (sn_func->sal_input_pending()) {
287 ch = sn_func->sal_getc();
289 printk(KERN_ERR "sn_serial: An error occured while "
290 "obtaining data from the console (0x%0x)\n", ch);
293 #if defined(CONFIG_SGI_L1_SERIAL_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
294 if (sysrq_requested) {
295 unsigned long sysrq_timeout = sysrq_requested + HZ*5;
298 if (ch && time_before(jiffies, sysrq_timeout)) {
299 spin_unlock_irqrestore(&sn_sal_lock, *flags);
300 handle_sysrq(ch, regs, NULL);
301 spin_lock_irqsave(&sn_sal_lock, *flags);
302 /* don't record this char */
306 if (ch == *sysrq_serial_ptr) {
307 if (!(*++sysrq_serial_ptr)) {
308 sysrq_requested = jiffies;
309 sysrq_serial_ptr = sysrq_serial_str;
313 sysrq_serial_ptr = sysrq_serial_str;
314 #endif /* CONFIG_SGI_L1_SERIAL_CONSOLE && CONFIG_MAGIC_SYSRQ */
316 /* record the character to pass up to the tty layer */
318 *sn_sal_tty->flip.char_buf_ptr = ch;
319 sn_sal_tty->flip.char_buf_ptr++;
320 sn_sal_tty->flip.count++;
321 if (sn_sal_tty->flip.count == TTY_FLIPBUF_SIZE)
328 tty_flip_buffer_push((struct tty_struct *)sn_sal_tty);
332 /* synch_flush_xmit must be called with sn_sal_lock */
334 synch_flush_xmit(void)
336 int xmit_count, tail, head, loops, ii;
340 if (xmit.cb_head == xmit.cb_tail)
341 return; /* Nothing to do. */
345 start = &xmit.cb_buf[tail];
347 /* twice around gets the tail to the end of the buffer and
348 * then to the head, if needed */
349 loops = (head < tail) ? 2 : 1;
351 for (ii = 0; ii < loops; ii++) {
352 xmit_count = (head < tail) ? (SN_SAL_BUFFER_SIZE - tail) : (head - tail);
354 if (xmit_count > 0) {
355 result = sn_func->sal_puts((char *)start, xmit_count);
357 DPRINTF("\n*** synch_flush_xmit failed to flush\n");
359 xmit_count -= result;
360 sn_total_tx_count += result;
362 tail &= SN_SAL_BUFFER_SIZE - 1;
364 start = (char *)&xmit.cb_buf[tail];
370 /* must be called with a lock protecting the circular buffer and
373 sn_poll_transmit_chars(void)
375 int xmit_count, tail, head;
379 BUG_ON(!sn_sal_is_asynch);
381 if (xmit.cb_head == xmit.cb_tail ||
382 (sn_sal_tty && (sn_sal_tty->stopped || sn_sal_tty->hw_stopped))) {
389 start = &xmit.cb_buf[tail];
391 xmit_count = (head < tail) ? (SN_SAL_BUFFER_SIZE - tail) : (head - tail);
394 DPRINTF("\n*** empty xmit_count\n");
396 /* use the ops, as we could be on the simulator */
397 result = sn_func->sal_puts((char *)start, xmit_count);
399 DPRINTF("\n*** error in synchronous sal_puts\n");
400 /* XXX chadt clean this up */
402 xmit_count -= result;
403 sn_total_tx_count += result;
405 tail &= SN_SAL_BUFFER_SIZE - 1;
407 start = &xmit.cb_buf[tail];
410 /* if there's few enough characters left in the xmit buffer
411 * that we could stand for the upper layer to send us some
412 * more, ask for it. */
414 if (CIRC_CNT(xmit.cb_head, xmit.cb_tail, SN_SAL_BUFFER_SIZE) < WAKEUP_CHARS)
415 sn_sal_sched_event(SN_SAL_EVENT_WRITE_WAKEUP);
419 /* must be called with a lock protecting the circular buffer and
422 sn_intr_transmit_chars(void)
424 int xmit_count, tail, head, loops, ii;
428 BUG_ON(!sn_sal_is_asynch);
430 if (xmit.cb_head == xmit.cb_tail ||
431 (sn_sal_tty && (sn_sal_tty->stopped || sn_sal_tty->hw_stopped))) {
438 start = &xmit.cb_buf[tail];
440 /* twice around gets the tail to the end of the buffer and
441 * then to the head, if needed */
442 loops = (head < tail) ? 2 : 1;
444 for (ii = 0; ii < loops; ii++) {
445 xmit_count = (head < tail) ?
446 (SN_SAL_BUFFER_SIZE - tail) : (head - tail);
448 if (xmit_count > 0) {
449 result = ia64_sn_console_xmit_chars((char *)start, xmit_count);
455 xmit_count -= result;
456 sn_total_tx_count += result;
458 tail &= SN_SAL_BUFFER_SIZE - 1;
460 start = &xmit.cb_buf[tail];
465 /* if there's few enough characters left in the xmit buffer
466 * that we could stand for the upper layer to send us some
467 * more, ask for it. */
469 if (CIRC_CNT(xmit.cb_head, xmit.cb_tail, SN_SAL_BUFFER_SIZE) < WAKEUP_CHARS)
470 sn_sal_sched_event(SN_SAL_EVENT_WRITE_WAKEUP);
475 sn_sal_interrupt(int irq, void *dev_id, struct pt_regs *regs)
477 /* this call is necessary to pass the interrupt back to the
478 * SAL, since it doesn't intercept the UART interrupts
480 int status = ia64_sn_console_intr_status();
483 spin_lock_irqsave(&sn_sal_lock, flags);
484 if (status & SAL_CONSOLE_INTR_RECV)
485 sn_receive_chars(regs, &flags);
486 if (status & SAL_CONSOLE_INTR_XMIT)
487 sn_intr_transmit_chars();
488 spin_unlock_irqrestore(&sn_sal_lock, flags);
493 /* returns the console irq if interrupt is successfully registered,
496 sn_sal_connect_interrupt(void)
499 unsigned int intr_cpuloc;
500 nasid_t console_nasid;
501 unsigned int console_irq;
504 console_nasid = ia64_sn_get_console_nasid();
505 intr_cpuid = first_cpu(node_to_cpumask(nasid_to_cnodeid(console_nasid)));
506 intr_cpuloc = cpu_physical_id(intr_cpuid);
507 console_irq = CPU_VECTOR_TO_IRQ(intr_cpuloc, SGI_UART_VECTOR);
509 result = intr_connect_level(intr_cpuid, SGI_UART_VECTOR);
510 BUG_ON(result != SGI_UART_VECTOR);
512 result = request_irq(console_irq, sn_sal_interrupt, SA_INTERRUPT, "SAL console driver", &sn_sal_tty);
516 printk(KERN_WARNING "sn_serial: console proceeding in polled mode\n");
521 sn_sal_tasklet_action(unsigned long data)
526 spin_lock_irqsave(&sn_sal_lock, flags);
528 if (test_and_clear_bit(SN_SAL_EVENT_WRITE_WAKEUP, &sn_sal_event)) {
529 if ((sn_sal_tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) && sn_sal_tty->ldisc.write_wakeup)
530 (sn_sal_tty->ldisc.write_wakeup)((struct tty_struct *)sn_sal_tty);
531 wake_up_interruptible((wait_queue_head_t *)&sn_sal_tty->write_wait);
534 spin_unlock_irqrestore(&sn_sal_lock, flags);
540 * This function handles polled mode.
543 sn_sal_timer_poll(unsigned long dummy)
548 spin_lock_irqsave(&sn_sal_lock, flags);
549 sn_receive_chars(NULL, &flags);
550 sn_poll_transmit_chars();
551 spin_unlock_irqrestore(&sn_sal_lock, flags);
552 mod_timer(&sn_sal_timer, jiffies + sn_interrupt_timeout);
558 * User-level console routines
562 sn_sal_open(struct tty_struct *tty, struct file *filp)
566 DPRINTF("sn_sal_open: sn_sal_tty = %p, tty = %p, filp = %p\n",
567 sn_sal_tty, tty, filp);
569 spin_lock_irqsave(&sn_sal_lock, flags);
572 spin_unlock_irqrestore(&sn_sal_lock, flags);
578 /* We're keeping all our resources. We're keeping interrupts turned
579 * on. Maybe just let the tty layer finish its stuff...? GMSH
582 sn_sal_close(struct tty_struct *tty, struct file * filp)
584 if (tty->count == 1) {
587 if (tty->driver->flush_buffer)
588 tty->driver->flush_buffer(tty);
589 if (tty->ldisc.flush_buffer)
590 tty->ldisc.flush_buffer(tty);
592 spin_lock_irqsave(&sn_sal_lock, flags);
594 spin_unlock_irqrestore(&sn_sal_lock, flags);
600 sn_sal_write(struct tty_struct *tty, int from_user,
601 const unsigned char *buf, int count)
609 c = CIRC_SPACE_TO_END(xmit.cb_head, xmit.cb_tail,
617 c -= copy_from_user(sn_tmp_buffer, buf, c);
624 /* Turn off interrupts and see if the xmit buffer has
625 * moved since the last time we looked.
627 spin_lock_irqsave(&sn_sal_lock, flags);
628 c1 = CIRC_SPACE_TO_END(xmit.cb_head, xmit.cb_tail, SN_SAL_BUFFER_SIZE);
633 memcpy(xmit.cb_buf + xmit.cb_head, sn_tmp_buffer, c);
634 xmit.cb_head = ((xmit.cb_head + c) & (SN_SAL_BUFFER_SIZE - 1));
635 spin_unlock_irqrestore(&sn_sal_lock, flags);
643 /* The buffer passed in isn't coming from userland,
644 * so cut out the middleman (sn_tmp_buffer).
646 spin_lock_irqsave(&sn_sal_lock, flags);
648 c = CIRC_SPACE_TO_END(xmit.cb_head, xmit.cb_tail, SN_SAL_BUFFER_SIZE);
655 memcpy(xmit.cb_buf + xmit.cb_head, buf, c);
656 xmit.cb_head = ((xmit.cb_head + c) & (SN_SAL_BUFFER_SIZE - 1));
661 spin_unlock_irqrestore(&sn_sal_lock, flags);
664 spin_lock_irqsave(&sn_sal_lock, flags);
665 if (xmit.cb_head != xmit.cb_tail && !(tty && (tty->stopped || tty->hw_stopped)))
666 if (sn_func->sal_wakeup_transmit)
667 sn_func->sal_wakeup_transmit();
668 spin_unlock_irqrestore(&sn_sal_lock, flags);
675 sn_sal_put_char(struct tty_struct *tty, unsigned char ch)
679 spin_lock_irqsave(&sn_sal_lock, flags);
680 if (CIRC_SPACE(xmit.cb_head, xmit.cb_tail, SN_SAL_BUFFER_SIZE) != 0) {
681 xmit.cb_buf[xmit.cb_head] = ch;
682 xmit.cb_head = (xmit.cb_head + 1) & (SN_SAL_BUFFER_SIZE-1);
683 if ( sn_func->sal_wakeup_transmit )
684 sn_func->sal_wakeup_transmit();
686 spin_unlock_irqrestore(&sn_sal_lock, flags);
691 sn_sal_flush_chars(struct tty_struct *tty)
695 spin_lock_irqsave(&sn_sal_lock, flags);
696 if (CIRC_CNT(xmit.cb_head, xmit.cb_tail, SN_SAL_BUFFER_SIZE))
697 if (sn_func->sal_wakeup_transmit)
698 sn_func->sal_wakeup_transmit();
699 spin_unlock_irqrestore(&sn_sal_lock, flags);
704 sn_sal_write_room(struct tty_struct *tty)
709 spin_lock_irqsave(&sn_sal_lock, flags);
710 space = CIRC_SPACE(xmit.cb_head, xmit.cb_tail, SN_SAL_BUFFER_SIZE);
711 spin_unlock_irqrestore(&sn_sal_lock, flags);
717 sn_sal_chars_in_buffer(struct tty_struct *tty)
722 spin_lock_irqsave(&sn_sal_lock, flags);
723 space = CIRC_CNT(xmit.cb_head, xmit.cb_tail, SN_SAL_BUFFER_SIZE);
724 DPRINTF("<%d>", space);
725 spin_unlock_irqrestore(&sn_sal_lock, flags);
731 sn_sal_flush_buffer(struct tty_struct *tty)
735 /* drop everything */
736 spin_lock_irqsave(&sn_sal_lock, flags);
737 xmit.cb_head = xmit.cb_tail = 0;
738 spin_unlock_irqrestore(&sn_sal_lock, flags);
740 /* wake up tty level */
741 wake_up_interruptible(&tty->write_wait);
742 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) && tty->ldisc.write_wakeup)
743 (tty->ldisc.write_wakeup)(tty);
748 sn_sal_hangup(struct tty_struct *tty)
750 sn_sal_flush_buffer(tty);
755 sn_sal_wait_until_sent(struct tty_struct *tty, int timeout)
757 /* this is SAL's problem */
758 DPRINTF("<sn_serial: should wait until sent>");
765 * Console /proc interface
769 sn_sal_read_proc(char *page, char **start, off_t off, int count,
770 int *eof, void *data)
775 len += sprintf(page, "sn_serial: nasid:%ld irq:%d tx:%d rx:%d\n",
776 ia64_sn_get_console_nasid(), sn_sal_irq,
777 sn_total_tx_count, sn_total_rx_count);
780 if (off >= len+begin)
782 *start = page + (off-begin);
784 return count < begin+len-off ? count : begin+len-off;
788 static struct tty_operations sn_sal_driver_ops = {
790 .close = sn_sal_close,
791 .write = sn_sal_write,
792 .put_char = sn_sal_put_char,
793 .flush_chars = sn_sal_flush_chars,
794 .write_room = sn_sal_write_room,
795 .chars_in_buffer = sn_sal_chars_in_buffer,
796 .hangup = sn_sal_hangup,
797 .wait_until_sent = sn_sal_wait_until_sent,
798 .read_proc = sn_sal_read_proc,
800 static struct tty_driver *sn_sal_driver;
802 /* sn_sal_init wishlist:
803 * - allocate sn_tmp_buffer
804 * - fix up the tty_driver struct
805 * - turn on receive interrupts
806 * - do any termios twiddling once and for all
810 * Boot-time initialization code
814 sn_sal_switch_to_asynch(void)
818 /* without early_printk, we may be invoked late enough to race
819 * with other cpus doing console IO at this point, however
820 * console interrupts will never be enabled */
821 spin_lock_irqsave(&sn_sal_lock, flags);
823 if (sn_sal_is_asynch) {
824 spin_unlock_irqrestore(&sn_sal_lock, flags);
828 DPRINTF("sn_serial: switch to asynchronous console\n");
830 /* early_printk invocation may have done this for us */
832 if (IS_RUNNING_ON_SIMULATOR())
838 /* we can't turn on the console interrupt (as request_irq
839 * calls kmalloc, which isn't set up yet), so we rely on a
840 * timer to poll for input and push data from the console
843 init_timer(&sn_sal_timer);
844 sn_sal_timer.function = sn_sal_timer_poll;
846 if (IS_RUNNING_ON_SIMULATOR())
847 sn_interrupt_timeout = 6;
849 /* 960cps / 16 char FIFO = 60HZ
850 * HZ / (SN_SAL_FIFO_SPEED_CPS / SN_SAL_FIFO_DEPTH) */
851 sn_interrupt_timeout = HZ * SN_SAL_UART_FIFO_DEPTH / SN_SAL_UART_FIFO_SPEED_CPS;
853 mod_timer(&sn_sal_timer, jiffies + sn_interrupt_timeout);
855 sn_sal_is_asynch = 1;
856 spin_unlock_irqrestore(&sn_sal_lock, flags);
860 sn_sal_switch_to_interrupts(void)
864 DPRINTF("sn_serial: switching to interrupt driven console\n");
866 irq = sn_sal_connect_interrupt();
869 spin_lock_irqsave(&sn_sal_lock, flags);
871 /* sn_sal_irq is a global variable. When it's set to
872 * a non-zero value, we stop polling for input (since
873 * interrupts should now be enabled). */
877 /* turn on receive interrupts */
878 ia64_sn_console_intr_enable(SAL_CONSOLE_INTR_RECV);
879 spin_unlock_irqrestore(&sn_sal_lock, flags);
884 sn_sal_module_init(void)
888 DPRINTF("sn_serial: sn_sal_module_init\n");
890 if (!ia64_platform_is("sn2"))
893 sn_sal_driver = alloc_tty_driver(1);
894 if ( !sn_sal_driver )
897 sn_sal_driver->owner = THIS_MODULE;
898 sn_sal_driver->driver_name = "sn_serial";
899 sn_sal_driver->name = "ttyS";
900 sn_sal_driver->major = TTY_MAJOR;
901 sn_sal_driver->minor_start = SN_SAL_MINOR;
902 sn_sal_driver->type = TTY_DRIVER_TYPE_SERIAL;
903 sn_sal_driver->subtype = SERIAL_TYPE_NORMAL;
904 sn_sal_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_NO_DEVFS;
906 tty_set_operations(sn_sal_driver, &sn_sal_driver_ops);
908 /* when this driver is compiled in, the console initialization
909 * will have already switched us into asynchronous operation
910 * before we get here through the module initcalls */
911 sn_sal_switch_to_asynch();
913 /* at this point (module_init) we can try to turn on interrupts */
914 if (!IS_RUNNING_ON_SIMULATOR())
915 sn_sal_switch_to_interrupts();
917 sn_sal_driver->init_termios = tty_std_termios;
918 sn_sal_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
920 if ((retval = tty_register_driver(sn_sal_driver))) {
921 printk(KERN_ERR "sn_serial: Unable to register tty driver\n");
929 sn_sal_module_exit(void)
931 del_timer_sync(&sn_sal_timer);
932 tty_unregister_driver(sn_sal_driver);
933 put_tty_driver(sn_sal_driver);
936 module_init(sn_sal_module_init);
937 module_exit(sn_sal_module_exit);
940 * Kernel console definitions
943 #ifdef CONFIG_SGI_L1_SERIAL_CONSOLE
945 * Print a string to the SAL console. The console_lock must be held
949 sn_sal_console_write(struct console *co, const char *s, unsigned count)
954 BUG_ON(!sn_sal_is_asynch);
956 /* somebody really wants this output, might be an
957 * oops, kdb, panic, etc. make sure they get it. */
958 if (spin_is_locked(&sn_sal_lock)) {
960 /* Output '\r' before each '\n' */
961 while ((s1 = memchr(s, '\n', count)) != NULL) {
962 sn_func->sal_puts(s, s1 - s);
963 sn_func->sal_puts("\r\n", 2);
967 sn_func->sal_puts(s, count);
969 else if (in_interrupt()) {
970 spin_lock_irqsave(&sn_sal_lock, flags);
972 spin_unlock_irqrestore(&sn_sal_lock, flags);
973 /* Output '\r' before each '\n' */
974 while ((s1 = memchr(s, '\n', count)) != NULL) {
975 sn_func->sal_puts(s, s1 - s);
976 sn_func->sal_puts("\r\n", 2);
980 sn_func->sal_puts(s, count);
983 /* Output '\r' before each '\n' */
984 while ((s1 = memchr(s, '\n', count)) != NULL) {
985 sn_sal_write(NULL, 0, s, s1 - s);
986 sn_sal_write(NULL, 0, "\r\n", 2);
990 sn_sal_write(NULL, 0, s, count);
994 static struct tty_driver *
995 sn_sal_console_device(struct console *c, int *index)
998 return sn_sal_driver;
1002 sn_sal_console_setup(struct console *co, char *options)
1008 static struct console sal_console = {
1010 .write = sn_sal_console_write,
1011 .device = sn_sal_console_device,
1012 .setup = sn_sal_console_setup,
1017 sn_sal_serial_console_init(void)
1019 if (ia64_platform_is("sn2")) {
1020 sn_sal_switch_to_asynch();
1021 DPRINTF("sn_sal_serial_console_init : register console\n");
1022 register_console(&sal_console);
1026 console_initcall(sn_sal_serial_console_init);
1028 #endif /* CONFIG_SGI_L1_SERIAL_CONSOLE */