]> Pileus Git - ~andy/linux/blob - arch/ia64/hp/sim/simserial.c
TTY: simserial, pass tty down to functions
[~andy/linux] / arch / ia64 / hp / sim / simserial.c
1 /*
2  * Simulated Serial Driver (fake serial)
3  *
4  * This driver is mostly used for bringup purposes and will go away.
5  * It has a strong dependency on the system console. All outputs
6  * are rerouted to the same facility as the one used by printk which, in our
7  * case means sys_sim.c console (goes via the simulator). The code hereafter
8  * is completely leveraged from the serial.c driver.
9  *
10  * Copyright (C) 1999-2000, 2002-2003 Hewlett-Packard Co
11  *      Stephane Eranian <eranian@hpl.hp.com>
12  *      David Mosberger-Tang <davidm@hpl.hp.com>
13  *
14  * 02/04/00 D. Mosberger        Merged in serial.c bug fixes in rs_close().
15  * 02/25/00 D. Mosberger        Synced up with 2.3.99pre-5 version of serial.c.
16  * 07/30/02 D. Mosberger        Replace sti()/cli() with explicit spinlocks & local irq masking
17  */
18
19 #include <linux/init.h>
20 #include <linux/errno.h>
21 #include <linux/sched.h>
22 #include <linux/tty.h>
23 #include <linux/tty_flip.h>
24 #include <linux/major.h>
25 #include <linux/fcntl.h>
26 #include <linux/mm.h>
27 #include <linux/seq_file.h>
28 #include <linux/slab.h>
29 #include <linux/capability.h>
30 #include <linux/console.h>
31 #include <linux/module.h>
32 #include <linux/serial.h>
33 #include <linux/serialP.h>
34 #include <linux/sysrq.h>
35
36 #include <asm/irq.h>
37 #include <asm/hpsim.h>
38 #include <asm/hw_irq.h>
39 #include <asm/uaccess.h>
40
41 #include "hpsim_ssc.h"
42
43 #undef SIMSERIAL_DEBUG  /* define this to get some debug information */
44
45 #define KEYBOARD_INTR   3       /* must match with simulator! */
46
47 #define NR_PORTS        1       /* only one port for now */
48
49 static char *serial_name = "SimSerial driver";
50 static char *serial_version = "0.6";
51
52 /*
53  * This has been extracted from asm/serial.h. We need one eventually but
54  * I don't know exactly what we're going to put in it so just fake one
55  * for now.
56  */
57 #define BASE_BAUD ( 1843200 / 16 )
58
59 #define STD_COM_FLAGS (ASYNC_BOOT_AUTOCONF | ASYNC_SKIP_TEST)
60
61 /*
62  * Most of the values here are meaningless to this particular driver.
63  * However some values must be preserved for the code (leveraged from serial.c
64  * to work correctly).
65  * port must not be 0
66  * type must not be UNKNOWN
67  * So I picked arbitrary (guess from where?) values instead
68  */
69 static struct serial_state rs_table[NR_PORTS]={
70   /* UART CLK   PORT IRQ     FLAGS        */
71   { BASE_BAUD, 0x3F8, 0, STD_COM_FLAGS, PORT_16550 }  /* ttyS0 */
72 };
73
74 /*
75  * Just for the fun of it !
76  */
77 static struct serial_uart_config uart_config[] = {
78         { "unknown", 1, 0 },
79         { "8250", 1, 0 },
80         { "16450", 1, 0 },
81         { "16550", 1, 0 },
82         { "16550A", 16, UART_CLEAR_FIFO | UART_USE_FIFO },
83         { "cirrus", 1, 0 },
84         { "ST16650", 1, UART_CLEAR_FIFO | UART_STARTECH },
85         { "ST16650V2", 32, UART_CLEAR_FIFO | UART_USE_FIFO |
86                   UART_STARTECH },
87         { "TI16750", 64, UART_CLEAR_FIFO | UART_USE_FIFO},
88         { NULL, 0}
89 };
90
91 struct tty_driver *hp_simserial_driver;
92
93 static struct console *console;
94
95 static unsigned char *tmp_buf;
96
97 extern struct console *console_drivers; /* from kernel/printk.c */
98
99 /*
100  * ------------------------------------------------------------
101  * rs_stop() and rs_start()
102  *
103  * This routines are called before setting or resetting tty->stopped.
104  * They enable or disable transmitter interrupts, as necessary.
105  * ------------------------------------------------------------
106  */
107 static void rs_stop(struct tty_struct *tty)
108 {
109 #ifdef SIMSERIAL_DEBUG
110         printk("rs_stop: tty->stopped=%d tty->hw_stopped=%d tty->flow_stopped=%d\n",
111                 tty->stopped, tty->hw_stopped, tty->flow_stopped);
112 #endif
113
114 }
115
116 static void rs_start(struct tty_struct *tty)
117 {
118 #ifdef SIMSERIAL_DEBUG
119         printk("rs_start: tty->stopped=%d tty->hw_stopped=%d tty->flow_stopped=%d\n",
120                 tty->stopped, tty->hw_stopped, tty->flow_stopped);
121 #endif
122 }
123
124 static  void receive_chars(struct tty_struct *tty)
125 {
126         unsigned char ch;
127         static unsigned char seen_esc = 0;
128
129         while ( (ch = ia64_ssc(0, 0, 0, 0, SSC_GETCHAR)) ) {
130                 if ( ch == 27 && seen_esc == 0 ) {
131                         seen_esc = 1;
132                         continue;
133                 } else {
134                         if ( seen_esc==1 && ch == 'O' ) {
135                                 seen_esc = 2;
136                                 continue;
137                         } else if ( seen_esc == 2 ) {
138                                 if ( ch == 'P' ) /* F1 */
139                                         show_state();
140 #ifdef CONFIG_MAGIC_SYSRQ
141                                 if ( ch == 'S' ) { /* F4 */
142                                         do
143                                                 ch = ia64_ssc(0, 0, 0, 0,
144                                                               SSC_GETCHAR);
145                                         while (!ch);
146                                         handle_sysrq(ch);
147                                 }
148 #endif
149                                 seen_esc = 0;
150                                 continue;
151                         }
152                 }
153                 seen_esc = 0;
154
155                 if (tty_insert_flip_char(tty, ch, TTY_NORMAL) == 0)
156                         break;
157         }
158         tty_flip_buffer_push(tty);
159 }
160
161 /*
162  * This is the serial driver's interrupt routine for a single port
163  */
164 static irqreturn_t rs_interrupt_single(int irq, void *dev_id)
165 {
166         struct serial_state *info = dev_id;
167
168         if (!info->tty) {
169                 printk(KERN_INFO "simrs_interrupt_single: info|tty=0 info=%p problem\n", info);
170                 return IRQ_NONE;
171         }
172         /*
173          * pretty simple in our case, because we only get interrupts
174          * on inbound traffic
175          */
176         receive_chars(info->tty);
177         return IRQ_HANDLED;
178 }
179
180 /*
181  * -------------------------------------------------------------------
182  * Here ends the serial interrupt routines.
183  * -------------------------------------------------------------------
184  */
185
186 static int rs_put_char(struct tty_struct *tty, unsigned char ch)
187 {
188         struct serial_state *info = tty->driver_data;
189         unsigned long flags;
190
191         if (!tty || !info->xmit.buf)
192                 return 0;
193
194         local_irq_save(flags);
195         if (CIRC_SPACE(info->xmit.head, info->xmit.tail, SERIAL_XMIT_SIZE) == 0) {
196                 local_irq_restore(flags);
197                 return 0;
198         }
199         info->xmit.buf[info->xmit.head] = ch;
200         info->xmit.head = (info->xmit.head + 1) & (SERIAL_XMIT_SIZE-1);
201         local_irq_restore(flags);
202         return 1;
203 }
204
205 static void transmit_chars(struct tty_struct *tty, struct serial_state *info,
206                 int *intr_done)
207 {
208         int count;
209         unsigned long flags;
210
211         local_irq_save(flags);
212
213         if (info->x_char) {
214                 char c = info->x_char;
215
216                 console->write(console, &c, 1);
217
218                 info->icount.tx++;
219                 info->x_char = 0;
220
221                 goto out;
222         }
223
224         if (info->xmit.head == info->xmit.tail || tty->stopped ||
225                         tty->hw_stopped) {
226 #ifdef SIMSERIAL_DEBUG
227                 printk("transmit_chars: head=%d, tail=%d, stopped=%d\n",
228                        info->xmit.head, info->xmit.tail, tty->stopped);
229 #endif
230                 goto out;
231         }
232         /*
233          * We removed the loop and try to do it in to chunks. We need
234          * 2 operations maximum because it's a ring buffer.
235          *
236          * First from current to tail if possible.
237          * Then from the beginning of the buffer until necessary
238          */
239
240         count = min(CIRC_CNT(info->xmit.head, info->xmit.tail, SERIAL_XMIT_SIZE),
241                     SERIAL_XMIT_SIZE - info->xmit.tail);
242         console->write(console, info->xmit.buf+info->xmit.tail, count);
243
244         info->xmit.tail = (info->xmit.tail+count) & (SERIAL_XMIT_SIZE-1);
245
246         /*
247          * We have more at the beginning of the buffer
248          */
249         count = CIRC_CNT(info->xmit.head, info->xmit.tail, SERIAL_XMIT_SIZE);
250         if (count) {
251                 console->write(console, info->xmit.buf, count);
252                 info->xmit.tail += count;
253         }
254 out:
255         local_irq_restore(flags);
256 }
257
258 static void rs_flush_chars(struct tty_struct *tty)
259 {
260         struct serial_state *info = tty->driver_data;
261
262         if (info->xmit.head == info->xmit.tail || tty->stopped || tty->hw_stopped ||
263             !info->xmit.buf)
264                 return;
265
266         transmit_chars(tty, info, NULL);
267 }
268
269
270 static int rs_write(struct tty_struct * tty,
271                     const unsigned char *buf, int count)
272 {
273         struct serial_state *info = tty->driver_data;
274         int     c, ret = 0;
275         unsigned long flags;
276
277         if (!tty || !info->xmit.buf || !tmp_buf) return 0;
278
279         local_irq_save(flags);
280         while (1) {
281                 c = CIRC_SPACE_TO_END(info->xmit.head, info->xmit.tail, SERIAL_XMIT_SIZE);
282                 if (count < c)
283                         c = count;
284                 if (c <= 0) {
285                         break;
286                 }
287                 memcpy(info->xmit.buf + info->xmit.head, buf, c);
288                 info->xmit.head = ((info->xmit.head + c) &
289                                    (SERIAL_XMIT_SIZE-1));
290                 buf += c;
291                 count -= c;
292                 ret += c;
293         }
294         local_irq_restore(flags);
295         /*
296          * Hey, we transmit directly from here in our case
297          */
298         if (CIRC_CNT(info->xmit.head, info->xmit.tail, SERIAL_XMIT_SIZE)
299             && !tty->stopped && !tty->hw_stopped) {
300                 transmit_chars(tty, info, NULL);
301         }
302         return ret;
303 }
304
305 static int rs_write_room(struct tty_struct *tty)
306 {
307         struct serial_state *info = tty->driver_data;
308
309         return CIRC_SPACE(info->xmit.head, info->xmit.tail, SERIAL_XMIT_SIZE);
310 }
311
312 static int rs_chars_in_buffer(struct tty_struct *tty)
313 {
314         struct serial_state *info = tty->driver_data;
315
316         return CIRC_CNT(info->xmit.head, info->xmit.tail, SERIAL_XMIT_SIZE);
317 }
318
319 static void rs_flush_buffer(struct tty_struct *tty)
320 {
321         struct serial_state *info = tty->driver_data;
322         unsigned long flags;
323
324         local_irq_save(flags);
325         info->xmit.head = info->xmit.tail = 0;
326         local_irq_restore(flags);
327
328         tty_wakeup(tty);
329 }
330
331 /*
332  * This function is used to send a high-priority XON/XOFF character to
333  * the device
334  */
335 static void rs_send_xchar(struct tty_struct *tty, char ch)
336 {
337         struct serial_state *info = tty->driver_data;
338
339         info->x_char = ch;
340         if (ch) {
341                 /*
342                  * I guess we could call console->write() directly but
343                  * let's do that for now.
344                  */
345                 transmit_chars(tty, info, NULL);
346         }
347 }
348
349 /*
350  * ------------------------------------------------------------
351  * rs_throttle()
352  *
353  * This routine is called by the upper-layer tty layer to signal that
354  * incoming characters should be throttled.
355  * ------------------------------------------------------------
356  */
357 static void rs_throttle(struct tty_struct * tty)
358 {
359         if (I_IXOFF(tty)) rs_send_xchar(tty, STOP_CHAR(tty));
360
361         printk(KERN_INFO "simrs_throttle called\n");
362 }
363
364 static void rs_unthrottle(struct tty_struct * tty)
365 {
366         struct serial_state *info = tty->driver_data;
367
368         if (I_IXOFF(tty)) {
369                 if (info->x_char)
370                         info->x_char = 0;
371                 else
372                         rs_send_xchar(tty, START_CHAR(tty));
373         }
374         printk(KERN_INFO "simrs_unthrottle called\n");
375 }
376
377
378 static int rs_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg)
379 {
380         if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
381             (cmd != TIOCSERCONFIG) && (cmd != TIOCSERGSTRUCT) &&
382             (cmd != TIOCMIWAIT)) {
383                 if (tty->flags & (1 << TTY_IO_ERROR))
384                     return -EIO;
385         }
386
387         switch (cmd) {
388                 case TIOCGSERIAL:
389                         printk(KERN_INFO "simrs_ioctl TIOCGSERIAL called\n");
390                         return 0;
391                 case TIOCSSERIAL:
392                         printk(KERN_INFO "simrs_ioctl TIOCSSERIAL called\n");
393                         return 0;
394                 case TIOCSERCONFIG:
395                         printk(KERN_INFO "rs_ioctl: TIOCSERCONFIG called\n");
396                         return -EINVAL;
397
398                 case TIOCSERGETLSR: /* Get line status register */
399                         printk(KERN_INFO "rs_ioctl: TIOCSERGETLSR called\n");
400                         return  -EINVAL;
401
402                 case TIOCSERGSTRUCT:
403                         printk(KERN_INFO "rs_ioctl: TIOCSERGSTRUCT called\n");
404 #if 0
405                         if (copy_to_user((struct async_struct *) arg,
406                                          info, sizeof(struct async_struct)))
407                                 return -EFAULT;
408 #endif
409                         return 0;
410
411                 /*
412                  * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
413                  * - mask passed in arg for lines of interest
414                  *   (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
415                  * Caller should use TIOCGICOUNT to see which one it was
416                  */
417                 case TIOCMIWAIT:
418                         printk(KERN_INFO "rs_ioctl: TIOCMIWAIT: called\n");
419                         return 0;
420                 case TIOCSERGWILD:
421                 case TIOCSERSWILD:
422                         /* "setserial -W" is called in Debian boot */
423                         printk (KERN_INFO "TIOCSER?WILD ioctl obsolete, ignored.\n");
424                         return 0;
425
426                 default:
427                         return -ENOIOCTLCMD;
428                 }
429         return 0;
430 }
431
432 #define RELEVANT_IFLAG(iflag) (iflag & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK))
433
434 static void rs_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
435 {
436         /* Handle turning off CRTSCTS */
437         if ((old_termios->c_cflag & CRTSCTS) &&
438             !(tty->termios->c_cflag & CRTSCTS)) {
439                 tty->hw_stopped = 0;
440                 rs_start(tty);
441         }
442 }
443 /*
444  * This routine will shutdown a serial port; interrupts are disabled, and
445  * DTR is dropped if the hangup on close termio flag is on.
446  */
447 static void shutdown(struct tty_struct *tty, struct serial_state *info)
448 {
449         unsigned long   flags;
450
451         if (!(info->flags & ASYNC_INITIALIZED))
452                 return;
453
454 #ifdef SIMSERIAL_DEBUG
455         printk("Shutting down serial port %d (irq %d)...\n", info->line,
456                info->irq);
457 #endif
458
459         local_irq_save(flags);
460         {
461                 if (info->irq)
462                         free_irq(info->irq, info);
463
464                 if (info->xmit.buf) {
465                         free_page((unsigned long) info->xmit.buf);
466                         info->xmit.buf = NULL;
467                 }
468
469                 set_bit(TTY_IO_ERROR, &tty->flags);
470
471                 info->flags &= ~ASYNC_INITIALIZED;
472         }
473         local_irq_restore(flags);
474 }
475
476 /*
477  * ------------------------------------------------------------
478  * rs_close()
479  *
480  * This routine is called when the serial port gets closed.  First, we
481  * wait for the last remaining data to be sent.  Then, we unlink its
482  * async structure from the interrupt chain if necessary, and we free
483  * that IRQ if nothing is left in the chain.
484  * ------------------------------------------------------------
485  */
486 static void rs_close(struct tty_struct *tty, struct file * filp)
487 {
488         struct serial_state *info = tty->driver_data;
489         unsigned long flags;
490
491         if (!info)
492                 return;
493
494         local_irq_save(flags);
495         if (tty_hung_up_p(filp)) {
496 #ifdef SIMSERIAL_DEBUG
497                 printk("rs_close: hung_up\n");
498 #endif
499                 local_irq_restore(flags);
500                 return;
501         }
502 #ifdef SIMSERIAL_DEBUG
503         printk("rs_close ttys%d, count = %d\n", info->line, info->count);
504 #endif
505         if ((tty->count == 1) && (info->count != 1)) {
506                 /*
507                  * Uh, oh.  tty->count is 1, which means that the tty
508                  * structure will be freed.  info->count should always
509                  * be one in these conditions.  If it's greater than
510                  * one, we've got real problems, since it means the
511                  * serial port won't be shutdown.
512                  */
513                 printk(KERN_ERR "rs_close: bad serial port count; tty->count is 1, "
514                        "info->count is %d\n", info->count);
515                 info->count = 1;
516         }
517         if (--info->count < 0) {
518                 printk(KERN_ERR "rs_close: bad serial port count for ttys%d: %d\n",
519                        info->line, info->count);
520                 info->count = 0;
521         }
522         if (info->count) {
523                 local_irq_restore(flags);
524                 return;
525         }
526         info->flags |= ASYNC_CLOSING;
527         local_irq_restore(flags);
528
529         /*
530          * Now we wait for the transmit buffer to clear; and we notify
531          * the line discipline to only process XON/XOFF characters.
532          */
533         shutdown(tty, info);
534         rs_flush_buffer(tty);
535         tty_ldisc_flush(tty);
536         info->tty = NULL;
537         if (info->blocked_open) {
538                 if (info->close_delay)
539                         schedule_timeout_interruptible(info->close_delay);
540                 wake_up_interruptible(&info->open_wait);
541         }
542         info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
543         wake_up_interruptible(&info->close_wait);
544 }
545
546 /*
547  * rs_wait_until_sent() --- wait until the transmitter is empty
548  */
549 static void rs_wait_until_sent(struct tty_struct *tty, int timeout)
550 {
551 }
552
553
554 /*
555  * rs_hangup() --- called by tty_hangup() when a hangup is signaled.
556  */
557 static void rs_hangup(struct tty_struct *tty)
558 {
559         struct serial_state *info = tty->driver_data;
560
561 #ifdef SIMSERIAL_DEBUG
562         printk("rs_hangup: called\n");
563 #endif
564
565         rs_flush_buffer(tty);
566         if (info->flags & ASYNC_CLOSING)
567                 return;
568         shutdown(tty, info);
569
570         info->count = 0;
571         info->flags &= ~ASYNC_NORMAL_ACTIVE;
572         info->tty = NULL;
573         wake_up_interruptible(&info->open_wait);
574 }
575
576
577 static int startup(struct tty_struct *tty, struct serial_state *state)
578 {
579         unsigned long flags;
580         int     retval=0;
581         unsigned long page;
582
583         page = get_zeroed_page(GFP_KERNEL);
584         if (!page)
585                 return -ENOMEM;
586
587         local_irq_save(flags);
588
589         if (state->flags & ASYNC_INITIALIZED) {
590                 free_page(page);
591                 goto errout;
592         }
593
594         if (!state->port || !state->type) {
595                 set_bit(TTY_IO_ERROR, &tty->flags);
596                 free_page(page);
597                 goto errout;
598         }
599         if (state->xmit.buf)
600                 free_page(page);
601         else
602                 state->xmit.buf = (unsigned char *) page;
603
604 #ifdef SIMSERIAL_DEBUG
605         printk("startup: ttys%d (irq %d)...", state->line, state->irq);
606 #endif
607
608         /*
609          * Allocate the IRQ if necessary
610          */
611         if (state->irq) {
612                 retval = request_irq(state->irq, rs_interrupt_single, 0,
613                                 "simserial", state);
614                 if (retval)
615                         goto errout;
616         }
617
618         clear_bit(TTY_IO_ERROR, &tty->flags);
619
620         state->xmit.head = state->xmit.tail = 0;
621
622 #if 0
623         /*
624          * Set up serial timers...
625          */
626         timer_table[RS_TIMER].expires = jiffies + 2*HZ/100;
627         timer_active |= 1 << RS_TIMER;
628 #endif
629
630         /*
631          * Set up the tty->alt_speed kludge
632          */
633         if ((state->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
634                 tty->alt_speed = 57600;
635         if ((state->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
636                 tty->alt_speed = 115200;
637         if ((state->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
638                 tty->alt_speed = 230400;
639         if ((state->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
640                 tty->alt_speed = 460800;
641
642         state->flags |= ASYNC_INITIALIZED;
643         local_irq_restore(flags);
644         return 0;
645
646 errout:
647         local_irq_restore(flags);
648         return retval;
649 }
650
651
652 /*
653  * This routine is called whenever a serial port is opened.  It
654  * enables interrupts for a serial port, linking in its async structure into
655  * the IRQ chain.   It also performs the serial-specific
656  * initialization for the tty structure.
657  */
658 static int rs_open(struct tty_struct *tty, struct file * filp)
659 {
660         struct serial_state *info = rs_table + tty->index;
661         int                     retval;
662         unsigned long           page;
663
664         info->count++;
665         info->tty = tty;
666         tty->driver_data = info;
667
668 #ifdef SIMSERIAL_DEBUG
669         printk("rs_open %s, count = %d\n", tty->name, info->count);
670 #endif
671         tty->low_latency = (info->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
672
673         if (!tmp_buf) {
674                 page = get_zeroed_page(GFP_KERNEL);
675                 if (!page)
676                         return -ENOMEM;
677                 if (tmp_buf)
678                         free_page(page);
679                 else
680                         tmp_buf = (unsigned char *) page;
681         }
682
683         /*
684          * If the port is the middle of closing, bail out now
685          */
686         if (tty_hung_up_p(filp) || (info->flags & ASYNC_CLOSING)) {
687                 if (info->flags & ASYNC_CLOSING)
688                         interruptible_sleep_on(&info->close_wait);
689 #ifdef SERIAL_DO_RESTART
690                 return ((info->flags & ASYNC_HUP_NOTIFY) ?
691                         -EAGAIN : -ERESTARTSYS);
692 #else
693                 return -EAGAIN;
694 #endif
695         }
696
697         /*
698          * Start up serial port
699          */
700         retval = startup(tty, info);
701         if (retval) {
702                 return retval;
703         }
704
705         /*
706          * figure out which console to use (should be one already)
707          */
708         console = console_drivers;
709         while (console) {
710                 if ((console->flags & CON_ENABLED) && console->write) break;
711                 console = console->next;
712         }
713
714 #ifdef SIMSERIAL_DEBUG
715         printk("rs_open ttys%d successful\n", info->line);
716 #endif
717         return 0;
718 }
719
720 /*
721  * /proc fs routines....
722  */
723
724 static inline void line_info(struct seq_file *m, struct serial_state *state)
725 {
726         seq_printf(m, "%d: uart:%s port:%lX irq:%d\n",
727                        state->line, uart_config[state->type].name,
728                        state->port, state->irq);
729 }
730
731 static int rs_proc_show(struct seq_file *m, void *v)
732 {
733         int i;
734
735         seq_printf(m, "simserinfo:1.0 driver:%s\n", serial_version);
736         for (i = 0; i < NR_PORTS; i++)
737                 line_info(m, &rs_table[i]);
738         return 0;
739 }
740
741 static int rs_proc_open(struct inode *inode, struct file *file)
742 {
743         return single_open(file, rs_proc_show, NULL);
744 }
745
746 static const struct file_operations rs_proc_fops = {
747         .owner          = THIS_MODULE,
748         .open           = rs_proc_open,
749         .read           = seq_read,
750         .llseek         = seq_lseek,
751         .release        = single_release,
752 };
753
754 /*
755  * ---------------------------------------------------------------------
756  * rs_init() and friends
757  *
758  * rs_init() is called at boot-time to initialize the serial driver.
759  * ---------------------------------------------------------------------
760  */
761
762 /*
763  * This routine prints out the appropriate serial driver version
764  * number, and identifies which options were configured into this
765  * driver.
766  */
767 static inline void show_serial_version(void)
768 {
769         printk(KERN_INFO "%s version %s with", serial_name, serial_version);
770         printk(KERN_INFO " no serial options enabled\n");
771 }
772
773 static const struct tty_operations hp_ops = {
774         .open = rs_open,
775         .close = rs_close,
776         .write = rs_write,
777         .put_char = rs_put_char,
778         .flush_chars = rs_flush_chars,
779         .write_room = rs_write_room,
780         .chars_in_buffer = rs_chars_in_buffer,
781         .flush_buffer = rs_flush_buffer,
782         .ioctl = rs_ioctl,
783         .throttle = rs_throttle,
784         .unthrottle = rs_unthrottle,
785         .send_xchar = rs_send_xchar,
786         .set_termios = rs_set_termios,
787         .stop = rs_stop,
788         .start = rs_start,
789         .hangup = rs_hangup,
790         .wait_until_sent = rs_wait_until_sent,
791         .proc_fops = &rs_proc_fops,
792 };
793
794 /*
795  * The serial driver boot-time initialization code!
796  */
797 static int __init
798 simrs_init (void)
799 {
800         int                     i, rc;
801         struct serial_state     *state;
802
803         if (!ia64_platform_is("hpsim"))
804                 return -ENODEV;
805
806         hp_simserial_driver = alloc_tty_driver(NR_PORTS);
807         if (!hp_simserial_driver)
808                 return -ENOMEM;
809
810         show_serial_version();
811
812         /* Initialize the tty_driver structure */
813
814         hp_simserial_driver->driver_name = "simserial";
815         hp_simserial_driver->name = "ttyS";
816         hp_simserial_driver->major = TTY_MAJOR;
817         hp_simserial_driver->minor_start = 64;
818         hp_simserial_driver->type = TTY_DRIVER_TYPE_SERIAL;
819         hp_simserial_driver->subtype = SERIAL_TYPE_NORMAL;
820         hp_simserial_driver->init_termios = tty_std_termios;
821         hp_simserial_driver->init_termios.c_cflag =
822                 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
823         hp_simserial_driver->flags = TTY_DRIVER_REAL_RAW;
824         tty_set_operations(hp_simserial_driver, &hp_ops);
825
826         /*
827          * Let's have a little bit of fun !
828          */
829         for (i = 0, state = rs_table; i < NR_PORTS; i++,state++) {
830                 init_waitqueue_head(&state->open_wait);
831                 init_waitqueue_head(&state->close_wait);
832
833                 if (state->type == PORT_UNKNOWN) continue;
834
835                 if (!state->irq) {
836                         if ((rc = hpsim_get_irq(KEYBOARD_INTR)) < 0)
837                                 panic("%s: out of interrupt vectors!\n",
838                                       __func__);
839                         state->irq = rc;
840                 }
841
842                 printk(KERN_INFO "ttyS%d at 0x%04lx (irq = %d) is a %s\n",
843                        state->line,
844                        state->port, state->irq,
845                        uart_config[state->type].name);
846         }
847
848         if (tty_register_driver(hp_simserial_driver))
849                 panic("Couldn't register simserial driver\n");
850
851         return 0;
852 }
853
854 #ifndef MODULE
855 __initcall(simrs_init);
856 #endif