2 * Copyright (c) 1998 Doug Rabson
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPEAPECSL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
30 #include <sys/param.h>
31 #include <sys/systm.h>
32 #include <sys/kernel.h>
33 #include <sys/module.h>
35 #include <machine/bus.h>
37 #include <dev/pci/pcireg.h>
38 #include <dev/pci/pcivar.h>
39 #include <machine/cpuconf.h>
40 #include <machine/swiz.h>
41 #include <machine/md_var.h>
42 #include <machine/rpb.h>
43 #include <machine/resource.h>
45 #include <alpha/pci/apecsreg.h>
46 #include <alpha/pci/apecsvar.h>
47 #include <alpha/pci/pcibus.h>
48 #include <alpha/isa/isavar.h>
50 #include "alphapci_if.h"
53 #define KV(pa) ALPHA_PHYS_TO_K0SEG(pa)
55 static devclass_t pcib_devclass;
58 apecs_pcib_probe(device_t dev)
60 device_set_desc(dev, "2107x PCI host bus adapter");
63 device_add_child(dev, "pci", 0);
69 apecs_pcib_read_ivar(device_t dev, device_t child, int which, u_long *result)
71 if (which == PCIB_IVAR_BUS) {
78 static struct resource *
79 apecs_pcib_alloc_resource(device_t bus, device_t child, int type, int *rid,
80 u_long start, u_long end, u_long count, u_int flags)
82 struct resource *rv = NULL;
84 if ((hwrpb->rpb_type == ST_DEC_2100_A50) &&
85 (type == SYS_RES_IRQ))
86 rv = isa_alloc_intr(bus, child, start);
88 rv = alpha_pci_alloc_resource(bus, child, type, rid,
89 start, end, count, flags);
91 rman_set_rid(rv, *rid);
96 apecs_pcib_release_resource(device_t bus, device_t child, int type, int rid,
99 if ((hwrpb->rpb_type == ST_DEC_2100_A50) &&
100 (type == SYS_RES_IRQ))
101 return isa_release_intr(bus, child, r);
103 return pci_release_resource(bus, child, type, rid, r);
107 apecs_pcib_cvt_dense(device_t dev, vm_offset_t addr)
109 addr &= 0xffffffffUL;
110 return (void *) KV(addr | APECS_PCI_DENSE);
114 apecs_pcib_maxslots(device_t dev)
119 #define APECS_SWIZ_CFGOFF(b, s, f, r) \
120 (((b) << 16) | ((s) << 11) | ((f) << 8) | (r))
122 #define APECS_TYPE1_SETUP(b,s,old_haxr2) if((b)) { \
125 (old_haxr2) = REGVAL(EPIC_HAXR2); \
127 REGVAL(EPIC_HAXR2) = (old_haxr2) | 0x1; \
132 #define APECS_TYPE1_TEARDOWN(b,s,old_haxr2) if((b)) { \
135 REGVAL(EPIC_HAXR2) = (old_haxr2); \
141 #define SWIZ_CFGREAD(b, s, f, r, width, type) do { \
144 u_int32_t old_haxr2 = 0; \
145 vm_offset_t off = APECS_SWIZ_CFGOFF(b, s, f, r); \
147 SPARSE_##width##_ADDRESS(KV(APECS_PCI_CONF), off); \
149 APECS_TYPE1_SETUP(b,ipl,old_haxr2); \
150 if (!badaddr((caddr_t)kv, sizeof(type))) { \
151 val = SPARSE_##width##_EXTRACT(off, SPARSE_READ(kv)); \
153 APECS_TYPE1_TEARDOWN(b,ipl,old_haxr2); \
157 #define SWIZ_CFGWRITE(b, s, f, r, data, width, type) do { \
159 u_int32_t old_haxr2 = 0; \
160 vm_offset_t off = APECS_SWIZ_CFGOFF(b, s, f, r); \
162 SPARSE_##width##_ADDRESS(KV(APECS_PCI_CONF), off); \
164 APECS_TYPE1_SETUP(b,ipl,old_haxr2); \
165 if (!badaddr((caddr_t)kv, sizeof(type))) { \
166 SPARSE_WRITE(kv, SPARSE_##width##_INSERT(off, data)); \
169 APECS_TYPE1_TEARDOWN(b,ipl,old_haxr2); \
174 apecs_pcib_read_config(device_t dev, u_int b, u_int s, u_int f,
175 u_int reg, int width)
179 if ((reg == PCIR_INTLINE) && (width == 1) &&
180 (platform.pci_intr_map != NULL)) {
186 apecs_pcib_read_config(dev, b, s, f, PCIR_INTPIN, 1);
187 platform.pci_intr_map((void *)&cfg);
188 if (cfg.intline != 255)
194 SWIZ_CFGREAD(b, s, f, reg, BYTE, u_int8_t);
197 SWIZ_CFGREAD(b, s, f, reg, WORD, u_int16_t);
200 SWIZ_CFGREAD(b, s, f, reg, LONG, u_int32_t);
206 apecs_pcib_write_config(device_t dev, u_int b, u_int s, u_int f,
207 u_int reg, u_int32_t val, int width)
211 SWIZ_CFGWRITE(b, s, f, reg, val, BYTE, u_int8_t);
214 SWIZ_CFGWRITE(b, s, f, reg, val, WORD, u_int16_t);
217 SWIZ_CFGWRITE(b, s, f, reg, val, LONG, u_int32_t);
221 static device_method_t apecs_pcib_methods[] = {
222 /* Device interface */
223 DEVMETHOD(device_probe, apecs_pcib_probe),
224 DEVMETHOD(device_attach, bus_generic_attach),
227 DEVMETHOD(bus_print_child, bus_generic_print_child),
228 DEVMETHOD(bus_read_ivar, apecs_pcib_read_ivar),
229 DEVMETHOD(bus_alloc_resource, apecs_pcib_alloc_resource),
230 DEVMETHOD(bus_release_resource, apecs_pcib_release_resource),
231 DEVMETHOD(bus_activate_resource, pci_activate_resource),
232 DEVMETHOD(bus_deactivate_resource, pci_deactivate_resource),
233 DEVMETHOD(bus_setup_intr, bus_generic_setup_intr),
234 DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr),
236 /* alphapci interface */
237 DEVMETHOD(alphapci_cvt_dense, apecs_pcib_cvt_dense),
240 DEVMETHOD(pcib_maxslots, apecs_pcib_maxslots),
241 DEVMETHOD(pcib_read_config, apecs_pcib_read_config),
242 DEVMETHOD(pcib_write_config, apecs_pcib_write_config),
243 DEVMETHOD(pcib_route_interrupt, alpha_pci_route_interrupt),
248 static driver_t apecs_pcib_driver = {
254 DRIVER_MODULE(pcib, apecs, apecs_pcib_driver, pcib_devclass, 0, 0);