empb.c revision 1.8.2.2 1 1.8.2.2 yamt /* $NetBSD: empb.c,v 1.8.2.2 2012/10/30 17:18:52 yamt Exp $ */
2 1.8.2.2 yamt
3 1.8.2.2 yamt /*-
4 1.8.2.2 yamt * Copyright (c) 2012 The NetBSD Foundation, Inc.
5 1.8.2.2 yamt * All rights reserved.
6 1.8.2.2 yamt *
7 1.8.2.2 yamt * This code is derived from software contributed to The NetBSD Foundation
8 1.8.2.2 yamt * by Radoslaw Kujawa.
9 1.8.2.2 yamt *
10 1.8.2.2 yamt * Redistribution and use in source and binary forms, with or without
11 1.8.2.2 yamt * modification, are permitted provided that the following conditions
12 1.8.2.2 yamt * are met:
13 1.8.2.2 yamt * 1. Redistributions of source code must retain the above copyright
14 1.8.2.2 yamt * notice, this list of conditions and the following disclaimer.
15 1.8.2.2 yamt * 2. Redistributions in binary form must reproduce the above copyright
16 1.8.2.2 yamt * notice, this list of conditions and the following disclaimer in the
17 1.8.2.2 yamt * documentation and/or other materials provided with the distribution.
18 1.8.2.2 yamt *
19 1.8.2.2 yamt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.8.2.2 yamt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.8.2.2 yamt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.8.2.2 yamt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.8.2.2 yamt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.8.2.2 yamt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.8.2.2 yamt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.8.2.2 yamt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.8.2.2 yamt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.8.2.2 yamt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.8.2.2 yamt * POSSIBILITY OF SUCH DAMAGE.
30 1.8.2.2 yamt */
31 1.8.2.2 yamt
32 1.8.2.2 yamt /* Elbox Mediator PCI bridge driver. Currently supports Mediator 1200 models.*/
33 1.8.2.2 yamt
34 1.8.2.2 yamt #include <sys/types.h>
35 1.8.2.2 yamt #include <sys/param.h>
36 1.8.2.2 yamt #include <sys/time.h>
37 1.8.2.2 yamt #include <sys/systm.h>
38 1.8.2.2 yamt #include <sys/errno.h>
39 1.8.2.2 yamt #include <sys/device.h>
40 1.8.2.2 yamt #include <sys/malloc.h>
41 1.8.2.2 yamt #include <sys/extent.h>
42 1.8.2.2 yamt #include <sys/kmem.h>
43 1.8.2.2 yamt
44 1.8.2.2 yamt #include <uvm/uvm_extern.h>
45 1.8.2.2 yamt
46 1.8.2.2 yamt #include <machine/bus.h>
47 1.8.2.2 yamt #include <machine/cpu.h>
48 1.8.2.2 yamt
49 1.8.2.2 yamt #include <amiga/dev/zbusvar.h>
50 1.8.2.2 yamt #include <amiga/pci/empbreg.h>
51 1.8.2.2 yamt #include <amiga/pci/empbvar.h>
52 1.8.2.2 yamt #include <amiga/pci/emmemvar.h>
53 1.8.2.2 yamt
54 1.8.2.2 yamt #include <dev/pci/pciconf.h>
55 1.8.2.2 yamt
56 1.8.2.2 yamt #include "opt_pci.h"
57 1.8.2.2 yamt
58 1.8.2.2 yamt /*#define EMPB_DEBUG 1 */
59 1.8.2.2 yamt
60 1.8.2.2 yamt #define PCI_CONF_LOCK(s) (s) = splhigh()
61 1.8.2.2 yamt #define PCI_CONF_UNLOCK(s) splx((s))
62 1.8.2.2 yamt
63 1.8.2.2 yamt #define WINDOW_LOCK(s) (s) = splhigh()
64 1.8.2.2 yamt #define WINDOW_UNLOCK(s) splx((s))
65 1.8.2.2 yamt
66 1.8.2.2 yamt static int empb_match(device_t, cfdata_t, void *);
67 1.8.2.2 yamt static void empb_attach(device_t, device_t, void *);
68 1.8.2.2 yamt
69 1.8.2.2 yamt static void empb_callback(device_t);
70 1.8.2.2 yamt
71 1.8.2.2 yamt static void empb_find_mem(struct empb_softc *);
72 1.8.2.2 yamt static void empb_switch_bridge(struct empb_softc *, uint8_t);
73 1.8.2.2 yamt static void empb_intr_enable(struct empb_softc *);
74 1.8.2.2 yamt
75 1.8.2.2 yamt pcireg_t empb_pci_conf_read(pci_chipset_tag_t, pcitag_t, int);
76 1.8.2.2 yamt void empb_pci_conf_write(pci_chipset_tag_t, pcitag_t, int, pcireg_t);
77 1.8.2.2 yamt int empb_pci_bus_maxdevs(pci_chipset_tag_t, int);
78 1.8.2.2 yamt void empb_pci_attach_hook(device_t, device_t,
79 1.8.2.2 yamt struct pcibus_attach_args *);
80 1.8.2.2 yamt pcitag_t empb_pci_make_tag(pci_chipset_tag_t, int, int, int);
81 1.8.2.2 yamt void empb_pci_decompose_tag(pci_chipset_tag_t, pcitag_t,
82 1.8.2.2 yamt int *, int *, int *);
83 1.8.2.2 yamt int empb_pci_intr_map(const struct pci_attach_args *,
84 1.8.2.2 yamt pci_intr_handle_t *);
85 1.8.2.2 yamt const struct evcnt * empb_pci_intr_evcnt(pci_chipset_tag_t,
86 1.8.2.2 yamt pci_intr_handle_t);
87 1.8.2.2 yamt int empb_pci_conf_hook(pci_chipset_tag_t, int, int, int, pcireg_t);
88 1.8.2.2 yamt
89 1.8.2.2 yamt CFATTACH_DECL_NEW(empb, sizeof(struct empb_softc),
90 1.8.2.2 yamt empb_match, empb_attach, NULL, NULL);
91 1.8.2.2 yamt
92 1.8.2.2 yamt static int
93 1.8.2.2 yamt empb_match(device_t parent, cfdata_t cf, void *aux)
94 1.8.2.2 yamt {
95 1.8.2.2 yamt struct zbus_args *zap;
96 1.8.2.2 yamt
97 1.8.2.2 yamt zap = aux;
98 1.8.2.2 yamt
99 1.8.2.2 yamt if (zap->manid != ZORRO_MANID_ELBOX)
100 1.8.2.2 yamt return 0;
101 1.8.2.2 yamt
102 1.8.2.2 yamt switch (zap->prodid) {
103 1.8.2.2 yamt case ZORRO_PRODID_MED1K2:
104 1.8.2.2 yamt case ZORRO_PRODID_MED1K2SX:
105 1.8.2.2 yamt case ZORRO_PRODID_MED1K2LT2:
106 1.8.2.2 yamt case ZORRO_PRODID_MED1K2LT4:
107 1.8.2.2 yamt case ZORRO_PRODID_MED1K2TX:
108 1.8.2.2 yamt return 1;
109 1.8.2.2 yamt }
110 1.8.2.2 yamt
111 1.8.2.2 yamt return 0;
112 1.8.2.2 yamt }
113 1.8.2.2 yamt
114 1.8.2.2 yamt
115 1.8.2.2 yamt static void
116 1.8.2.2 yamt empb_attach(device_t parent, device_t self, void *aux)
117 1.8.2.2 yamt {
118 1.8.2.2 yamt struct empb_softc *sc;
119 1.8.2.2 yamt struct zbus_args *zap;
120 1.8.2.2 yamt
121 1.8.2.2 yamt volatile char *ba;
122 1.8.2.2 yamt
123 1.8.2.2 yamt zap = aux;
124 1.8.2.2 yamt sc = device_private(self);
125 1.8.2.2 yamt sc->sc_dev = self;
126 1.8.2.2 yamt ba = zap->va;
127 1.8.2.2 yamt
128 1.8.2.2 yamt switch (zap->prodid) {
129 1.8.2.2 yamt case ZORRO_PRODID_MED1K2:
130 1.8.2.2 yamt aprint_normal(": ELBOX Mediator PCI 1200\n");
131 1.8.2.2 yamt break;
132 1.8.2.2 yamt case ZORRO_PRODID_MED1K2SX:
133 1.8.2.2 yamt aprint_normal(": ELBOX Mediator PCI 1200 SX\n");
134 1.8.2.2 yamt break;
135 1.8.2.2 yamt case ZORRO_PRODID_MED1K2LT2:
136 1.8.2.2 yamt aprint_normal(": ELBOX Mediator PCI 1200 LT2\n");
137 1.8.2.2 yamt break;
138 1.8.2.2 yamt case ZORRO_PRODID_MED1K2LT4:
139 1.8.2.2 yamt aprint_normal(": ELBOX Mediator PCI 1200 LT4\n");
140 1.8.2.2 yamt break;
141 1.8.2.2 yamt case ZORRO_PRODID_MED1K2TX:
142 1.8.2.2 yamt aprint_normal(": ELBOX Mediator PCI 1200 TX\n");
143 1.8.2.2 yamt break;
144 1.8.2.2 yamt default:
145 1.8.2.2 yamt aprint_normal(": ELBOX Mediator PCI (unknown)\n");
146 1.8.2.2 yamt break;
147 1.8.2.2 yamt }
148 1.8.2.2 yamt
149 1.8.2.2 yamt /* Setup bus space mappings. */
150 1.8.2.2 yamt sc->pci_confio_area.base = (bus_addr_t) ba + EMPB_BRIDGE_OFF;
151 1.8.2.2 yamt sc->pci_confio_area.absm = &amiga_bus_stride_1swap;
152 1.8.2.2 yamt
153 1.8.2.2 yamt sc->setup_area.base = (bus_addr_t) ba + EMPB_SETUP_OFF;
154 1.8.2.2 yamt sc->setup_area.absm = &amiga_bus_stride_1;
155 1.8.2.2 yamt
156 1.8.2.2 yamt /*
157 1.8.2.2 yamt * Defer everything until later, we need to wait for possible
158 1.8.2.2 yamt * emmem attachments.
159 1.8.2.2 yamt */
160 1.8.2.2 yamt
161 1.8.2.2 yamt config_defer(self, empb_callback);
162 1.8.2.2 yamt }
163 1.8.2.2 yamt
164 1.8.2.2 yamt static void
165 1.8.2.2 yamt empb_callback(device_t self) {
166 1.8.2.2 yamt
167 1.8.2.2 yamt struct empb_softc *sc;
168 1.8.2.2 yamt pci_chipset_tag_t pc;
169 1.8.2.2 yamt struct pcibus_attach_args pba;
170 1.8.2.2 yamt #ifdef PCI_NETBSD_CONFIGURE
171 1.8.2.2 yamt struct extent *ioext, *memext;
172 1.8.2.2 yamt #endif /* PCI_NETBSD_CONFIGURE */
173 1.8.2.2 yamt
174 1.8.2.2 yamt sc = device_private(self);
175 1.8.2.2 yamt pc = &sc->apc;
176 1.8.2.2 yamt
177 1.8.2.2 yamt #ifdef EMPB_DEBUG
178 1.8.2.2 yamt aprint_normal("empb: mapped setup %x->%x, conf/io %x->%x\n",
179 1.8.2.2 yamt kvtop((void*) sc->setup_area.base), sc->setup_area.base,
180 1.8.2.2 yamt kvtop((void*) sc->pci_confio_area.base), sc->pci_confio_area.base);
181 1.8.2.2 yamt #endif
182 1.8.2.2 yamt
183 1.8.2.2 yamt sc->pci_confio_t = &(sc->pci_confio_area);
184 1.8.2.2 yamt
185 1.8.2.2 yamt /*
186 1.8.2.2 yamt * We should not map I/O space here, however we have no choice
187 1.8.2.2 yamt * since these addresses are shared between configuration space and
188 1.8.2.2 yamt * I/O space. Not really a problem on m68k, however on PPC...
189 1.8.2.2 yamt */
190 1.8.2.2 yamt if (bus_space_map(sc->pci_confio_t, 0, EMPB_BRIDGE_SIZE, 0,
191 1.8.2.2 yamt &sc->pci_confio_h))
192 1.8.2.2 yamt aprint_error_dev(self,
193 1.8.2.2 yamt "couldn't map PCI configuration & I/O space\n");
194 1.8.2.2 yamt
195 1.8.2.2 yamt sc->apc.pci_conf_datat = sc->pci_confio_t;
196 1.8.2.2 yamt sc->apc.pci_conf_datah = sc->pci_confio_h;
197 1.8.2.2 yamt
198 1.8.2.2 yamt sc->setup_area_t = &(sc->setup_area);
199 1.8.2.2 yamt
200 1.8.2.2 yamt if (bus_space_map(sc->setup_area_t, 0, EMPB_SETUP_SIZE, 0,
201 1.8.2.2 yamt &sc->setup_area_h))
202 1.8.2.2 yamt aprint_error_dev(self,
203 1.8.2.2 yamt "couldn't map Mediator setup space\n");
204 1.8.2.2 yamt
205 1.8.2.2 yamt empb_find_mem(sc);
206 1.8.2.2 yamt if (sc->pci_mem_win_size == 0)
207 1.8.2.2 yamt aprint_error_dev(self,
208 1.8.2.2 yamt "couldn't find memory space, check your WINDOW jumper\n");
209 1.8.2.2 yamt
210 1.8.2.2 yamt /* Initialize the PCI chipset tag. */
211 1.8.2.2 yamt sc->apc.pc_conf_v = (void*) pc;
212 1.8.2.2 yamt sc->apc.pc_bus_maxdevs = empb_pci_bus_maxdevs;
213 1.8.2.2 yamt sc->apc.pc_make_tag = amiga_pci_make_tag;
214 1.8.2.2 yamt sc->apc.pc_decompose_tag = amiga_pci_decompose_tag;
215 1.8.2.2 yamt sc->apc.pc_conf_read = empb_pci_conf_read;
216 1.8.2.2 yamt sc->apc.pc_conf_write = empb_pci_conf_write;
217 1.8.2.2 yamt sc->apc.pc_attach_hook = empb_pci_attach_hook;
218 1.8.2.2 yamt
219 1.8.2.2 yamt sc->apc.pc_intr_map = empb_pci_intr_map;
220 1.8.2.2 yamt sc->apc.pc_intr_string = amiga_pci_intr_string;
221 1.8.2.2 yamt sc->apc.pc_intr_establish = amiga_pci_intr_establish;
222 1.8.2.2 yamt sc->apc.pc_intr_disestablish = amiga_pci_intr_disestablish;
223 1.8.2.2 yamt
224 1.8.2.2 yamt sc->apc.pc_conf_hook = empb_pci_conf_hook;
225 1.8.2.2 yamt sc->apc.pc_conf_interrupt = amiga_pci_conf_interrupt;
226 1.8.2.2 yamt
227 1.8.2.2 yamt sc->apc.cookie = sc;
228 1.8.2.2 yamt
229 1.8.2.2 yamt #ifdef PCI_NETBSD_CONFIGURE
230 1.8.2.2 yamt ioext = extent_create("empbio", 0, EMPB_BRIDGE_SIZE,
231 1.8.2.2 yamt NULL, 0, EX_NOWAIT);
232 1.8.2.2 yamt
233 1.8.2.2 yamt memext = extent_create("empbmem", EMPB_MEM_BASE, EMPB_MEM_END,
234 1.8.2.2 yamt NULL, 0, EX_NOWAIT);
235 1.8.2.2 yamt
236 1.8.2.2 yamt pci_configure_bus(pc, ioext, memext, NULL, 0, CACHELINE_SIZE);
237 1.8.2.2 yamt
238 1.8.2.2 yamt extent_destroy(ioext);
239 1.8.2.2 yamt extent_destroy(memext);
240 1.8.2.2 yamt
241 1.8.2.2 yamt #endif /* PCI_NETBSD_CONFIGURE */
242 1.8.2.2 yamt
243 1.8.2.2 yamt pba.pba_iot = &(sc->pci_confio_area);
244 1.8.2.2 yamt pba.pba_dmat = NULL;
245 1.8.2.2 yamt pba.pba_dmat64 = NULL;
246 1.8.2.2 yamt pba.pba_pc = pc;
247 1.8.2.2 yamt pba.pba_flags = PCI_FLAGS_IO_OKAY;
248 1.8.2.2 yamt
249 1.8.2.2 yamt if(sc->pci_mem_win_size > 0) {
250 1.8.2.2 yamt pba.pba_memt = &(sc->pci_mem_win);
251 1.8.2.2 yamt pba.pba_flags |= PCI_FLAGS_MEM_OKAY;
252 1.8.2.2 yamt } else
253 1.8.2.2 yamt pba.pba_memt = NULL;
254 1.8.2.2 yamt
255 1.8.2.2 yamt pba.pba_bus = 0;
256 1.8.2.2 yamt pba.pba_bridgetag = NULL;
257 1.8.2.2 yamt
258 1.8.2.2 yamt empb_intr_enable(sc);
259 1.8.2.2 yamt
260 1.8.2.2 yamt config_found_ia(self, "pcibus", &pba, pcibusprint);
261 1.8.2.2 yamt }
262 1.8.2.2 yamt
263 1.8.2.2 yamt static void
264 1.8.2.2 yamt empb_intr_enable(struct empb_softc *sc)
265 1.8.2.2 yamt {
266 1.8.2.2 yamt bus_space_write_1(sc->setup_area_t, sc->setup_area_h,
267 1.8.2.2 yamt EMPB_SETUP_INTR_OFF, EMPB_INTR_ENABLE);
268 1.8.2.2 yamt }
269 1.8.2.2 yamt
270 1.8.2.2 yamt /*
271 1.8.2.2 yamt * Switch between configuration space and I/O space.
272 1.8.2.2 yamt */
273 1.8.2.2 yamt static void
274 1.8.2.2 yamt empb_switch_bridge(struct empb_softc *sc, uint8_t mode)
275 1.8.2.2 yamt {
276 1.8.2.2 yamt bus_space_write_1(sc->setup_area_t, sc->setup_area_h,
277 1.8.2.2 yamt EMPB_SETUP_BRIDGE_OFF, mode);
278 1.8.2.2 yamt }
279 1.8.2.2 yamt
280 1.8.2.2 yamt
281 1.8.2.2 yamt /*
282 1.8.2.2 yamt * Try to find a (optional) memory window board.
283 1.8.2.2 yamt */
284 1.8.2.2 yamt static void
285 1.8.2.2 yamt empb_find_mem(struct empb_softc *sc)
286 1.8.2.2 yamt {
287 1.8.2.2 yamt device_t memdev;
288 1.8.2.2 yamt struct emmem_softc *mem_sc;
289 1.8.2.2 yamt
290 1.8.2.2 yamt memdev = device_find_by_xname("emmem0");
291 1.8.2.2 yamt sc->pci_mem_win_size = 0;
292 1.8.2.2 yamt
293 1.8.2.2 yamt if(memdev == NULL) {
294 1.8.2.2 yamt return;
295 1.8.2.2 yamt }
296 1.8.2.2 yamt
297 1.8.2.2 yamt mem_sc = device_private(memdev);
298 1.8.2.2 yamt
299 1.8.2.2 yamt sc->pci_mem_win.base = (bus_addr_t) mem_sc->sc_base;
300 1.8.2.2 yamt sc->pci_mem_win.absm = &empb_bus_swap;
301 1.8.2.2 yamt sc->pci_mem_win_size = mem_sc->sc_size;
302 1.8.2.2 yamt sc->pci_mem_win_t = &sc->pci_mem_win;
303 1.8.2.2 yamt
304 1.8.2.2 yamt if(sc->pci_mem_win_size == 8*1024*1024)
305 1.8.2.2 yamt sc->pci_mem_win_mask = EMPB_WINDOW_MASK_8M;
306 1.8.2.2 yamt else if(sc->pci_mem_win_size == 4*1024*1024)
307 1.8.2.2 yamt sc->pci_mem_win_mask = EMPB_WINDOW_MASK_4M;
308 1.8.2.2 yamt else /* disable anyway */
309 1.8.2.2 yamt sc->pci_mem_win_size = 0;
310 1.8.2.2 yamt
311 1.8.2.2 yamt #ifdef EMPB_DEBUG
312 1.8.2.2 yamt aprint_normal("empb: found %x b window at %p, switch mask %x\n",
313 1.8.2.2 yamt sc->pci_mem_win_size, (void*) sc->pci_mem_win.base,
314 1.8.2.2 yamt sc->pci_mem_win_mask);
315 1.8.2.2 yamt #endif /* EMPB_DEBUG */
316 1.8.2.2 yamt
317 1.8.2.2 yamt }
318 1.8.2.2 yamt
319 1.8.2.2 yamt /*
320 1.8.2.2 yamt * Switch memory window position. Return PCI mem address seen at the beginning
321 1.8.2.2 yamt * of window.
322 1.8.2.2 yamt */
323 1.8.2.2 yamt bus_addr_t
324 1.8.2.2 yamt empb_switch_window(struct empb_softc *sc, bus_addr_t address)
325 1.8.2.2 yamt {
326 1.8.2.2 yamt int s;
327 1.8.2.2 yamt uint16_t win_reg;
328 1.8.2.2 yamt #ifdef EMPB_DEBUG
329 1.8.2.2 yamt uint16_t rwin_reg;
330 1.8.2.2 yamt #endif /* EMPB_DEBUG */
331 1.8.2.2 yamt
332 1.8.2.2 yamt WINDOW_LOCK(s);
333 1.8.2.2 yamt
334 1.8.2.2 yamt win_reg = bswap16((address >> EMPB_WINDOW_SHIFT)
335 1.8.2.2 yamt & sc->pci_mem_win_mask);
336 1.8.2.2 yamt
337 1.8.2.2 yamt bus_space_write_2(sc->setup_area_t, sc->setup_area_h,
338 1.8.2.2 yamt EMPB_SETUP_WINDOW_OFF, win_reg);
339 1.8.2.2 yamt
340 1.8.2.2 yamt /* store window pos, like: sc->pci_mem_win_pos = win_reg ? */
341 1.8.2.2 yamt
342 1.8.2.2 yamt #ifdef EMPB_DEBUG
343 1.8.2.2 yamt rwin_reg = bus_space_read_2(sc->setup_area_t, sc->setup_area_h,
344 1.8.2.2 yamt EMPB_SETUP_WINDOW_OFF);
345 1.8.2.2 yamt
346 1.8.2.2 yamt aprint_normal("empb: access to %p window switch to %x => reg now %x\n",
347 1.8.2.2 yamt (void*) address, win_reg, rwin_reg);
348 1.8.2.2 yamt #endif /* EMPB_DEBUG */
349 1.8.2.2 yamt
350 1.8.2.2 yamt WINDOW_UNLOCK(s);
351 1.8.2.2 yamt
352 1.8.2.2 yamt return (bus_addr_t)((bswap16(win_reg)) << EMPB_WINDOW_SHIFT);
353 1.8.2.2 yamt }
354 1.8.2.2 yamt
355 1.8.2.2 yamt
356 1.8.2.2 yamt pcireg_t
357 1.8.2.2 yamt empb_pci_conf_read(pci_chipset_tag_t pc, pcitag_t tag, int reg)
358 1.8.2.2 yamt {
359 1.8.2.2 yamt uint32_t data;
360 1.8.2.2 yamt uint32_t bus, dev, func;
361 1.8.2.2 yamt struct empb_softc *sc;
362 1.8.2.2 yamt int s;
363 1.8.2.2 yamt
364 1.8.2.2 yamt sc = pc->cookie;
365 1.8.2.2 yamt
366 1.8.2.2 yamt pci_decompose_tag(pc, tag, &bus, &dev, &func);
367 1.8.2.2 yamt
368 1.8.2.2 yamt PCI_CONF_LOCK(s);
369 1.8.2.2 yamt
370 1.8.2.2 yamt empb_switch_bridge(sc, BRIDGE_CONF);
371 1.8.2.2 yamt
372 1.8.2.2 yamt data = bus_space_read_4(pc->pci_conf_datat, pc->pci_conf_datah,
373 1.8.2.2 yamt EMPB_CONF_DEV_STRIDE*dev + EMPB_CONF_FUNC_STRIDE*func + reg);
374 1.8.2.2 yamt #ifdef EMPB_DEBUG_CONF
375 1.8.2.2 yamt aprint_normal("empb conf read va: %lx, bus: %d, dev: %d, "
376 1.8.2.2 yamt "func: %d, reg: %d -r-> data %x\n",
377 1.8.2.2 yamt pc->pci_conf_datah, bus, dev, func, reg, data);
378 1.8.2.2 yamt #endif /* EMPB_DEBUG_CONF */
379 1.8.2.2 yamt
380 1.8.2.2 yamt empb_switch_bridge(sc, BRIDGE_IO);
381 1.8.2.2 yamt
382 1.8.2.2 yamt PCI_CONF_UNLOCK(s);
383 1.8.2.2 yamt
384 1.8.2.2 yamt return data;
385 1.8.2.2 yamt }
386 1.8.2.2 yamt
387 1.8.2.2 yamt void
388 1.8.2.2 yamt empb_pci_conf_write(pci_chipset_tag_t pc, pcitag_t tag, int reg, pcireg_t val)
389 1.8.2.2 yamt {
390 1.8.2.2 yamt uint32_t bus, dev, func;
391 1.8.2.2 yamt struct empb_softc *sc;
392 1.8.2.2 yamt int s;
393 1.8.2.2 yamt
394 1.8.2.2 yamt sc = pc->cookie;
395 1.8.2.2 yamt
396 1.8.2.2 yamt pci_decompose_tag(pc, tag, &bus, &dev, &func);
397 1.8.2.2 yamt
398 1.8.2.2 yamt PCI_CONF_LOCK(s);
399 1.8.2.2 yamt
400 1.8.2.2 yamt empb_switch_bridge(sc, BRIDGE_CONF);
401 1.8.2.2 yamt
402 1.8.2.2 yamt bus_space_write_4(pc->pci_conf_datat, pc->pci_conf_datah,
403 1.8.2.2 yamt EMPB_CONF_DEV_STRIDE*dev + EMPB_CONF_FUNC_STRIDE*func + reg, val);
404 1.8.2.2 yamt #ifdef EMPB_DEBUG_CONF
405 1.8.2.2 yamt aprint_normal("empb conf write va: %lx, bus: %d, dev: %d, "
406 1.8.2.2 yamt "func: %d, reg: %d -w-> data %x\n",
407 1.8.2.2 yamt pc->pci_conf_datah, bus, dev, func, reg, val);
408 1.8.2.2 yamt #endif /* EMPB_DEBUG_CONF */
409 1.8.2.2 yamt empb_switch_bridge(sc, BRIDGE_IO);
410 1.8.2.2 yamt
411 1.8.2.2 yamt PCI_CONF_UNLOCK(s);
412 1.8.2.2 yamt }
413 1.8.2.2 yamt
414 1.8.2.2 yamt int
415 1.8.2.2 yamt empb_pci_bus_maxdevs(pci_chipset_tag_t pc, int busno)
416 1.8.2.2 yamt {
417 1.8.2.2 yamt return 6; /* no Mediator with more than 6 slots? */
418 1.8.2.2 yamt }
419 1.8.2.2 yamt
420 1.8.2.2 yamt void
421 1.8.2.2 yamt empb_pci_attach_hook(device_t parent, device_t self,
422 1.8.2.2 yamt struct pcibus_attach_args *pba)
423 1.8.2.2 yamt {
424 1.8.2.2 yamt }
425 1.8.2.2 yamt
426 1.8.2.2 yamt int
427 1.8.2.2 yamt empb_pci_intr_map(const struct pci_attach_args *pa, pci_intr_handle_t *ihp)
428 1.8.2.2 yamt {
429 1.8.2.2 yamt /* TODO: add sanity checking */
430 1.8.2.2 yamt
431 1.8.2.2 yamt *ihp = EMPB_INT;
432 1.8.2.2 yamt return 0;
433 1.8.2.2 yamt }
434 1.8.2.2 yamt
435 1.8.2.2 yamt const struct evcnt *
436 1.8.2.2 yamt empb_pci_intr_evcnt(pci_chipset_tag_t pc, pci_intr_handle_t ih)
437 1.8.2.2 yamt {
438 1.8.2.2 yamt /* TODO: implement */
439 1.8.2.2 yamt return NULL;
440 1.8.2.2 yamt }
441 1.8.2.2 yamt
442 1.8.2.2 yamt int
443 1.8.2.2 yamt empb_pci_conf_hook(pci_chipset_tag_t pct, int bus, int dev, int func,
444 1.8.2.2 yamt pcireg_t id)
445 1.8.2.2 yamt {
446 1.8.2.2 yamt
447 1.8.2.2 yamt /*
448 1.8.2.2 yamt * Register information about some known PCI devices with
449 1.8.2.2 yamt * DMA-able memory.
450 1.8.2.2 yamt */
451 1.8.2.2 yamt /*if ((PCI_VENDOR(id) == PCI_VENDOR_3DFX) &&
452 1.8.2.2 yamt (PCI_PRODUCT(id) >= PCI_PRODUCT_3DFX_VOODOO3))*/
453 1.8.2.2 yamt
454 1.8.2.2 yamt
455 1.8.2.2 yamt return PCI_CONF_DEFAULT;
456 1.8.2.2 yamt }
457