gt_mainbus.c revision 1.7 1 1.7 matt /* $NetBSD: gt_mainbus.c,v 1.7 2003/03/24 17:07:17 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.7 matt #include "opt_ev64260.h"
39 1.1 matt #include <sys/types.h>
40 1.1 matt #include <sys/param.h>
41 1.1 matt #include <sys/device.h>
42 1.1 matt #include <sys/extent.h>
43 1.1 matt #include <sys/malloc.h>
44 1.1 matt
45 1.1 matt #define _POWERPC_BUS_DMA_PRIVATE
46 1.1 matt #include <machine/bus.h>
47 1.1 matt
48 1.3 matt #include "opt_pci.h"
49 1.1 matt #include <dev/pci/pcivar.h>
50 1.1 matt #include <dev/pci/pciconf.h>
51 1.1 matt
52 1.1 matt #include "opt_marvell.h"
53 1.1 matt #include <dev/marvell/gtreg.h>
54 1.1 matt #include <dev/marvell/gtvar.h>
55 1.1 matt #include <dev/marvell/gtpcireg.h>
56 1.1 matt #include <dev/marvell/gtpcivar.h>
57 1.1 matt
58 1.3 matt extern struct powerpc_bus_space gt_mem_bs_tag;
59 1.3 matt extern struct powerpc_bus_space gt_pci0_mem_bs_tag;
60 1.3 matt extern struct powerpc_bus_space gt_pci0_io_bs_tag;
61 1.3 matt extern struct powerpc_bus_space gt_pci1_mem_bs_tag;
62 1.3 matt extern struct powerpc_bus_space gt_pci1_io_bs_tag;
63 1.1 matt
64 1.1 matt struct powerpc_bus_dma_tag gt_bus_dma_tag = {
65 1.1 matt 0, /* _bounce_thresh */
66 1.1 matt _bus_dmamap_create,
67 1.1 matt _bus_dmamap_destroy,
68 1.1 matt _bus_dmamap_load,
69 1.1 matt _bus_dmamap_load_mbuf,
70 1.1 matt _bus_dmamap_load_uio,
71 1.1 matt _bus_dmamap_load_raw,
72 1.1 matt _bus_dmamap_unload,
73 1.1 matt _bus_dmamap_sync,
74 1.1 matt _bus_dmamem_alloc,
75 1.1 matt _bus_dmamem_free,
76 1.1 matt _bus_dmamem_map,
77 1.1 matt _bus_dmamem_unmap,
78 1.1 matt _bus_dmamem_mmap,
79 1.1 matt };
80 1.1 matt
81 1.7 matt const int gtpci_skipmask[2] = {
82 1.7 matt #ifdef PCI0_SKIPMASK
83 1.7 matt PCI0_SKIPMASK,
84 1.7 matt #else
85 1.7 matt 0,
86 1.7 matt #endif
87 1.7 matt #ifdef PCI1_SKIPMASK
88 1.7 matt PCI1_SKIPMASK,
89 1.7 matt #else
90 1.7 matt 0,
91 1.7 matt #endif
92 1.7 matt };
93 1.7 matt
94 1.1 matt static int gt_match(struct device *, struct cfdata *, void *);
95 1.1 matt static void gt_attach(struct device *, struct device *, void *);
96 1.1 matt
97 1.1 matt CFATTACH_DECL(gt, sizeof(struct gt_softc), gt_match, gt_attach, NULL, NULL);
98 1.1 matt
99 1.1 matt extern struct cfdriver gt_cd;
100 1.4 matt extern bus_space_handle_t gt_memh;
101 1.1 matt
102 1.1 matt static int gt_found;
103 1.1 matt
104 1.1 matt int
105 1.1 matt gt_match(struct device *parent, struct cfdata *cf, void *aux)
106 1.1 matt {
107 1.4 matt const char **busname = aux;
108 1.1 matt
109 1.4 matt if (strcmp(*busname, gt_cd.cd_name) != 0)
110 1.1 matt return 0;
111 1.1 matt
112 1.1 matt if (gt_found)
113 1.1 matt return 0;
114 1.1 matt
115 1.1 matt return 1;
116 1.1 matt }
117 1.1 matt
118 1.1 matt void
119 1.1 matt gt_attach(struct device *parent, struct device *self, void *aux)
120 1.1 matt {
121 1.1 matt struct gt_softc *gt = (struct gt_softc *) self;
122 1.1 matt
123 1.1 matt gt->gt_dmat = >_bus_dma_tag;
124 1.3 matt gt->gt_memt = >_mem_bs_tag;
125 1.6 matt gt->gt_pci0_memt = >_pci0_mem_bs_tag;
126 1.6 matt gt->gt_pci0_iot = >_pci0_io_bs_tag;
127 1.6 matt gt->gt_pci1_memt = >_pci1_mem_bs_tag;
128 1.6 matt gt->gt_pci1_iot = >_pci1_io_bs_tag;
129 1.1 matt
130 1.4 matt gt->gt_memh = gt_memh;
131 1.1 matt
132 1.6 matt #if 0
133 1.3 matt GT_DecodeAddr_SET(gt, GT_PCI0_IO_Low_Decode,
134 1.3 matt gt_pci0_io_bs_tag.pbs_offset + gt_pci0_io_bs_tag.pbs_base);
135 1.3 matt GT_DecodeAddr_SET(gt, GT_PCI0_IO_High_Decode,
136 1.3 matt gt_pci0_io_bs_tag.pbs_offset + gt_pci0_io_bs_tag.pbs_limit - 1);
137 1.3 matt
138 1.3 matt GT_DecodeAddr_SET(gt, GT_PCI1_IO_Low_Decode,
139 1.3 matt gt_pci1_io_bs_tag.pbs_offset + gt_pci1_io_bs_tag.pbs_base);
140 1.3 matt GT_DecodeAddr_SET(gt, GT_PCI1_IO_High_Decode,
141 1.3 matt gt_pci1_io_bs_tag.pbs_offset + gt_pci1_io_bs_tag.pbs_limit - 1);
142 1.3 matt
143 1.3 matt GT_DecodeAddr_SET(gt, GT_PCI0_Mem0_Low_Decode,
144 1.3 matt gt_pci0_mem_bs_tag.pbs_offset + gt_pci0_mem_bs_tag.pbs_base);
145 1.3 matt GT_DecodeAddr_SET(gt, GT_PCI0_Mem0_High_Decode,
146 1.3 matt gt_pci1_mem_bs_tag.pbs_offset + gt_pci1_mem_bs_tag.pbs_limit - 1);
147 1.3 matt
148 1.3 matt GT_DecodeAddr_SET(gt, GT_PCI1_Mem0_Low_Decode,
149 1.3 matt gt_pci1_mem_bs_tag.pbs_offset + gt_pci1_mem_bs_tag.pbs_base);
150 1.3 matt GT_DecodeAddr_SET(gt, GT_PCI1_Mem0_High_Decode,
151 1.3 matt gt_pci1_mem_bs_tag.pbs_offset + gt_pci1_mem_bs_tag.pbs_limit - 1);
152 1.1 matt #endif
153 1.4 matt
154 1.4 matt gt_attach_common(gt);
155 1.1 matt }
156 1.1 matt
157 1.1 matt void
158 1.6 matt gtpci_bus_configure(struct gtpci_chipset *gtpc)
159 1.1 matt {
160 1.3 matt #ifdef PCI_NETBSD_CONFIGURE
161 1.1 matt struct extent *ioext, *memext;
162 1.7 matt #if 0
163 1.7 matt extern int pci_conf_debug;
164 1.7 matt pci_conf_debug = 1;
165 1.7 matt #endif
166 1.1 matt
167 1.6 matt switch (gtpc->gtpc_busno) {
168 1.1 matt case 0:
169 1.3 matt ioext = extent_create("pci0-io", 0x00000600, 0x0000ffff,
170 1.3 matt M_DEVBUF, NULL, 0, EX_NOWAIT);
171 1.3 matt memext = extent_create("pci0-mem",
172 1.3 matt gt_pci0_mem_bs_tag.pbs_base,
173 1.3 matt gt_pci0_mem_bs_tag.pbs_limit-1,
174 1.3 matt M_DEVBUF, NULL, 0, EX_NOWAIT);
175 1.1 matt break;
176 1.1 matt case 1:
177 1.3 matt ioext = extent_create("pci1-io", 0x00000600, 0x0000ffff,
178 1.3 matt M_DEVBUF, NULL, 0, EX_NOWAIT);
179 1.3 matt memext = extent_create("pci1-mem",
180 1.3 matt gt_pci1_mem_bs_tag.pbs_base,
181 1.3 matt gt_pci1_mem_bs_tag.pbs_limit-1,
182 1.3 matt M_DEVBUF, NULL, 0, EX_NOWAIT);
183 1.1 matt break;
184 1.1 matt }
185 1.1 matt
186 1.6 matt pci_configure_bus(>pc->gtpc_pc, ioext, memext, NULL, 0, 32);
187 1.1 matt
188 1.1 matt extent_destroy(ioext);
189 1.1 matt extent_destroy(memext);
190 1.3 matt #endif /* PCI_NETBSD_CONFIGURE */
191 1.3 matt }
192 1.3 matt
193 1.3 matt void
194 1.3 matt gtpci_md_conf_interrupt(pci_chipset_tag_t pc, int bus, int dev, int pin,
195 1.3 matt int swiz, int *iline)
196 1.3 matt {
197 1.3 matt #ifdef PCI_NETBSD_CONFIGURE
198 1.4 matt struct gtpci_chipset *gtpc = (struct gtpci_chipset *)pc;
199 1.7 matt int line = (gtpc->gtpc_busno == 0 ? PCI0_GPPINTS : PCI1_GPPINTS);
200 1.7 matt *iline = (line >> (8 * ((pin + swiz - 1) & 3))) & 0xff;
201 1.7 matt if (*iline != 0xff)
202 1.7 matt *iline += IRQ_GPP_BASE;
203 1.3 matt #endif /* PCI_NETBSD_CONFIGURE */
204 1.1 matt }
205 1.1 matt
206 1.1 matt void
207 1.1 matt gtpci_md_bus_devorder(pci_chipset_tag_t pc, int busno, char devs[])
208 1.1 matt {
209 1.7 matt struct gtpci_chipset *gtpc = (struct gtpci_chipset *)pc;
210 1.7 matt int dev;
211 1.1 matt
212 1.6 matt /*
213 1.6 matt * Don't bother probing the GT itself.
214 1.6 matt */
215 1.7 matt for (dev = 0; dev < 32; dev++) {
216 1.7 matt if (PCI_CFG_GET_BUSNO(gtpc->gtpc_self) == busno &&
217 1.7 matt (PCI_CFG_GET_DEVNO(gtpc->gtpc_self) == dev ||
218 1.7 matt (gtpci_skipmask[gtpc->gtpc_busno] & (1 << dev))))
219 1.7 matt continue;
220 1.7 matt
221 1.7 matt *devs++ = dev;
222 1.7 matt }
223 1.1 matt *devs = -1;
224 1.1 matt }
225 1.1 matt
226 1.1 matt int
227 1.1 matt gtpci_md_conf_hook(pci_chipset_tag_t pc, int bus, int dev, int func,
228 1.1 matt pcireg_t id)
229 1.1 matt {
230 1.6 matt if (bus == 0 && dev == 0) /* don't configure GT */
231 1.1 matt return 0;
232 1.1 matt
233 1.7 matt return PCI_CONF_ALL;
234 1.1 matt }
235 1.1 matt
236 1.1 matt int
237 1.1 matt gtpci_md_intr_map(struct pci_attach_args *pa, pci_intr_handle_t *ihp)
238 1.1 matt {
239 1.1 matt int pin = pa->pa_intrpin;
240 1.1 matt int line = pa->pa_intrline;
241 1.1 matt
242 1.7 matt if (pin > 4 || line >= NIRQ) {
243 1.1 matt printf("pci_intr_map: bad interrupt pin %d\n", pin);
244 1.1 matt *ihp = -1;
245 1.1 matt return 1;
246 1.1 matt }
247 1.1 matt
248 1.1 matt *ihp = line;
249 1.1 matt return 0;
250 1.1 matt }
251