gt_mainbus.c revision 1.1 1 1.1 matt /* $NetBSD: gt_mainbus.c,v 1.1 2003/03/05 22:08:27 matt Exp $ */
2 1.1 matt
3 1.1 matt /*
4 1.1 matt * Copyright (c) 2002 Wasabi Systems, Inc.
5 1.1 matt * All rights reserved.
6 1.1 matt *
7 1.1 matt * Written by Allen Briggs for Wasabi Systems, Inc.
8 1.1 matt *
9 1.1 matt * Redistribution and use in source and binary forms, with or without
10 1.1 matt * modification, are permitted provided that the following conditions
11 1.1 matt * are met:
12 1.1 matt * 1. Redistributions of source code must retain the above copyright
13 1.1 matt * notice, this list of conditions and the following disclaimer.
14 1.1 matt * 2. Redistributions in binary form must reproduce the above copyright
15 1.1 matt * notice, this list of conditions and the following disclaimer in the
16 1.1 matt * documentation and/or other materials provided with the distribution.
17 1.1 matt * 3. All advertising materials mentioning features or use of this software
18 1.1 matt * must display the following acknowledgement:
19 1.1 matt * This product includes software developed for the NetBSD Project by
20 1.1 matt * Wasabi Systems, Inc.
21 1.1 matt * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22 1.1 matt * or promote products derived from this software without specific prior
23 1.1 matt * written permission.
24 1.1 matt *
25 1.1 matt * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26 1.1 matt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 1.1 matt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 1.1 matt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
29 1.1 matt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 1.1 matt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 1.1 matt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 1.1 matt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 1.1 matt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 1.1 matt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 1.1 matt * POSSIBILITY OF SUCH DAMAGE.
36 1.1 matt */
37 1.1 matt
38 1.1 matt #include <sys/types.h>
39 1.1 matt #include <sys/param.h>
40 1.1 matt #include <sys/device.h>
41 1.1 matt #include <sys/extent.h>
42 1.1 matt #include <sys/malloc.h>
43 1.1 matt
44 1.1 matt #define _POWERPC_BUS_DMA_PRIVATE
45 1.1 matt #include <machine/bus.h>
46 1.1 matt
47 1.1 matt #include <dev/pci/pcivar.h>
48 1.1 matt #include <dev/pci/pciconf.h>
49 1.1 matt
50 1.1 matt #include "opt_marvell.h"
51 1.1 matt #include <dev/marvell/gtreg.h>
52 1.1 matt #include <dev/marvell/gtvar.h>
53 1.1 matt #include <dev/marvell/gtpcireg.h>
54 1.1 matt #include <dev/marvell/gtpcivar.h>
55 1.1 matt
56 1.1 matt extern struct powerpc_bus_space ev64260_gt_mem_bs_tag;
57 1.1 matt extern struct powerpc_bus_space ev64260_pci0_mem_bs_tag;
58 1.1 matt extern struct powerpc_bus_space ev64260_pci0_io_bs_tag;
59 1.1 matt extern struct powerpc_bus_space ev64260_pci1_mem_bs_tag;
60 1.1 matt extern struct powerpc_bus_space ev64260_pci1_io_bs_tag;
61 1.1 matt
62 1.1 matt struct powerpc_bus_dma_tag gt_bus_dma_tag = {
63 1.1 matt 0, /* _bounce_thresh */
64 1.1 matt _bus_dmamap_create,
65 1.1 matt _bus_dmamap_destroy,
66 1.1 matt _bus_dmamap_load,
67 1.1 matt _bus_dmamap_load_mbuf,
68 1.1 matt _bus_dmamap_load_uio,
69 1.1 matt _bus_dmamap_load_raw,
70 1.1 matt _bus_dmamap_unload,
71 1.1 matt _bus_dmamap_sync,
72 1.1 matt _bus_dmamem_alloc,
73 1.1 matt _bus_dmamem_free,
74 1.1 matt _bus_dmamem_map,
75 1.1 matt _bus_dmamem_unmap,
76 1.1 matt _bus_dmamem_mmap,
77 1.1 matt };
78 1.1 matt
79 1.1 matt static int gt_match(struct device *, struct cfdata *, void *);
80 1.1 matt static void gt_attach(struct device *, struct device *, void *);
81 1.1 matt
82 1.1 matt CFATTACH_DECL(gt, sizeof(struct gt_softc), gt_match, gt_attach, NULL, NULL);
83 1.1 matt
84 1.1 matt extern struct cfdriver gt_cd;
85 1.1 matt
86 1.1 matt static int gt_found;
87 1.1 matt
88 1.1 matt int
89 1.1 matt gt_match(struct device *parent, struct cfdata *cf, void *aux)
90 1.1 matt {
91 1.1 matt const char *busname = aux;
92 1.1 matt
93 1.1 matt if (strcmp(busname, gt_cd.cd_name) != 0)
94 1.1 matt return 0;
95 1.1 matt
96 1.1 matt if (gt_found)
97 1.1 matt return 0;
98 1.1 matt
99 1.1 matt return 1;
100 1.1 matt }
101 1.1 matt
102 1.1 matt void
103 1.1 matt gt_attach(struct device *parent, struct device *self, void *aux)
104 1.1 matt {
105 1.1 matt struct gt_softc *gt = (struct gt_softc *) self;
106 1.1 matt
107 1.1 matt gt->gt_vbase = GT_BASE;
108 1.1 matt gt->gt_dmat = >_bus_dma_tag;
109 1.1 matt gt->gt_memt = &ev64260_gt_mem_bs_tag;
110 1.1 matt gt->gt_pci0_memt = &ev64260_pci0_io_bs_tag;
111 1.1 matt gt->gt_pci0_iot = &ev64260_pci0_mem_bs_tag;
112 1.1 matt gt->gt_pci1_memt = &ev64260_pci1_io_bs_tag;
113 1.1 matt gt->gt_pci1_iot = &ev64260_pci1_mem_bs_tag;
114 1.1 matt
115 1.1 matt gt_attach_common(gt);
116 1.1 matt }
117 1.1 matt
118 1.1 matt void
119 1.1 matt gt_setup(struct device *gt)
120 1.1 matt {
121 1.1 matt #if 1
122 1.1 matt GT_DecodeAddr_SET(gt, GT_PCI0_IO_Low_Decode, 0x80000000);
123 1.1 matt GT_DecodeAddr_SET(gt, GT_PCI0_IO_High_Decode, 0x807FFFFF);
124 1.1 matt GT_DecodeAddr_SET(gt, GT_PCI1_IO_Low_Decode, 0x80800000);
125 1.1 matt GT_DecodeAddr_SET(gt, GT_PCI1_IO_High_Decode, 0x80FFFFFF);
126 1.1 matt GT_DecodeAddr_SET(gt, GT_PCI0_Mem0_Low_Decode, 0x81000000);
127 1.1 matt GT_DecodeAddr_SET(gt, GT_PCI0_Mem0_High_Decode, 0x88FFFFFF);
128 1.1 matt GT_DecodeAddr_SET(gt, GT_PCI1_Mem0_Low_Decode, 0x89000000);
129 1.1 matt GT_DecodeAddr_SET(gt, GT_PCI1_Mem0_High_Decode, 0x8FFFFFFF);
130 1.1 matt #endif
131 1.1 matt }
132 1.1 matt
133 1.1 matt void
134 1.1 matt gtpci_config_bus(struct pci_chipset *pc, int busno)
135 1.1 matt {
136 1.1 matt struct extent *ioext, *memext;
137 1.1 matt uint32_t data;
138 1.1 matt pcitag_t tag;
139 1.1 matt #if 0
140 1.1 matt uint32_t data2;
141 1.1 matt int i;
142 1.1 matt #endif
143 1.1 matt
144 1.1 matt switch (busno) {
145 1.1 matt case 0:
146 1.1 matt ioext = extent_create("pciio0", 0x00000600, 0x0000ffff,
147 1.1 matt M_DEVBUF, NULL, 0, EX_NOWAIT);
148 1.1 matt memext = extent_create("pcimem0", 0x81000000, 0x88ffffff,
149 1.1 matt M_DEVBUF, NULL, 0, EX_NOWAIT);
150 1.1 matt break;
151 1.1 matt case 1:
152 1.1 matt ioext = extent_create("pciio1", 0x00000600, 0x0000ffff,
153 1.1 matt M_DEVBUF, NULL, 0, EX_NOWAIT);
154 1.1 matt memext = extent_create("pcimem1", 0x89000000, 0x8fffffff,
155 1.1 matt M_DEVBUF, NULL, 0, EX_NOWAIT);
156 1.1 matt break;
157 1.1 matt }
158 1.1 matt
159 1.1 matt pci_configure_bus(pc, ioext, memext, NULL, 0, 32);
160 1.1 matt
161 1.1 matt extent_destroy(ioext);
162 1.1 matt extent_destroy(memext);
163 1.1 matt
164 1.1 matt gtpci_write(pc, PCI_BASE_ADDR_REGISTERS_ENABLE(pc->pc_md.mdpc_busno),
165 1.1 matt 0xffffffff);
166 1.1 matt
167 1.1 matt tag = gtpci_make_tag(pc, 0, 0, 0);
168 1.1 matt data = gtpci_conf_read(pc, tag, PCI_COMMAND_STATUS_REG);
169 1.1 matt gtpci_conf_write(pc, tag, PCI_COMMAND_STATUS_REG, 0);
170 1.1 matt gtpci_conf_write(pc, tag, 0x10, 0x00000000);
171 1.1 matt gtpci_write(pc, PCI_SCS0_BAR_SIZE(busno), 0x0fffffff);
172 1.1 matt gtpci_conf_write(pc, tag, 0x14, 0x04000000);
173 1.1 matt gtpci_write(pc, PCI_SCS1_BAR_SIZE(busno), 0x03ffffff);
174 1.1 matt gtpci_conf_write(pc, tag, 0x18, 0x10000000);
175 1.1 matt gtpci_write(pc, PCI_SCS2_BAR_SIZE(busno), 0x0fffffff);
176 1.1 matt gtpci_conf_write(pc, tag, 0x1c, 0x0c000000);
177 1.1 matt gtpci_write(pc, PCI_SCS3_BAR_SIZE(busno), 0x03ffffff);
178 1.1 matt gtpci_conf_write(pc, tag, PCI_COMMAND_STATUS_REG, data);
179 1.1 matt
180 1.1 matt #if 0
181 1.1 matt tag = gtpci_make_tag(pc, 0, 0, 1);
182 1.1 matt data = gtpci_conf_read(pc, tag, PCI_COMMAND_STATUS_REG);
183 1.1 matt gtpci_conf_write(pc, tag, PCI_COMMAND_STATUS_REG, 0);
184 1.1 matt gtpci_conf_write(pc, tag, 0x10, 0xfff00000);
185 1.1 matt gtpci_write(pc, PCI_CS0_BAR_SIZE(busno), 0x00000000);
186 1.1 matt gtpci_conf_write(pc, tag, 0x14, 0xfff00000);
187 1.1 matt gtpci_write(pc, PCI_CS1_BAR_SIZE(busno), 0x00000000);
188 1.1 matt gtpci_conf_write(pc, tag, 0x18, 0xfff00000);
189 1.1 matt gtpci_write(pc, PCI_CS2_BAR_SIZE(busno), 0x00000000);
190 1.1 matt gtpci_conf_write(pc, tag, 0x1c, 0xfff00000);
191 1.1 matt gtpci_write(pc, PCI_CS3_BAR_SIZE(busno), 0x00000000);
192 1.1 matt gtpci_conf_write(pc, tag, 0x20, 0xfff00000);
193 1.1 matt gtpci_write(pc, PCI_BOOTCS_BAR_SIZE(busno), 0x00000000);
194 1.1 matt gtpci_conf_write(pc, tag, PCI_COMMAND_STATUS_REG, data);
195 1.1 matt
196 1.1 matt tag = gtpci_make_tag(pc, 0, 0, 2);
197 1.1 matt data = gtpci_conf_read(pc, tag, PCI_COMMAND_STATUS_REG);
198 1.1 matt gtpci_conf_write(pc, tag, PCI_COMMAND_STATUS_REG, 0);
199 1.1 matt gtpci_conf_write(pc, tag, 0x10, 0xfff00000);
200 1.1 matt gtpci_write(pc, PCI_P2P_MEM0_BAR_SIZE(busno), 0x00000000);
201 1.1 matt gtpci_conf_write(pc, tag, 0x14, 0xfff00000);
202 1.1 matt gtpci_write(pc, PCI_P2P_MEM1_BAR_SIZE(busno), 0x00000000);
203 1.1 matt gtpci_conf_write(pc, tag, 0x18, 0xfff00000);
204 1.1 matt gtpci_write(pc, PCI_P2P_IO_BAR_SIZE(busno), 0x00000000);
205 1.1 matt gtpci_conf_write(pc, tag, 0x1c, 0xfff00000);
206 1.1 matt gtpci_write(pc, PCI_CPU_BAR_SIZE(busno), 0x00000000);
207 1.1 matt gtpci_conf_write(pc, tag, PCI_COMMAND_STATUS_REG, data);
208 1.1 matt
209 1.1 matt for (i=4; i<8; i++) {
210 1.1 matt tag = gtpci_make_tag(pc, 0, 0, i);
211 1.1 matt data = gtpci_conf_read(pc, tag, PCI_COMMAND_STATUS_REG);
212 1.1 matt gtpci_conf_write(pc, tag, PCI_COMMAND_STATUS_REG, 0);
213 1.1 matt gtpci_conf_write(pc, tag, 0x10, 0xfff00000);
214 1.1 matt gtpci_conf_write(pc, tag, 0x14, 0xfff00000);
215 1.1 matt gtpci_conf_write(pc, tag, 0x18, 0xfff00000);
216 1.1 matt gtpci_conf_write(pc, tag, 0x1c, 0xfff00000);
217 1.1 matt gtpci_conf_write(pc, tag, 0x20, 0xfff00000);
218 1.1 matt gtpci_conf_write(pc, tag, 0x24, 0xfff00000);
219 1.1 matt gtpci_conf_write(pc, tag, PCI_COMMAND_STATUS_REG, data);
220 1.1 matt }
221 1.1 matt #endif
222 1.1 matt switch (busno) {
223 1.1 matt case 0:
224 1.1 matt /* set Internal Mem to 1d000000 - 1dffffff */
225 1.1 matt tag = gtpci_make_tag(pc, 0, 0, 0);
226 1.1 matt data = gtpci_conf_read(pc, tag, PCI_COMMAND_STATUS_REG);
227 1.1 matt gtpci_conf_write(pc, tag, PCI_COMMAND_STATUS_REG, 0);
228 1.1 matt
229 1.1 matt gtpci_conf_write(pc, tag, 0x20, 0xf1000008);
230 1.1 matt gtpci_conf_write(pc, tag, 0x24, 0xf1000001);
231 1.1 matt
232 1.1 matt gtpci_conf_write(pc, tag, PCI_COMMAND_STATUS_REG, data);
233 1.1 matt break;
234 1.1 matt case 1:
235 1.1 matt /* set Internal Mem to 1f000000 - 1fffffff */
236 1.1 matt tag = gtpci_make_tag(pc, 0, 0, 0);
237 1.1 matt data = gtpci_conf_read(pc, tag, PCI_COMMAND_STATUS_REG);
238 1.1 matt gtpci_conf_write(pc, tag, PCI_COMMAND_STATUS_REG, 0);
239 1.1 matt
240 1.1 matt gtpci_conf_write(pc, tag, 0x20, 0xf1000008);
241 1.1 matt gtpci_conf_write(pc, tag, 0x24, 0xf1000001);
242 1.1 matt
243 1.1 matt gtpci_conf_write(pc, tag, PCI_COMMAND_STATUS_REG, data);
244 1.1 matt break;
245 1.1 matt }
246 1.1 matt
247 1.1 matt #if 0
248 1.1 matt tag = gtpci_make_tag(pc, 0, 0, 3);
249 1.1 matt gtpci_conf_write(pc, tag, PCI_COMMAND_STATUS_REG, data2);
250 1.1 matt #endif
251 1.1 matt
252 1.1 matt data = ~(PCI_BARE_SCS0En | /* PCI_BARE_SCS1En | */ \
253 1.1 matt PCI_BARE_SCS2En | /* PCI_BARE_SCS3En | */ \
254 1.1 matt PCI_BARE_IntMemEn | PCI_BARE_IntIOEn);
255 1.1 matt gtpci_write(pc, PCI_BASE_ADDR_REGISTERS_ENABLE(pc->pc_md.mdpc_busno), data);
256 1.1 matt }
257 1.1 matt
258 1.1 matt void
259 1.1 matt gtpci_md_bus_devorder(pci_chipset_tag_t pc, int busno, char devs[])
260 1.1 matt {
261 1.1 matt int i;
262 1.1 matt
263 1.1 matt for (i = 0; i < 32; i++)
264 1.1 matt *devs++ = i;
265 1.1 matt *devs = -1;
266 1.1 matt }
267 1.1 matt
268 1.1 matt int
269 1.1 matt gtpci_md_conf_hook(pci_chipset_tag_t pc, int bus, int dev, int func,
270 1.1 matt pcireg_t id)
271 1.1 matt {
272 1.1 matt if (bus == 0 && dev == 0)
273 1.1 matt return 0;
274 1.1 matt
275 1.1 matt return 1;
276 1.1 matt }
277 1.1 matt
278 1.1 matt void
279 1.1 matt gtpci_md_conf_interrupt(pci_chipset_tag_t pc, int bus, int dev, int pin,
280 1.1 matt int swiz, int *iline)
281 1.1 matt {
282 1.1 matt }
283 1.1 matt
284 1.1 matt int
285 1.1 matt gtpci_md_intr_map(struct pci_attach_args *pa, pci_intr_handle_t *ihp)
286 1.1 matt {
287 1.1 matt int pin = pa->pa_intrpin;
288 1.1 matt int line = pa->pa_intrline;
289 1.1 matt
290 1.1 matt if (pin > 4) {
291 1.1 matt printf("pci_intr_map: bad interrupt pin %d\n", pin);
292 1.1 matt *ihp = -1;
293 1.1 matt return 1;
294 1.1 matt }
295 1.1 matt
296 1.1 matt *ihp = line;
297 1.1 matt return 0;
298 1.1 matt }
299