This source file includes following definitions.
- mtd_pci_match
- mtd_pci_attach
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31 #include <sys/param.h>
32 #include <sys/device.h>
33 #include <sys/systm.h>
34 #include <sys/socket.h>
35
36 #include <net/if.h>
37 #include <net/if_media.h>
38
39 #ifdef INET
40 #include <netinet/in.h>
41 #include <netinet/if_ether.h>
42 #endif
43
44 #include <machine/bus.h>
45
46 #include <dev/mii/miivar.h>
47
48 #include <dev/pci/pcidevs.h>
49 #include <dev/pci/pcireg.h>
50 #include <dev/pci/pcivar.h>
51
52 #include <dev/ic/mtd8xxreg.h>
53 #include <dev/ic/mtd8xxvar.h>
54
55 static int mtd_pci_match(struct device *, void *, void *);
56 static void mtd_pci_attach(struct device *, struct device *, void *);
57
58
59 struct cfattach mtd_pci_ca = {
60 sizeof(struct mtd_softc), mtd_pci_match, mtd_pci_attach
61 };
62
63 const static struct pci_matchid mtd_pci_devices[] = {
64 { PCI_VENDOR_MYSON, PCI_PRODUCT_MYSON_MTD800 },
65 { PCI_VENDOR_MYSON, PCI_PRODUCT_MYSON_MTD803 },
66 { PCI_VENDOR_MYSON, PCI_PRODUCT_MYSON_MTD891 },
67 };
68
69
70 static int
71 mtd_pci_match(struct device *parent, void *match, void *aux)
72 {
73 return (pci_matchbyid((struct pci_attach_args *)aux, mtd_pci_devices,
74 sizeof(mtd_pci_devices) / sizeof(mtd_pci_devices[0])));
75 }
76
77
78 static void
79 mtd_pci_attach(struct device *parent, struct device *self, void *aux)
80 {
81 struct mtd_softc *sc = (void *)self;
82 struct pci_attach_args *pa = aux;
83 pci_intr_handle_t ih;
84 const char *intrstr = NULL;
85 u_int32_t command;
86 bus_size_t iosize;
87
88 sc->sc_devid = PCI_PRODUCT(pa->pa_id);
89 command = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
90 if (sc->sc_devid == PCI_PRODUCT_MYSON_MTD800 &&
91 pci_conf_read(pa->pa_pc, pa->pa_tag, MTD_PCI_LOIO) & 0x300) {
92 pa->pa_flags &= ~PCI_FLAGS_IO_ENABLED;
93 command &= ~PCI_COMMAND_IO_ENABLE;
94 }
95 pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG, command);
96
97 command = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
98 if (command & PCI_COMMAND_MEM_ENABLE) {
99 if (pci_mapreg_map(pa, MTD_PCI_LOMEM, PCI_MAPREG_TYPE_MEM, 0,
100 &sc->sc_bust, &sc->sc_bush, NULL, &iosize, 0)) {
101 printf(": can't map mem space\n");
102 return;
103 }
104 } else {
105 if (pci_mapreg_map(pa, MTD_PCI_LOIO, PCI_MAPREG_TYPE_IO, 0,
106 &sc->sc_bust, &sc->sc_bush, NULL, &iosize, 0)) {
107 printf(": can't map io space\n");
108 return;
109 }
110 }
111
112
113
114
115 if (pci_intr_map(pa, &ih)) {
116 printf(": couldn't map interrupt\n");
117 bus_space_unmap(sc->sc_bust, sc->sc_bush, iosize);
118 return;
119 }
120
121 intrstr = pci_intr_string(pa->pa_pc, ih);
122 if (pci_intr_establish(pa->pa_pc, ih, IPL_NET, mtd_intr, sc,
123 self->dv_xname) == NULL) {
124 printf(": couldn't establish interrupt");
125 if (intrstr != NULL)
126 printf(" at %s", intrstr);
127 printf("\n");
128 bus_space_unmap(sc->sc_bust, sc->sc_bush, iosize);
129 return;
130 }
131 printf(": %s", intrstr);
132
133 sc->sc_dmat = pa->pa_dmat;
134 mtd_attach(sc);
135 }