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