uartisa.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. extern PhysUart i8250physuart;
  9. extern PhysUart isaphysuart;
  10. extern void* i8250alloc(int, int, int);
  11. static Uart*
  12. uartisa(int ctlrno, ISAConf* isa)
  13. {
  14. int io;
  15. void *ctlr;
  16. Uart *uart;
  17. char buf[64];
  18. io = isa->port;
  19. snprint(buf, sizeof(buf), "%s%d", isaphysuart.name, ctlrno);
  20. if(ioalloc(io, 8, 0, buf) < 0){
  21. print("uartisa: I/O 0x%uX in use\n", io);
  22. return nil;
  23. }
  24. uart = malloc(sizeof(Uart));
  25. ctlr = i8250alloc(io, isa->irq, BUSUNKNOWN);
  26. if(ctlr == nil){
  27. iofree(io);
  28. free(uart);
  29. return nil;
  30. }
  31. uart->regs = ctlr;
  32. snprint(buf, sizeof(buf), "COM%d", ctlrno+1);
  33. kstrdup(&uart->name, buf);
  34. uart->freq = isa->freq;
  35. uart->phys = &i8250physuart;
  36. return uart;
  37. }
  38. static Uart*
  39. uartisapnp(void)
  40. {
  41. int ctlrno;
  42. ISAConf isa;
  43. Uart *head, *tail, *uart;
  44. /*
  45. * Look for up to 4 discrete UARTs on the ISA bus.
  46. * All suitable devices are configured to simply point
  47. * to the generic i8250 driver.
  48. */
  49. head = tail = nil;
  50. for(ctlrno = 2; ctlrno < 6; ctlrno++){
  51. memset(&isa, 0, sizeof(isa));
  52. if(!isaconfig("uart", ctlrno, &isa))
  53. continue;
  54. if(strcmp(isa.type, "isa") != 0)
  55. continue;
  56. if(isa.port == 0 || isa.irq == 0)
  57. continue;
  58. if(isa.freq == 0)
  59. isa.freq = 1843200;
  60. uart = uartisa(ctlrno, &isa);
  61. if(uart == nil)
  62. continue;
  63. if(head != nil)
  64. tail->next = uart;
  65. else
  66. head = uart;
  67. tail = uart;
  68. }
  69. return head;
  70. }
  71. PhysUart isaphysuart = {
  72. .name = "UartISA",
  73. .pnp = uartisapnp,
  74. .enable = nil,
  75. .disable = nil,
  76. .kick = nil,
  77. .dobreak = nil,
  78. .baud = nil,
  79. .bits = nil,
  80. .stop = nil,
  81. .parity = nil,
  82. .modemctl = nil,
  83. .rts = nil,
  84. .dtr = nil,
  85. .status = nil,
  86. .fifo = nil,
  87. };