simserial.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806
  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. #include <linux/init.h>
  19. #include <linux/errno.h>
  20. #include <linux/sched.h>
  21. #include <linux/tty.h>
  22. #include <linux/tty_flip.h>
  23. #include <linux/major.h>
  24. #include <linux/fcntl.h>
  25. #include <linux/mm.h>
  26. #include <linux/seq_file.h>
  27. #include <linux/slab.h>
  28. #include <linux/capability.h>
  29. #include <linux/circ_buf.h>
  30. #include <linux/console.h>
  31. #include <linux/module.h>
  32. #include <linux/serial.h>
  33. #include <linux/sysrq.h>
  34. #include <asm/irq.h>
  35. #include <asm/hpsim.h>
  36. #include <asm/hw_irq.h>
  37. #include <asm/uaccess.h>
  38. #include "hpsim_ssc.h"
  39. #undef SIMSERIAL_DEBUG /* define this to get some debug information */
  40. #define KEYBOARD_INTR 3 /* must match with simulator! */
  41. #define NR_PORTS 1 /* only one port for now */
  42. struct serial_state {
  43. struct tty_port tport;
  44. struct circ_buf xmit;
  45. int irq;
  46. int x_char;
  47. };
  48. static char *serial_name = "SimSerial driver";
  49. static char *serial_version = "0.6";
  50. static struct serial_state rs_table[NR_PORTS];
  51. struct tty_driver *hp_simserial_driver;
  52. static struct console *console;
  53. extern struct console *console_drivers; /* from kernel/printk.c */
  54. /*
  55. * ------------------------------------------------------------
  56. * rs_stop() and rs_start()
  57. *
  58. * This routines are called before setting or resetting tty->stopped.
  59. * They enable or disable transmitter interrupts, as necessary.
  60. * ------------------------------------------------------------
  61. */
  62. static void rs_stop(struct tty_struct *tty)
  63. {
  64. #ifdef SIMSERIAL_DEBUG
  65. printk("rs_stop: tty->stopped=%d tty->hw_stopped=%d tty->flow_stopped=%d\n",
  66. tty->stopped, tty->hw_stopped, tty->flow_stopped);
  67. #endif
  68. }
  69. static void rs_start(struct tty_struct *tty)
  70. {
  71. #ifdef SIMSERIAL_DEBUG
  72. printk("rs_start: tty->stopped=%d tty->hw_stopped=%d tty->flow_stopped=%d\n",
  73. tty->stopped, tty->hw_stopped, tty->flow_stopped);
  74. #endif
  75. }
  76. static void receive_chars(struct tty_struct *tty)
  77. {
  78. unsigned char ch;
  79. static unsigned char seen_esc = 0;
  80. while ( (ch = ia64_ssc(0, 0, 0, 0, SSC_GETCHAR)) ) {
  81. if ( ch == 27 && seen_esc == 0 ) {
  82. seen_esc = 1;
  83. continue;
  84. } else {
  85. if ( seen_esc==1 && ch == 'O' ) {
  86. seen_esc = 2;
  87. continue;
  88. } else if ( seen_esc == 2 ) {
  89. if ( ch == 'P' ) /* F1 */
  90. show_state();
  91. #ifdef CONFIG_MAGIC_SYSRQ
  92. if ( ch == 'S' ) { /* F4 */
  93. do
  94. ch = ia64_ssc(0, 0, 0, 0,
  95. SSC_GETCHAR);
  96. while (!ch);
  97. handle_sysrq(ch);
  98. }
  99. #endif
  100. seen_esc = 0;
  101. continue;
  102. }
  103. }
  104. seen_esc = 0;
  105. if (tty_insert_flip_char(tty, ch, TTY_NORMAL) == 0)
  106. break;
  107. }
  108. tty_flip_buffer_push(tty);
  109. }
  110. /*
  111. * This is the serial driver's interrupt routine for a single port
  112. */
  113. static irqreturn_t rs_interrupt_single(int irq, void *dev_id)
  114. {
  115. struct serial_state *info = dev_id;
  116. if (!info->tport.tty) {
  117. printk(KERN_INFO "simrs_interrupt_single: info|tty=0 info=%p problem\n", info);
  118. return IRQ_NONE;
  119. }
  120. /*
  121. * pretty simple in our case, because we only get interrupts
  122. * on inbound traffic
  123. */
  124. receive_chars(info->tport.tty);
  125. return IRQ_HANDLED;
  126. }
  127. /*
  128. * -------------------------------------------------------------------
  129. * Here ends the serial interrupt routines.
  130. * -------------------------------------------------------------------
  131. */
  132. static int rs_put_char(struct tty_struct *tty, unsigned char ch)
  133. {
  134. struct serial_state *info = tty->driver_data;
  135. unsigned long flags;
  136. if (!tty || !info->xmit.buf)
  137. return 0;
  138. local_irq_save(flags);
  139. if (CIRC_SPACE(info->xmit.head, info->xmit.tail, SERIAL_XMIT_SIZE) == 0) {
  140. local_irq_restore(flags);
  141. return 0;
  142. }
  143. info->xmit.buf[info->xmit.head] = ch;
  144. info->xmit.head = (info->xmit.head + 1) & (SERIAL_XMIT_SIZE-1);
  145. local_irq_restore(flags);
  146. return 1;
  147. }
  148. static void transmit_chars(struct tty_struct *tty, struct serial_state *info,
  149. int *intr_done)
  150. {
  151. int count;
  152. unsigned long flags;
  153. local_irq_save(flags);
  154. if (info->x_char) {
  155. char c = info->x_char;
  156. console->write(console, &c, 1);
  157. info->x_char = 0;
  158. goto out;
  159. }
  160. if (info->xmit.head == info->xmit.tail || tty->stopped ||
  161. tty->hw_stopped) {
  162. #ifdef SIMSERIAL_DEBUG
  163. printk("transmit_chars: head=%d, tail=%d, stopped=%d\n",
  164. info->xmit.head, info->xmit.tail, tty->stopped);
  165. #endif
  166. goto out;
  167. }
  168. /*
  169. * We removed the loop and try to do it in to chunks. We need
  170. * 2 operations maximum because it's a ring buffer.
  171. *
  172. * First from current to tail if possible.
  173. * Then from the beginning of the buffer until necessary
  174. */
  175. count = min(CIRC_CNT(info->xmit.head, info->xmit.tail, SERIAL_XMIT_SIZE),
  176. SERIAL_XMIT_SIZE - info->xmit.tail);
  177. console->write(console, info->xmit.buf+info->xmit.tail, count);
  178. info->xmit.tail = (info->xmit.tail+count) & (SERIAL_XMIT_SIZE-1);
  179. /*
  180. * We have more at the beginning of the buffer
  181. */
  182. count = CIRC_CNT(info->xmit.head, info->xmit.tail, SERIAL_XMIT_SIZE);
  183. if (count) {
  184. console->write(console, info->xmit.buf, count);
  185. info->xmit.tail += count;
  186. }
  187. out:
  188. local_irq_restore(flags);
  189. }
  190. static void rs_flush_chars(struct tty_struct *tty)
  191. {
  192. struct serial_state *info = tty->driver_data;
  193. if (info->xmit.head == info->xmit.tail || tty->stopped || tty->hw_stopped ||
  194. !info->xmit.buf)
  195. return;
  196. transmit_chars(tty, info, NULL);
  197. }
  198. static int rs_write(struct tty_struct * tty,
  199. const unsigned char *buf, int count)
  200. {
  201. struct serial_state *info = tty->driver_data;
  202. int c, ret = 0;
  203. unsigned long flags;
  204. if (!tty || !info->xmit.buf)
  205. return 0;
  206. local_irq_save(flags);
  207. while (1) {
  208. c = CIRC_SPACE_TO_END(info->xmit.head, info->xmit.tail, SERIAL_XMIT_SIZE);
  209. if (count < c)
  210. c = count;
  211. if (c <= 0) {
  212. break;
  213. }
  214. memcpy(info->xmit.buf + info->xmit.head, buf, c);
  215. info->xmit.head = ((info->xmit.head + c) &
  216. (SERIAL_XMIT_SIZE-1));
  217. buf += c;
  218. count -= c;
  219. ret += c;
  220. }
  221. local_irq_restore(flags);
  222. /*
  223. * Hey, we transmit directly from here in our case
  224. */
  225. if (CIRC_CNT(info->xmit.head, info->xmit.tail, SERIAL_XMIT_SIZE)
  226. && !tty->stopped && !tty->hw_stopped) {
  227. transmit_chars(tty, info, NULL);
  228. }
  229. return ret;
  230. }
  231. static int rs_write_room(struct tty_struct *tty)
  232. {
  233. struct serial_state *info = tty->driver_data;
  234. return CIRC_SPACE(info->xmit.head, info->xmit.tail, SERIAL_XMIT_SIZE);
  235. }
  236. static int rs_chars_in_buffer(struct tty_struct *tty)
  237. {
  238. struct serial_state *info = tty->driver_data;
  239. return CIRC_CNT(info->xmit.head, info->xmit.tail, SERIAL_XMIT_SIZE);
  240. }
  241. static void rs_flush_buffer(struct tty_struct *tty)
  242. {
  243. struct serial_state *info = tty->driver_data;
  244. unsigned long flags;
  245. local_irq_save(flags);
  246. info->xmit.head = info->xmit.tail = 0;
  247. local_irq_restore(flags);
  248. tty_wakeup(tty);
  249. }
  250. /*
  251. * This function is used to send a high-priority XON/XOFF character to
  252. * the device
  253. */
  254. static void rs_send_xchar(struct tty_struct *tty, char ch)
  255. {
  256. struct serial_state *info = tty->driver_data;
  257. info->x_char = ch;
  258. if (ch) {
  259. /*
  260. * I guess we could call console->write() directly but
  261. * let's do that for now.
  262. */
  263. transmit_chars(tty, info, NULL);
  264. }
  265. }
  266. /*
  267. * ------------------------------------------------------------
  268. * rs_throttle()
  269. *
  270. * This routine is called by the upper-layer tty layer to signal that
  271. * incoming characters should be throttled.
  272. * ------------------------------------------------------------
  273. */
  274. static void rs_throttle(struct tty_struct * tty)
  275. {
  276. if (I_IXOFF(tty)) rs_send_xchar(tty, STOP_CHAR(tty));
  277. printk(KERN_INFO "simrs_throttle called\n");
  278. }
  279. static void rs_unthrottle(struct tty_struct * tty)
  280. {
  281. struct serial_state *info = tty->driver_data;
  282. if (I_IXOFF(tty)) {
  283. if (info->x_char)
  284. info->x_char = 0;
  285. else
  286. rs_send_xchar(tty, START_CHAR(tty));
  287. }
  288. printk(KERN_INFO "simrs_unthrottle called\n");
  289. }
  290. static int rs_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg)
  291. {
  292. if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
  293. (cmd != TIOCSERCONFIG) && (cmd != TIOCSERGSTRUCT) &&
  294. (cmd != TIOCMIWAIT)) {
  295. if (tty->flags & (1 << TTY_IO_ERROR))
  296. return -EIO;
  297. }
  298. switch (cmd) {
  299. case TIOCGSERIAL:
  300. printk(KERN_INFO "simrs_ioctl TIOCGSERIAL called\n");
  301. return 0;
  302. case TIOCSSERIAL:
  303. printk(KERN_INFO "simrs_ioctl TIOCSSERIAL called\n");
  304. return 0;
  305. case TIOCSERCONFIG:
  306. printk(KERN_INFO "rs_ioctl: TIOCSERCONFIG called\n");
  307. return -EINVAL;
  308. case TIOCSERGETLSR: /* Get line status register */
  309. printk(KERN_INFO "rs_ioctl: TIOCSERGETLSR called\n");
  310. return -EINVAL;
  311. case TIOCSERGSTRUCT:
  312. printk(KERN_INFO "rs_ioctl: TIOCSERGSTRUCT called\n");
  313. #if 0
  314. if (copy_to_user((struct async_struct *) arg,
  315. info, sizeof(struct async_struct)))
  316. return -EFAULT;
  317. #endif
  318. return 0;
  319. /*
  320. * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
  321. * - mask passed in arg for lines of interest
  322. * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
  323. * Caller should use TIOCGICOUNT to see which one it was
  324. */
  325. case TIOCMIWAIT:
  326. printk(KERN_INFO "rs_ioctl: TIOCMIWAIT: called\n");
  327. return 0;
  328. case TIOCSERGWILD:
  329. case TIOCSERSWILD:
  330. /* "setserial -W" is called in Debian boot */
  331. printk (KERN_INFO "TIOCSER?WILD ioctl obsolete, ignored.\n");
  332. return 0;
  333. default:
  334. return -ENOIOCTLCMD;
  335. }
  336. return 0;
  337. }
  338. #define RELEVANT_IFLAG(iflag) (iflag & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK))
  339. static void rs_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
  340. {
  341. /* Handle turning off CRTSCTS */
  342. if ((old_termios->c_cflag & CRTSCTS) &&
  343. !(tty->termios->c_cflag & CRTSCTS)) {
  344. tty->hw_stopped = 0;
  345. rs_start(tty);
  346. }
  347. }
  348. /*
  349. * This routine will shutdown a serial port; interrupts are disabled, and
  350. * DTR is dropped if the hangup on close termio flag is on.
  351. */
  352. static void shutdown(struct tty_struct *tty, struct serial_state *info)
  353. {
  354. unsigned long flags;
  355. if (!(info->tport.flags & ASYNC_INITIALIZED))
  356. return;
  357. #ifdef SIMSERIAL_DEBUG
  358. printk("Shutting down serial port %d (irq %d)...\n", info->line,
  359. info->irq);
  360. #endif
  361. local_irq_save(flags);
  362. {
  363. if (info->irq)
  364. free_irq(info->irq, info);
  365. if (info->xmit.buf) {
  366. free_page((unsigned long) info->xmit.buf);
  367. info->xmit.buf = NULL;
  368. }
  369. set_bit(TTY_IO_ERROR, &tty->flags);
  370. info->tport.flags &= ~ASYNC_INITIALIZED;
  371. }
  372. local_irq_restore(flags);
  373. }
  374. /*
  375. * ------------------------------------------------------------
  376. * rs_close()
  377. *
  378. * This routine is called when the serial port gets closed. First, we
  379. * wait for the last remaining data to be sent. Then, we unlink its
  380. * async structure from the interrupt chain if necessary, and we free
  381. * that IRQ if nothing is left in the chain.
  382. * ------------------------------------------------------------
  383. */
  384. static void rs_close(struct tty_struct *tty, struct file * filp)
  385. {
  386. struct serial_state *info = tty->driver_data;
  387. unsigned long flags;
  388. if (!info)
  389. return;
  390. local_irq_save(flags);
  391. if (tty_hung_up_p(filp)) {
  392. #ifdef SIMSERIAL_DEBUG
  393. printk("rs_close: hung_up\n");
  394. #endif
  395. local_irq_restore(flags);
  396. return;
  397. }
  398. #ifdef SIMSERIAL_DEBUG
  399. printk("rs_close ttys%d, count = %d\n", info->line, info->tport.count);
  400. #endif
  401. if ((tty->count == 1) && (info->tport.count != 1)) {
  402. /*
  403. * Uh, oh. tty->count is 1, which means that the tty
  404. * structure will be freed. info->tport.count should always
  405. * be one in these conditions. If it's greater than
  406. * one, we've got real problems, since it means the
  407. * serial port won't be shutdown.
  408. */
  409. printk(KERN_ERR "rs_close: bad serial port count; tty->count is 1, "
  410. "info->tport.count is %d\n", info->tport.count);
  411. info->tport.count = 1;
  412. }
  413. if (--info->tport.count < 0) {
  414. printk(KERN_ERR "rs_close: bad serial port count for ttys%d: %d\n",
  415. tty->index, info->tport.count);
  416. info->tport.count = 0;
  417. }
  418. if (info->tport.count) {
  419. local_irq_restore(flags);
  420. return;
  421. }
  422. info->tport.flags |= ASYNC_CLOSING;
  423. local_irq_restore(flags);
  424. /*
  425. * Now we wait for the transmit buffer to clear; and we notify
  426. * the line discipline to only process XON/XOFF characters.
  427. */
  428. shutdown(tty, info);
  429. rs_flush_buffer(tty);
  430. tty_ldisc_flush(tty);
  431. info->tport.tty = NULL;
  432. if (info->tport.blocked_open) {
  433. if (info->tport.close_delay)
  434. schedule_timeout_interruptible(info->tport.close_delay);
  435. wake_up_interruptible(&info->tport.open_wait);
  436. }
  437. info->tport.flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
  438. wake_up_interruptible(&info->tport.close_wait);
  439. }
  440. /*
  441. * rs_wait_until_sent() --- wait until the transmitter is empty
  442. */
  443. static void rs_wait_until_sent(struct tty_struct *tty, int timeout)
  444. {
  445. }
  446. /*
  447. * rs_hangup() --- called by tty_hangup() when a hangup is signaled.
  448. */
  449. static void rs_hangup(struct tty_struct *tty)
  450. {
  451. struct serial_state *info = tty->driver_data;
  452. #ifdef SIMSERIAL_DEBUG
  453. printk("rs_hangup: called\n");
  454. #endif
  455. rs_flush_buffer(tty);
  456. if (info->tport.flags & ASYNC_CLOSING)
  457. return;
  458. shutdown(tty, info);
  459. info->tport.count = 0;
  460. info->tport.flags &= ~ASYNC_NORMAL_ACTIVE;
  461. info->tport.tty = NULL;
  462. wake_up_interruptible(&info->tport.open_wait);
  463. }
  464. static int startup(struct tty_struct *tty, struct serial_state *state)
  465. {
  466. struct tty_port *port = &state->tport;
  467. unsigned long flags;
  468. int retval=0;
  469. unsigned long page;
  470. page = get_zeroed_page(GFP_KERNEL);
  471. if (!page)
  472. return -ENOMEM;
  473. local_irq_save(flags);
  474. if (port->flags & ASYNC_INITIALIZED) {
  475. free_page(page);
  476. goto errout;
  477. }
  478. if (state->xmit.buf)
  479. free_page(page);
  480. else
  481. state->xmit.buf = (unsigned char *) page;
  482. #ifdef SIMSERIAL_DEBUG
  483. printk("startup: ttys%d (irq %d)...", state->line, state->irq);
  484. #endif
  485. /*
  486. * Allocate the IRQ if necessary
  487. */
  488. if (state->irq) {
  489. retval = request_irq(state->irq, rs_interrupt_single, 0,
  490. "simserial", state);
  491. if (retval)
  492. goto errout;
  493. }
  494. clear_bit(TTY_IO_ERROR, &tty->flags);
  495. state->xmit.head = state->xmit.tail = 0;
  496. #if 0
  497. /*
  498. * Set up serial timers...
  499. */
  500. timer_table[RS_TIMER].expires = jiffies + 2*HZ/100;
  501. timer_active |= 1 << RS_TIMER;
  502. #endif
  503. /*
  504. * Set up the tty->alt_speed kludge
  505. */
  506. if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
  507. tty->alt_speed = 57600;
  508. if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
  509. tty->alt_speed = 115200;
  510. if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
  511. tty->alt_speed = 230400;
  512. if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
  513. tty->alt_speed = 460800;
  514. port->flags |= ASYNC_INITIALIZED;
  515. local_irq_restore(flags);
  516. return 0;
  517. errout:
  518. local_irq_restore(flags);
  519. return retval;
  520. }
  521. /*
  522. * This routine is called whenever a serial port is opened. It
  523. * enables interrupts for a serial port, linking in its async structure into
  524. * the IRQ chain. It also performs the serial-specific
  525. * initialization for the tty structure.
  526. */
  527. static int rs_open(struct tty_struct *tty, struct file * filp)
  528. {
  529. struct serial_state *info = rs_table + tty->index;
  530. int retval;
  531. info->tport.count++;
  532. info->tport.tty = tty;
  533. tty->driver_data = info;
  534. tty->port = &info->tport;
  535. #ifdef SIMSERIAL_DEBUG
  536. printk("rs_open %s, count = %d\n", tty->name, info->tport.count);
  537. #endif
  538. tty->low_latency = (info->tport.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
  539. /*
  540. * If the port is the middle of closing, bail out now
  541. */
  542. if (tty_hung_up_p(filp) || (info->tport.flags & ASYNC_CLOSING)) {
  543. if (info->tport.flags & ASYNC_CLOSING)
  544. interruptible_sleep_on(&info->tport.close_wait);
  545. #ifdef SERIAL_DO_RESTART
  546. return ((info->tport.flags & ASYNC_HUP_NOTIFY) ?
  547. -EAGAIN : -ERESTARTSYS);
  548. #else
  549. return -EAGAIN;
  550. #endif
  551. }
  552. /*
  553. * Start up serial port
  554. */
  555. retval = startup(tty, info);
  556. if (retval) {
  557. return retval;
  558. }
  559. /*
  560. * figure out which console to use (should be one already)
  561. */
  562. console = console_drivers;
  563. while (console) {
  564. if ((console->flags & CON_ENABLED) && console->write) break;
  565. console = console->next;
  566. }
  567. #ifdef SIMSERIAL_DEBUG
  568. printk("rs_open ttys%d successful\n", info->line);
  569. #endif
  570. return 0;
  571. }
  572. /*
  573. * /proc fs routines....
  574. */
  575. static int rs_proc_show(struct seq_file *m, void *v)
  576. {
  577. int i;
  578. seq_printf(m, "simserinfo:1.0 driver:%s\n", serial_version);
  579. for (i = 0; i < NR_PORTS; i++)
  580. seq_printf(m, "%d: uart:16550 port:3F8 irq:%d\n",
  581. i, rs_table[i].irq);
  582. return 0;
  583. }
  584. static int rs_proc_open(struct inode *inode, struct file *file)
  585. {
  586. return single_open(file, rs_proc_show, NULL);
  587. }
  588. static const struct file_operations rs_proc_fops = {
  589. .owner = THIS_MODULE,
  590. .open = rs_proc_open,
  591. .read = seq_read,
  592. .llseek = seq_lseek,
  593. .release = single_release,
  594. };
  595. /*
  596. * ---------------------------------------------------------------------
  597. * rs_init() and friends
  598. *
  599. * rs_init() is called at boot-time to initialize the serial driver.
  600. * ---------------------------------------------------------------------
  601. */
  602. /*
  603. * This routine prints out the appropriate serial driver version
  604. * number, and identifies which options were configured into this
  605. * driver.
  606. */
  607. static inline void show_serial_version(void)
  608. {
  609. printk(KERN_INFO "%s version %s with", serial_name, serial_version);
  610. printk(KERN_INFO " no serial options enabled\n");
  611. }
  612. static const struct tty_operations hp_ops = {
  613. .open = rs_open,
  614. .close = rs_close,
  615. .write = rs_write,
  616. .put_char = rs_put_char,
  617. .flush_chars = rs_flush_chars,
  618. .write_room = rs_write_room,
  619. .chars_in_buffer = rs_chars_in_buffer,
  620. .flush_buffer = rs_flush_buffer,
  621. .ioctl = rs_ioctl,
  622. .throttle = rs_throttle,
  623. .unthrottle = rs_unthrottle,
  624. .send_xchar = rs_send_xchar,
  625. .set_termios = rs_set_termios,
  626. .stop = rs_stop,
  627. .start = rs_start,
  628. .hangup = rs_hangup,
  629. .wait_until_sent = rs_wait_until_sent,
  630. .proc_fops = &rs_proc_fops,
  631. };
  632. /*
  633. * The serial driver boot-time initialization code!
  634. */
  635. static int __init simrs_init(void)
  636. {
  637. struct serial_state *state;
  638. int retval;
  639. if (!ia64_platform_is("hpsim"))
  640. return -ENODEV;
  641. hp_simserial_driver = alloc_tty_driver(NR_PORTS);
  642. if (!hp_simserial_driver)
  643. return -ENOMEM;
  644. show_serial_version();
  645. /* Initialize the tty_driver structure */
  646. hp_simserial_driver->driver_name = "simserial";
  647. hp_simserial_driver->name = "ttyS";
  648. hp_simserial_driver->major = TTY_MAJOR;
  649. hp_simserial_driver->minor_start = 64;
  650. hp_simserial_driver->type = TTY_DRIVER_TYPE_SERIAL;
  651. hp_simserial_driver->subtype = SERIAL_TYPE_NORMAL;
  652. hp_simserial_driver->init_termios = tty_std_termios;
  653. hp_simserial_driver->init_termios.c_cflag =
  654. B9600 | CS8 | CREAD | HUPCL | CLOCAL;
  655. hp_simserial_driver->flags = TTY_DRIVER_REAL_RAW;
  656. tty_set_operations(hp_simserial_driver, &hp_ops);
  657. /*
  658. * Let's have a little bit of fun !
  659. */
  660. state = rs_table;
  661. tty_port_init(&state->tport);
  662. state->tport.close_delay = 0; /* XXX really 0? */
  663. retval = hpsim_get_irq(KEYBOARD_INTR);
  664. if (retval < 0) {
  665. printk(KERN_ERR "%s: out of interrupt vectors!\n",
  666. __func__);
  667. goto err_free_tty;
  668. }
  669. state->irq = retval;
  670. /* the port is imaginary */
  671. printk(KERN_INFO "ttyS0 at 0x03f8 (irq = %d) is a 16550\n", state->irq);
  672. retval = tty_register_driver(hp_simserial_driver);
  673. if (retval) {
  674. printk(KERN_ERR "Couldn't register simserial driver\n");
  675. goto err_free_tty;
  676. }
  677. return 0;
  678. err_free_tty:
  679. put_tty_driver(hp_simserial_driver);
  680. return retval;
  681. }
  682. #ifndef MODULE
  683. __initcall(simrs_init);
  684. #endif