uarti8250.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741
  1. #include "u.h"
  2. #include "../port/lib.h"
  3. #include "mem.h"
  4. #include "dat.h"
  5. #include "fns.h"
  6. #include "io.h"
  7. #include "../port/error.h"
  8. /*
  9. * 8250 UART and compatibles.
  10. */
  11. enum {
  12. Uart0 = 0x3F8, /* COM1 */
  13. Uart0IRQ = 4,
  14. Uart1 = 0x2F8, /* COM2 */
  15. Uart1IRQ = 3,
  16. UartFREQ = 1843200,
  17. };
  18. enum { /* I/O ports */
  19. Rbr = 0, /* Receiver Buffer (RO) */
  20. Thr = 0, /* Transmitter Holding (WO) */
  21. Ier = 1, /* Interrupt Enable */
  22. Iir = 2, /* Interrupt Identification (RO) */
  23. Fcr = 2, /* FIFO Control (WO) */
  24. Lcr = 3, /* Line Control */
  25. Mcr = 4, /* Modem Control */
  26. Lsr = 5, /* Line Status */
  27. Msr = 6, /* Modem Status */
  28. Scr = 7, /* Scratch Pad */
  29. Dll = 0, /* Divisor Latch LSB */
  30. Dlm = 1, /* Divisor Latch MSB */
  31. };
  32. enum { /* Ier */
  33. Erda = 0x01, /* Enable Received Data Available */
  34. Ethre = 0x02, /* Enable Thr Empty */
  35. Erls = 0x04, /* Enable Receiver Line Status */
  36. Ems = 0x08, /* Enable Modem Status */
  37. };
  38. enum { /* Iir */
  39. Ims = 0x00, /* Ms interrupt */
  40. Ip = 0x01, /* Interrupt Pending (not) */
  41. Ithre = 0x02, /* Thr Empty */
  42. Irda = 0x04, /* Received Data Available */
  43. Irls = 0x06, /* Receiver Line Status */
  44. Ictoi = 0x0C, /* Character Time-out Indication */
  45. IirMASK = 0x3F,
  46. Ifena = 0xC0, /* FIFOs enabled */
  47. };
  48. enum { /* Fcr */
  49. FIFOena = 0x01, /* FIFO enable */
  50. FIFOrclr = 0x02, /* clear Rx FIFO */
  51. FIFOtclr = 0x04, /* clear Tx FIFO */
  52. FIFO1 = 0x00, /* Rx FIFO trigger level 1 byte */
  53. FIFO4 = 0x40, /* 4 bytes */
  54. FIFO8 = 0x80, /* 8 bytes */
  55. FIFO14 = 0xC0, /* 14 bytes */
  56. };
  57. enum { /* Lcr */
  58. Wls5 = 0x00, /* Word Length Select 5 bits/byte */
  59. Wls6 = 0x01, /* 6 bits/byte */
  60. Wls7 = 0x02, /* 7 bits/byte */
  61. Wls8 = 0x03, /* 8 bits/byte */
  62. WlsMASK = 0x03,
  63. Stb = 0x04, /* 2 stop bits */
  64. Pen = 0x08, /* Parity Enable */
  65. Eps = 0x10, /* Even Parity Select */
  66. Stp = 0x20, /* Stick Parity */
  67. Brk = 0x40, /* Break */
  68. Dlab = 0x80, /* Divisor Latch Access Bit */
  69. };
  70. enum { /* Mcr */
  71. Dtr = 0x01, /* Data Terminal Ready */
  72. Rts = 0x02, /* Ready To Send */
  73. Out1 = 0x04, /* no longer in use */
  74. Ie = 0x08, /* IRQ Enable */
  75. Dm = 0x10, /* Diagnostic Mode loopback */
  76. };
  77. enum { /* Lsr */
  78. Dr = 0x01, /* Data Ready */
  79. Oe = 0x02, /* Overrun Error */
  80. Pe = 0x04, /* Parity Error */
  81. Fe = 0x08, /* Framing Error */
  82. Bi = 0x10, /* Break Interrupt */
  83. Thre = 0x20, /* Thr Empty */
  84. Temt = 0x40, /* Tramsmitter Empty */
  85. FIFOerr = 0x80, /* error in receiver FIFO */
  86. };
  87. enum { /* Msr */
  88. Dcts = 0x01, /* Delta Cts */
  89. Ddsr = 0x02, /* Delta Dsr */
  90. Teri = 0x04, /* Trailing Edge of Ri */
  91. Ddcd = 0x08, /* Delta Dcd */
  92. Cts = 0x10, /* Clear To Send */
  93. Dsr = 0x20, /* Data Set Ready */
  94. Ri = 0x40, /* Ring Indicator */
  95. Dcd = 0x80, /* Data Set Ready */
  96. };
  97. typedef struct Ctlr {
  98. int io;
  99. int irq;
  100. int tbdf;
  101. int iena;
  102. uchar sticky[8];
  103. Lock;
  104. int hasfifo;
  105. int checkfifo;
  106. int fena;
  107. } Ctlr;
  108. extern PhysUart i8250physuart;
  109. static Ctlr i8250ctlr[2] = {
  110. { .io = Uart0,
  111. .irq = Uart0IRQ,
  112. .tbdf = BUSUNKNOWN, },
  113. { .io = Uart1,
  114. .irq = Uart1IRQ,
  115. .tbdf = BUSUNKNOWN, },
  116. };
  117. static Uart i8250uart[2] = {
  118. { .regs = &i8250ctlr[0],
  119. .name = "COM1",
  120. .freq = UartFREQ,
  121. .phys = &i8250physuart,
  122. .special= 0,
  123. .next = &i8250uart[1], },
  124. { .regs = &i8250ctlr[1],
  125. .name = "COM2",
  126. .freq = UartFREQ,
  127. .phys = &i8250physuart,
  128. .special= 0,
  129. .next = nil, },
  130. };
  131. #define csr8r(c, r) inb((c)->io+(r))
  132. #define csr8w(c, r, v) outb((c)->io+(r), (c)->sticky[(r)]|(v))
  133. static long
  134. i8250status(Uart* uart, void* buf, long n, long offset)
  135. {
  136. char *p;
  137. Ctlr *ctlr;
  138. uchar ier, lcr, mcr, msr;
  139. p = malloc(READSTR);
  140. if(p == nil)
  141. error(Enomem);
  142. ctlr = uart->regs;
  143. mcr = ctlr->sticky[Mcr];
  144. msr = csr8r(ctlr, Msr);
  145. ier = ctlr->sticky[Ier];
  146. lcr = ctlr->sticky[Lcr];
  147. snprint(p, READSTR,
  148. "b%d c%d d%d e%d l%d m%d p%c r%d s%d i%d\n"
  149. "dev(%d) type(%d) framing(%d) overruns(%d) "
  150. "berr(%d) serr(%d)%s%s%s%s\n",
  151. uart->baud,
  152. uart->hup_dcd,
  153. (msr & Dsr) != 0,
  154. uart->hup_dsr,
  155. (lcr & WlsMASK) + 5,
  156. (ier & Ems) != 0,
  157. (lcr & Pen) ? ((lcr & Eps) ? 'e': 'o'): 'n',
  158. (mcr & Rts) != 0,
  159. (lcr & Stb) ? 2: 1,
  160. ctlr->fena,
  161. uart->dev,
  162. uart->type,
  163. uart->ferr,
  164. uart->oerr,
  165. uart->berr,
  166. uart->serr,
  167. (msr & Cts) ? " cts": "",
  168. (msr & Dsr) ? " dsr": "",
  169. (msr & Dcd) ? " dcd": "",
  170. (msr & Ri) ? " ring": ""
  171. );
  172. n = readstr(offset, buf, n, p);
  173. free(p);
  174. return n;
  175. }
  176. static void
  177. i8250fifo(Uart* uart, int level)
  178. {
  179. Ctlr *ctlr;
  180. ctlr = uart->regs;
  181. if(ctlr->hasfifo == 0)
  182. return;
  183. /*
  184. * Changing the FIFOena bit in Fcr flushes data
  185. * from both receive and transmit FIFOs; there's
  186. * no easy way to guarantee not losing data on
  187. * the receive side, but it's possible to wait until
  188. * the transmitter is really empty.
  189. */
  190. ilock(ctlr);
  191. while(!(csr8r(ctlr, Lsr) & Temt))
  192. ;
  193. /*
  194. * Set the trigger level, default is the max.
  195. * value.
  196. * Some UARTs require FIFOena to be set before
  197. * other bits can take effect, so set it twice.
  198. */
  199. ctlr->fena = level;
  200. switch(level){
  201. case 0:
  202. break;
  203. case 1:
  204. level = FIFO1|FIFOena;
  205. break;
  206. case 4:
  207. level = FIFO4|FIFOena;
  208. break;
  209. case 8:
  210. level = FIFO8|FIFOena;
  211. break;
  212. default:
  213. level = FIFO14|FIFOena;
  214. break;
  215. }
  216. csr8w(ctlr, Fcr, level);
  217. csr8w(ctlr, Fcr, level);
  218. iunlock(ctlr);
  219. }
  220. static void
  221. i8250dtr(Uart* uart, int on)
  222. {
  223. Ctlr *ctlr;
  224. /*
  225. * Toggle DTR.
  226. */
  227. ctlr = uart->regs;
  228. if(on)
  229. ctlr->sticky[Mcr] |= Dtr;
  230. else
  231. ctlr->sticky[Mcr] &= ~Dtr;
  232. csr8w(ctlr, Mcr, 0);
  233. }
  234. static void
  235. i8250rts(Uart* uart, int on)
  236. {
  237. Ctlr *ctlr;
  238. /*
  239. * Toggle RTS.
  240. */
  241. ctlr = uart->regs;
  242. if(on)
  243. ctlr->sticky[Mcr] |= Rts;
  244. else
  245. ctlr->sticky[Mcr] &= ~Rts;
  246. csr8w(ctlr, Mcr, 0);
  247. }
  248. static void
  249. i8250modemctl(Uart* uart, int on)
  250. {
  251. Ctlr *ctlr;
  252. ctlr = uart->regs;
  253. ilock(&uart->tlock);
  254. if(on){
  255. ctlr->sticky[Ier] |= Ems;
  256. csr8w(ctlr, Ier, ctlr->sticky[Ier]);
  257. uart->modem = 1;
  258. uart->cts = csr8r(ctlr, Msr) & Cts;
  259. }
  260. else{
  261. ctlr->sticky[Ier] &= ~Ems;
  262. csr8w(ctlr, Ier, ctlr->sticky[Ier]);
  263. uart->modem = 0;
  264. uart->cts = 1;
  265. }
  266. iunlock(&uart->tlock);
  267. /* modem needs fifo */
  268. (*uart->phys->fifo)(uart, on);
  269. }
  270. static int
  271. i8250parity(Uart* uart, int parity)
  272. {
  273. int lcr;
  274. Ctlr *ctlr;
  275. ctlr = uart->regs;
  276. lcr = ctlr->sticky[Lcr] & ~(Eps|Pen);
  277. switch(parity){
  278. case 'e':
  279. lcr |= Eps|Pen;
  280. break;
  281. case 'o':
  282. lcr |= Pen;
  283. break;
  284. case 'n':
  285. break;
  286. default:
  287. return -1;
  288. }
  289. ctlr->sticky[Lcr] = lcr;
  290. csr8w(ctlr, Lcr, 0);
  291. uart->parity = parity;
  292. return 0;
  293. }
  294. static int
  295. i8250stop(Uart* uart, int stop)
  296. {
  297. int lcr;
  298. Ctlr *ctlr;
  299. ctlr = uart->regs;
  300. lcr = ctlr->sticky[Lcr] & ~Stb;
  301. switch(stop){
  302. case 1:
  303. break;
  304. case 2:
  305. lcr |= Stb;
  306. break;
  307. default:
  308. return -1;
  309. }
  310. ctlr->sticky[Lcr] = lcr;
  311. csr8w(ctlr, Lcr, 0);
  312. uart->stop = stop;
  313. return 0;
  314. }
  315. static int
  316. i8250bits(Uart* uart, int bits)
  317. {
  318. int lcr;
  319. Ctlr *ctlr;
  320. ctlr = uart->regs;
  321. lcr = ctlr->sticky[Lcr] & ~WlsMASK;
  322. switch(bits){
  323. case 5:
  324. lcr |= Wls5;
  325. break;
  326. case 6:
  327. lcr |= Wls6;
  328. break;
  329. case 7:
  330. lcr |= Wls7;
  331. break;
  332. case 8:
  333. lcr |= Wls8;
  334. break;
  335. default:
  336. return -1;
  337. }
  338. ctlr->sticky[Lcr] = lcr;
  339. csr8w(ctlr, Lcr, 0);
  340. uart->bits = bits;
  341. return 0;
  342. }
  343. static int
  344. i8250baud(Uart* uart, int baud)
  345. {
  346. ulong bgc;
  347. Ctlr *ctlr;
  348. /*
  349. * Set the Baud rate by calculating and setting the Baud rate
  350. * Generator Constant. This will work with fairly non-standard
  351. * Baud rates.
  352. */
  353. if(uart->freq == 0 || baud <= 0)
  354. return -1;
  355. bgc = (uart->freq+8*baud-1)/(16*baud);
  356. ctlr = uart->regs;
  357. csr8w(ctlr, Lcr, Dlab);
  358. outb(ctlr->io+Dlm, bgc>>8);
  359. outb(ctlr->io+Dll, bgc);
  360. csr8w(ctlr, Lcr, 0);
  361. uart->baud = baud;
  362. return 0;
  363. }
  364. static void
  365. i8250break(Uart* uart, int ms)
  366. {
  367. Ctlr *ctlr;
  368. /*
  369. * Send a break.
  370. */
  371. if(ms <= 0)
  372. ms = 200;
  373. ctlr = uart->regs;
  374. csr8w(ctlr, Lcr, Brk);
  375. tsleep(&up->sleep, return0, 0, ms);
  376. csr8w(ctlr, Lcr, 0);
  377. }
  378. static void
  379. i8250kick(Uart* uart)
  380. {
  381. int i;
  382. Ctlr *ctlr;
  383. if(uart->cts == 0 || uart->blocked)
  384. return;
  385. /*
  386. * 128 here is an arbitrary limit to make sure
  387. * we don't stay in this loop too long. If the
  388. * chip's output queue is longer than 128, too
  389. * bad -- presotto
  390. */
  391. ctlr = uart->regs;
  392. for(i = 0; i < 128; i++){
  393. if(!(csr8r(ctlr, Lsr) & Thre))
  394. break;
  395. if(uart->op >= uart->oe && uartstageoutput(uart) == 0)
  396. break;
  397. outb(ctlr->io+Thr, *(uart->op++));
  398. }
  399. }
  400. static void
  401. i8250interrupt(Ureg*, void* arg)
  402. {
  403. Ctlr *ctlr;
  404. Uart *uart;
  405. int iir, lsr, old, r;
  406. uart = arg;
  407. ctlr = uart->regs;
  408. for(iir = csr8r(ctlr, Iir); !(iir & Ip); iir = csr8r(ctlr, Iir)){
  409. switch(iir & IirMASK){
  410. case Ims: /* Ms interrupt */
  411. r = csr8r(ctlr, Msr);
  412. if(r & Dcts){
  413. ilock(&uart->tlock);
  414. old = uart->cts;
  415. uart->cts = r & Cts;
  416. if(old == 0 && uart->cts)
  417. uart->ctsbackoff = 2;
  418. iunlock(&uart->tlock);
  419. }
  420. if(r & Ddsr){
  421. old = r & Dsr;
  422. if(uart->hup_dsr && uart->dsr && !old)
  423. uart->dohup = 1;
  424. uart->dsr = old;
  425. }
  426. if(r & Ddcd){
  427. old = r & Dcd;
  428. if(uart->hup_dcd && uart->dcd && !old)
  429. uart->dohup = 1;
  430. uart->dcd = old;
  431. }
  432. break;
  433. case Ithre: /* Thr Empty */
  434. uartkick(uart);
  435. break;
  436. case Irda: /* Received Data Available */
  437. case Irls: /* Receiver Line Status */
  438. case Ictoi: /* Character Time-out Indication */
  439. /*
  440. * Consume any received data.
  441. * If the received byte came in with a break,
  442. * parity or framing error, throw it away;
  443. * overrun is an indication that something has
  444. * already been tossed.
  445. */
  446. while((lsr = csr8r(ctlr, Lsr)) & Dr){
  447. if(lsr & (FIFOerr|Oe))
  448. uart->oerr++;
  449. if(lsr & Pe)
  450. uart->perr++;
  451. if(lsr & Fe)
  452. uart->ferr++;
  453. r = csr8r(ctlr, Rbr);
  454. if(!(lsr & (Bi|Fe|Pe)))
  455. uartrecv(uart, r);
  456. }
  457. break;
  458. default:
  459. iprint("weird uart interrupt 0x%2.2uX\n", iir);
  460. break;
  461. }
  462. }
  463. }
  464. static void
  465. i8250disable(Uart* uart)
  466. {
  467. Ctlr *ctlr;
  468. /*
  469. * Turn off DTR and RTS, disable interrupts and fifos.
  470. */
  471. (*uart->phys->dtr)(uart, 0);
  472. (*uart->phys->rts)(uart, 0);
  473. (*uart->phys->fifo)(uart, 0);
  474. ctlr = uart->regs;
  475. ctlr->sticky[Ier] = 0;
  476. csr8w(ctlr, Ier, ctlr->sticky[Ier]);
  477. if(ctlr->iena != 0){
  478. if(intrdisable(ctlr->irq, i8250interrupt, uart, ctlr->tbdf, uart->name) == 0)
  479. ctlr->iena = 0;
  480. }
  481. }
  482. static void
  483. i8250enable(Uart* uart, int ie)
  484. {
  485. Ctlr *ctlr;
  486. ctlr = uart->regs;
  487. /*
  488. * Check if there is a FIFO.
  489. * Changing the FIFOena bit in Fcr flushes data
  490. * from both receive and transmit FIFOs; there's
  491. * no easy way to guarantee not losing data on
  492. * the receive side, but it's possible to wait until
  493. * the transmitter is really empty.
  494. * Also, reading the Iir outwith i8250interrupt()
  495. * can be dangerous, but this should only happen
  496. * once before interrupts are enabled.
  497. */
  498. ilock(ctlr);
  499. if(!ctlr->checkfifo){
  500. /*
  501. * Wait until the transmitter is really empty.
  502. */
  503. while(!(csr8r(ctlr, Lsr) & Temt))
  504. ;
  505. csr8w(ctlr, Fcr, FIFOena);
  506. if(csr8r(ctlr, Iir) & Ifena)
  507. ctlr->hasfifo = 1;
  508. csr8w(ctlr, Fcr, 0);
  509. ctlr->checkfifo = 1;
  510. }
  511. iunlock(ctlr);
  512. /*
  513. * Enable interrupts and turn on DTR and RTS.
  514. * Be careful if this is called to set up a polled serial line
  515. * early on not to try to enable interrupts as interrupt-
  516. * -enabling mechanisms might not be set up yet.
  517. */
  518. if(ie){
  519. if(ctlr->iena == 0){
  520. intrenable(ctlr->irq, i8250interrupt, uart, ctlr->tbdf, uart->name);
  521. ctlr->iena = 1;
  522. }
  523. ctlr->sticky[Ier] = Ethre|Erda;
  524. ctlr->sticky[Mcr] |= Ie;
  525. }
  526. else{
  527. ctlr->sticky[Ier] = 0;
  528. ctlr->sticky[Mcr] = 0;
  529. }
  530. csr8w(ctlr, Ier, ctlr->sticky[Ier]);
  531. csr8w(ctlr, Mcr, ctlr->sticky[Mcr]);
  532. (*uart->phys->dtr)(uart, 1);
  533. (*uart->phys->rts)(uart, 1);
  534. /*
  535. * During startup, the i8259 interrupt controller is reset.
  536. * This may result in a lost interrupt from the i8250 uart.
  537. * The i8250 thinks the interrupt is still outstanding and does not
  538. * generate any further interrupts. The workaround is to call the
  539. * interrupt handler to clear any pending interrupt events.
  540. * Note: this must be done after setting Ier.
  541. */
  542. if(ie)
  543. i8250interrupt(nil, uart);
  544. }
  545. void*
  546. i8250alloc(int io, int irq, int tbdf)
  547. {
  548. Ctlr *ctlr;
  549. if((ctlr = malloc(sizeof(Ctlr))) != nil){
  550. ctlr->io = io;
  551. ctlr->irq = irq;
  552. ctlr->tbdf = tbdf;
  553. }
  554. return ctlr;
  555. }
  556. static Uart*
  557. i8250pnp(void)
  558. {
  559. return i8250uart;
  560. }
  561. static int
  562. i8250getc(Uart *uart)
  563. {
  564. Ctlr *ctlr;
  565. ctlr = uart->regs;
  566. while(!(csr8r(ctlr, Lsr)&Dr))
  567. delay(1);
  568. return csr8r(ctlr, Rbr);
  569. }
  570. static void
  571. i8250putc(Uart *uart, int c)
  572. {
  573. int i;
  574. Ctlr *ctlr;
  575. ctlr = uart->regs;
  576. for(i = 0; !(csr8r(ctlr, Lsr)&Thre) && i < 128; i++)
  577. delay(1);
  578. outb(ctlr->io+Thr, c);
  579. for(i = 0; !(csr8r(ctlr, Lsr)&Thre) && i < 128; i++)
  580. delay(1);
  581. }
  582. PhysUart i8250physuart = {
  583. .name = "i8250",
  584. .pnp = i8250pnp,
  585. .enable = i8250enable,
  586. .disable = i8250disable,
  587. .kick = i8250kick,
  588. .dobreak = i8250break,
  589. .baud = i8250baud,
  590. .bits = i8250bits,
  591. .stop = i8250stop,
  592. .parity = i8250parity,
  593. .modemctl = i8250modemctl,
  594. .rts = i8250rts,
  595. .dtr = i8250dtr,
  596. .status = i8250status,
  597. .fifo = i8250fifo,
  598. .getc = i8250getc,
  599. .putc = i8250putc,
  600. };
  601. void
  602. i8250console(void)
  603. {
  604. Uart *uart;
  605. int n;
  606. char *cmd, *p;
  607. if((p = getconf("console")) == nil)
  608. return;
  609. n = strtoul(p, &cmd, 0);
  610. if(p == cmd)
  611. return;
  612. switch(n){
  613. default:
  614. return;
  615. case 0:
  616. uart = &i8250uart[0];
  617. break;
  618. case 1:
  619. uart = &i8250uart[1];
  620. break;
  621. }
  622. (*uart->phys->enable)(uart, 0);
  623. uartctl(uart, "b9600 l8 pn s1");
  624. if(*cmd != '\0')
  625. uartctl(uart, cmd);
  626. consuart = uart;
  627. uart->console = 1;
  628. }
  629. void
  630. i8250mouse(char* which, int (*putc)(Queue*, int), int setb1200)
  631. {
  632. char *p;
  633. int port;
  634. port = strtol(which, &p, 0);
  635. if(p == which || port < 0 || port > 1)
  636. error(Ebadarg);
  637. uartmouse(&i8250uart[port], putc, setb1200);
  638. }
  639. void
  640. i8250setmouseputc(char* which, int (*putc)(Queue*, int))
  641. {
  642. char *p;
  643. int port;
  644. port = strtol(which, &p, 0);
  645. if(p == which || port < 0 || port > 1)
  646. error(Ebadarg);
  647. uartsetmouseputc(&i8250uart[port], putc);
  648. }