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