simserial.c 19 KB

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