uartisa.c 1.8 KB

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