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