gt_mainbus.c revision 1.2.6.2 1 1.2.6.2 uebayasi /* $NetBSD: gt_mainbus.c,v 1.2.6.2 2010/08/17 06:45:01 uebayasi Exp $ */
2 1.2.6.2 uebayasi /*
3 1.2.6.2 uebayasi * Copyright (c) 2010 KIYOHARA Takashi
4 1.2.6.2 uebayasi * All rights reserved.
5 1.2.6.2 uebayasi *
6 1.2.6.2 uebayasi * Redistribution and use in source and binary forms, with or without
7 1.2.6.2 uebayasi * modification, are permitted provided that the following conditions
8 1.2.6.2 uebayasi * are met:
9 1.2.6.2 uebayasi * 1. Redistributions of source code must retain the above copyright
10 1.2.6.2 uebayasi * notice, this list of conditions and the following disclaimer.
11 1.2.6.2 uebayasi * 2. Redistributions in binary form must reproduce the above copyright
12 1.2.6.2 uebayasi * notice, this list of conditions and the following disclaimer in the
13 1.2.6.2 uebayasi * documentation and/or other materials provided with the distribution.
14 1.2.6.2 uebayasi *
15 1.2.6.2 uebayasi * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 1.2.6.2 uebayasi * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 1.2.6.2 uebayasi * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 1.2.6.2 uebayasi * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
19 1.2.6.2 uebayasi * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 1.2.6.2 uebayasi * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21 1.2.6.2 uebayasi * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 1.2.6.2 uebayasi * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
23 1.2.6.2 uebayasi * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
24 1.2.6.2 uebayasi * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 1.2.6.2 uebayasi * POSSIBILITY OF SUCH DAMAGE.
26 1.2.6.2 uebayasi */
27 1.2.6.2 uebayasi
28 1.2.6.2 uebayasi #include <sys/cdefs.h>
29 1.2.6.2 uebayasi __KERNEL_RCSID(0, "$NetBSD: gt_mainbus.c,v 1.2.6.2 2010/08/17 06:45:01 uebayasi Exp $");
30 1.2.6.2 uebayasi
31 1.2.6.2 uebayasi #include "opt_pci.h"
32 1.2.6.2 uebayasi #include "opt_marvell.h"
33 1.2.6.2 uebayasi #include "gtpci.h"
34 1.2.6.2 uebayasi #include "pci.h"
35 1.2.6.2 uebayasi #include "isa.h"
36 1.2.6.2 uebayasi
37 1.2.6.2 uebayasi #define _POWERPC_BUS_DMA_PRIVATE
38 1.2.6.2 uebayasi
39 1.2.6.2 uebayasi #include <sys/param.h>
40 1.2.6.2 uebayasi #include <sys/device.h>
41 1.2.6.2 uebayasi #include <sys/errno.h>
42 1.2.6.2 uebayasi #include <sys/extent.h>
43 1.2.6.2 uebayasi #include <sys/malloc.h>
44 1.2.6.2 uebayasi
45 1.2.6.2 uebayasi #include <machine/autoconf.h>
46 1.2.6.2 uebayasi #include <machine/bus.h>
47 1.2.6.2 uebayasi #include <machine/isa_machdep.h>
48 1.2.6.2 uebayasi #include <machine/pegasosreg.h>
49 1.2.6.2 uebayasi
50 1.2.6.2 uebayasi #include <dev/pci/pcivar.h>
51 1.2.6.2 uebayasi #include <dev/pci/pciconf.h>
52 1.2.6.2 uebayasi
53 1.2.6.2 uebayasi #include <dev/marvell/gtreg.h>
54 1.2.6.2 uebayasi #include <dev/marvell/gtvar.h>
55 1.2.6.2 uebayasi #include <dev/marvell/gtpcireg.h>
56 1.2.6.2 uebayasi #include <dev/marvell/gtpcivar.h>
57 1.2.6.2 uebayasi #include <dev/marvell/marvellvar.h>
58 1.2.6.2 uebayasi #include <dev/ofw/openfirm.h>
59 1.2.6.2 uebayasi
60 1.2.6.2 uebayasi
61 1.2.6.2 uebayasi static int gt_match(device_t, cfdata_t, void *);
62 1.2.6.2 uebayasi static void gt_attach(device_t, device_t, void *);
63 1.2.6.2 uebayasi
64 1.2.6.2 uebayasi #if NGTPCI > 0
65 1.2.6.2 uebayasi static void gtpci_md_attach_hook(device_t, device_t,
66 1.2.6.2 uebayasi struct pcibus_attach_args *);
67 1.2.6.2 uebayasi void gtpci_md_conf_interrupt(void *, int, int, int, int, int *);
68 1.2.6.2 uebayasi int gtpci_md_conf_hook(void *, int, int, int, pcireg_t);
69 1.2.6.2 uebayasi #endif
70 1.2.6.2 uebayasi
71 1.2.6.2 uebayasi CFATTACH_DECL_NEW(gt, sizeof(struct gt_softc), gt_match, gt_attach, NULL, NULL);
72 1.2.6.2 uebayasi
73 1.2.6.2 uebayasi static struct powerpc_bus_space pegasosii_gt_bs_tag = {
74 1.2.6.2 uebayasi .pbs_offset = PEGASOS2_GT_REGBASE,
75 1.2.6.2 uebayasi .pbs_base = 0x00000000,
76 1.2.6.2 uebayasi .pbs_limit = GT_SIZE,
77 1.2.6.2 uebayasi };
78 1.2.6.2 uebayasi static char ex_storage[EXTENT_FIXED_STORAGE_SIZE(8)]
79 1.2.6.2 uebayasi __attribute__((aligned(8)));
80 1.2.6.2 uebayasi
81 1.2.6.2 uebayasi struct powerpc_bus_dma_tag pegasosii_bus_dma_tag = {
82 1.2.6.2 uebayasi 0, /* _bounce_thresh */
83 1.2.6.2 uebayasi _bus_dmamap_create,
84 1.2.6.2 uebayasi _bus_dmamap_destroy,
85 1.2.6.2 uebayasi _bus_dmamap_load,
86 1.2.6.2 uebayasi _bus_dmamap_load_mbuf,
87 1.2.6.2 uebayasi _bus_dmamap_load_uio,
88 1.2.6.2 uebayasi _bus_dmamap_load_raw,
89 1.2.6.2 uebayasi _bus_dmamap_unload,
90 1.2.6.2 uebayasi _bus_dmamap_sync,
91 1.2.6.2 uebayasi _bus_dmamem_alloc,
92 1.2.6.2 uebayasi _bus_dmamem_free,
93 1.2.6.2 uebayasi _bus_dmamem_map,
94 1.2.6.2 uebayasi _bus_dmamem_unmap,
95 1.2.6.2 uebayasi _bus_dmamem_mmap,
96 1.2.6.2 uebayasi };
97 1.2.6.2 uebayasi
98 1.2.6.2 uebayasi #if NGTPCI > 0
99 1.2.6.2 uebayasi struct powerpc_bus_space
100 1.2.6.2 uebayasi gtpci0_io_bs_tag, gtpci0_mem_bs_tag,
101 1.2.6.2 uebayasi gtpci1_io_bs_tag, gtpci1_mem_bs_tag;
102 1.2.6.2 uebayasi #endif
103 1.2.6.2 uebayasi
104 1.2.6.2 uebayasi struct gtpci_prot gtpci0_prot = {
105 1.2.6.2 uebayasi GTPCI_ACBL_RDSIZE_32BYTE |
106 1.2.6.2 uebayasi GTPCI_ACBL_RDMBURST_32BYTE |
107 1.2.6.2 uebayasi GTPCI_ACBL_PCISWAP_BYTESWAP |
108 1.2.6.2 uebayasi GTPCI_ACBL_SNOOP_WB |
109 1.2.6.2 uebayasi GTPCI_ACBL_EN,
110 1.2.6.2 uebayasi 0,
111 1.2.6.2 uebayasi }, gtpci1_prot = {
112 1.2.6.2 uebayasi GTPCI_ACBL_RDSIZE_128BYTE |
113 1.2.6.2 uebayasi GTPCI_ACBL_RDMBURST_32BYTE |
114 1.2.6.2 uebayasi GTPCI_ACBL_PCISWAP_BYTESWAP |
115 1.2.6.2 uebayasi GTPCI_ACBL_SNOOP_WB |
116 1.2.6.2 uebayasi GTPCI_ACBL_EN,
117 1.2.6.2 uebayasi 0,
118 1.2.6.2 uebayasi };
119 1.2.6.2 uebayasi
120 1.2.6.2 uebayasi
121 1.2.6.2 uebayasi int
122 1.2.6.2 uebayasi gt_match(device_t parent, cfdata_t cf, void *aux)
123 1.2.6.2 uebayasi {
124 1.2.6.2 uebayasi struct confargs *ca = aux;
125 1.2.6.2 uebayasi int node, pci, ethernet;
126 1.2.6.2 uebayasi char name[32];
127 1.2.6.2 uebayasi
128 1.2.6.2 uebayasi if (strcmp(ca->ca_name, "gt") != 0 ||
129 1.2.6.2 uebayasi strcmp(model_name, "Pegasos2") != 0)
130 1.2.6.2 uebayasi return 0;
131 1.2.6.2 uebayasi
132 1.2.6.2 uebayasi /* Paranoid check... */
133 1.2.6.2 uebayasi
134 1.2.6.2 uebayasi pci = ethernet = 0;
135 1.2.6.2 uebayasi for (node = OF_child(OF_finddevice("/")); node; node = OF_peer(node)) {
136 1.2.6.2 uebayasi memset(name, 0, sizeof(name));
137 1.2.6.2 uebayasi if (OF_getprop(node, "name", name, sizeof(name)) == -1)
138 1.2.6.2 uebayasi continue;
139 1.2.6.2 uebayasi if (strcmp(name, "pci") == 0)
140 1.2.6.2 uebayasi pci++;
141 1.2.6.2 uebayasi else if (strcmp(name, "ethernet") == 0)
142 1.2.6.2 uebayasi ethernet++;
143 1.2.6.2 uebayasi
144 1.2.6.2 uebayasi }
145 1.2.6.2 uebayasi if (pci == 2 && (ethernet == 1 || ethernet == 0))
146 1.2.6.2 uebayasi return 1;
147 1.2.6.2 uebayasi return 0;
148 1.2.6.2 uebayasi }
149 1.2.6.2 uebayasi
150 1.2.6.2 uebayasi /* ARGSUSED */
151 1.2.6.2 uebayasi void
152 1.2.6.2 uebayasi gt_attach(device_t parent, device_t self, void *aux)
153 1.2.6.2 uebayasi {
154 1.2.6.2 uebayasi struct gt_softc *sc = device_private(self);
155 1.2.6.2 uebayasi #if NGTPCI > 0
156 1.2.6.2 uebayasi uint32_t busrange[2];
157 1.2.6.2 uebayasi int node;
158 1.2.6.2 uebayasi extern struct genppc_pci_chipset
159 1.2.6.2 uebayasi genppc_gtpci0_chipset, genppc_gtpci1_chipset;
160 1.2.6.2 uebayasi #endif
161 1.2.6.2 uebayasi
162 1.2.6.2 uebayasi bus_space_init(&pegasosii_gt_bs_tag, "gt",
163 1.2.6.2 uebayasi ex_storage, sizeof(ex_storage));
164 1.2.6.2 uebayasi
165 1.2.6.2 uebayasi sc->sc_dev = self;
166 1.2.6.2 uebayasi sc->sc_addr = 0x00000000;
167 1.2.6.2 uebayasi sc->sc_iot = &pegasosii_gt_bs_tag;
168 1.2.6.2 uebayasi sc->sc_dmat = &pegasosii_bus_dma_tag;
169 1.2.6.2 uebayasi
170 1.2.6.2 uebayasi if (bus_space_map(sc->sc_iot, sc->sc_addr, GT_SIZE, 0, &sc->sc_ioh) !=
171 1.2.6.2 uebayasi 0) {
172 1.2.6.2 uebayasi aprint_error(": registers map failed\n");
173 1.2.6.2 uebayasi return;
174 1.2.6.2 uebayasi }
175 1.2.6.2 uebayasi
176 1.2.6.2 uebayasi init_ofppc_interrupt();
177 1.2.6.2 uebayasi
178 1.2.6.2 uebayasi #if NGTPCI > 0
179 1.2.6.2 uebayasi /* bus space map the I/O and Memory ranges of PCI unit 1(PCI bus) */
180 1.2.6.2 uebayasi node = of_find_firstchild_byname(OF_finddevice("/"), "pci");
181 1.2.6.2 uebayasi if (node != -1) {
182 1.2.6.2 uebayasi gtpci1_io_bs_tag.pbs_flags =
183 1.2.6.2 uebayasi _BUS_SPACE_LITTLE_ENDIAN | _BUS_SPACE_IO_TYPE;
184 1.2.6.2 uebayasi gtpci1_io_bs_tag.pbs_base = 0x00000000;
185 1.2.6.2 uebayasi if (ofwoea_map_space(RANGE_TYPE_PCI, RANGE_IO, node,
186 1.2.6.2 uebayasi >pci1_io_bs_tag, "gtpci 1 io-space") != 0)
187 1.2.6.2 uebayasi panic("Can't init gtpci 1 io tag");
188 1.2.6.2 uebayasi gtpci1_mem_bs_tag.pbs_flags =
189 1.2.6.2 uebayasi _BUS_SPACE_LITTLE_ENDIAN | _BUS_SPACE_MEM_TYPE;
190 1.2.6.2 uebayasi gtpci1_mem_bs_tag.pbs_base = 0x00000000;
191 1.2.6.2 uebayasi if (ofwoea_map_space(RANGE_TYPE_PCI, RANGE_MEM, node,
192 1.2.6.2 uebayasi >pci1_mem_bs_tag, "gtpci 1 mem-space") != 0)
193 1.2.6.2 uebayasi panic("Can't init gtpci 1 mem tag");
194 1.2.6.2 uebayasi
195 1.2.6.2 uebayasi /* PCI bus number */
196 1.2.6.2 uebayasi if (OF_getprop(node, "bus-range", busrange, sizeof(busrange)) !=
197 1.2.6.2 uebayasi sizeof(busrange)) {
198 1.2.6.2 uebayasi aprint_error(": PCI bus range failed\n");
199 1.2.6.2 uebayasi return;
200 1.2.6.2 uebayasi }
201 1.2.6.2 uebayasi
202 1.2.6.2 uebayasi /* Override some functions */
203 1.2.6.2 uebayasi genppc_gtpci1_chipset.pc_attach_hook = gtpci_md_attach_hook;
204 1.2.6.2 uebayasi genppc_gtpci1_chipset.pc_intr_map = genofw_pci_intr_map;
205 1.2.6.2 uebayasi genppc_gtpci1_chipset.pc_node = node;
206 1.2.6.2 uebayasi genppc_gtpci1_chipset.pc_bus = busrange[0];
207 1.2.6.2 uebayasi genppc_gtpci1_chipset.pc_iot = >pci1_io_bs_tag;
208 1.2.6.2 uebayasi genppc_gtpci1_chipset.pc_memt = >pci1_mem_bs_tag;
209 1.2.6.2 uebayasi
210 1.2.6.2 uebayasi #if NISA > 0
211 1.2.6.2 uebayasi genppc_isa_io_space_tag = gtpci1_io_bs_tag;
212 1.2.6.2 uebayasi genppc_isa_mem_space_tag = gtpci1_mem_bs_tag;
213 1.2.6.2 uebayasi map_isa_ioregs();
214 1.2.6.2 uebayasi ofppc_init_comcons(of_find_firstchild_byname(node, "isa"));
215 1.2.6.2 uebayasi #endif
216 1.2.6.2 uebayasi }
217 1.2.6.2 uebayasi
218 1.2.6.2 uebayasi /* bus space map the I/O and Memory ranges of PCI unit 0(AGP bus) */
219 1.2.6.2 uebayasi if (node != -1)
220 1.2.6.2 uebayasi node = of_getnode_byname(OF_peer(node), "pci");
221 1.2.6.2 uebayasi if (node != -1 && node != 0) {
222 1.2.6.2 uebayasi gtpci0_io_bs_tag.pbs_flags =
223 1.2.6.2 uebayasi _BUS_SPACE_LITTLE_ENDIAN | _BUS_SPACE_IO_TYPE;
224 1.2.6.2 uebayasi gtpci0_io_bs_tag.pbs_base = 0x00000000;
225 1.2.6.2 uebayasi if (ofwoea_map_space(RANGE_TYPE_PCI, RANGE_IO, node,
226 1.2.6.2 uebayasi >pci0_io_bs_tag, "gtpci 0 io-space") != 0)
227 1.2.6.2 uebayasi panic("Can't init gtpci 0 io tag");
228 1.2.6.2 uebayasi gtpci0_mem_bs_tag.pbs_flags =
229 1.2.6.2 uebayasi _BUS_SPACE_LITTLE_ENDIAN | _BUS_SPACE_MEM_TYPE;
230 1.2.6.2 uebayasi gtpci0_mem_bs_tag.pbs_base = 0x00000000;
231 1.2.6.2 uebayasi if (ofwoea_map_space(RANGE_TYPE_PCI, RANGE_MEM, node,
232 1.2.6.2 uebayasi >pci0_mem_bs_tag, "gtpci 0 mem-space") != 0)
233 1.2.6.2 uebayasi panic("Can't init gtpci 0 mem tag");
234 1.2.6.2 uebayasi
235 1.2.6.2 uebayasi /* PCI bus number */
236 1.2.6.2 uebayasi if (OF_getprop(node, "bus-range", busrange, sizeof(busrange)) !=
237 1.2.6.2 uebayasi sizeof(busrange)) {
238 1.2.6.2 uebayasi aprint_error(": AGP bus range failed\n");
239 1.2.6.2 uebayasi return;
240 1.2.6.2 uebayasi }
241 1.2.6.2 uebayasi
242 1.2.6.2 uebayasi genppc_gtpci0_chipset.pc_node = node;
243 1.2.6.2 uebayasi genppc_gtpci0_chipset.pc_bus = busrange[0];
244 1.2.6.2 uebayasi genppc_gtpci0_chipset.pc_iot = >pci0_io_bs_tag;
245 1.2.6.2 uebayasi genppc_gtpci0_chipset.pc_memt = >pci0_mem_bs_tag;
246 1.2.6.2 uebayasi
247 1.2.6.2 uebayasi /* Enable access to space of configuration for AGP. */
248 1.2.6.2 uebayasi bus_space_write_4(sc->sc_iot, sc->sc_ioh, GT_GPP_Value_Set,
249 1.2.6.2 uebayasi (1 << 23));
250 1.2.6.2 uebayasi }
251 1.2.6.2 uebayasi #endif
252 1.2.6.2 uebayasi
253 1.2.6.2 uebayasi gt_attach_common(sc);
254 1.2.6.2 uebayasi
255 1.2.6.2 uebayasi #if NGTPCI > 0
256 1.2.6.2 uebayasi /* Disable access to space of configuration for AGP. */
257 1.2.6.2 uebayasi bus_space_write_4(sc->sc_iot, sc->sc_ioh, GT_GPP_Value_Clear,
258 1.2.6.2 uebayasi (1 << 23));
259 1.2.6.2 uebayasi #endif
260 1.2.6.2 uebayasi }
261 1.2.6.2 uebayasi
262 1.2.6.2 uebayasi
263 1.2.6.2 uebayasi #if NGTPCI > 0
264 1.2.6.2 uebayasi static void
265 1.2.6.2 uebayasi gtpci_md_attach_hook(device_t parent, device_t self,
266 1.2.6.2 uebayasi struct pcibus_attach_args *pba)
267 1.2.6.2 uebayasi {
268 1.2.6.2 uebayasi extern struct genppc_pci_chipset genppc_gtpci1_chipset;
269 1.2.6.2 uebayasi
270 1.2.6.2 uebayasi if (device_is_a(parent, "gtpci") &&
271 1.2.6.2 uebayasi pba->pba_pc == &genppc_gtpci1_chipset) {
272 1.2.6.2 uebayasi /* Setup interrupts for PCI bus */
273 1.2.6.2 uebayasi struct genppc_pci_chipset_businfo *pbi;
274 1.2.6.2 uebayasi
275 1.2.6.2 uebayasi pbi = malloc(sizeof(struct genppc_pci_chipset_businfo),
276 1.2.6.2 uebayasi M_DEVBUF, M_NOWAIT);
277 1.2.6.2 uebayasi KASSERT(pbi != NULL);
278 1.2.6.2 uebayasi pbi->pbi_properties = prop_dictionary_create();
279 1.2.6.2 uebayasi KASSERT(pbi->pbi_properties != NULL);
280 1.2.6.2 uebayasi SIMPLEQ_INIT(&genppc_gtpci1_chipset.pc_pbi);
281 1.2.6.2 uebayasi SIMPLEQ_INSERT_TAIL(&genppc_gtpci1_chipset.pc_pbi, pbi, next);
282 1.2.6.2 uebayasi
283 1.2.6.2 uebayasi genofw_setup_pciintr_map(&genppc_gtpci1_chipset, pbi,
284 1.2.6.2 uebayasi genppc_gtpci1_chipset.pc_node);
285 1.2.6.2 uebayasi }
286 1.2.6.2 uebayasi gtpci_attach_hook(parent, self, pba);
287 1.2.6.2 uebayasi }
288 1.2.6.2 uebayasi
289 1.2.6.2 uebayasi /* ARGSUSED */
290 1.2.6.2 uebayasi void
291 1.2.6.2 uebayasi gtpci_md_conf_interrupt(void * v, int bus, int dev, int pin, int swiz,
292 1.2.6.2 uebayasi int *iline)
293 1.2.6.2 uebayasi {
294 1.2.6.2 uebayasi
295 1.2.6.2 uebayasi /* do nothing */
296 1.2.6.2 uebayasi }
297 1.2.6.2 uebayasi
298 1.2.6.2 uebayasi int
299 1.2.6.2 uebayasi gtpci_md_conf_hook(void *v, int bus, int dev, int func, pcireg_t id)
300 1.2.6.2 uebayasi {
301 1.2.6.2 uebayasi struct gtpci_softc *sc = v;
302 1.2.6.2 uebayasi
303 1.2.6.2 uebayasi if (gtpci_conf_hook(sc->sc_pc, bus, dev, func, id) == 0)
304 1.2.6.2 uebayasi return 0;
305 1.2.6.2 uebayasi return genofw_pci_conf_hook(sc->sc_pc, bus, dev, func, id);
306 1.2.6.2 uebayasi }
307 1.2.6.2 uebayasi #endif
308 1.2.6.2 uebayasi
309 1.2.6.2 uebayasi
310 1.2.6.2 uebayasi void *
311 1.2.6.2 uebayasi marvell_intr_establish(int irq, int ipl, int (*func)(void *), void *arg)
312 1.2.6.2 uebayasi {
313 1.2.6.2 uebayasi
314 1.2.6.2 uebayasi /* pass through */
315 1.2.6.2 uebayasi return intr_establish(irq, IST_LEVEL, ipl, func, arg);
316 1.2.6.2 uebayasi }
317