gt_mainbus.c revision 1.7 1 /* $NetBSD: gt_mainbus.c,v 1.7 2003/03/24 17:07:17 matt Exp $ */
2
3 /*
4 * Copyright (c) 2002 Wasabi Systems, Inc.
5 * All rights reserved.
6 *
7 * Written by Allen Briggs for Wasabi Systems, Inc.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed for the NetBSD Project by
20 * Wasabi Systems, Inc.
21 * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22 * or promote products derived from this software without specific prior
23 * written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
36 */
37
38 #include "opt_ev64260.h"
39 #include <sys/types.h>
40 #include <sys/param.h>
41 #include <sys/device.h>
42 #include <sys/extent.h>
43 #include <sys/malloc.h>
44
45 #define _POWERPC_BUS_DMA_PRIVATE
46 #include <machine/bus.h>
47
48 #include "opt_pci.h"
49 #include <dev/pci/pcivar.h>
50 #include <dev/pci/pciconf.h>
51
52 #include "opt_marvell.h"
53 #include <dev/marvell/gtreg.h>
54 #include <dev/marvell/gtvar.h>
55 #include <dev/marvell/gtpcireg.h>
56 #include <dev/marvell/gtpcivar.h>
57
58 extern struct powerpc_bus_space gt_mem_bs_tag;
59 extern struct powerpc_bus_space gt_pci0_mem_bs_tag;
60 extern struct powerpc_bus_space gt_pci0_io_bs_tag;
61 extern struct powerpc_bus_space gt_pci1_mem_bs_tag;
62 extern struct powerpc_bus_space gt_pci1_io_bs_tag;
63
64 struct powerpc_bus_dma_tag gt_bus_dma_tag = {
65 0, /* _bounce_thresh */
66 _bus_dmamap_create,
67 _bus_dmamap_destroy,
68 _bus_dmamap_load,
69 _bus_dmamap_load_mbuf,
70 _bus_dmamap_load_uio,
71 _bus_dmamap_load_raw,
72 _bus_dmamap_unload,
73 _bus_dmamap_sync,
74 _bus_dmamem_alloc,
75 _bus_dmamem_free,
76 _bus_dmamem_map,
77 _bus_dmamem_unmap,
78 _bus_dmamem_mmap,
79 };
80
81 const int gtpci_skipmask[2] = {
82 #ifdef PCI0_SKIPMASK
83 PCI0_SKIPMASK,
84 #else
85 0,
86 #endif
87 #ifdef PCI1_SKIPMASK
88 PCI1_SKIPMASK,
89 #else
90 0,
91 #endif
92 };
93
94 static int gt_match(struct device *, struct cfdata *, void *);
95 static void gt_attach(struct device *, struct device *, void *);
96
97 CFATTACH_DECL(gt, sizeof(struct gt_softc), gt_match, gt_attach, NULL, NULL);
98
99 extern struct cfdriver gt_cd;
100 extern bus_space_handle_t gt_memh;
101
102 static int gt_found;
103
104 int
105 gt_match(struct device *parent, struct cfdata *cf, void *aux)
106 {
107 const char **busname = aux;
108
109 if (strcmp(*busname, gt_cd.cd_name) != 0)
110 return 0;
111
112 if (gt_found)
113 return 0;
114
115 return 1;
116 }
117
118 void
119 gt_attach(struct device *parent, struct device *self, void *aux)
120 {
121 struct gt_softc *gt = (struct gt_softc *) self;
122
123 gt->gt_dmat = >_bus_dma_tag;
124 gt->gt_memt = >_mem_bs_tag;
125 gt->gt_pci0_memt = >_pci0_mem_bs_tag;
126 gt->gt_pci0_iot = >_pci0_io_bs_tag;
127 gt->gt_pci1_memt = >_pci1_mem_bs_tag;
128 gt->gt_pci1_iot = >_pci1_io_bs_tag;
129
130 gt->gt_memh = gt_memh;
131
132 #if 0
133 GT_DecodeAddr_SET(gt, GT_PCI0_IO_Low_Decode,
134 gt_pci0_io_bs_tag.pbs_offset + gt_pci0_io_bs_tag.pbs_base);
135 GT_DecodeAddr_SET(gt, GT_PCI0_IO_High_Decode,
136 gt_pci0_io_bs_tag.pbs_offset + gt_pci0_io_bs_tag.pbs_limit - 1);
137
138 GT_DecodeAddr_SET(gt, GT_PCI1_IO_Low_Decode,
139 gt_pci1_io_bs_tag.pbs_offset + gt_pci1_io_bs_tag.pbs_base);
140 GT_DecodeAddr_SET(gt, GT_PCI1_IO_High_Decode,
141 gt_pci1_io_bs_tag.pbs_offset + gt_pci1_io_bs_tag.pbs_limit - 1);
142
143 GT_DecodeAddr_SET(gt, GT_PCI0_Mem0_Low_Decode,
144 gt_pci0_mem_bs_tag.pbs_offset + gt_pci0_mem_bs_tag.pbs_base);
145 GT_DecodeAddr_SET(gt, GT_PCI0_Mem0_High_Decode,
146 gt_pci1_mem_bs_tag.pbs_offset + gt_pci1_mem_bs_tag.pbs_limit - 1);
147
148 GT_DecodeAddr_SET(gt, GT_PCI1_Mem0_Low_Decode,
149 gt_pci1_mem_bs_tag.pbs_offset + gt_pci1_mem_bs_tag.pbs_base);
150 GT_DecodeAddr_SET(gt, GT_PCI1_Mem0_High_Decode,
151 gt_pci1_mem_bs_tag.pbs_offset + gt_pci1_mem_bs_tag.pbs_limit - 1);
152 #endif
153
154 gt_attach_common(gt);
155 }
156
157 void
158 gtpci_bus_configure(struct gtpci_chipset *gtpc)
159 {
160 #ifdef PCI_NETBSD_CONFIGURE
161 struct extent *ioext, *memext;
162 #if 0
163 extern int pci_conf_debug;
164 pci_conf_debug = 1;
165 #endif
166
167 switch (gtpc->gtpc_busno) {
168 case 0:
169 ioext = extent_create("pci0-io", 0x00000600, 0x0000ffff,
170 M_DEVBUF, NULL, 0, EX_NOWAIT);
171 memext = extent_create("pci0-mem",
172 gt_pci0_mem_bs_tag.pbs_base,
173 gt_pci0_mem_bs_tag.pbs_limit-1,
174 M_DEVBUF, NULL, 0, EX_NOWAIT);
175 break;
176 case 1:
177 ioext = extent_create("pci1-io", 0x00000600, 0x0000ffff,
178 M_DEVBUF, NULL, 0, EX_NOWAIT);
179 memext = extent_create("pci1-mem",
180 gt_pci1_mem_bs_tag.pbs_base,
181 gt_pci1_mem_bs_tag.pbs_limit-1,
182 M_DEVBUF, NULL, 0, EX_NOWAIT);
183 break;
184 }
185
186 pci_configure_bus(>pc->gtpc_pc, ioext, memext, NULL, 0, 32);
187
188 extent_destroy(ioext);
189 extent_destroy(memext);
190 #endif /* PCI_NETBSD_CONFIGURE */
191 }
192
193 void
194 gtpci_md_conf_interrupt(pci_chipset_tag_t pc, int bus, int dev, int pin,
195 int swiz, int *iline)
196 {
197 #ifdef PCI_NETBSD_CONFIGURE
198 struct gtpci_chipset *gtpc = (struct gtpci_chipset *)pc;
199 int line = (gtpc->gtpc_busno == 0 ? PCI0_GPPINTS : PCI1_GPPINTS);
200 *iline = (line >> (8 * ((pin + swiz - 1) & 3))) & 0xff;
201 if (*iline != 0xff)
202 *iline += IRQ_GPP_BASE;
203 #endif /* PCI_NETBSD_CONFIGURE */
204 }
205
206 void
207 gtpci_md_bus_devorder(pci_chipset_tag_t pc, int busno, char devs[])
208 {
209 struct gtpci_chipset *gtpc = (struct gtpci_chipset *)pc;
210 int dev;
211
212 /*
213 * Don't bother probing the GT itself.
214 */
215 for (dev = 0; dev < 32; dev++) {
216 if (PCI_CFG_GET_BUSNO(gtpc->gtpc_self) == busno &&
217 (PCI_CFG_GET_DEVNO(gtpc->gtpc_self) == dev ||
218 (gtpci_skipmask[gtpc->gtpc_busno] & (1 << dev))))
219 continue;
220
221 *devs++ = dev;
222 }
223 *devs = -1;
224 }
225
226 int
227 gtpci_md_conf_hook(pci_chipset_tag_t pc, int bus, int dev, int func,
228 pcireg_t id)
229 {
230 if (bus == 0 && dev == 0) /* don't configure GT */
231 return 0;
232
233 return PCI_CONF_ALL;
234 }
235
236 int
237 gtpci_md_intr_map(struct pci_attach_args *pa, pci_intr_handle_t *ihp)
238 {
239 int pin = pa->pa_intrpin;
240 int line = pa->pa_intrline;
241
242 if (pin > 4 || line >= NIRQ) {
243 printf("pci_intr_map: bad interrupt pin %d\n", pin);
244 *ihp = -1;
245 return 1;
246 }
247
248 *ihp = line;
249 return 0;
250 }
251