This source file includes following definitions.
- sf_pci_match
- sf_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
32
33
34
35
36
37
38
39
40
41
42
43
44
45 #include <sys/param.h>
46 #include <sys/systm.h>
47 #include <sys/mbuf.h>
48 #include <sys/malloc.h>
49 #include <sys/kernel.h>
50 #include <sys/socket.h>
51 #include <sys/ioctl.h>
52 #include <sys/errno.h>
53 #include <sys/device.h>
54
55 #include <net/if.h>
56 #include <net/if_dl.h>
57 #include <net/if_types.h>
58
59 #ifdef INET
60 #include <netinet/in.h>
61 #include <netinet/in_systm.h>
62 #include <netinet/in_var.h>
63 #include <netinet/ip.h>
64 #include <netinet/if_ether.h>
65 #endif
66
67 #include <net/if_media.h>
68
69 #include <machine/bus.h>
70 #include <machine/intr.h>
71
72 #include <dev/mii/miivar.h>
73
74 #include <dev/ic/aic6915.h>
75
76 #include <dev/pci/pcireg.h>
77 #include <dev/pci/pcivar.h>
78 #include <dev/pci/pcidevs.h>
79
80 struct sf_pci_softc {
81 struct sf_softc sc_starfire;
82
83
84 void *sc_ih;
85 };
86
87 int sf_pci_match(struct device *, void *, void *);
88 void sf_pci_attach(struct device *, struct device *, void *);
89
90 struct cfattach sf_pci_ca = {
91 sizeof(struct sf_pci_softc), sf_pci_match, sf_pci_attach
92 };
93
94 const struct pci_matchid sf_pci_products[] = {
95 { PCI_VENDOR_ADP, PCI_PRODUCT_ADP_AIC6915 },
96 };
97
98 int
99 sf_pci_match(struct device *parent, void *match, void *aux)
100 {
101 return (pci_matchbyid((struct pci_attach_args *)aux, sf_pci_products,
102 sizeof(sf_pci_products)/sizeof(sf_pci_products[0])));
103 }
104
105 void
106 sf_pci_attach(struct device *parent, struct device *self, void *aux)
107 {
108 struct sf_pci_softc *psc = (void *) self;
109 struct sf_softc *sc = &psc->sc_starfire;
110 struct pci_attach_args *pa = aux;
111 pci_intr_handle_t ih;
112 const char *intrstr = NULL;
113 bus_space_tag_t iot, memt;
114 bus_space_handle_t ioh, memh;
115 pcireg_t reg;
116 int pmreg, ioh_valid, memh_valid;
117
118 if (pci_get_capability(pa->pa_pc, pa->pa_tag, PCI_CAP_PWRMGMT,
119 &pmreg, 0)) {
120 reg = pci_conf_read(pa->pa_pc, pa->pa_tag, pmreg + PCI_PMCSR);
121 switch (reg & PCI_PMCSR_STATE_MASK) {
122 case PCI_PMCSR_STATE_D1:
123 case PCI_PMCSR_STATE_D2:
124 printf(": waking up from power state D%d\n%s",
125 reg & PCI_PMCSR_STATE_MASK, sc->sc_dev.dv_xname);
126 pci_conf_write(pa->pa_pc, pa->pa_tag, pmreg + PCI_PMCSR,
127 (reg & ~PCI_PMCSR_STATE_MASK) |
128 PCI_PMCSR_STATE_D0);
129 break;
130
131 case PCI_PMCSR_STATE_D3:
132 printf("%s: unable to wake up from power state D3\n",
133 sc->sc_dev.dv_xname);
134 pci_conf_write(pa->pa_pc, pa->pa_tag, pmreg + PCI_PMCSR,
135 (reg & ~PCI_PMCSR_STATE_MASK) |
136 PCI_PMCSR_STATE_D0);
137 return;
138 }
139 }
140
141
142
143
144 reg = pci_mapreg_type(pa->pa_pc, pa->pa_tag, SF_PCI_MEMBA);
145 switch (reg) {
146 case PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_32BIT:
147 case PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_64BIT:
148 memh_valid = (pci_mapreg_map(pa, SF_PCI_MEMBA,
149 reg, 0, &memt, &memh, NULL, NULL, 0) == 0);
150 break;
151 default:
152 memh_valid = 0;
153 }
154
155 ioh_valid = (pci_mapreg_map(pa,
156 (reg == (PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_64BIT)) ?
157 SF_PCI_IOBA : SF_PCI_IOBA - 0x04,
158 PCI_MAPREG_TYPE_IO, 0,
159 &iot, &ioh, NULL, NULL, 0) == 0);
160
161 if (memh_valid) {
162 sc->sc_st = memt;
163 sc->sc_sh = memh;
164 sc->sc_iomapped = 0;
165 } else if (ioh_valid) {
166 sc->sc_st = iot;
167 sc->sc_sh = ioh;
168 sc->sc_iomapped = 1;
169 } else {
170 printf("%s: unable to map device registers\n",
171 sc->sc_dev.dv_xname);
172 return;
173 }
174
175 sc->sc_dmat = pa->pa_dmat;
176
177
178 pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
179 pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG) |
180 PCI_COMMAND_MASTER_ENABLE);
181
182
183
184
185 if (pci_intr_map(pa, &ih)) {
186 printf("%s: unable to map interrupt\n", sc->sc_dev.dv_xname);
187 return;
188 }
189 intrstr = pci_intr_string(pa->pa_pc, ih);
190 psc->sc_ih = pci_intr_establish(pa->pa_pc, ih, IPL_NET, sf_intr, sc,
191 self->dv_xname);
192 if (psc->sc_ih == NULL) {
193 printf("%s: unable to establish interrupt",
194 sc->sc_dev.dv_xname);
195 if (intrstr != NULL)
196 printf(" at %s", intrstr);
197 return;
198 }
199 printf(": %s", intrstr);
200
201
202
203
204 sf_attach(sc);
205 }