xref: /netbsd-src/sys/arch/alpha/pci/irongate.c (revision 69b6d498973bb4d7230c2d3c12bd9a032738ec8e)
1 /* $NetBSD: irongate.c,v 1.12 2004/08/30 15:05:16 drochner 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.12 2004/08/30 15:05:16 drochner 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 extern struct cfdriver irongate_cd;
74 
75 /* There can be only one. */
76 struct irongate_config irongate_configuration;
77 int	irongate_found;
78 
79 int	irongate_bus_get_window(int, int,
80 	    struct alpha_bus_space_translation *);
81 
82 /*
83  * Set up the chipset's function pointers.
84  */
85 void
86 irongate_init(struct irongate_config *icp, int mallocsafe)
87 {
88 	pcitag_t tag;
89 	pcireg_t reg;
90 
91 	icp->ic_mallocsafe = mallocsafe;
92 
93 	/*
94 	 * Set up PCI configuration space; we can only read the
95 	 * revision info through configuration space.
96 	 */
97 	irongate_pci_init(&icp->ic_pc, icp);
98 	alpha_pci_chipset = &icp->ic_pc;
99 
100 	tag = pci_make_tag(&icp->ic_pc, 0, IRONGATE_PCIHOST_DEV, 0);
101 
102 	/* Read the revision. */
103 	reg = irongate_conf_read0(icp, tag, PCI_CLASS_REG);
104 	icp->ic_rev = PCI_REVISION(reg);
105 
106 	if (icp->ic_initted == 0) {
107 		/* Don't do these twice, since they set up extents. */
108 		irongate_bus_io_init(&icp->ic_iot, icp);
109 		irongate_bus_mem_init(&icp->ic_memt, icp);
110 
111 		/* Only one each PCI I/O and MEM window. */
112 		alpha_bus_window_count[ALPHA_BUS_TYPE_PCI_IO] = 1;
113 		alpha_bus_window_count[ALPHA_BUS_TYPE_PCI_MEM] = 1;
114 
115 		alpha_bus_get_window = irongate_bus_get_window;
116 	}
117 
118 	icp->ic_initted = 1;
119 }
120 
121 int
122 irongate_match(struct device *parent, struct cfdata *match, void *aux)
123 {
124 	struct mainbus_attach_args *ma = aux;
125 
126 	/* Make sure we're looking for an Irongate. */
127 	if (strcmp(ma->ma_name, irongate_cd.cd_name) != 0)
128 		return (0);
129 
130 	if (irongate_found)
131 		return (0);
132 
133 	return (1);
134 }
135 
136 void
137 irongate_attach(struct device *parent, struct device *self, void *aux)
138 {
139 	struct irongate_softc *sc = (void *) self;
140 	struct irongate_config *icp;
141 	struct pcibus_attach_args pba;
142 	struct agpbus_attach_args apa;
143 	pcitag_t tag;
144 
145 	/* Note that we've attached the chipset; can't have 2 Irongates. */
146 	irongate_found = 1;
147 
148 	/*
149 	 * Set up the chipset's info; done once at console init time
150 	 * (maybe), but we must do it here as well to take care of things
151 	 * that need to use memory allocation.
152 	 */
153 	icp = sc->sc_icp = &irongate_configuration;
154 	irongate_init(icp, 1);
155 
156 	printf(": AMD 751 Core Logic + AGP Chipset, rev. %d\n", icp->ic_rev);
157 
158 	irongate_dma_init(icp);
159 
160 	/*
161 	 * Do PCI memory initialization that needs to be deferred until
162 	 * malloc is safe.
163 	 */
164 	irongate_bus_mem_init2(&icp->ic_memt, icp);
165 
166 	switch (cputype) {
167 #ifdef API_UP1000
168 	case ST_API_NAUTILUS:
169 		pci_up1000_pickintr(icp);
170 		break;
171 #endif
172 
173 	default:
174 		panic("irongate_attach: shouldn't be here, really...");
175 	}
176 
177 	tag = pci_make_tag(&icp->ic_pc, 0, IRONGATE_PCIHOST_DEV, 0);
178 
179 	pba.pba_iot = &icp->ic_iot;
180 	pba.pba_memt = &icp->ic_memt;
181 	pba.pba_dmat =
182 	    alphabus_dma_get_tag(&icp->ic_dmat_pci, ALPHA_BUS_PCI);
183 	pba.pba_dmat64 = NULL;
184 	pba.pba_pc = &icp->ic_pc;
185 	pba.pba_bus = 0;
186 	pba.pba_bridgetag = NULL;
187 	pba.pba_flags = PCI_FLAGS_IO_ENABLED | PCI_FLAGS_MEM_ENABLED |
188 	    PCI_FLAGS_MRL_OKAY | PCI_FLAGS_MRM_OKAY | PCI_FLAGS_MWI_OKAY;
189 
190 	if (pci_get_capability(&icp->ic_pc, tag, PCI_CAP_AGP,
191 	    NULL, NULL) != 0) {
192 		apa.apa_pci_args.pa_iot = pba.pba_iot;
193 		apa.apa_pci_args.pa_memt = pba.pba_memt;
194 		apa.apa_pci_args.pa_dmat = pba.pba_dmat;
195 		apa.apa_pci_args.pa_pc = pba.pba_pc;
196 		apa.apa_pci_args.pa_bus = pba.pba_bus;
197 		apa.apa_pci_args.pa_device = IRONGATE_PCIHOST_DEV;
198 		apa.apa_pci_args.pa_function = 0;
199 		apa.apa_pci_args.pa_tag = tag;
200 		apa.apa_pci_args.pa_id =
201 		    irongate_conf_read0(icp, tag, PCI_ID_REG);
202 		apa.apa_pci_args.pa_class =
203 		    irongate_conf_read0(icp, tag, PCI_CLASS_REG);
204 		apa.apa_pci_args.pa_flags = pba.pba_flags;
205 
206 		(void) config_found_ia(self, "agpbus", &apa, agpbusprint);
207 	}
208 
209 	(void) config_found_ia(self, "pcibus", &pba, pcibusprint);
210 }
211 
212 int
213 irongate_bus_get_window(int type, int window,
214     struct alpha_bus_space_translation *abst)
215 {
216 	struct irongate_config *icp = &irongate_configuration;
217 	bus_space_tag_t st;
218 	int error;
219 
220 	switch (type) {
221 	case ALPHA_BUS_TYPE_PCI_IO:
222 		st = &icp->ic_iot;
223 		break;
224 
225 	case ALPHA_BUS_TYPE_PCI_MEM:
226 		st = &icp->ic_memt;
227 		break;
228 
229 	default:
230 		panic("irongate_bus_get_window");
231 	}
232 
233 	error = alpha_bus_space_get_window(st, window, abst);
234 	if (error)
235 		return (error);
236 
237 	abst->abst_sys_start = IRONGATE_PHYSADDR(abst->abst_sys_start);
238 	abst->abst_sys_end = IRONGATE_PHYSADDR(abst->abst_sys_end);
239 
240 	return (0);
241 }
242