pyro.c revision 1.4.2.4 1 1.4.2.2 rmind /* $NetBSD: pyro.c,v 1.4.2.4 2011/06/12 00:24:08 rmind Exp $ */
2 1.4.2.2 rmind /* from: $OpenBSD: pyro.c,v 1.20 2010/12/05 15:15:14 kettenis Exp $ */
3 1.4.2.2 rmind
4 1.4.2.2 rmind /*
5 1.4.2.2 rmind * Copyright (c) 2002 Jason L. Wright (jason (at) thought.net)
6 1.4.2.2 rmind * Copyright (c) 2003 Henric Jungheim
7 1.4.2.2 rmind * Copyright (c) 2007 Mark Kettenis
8 1.4.2.2 rmind * Copyright (c) 2011 Matthew R. Green
9 1.4.2.2 rmind * All rights reserved.
10 1.4.2.2 rmind *
11 1.4.2.2 rmind * Redistribution and use in source and binary forms, with or without
12 1.4.2.2 rmind * modification, are permitted provided that the following conditions
13 1.4.2.2 rmind * are met:
14 1.4.2.2 rmind * 1. Redistributions of source code must retain the above copyright
15 1.4.2.2 rmind * notice, this list of conditions and the following disclaimer.
16 1.4.2.2 rmind * 2. Redistributions in binary form must reproduce the above copyright
17 1.4.2.2 rmind * notice, this list of conditions and the following disclaimer in the
18 1.4.2.2 rmind * documentation and/or other materials provided with the distribution.
19 1.4.2.2 rmind *
20 1.4.2.2 rmind * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 1.4.2.2 rmind * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22 1.4.2.2 rmind * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 1.4.2.2 rmind * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
24 1.4.2.2 rmind * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25 1.4.2.2 rmind * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26 1.4.2.2 rmind * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 1.4.2.2 rmind * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
28 1.4.2.2 rmind * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29 1.4.2.2 rmind * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 1.4.2.2 rmind * POSSIBILITY OF SUCH DAMAGE.
31 1.4.2.2 rmind */
32 1.4.2.2 rmind
33 1.4.2.2 rmind #include <sys/param.h>
34 1.4.2.2 rmind #include <sys/device.h>
35 1.4.2.2 rmind #include <sys/errno.h>
36 1.4.2.2 rmind #include <sys/malloc.h>
37 1.4.2.2 rmind #include <sys/systm.h>
38 1.4.2.2 rmind
39 1.4.2.2 rmind #define _SPARC_BUS_DMA_PRIVATE
40 1.4.2.2 rmind #include <machine/bus.h>
41 1.4.2.2 rmind #include <machine/autoconf.h>
42 1.4.2.2 rmind
43 1.4.2.2 rmind #ifdef DDB
44 1.4.2.2 rmind #include <machine/db_machdep.h>
45 1.4.2.2 rmind #endif
46 1.4.2.2 rmind
47 1.4.2.2 rmind #include <dev/pci/pcivar.h>
48 1.4.2.2 rmind #include <dev/pci/pcireg.h>
49 1.4.2.2 rmind
50 1.4.2.2 rmind #include <sparc64/dev/iommureg.h>
51 1.4.2.2 rmind #include <sparc64/dev/iommuvar.h>
52 1.4.2.2 rmind #include <sparc64/dev/pyrovar.h>
53 1.4.2.2 rmind
54 1.4.2.2 rmind #ifdef DEBUG
55 1.4.2.2 rmind #define PDB_PROM 0x01
56 1.4.2.2 rmind #define PDB_BUSMAP 0x02
57 1.4.2.2 rmind #define PDB_INTR 0x04
58 1.4.2.2 rmind #define PDB_CONF 0x08
59 1.4.2.2 rmind int pyro_debug = 0x4;
60 1.4.2.2 rmind #define DPRINTF(l, s) do { if (pyro_debug & l) printf s; } while (0)
61 1.4.2.2 rmind #else
62 1.4.2.2 rmind #define DPRINTF(l, s)
63 1.4.2.2 rmind #endif
64 1.4.2.2 rmind
65 1.4.2.2 rmind #define FIRE_RESET_GEN 0x7010
66 1.4.2.2 rmind
67 1.4.2.2 rmind #define FIRE_RESET_GEN_XIR 0x0000000000000002L
68 1.4.2.2 rmind
69 1.4.2.2 rmind #define FIRE_INTRMAP_INT_CNTRL_NUM_MASK 0x000003c0
70 1.4.2.2 rmind #define FIRE_INTRMAP_INT_CNTRL_NUM0 0x00000040
71 1.4.2.2 rmind #define FIRE_INTRMAP_INT_CNTRL_NUM1 0x00000080
72 1.4.2.2 rmind #define FIRE_INTRMAP_INT_CNTRL_NUM2 0x00000100
73 1.4.2.2 rmind #define FIRE_INTRMAP_INT_CNTRL_NUM3 0x00000200
74 1.4.2.2 rmind #define FIRE_INTRMAP_T_JPID_SHIFT 26
75 1.4.2.2 rmind #define FIRE_INTRMAP_T_JPID_MASK 0x7c000000
76 1.4.2.2 rmind
77 1.4.2.2 rmind #define OBERON_INTRMAP_T_DESTID_SHIFT 21
78 1.4.2.2 rmind #define OBERON_INTRMAP_T_DESTID_MASK 0x7fe00000
79 1.4.2.2 rmind
80 1.4.2.2 rmind extern struct sparc_pci_chipset _sparc_pci_chipset;
81 1.4.2.2 rmind
82 1.4.2.4 rmind int pyro_match(device_t, cfdata_t, void *);
83 1.4.2.4 rmind void pyro_attach(device_t, device_t, void *);
84 1.4.2.2 rmind int pyro_print(void *, const char *);
85 1.4.2.2 rmind
86 1.4.2.4 rmind CFATTACH_DECL_NEW(pyro, sizeof(struct pyro_softc),
87 1.4.2.2 rmind pyro_match, pyro_attach, NULL, NULL);
88 1.4.2.2 rmind
89 1.4.2.2 rmind void pyro_init(struct pyro_softc *, int);
90 1.4.2.2 rmind void pyro_init_iommu(struct pyro_softc *, struct pyro_pbm *);
91 1.4.2.2 rmind
92 1.4.2.2 rmind pci_chipset_tag_t pyro_alloc_chipset(struct pyro_pbm *, int,
93 1.4.2.2 rmind pci_chipset_tag_t);
94 1.4.2.2 rmind bus_space_tag_t pyro_alloc_mem_tag(struct pyro_pbm *);
95 1.4.2.2 rmind bus_space_tag_t pyro_alloc_io_tag(struct pyro_pbm *);
96 1.4.2.2 rmind bus_space_tag_t pyro_alloc_config_tag(struct pyro_pbm *);
97 1.4.2.2 rmind bus_space_tag_t pyro_alloc_bus_tag(struct pyro_pbm *, const char *, int);
98 1.4.2.2 rmind bus_dma_tag_t pyro_alloc_dma_tag(struct pyro_pbm *);
99 1.4.2.2 rmind
100 1.4.2.2 rmind #if 0
101 1.4.2.2 rmind int pyro_conf_size(pci_chipset_tag_t, pcitag_t);
102 1.4.2.2 rmind #endif
103 1.4.2.2 rmind pcireg_t pyro_conf_read(pci_chipset_tag_t, pcitag_t, int);
104 1.4.2.2 rmind void pyro_conf_write(pci_chipset_tag_t, pcitag_t, int, pcireg_t);
105 1.4.2.2 rmind
106 1.4.2.2 rmind static void * pyro_pci_intr_establish(pci_chipset_tag_t pc,
107 1.4.2.2 rmind pci_intr_handle_t ih, int level,
108 1.4.2.2 rmind int (*func)(void *), void *arg);
109 1.4.2.2 rmind
110 1.4.2.2 rmind int pyro_intr_map(const struct pci_attach_args *, pci_intr_handle_t *);
111 1.4.2.2 rmind int pyro_bus_map(bus_space_tag_t, bus_addr_t,
112 1.4.2.2 rmind bus_size_t, int, vaddr_t, bus_space_handle_t *);
113 1.4.2.2 rmind paddr_t pyro_bus_mmap(bus_space_tag_t, bus_addr_t, off_t,
114 1.4.2.2 rmind int, int);
115 1.4.2.2 rmind void *pyro_intr_establish(bus_space_tag_t, int, int,
116 1.4.2.2 rmind int (*)(void *), void *, void (*)(void));
117 1.4.2.2 rmind
118 1.4.2.2 rmind int pyro_dmamap_create(bus_dma_tag_t, bus_size_t, int,
119 1.4.2.2 rmind bus_size_t, bus_size_t, int, bus_dmamap_t *);
120 1.4.2.2 rmind
121 1.4.2.2 rmind int
122 1.4.2.4 rmind pyro_match(struct device *parent, cfdata_t match, void *aux)
123 1.4.2.2 rmind {
124 1.4.2.2 rmind struct mainbus_attach_args *ma = aux;
125 1.4.2.2 rmind char *str;
126 1.4.2.2 rmind
127 1.4.2.2 rmind if (strcmp(ma->ma_name, "pci") != 0)
128 1.4.2.2 rmind return (0);
129 1.4.2.2 rmind
130 1.4.2.2 rmind str = prom_getpropstring(ma->ma_node, "compatible");
131 1.4.2.2 rmind if (strcmp(str, "pciex108e,80f0") == 0 ||
132 1.4.2.2 rmind strcmp(str, "pciex108e,80f8") == 0)
133 1.4.2.2 rmind return (1);
134 1.4.2.2 rmind
135 1.4.2.2 rmind return (0);
136 1.4.2.2 rmind }
137 1.4.2.2 rmind
138 1.4.2.2 rmind void
139 1.4.2.2 rmind pyro_attach(struct device *parent, struct device *self, void *aux)
140 1.4.2.2 rmind {
141 1.4.2.4 rmind struct pyro_softc *sc = device_private(self);
142 1.4.2.2 rmind struct mainbus_attach_args *ma = aux;
143 1.4.2.2 rmind char *str;
144 1.4.2.2 rmind int busa;
145 1.4.2.2 rmind
146 1.4.2.4 rmind sc->sc_dev = self;
147 1.4.2.2 rmind sc->sc_node = ma->ma_node;
148 1.4.2.2 rmind sc->sc_dmat = ma->ma_dmatag;
149 1.4.2.2 rmind sc->sc_bustag = ma->ma_bustag;
150 1.4.2.2 rmind sc->sc_csr = ma->ma_reg[0].ur_paddr;
151 1.4.2.2 rmind sc->sc_xbc = ma->ma_reg[1].ur_paddr;
152 1.4.2.2 rmind sc->sc_ign = INTIGN(ma->ma_upaid << INTMAP_IGN_SHIFT);
153 1.4.2.2 rmind
154 1.4.2.2 rmind if ((ma->ma_reg[0].ur_paddr & 0x00700000) == 0x00600000)
155 1.4.2.2 rmind busa = 1;
156 1.4.2.2 rmind else
157 1.4.2.2 rmind busa = 0;
158 1.4.2.2 rmind
159 1.4.2.2 rmind if (bus_space_map(sc->sc_bustag, sc->sc_csr,
160 1.4.2.2 rmind ma->ma_reg[0].ur_len, BUS_SPACE_MAP_LINEAR, &sc->sc_csrh)) {
161 1.4.2.2 rmind printf(": failed to map csr registers\n");
162 1.4.2.2 rmind return;
163 1.4.2.2 rmind }
164 1.4.2.2 rmind
165 1.4.2.2 rmind if (bus_space_map(sc->sc_bustag, sc->sc_xbc,
166 1.4.2.2 rmind ma->ma_reg[1].ur_len, 0, &sc->sc_xbch)) {
167 1.4.2.2 rmind printf(": failed to map xbc registers\n");
168 1.4.2.2 rmind return;
169 1.4.2.2 rmind }
170 1.4.2.2 rmind
171 1.4.2.2 rmind str = prom_getpropstring(ma->ma_node, "compatible");
172 1.4.2.2 rmind if (strcmp(str, "pciex108e,80f8") == 0)
173 1.4.2.2 rmind sc->sc_oberon = 1;
174 1.4.2.2 rmind
175 1.4.2.2 rmind pyro_init(sc, busa);
176 1.4.2.2 rmind }
177 1.4.2.2 rmind
178 1.4.2.2 rmind void
179 1.4.2.2 rmind pyro_init(struct pyro_softc *sc, int busa)
180 1.4.2.2 rmind {
181 1.4.2.2 rmind struct pyro_pbm *pbm;
182 1.4.2.2 rmind struct pcibus_attach_args pba;
183 1.4.2.2 rmind int *busranges = NULL, nranges;
184 1.4.2.2 rmind
185 1.4.2.2 rmind pbm = malloc(sizeof(*pbm), M_DEVBUF, M_NOWAIT | M_ZERO);
186 1.4.2.2 rmind if (pbm == NULL)
187 1.4.2.2 rmind panic("pyro: can't alloc pyro pbm");
188 1.4.2.2 rmind
189 1.4.2.2 rmind pbm->pp_sc = sc;
190 1.4.2.2 rmind pbm->pp_bus_a = busa;
191 1.4.2.2 rmind
192 1.4.2.2 rmind if (prom_getprop(sc->sc_node, "ranges", sizeof(struct pyro_range),
193 1.4.2.2 rmind &pbm->pp_nrange, (void **)&pbm->pp_range))
194 1.4.2.2 rmind panic("pyro: can't get ranges");
195 1.4.2.2 rmind
196 1.4.2.2 rmind if (prom_getprop(sc->sc_node, "bus-range", sizeof(int), &nranges,
197 1.4.2.2 rmind (void **)&busranges))
198 1.4.2.2 rmind panic("pyro: can't get bus-range");
199 1.4.2.2 rmind
200 1.4.2.2 rmind printf(": \"%s\", rev %d, ign %x, bus %c %d to %d\n",
201 1.4.2.2 rmind sc->sc_oberon ? "Oberon" : "Fire",
202 1.4.2.2 rmind prom_getpropint(sc->sc_node, "module-revision#", 0), sc->sc_ign,
203 1.4.2.2 rmind busa ? 'A' : 'B', busranges[0], busranges[1]);
204 1.4.2.2 rmind
205 1.4.2.4 rmind printf("%s: ", device_xname(sc->sc_dev));
206 1.4.2.2 rmind pyro_init_iommu(sc, pbm);
207 1.4.2.2 rmind
208 1.4.2.2 rmind pbm->pp_memt = pyro_alloc_mem_tag(pbm);
209 1.4.2.2 rmind pbm->pp_iot = pyro_alloc_io_tag(pbm);
210 1.4.2.2 rmind pbm->pp_cfgt = pyro_alloc_config_tag(pbm);
211 1.4.2.2 rmind pbm->pp_dmat = pyro_alloc_dma_tag(pbm);
212 1.4.2.3 rmind pbm->pp_flags = (pbm->pp_memt ? PCI_FLAGS_MEM_OKAY : 0) |
213 1.4.2.3 rmind (pbm->pp_iot ? PCI_FLAGS_IO_OKAY : 0);
214 1.4.2.2 rmind
215 1.4.2.2 rmind if (bus_space_map(pbm->pp_cfgt, 0, 0x10000000, 0, &pbm->pp_cfgh))
216 1.4.2.2 rmind panic("pyro: can't map config space");
217 1.4.2.2 rmind
218 1.4.2.2 rmind pbm->pp_pc = pyro_alloc_chipset(pbm, sc->sc_node, &_sparc_pci_chipset);
219 1.4.2.2 rmind pbm->pp_pc->spc_busmax = busranges[1];
220 1.4.2.2 rmind pbm->pp_pc->spc_busnode = malloc(sizeof(*pbm->pp_pc->spc_busnode),
221 1.4.2.2 rmind M_DEVBUF, M_NOWAIT | M_ZERO);
222 1.4.2.2 rmind if (pbm->pp_pc->spc_busnode == NULL)
223 1.4.2.2 rmind panic("schizo: malloc busnode");
224 1.4.2.2 rmind
225 1.4.2.2 rmind #if 0
226 1.4.2.2 rmind pbm->pp_pc->bustag = pbm->pp_cfgt;
227 1.4.2.2 rmind pbm->pp_pc->bushandle = pbm->pp_cfgh;
228 1.4.2.2 rmind #endif
229 1.4.2.2 rmind
230 1.4.2.2 rmind bzero(&pba, sizeof(pba));
231 1.4.2.2 rmind pba.pba_bus = busranges[0];
232 1.4.2.2 rmind pba.pba_pc = pbm->pp_pc;
233 1.4.2.2 rmind pba.pba_flags = pbm->pp_flags;
234 1.4.2.2 rmind pba.pba_dmat = pbm->pp_dmat;
235 1.4.2.2 rmind pba.pba_dmat64 = NULL; /* XXX */
236 1.4.2.2 rmind pba.pba_memt = pbm->pp_memt;
237 1.4.2.2 rmind pba.pba_iot = pbm->pp_iot;
238 1.4.2.2 rmind
239 1.4.2.2 rmind free(busranges, M_DEVBUF);
240 1.4.2.2 rmind
241 1.4.2.4 rmind config_found(sc->sc_dev, &pba, pyro_print);
242 1.4.2.2 rmind }
243 1.4.2.2 rmind
244 1.4.2.2 rmind void
245 1.4.2.2 rmind pyro_init_iommu(struct pyro_softc *sc, struct pyro_pbm *pbm)
246 1.4.2.2 rmind {
247 1.4.2.2 rmind struct iommu_state *is = &pbm->pp_is;
248 1.4.2.2 rmind int tsbsize = 7;
249 1.4.2.2 rmind u_int32_t iobase = -1;
250 1.4.2.2 rmind char *name;
251 1.4.2.2 rmind
252 1.4.2.2 rmind pbm->pp_sb.sb_is = is;
253 1.4.2.2 rmind is->is_bustag = sc->sc_bustag;
254 1.4.2.2 rmind
255 1.4.2.2 rmind if (bus_space_subregion(is->is_bustag, sc->sc_csrh,
256 1.4.2.2 rmind 0x40000, 0x100, &is->is_iommu)) {
257 1.4.2.2 rmind panic("pyro: unable to create iommu handle");
258 1.4.2.2 rmind }
259 1.4.2.2 rmind
260 1.4.2.2 rmind /* We have no STC. */
261 1.4.2.2 rmind is->is_sb[0] = NULL;
262 1.4.2.2 rmind
263 1.4.2.2 rmind name = (char *)malloc(32, M_DEVBUF, M_NOWAIT);
264 1.4.2.2 rmind if (name == NULL)
265 1.4.2.2 rmind panic("couldn't malloc iommu name");
266 1.4.2.4 rmind snprintf(name, 32, "%s dvma", device_xname(sc->sc_dev));
267 1.4.2.2 rmind
268 1.4.2.2 rmind /* Tell iommu how to set the TSB size. */
269 1.4.2.2 rmind is->is_flags = IOMMU_TSBSIZE_IN_PTSB;
270 1.4.2.2 rmind
271 1.4.2.2 rmind /* On Oberon, we need to flush the cache. */
272 1.4.2.2 rmind if (sc->sc_oberon)
273 1.4.2.2 rmind is->is_flags |= IOMMU_FLUSH_CACHE;
274 1.4.2.2 rmind
275 1.4.2.2 rmind iommu_init(name, is, tsbsize, iobase);
276 1.4.2.2 rmind }
277 1.4.2.2 rmind
278 1.4.2.2 rmind int
279 1.4.2.2 rmind pyro_print(void *aux, const char *p)
280 1.4.2.2 rmind {
281 1.4.2.2 rmind if (p == NULL)
282 1.4.2.2 rmind return (UNCONF);
283 1.4.2.2 rmind return (QUIET);
284 1.4.2.2 rmind }
285 1.4.2.2 rmind
286 1.4.2.2 rmind pcireg_t
287 1.4.2.2 rmind pyro_conf_read(pci_chipset_tag_t pc, pcitag_t tag, int reg)
288 1.4.2.2 rmind {
289 1.4.2.2 rmind struct pyro_pbm *pp = pc->cookie;
290 1.4.2.2 rmind pcireg_t val = (pcireg_t)~0;
291 1.4.2.2 rmind
292 1.4.2.2 rmind DPRINTF(PDB_CONF, ("%s: tag %lx reg %x ", __func__, (long)tag, reg));
293 1.4.2.2 rmind if (PCITAG_NODE(tag) != -1)
294 1.4.2.2 rmind val = bus_space_read_4(pp->pp_cfgt, pp->pp_cfgh,
295 1.4.2.2 rmind (PCITAG_OFFSET(tag) << 4) + reg);
296 1.4.2.2 rmind DPRINTF(PDB_CONF, (" returning %08x\n", (u_int)val));
297 1.4.2.2 rmind return (val);
298 1.4.2.2 rmind }
299 1.4.2.2 rmind
300 1.4.2.2 rmind void
301 1.4.2.2 rmind pyro_conf_write(pci_chipset_tag_t pc, pcitag_t tag, int reg, pcireg_t data)
302 1.4.2.2 rmind {
303 1.4.2.2 rmind struct pyro_pbm *pp = pc->cookie;
304 1.4.2.2 rmind
305 1.4.2.2 rmind DPRINTF(PDB_CONF, ("%s: tag %lx; reg %x; data %x", __func__,
306 1.4.2.2 rmind (long)tag, reg, (int)data));
307 1.4.2.2 rmind
308 1.4.2.2 rmind /* If we don't know it, just punt it. */
309 1.4.2.2 rmind if (PCITAG_NODE(tag) == -1) {
310 1.4.2.2 rmind DPRINTF(PDB_CONF, (" .. bad addr\n"));
311 1.4.2.2 rmind return;
312 1.4.2.2 rmind }
313 1.4.2.2 rmind
314 1.4.2.2 rmind bus_space_write_4(pp->pp_cfgt, pp->pp_cfgh,
315 1.4.2.2 rmind (PCITAG_OFFSET(tag) << 4) + reg, data);
316 1.4.2.2 rmind DPRINTF(PDB_CONF, (" .. done\n"));
317 1.4.2.2 rmind }
318 1.4.2.2 rmind
319 1.4.2.2 rmind /*
320 1.4.2.2 rmind * Bus-specific interrupt mapping
321 1.4.2.2 rmind */
322 1.4.2.2 rmind int
323 1.4.2.2 rmind pyro_intr_map(const struct pci_attach_args *pa, pci_intr_handle_t *ihp)
324 1.4.2.2 rmind {
325 1.4.2.2 rmind struct pyro_pbm *pp = pa->pa_pc->cookie;
326 1.4.2.2 rmind struct pyro_softc *sc = pp->pp_sc;
327 1.4.2.2 rmind u_int dev;
328 1.4.2.2 rmind
329 1.4.2.2 rmind if (*ihp != (pci_intr_handle_t)-1) {
330 1.4.2.2 rmind *ihp |= sc->sc_ign;
331 1.4.2.2 rmind DPRINTF(PDB_INTR, ("%s: not -1 -> ih %lx\n", __func__, (u_long)*ihp));
332 1.4.2.2 rmind return (0);
333 1.4.2.2 rmind }
334 1.4.2.2 rmind
335 1.4.2.2 rmind /*
336 1.4.2.2 rmind * We didn't find a PROM mapping for this interrupt. Try to
337 1.4.2.2 rmind * construct one ourselves based on the swizzled interrupt pin
338 1.4.2.2 rmind * and the interrupt mapping for PCI slots documented in the
339 1.4.2.2 rmind * UltraSPARC-IIi User's Manual.
340 1.4.2.2 rmind */
341 1.4.2.2 rmind
342 1.4.2.2 rmind if (pa->pa_intrpin == 0) {
343 1.4.2.2 rmind DPRINTF(PDB_INTR, ("%s: no intrpen\n", __func__));
344 1.4.2.2 rmind return (-1);
345 1.4.2.2 rmind }
346 1.4.2.2 rmind
347 1.4.2.2 rmind /*
348 1.4.2.2 rmind * This deserves some documentation. Should anyone
349 1.4.2.2 rmind * have anything official looking, please speak up.
350 1.4.2.2 rmind */
351 1.4.2.2 rmind dev = pa->pa_device - 1;
352 1.4.2.2 rmind
353 1.4.2.2 rmind *ihp = (pa->pa_intrpin - 1) & INTMAP_PCIINT;
354 1.4.2.2 rmind *ihp |= (dev << 2) & INTMAP_PCISLOT;
355 1.4.2.2 rmind *ihp |= sc->sc_ign;
356 1.4.2.2 rmind
357 1.4.2.2 rmind DPRINTF(PDB_INTR, ("%s: weird hack -> ih %lx\n", __func__, (u_long)*ihp));
358 1.4.2.2 rmind return (0);
359 1.4.2.2 rmind }
360 1.4.2.2 rmind
361 1.4.2.2 rmind bus_space_tag_t
362 1.4.2.2 rmind pyro_alloc_mem_tag(struct pyro_pbm *pp)
363 1.4.2.2 rmind {
364 1.4.2.2 rmind return (pyro_alloc_bus_tag(pp, "mem", PCI_MEMORY_BUS_SPACE));
365 1.4.2.2 rmind }
366 1.4.2.2 rmind
367 1.4.2.2 rmind bus_space_tag_t
368 1.4.2.2 rmind pyro_alloc_io_tag(struct pyro_pbm *pp)
369 1.4.2.2 rmind {
370 1.4.2.2 rmind return (pyro_alloc_bus_tag(pp, "io", PCI_IO_BUS_SPACE));
371 1.4.2.2 rmind }
372 1.4.2.2 rmind
373 1.4.2.2 rmind bus_space_tag_t
374 1.4.2.2 rmind pyro_alloc_config_tag(struct pyro_pbm *pp)
375 1.4.2.2 rmind {
376 1.4.2.2 rmind return (pyro_alloc_bus_tag(pp, "cfg", PCI_CONFIG_BUS_SPACE));
377 1.4.2.2 rmind }
378 1.4.2.2 rmind
379 1.4.2.2 rmind bus_space_tag_t
380 1.4.2.2 rmind pyro_alloc_bus_tag(struct pyro_pbm *pbm, const char *name, int type)
381 1.4.2.2 rmind {
382 1.4.2.2 rmind struct pyro_softc *sc = pbm->pp_sc;
383 1.4.2.2 rmind struct sparc_bus_space_tag *bt;
384 1.4.2.2 rmind
385 1.4.2.2 rmind bt = malloc(sizeof(*bt), M_DEVBUF, M_NOWAIT | M_ZERO);
386 1.4.2.2 rmind if (bt == NULL)
387 1.4.2.2 rmind panic("pyro: could not allocate bus tag");
388 1.4.2.2 rmind
389 1.4.2.2 rmind #if 0
390 1.4.2.2 rmind snprintf(bt->name, sizeof(bt->name), "%s-pbm_%s(%d/%2.2x)",
391 1.4.2.4 rmind device_xname(sc->sc_dev), name, ss, asi);
392 1.4.2.2 rmind #endif
393 1.4.2.2 rmind
394 1.4.2.2 rmind bt->cookie = pbm;
395 1.4.2.2 rmind bt->parent = sc->sc_bustag;
396 1.4.2.2 rmind bt->type = type;
397 1.4.2.2 rmind bt->sparc_bus_map = pyro_bus_map;
398 1.4.2.2 rmind bt->sparc_bus_mmap = pyro_bus_mmap;
399 1.4.2.2 rmind bt->sparc_intr_establish = pyro_intr_establish;
400 1.4.2.2 rmind return (bt);
401 1.4.2.2 rmind }
402 1.4.2.2 rmind
403 1.4.2.2 rmind bus_dma_tag_t
404 1.4.2.2 rmind pyro_alloc_dma_tag(struct pyro_pbm *pbm)
405 1.4.2.2 rmind {
406 1.4.2.2 rmind struct pyro_softc *sc = pbm->pp_sc;
407 1.4.2.2 rmind bus_dma_tag_t dt, pdt = sc->sc_dmat;
408 1.4.2.2 rmind
409 1.4.2.2 rmind dt = malloc(sizeof(*dt), M_DEVBUF, M_NOWAIT | M_ZERO);
410 1.4.2.2 rmind if (dt == NULL)
411 1.4.2.2 rmind panic("pyro: could not alloc dma tag");
412 1.4.2.2 rmind
413 1.4.2.2 rmind dt->_cookie = pbm;
414 1.4.2.2 rmind dt->_parent = pdt;
415 1.4.2.2 rmind #define PCOPY(x) dt->x = pdt->x
416 1.4.2.2 rmind dt->_dmamap_create = pyro_dmamap_create;
417 1.4.2.2 rmind PCOPY(_dmamap_destroy);
418 1.4.2.2 rmind dt->_dmamap_load = iommu_dvmamap_load;
419 1.4.2.2 rmind PCOPY(_dmamap_load_mbuf);
420 1.4.2.2 rmind PCOPY(_dmamap_load_uio);
421 1.4.2.2 rmind dt->_dmamap_load_raw = iommu_dvmamap_load_raw;
422 1.4.2.2 rmind dt->_dmamap_unload = iommu_dvmamap_unload;
423 1.4.2.2 rmind dt->_dmamap_sync = iommu_dvmamap_sync;
424 1.4.2.2 rmind dt->_dmamem_alloc = iommu_dvmamem_alloc;
425 1.4.2.2 rmind dt->_dmamem_free = iommu_dvmamem_free;
426 1.4.2.2 rmind dt->_dmamem_map = iommu_dvmamem_map;
427 1.4.2.2 rmind dt->_dmamem_unmap = iommu_dvmamem_unmap;
428 1.4.2.2 rmind PCOPY(_dmamem_mmap);
429 1.4.2.2 rmind #undef PCOPY
430 1.4.2.2 rmind return (dt);
431 1.4.2.2 rmind }
432 1.4.2.2 rmind
433 1.4.2.2 rmind pci_chipset_tag_t
434 1.4.2.2 rmind pyro_alloc_chipset(struct pyro_pbm *pbm, int node, pci_chipset_tag_t pc)
435 1.4.2.2 rmind {
436 1.4.2.2 rmind pci_chipset_tag_t npc;
437 1.4.2.2 rmind
438 1.4.2.2 rmind npc = malloc(sizeof *npc, M_DEVBUF, M_NOWAIT);
439 1.4.2.2 rmind if (npc == NULL)
440 1.4.2.2 rmind panic("pyro: could not allocate pci_chipset_tag_t");
441 1.4.2.2 rmind memcpy(npc, pc, sizeof *pc);
442 1.4.2.2 rmind npc->cookie = pbm;
443 1.4.2.2 rmind npc->rootnode = node;
444 1.4.2.2 rmind npc->spc_conf_read = pyro_conf_read;
445 1.4.2.2 rmind npc->spc_conf_write = pyro_conf_write;
446 1.4.2.2 rmind npc->spc_intr_map = pyro_intr_map;
447 1.4.2.2 rmind npc->spc_intr_establish = pyro_pci_intr_establish;
448 1.4.2.2 rmind npc->spc_find_ino = NULL;
449 1.4.2.2 rmind return (npc);
450 1.4.2.2 rmind }
451 1.4.2.2 rmind
452 1.4.2.2 rmind int
453 1.4.2.2 rmind pyro_dmamap_create(bus_dma_tag_t t, bus_size_t size,
454 1.4.2.2 rmind int nsegments, bus_size_t maxsegsz, bus_size_t boundary, int flags,
455 1.4.2.2 rmind bus_dmamap_t *dmamp)
456 1.4.2.2 rmind {
457 1.4.2.2 rmind struct pyro_pbm *pbm = t->_cookie;
458 1.4.2.2 rmind int error;
459 1.4.2.2 rmind
460 1.4.2.2 rmind error = bus_dmamap_create(t->_parent, size, nsegments, maxsegsz,
461 1.4.2.2 rmind boundary, flags, dmamp);
462 1.4.2.2 rmind if (error == 0)
463 1.4.2.2 rmind (*dmamp)->_dm_cookie = &pbm->pp_sb;
464 1.4.2.2 rmind return error;
465 1.4.2.2 rmind }
466 1.4.2.2 rmind
467 1.4.2.2 rmind int
468 1.4.2.2 rmind pyro_bus_map(bus_space_tag_t t, bus_addr_t offset,
469 1.4.2.2 rmind bus_size_t size, int flags, vaddr_t unused, bus_space_handle_t *hp)
470 1.4.2.2 rmind {
471 1.4.2.2 rmind struct pyro_pbm *pbm = t->cookie;
472 1.4.2.2 rmind struct pyro_softc *sc = pbm->pp_sc;
473 1.4.2.2 rmind int i, ss;
474 1.4.2.2 rmind
475 1.4.2.2 rmind DPRINTF(PDB_BUSMAP, ("pyro_bus_map: type %d off %qx sz %qx flags %d",
476 1.4.2.2 rmind t->type,
477 1.4.2.2 rmind (unsigned long long)offset,
478 1.4.2.2 rmind (unsigned long long)size,
479 1.4.2.2 rmind flags));
480 1.4.2.2 rmind
481 1.4.2.2 rmind ss = sparc_pci_childspace(t->type);
482 1.4.2.2 rmind DPRINTF(PDB_BUSMAP, (" cspace %d", ss));
483 1.4.2.2 rmind
484 1.4.2.2 rmind if (t->parent == 0 || t->parent->sparc_bus_map == 0) {
485 1.4.2.2 rmind printf("\n_pyro_bus_map: invalid parent");
486 1.4.2.2 rmind return (EINVAL);
487 1.4.2.2 rmind }
488 1.4.2.2 rmind
489 1.4.2.2 rmind for (i = 0; i < pbm->pp_nrange; i++) {
490 1.4.2.2 rmind bus_addr_t paddr;
491 1.4.2.2 rmind struct pyro_range *pr = &pbm->pp_range[i];
492 1.4.2.2 rmind
493 1.4.2.2 rmind if (((pr->cspace >> 24) & 0x03) != ss)
494 1.4.2.2 rmind continue;
495 1.4.2.2 rmind
496 1.4.2.2 rmind paddr = BUS_ADDR(pr->phys_hi, pr->phys_lo + offset);
497 1.4.2.2 rmind return ((*sc->sc_bustag->sparc_bus_map)(t, paddr, size,
498 1.4.2.2 rmind flags, 0, hp));
499 1.4.2.2 rmind }
500 1.4.2.2 rmind
501 1.4.2.2 rmind return (EINVAL);
502 1.4.2.2 rmind }
503 1.4.2.2 rmind
504 1.4.2.2 rmind paddr_t
505 1.4.2.2 rmind pyro_bus_mmap(bus_space_tag_t t, bus_addr_t paddr,
506 1.4.2.2 rmind off_t off, int prot, int flags)
507 1.4.2.2 rmind {
508 1.4.2.2 rmind bus_addr_t offset = paddr;
509 1.4.2.2 rmind struct pyro_pbm *pbm = t->cookie;
510 1.4.2.2 rmind struct pyro_softc *sc = pbm->pp_sc;
511 1.4.2.2 rmind int i, ss;
512 1.4.2.2 rmind
513 1.4.2.2 rmind ss = sparc_pci_childspace(t->type);
514 1.4.2.2 rmind
515 1.4.2.2 rmind DPRINTF(PDB_BUSMAP, ("pyro_bus_mmap: prot %d flags %d pa %qx\n",
516 1.4.2.2 rmind prot, flags, (unsigned long long)paddr));
517 1.4.2.2 rmind
518 1.4.2.2 rmind if (t->parent == 0 || t->parent->sparc_bus_mmap == 0) {
519 1.4.2.2 rmind printf("\n_pyro_bus_mmap: invalid parent");
520 1.4.2.2 rmind return (-1);
521 1.4.2.2 rmind }
522 1.4.2.2 rmind
523 1.4.2.2 rmind for (i = 0; i < pbm->pp_nrange; i++) {
524 1.4.2.2 rmind struct pyro_range *pr = &pbm->pp_range[i];
525 1.4.2.2 rmind
526 1.4.2.2 rmind if (((pr->cspace >> 24) & 0x03) != ss)
527 1.4.2.2 rmind continue;
528 1.4.2.2 rmind
529 1.4.2.2 rmind paddr = BUS_ADDR(pr->phys_hi, pr->phys_lo + offset);
530 1.4.2.2 rmind return (bus_space_mmap(sc->sc_bustag, paddr, off,
531 1.4.2.2 rmind prot, flags));
532 1.4.2.2 rmind }
533 1.4.2.2 rmind
534 1.4.2.2 rmind return (-1);
535 1.4.2.2 rmind }
536 1.4.2.2 rmind
537 1.4.2.2 rmind void *
538 1.4.2.2 rmind pyro_intr_establish(bus_space_tag_t t, int ihandle, int level,
539 1.4.2.2 rmind int (*handler)(void *), void *arg, void (*fastvec)(void) /* ignored */)
540 1.4.2.2 rmind {
541 1.4.2.2 rmind struct pyro_pbm *pbm = t->cookie;
542 1.4.2.2 rmind struct pyro_softc *sc = pbm->pp_sc;
543 1.4.2.2 rmind struct intrhand *ih = NULL;
544 1.4.2.2 rmind volatile u_int64_t *intrmapptr = NULL, *intrclrptr = NULL;
545 1.4.2.2 rmind u_int64_t *imapbase, *iclrbase;
546 1.4.2.2 rmind int ino;
547 1.4.2.2 rmind
548 1.4.2.2 rmind ino = INTINO(ihandle);
549 1.4.2.2 rmind DPRINTF(PDB_INTR, ("%s: ih %lx; level %d ino %d", __func__, (u_long)ih, level, ino));
550 1.4.2.2 rmind
551 1.4.2.2 rmind if (level == IPL_NONE)
552 1.4.2.2 rmind level = INTLEV(ihandle);
553 1.4.2.2 rmind if (level == IPL_NONE) {
554 1.4.2.2 rmind printf(": no IPL, setting IPL 2.\n");
555 1.4.2.2 rmind level = 2;
556 1.4.2.2 rmind }
557 1.4.2.2 rmind
558 1.4.2.2 rmind imapbase = (uint64_t *)((uintptr_t)bus_space_vaddr(sc->sc_bustag, sc->sc_csrh) + 0x1000);
559 1.4.2.2 rmind iclrbase = (uint64_t *)((uintptr_t)bus_space_vaddr(sc->sc_bustag, sc->sc_csrh) + 0x1400);
560 1.4.2.2 rmind intrmapptr = &imapbase[ino];
561 1.4.2.2 rmind intrclrptr = &iclrbase[ino];
562 1.4.2.2 rmind DPRINTF(PDB_INTR, (" imapbase %p iclrbase %p mapptr %p clrptr %p\n", imapbase, iclrbase, intrmapptr, intrclrptr));
563 1.4.2.2 rmind ino |= INTVEC(ihandle);
564 1.4.2.2 rmind
565 1.4.2.2 rmind ih = malloc(sizeof *ih, M_DEVBUF, M_NOWAIT);
566 1.4.2.2 rmind if (ih == NULL)
567 1.4.2.2 rmind return (NULL);
568 1.4.2.2 rmind
569 1.4.2.2 rmind /* Register the map and clear intr registers */
570 1.4.2.2 rmind ih->ih_map = intrmapptr;
571 1.4.2.2 rmind ih->ih_clr = intrclrptr;
572 1.4.2.2 rmind
573 1.4.2.2 rmind ih->ih_fun = handler;
574 1.4.2.2 rmind ih->ih_arg = arg;
575 1.4.2.2 rmind ih->ih_pil = level;
576 1.4.2.2 rmind ih->ih_number = ino;
577 1.4.2.2 rmind
578 1.4.2.2 rmind intr_establish(ih->ih_pil, level != IPL_VM, ih);
579 1.4.2.2 rmind
580 1.4.2.2 rmind if (intrmapptr != NULL) {
581 1.4.2.2 rmind u_int64_t imap;
582 1.4.2.2 rmind
583 1.4.2.2 rmind imap = *intrmapptr;
584 1.4.2.2 rmind DPRINTF(PDB_INTR, ("%s: read intrmap = %016qx", __func__,
585 1.4.2.2 rmind (unsigned long long)imap));
586 1.4.2.2 rmind imap &= ~FIRE_INTRMAP_INT_CNTRL_NUM_MASK;
587 1.4.2.2 rmind imap |= FIRE_INTRMAP_INT_CNTRL_NUM0;
588 1.4.2.2 rmind DPRINTF(PDB_INTR, ("; set intr group intrmap = %016qx",
589 1.4.2.2 rmind (unsigned long long)imap));
590 1.4.2.2 rmind if (sc->sc_oberon) {
591 1.4.2.2 rmind imap &= ~OBERON_INTRMAP_T_DESTID_MASK;
592 1.4.2.2 rmind imap |= CPU_JUPITERID <<
593 1.4.2.2 rmind OBERON_INTRMAP_T_DESTID_SHIFT;
594 1.4.2.2 rmind } else {
595 1.4.2.2 rmind imap &= ~FIRE_INTRMAP_T_JPID_MASK;
596 1.4.2.2 rmind imap |= CPU_UPAID << FIRE_INTRMAP_T_JPID_SHIFT;
597 1.4.2.2 rmind }
598 1.4.2.2 rmind DPRINTF(PDB_INTR, ("; set cpuid num intrmap = %016qx",
599 1.4.2.2 rmind (unsigned long long)imap));
600 1.4.2.2 rmind imap |= INTMAP_V;
601 1.4.2.2 rmind *intrmapptr = imap;
602 1.4.2.2 rmind DPRINTF(PDB_INTR, ("; writing intrmap = %016qx",
603 1.4.2.2 rmind (unsigned long long)imap));
604 1.4.2.2 rmind imap = *intrmapptr;
605 1.4.2.2 rmind DPRINTF(PDB_INTR, ("; reread intrmap = %016qx\n",
606 1.4.2.2 rmind (unsigned long long)imap));
607 1.4.2.2 rmind ih->ih_number |= imap & INTMAP_INR;
608 1.4.2.2 rmind }
609 1.4.2.2 rmind if (intrclrptr) {
610 1.4.2.2 rmind /* set state to IDLE */
611 1.4.2.2 rmind *intrclrptr = 0;
612 1.4.2.2 rmind }
613 1.4.2.2 rmind
614 1.4.2.2 rmind return (ih);
615 1.4.2.2 rmind }
616 1.4.2.2 rmind
617 1.4.2.2 rmind static void *
618 1.4.2.2 rmind pyro_pci_intr_establish(pci_chipset_tag_t pc, pci_intr_handle_t ih, int level,
619 1.4.2.2 rmind int (*func)(void *), void *arg)
620 1.4.2.2 rmind {
621 1.4.2.2 rmind void *cookie;
622 1.4.2.2 rmind struct pyro_pbm *pbm = (struct pyro_pbm *)pc->cookie;
623 1.4.2.2 rmind
624 1.4.2.2 rmind DPRINTF(PDB_INTR, ("%s: ih %lx; level %d\n", __func__, (u_long)ih, level));
625 1.4.2.2 rmind cookie = bus_intr_establish(pbm->pp_memt, ih, level, func, arg);
626 1.4.2.2 rmind
627 1.4.2.2 rmind DPRINTF(PDB_INTR, ("%s: returning handle %p\n", __func__, cookie));
628 1.4.2.2 rmind return (cookie);
629 1.4.2.2 rmind }
630