Linux Audio

Check our new training course

Loading...
v4.17
   1/*
   2 * C-Brick Serial Port (and console) driver for SGI Altix machines.
   3 *
   4 * This driver is NOT suitable for talking to the l1-controller for
   5 * anything other than 'console activities' --- please use the l1
   6 * driver for that.
   7 *
   8 *
   9 * Copyright (c) 2004-2006 Silicon Graphics, Inc.  All Rights Reserved.
  10 *
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  11 * Contact information:  Silicon Graphics, Inc., 1500 Crittenden Lane,
  12 * Mountain View, CA  94043, or:
  13 *
  14 * http://www.sgi.com
  15 *
  16 * For further information regarding this notice, see:
  17 *
  18 * http://oss.sgi.com/projects/GenInfo/NoticeExplan
  19 */
  20
  21#include <linux/interrupt.h>
  22#include <linux/tty.h>
  23#include <linux/tty_flip.h>
  24#include <linux/serial.h>
  25#include <linux/console.h>
  26#include <linux/init.h>
  27#include <linux/sysrq.h>
  28#include <linux/circ_buf.h>
  29#include <linux/serial_reg.h>
  30#include <linux/delay.h> /* for mdelay */
  31#include <linux/miscdevice.h>
  32#include <linux/serial_core.h>
  33
  34#include <asm/io.h>
  35#include <asm/sn/simulator.h>
  36#include <asm/sn/sn_sal.h>
  37
  38/* number of characters we can transmit to the SAL console at a time */
  39#define SN_SAL_MAX_CHARS 120
  40
  41/* 64K, when we're asynch, it must be at least printk's LOG_BUF_LEN to
  42 * avoid losing chars, (always has to be a power of 2) */
  43#define SN_SAL_BUFFER_SIZE (64 * (1 << 10))
  44
  45#define SN_SAL_UART_FIFO_DEPTH 16
  46#define SN_SAL_UART_FIFO_SPEED_CPS (9600/10)
  47
  48/* sn_transmit_chars() calling args */
  49#define TRANSMIT_BUFFERED	0
  50#define TRANSMIT_RAW		1
  51
  52/* To use dynamic numbers only and not use the assigned major and minor,
  53 * define the following.. */
  54				  /* #define USE_DYNAMIC_MINOR 1 *//* use dynamic minor number */
  55#define USE_DYNAMIC_MINOR 0	/* Don't rely on misc_register dynamic minor */
  56
  57/* Device name we're using */
  58#define DEVICE_NAME "ttySG"
  59#define DEVICE_NAME_DYNAMIC "ttySG0"	/* need full name for misc_register */
  60/* The major/minor we are using, ignored for USE_DYNAMIC_MINOR */
  61#define DEVICE_MAJOR 204
  62#define DEVICE_MINOR 40
  63
  64#ifdef CONFIG_MAGIC_SYSRQ
  65static char sysrq_serial_str[] = "\eSYS";
  66static char *sysrq_serial_ptr = sysrq_serial_str;
  67static unsigned long sysrq_requested;
  68#endif /* CONFIG_MAGIC_SYSRQ */
  69
  70/*
  71 * Port definition - this kinda drives it all
  72 */
  73struct sn_cons_port {
  74	struct timer_list sc_timer;
  75	struct uart_port sc_port;
  76	struct sn_sal_ops {
  77		int (*sal_puts_raw) (const char *s, int len);
  78		int (*sal_puts) (const char *s, int len);
  79		int (*sal_getc) (void);
  80		int (*sal_input_pending) (void);
  81		void (*sal_wakeup_transmit) (struct sn_cons_port *, int);
  82	} *sc_ops;
  83	unsigned long sc_interrupt_timeout;
  84	int sc_is_asynch;
  85};
  86
  87static struct sn_cons_port sal_console_port;
  88static int sn_process_input;
  89
  90/* Only used if USE_DYNAMIC_MINOR is set to 1 */
  91static struct miscdevice misc;	/* used with misc_register for dynamic */
  92
  93extern void early_sn_setup(void);
  94
  95#undef DEBUG
  96#ifdef DEBUG
  97static int sn_debug_printf(const char *fmt, ...);
  98#define DPRINTF(x...) sn_debug_printf(x)
  99#else
 100#define DPRINTF(x...) do { } while (0)
 101#endif
 102
 103/* Prototypes */
 104static int snt_hw_puts_raw(const char *, int);
 105static int snt_hw_puts_buffered(const char *, int);
 106static int snt_poll_getc(void);
 107static int snt_poll_input_pending(void);
 108static int snt_intr_getc(void);
 109static int snt_intr_input_pending(void);
 110static void sn_transmit_chars(struct sn_cons_port *, int);
 111
 112/* A table for polling:
 113 */
 114static struct sn_sal_ops poll_ops = {
 115	.sal_puts_raw = snt_hw_puts_raw,
 116	.sal_puts = snt_hw_puts_raw,
 117	.sal_getc = snt_poll_getc,
 118	.sal_input_pending = snt_poll_input_pending
 119};
 120
 121/* A table for interrupts enabled */
 122static struct sn_sal_ops intr_ops = {
 123	.sal_puts_raw = snt_hw_puts_raw,
 124	.sal_puts = snt_hw_puts_buffered,
 125	.sal_getc = snt_intr_getc,
 126	.sal_input_pending = snt_intr_input_pending,
 127	.sal_wakeup_transmit = sn_transmit_chars
 128};
 129
 130/* the console does output in two distinctly different ways:
 131 * synchronous (raw) and asynchronous (buffered).  initially, early_printk
 132 * does synchronous output.  any data written goes directly to the SAL
 133 * to be output (incidentally, it is internally buffered by the SAL)
 134 * after interrupts and timers are initialized and available for use,
 135 * the console init code switches to asynchronous output.  this is
 136 * also the earliest opportunity to begin polling for console input.
 137 * after console initialization, console output and tty (serial port)
 138 * output is buffered and sent to the SAL asynchronously (either by
 139 * timer callback or by UART interrupt) */
 140
 141/* routines for running the console in polling mode */
 142
 143/**
 144 * snt_poll_getc - Get a character from the console in polling mode
 145 *
 146 */
 147static int snt_poll_getc(void)
 148{
 149	int ch;
 150
 151	ia64_sn_console_getc(&ch);
 152	return ch;
 153}
 154
 155/**
 156 * snt_poll_input_pending - Check if any input is waiting - polling mode.
 157 *
 158 */
 159static int snt_poll_input_pending(void)
 160{
 161	int status, input;
 162
 163	status = ia64_sn_console_check(&input);
 164	return !status && input;
 165}
 166
 167/* routines for an interrupt driven console (normal) */
 168
 169/**
 170 * snt_intr_getc - Get a character from the console, interrupt mode
 171 *
 172 */
 173static int snt_intr_getc(void)
 174{
 175	return ia64_sn_console_readc();
 176}
 177
 178/**
 179 * snt_intr_input_pending - Check if input is pending, interrupt mode
 180 *
 181 */
 182static int snt_intr_input_pending(void)
 183{
 184	return ia64_sn_console_intr_status() & SAL_CONSOLE_INTR_RECV;
 185}
 186
 187/* these functions are polled and interrupt */
 188
 189/**
 190 * snt_hw_puts_raw - Send raw string to the console, polled or interrupt mode
 191 * @s: String
 192 * @len: Length
 193 *
 194 */
 195static int snt_hw_puts_raw(const char *s, int len)
 196{
 197	/* this will call the PROM and not return until this is done */
 198	return ia64_sn_console_putb(s, len);
 199}
 200
 201/**
 202 * snt_hw_puts_buffered - Send string to console, polled or interrupt mode
 203 * @s: String
 204 * @len: Length
 205 *
 206 */
 207static int snt_hw_puts_buffered(const char *s, int len)
 208{
 209	/* queue data to the PROM */
 210	return ia64_sn_console_xmit_chars((char *)s, len);
 211}
 212
 213/* uart interface structs
 214 * These functions are associated with the uart_port that the serial core
 215 * infrastructure calls.
 216 *
 217 * Note: Due to how the console works, many routines are no-ops.
 218 */
 219
 220/**
 221 * snp_type - What type of console are we?
 222 * @port: Port to operate with (we ignore since we only have one port)
 223 *
 224 */
 225static const char *snp_type(struct uart_port *port)
 226{
 227	return ("SGI SN L1");
 228}
 229
 230/**
 231 * snp_tx_empty - Is the transmitter empty?  We pretend we're always empty
 232 * @port: Port to operate on (we ignore since we only have one port)
 233 *
 234 */
 235static unsigned int snp_tx_empty(struct uart_port *port)
 236{
 237	return 1;
 238}
 239
 240/**
 241 * snp_stop_tx - stop the transmitter - no-op for us
 242 * @port: Port to operat eon - we ignore - no-op function
 243 *
 244 */
 245static void snp_stop_tx(struct uart_port *port)
 246{
 247}
 248
 249/**
 250 * snp_release_port - Free i/o and resources for port - no-op for us
 251 * @port: Port to operate on - we ignore - no-op function
 252 *
 253 */
 254static void snp_release_port(struct uart_port *port)
 255{
 256}
 257
 258/**
 
 
 
 
 
 
 
 
 
 259 * snp_shutdown - shut down the port - free irq and disable - no-op for us
 260 * @port: Port to shut down - we ignore
 261 *
 262 */
 263static void snp_shutdown(struct uart_port *port)
 264{
 265}
 266
 267/**
 268 * snp_set_mctrl - set control lines (dtr, rts, etc) - no-op for our console
 269 * @port: Port to operate on - we ignore
 270 * @mctrl: Lines to set/unset - we ignore
 271 *
 272 */
 273static void snp_set_mctrl(struct uart_port *port, unsigned int mctrl)
 274{
 275}
 276
 277/**
 278 * snp_get_mctrl - get contorl line info, we just return a static value
 279 * @port: port to operate on - we only have one port so we ignore this
 280 *
 281 */
 282static unsigned int snp_get_mctrl(struct uart_port *port)
 283{
 284	return TIOCM_CAR | TIOCM_RNG | TIOCM_DSR | TIOCM_CTS;
 285}
 286
 287/**
 288 * snp_stop_rx - Stop the receiver - we ignor ethis
 289 * @port: Port to operate on - we ignore
 290 *
 291 */
 292static void snp_stop_rx(struct uart_port *port)
 293{
 294}
 295
 296/**
 297 * snp_start_tx - Start transmitter
 298 * @port: Port to operate on
 299 *
 300 */
 301static void snp_start_tx(struct uart_port *port)
 302{
 303	if (sal_console_port.sc_ops->sal_wakeup_transmit)
 304		sal_console_port.sc_ops->sal_wakeup_transmit(&sal_console_port,
 305							     TRANSMIT_BUFFERED);
 306
 307}
 308
 309/**
 310 * snp_break_ctl - handle breaks - ignored by us
 311 * @port: Port to operate on
 312 * @break_state: Break state
 313 *
 314 */
 315static void snp_break_ctl(struct uart_port *port, int break_state)
 316{
 317}
 318
 319/**
 320 * snp_startup - Start up the serial port - always return 0 (We're always on)
 321 * @port: Port to operate on
 322 *
 323 */
 324static int snp_startup(struct uart_port *port)
 325{
 326	return 0;
 327}
 328
 329/**
 330 * snp_set_termios - set termios stuff - we ignore these
 331 * @port: port to operate on
 332 * @termios: New settings
 333 * @termios: Old
 334 *
 335 */
 336static void
 337snp_set_termios(struct uart_port *port, struct ktermios *termios,
 338		struct ktermios *old)
 339{
 340}
 341
 342/**
 343 * snp_request_port - allocate resources for port - ignored by us
 344 * @port: port to operate on
 345 *
 346 */
 347static int snp_request_port(struct uart_port *port)
 348{
 349	return 0;
 350}
 351
 352/**
 353 * snp_config_port - allocate resources, set up - we ignore,  we're always on
 354 * @port: Port to operate on
 355 * @flags: flags used for port setup
 356 *
 357 */
 358static void snp_config_port(struct uart_port *port, int flags)
 359{
 360}
 361
 362/* Associate the uart functions above - given to serial core */
 363
 364static const struct uart_ops sn_console_ops = {
 365	.tx_empty = snp_tx_empty,
 366	.set_mctrl = snp_set_mctrl,
 367	.get_mctrl = snp_get_mctrl,
 368	.stop_tx = snp_stop_tx,
 369	.start_tx = snp_start_tx,
 370	.stop_rx = snp_stop_rx,
 
 371	.break_ctl = snp_break_ctl,
 372	.startup = snp_startup,
 373	.shutdown = snp_shutdown,
 374	.set_termios = snp_set_termios,
 375	.pm = NULL,
 376	.type = snp_type,
 377	.release_port = snp_release_port,
 378	.request_port = snp_request_port,
 379	.config_port = snp_config_port,
 380	.verify_port = NULL,
 381};
 382
 383/* End of uart struct functions and defines */
 384
 385#ifdef DEBUG
 386
 387/**
 388 * sn_debug_printf - close to hardware debugging printf
 389 * @fmt: printf format
 390 *
 391 * This is as "close to the metal" as we can get, used when the driver
 392 * itself may be broken.
 393 *
 394 */
 395static int sn_debug_printf(const char *fmt, ...)
 396{
 397	static char printk_buf[1024];
 398	int printed_len;
 399	va_list args;
 400
 401	va_start(args, fmt);
 402	printed_len = vsnprintf(printk_buf, sizeof(printk_buf), fmt, args);
 403
 404	if (!sal_console_port.sc_ops) {
 405		sal_console_port.sc_ops = &poll_ops;
 406		early_sn_setup();
 407	}
 408	sal_console_port.sc_ops->sal_puts_raw(printk_buf, printed_len);
 409
 410	va_end(args);
 411	return printed_len;
 412}
 413#endif				/* DEBUG */
 414
 415/*
 416 * Interrupt handling routines.
 417 */
 418
 419/**
 420 * sn_receive_chars - Grab characters, pass them to tty layer
 421 * @port: Port to operate on
 422 * @flags: irq flags
 423 *
 424 * Note: If we're not registered with the serial core infrastructure yet,
 425 * we don't try to send characters to it...
 426 *
 427 */
 428static void
 429sn_receive_chars(struct sn_cons_port *port, unsigned long flags)
 430{
 431	struct tty_port *tport = NULL;
 432	int ch;
 
 433
 434	if (!port) {
 435		printk(KERN_ERR "sn_receive_chars - port NULL so can't receive\n");
 436		return;
 437	}
 438
 439	if (!port->sc_ops) {
 440		printk(KERN_ERR "sn_receive_chars - port->sc_ops  NULL so can't receive\n");
 441		return;
 442	}
 443
 444	if (port->sc_port.state) {
 445		/* The serial_core stuffs are initialized, use them */
 446		tport = &port->sc_port.state->port;
 
 
 
 
 447	}
 448
 449	while (port->sc_ops->sal_input_pending()) {
 450		ch = port->sc_ops->sal_getc();
 451		if (ch < 0) {
 452			printk(KERN_ERR "sn_console: An error occurred while "
 453			       "obtaining data from the console (0x%0x)\n", ch);
 454			break;
 455		}
 456#ifdef CONFIG_MAGIC_SYSRQ
 457                if (sysrq_requested) {
 458                        unsigned long sysrq_timeout = sysrq_requested + HZ*5;
 459
 460                        sysrq_requested = 0;
 461                        if (ch && time_before(jiffies, sysrq_timeout)) {
 462                                spin_unlock_irqrestore(&port->sc_port.lock, flags);
 463                                handle_sysrq(ch);
 464                                spin_lock_irqsave(&port->sc_port.lock, flags);
 465                                /* ignore actual sysrq command char */
 466                                continue;
 467                        }
 468                }
 469                if (ch == *sysrq_serial_ptr) {
 470                        if (!(*++sysrq_serial_ptr)) {
 471                                sysrq_requested = jiffies;
 472                                sysrq_serial_ptr = sysrq_serial_str;
 473                        }
 474			/*
 475			 * ignore the whole sysrq string except for the
 476			 * leading escape
 477			 */
 478			if (ch != '\e')
 479				continue;
 480                }
 481                else
 482			sysrq_serial_ptr = sysrq_serial_str;
 483#endif /* CONFIG_MAGIC_SYSRQ */
 484
 485		/* record the character to pass up to the tty layer */
 486		if (tport) {
 487			if (tty_insert_flip_char(tport, ch, TTY_NORMAL) == 0)
 488				break;
 489		}
 490		port->sc_port.icount.rx++;
 491	}
 492
 493	if (tport)
 494		tty_flip_buffer_push(tport);
 495}
 496
 497/**
 498 * sn_transmit_chars - grab characters from serial core, send off
 499 * @port: Port to operate on
 500 * @raw: Transmit raw or buffered
 501 *
 502 * Note: If we're early, before we're registered with serial core, the
 503 * writes are going through sn_sal_console_write because that's how
 504 * register_console has been set up.  We currently could have asynch
 505 * polls calling this function due to sn_sal_switch_to_asynch but we can
 506 * ignore them until we register with the serial core stuffs.
 507 *
 508 */
 509static void sn_transmit_chars(struct sn_cons_port *port, int raw)
 510{
 511	int xmit_count, tail, head, loops, ii;
 512	int result;
 513	char *start;
 514	struct circ_buf *xmit;
 515
 516	if (!port)
 517		return;
 518
 519	BUG_ON(!port->sc_is_asynch);
 520
 521	if (port->sc_port.state) {
 522		/* We're initialized, using serial core infrastructure */
 523		xmit = &port->sc_port.state->xmit;
 524	} else {
 525		/* Probably sn_sal_switch_to_asynch has been run but serial core isn't
 526		 * initialized yet.  Just return.  Writes are going through
 527		 * sn_sal_console_write (due to register_console) at this time.
 528		 */
 529		return;
 530	}
 531
 532	if (uart_circ_empty(xmit) || uart_tx_stopped(&port->sc_port)) {
 533		/* Nothing to do. */
 534		ia64_sn_console_intr_disable(SAL_CONSOLE_INTR_XMIT);
 535		return;
 536	}
 537
 538	head = xmit->head;
 539	tail = xmit->tail;
 540	start = &xmit->buf[tail];
 541
 542	/* twice around gets the tail to the end of the buffer and
 543	 * then to the head, if needed */
 544	loops = (head < tail) ? 2 : 1;
 545
 546	for (ii = 0; ii < loops; ii++) {
 547		xmit_count = (head < tail) ?
 548		    (UART_XMIT_SIZE - tail) : (head - tail);
 549
 550		if (xmit_count > 0) {
 551			if (raw == TRANSMIT_RAW)
 552				result =
 553				    port->sc_ops->sal_puts_raw(start,
 554							       xmit_count);
 555			else
 556				result =
 557				    port->sc_ops->sal_puts(start, xmit_count);
 558#ifdef DEBUG
 559			if (!result)
 560				DPRINTF("`");
 561#endif
 562			if (result > 0) {
 563				xmit_count -= result;
 564				port->sc_port.icount.tx += result;
 565				tail += result;
 566				tail &= UART_XMIT_SIZE - 1;
 567				xmit->tail = tail;
 568				start = &xmit->buf[tail];
 569			}
 570		}
 571	}
 572
 573	if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
 574		uart_write_wakeup(&port->sc_port);
 575
 576	if (uart_circ_empty(xmit))
 577		snp_stop_tx(&port->sc_port);	/* no-op for us */
 578}
 579
 580/**
 581 * sn_sal_interrupt - Handle console interrupts
 582 * @irq: irq #, useful for debug statements
 583 * @dev_id: our pointer to our port (sn_cons_port which contains the uart port)
 584 *
 585 */
 586static irqreturn_t sn_sal_interrupt(int irq, void *dev_id)
 587{
 588	struct sn_cons_port *port = (struct sn_cons_port *)dev_id;
 589	unsigned long flags;
 590	int status = ia64_sn_console_intr_status();
 591
 592	if (!port)
 593		return IRQ_NONE;
 594
 595	spin_lock_irqsave(&port->sc_port.lock, flags);
 596	if (status & SAL_CONSOLE_INTR_RECV) {
 597		sn_receive_chars(port, flags);
 598	}
 599	if (status & SAL_CONSOLE_INTR_XMIT) {
 600		sn_transmit_chars(port, TRANSMIT_BUFFERED);
 601	}
 602	spin_unlock_irqrestore(&port->sc_port.lock, flags);
 603	return IRQ_HANDLED;
 604}
 605
 606/**
 607 * sn_sal_timer_poll - this function handles polled console mode
 608 * @data: A pointer to our sn_cons_port (which contains the uart port)
 609 *
 610 * data is the pointer that init_timer will store for us.  This function is
 611 * associated with init_timer to see if there is any console traffic.
 612 * Obviously not used in interrupt mode
 613 *
 614 */
 615static void sn_sal_timer_poll(struct timer_list *t)
 616{
 617	struct sn_cons_port *port = from_timer(port, t, sc_timer);
 618	unsigned long flags;
 619
 620	if (!port)
 621		return;
 622
 623	if (!port->sc_port.irq) {
 624		spin_lock_irqsave(&port->sc_port.lock, flags);
 625		if (sn_process_input)
 626			sn_receive_chars(port, flags);
 627		sn_transmit_chars(port, TRANSMIT_RAW);
 628		spin_unlock_irqrestore(&port->sc_port.lock, flags);
 629		mod_timer(&port->sc_timer,
 630			  jiffies + port->sc_interrupt_timeout);
 631	}
 632}
 633
 634/*
 635 * Boot-time initialization code
 636 */
 637
 638/**
 639 * sn_sal_switch_to_asynch - Switch to async mode (as opposed to synch)
 640 * @port: Our sn_cons_port (which contains the uart port)
 641 *
 642 * So this is used by sn_sal_serial_console_init (early on, before we're
 643 * registered with serial core).  It's also used by sn_sal_init
 644 * right after we've registered with serial core.  The later only happens
 645 * if we didn't already come through here via sn_sal_serial_console_init.
 646 *
 647 */
 648static void __init sn_sal_switch_to_asynch(struct sn_cons_port *port)
 649{
 650	unsigned long flags;
 651
 652	if (!port)
 653		return;
 654
 655	DPRINTF("sn_console: about to switch to asynchronous console\n");
 656
 657	/* without early_printk, we may be invoked late enough to race
 658	 * with other cpus doing console IO at this point, however
 659	 * console interrupts will never be enabled */
 660	spin_lock_irqsave(&port->sc_port.lock, flags);
 661
 662	/* early_printk invocation may have done this for us */
 663	if (!port->sc_ops)
 664		port->sc_ops = &poll_ops;
 665
 666	/* we can't turn on the console interrupt (as request_irq
 667	 * calls kmalloc, which isn't set up yet), so we rely on a
 668	 * timer to poll for input and push data from the console
 669	 * buffer.
 670	 */
 671	timer_setup(&port->sc_timer, sn_sal_timer_poll, 0);
 
 
 672
 673	if (IS_RUNNING_ON_SIMULATOR())
 674		port->sc_interrupt_timeout = 6;
 675	else {
 676		/* 960cps / 16 char FIFO = 60HZ
 677		 * HZ / (SN_SAL_FIFO_SPEED_CPS / SN_SAL_FIFO_DEPTH) */
 678		port->sc_interrupt_timeout =
 679		    HZ * SN_SAL_UART_FIFO_DEPTH / SN_SAL_UART_FIFO_SPEED_CPS;
 680	}
 681	mod_timer(&port->sc_timer, jiffies + port->sc_interrupt_timeout);
 682
 683	port->sc_is_asynch = 1;
 684	spin_unlock_irqrestore(&port->sc_port.lock, flags);
 685}
 686
 687/**
 688 * sn_sal_switch_to_interrupts - Switch to interrupt driven mode
 689 * @port: Our sn_cons_port (which contains the uart port)
 690 *
 691 * In sn_sal_init, after we're registered with serial core and
 692 * the port is added, this function is called to switch us to interrupt
 693 * mode.  We were previously in asynch/polling mode (using init_timer).
 694 *
 695 * We attempt to switch to interrupt mode here by calling
 696 * request_irq.  If that works out, we enable receive interrupts.
 697 */
 698static void __init sn_sal_switch_to_interrupts(struct sn_cons_port *port)
 699{
 700	unsigned long flags;
 701
 702	if (port) {
 703		DPRINTF("sn_console: switching to interrupt driven console\n");
 704
 705		if (request_irq(SGI_UART_VECTOR, sn_sal_interrupt,
 706				IRQF_SHARED,
 707				"SAL console driver", port) >= 0) {
 708			spin_lock_irqsave(&port->sc_port.lock, flags);
 709			port->sc_port.irq = SGI_UART_VECTOR;
 710			port->sc_ops = &intr_ops;
 711			irq_set_handler(port->sc_port.irq, handle_level_irq);
 712
 713			/* turn on receive interrupts */
 714			ia64_sn_console_intr_enable(SAL_CONSOLE_INTR_RECV);
 715			spin_unlock_irqrestore(&port->sc_port.lock, flags);
 716		}
 717		else {
 718			printk(KERN_INFO
 719			    "sn_console: console proceeding in polled mode\n");
 720		}
 721	}
 722}
 723
 724/*
 725 * Kernel console definitions
 726 */
 727
 728static void sn_sal_console_write(struct console *, const char *, unsigned);
 729static int sn_sal_console_setup(struct console *, char *);
 730static struct uart_driver sal_console_uart;
 731extern struct tty_driver *uart_console_device(struct console *, int *);
 732
 733static struct console sal_console = {
 734	.name = DEVICE_NAME,
 735	.write = sn_sal_console_write,
 736	.device = uart_console_device,
 737	.setup = sn_sal_console_setup,
 738	.index = -1,		/* unspecified */
 739	.data = &sal_console_uart,
 740};
 741
 742#define SAL_CONSOLE	&sal_console
 743
 744static struct uart_driver sal_console_uart = {
 745	.owner = THIS_MODULE,
 746	.driver_name = "sn_console",
 747	.dev_name = DEVICE_NAME,
 748	.major = 0,		/* major/minor set at registration time per USE_DYNAMIC_MINOR */
 749	.minor = 0,
 750	.nr = 1,		/* one port */
 751	.cons = SAL_CONSOLE,
 752};
 753
 754/**
 755 * sn_sal_init - When the kernel loads us, get us rolling w/ serial core
 756 *
 757 * Before this is called, we've been printing kernel messages in a special
 758 * early mode not making use of the serial core infrastructure.  When our
 759 * driver is loaded for real, we register the driver and port with serial
 760 * core and try to enable interrupt driven mode.
 761 *
 762 */
 763static int __init sn_sal_init(void)
 764{
 765	int retval;
 766
 767	if (!ia64_platform_is("sn2"))
 768		return 0;
 769
 770	printk(KERN_INFO "sn_console: Console driver init\n");
 771
 772	if (USE_DYNAMIC_MINOR == 1) {
 773		misc.minor = MISC_DYNAMIC_MINOR;
 774		misc.name = DEVICE_NAME_DYNAMIC;
 775		retval = misc_register(&misc);
 776		if (retval != 0) {
 777			printk(KERN_WARNING "Failed to register console "
 778			       "device using misc_register.\n");
 779			return -ENODEV;
 780		}
 781		sal_console_uart.major = MISC_MAJOR;
 782		sal_console_uart.minor = misc.minor;
 783	} else {
 784		sal_console_uart.major = DEVICE_MAJOR;
 785		sal_console_uart.minor = DEVICE_MINOR;
 786	}
 787
 788	/* We register the driver and the port before switching to interrupts
 789	 * or async above so the proper uart structures are populated */
 790
 791	if (uart_register_driver(&sal_console_uart) < 0) {
 792		printk
 793		    ("ERROR sn_sal_init failed uart_register_driver, line %d\n",
 794		     __LINE__);
 795		return -ENODEV;
 796	}
 797
 798	spin_lock_init(&sal_console_port.sc_port.lock);
 799
 800	/* Setup the port struct with the minimum needed */
 801	sal_console_port.sc_port.membase = (char *)1;	/* just needs to be non-zero */
 802	sal_console_port.sc_port.type = PORT_16550A;
 803	sal_console_port.sc_port.fifosize = SN_SAL_MAX_CHARS;
 804	sal_console_port.sc_port.ops = &sn_console_ops;
 805	sal_console_port.sc_port.line = 0;
 806
 807	if (uart_add_one_port(&sal_console_uart, &sal_console_port.sc_port) < 0) {
 808		/* error - not sure what I'd do - so I'll do nothing */
 809		printk(KERN_ERR "%s: unable to add port\n", __func__);
 810	}
 811
 812	/* when this driver is compiled in, the console initialization
 813	 * will have already switched us into asynchronous operation
 814	 * before we get here through the initcalls */
 815	if (!sal_console_port.sc_is_asynch) {
 816		sn_sal_switch_to_asynch(&sal_console_port);
 817	}
 818
 819	/* at this point (device_init) we can try to turn on interrupts */
 820	if (!IS_RUNNING_ON_SIMULATOR()) {
 821		sn_sal_switch_to_interrupts(&sal_console_port);
 822	}
 823	sn_process_input = 1;
 824	return 0;
 825}
 826device_initcall(sn_sal_init);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 827
 828/**
 829 * puts_raw_fixed - sn_sal_console_write helper for adding \r's as required
 830 * @puts_raw : puts function to do the writing
 831 * @s: input string
 832 * @count: length
 833 *
 834 * We need a \r ahead of every \n for direct writes through
 835 * ia64_sn_console_putb (what sal_puts_raw below actually does).
 836 *
 837 */
 838
 839static void puts_raw_fixed(int (*puts_raw) (const char *s, int len),
 840			   const char *s, int count)
 841{
 842	const char *s1;
 843
 844	/* Output '\r' before each '\n' */
 845	while ((s1 = memchr(s, '\n', count)) != NULL) {
 846		puts_raw(s, s1 - s);
 847		puts_raw("\r\n", 2);
 848		count -= s1 + 1 - s;
 849		s = s1 + 1;
 850	}
 851	puts_raw(s, count);
 852}
 853
 854/**
 855 * sn_sal_console_write - Print statements before serial core available
 856 * @console: Console to operate on - we ignore since we have just one
 857 * @s: String to send
 858 * @count: length
 859 *
 860 * This is referenced in the console struct.  It is used for early
 861 * console printing before we register with serial core and for things
 862 * such as kdb.  The console_lock must be held when we get here.
 863 *
 864 * This function has some code for trying to print output even if the lock
 865 * is held.  We try to cover the case where a lock holder could have died.
 866 * We don't use this special case code if we're not registered with serial
 867 * core yet.  After we're registered with serial core, the only time this
 868 * function would be used is for high level kernel output like magic sys req,
 869 * kdb, and printk's.
 870 */
 871static void
 872sn_sal_console_write(struct console *co, const char *s, unsigned count)
 873{
 874	unsigned long flags = 0;
 875	struct sn_cons_port *port = &sal_console_port;
 876	static int stole_lock = 0;
 877
 878	BUG_ON(!port->sc_is_asynch);
 879
 880	/* We can't look at the xmit buffer if we're not registered with serial core
 881	 *  yet.  So only do the fancy recovery after registering
 882	 */
 883	if (!port->sc_port.state) {
 884		/* Not yet registered with serial core - simple case */
 885		puts_raw_fixed(port->sc_ops->sal_puts_raw, s, count);
 886		return;
 887	}
 888
 889	/* somebody really wants this output, might be an
 890	 * oops, kdb, panic, etc.  make sure they get it. */
 891	if (spin_is_locked(&port->sc_port.lock)) {
 892		int lhead = port->sc_port.state->xmit.head;
 893		int ltail = port->sc_port.state->xmit.tail;
 894		int counter, got_lock = 0;
 895
 896		/*
 897		 * We attempt to determine if someone has died with the
 898		 * lock. We wait ~20 secs after the head and tail ptrs
 899		 * stop moving and assume the lock holder is not functional
 900		 * and plow ahead. If the lock is freed within the time out
 901		 * period we re-get the lock and go ahead normally. We also
 902		 * remember if we have plowed ahead so that we don't have
 903		 * to wait out the time out period again - the asumption
 904		 * is that we will time out again.
 905		 */
 906
 907		for (counter = 0; counter < 150; mdelay(125), counter++) {
 908			if (!spin_is_locked(&port->sc_port.lock)
 909			    || stole_lock) {
 910				if (!stole_lock) {
 911					spin_lock_irqsave(&port->sc_port.lock,
 912							  flags);
 913					got_lock = 1;
 914				}
 915				break;
 916			} else {
 917				/* still locked */
 918				if ((lhead != port->sc_port.state->xmit.head)
 919				    || (ltail !=
 920					port->sc_port.state->xmit.tail)) {
 921					lhead =
 922						port->sc_port.state->xmit.head;
 923					ltail =
 924						port->sc_port.state->xmit.tail;
 925					counter = 0;
 926				}
 927			}
 928		}
 929		/* flush anything in the serial core xmit buffer, raw */
 930		sn_transmit_chars(port, 1);
 931		if (got_lock) {
 932			spin_unlock_irqrestore(&port->sc_port.lock, flags);
 933			stole_lock = 0;
 934		} else {
 935			/* fell thru */
 936			stole_lock = 1;
 937		}
 938		puts_raw_fixed(port->sc_ops->sal_puts_raw, s, count);
 939	} else {
 940		stole_lock = 0;
 941		spin_lock_irqsave(&port->sc_port.lock, flags);
 942		sn_transmit_chars(port, 1);
 943		spin_unlock_irqrestore(&port->sc_port.lock, flags);
 944
 945		puts_raw_fixed(port->sc_ops->sal_puts_raw, s, count);
 946	}
 947}
 948
 949
 950/**
 951 * sn_sal_console_setup - Set up console for early printing
 952 * @co: Console to work with
 953 * @options: Options to set
 954 *
 955 * Altix console doesn't do anything with baud rates, etc, anyway.
 956 *
 957 * This isn't required since not providing the setup function in the
 958 * console struct is ok.  However, other patches like KDB plop something
 959 * here so providing it is easier.
 960 *
 961 */
 962static int sn_sal_console_setup(struct console *co, char *options)
 963{
 964	return 0;
 965}
 966
 967/**
 968 * sn_sal_console_write_early - simple early output routine
 969 * @co - console struct
 970 * @s - string to print
 971 * @count - count
 972 *
 973 * Simple function to provide early output, before even
 974 * sn_sal_serial_console_init is called.  Referenced in the
 975 * console struct registerd in sn_serial_console_early_setup.
 976 *
 977 */
 978static void __init
 979sn_sal_console_write_early(struct console *co, const char *s, unsigned count)
 980{
 981	puts_raw_fixed(sal_console_port.sc_ops->sal_puts_raw, s, count);
 982}
 983
 984/* Used for very early console printing - again, before
 985 * sn_sal_serial_console_init is run */
 986static struct console sal_console_early __initdata = {
 987	.name = "sn_sal",
 988	.write = sn_sal_console_write_early,
 989	.flags = CON_PRINTBUFFER,
 990	.index = -1,
 991};
 992
 993/**
 994 * sn_serial_console_early_setup - Sets up early console output support
 995 *
 996 * Register a console early on...  This is for output before even
 997 * sn_sal_serial_cosnole_init is called.  This function is called from
 998 * setup.c.  This allows us to do really early polled writes. When
 999 * sn_sal_serial_console_init is called, this console is unregistered
1000 * and a new one registered.
1001 */
1002int __init sn_serial_console_early_setup(void)
1003{
1004	if (!ia64_platform_is("sn2"))
1005		return -1;
1006
1007	sal_console_port.sc_ops = &poll_ops;
1008	spin_lock_init(&sal_console_port.sc_port.lock);
1009	early_sn_setup();	/* Find SAL entry points */
1010	register_console(&sal_console_early);
1011
1012	return 0;
1013}
1014
1015/**
1016 * sn_sal_serial_console_init - Early console output - set up for register
1017 *
1018 * This function is called when regular console init happens.  Because we
1019 * support even earlier console output with sn_serial_console_early_setup
1020 * (called from setup.c directly), this function unregisters the really
1021 * early console.
1022 *
1023 * Note: Even if setup.c doesn't register sal_console_early, unregistering
1024 * it here doesn't hurt anything.
1025 *
1026 */
1027static int __init sn_sal_serial_console_init(void)
1028{
1029	if (ia64_platform_is("sn2")) {
1030		sn_sal_switch_to_asynch(&sal_console_port);
1031		DPRINTF("sn_sal_serial_console_init : register console\n");
1032		register_console(&sal_console);
1033		unregister_console(&sal_console_early);
1034	}
1035	return 0;
1036}
1037
1038console_initcall(sn_sal_serial_console_init);
v3.5.6
   1/*
   2 * C-Brick Serial Port (and console) driver for SGI Altix machines.
   3 *
   4 * This driver is NOT suitable for talking to the l1-controller for
   5 * anything other than 'console activities' --- please use the l1
   6 * driver for that.
   7 *
   8 *
   9 * Copyright (c) 2004-2006 Silicon Graphics, Inc.  All Rights Reserved.
  10 *
  11 * This program is free software; you can redistribute it and/or modify it
  12 * under the terms of version 2 of the GNU General Public License
  13 * as published by the Free Software Foundation.
  14 *
  15 * This program is distributed in the hope that it would be useful, but
  16 * WITHOUT ANY WARRANTY; without even the implied warranty of
  17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  18 *
  19 * Further, this software is distributed without any warranty that it is
  20 * free of the rightful claim of any third person regarding infringement
  21 * or the like.  Any license provided herein, whether implied or
  22 * otherwise, applies only to this software file.  Patent licenses, if
  23 * any, provided herein do not apply to combinations of this program with
  24 * other software, or any other product whatsoever.
  25 *
  26 * You should have received a copy of the GNU General Public
  27 * License along with this program; if not, write the Free Software
  28 * Foundation, Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
  29 *
  30 * Contact information:  Silicon Graphics, Inc., 1500 Crittenden Lane,
  31 * Mountain View, CA  94043, or:
  32 *
  33 * http://www.sgi.com
  34 *
  35 * For further information regarding this notice, see:
  36 *
  37 * http://oss.sgi.com/projects/GenInfo/NoticeExplan
  38 */
  39
  40#include <linux/interrupt.h>
  41#include <linux/tty.h>
  42#include <linux/tty_flip.h>
  43#include <linux/serial.h>
  44#include <linux/console.h>
  45#include <linux/module.h>
  46#include <linux/sysrq.h>
  47#include <linux/circ_buf.h>
  48#include <linux/serial_reg.h>
  49#include <linux/delay.h> /* for mdelay */
  50#include <linux/miscdevice.h>
  51#include <linux/serial_core.h>
  52
  53#include <asm/io.h>
  54#include <asm/sn/simulator.h>
  55#include <asm/sn/sn_sal.h>
  56
  57/* number of characters we can transmit to the SAL console at a time */
  58#define SN_SAL_MAX_CHARS 120
  59
  60/* 64K, when we're asynch, it must be at least printk's LOG_BUF_LEN to
  61 * avoid losing chars, (always has to be a power of 2) */
  62#define SN_SAL_BUFFER_SIZE (64 * (1 << 10))
  63
  64#define SN_SAL_UART_FIFO_DEPTH 16
  65#define SN_SAL_UART_FIFO_SPEED_CPS (9600/10)
  66
  67/* sn_transmit_chars() calling args */
  68#define TRANSMIT_BUFFERED	0
  69#define TRANSMIT_RAW		1
  70
  71/* To use dynamic numbers only and not use the assigned major and minor,
  72 * define the following.. */
  73				  /* #define USE_DYNAMIC_MINOR 1 *//* use dynamic minor number */
  74#define USE_DYNAMIC_MINOR 0	/* Don't rely on misc_register dynamic minor */
  75
  76/* Device name we're using */
  77#define DEVICE_NAME "ttySG"
  78#define DEVICE_NAME_DYNAMIC "ttySG0"	/* need full name for misc_register */
  79/* The major/minor we are using, ignored for USE_DYNAMIC_MINOR */
  80#define DEVICE_MAJOR 204
  81#define DEVICE_MINOR 40
  82
  83#ifdef CONFIG_MAGIC_SYSRQ
  84static char sysrq_serial_str[] = "\eSYS";
  85static char *sysrq_serial_ptr = sysrq_serial_str;
  86static unsigned long sysrq_requested;
  87#endif /* CONFIG_MAGIC_SYSRQ */
  88
  89/*
  90 * Port definition - this kinda drives it all
  91 */
  92struct sn_cons_port {
  93	struct timer_list sc_timer;
  94	struct uart_port sc_port;
  95	struct sn_sal_ops {
  96		int (*sal_puts_raw) (const char *s, int len);
  97		int (*sal_puts) (const char *s, int len);
  98		int (*sal_getc) (void);
  99		int (*sal_input_pending) (void);
 100		void (*sal_wakeup_transmit) (struct sn_cons_port *, int);
 101	} *sc_ops;
 102	unsigned long sc_interrupt_timeout;
 103	int sc_is_asynch;
 104};
 105
 106static struct sn_cons_port sal_console_port;
 107static int sn_process_input;
 108
 109/* Only used if USE_DYNAMIC_MINOR is set to 1 */
 110static struct miscdevice misc;	/* used with misc_register for dynamic */
 111
 112extern void early_sn_setup(void);
 113
 114#undef DEBUG
 115#ifdef DEBUG
 116static int sn_debug_printf(const char *fmt, ...);
 117#define DPRINTF(x...) sn_debug_printf(x)
 118#else
 119#define DPRINTF(x...) do { } while (0)
 120#endif
 121
 122/* Prototypes */
 123static int snt_hw_puts_raw(const char *, int);
 124static int snt_hw_puts_buffered(const char *, int);
 125static int snt_poll_getc(void);
 126static int snt_poll_input_pending(void);
 127static int snt_intr_getc(void);
 128static int snt_intr_input_pending(void);
 129static void sn_transmit_chars(struct sn_cons_port *, int);
 130
 131/* A table for polling:
 132 */
 133static struct sn_sal_ops poll_ops = {
 134	.sal_puts_raw = snt_hw_puts_raw,
 135	.sal_puts = snt_hw_puts_raw,
 136	.sal_getc = snt_poll_getc,
 137	.sal_input_pending = snt_poll_input_pending
 138};
 139
 140/* A table for interrupts enabled */
 141static struct sn_sal_ops intr_ops = {
 142	.sal_puts_raw = snt_hw_puts_raw,
 143	.sal_puts = snt_hw_puts_buffered,
 144	.sal_getc = snt_intr_getc,
 145	.sal_input_pending = snt_intr_input_pending,
 146	.sal_wakeup_transmit = sn_transmit_chars
 147};
 148
 149/* the console does output in two distinctly different ways:
 150 * synchronous (raw) and asynchronous (buffered).  initially, early_printk
 151 * does synchronous output.  any data written goes directly to the SAL
 152 * to be output (incidentally, it is internally buffered by the SAL)
 153 * after interrupts and timers are initialized and available for use,
 154 * the console init code switches to asynchronous output.  this is
 155 * also the earliest opportunity to begin polling for console input.
 156 * after console initialization, console output and tty (serial port)
 157 * output is buffered and sent to the SAL asynchronously (either by
 158 * timer callback or by UART interrupt) */
 159
 160/* routines for running the console in polling mode */
 161
 162/**
 163 * snt_poll_getc - Get a character from the console in polling mode
 164 *
 165 */
 166static int snt_poll_getc(void)
 167{
 168	int ch;
 169
 170	ia64_sn_console_getc(&ch);
 171	return ch;
 172}
 173
 174/**
 175 * snt_poll_input_pending - Check if any input is waiting - polling mode.
 176 *
 177 */
 178static int snt_poll_input_pending(void)
 179{
 180	int status, input;
 181
 182	status = ia64_sn_console_check(&input);
 183	return !status && input;
 184}
 185
 186/* routines for an interrupt driven console (normal) */
 187
 188/**
 189 * snt_intr_getc - Get a character from the console, interrupt mode
 190 *
 191 */
 192static int snt_intr_getc(void)
 193{
 194	return ia64_sn_console_readc();
 195}
 196
 197/**
 198 * snt_intr_input_pending - Check if input is pending, interrupt mode
 199 *
 200 */
 201static int snt_intr_input_pending(void)
 202{
 203	return ia64_sn_console_intr_status() & SAL_CONSOLE_INTR_RECV;
 204}
 205
 206/* these functions are polled and interrupt */
 207
 208/**
 209 * snt_hw_puts_raw - Send raw string to the console, polled or interrupt mode
 210 * @s: String
 211 * @len: Length
 212 *
 213 */
 214static int snt_hw_puts_raw(const char *s, int len)
 215{
 216	/* this will call the PROM and not return until this is done */
 217	return ia64_sn_console_putb(s, len);
 218}
 219
 220/**
 221 * snt_hw_puts_buffered - Send string to console, polled or interrupt mode
 222 * @s: String
 223 * @len: Length
 224 *
 225 */
 226static int snt_hw_puts_buffered(const char *s, int len)
 227{
 228	/* queue data to the PROM */
 229	return ia64_sn_console_xmit_chars((char *)s, len);
 230}
 231
 232/* uart interface structs
 233 * These functions are associated with the uart_port that the serial core
 234 * infrastructure calls.
 235 *
 236 * Note: Due to how the console works, many routines are no-ops.
 237 */
 238
 239/**
 240 * snp_type - What type of console are we?
 241 * @port: Port to operate with (we ignore since we only have one port)
 242 *
 243 */
 244static const char *snp_type(struct uart_port *port)
 245{
 246	return ("SGI SN L1");
 247}
 248
 249/**
 250 * snp_tx_empty - Is the transmitter empty?  We pretend we're always empty
 251 * @port: Port to operate on (we ignore since we only have one port)
 252 *
 253 */
 254static unsigned int snp_tx_empty(struct uart_port *port)
 255{
 256	return 1;
 257}
 258
 259/**
 260 * snp_stop_tx - stop the transmitter - no-op for us
 261 * @port: Port to operat eon - we ignore - no-op function
 262 *
 263 */
 264static void snp_stop_tx(struct uart_port *port)
 265{
 266}
 267
 268/**
 269 * snp_release_port - Free i/o and resources for port - no-op for us
 270 * @port: Port to operate on - we ignore - no-op function
 271 *
 272 */
 273static void snp_release_port(struct uart_port *port)
 274{
 275}
 276
 277/**
 278 * snp_enable_ms - Force modem status interrupts on - no-op for us
 279 * @port: Port to operate on - we ignore - no-op function
 280 *
 281 */
 282static void snp_enable_ms(struct uart_port *port)
 283{
 284}
 285
 286/**
 287 * snp_shutdown - shut down the port - free irq and disable - no-op for us
 288 * @port: Port to shut down - we ignore
 289 *
 290 */
 291static void snp_shutdown(struct uart_port *port)
 292{
 293}
 294
 295/**
 296 * snp_set_mctrl - set control lines (dtr, rts, etc) - no-op for our console
 297 * @port: Port to operate on - we ignore
 298 * @mctrl: Lines to set/unset - we ignore
 299 *
 300 */
 301static void snp_set_mctrl(struct uart_port *port, unsigned int mctrl)
 302{
 303}
 304
 305/**
 306 * snp_get_mctrl - get contorl line info, we just return a static value
 307 * @port: port to operate on - we only have one port so we ignore this
 308 *
 309 */
 310static unsigned int snp_get_mctrl(struct uart_port *port)
 311{
 312	return TIOCM_CAR | TIOCM_RNG | TIOCM_DSR | TIOCM_CTS;
 313}
 314
 315/**
 316 * snp_stop_rx - Stop the receiver - we ignor ethis
 317 * @port: Port to operate on - we ignore
 318 *
 319 */
 320static void snp_stop_rx(struct uart_port *port)
 321{
 322}
 323
 324/**
 325 * snp_start_tx - Start transmitter
 326 * @port: Port to operate on
 327 *
 328 */
 329static void snp_start_tx(struct uart_port *port)
 330{
 331	if (sal_console_port.sc_ops->sal_wakeup_transmit)
 332		sal_console_port.sc_ops->sal_wakeup_transmit(&sal_console_port,
 333							     TRANSMIT_BUFFERED);
 334
 335}
 336
 337/**
 338 * snp_break_ctl - handle breaks - ignored by us
 339 * @port: Port to operate on
 340 * @break_state: Break state
 341 *
 342 */
 343static void snp_break_ctl(struct uart_port *port, int break_state)
 344{
 345}
 346
 347/**
 348 * snp_startup - Start up the serial port - always return 0 (We're always on)
 349 * @port: Port to operate on
 350 *
 351 */
 352static int snp_startup(struct uart_port *port)
 353{
 354	return 0;
 355}
 356
 357/**
 358 * snp_set_termios - set termios stuff - we ignore these
 359 * @port: port to operate on
 360 * @termios: New settings
 361 * @termios: Old
 362 *
 363 */
 364static void
 365snp_set_termios(struct uart_port *port, struct ktermios *termios,
 366		struct ktermios *old)
 367{
 368}
 369
 370/**
 371 * snp_request_port - allocate resources for port - ignored by us
 372 * @port: port to operate on
 373 *
 374 */
 375static int snp_request_port(struct uart_port *port)
 376{
 377	return 0;
 378}
 379
 380/**
 381 * snp_config_port - allocate resources, set up - we ignore,  we're always on
 382 * @port: Port to operate on
 383 * @flags: flags used for port setup
 384 *
 385 */
 386static void snp_config_port(struct uart_port *port, int flags)
 387{
 388}
 389
 390/* Associate the uart functions above - given to serial core */
 391
 392static struct uart_ops sn_console_ops = {
 393	.tx_empty = snp_tx_empty,
 394	.set_mctrl = snp_set_mctrl,
 395	.get_mctrl = snp_get_mctrl,
 396	.stop_tx = snp_stop_tx,
 397	.start_tx = snp_start_tx,
 398	.stop_rx = snp_stop_rx,
 399	.enable_ms = snp_enable_ms,
 400	.break_ctl = snp_break_ctl,
 401	.startup = snp_startup,
 402	.shutdown = snp_shutdown,
 403	.set_termios = snp_set_termios,
 404	.pm = NULL,
 405	.type = snp_type,
 406	.release_port = snp_release_port,
 407	.request_port = snp_request_port,
 408	.config_port = snp_config_port,
 409	.verify_port = NULL,
 410};
 411
 412/* End of uart struct functions and defines */
 413
 414#ifdef DEBUG
 415
 416/**
 417 * sn_debug_printf - close to hardware debugging printf
 418 * @fmt: printf format
 419 *
 420 * This is as "close to the metal" as we can get, used when the driver
 421 * itself may be broken.
 422 *
 423 */
 424static int sn_debug_printf(const char *fmt, ...)
 425{
 426	static char printk_buf[1024];
 427	int printed_len;
 428	va_list args;
 429
 430	va_start(args, fmt);
 431	printed_len = vsnprintf(printk_buf, sizeof(printk_buf), fmt, args);
 432
 433	if (!sal_console_port.sc_ops) {
 434		sal_console_port.sc_ops = &poll_ops;
 435		early_sn_setup();
 436	}
 437	sal_console_port.sc_ops->sal_puts_raw(printk_buf, printed_len);
 438
 439	va_end(args);
 440	return printed_len;
 441}
 442#endif				/* DEBUG */
 443
 444/*
 445 * Interrupt handling routines.
 446 */
 447
 448/**
 449 * sn_receive_chars - Grab characters, pass them to tty layer
 450 * @port: Port to operate on
 451 * @flags: irq flags
 452 *
 453 * Note: If we're not registered with the serial core infrastructure yet,
 454 * we don't try to send characters to it...
 455 *
 456 */
 457static void
 458sn_receive_chars(struct sn_cons_port *port, unsigned long flags)
 459{
 
 460	int ch;
 461	struct tty_struct *tty;
 462
 463	if (!port) {
 464		printk(KERN_ERR "sn_receive_chars - port NULL so can't receive\n");
 465		return;
 466	}
 467
 468	if (!port->sc_ops) {
 469		printk(KERN_ERR "sn_receive_chars - port->sc_ops  NULL so can't receive\n");
 470		return;
 471	}
 472
 473	if (port->sc_port.state) {
 474		/* The serial_core stuffs are initialized, use them */
 475		tty = port->sc_port.state->port.tty;
 476	}
 477	else {
 478		/* Not registered yet - can't pass to tty layer.  */
 479		tty = NULL;
 480	}
 481
 482	while (port->sc_ops->sal_input_pending()) {
 483		ch = port->sc_ops->sal_getc();
 484		if (ch < 0) {
 485			printk(KERN_ERR "sn_console: An error occurred while "
 486			       "obtaining data from the console (0x%0x)\n", ch);
 487			break;
 488		}
 489#ifdef CONFIG_MAGIC_SYSRQ
 490                if (sysrq_requested) {
 491                        unsigned long sysrq_timeout = sysrq_requested + HZ*5;
 492
 493                        sysrq_requested = 0;
 494                        if (ch && time_before(jiffies, sysrq_timeout)) {
 495                                spin_unlock_irqrestore(&port->sc_port.lock, flags);
 496                                handle_sysrq(ch);
 497                                spin_lock_irqsave(&port->sc_port.lock, flags);
 498                                /* ignore actual sysrq command char */
 499                                continue;
 500                        }
 501                }
 502                if (ch == *sysrq_serial_ptr) {
 503                        if (!(*++sysrq_serial_ptr)) {
 504                                sysrq_requested = jiffies;
 505                                sysrq_serial_ptr = sysrq_serial_str;
 506                        }
 507			/*
 508			 * ignore the whole sysrq string except for the
 509			 * leading escape
 510			 */
 511			if (ch != '\e')
 512				continue;
 513                }
 514                else
 515			sysrq_serial_ptr = sysrq_serial_str;
 516#endif /* CONFIG_MAGIC_SYSRQ */
 517
 518		/* record the character to pass up to the tty layer */
 519		if (tty) {
 520			if(tty_insert_flip_char(tty, ch, TTY_NORMAL) == 0)
 521				break;
 522		}
 523		port->sc_port.icount.rx++;
 524	}
 525
 526	if (tty)
 527		tty_flip_buffer_push(tty);
 528}
 529
 530/**
 531 * sn_transmit_chars - grab characters from serial core, send off
 532 * @port: Port to operate on
 533 * @raw: Transmit raw or buffered
 534 *
 535 * Note: If we're early, before we're registered with serial core, the
 536 * writes are going through sn_sal_console_write because that's how
 537 * register_console has been set up.  We currently could have asynch
 538 * polls calling this function due to sn_sal_switch_to_asynch but we can
 539 * ignore them until we register with the serial core stuffs.
 540 *
 541 */
 542static void sn_transmit_chars(struct sn_cons_port *port, int raw)
 543{
 544	int xmit_count, tail, head, loops, ii;
 545	int result;
 546	char *start;
 547	struct circ_buf *xmit;
 548
 549	if (!port)
 550		return;
 551
 552	BUG_ON(!port->sc_is_asynch);
 553
 554	if (port->sc_port.state) {
 555		/* We're initialized, using serial core infrastructure */
 556		xmit = &port->sc_port.state->xmit;
 557	} else {
 558		/* Probably sn_sal_switch_to_asynch has been run but serial core isn't
 559		 * initialized yet.  Just return.  Writes are going through
 560		 * sn_sal_console_write (due to register_console) at this time.
 561		 */
 562		return;
 563	}
 564
 565	if (uart_circ_empty(xmit) || uart_tx_stopped(&port->sc_port)) {
 566		/* Nothing to do. */
 567		ia64_sn_console_intr_disable(SAL_CONSOLE_INTR_XMIT);
 568		return;
 569	}
 570
 571	head = xmit->head;
 572	tail = xmit->tail;
 573	start = &xmit->buf[tail];
 574
 575	/* twice around gets the tail to the end of the buffer and
 576	 * then to the head, if needed */
 577	loops = (head < tail) ? 2 : 1;
 578
 579	for (ii = 0; ii < loops; ii++) {
 580		xmit_count = (head < tail) ?
 581		    (UART_XMIT_SIZE - tail) : (head - tail);
 582
 583		if (xmit_count > 0) {
 584			if (raw == TRANSMIT_RAW)
 585				result =
 586				    port->sc_ops->sal_puts_raw(start,
 587							       xmit_count);
 588			else
 589				result =
 590				    port->sc_ops->sal_puts(start, xmit_count);
 591#ifdef DEBUG
 592			if (!result)
 593				DPRINTF("`");
 594#endif
 595			if (result > 0) {
 596				xmit_count -= result;
 597				port->sc_port.icount.tx += result;
 598				tail += result;
 599				tail &= UART_XMIT_SIZE - 1;
 600				xmit->tail = tail;
 601				start = &xmit->buf[tail];
 602			}
 603		}
 604	}
 605
 606	if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
 607		uart_write_wakeup(&port->sc_port);
 608
 609	if (uart_circ_empty(xmit))
 610		snp_stop_tx(&port->sc_port);	/* no-op for us */
 611}
 612
 613/**
 614 * sn_sal_interrupt - Handle console interrupts
 615 * @irq: irq #, useful for debug statements
 616 * @dev_id: our pointer to our port (sn_cons_port which contains the uart port)
 617 *
 618 */
 619static irqreturn_t sn_sal_interrupt(int irq, void *dev_id)
 620{
 621	struct sn_cons_port *port = (struct sn_cons_port *)dev_id;
 622	unsigned long flags;
 623	int status = ia64_sn_console_intr_status();
 624
 625	if (!port)
 626		return IRQ_NONE;
 627
 628	spin_lock_irqsave(&port->sc_port.lock, flags);
 629	if (status & SAL_CONSOLE_INTR_RECV) {
 630		sn_receive_chars(port, flags);
 631	}
 632	if (status & SAL_CONSOLE_INTR_XMIT) {
 633		sn_transmit_chars(port, TRANSMIT_BUFFERED);
 634	}
 635	spin_unlock_irqrestore(&port->sc_port.lock, flags);
 636	return IRQ_HANDLED;
 637}
 638
 639/**
 640 * sn_sal_timer_poll - this function handles polled console mode
 641 * @data: A pointer to our sn_cons_port (which contains the uart port)
 642 *
 643 * data is the pointer that init_timer will store for us.  This function is
 644 * associated with init_timer to see if there is any console traffic.
 645 * Obviously not used in interrupt mode
 646 *
 647 */
 648static void sn_sal_timer_poll(unsigned long data)
 649{
 650	struct sn_cons_port *port = (struct sn_cons_port *)data;
 651	unsigned long flags;
 652
 653	if (!port)
 654		return;
 655
 656	if (!port->sc_port.irq) {
 657		spin_lock_irqsave(&port->sc_port.lock, flags);
 658		if (sn_process_input)
 659			sn_receive_chars(port, flags);
 660		sn_transmit_chars(port, TRANSMIT_RAW);
 661		spin_unlock_irqrestore(&port->sc_port.lock, flags);
 662		mod_timer(&port->sc_timer,
 663			  jiffies + port->sc_interrupt_timeout);
 664	}
 665}
 666
 667/*
 668 * Boot-time initialization code
 669 */
 670
 671/**
 672 * sn_sal_switch_to_asynch - Switch to async mode (as opposed to synch)
 673 * @port: Our sn_cons_port (which contains the uart port)
 674 *
 675 * So this is used by sn_sal_serial_console_init (early on, before we're
 676 * registered with serial core).  It's also used by sn_sal_module_init
 677 * right after we've registered with serial core.  The later only happens
 678 * if we didn't already come through here via sn_sal_serial_console_init.
 679 *
 680 */
 681static void __init sn_sal_switch_to_asynch(struct sn_cons_port *port)
 682{
 683	unsigned long flags;
 684
 685	if (!port)
 686		return;
 687
 688	DPRINTF("sn_console: about to switch to asynchronous console\n");
 689
 690	/* without early_printk, we may be invoked late enough to race
 691	 * with other cpus doing console IO at this point, however
 692	 * console interrupts will never be enabled */
 693	spin_lock_irqsave(&port->sc_port.lock, flags);
 694
 695	/* early_printk invocation may have done this for us */
 696	if (!port->sc_ops)
 697		port->sc_ops = &poll_ops;
 698
 699	/* we can't turn on the console interrupt (as request_irq
 700	 * calls kmalloc, which isn't set up yet), so we rely on a
 701	 * timer to poll for input and push data from the console
 702	 * buffer.
 703	 */
 704	init_timer(&port->sc_timer);
 705	port->sc_timer.function = sn_sal_timer_poll;
 706	port->sc_timer.data = (unsigned long)port;
 707
 708	if (IS_RUNNING_ON_SIMULATOR())
 709		port->sc_interrupt_timeout = 6;
 710	else {
 711		/* 960cps / 16 char FIFO = 60HZ
 712		 * HZ / (SN_SAL_FIFO_SPEED_CPS / SN_SAL_FIFO_DEPTH) */
 713		port->sc_interrupt_timeout =
 714		    HZ * SN_SAL_UART_FIFO_DEPTH / SN_SAL_UART_FIFO_SPEED_CPS;
 715	}
 716	mod_timer(&port->sc_timer, jiffies + port->sc_interrupt_timeout);
 717
 718	port->sc_is_asynch = 1;
 719	spin_unlock_irqrestore(&port->sc_port.lock, flags);
 720}
 721
 722/**
 723 * sn_sal_switch_to_interrupts - Switch to interrupt driven mode
 724 * @port: Our sn_cons_port (which contains the uart port)
 725 *
 726 * In sn_sal_module_init, after we're registered with serial core and
 727 * the port is added, this function is called to switch us to interrupt
 728 * mode.  We were previously in asynch/polling mode (using init_timer).
 729 *
 730 * We attempt to switch to interrupt mode here by calling
 731 * request_irq.  If that works out, we enable receive interrupts.
 732 */
 733static void __init sn_sal_switch_to_interrupts(struct sn_cons_port *port)
 734{
 735	unsigned long flags;
 736
 737	if (port) {
 738		DPRINTF("sn_console: switching to interrupt driven console\n");
 739
 740		if (request_irq(SGI_UART_VECTOR, sn_sal_interrupt,
 741				IRQF_SHARED,
 742				"SAL console driver", port) >= 0) {
 743			spin_lock_irqsave(&port->sc_port.lock, flags);
 744			port->sc_port.irq = SGI_UART_VECTOR;
 745			port->sc_ops = &intr_ops;
 746			irq_set_handler(port->sc_port.irq, handle_level_irq);
 747
 748			/* turn on receive interrupts */
 749			ia64_sn_console_intr_enable(SAL_CONSOLE_INTR_RECV);
 750			spin_unlock_irqrestore(&port->sc_port.lock, flags);
 751		}
 752		else {
 753			printk(KERN_INFO
 754			    "sn_console: console proceeding in polled mode\n");
 755		}
 756	}
 757}
 758
 759/*
 760 * Kernel console definitions
 761 */
 762
 763static void sn_sal_console_write(struct console *, const char *, unsigned);
 764static int sn_sal_console_setup(struct console *, char *);
 765static struct uart_driver sal_console_uart;
 766extern struct tty_driver *uart_console_device(struct console *, int *);
 767
 768static struct console sal_console = {
 769	.name = DEVICE_NAME,
 770	.write = sn_sal_console_write,
 771	.device = uart_console_device,
 772	.setup = sn_sal_console_setup,
 773	.index = -1,		/* unspecified */
 774	.data = &sal_console_uart,
 775};
 776
 777#define SAL_CONSOLE	&sal_console
 778
 779static struct uart_driver sal_console_uart = {
 780	.owner = THIS_MODULE,
 781	.driver_name = "sn_console",
 782	.dev_name = DEVICE_NAME,
 783	.major = 0,		/* major/minor set at registration time per USE_DYNAMIC_MINOR */
 784	.minor = 0,
 785	.nr = 1,		/* one port */
 786	.cons = SAL_CONSOLE,
 787};
 788
 789/**
 790 * sn_sal_module_init - When the kernel loads us, get us rolling w/ serial core
 791 *
 792 * Before this is called, we've been printing kernel messages in a special
 793 * early mode not making use of the serial core infrastructure.  When our
 794 * driver is loaded for real, we register the driver and port with serial
 795 * core and try to enable interrupt driven mode.
 796 *
 797 */
 798static int __init sn_sal_module_init(void)
 799{
 800	int retval;
 801
 802	if (!ia64_platform_is("sn2"))
 803		return 0;
 804
 805	printk(KERN_INFO "sn_console: Console driver init\n");
 806
 807	if (USE_DYNAMIC_MINOR == 1) {
 808		misc.minor = MISC_DYNAMIC_MINOR;
 809		misc.name = DEVICE_NAME_DYNAMIC;
 810		retval = misc_register(&misc);
 811		if (retval != 0) {
 812			printk(KERN_WARNING "Failed to register console "
 813			       "device using misc_register.\n");
 814			return -ENODEV;
 815		}
 816		sal_console_uart.major = MISC_MAJOR;
 817		sal_console_uart.minor = misc.minor;
 818	} else {
 819		sal_console_uart.major = DEVICE_MAJOR;
 820		sal_console_uart.minor = DEVICE_MINOR;
 821	}
 822
 823	/* We register the driver and the port before switching to interrupts
 824	 * or async above so the proper uart structures are populated */
 825
 826	if (uart_register_driver(&sal_console_uart) < 0) {
 827		printk
 828		    ("ERROR sn_sal_module_init failed uart_register_driver, line %d\n",
 829		     __LINE__);
 830		return -ENODEV;
 831	}
 832
 833	spin_lock_init(&sal_console_port.sc_port.lock);
 834
 835	/* Setup the port struct with the minimum needed */
 836	sal_console_port.sc_port.membase = (char *)1;	/* just needs to be non-zero */
 837	sal_console_port.sc_port.type = PORT_16550A;
 838	sal_console_port.sc_port.fifosize = SN_SAL_MAX_CHARS;
 839	sal_console_port.sc_port.ops = &sn_console_ops;
 840	sal_console_port.sc_port.line = 0;
 841
 842	if (uart_add_one_port(&sal_console_uart, &sal_console_port.sc_port) < 0) {
 843		/* error - not sure what I'd do - so I'll do nothing */
 844		printk(KERN_ERR "%s: unable to add port\n", __func__);
 845	}
 846
 847	/* when this driver is compiled in, the console initialization
 848	 * will have already switched us into asynchronous operation
 849	 * before we get here through the module initcalls */
 850	if (!sal_console_port.sc_is_asynch) {
 851		sn_sal_switch_to_asynch(&sal_console_port);
 852	}
 853
 854	/* at this point (module_init) we can try to turn on interrupts */
 855	if (!IS_RUNNING_ON_SIMULATOR()) {
 856		sn_sal_switch_to_interrupts(&sal_console_port);
 857	}
 858	sn_process_input = 1;
 859	return 0;
 860}
 861
 862/**
 863 * sn_sal_module_exit - When we're unloaded, remove the driver/port
 864 *
 865 */
 866static void __exit sn_sal_module_exit(void)
 867{
 868	del_timer_sync(&sal_console_port.sc_timer);
 869	uart_remove_one_port(&sal_console_uart, &sal_console_port.sc_port);
 870	uart_unregister_driver(&sal_console_uart);
 871	misc_deregister(&misc);
 872}
 873
 874module_init(sn_sal_module_init);
 875module_exit(sn_sal_module_exit);
 876
 877/**
 878 * puts_raw_fixed - sn_sal_console_write helper for adding \r's as required
 879 * @puts_raw : puts function to do the writing
 880 * @s: input string
 881 * @count: length
 882 *
 883 * We need a \r ahead of every \n for direct writes through
 884 * ia64_sn_console_putb (what sal_puts_raw below actually does).
 885 *
 886 */
 887
 888static void puts_raw_fixed(int (*puts_raw) (const char *s, int len),
 889			   const char *s, int count)
 890{
 891	const char *s1;
 892
 893	/* Output '\r' before each '\n' */
 894	while ((s1 = memchr(s, '\n', count)) != NULL) {
 895		puts_raw(s, s1 - s);
 896		puts_raw("\r\n", 2);
 897		count -= s1 + 1 - s;
 898		s = s1 + 1;
 899	}
 900	puts_raw(s, count);
 901}
 902
 903/**
 904 * sn_sal_console_write - Print statements before serial core available
 905 * @console: Console to operate on - we ignore since we have just one
 906 * @s: String to send
 907 * @count: length
 908 *
 909 * This is referenced in the console struct.  It is used for early
 910 * console printing before we register with serial core and for things
 911 * such as kdb.  The console_lock must be held when we get here.
 912 *
 913 * This function has some code for trying to print output even if the lock
 914 * is held.  We try to cover the case where a lock holder could have died.
 915 * We don't use this special case code if we're not registered with serial
 916 * core yet.  After we're registered with serial core, the only time this
 917 * function would be used is for high level kernel output like magic sys req,
 918 * kdb, and printk's.
 919 */
 920static void
 921sn_sal_console_write(struct console *co, const char *s, unsigned count)
 922{
 923	unsigned long flags = 0;
 924	struct sn_cons_port *port = &sal_console_port;
 925	static int stole_lock = 0;
 926
 927	BUG_ON(!port->sc_is_asynch);
 928
 929	/* We can't look at the xmit buffer if we're not registered with serial core
 930	 *  yet.  So only do the fancy recovery after registering
 931	 */
 932	if (!port->sc_port.state) {
 933		/* Not yet registered with serial core - simple case */
 934		puts_raw_fixed(port->sc_ops->sal_puts_raw, s, count);
 935		return;
 936	}
 937
 938	/* somebody really wants this output, might be an
 939	 * oops, kdb, panic, etc.  make sure they get it. */
 940	if (spin_is_locked(&port->sc_port.lock)) {
 941		int lhead = port->sc_port.state->xmit.head;
 942		int ltail = port->sc_port.state->xmit.tail;
 943		int counter, got_lock = 0;
 944
 945		/*
 946		 * We attempt to determine if someone has died with the
 947		 * lock. We wait ~20 secs after the head and tail ptrs
 948		 * stop moving and assume the lock holder is not functional
 949		 * and plow ahead. If the lock is freed within the time out
 950		 * period we re-get the lock and go ahead normally. We also
 951		 * remember if we have plowed ahead so that we don't have
 952		 * to wait out the time out period again - the asumption
 953		 * is that we will time out again.
 954		 */
 955
 956		for (counter = 0; counter < 150; mdelay(125), counter++) {
 957			if (!spin_is_locked(&port->sc_port.lock)
 958			    || stole_lock) {
 959				if (!stole_lock) {
 960					spin_lock_irqsave(&port->sc_port.lock,
 961							  flags);
 962					got_lock = 1;
 963				}
 964				break;
 965			} else {
 966				/* still locked */
 967				if ((lhead != port->sc_port.state->xmit.head)
 968				    || (ltail !=
 969					port->sc_port.state->xmit.tail)) {
 970					lhead =
 971						port->sc_port.state->xmit.head;
 972					ltail =
 973						port->sc_port.state->xmit.tail;
 974					counter = 0;
 975				}
 976			}
 977		}
 978		/* flush anything in the serial core xmit buffer, raw */
 979		sn_transmit_chars(port, 1);
 980		if (got_lock) {
 981			spin_unlock_irqrestore(&port->sc_port.lock, flags);
 982			stole_lock = 0;
 983		} else {
 984			/* fell thru */
 985			stole_lock = 1;
 986		}
 987		puts_raw_fixed(port->sc_ops->sal_puts_raw, s, count);
 988	} else {
 989		stole_lock = 0;
 990		spin_lock_irqsave(&port->sc_port.lock, flags);
 991		sn_transmit_chars(port, 1);
 992		spin_unlock_irqrestore(&port->sc_port.lock, flags);
 993
 994		puts_raw_fixed(port->sc_ops->sal_puts_raw, s, count);
 995	}
 996}
 997
 998
 999/**
1000 * sn_sal_console_setup - Set up console for early printing
1001 * @co: Console to work with
1002 * @options: Options to set
1003 *
1004 * Altix console doesn't do anything with baud rates, etc, anyway.
1005 *
1006 * This isn't required since not providing the setup function in the
1007 * console struct is ok.  However, other patches like KDB plop something
1008 * here so providing it is easier.
1009 *
1010 */
1011static int sn_sal_console_setup(struct console *co, char *options)
1012{
1013	return 0;
1014}
1015
1016/**
1017 * sn_sal_console_write_early - simple early output routine
1018 * @co - console struct
1019 * @s - string to print
1020 * @count - count
1021 *
1022 * Simple function to provide early output, before even
1023 * sn_sal_serial_console_init is called.  Referenced in the
1024 * console struct registerd in sn_serial_console_early_setup.
1025 *
1026 */
1027static void __init
1028sn_sal_console_write_early(struct console *co, const char *s, unsigned count)
1029{
1030	puts_raw_fixed(sal_console_port.sc_ops->sal_puts_raw, s, count);
1031}
1032
1033/* Used for very early console printing - again, before
1034 * sn_sal_serial_console_init is run */
1035static struct console sal_console_early __initdata = {
1036	.name = "sn_sal",
1037	.write = sn_sal_console_write_early,
1038	.flags = CON_PRINTBUFFER,
1039	.index = -1,
1040};
1041
1042/**
1043 * sn_serial_console_early_setup - Sets up early console output support
1044 *
1045 * Register a console early on...  This is for output before even
1046 * sn_sal_serial_cosnole_init is called.  This function is called from
1047 * setup.c.  This allows us to do really early polled writes. When
1048 * sn_sal_serial_console_init is called, this console is unregistered
1049 * and a new one registered.
1050 */
1051int __init sn_serial_console_early_setup(void)
1052{
1053	if (!ia64_platform_is("sn2"))
1054		return -1;
1055
1056	sal_console_port.sc_ops = &poll_ops;
1057	spin_lock_init(&sal_console_port.sc_port.lock);
1058	early_sn_setup();	/* Find SAL entry points */
1059	register_console(&sal_console_early);
1060
1061	return 0;
1062}
1063
1064/**
1065 * sn_sal_serial_console_init - Early console output - set up for register
1066 *
1067 * This function is called when regular console init happens.  Because we
1068 * support even earlier console output with sn_serial_console_early_setup
1069 * (called from setup.c directly), this function unregisters the really
1070 * early console.
1071 *
1072 * Note: Even if setup.c doesn't register sal_console_early, unregistering
1073 * it here doesn't hurt anything.
1074 *
1075 */
1076static int __init sn_sal_serial_console_init(void)
1077{
1078	if (ia64_platform_is("sn2")) {
1079		sn_sal_switch_to_asynch(&sal_console_port);
1080		DPRINTF("sn_sal_serial_console_init : register console\n");
1081		register_console(&sal_console);
1082		unregister_console(&sal_console_early);
1083	}
1084	return 0;
1085}
1086
1087console_initcall(sn_sal_serial_console_init);