mppb.c revision 1.10.4.1 1 1.10.4.1 thorpej /* $NetBSD: mppb.c,v 1.10.4.1 2021/03/23 07:14:42 thorpej Exp $ */
2 1.1 rkujawa
3 1.1 rkujawa /*-
4 1.1 rkujawa * Copyright (c) 2011 The NetBSD Foundation, Inc.
5 1.1 rkujawa * All rights reserved.
6 1.1 rkujawa *
7 1.1 rkujawa * This code is derived from software contributed to The NetBSD Foundation
8 1.1 rkujawa * by Radoslaw Kujawa.
9 1.1 rkujawa *
10 1.1 rkujawa * Redistribution and use in source and binary forms, with or without
11 1.1 rkujawa * modification, are permitted provided that the following conditions
12 1.1 rkujawa * are met:
13 1.1 rkujawa * 1. Redistributions of source code must retain the above copyright
14 1.1 rkujawa * notice, this list of conditions and the following disclaimer.
15 1.1 rkujawa * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 rkujawa * notice, this list of conditions and the following disclaimer in the
17 1.1 rkujawa * documentation and/or other materials provided with the distribution.
18 1.1 rkujawa *
19 1.1 rkujawa * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.1 rkujawa * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1 rkujawa * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1 rkujawa * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.1 rkujawa * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1 rkujawa * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1 rkujawa * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1 rkujawa * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1 rkujawa * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1 rkujawa * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1 rkujawa * POSSIBILITY OF SUCH DAMAGE.
30 1.1 rkujawa */
31 1.1 rkujawa
32 1.1 rkujawa /* Matay Prometheus Zorro-PCI bridge driver. */
33 1.1 rkujawa
34 1.1 rkujawa #include <sys/types.h>
35 1.1 rkujawa #include <sys/param.h>
36 1.1 rkujawa #include <sys/time.h>
37 1.1 rkujawa #include <sys/systm.h>
38 1.1 rkujawa #include <sys/errno.h>
39 1.1 rkujawa #include <sys/device.h>
40 1.1 rkujawa #include <sys/malloc.h>
41 1.1 rkujawa #include <sys/kmem.h>
42 1.1 rkujawa
43 1.1 rkujawa #include <uvm/uvm_extern.h>
44 1.1 rkujawa
45 1.1 rkujawa #include <machine/bus.h>
46 1.1 rkujawa #include <machine/cpu.h>
47 1.1 rkujawa
48 1.1 rkujawa #include <m68k/bus_dma.h>
49 1.1 rkujawa #include <amiga/dev/zbusvar.h>
50 1.1 rkujawa #include <amiga/pci/mppbreg.h>
51 1.1 rkujawa
52 1.1 rkujawa #include <dev/pci/pcivar.h>
53 1.1 rkujawa #include <dev/pci/pcireg.h>
54 1.1 rkujawa #include <dev/pci/pcidevs.h>
55 1.1 rkujawa #include <dev/pci/pciconf.h>
56 1.1 rkujawa
57 1.5 rkujawa #include "opt_pci.h"
58 1.5 rkujawa
59 1.1 rkujawa /* Zorro IDs */
60 1.1 rkujawa #define ZORRO_MANID_MATAY 44359
61 1.1 rkujawa #define ZORRO_PRODID_PROMETHEUS 1
62 1.1 rkujawa
63 1.1 rkujawa struct mppb_softc {
64 1.1 rkujawa device_t sc_dev;
65 1.1 rkujawa volatile char *ba;
66 1.1 rkujawa struct bus_space_tag pci_conf_area;
67 1.1 rkujawa struct bus_space_tag pci_io_area;
68 1.1 rkujawa struct bus_space_tag pci_mem_area;
69 1.1 rkujawa struct amiga_pci_chipset apc;
70 1.1 rkujawa };
71 1.1 rkujawa
72 1.7 chs static int mppb_match(device_t, cfdata_t, void *);
73 1.7 chs static void mppb_attach(device_t, device_t, void *);
74 1.1 rkujawa pcireg_t mppb_pci_conf_read(pci_chipset_tag_t, pcitag_t, int);
75 1.1 rkujawa void mppb_pci_conf_write(pci_chipset_tag_t, pcitag_t, int, pcireg_t);
76 1.7 chs int mppb_pci_bus_maxdevs(pci_chipset_tag_t, int);
77 1.7 chs void mppb_pci_attach_hook (device_t, device_t,
78 1.7 chs struct pcibus_attach_args *pba);
79 1.7 chs pcitag_t mppb_pci_make_tag(pci_chipset_tag_t, int, int, int);
80 1.7 chs void mppb_pci_decompose_tag(pci_chipset_tag_t, pcitag_t,
81 1.7 chs int *, int *, int *);
82 1.7 chs int mppb_pci_intr_map(const struct pci_attach_args *,
83 1.7 chs pci_intr_handle_t *);
84 1.7 chs const struct evcnt * mppb_pci_intr_evcnt(pci_chipset_tag_t,
85 1.7 chs pci_intr_handle_t);
86 1.1 rkujawa
87 1.1 rkujawa CFATTACH_DECL_NEW(mppb, sizeof(struct mppb_softc),
88 1.1 rkujawa mppb_match, mppb_attach, NULL, NULL);
89 1.1 rkujawa
90 1.1 rkujawa static int
91 1.1 rkujawa mppb_match(device_t parent, cfdata_t cf, void *aux)
92 1.1 rkujawa {
93 1.1 rkujawa struct zbus_args *zap;
94 1.1 rkujawa
95 1.1 rkujawa zap = aux;
96 1.1 rkujawa
97 1.1 rkujawa if (zap->manid != ZORRO_MANID_MATAY)
98 1.1 rkujawa return 0;
99 1.1 rkujawa
100 1.1 rkujawa if (zap->prodid != ZORRO_PRODID_PROMETHEUS)
101 1.1 rkujawa return 0;
102 1.1 rkujawa
103 1.1 rkujawa return 1;
104 1.1 rkujawa }
105 1.1 rkujawa
106 1.1 rkujawa
107 1.1 rkujawa static void
108 1.1 rkujawa mppb_attach(device_t parent, device_t self, void *aux)
109 1.1 rkujawa {
110 1.1 rkujawa struct mppb_softc *sc;
111 1.1 rkujawa struct pcibus_attach_args pba;
112 1.1 rkujawa struct zbus_args *zap;
113 1.1 rkujawa pci_chipset_tag_t pc;
114 1.1 rkujawa
115 1.1 rkujawa zap = aux;
116 1.1 rkujawa sc = device_private(self);
117 1.1 rkujawa pc = &sc->apc;
118 1.1 rkujawa sc->sc_dev = self;
119 1.1 rkujawa sc->ba = zap->va;
120 1.1 rkujawa
121 1.1 rkujawa aprint_normal(": Matay Prometheus PCI bridge\n");
122 1.1 rkujawa
123 1.1 rkujawa /* Setup bus space mappings. */
124 1.1 rkujawa sc->pci_conf_area.base = (bus_addr_t) sc->ba + MPPB_CONF_BASE;
125 1.1 rkujawa sc->pci_conf_area.absm = &amiga_bus_stride_1swap;
126 1.1 rkujawa
127 1.1 rkujawa sc->pci_mem_area.base = (bus_addr_t) sc->ba + MPPB_MEM_BASE;
128 1.1 rkujawa sc->pci_mem_area.absm = &amiga_bus_stride_1;
129 1.1 rkujawa
130 1.1 rkujawa sc->pci_io_area.base = (bus_addr_t) sc->ba + MPPB_IO_BASE;
131 1.1 rkujawa sc->pci_io_area.absm = &amiga_bus_stride_1;
132 1.1 rkujawa
133 1.1 rkujawa #ifdef MPPB_DEBUG
134 1.5 rkujawa aprint_normal("mppb mapped conf %x->%x, mem %x->%x\n, io %x->%x\n",
135 1.5 rkujawa kvtop((void*) sc->pci_conf_area.base), sc->pci_conf_area.base,
136 1.5 rkujawa kvtop((void*) sc->pci_mem_area.base), sc->pci_mem_area.base,
137 1.5 rkujawa kvtop((void*) sc->pci_io_area.base), sc->pci_io_area.base);
138 1.1 rkujawa #endif
139 1.1 rkujawa
140 1.2 rkujawa sc->apc.pci_conf_datat = &(sc->pci_conf_area);
141 1.1 rkujawa
142 1.2 rkujawa if (bus_space_map(sc->apc.pci_conf_datat, 0, MPPB_CONF_SIZE, 0,
143 1.2 rkujawa &sc->apc.pci_conf_datah))
144 1.1 rkujawa aprint_error_dev(self,
145 1.1 rkujawa "couldn't map PCI configuration data space\n");
146 1.1 rkujawa
147 1.1 rkujawa /* Initialize the PCI chipset tag. */
148 1.1 rkujawa sc->apc.pc_conf_v = (void*) pc;
149 1.1 rkujawa sc->apc.pc_bus_maxdevs = mppb_pci_bus_maxdevs;
150 1.2 rkujawa sc->apc.pc_make_tag = amiga_pci_make_tag;
151 1.2 rkujawa sc->apc.pc_decompose_tag = amiga_pci_decompose_tag;
152 1.1 rkujawa sc->apc.pc_conf_read = mppb_pci_conf_read;
153 1.1 rkujawa sc->apc.pc_conf_write = mppb_pci_conf_write;
154 1.1 rkujawa sc->apc.pc_attach_hook = mppb_pci_attach_hook;
155 1.1 rkujawa
156 1.1 rkujawa sc->apc.pc_intr_map = mppb_pci_intr_map;
157 1.2 rkujawa sc->apc.pc_intr_string = amiga_pci_intr_string;
158 1.2 rkujawa sc->apc.pc_intr_establish = amiga_pci_intr_establish;
159 1.2 rkujawa sc->apc.pc_intr_disestablish = amiga_pci_intr_disestablish;
160 1.2 rkujawa
161 1.2 rkujawa sc->apc.pc_conf_hook = amiga_pci_conf_hook;
162 1.2 rkujawa sc->apc.pc_conf_interrupt = amiga_pci_conf_interrupt;
163 1.2 rkujawa
164 1.3 rkujawa #ifdef PCI_NETBSD_CONFIGURE
165 1.10 thorpej struct pciconf_resources *pcires = pciconf_resource_init();
166 1.10 thorpej
167 1.10 thorpej pciconf_resource_add(pcires, PCICONF_RESOURCE_IO,
168 1.10 thorpej MPPB_IO_BASE, MPPB_IO_SIZE);
169 1.10 thorpej pciconf_resource_add(pcires, PCICONF_RESOURCE_MEM,
170 1.10 thorpej MPPB_MEM_BASE, MPPB_MEM_SIZE);
171 1.5 rkujawa
172 1.5 rkujawa #ifdef MPPB_DEBUG
173 1.5 rkujawa aprint_normal("mppb: reconfiguring the bus!\n");
174 1.5 rkujawa #endif /* MPPB_DEBUG */
175 1.10 thorpej pci_configure_bus(pc, pcires, 0, CACHELINE_SIZE);
176 1.2 rkujawa
177 1.10 thorpej pciconf_resource_fini(pcires);
178 1.3 rkujawa #endif /* PCI_NETBSD_CONFIGURE */
179 1.2 rkujawa
180 1.1 rkujawa pba.pba_iot = &(sc->pci_io_area);
181 1.1 rkujawa pba.pba_memt = &(sc->pci_mem_area);
182 1.1 rkujawa pba.pba_dmat = NULL;
183 1.1 rkujawa pba.pba_dmat64 = NULL;
184 1.1 rkujawa pba.pba_pc = pc;
185 1.1 rkujawa pba.pba_flags = PCI_FLAGS_MEM_OKAY | PCI_FLAGS_IO_OKAY;
186 1.1 rkujawa pba.pba_bus = 0;
187 1.1 rkujawa pba.pba_bridgetag = NULL;
188 1.1 rkujawa
189 1.10.4.1 thorpej config_found(self, &pba, pcibusprint, CFARG_EOL);
190 1.1 rkujawa }
191 1.1 rkujawa
192 1.1 rkujawa pcireg_t
193 1.1 rkujawa mppb_pci_conf_read(pci_chipset_tag_t pc, pcitag_t tag, int reg)
194 1.1 rkujawa {
195 1.1 rkujawa uint32_t data;
196 1.1 rkujawa uint32_t bus, dev, func;
197 1.8 msaitoh
198 1.8 msaitoh if ((unsigned int)reg >= PCI_CONF_SIZE)
199 1.8 msaitoh return (pcireg_t) -1;
200 1.1 rkujawa
201 1.1 rkujawa pci_decompose_tag(pc, tag, &bus, &dev, &func);
202 1.1 rkujawa
203 1.2 rkujawa data = bus_space_read_4(pc->pci_conf_datat, pc->pci_conf_datah,
204 1.1 rkujawa (MPPB_CONF_STRIDE*dev) + reg);
205 1.5 rkujawa #ifdef MPPB_DEBUG_CONF
206 1.1 rkujawa aprint_normal("mppb conf read va: %lx, bus: %d, dev: %d, "
207 1.1 rkujawa "func: %d, reg: %d -r-> data %x\n",
208 1.2 rkujawa pc->pci_conf_datah, bus, dev, func, reg, data);
209 1.5 rkujawa #endif /* MPPB_DEBUG_CONF */
210 1.1 rkujawa return data;
211 1.1 rkujawa }
212 1.1 rkujawa
213 1.1 rkujawa void
214 1.1 rkujawa mppb_pci_conf_write(pci_chipset_tag_t pc, pcitag_t tag, int reg, pcireg_t val)
215 1.1 rkujawa {
216 1.1 rkujawa uint32_t bus, dev, func;
217 1.1 rkujawa
218 1.8 msaitoh if ((unsigned int)reg >= PCI_CONF_SIZE)
219 1.8 msaitoh return;
220 1.8 msaitoh
221 1.1 rkujawa pci_decompose_tag(pc, tag, &bus, &dev, &func);
222 1.1 rkujawa
223 1.2 rkujawa bus_space_write_4(pc->pci_conf_datat, pc->pci_conf_datah,
224 1.1 rkujawa (MPPB_CONF_STRIDE*dev) + reg, val);
225 1.5 rkujawa #ifdef MPPB_DEBUG_CONF
226 1.1 rkujawa aprint_normal("mppb conf write va: %lx, bus: %d, dev: %d, "
227 1.1 rkujawa "func: %d, reg: %d -w-> data %x\n",
228 1.2 rkujawa pc->pci_conf_datah, bus, dev, func, reg, val);
229 1.5 rkujawa #endif /* MPPB_DEBUG_CONF */
230 1.1 rkujawa
231 1.1 rkujawa }
232 1.1 rkujawa
233 1.1 rkujawa int
234 1.1 rkujawa mppb_pci_bus_maxdevs(pci_chipset_tag_t pc, int busno)
235 1.1 rkujawa {
236 1.1 rkujawa return 4; /* Prometheus has 4 slots */
237 1.1 rkujawa }
238 1.1 rkujawa
239 1.1 rkujawa void
240 1.7 chs mppb_pci_attach_hook(device_t parent, device_t self,
241 1.1 rkujawa struct pcibus_attach_args *pba)
242 1.1 rkujawa {
243 1.1 rkujawa }
244 1.1 rkujawa
245 1.1 rkujawa int
246 1.1 rkujawa mppb_pci_intr_map(const struct pci_attach_args *pa, pci_intr_handle_t *ihp)
247 1.1 rkujawa {
248 1.1 rkujawa /* TODO: add sanity checking */
249 1.1 rkujawa
250 1.1 rkujawa *ihp = MPPB_INT;
251 1.1 rkujawa return 0;
252 1.1 rkujawa }
253 1.1 rkujawa
254 1.1 rkujawa const struct evcnt *
255 1.1 rkujawa mppb_pci_intr_evcnt(pci_chipset_tag_t pc, pci_intr_handle_t ih)
256 1.1 rkujawa {
257 1.1 rkujawa /* TODO: implement */
258 1.1 rkujawa return NULL;
259 1.1 rkujawa }
260