irongate.c revision 1.4 1 1.4 thorpej /* $NetBSD: irongate.c,v 1.4 2001/09/15 04:33:39 thorpej Exp $ */
2 1.1 thorpej
3 1.1 thorpej /*-
4 1.4 thorpej * Copyright (c) 2000, 2001 The NetBSD Foundation, Inc.
5 1.1 thorpej * All rights reserved.
6 1.1 thorpej *
7 1.1 thorpej * This code is derived from software contributed to The NetBSD Foundation
8 1.4 thorpej * by Jason R. Thorpe of Wasabi Systems, Inc.
9 1.1 thorpej *
10 1.1 thorpej * Redistribution and use in source and binary forms, with or without
11 1.1 thorpej * modification, are permitted provided that the following conditions
12 1.1 thorpej * are met:
13 1.1 thorpej * 1. Redistributions of source code must retain the above copyright
14 1.1 thorpej * notice, this list of conditions and the following disclaimer.
15 1.1 thorpej * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 thorpej * notice, this list of conditions and the following disclaimer in the
17 1.1 thorpej * documentation and/or other materials provided with the distribution.
18 1.1 thorpej * 3. All advertising materials mentioning features or use of this software
19 1.1 thorpej * must display the following acknowledgement:
20 1.1 thorpej * This product includes software developed by the NetBSD
21 1.1 thorpej * Foundation, Inc. and its contributors.
22 1.1 thorpej * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1 thorpej * contributors may be used to endorse or promote products derived
24 1.1 thorpej * from this software without specific prior written permission.
25 1.1 thorpej *
26 1.1 thorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1 thorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1 thorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1 thorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1 thorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1 thorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1 thorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1 thorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1 thorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1 thorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1 thorpej * POSSIBILITY OF SUCH DAMAGE.
37 1.1 thorpej */
38 1.1 thorpej
39 1.1 thorpej #include "opt_api_up1000.h"
40 1.1 thorpej
41 1.1 thorpej #include <sys/cdefs.h>
42 1.1 thorpej
43 1.4 thorpej __KERNEL_RCSID(0, "$NetBSD: irongate.c,v 1.4 2001/09/15 04:33:39 thorpej Exp $");
44 1.1 thorpej
45 1.1 thorpej #include <sys/param.h>
46 1.1 thorpej #include <sys/systm.h>
47 1.1 thorpej #include <sys/device.h>
48 1.1 thorpej #include <sys/malloc.h>
49 1.1 thorpej
50 1.1 thorpej #include <machine/autoconf.h>
51 1.1 thorpej #include <machine/rpb.h>
52 1.1 thorpej #include <machine/sysarch.h>
53 1.1 thorpej
54 1.1 thorpej #include <dev/isa/isareg.h>
55 1.1 thorpej #include <dev/isa/isavar.h>
56 1.1 thorpej #include <dev/pci/pcireg.h>
57 1.1 thorpej #include <dev/pci/pcivar.h>
58 1.4 thorpej #include <dev/pci/agpvar.h>
59 1.1 thorpej
60 1.1 thorpej #include <alpha/pci/irongatereg.h>
61 1.1 thorpej #include <alpha/pci/irongatevar.h>
62 1.1 thorpej
63 1.1 thorpej #ifdef API_UP1000
64 1.1 thorpej #include <alpha/pci/pci_up1000.h>
65 1.1 thorpej #endif
66 1.1 thorpej
67 1.1 thorpej int irongate_match(struct device *, struct cfdata *, void *);
68 1.1 thorpej void irongate_attach(struct device *, struct device *, void *);
69 1.1 thorpej
70 1.1 thorpej struct cfattach irongate_ca = {
71 1.1 thorpej sizeof(struct irongate_softc), irongate_match, irongate_attach,
72 1.1 thorpej };
73 1.1 thorpej
74 1.1 thorpej int irongate_print(void *, const char *pnp);
75 1.1 thorpej
76 1.1 thorpej extern struct cfdriver irongate_cd;
77 1.1 thorpej
78 1.1 thorpej /* There can be only one. */
79 1.1 thorpej struct irongate_config irongate_configuration;
80 1.1 thorpej int irongate_found;
81 1.1 thorpej
82 1.1 thorpej int irongate_bus_get_window(int, int,
83 1.1 thorpej struct alpha_bus_space_translation *);
84 1.1 thorpej
85 1.1 thorpej /*
86 1.1 thorpej * Set up the chipset's function pointers.
87 1.1 thorpej */
88 1.1 thorpej void
89 1.1 thorpej irongate_init(struct irongate_config *icp, int mallocsafe)
90 1.1 thorpej {
91 1.1 thorpej pcitag_t tag;
92 1.1 thorpej pcireg_t reg;
93 1.1 thorpej
94 1.1 thorpej icp->ic_mallocsafe = mallocsafe;
95 1.1 thorpej
96 1.1 thorpej /*
97 1.1 thorpej * Set up PCI configuration space; we can only read the
98 1.1 thorpej * revision info through configuration space.
99 1.1 thorpej */
100 1.1 thorpej irongate_pci_init(&icp->ic_pc, icp);
101 1.1 thorpej alpha_pci_chipset = &icp->ic_pc;
102 1.1 thorpej
103 1.1 thorpej tag = pci_make_tag(&icp->ic_pc, 0, IRONGATE_PCIHOST_DEV, 0);
104 1.1 thorpej
105 1.1 thorpej /* Read the revision. */
106 1.1 thorpej reg = irongate_conf_read0(icp, tag, PCI_CLASS_REG);
107 1.1 thorpej icp->ic_rev = PCI_REVISION(reg);
108 1.1 thorpej
109 1.1 thorpej if (icp->ic_initted == 0) {
110 1.1 thorpej /* Don't do these twice, since they set up extents. */
111 1.1 thorpej irongate_bus_io_init(&icp->ic_iot, icp);
112 1.1 thorpej irongate_bus_mem_init(&icp->ic_memt, icp);
113 1.1 thorpej
114 1.1 thorpej /* Only one each PCI I/O and MEM window. */
115 1.1 thorpej alpha_bus_window_count[ALPHA_BUS_TYPE_PCI_IO] = 1;
116 1.1 thorpej alpha_bus_window_count[ALPHA_BUS_TYPE_PCI_MEM] = 1;
117 1.1 thorpej
118 1.1 thorpej alpha_bus_get_window = irongate_bus_get_window;
119 1.1 thorpej }
120 1.1 thorpej
121 1.1 thorpej icp->ic_initted = 1;
122 1.1 thorpej }
123 1.1 thorpej
124 1.1 thorpej int
125 1.1 thorpej irongate_match(struct device *parent, struct cfdata *match, void *aux)
126 1.1 thorpej {
127 1.1 thorpej struct mainbus_attach_args *ma = aux;
128 1.1 thorpej
129 1.1 thorpej /* Make sure we're looking for an Irongate. */
130 1.1 thorpej if (strcmp(ma->ma_name, irongate_cd.cd_name) != 0)
131 1.1 thorpej return (0);
132 1.1 thorpej
133 1.1 thorpej if (irongate_found)
134 1.1 thorpej return (0);
135 1.1 thorpej
136 1.1 thorpej return (1);
137 1.1 thorpej }
138 1.1 thorpej
139 1.1 thorpej void
140 1.1 thorpej irongate_attach(struct device *parent, struct device *self, void *aux)
141 1.1 thorpej {
142 1.1 thorpej struct irongate_softc *sc = (void *) self;
143 1.1 thorpej struct irongate_config *icp;
144 1.1 thorpej struct pcibus_attach_args pba;
145 1.4 thorpej struct agpbus_attach_args apa;
146 1.4 thorpej pcitag_t tag;
147 1.1 thorpej
148 1.1 thorpej /* Note that we've attached the chipset; can't have 2 Irongates. */
149 1.1 thorpej irongate_found = 1;
150 1.1 thorpej
151 1.1 thorpej /*
152 1.1 thorpej * Set up the chipset's info; done once at console init time
153 1.1 thorpej * (maybe), but we must do it here as well to take care of things
154 1.1 thorpej * that need to use memory allocation.
155 1.1 thorpej */
156 1.1 thorpej icp = sc->sc_icp = &irongate_configuration;
157 1.1 thorpej irongate_init(icp, 1);
158 1.1 thorpej
159 1.1 thorpej printf(": AMD 751 Core Logic + AGP Chipset, rev. %d\n", icp->ic_rev);
160 1.1 thorpej
161 1.1 thorpej irongate_dma_init(icp);
162 1.3 thorpej
163 1.3 thorpej /*
164 1.3 thorpej * Do PCI memory initialization that needs to be deferred until
165 1.3 thorpej * malloc is safe.
166 1.3 thorpej */
167 1.3 thorpej irongate_bus_mem_init2(&icp->ic_memt, icp);
168 1.1 thorpej
169 1.1 thorpej switch (cputype) {
170 1.1 thorpej #ifdef API_UP1000
171 1.1 thorpej case ST_API_NAUTILUS:
172 1.1 thorpej pci_up1000_pickintr(icp);
173 1.1 thorpej break;
174 1.1 thorpej #endif
175 1.1 thorpej
176 1.1 thorpej default:
177 1.1 thorpej panic("irongate_attach: shouldn't be here, really...");
178 1.1 thorpej }
179 1.1 thorpej
180 1.4 thorpej tag = pci_make_tag(&icp->ic_pc, 0, IRONGATE_PCIHOST_DEV, 0);
181 1.4 thorpej
182 1.4 thorpej pba.pba_busname = "pci";
183 1.4 thorpej pba.pba_iot = &icp->ic_iot;
184 1.4 thorpej pba.pba_memt = &icp->ic_memt;
185 1.4 thorpej pba.pba_dmat =
186 1.4 thorpej alphabus_dma_get_tag(&icp->ic_dmat_pci, ALPHA_BUS_PCI);
187 1.4 thorpej pba.pba_pc = &icp->ic_pc;
188 1.4 thorpej pba.pba_bus = 0;
189 1.4 thorpej pba.pba_flags = PCI_FLAGS_IO_ENABLED | PCI_FLAGS_MEM_ENABLED |
190 1.4 thorpej PCI_FLAGS_MRL_OKAY | PCI_FLAGS_MRM_OKAY | PCI_FLAGS_MWI_OKAY;
191 1.4 thorpej
192 1.4 thorpej if (pci_get_capability(&icp->ic_pc, tag, PCI_CAP_AGP,
193 1.4 thorpej NULL, NULL) != 0) {
194 1.4 thorpej apa.apa_busname = "agp";
195 1.4 thorpej apa.apa_pci_args.pa_iot = pba.pba_iot;
196 1.4 thorpej apa.apa_pci_args.pa_memt = pba.pba_memt;
197 1.4 thorpej apa.apa_pci_args.pa_pc = pba.pba_pc;
198 1.4 thorpej apa.apa_pci_args.pa_bus = pba.pba_bus;
199 1.4 thorpej apa.apa_pci_args.pa_device = IRONGATE_PCIHOST_DEV;
200 1.4 thorpej apa.apa_pci_args.pa_function = 0;
201 1.4 thorpej apa.apa_pci_args.pa_tag = tag;
202 1.4 thorpej apa.apa_pci_args.pa_id =
203 1.4 thorpej irongate_conf_read0(icp, tag, PCI_ID_REG);
204 1.4 thorpej apa.apa_pci_args.pa_class =
205 1.4 thorpej irongate_conf_read0(icp, tag, PCI_CLASS_REG);
206 1.4 thorpej apa.apa_pci_args.pa_flags = pba.pba_flags;
207 1.4 thorpej
208 1.4 thorpej config_found(self, &apa, irongate_print);
209 1.4 thorpej }
210 1.4 thorpej
211 1.1 thorpej pba.pba_busname = "pci";
212 1.1 thorpej pba.pba_iot = &icp->ic_iot;
213 1.1 thorpej pba.pba_memt = &icp->ic_memt;
214 1.1 thorpej pba.pba_dmat =
215 1.1 thorpej alphabus_dma_get_tag(&icp->ic_dmat_pci, ALPHA_BUS_PCI);
216 1.1 thorpej pba.pba_pc = &icp->ic_pc;
217 1.1 thorpej pba.pba_bus = 0;
218 1.1 thorpej pba.pba_flags = PCI_FLAGS_IO_ENABLED | PCI_FLAGS_MEM_ENABLED |
219 1.1 thorpej PCI_FLAGS_MRL_OKAY | PCI_FLAGS_MRM_OKAY | PCI_FLAGS_MWI_OKAY;
220 1.1 thorpej (void) config_found(self, &pba, irongate_print);
221 1.1 thorpej }
222 1.1 thorpej
223 1.1 thorpej int
224 1.1 thorpej irongate_print(void *aux, const char *pnp)
225 1.1 thorpej {
226 1.1 thorpej struct pcibus_attach_args *pba = aux;
227 1.1 thorpej
228 1.1 thorpej /* Only PCIs can attach to Irongates; easy. */
229 1.1 thorpej if (pnp != NULL)
230 1.1 thorpej printf("%s at %s", pba->pba_busname, pnp);
231 1.4 thorpej if (strcmp(pba->pba_busname, "pci") == 0)
232 1.4 thorpej printf(" bus %d", pba->pba_bus);
233 1.1 thorpej return (UNCONF);
234 1.1 thorpej }
235 1.1 thorpej
236 1.1 thorpej int
237 1.1 thorpej irongate_bus_get_window(int type, int window,
238 1.1 thorpej struct alpha_bus_space_translation *abst)
239 1.1 thorpej {
240 1.1 thorpej struct irongate_config *icp = &irongate_configuration;
241 1.1 thorpej bus_space_tag_t st;
242 1.2 thorpej int error;
243 1.1 thorpej
244 1.1 thorpej switch (type) {
245 1.1 thorpej case ALPHA_BUS_TYPE_PCI_IO:
246 1.1 thorpej st = &icp->ic_iot;
247 1.1 thorpej break;
248 1.1 thorpej
249 1.1 thorpej case ALPHA_BUS_TYPE_PCI_MEM:
250 1.1 thorpej st = &icp->ic_memt;
251 1.1 thorpej break;
252 1.1 thorpej
253 1.1 thorpej default:
254 1.1 thorpej panic("irongate_bus_get_window");
255 1.1 thorpej }
256 1.1 thorpej
257 1.2 thorpej error = alpha_bus_space_get_window(st, window, abst);
258 1.2 thorpej if (error)
259 1.2 thorpej return (error);
260 1.2 thorpej
261 1.2 thorpej abst->abst_sys_start = IRONGATE_PHYSADDR(abst->abst_sys_start);
262 1.2 thorpej abst->abst_sys_end = IRONGATE_PHYSADDR(abst->abst_sys_end);
263 1.2 thorpej
264 1.2 thorpej return (0);
265 1.1 thorpej }
266