xref: /netbsd-src/sys/arch/alpha/pci/apecs.c (revision 274254cdae52594c1aa480a736aef78313d15c9c)
1 /* $NetBSD: apecs.c,v 1.49 2009/03/14 21:04:02 dsl Exp $ */
2 
3 /*-
4  * Copyright (c) 2000 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.
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  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 /*
33  * Copyright (c) 1995, 1996 Carnegie-Mellon University.
34  * All rights reserved.
35  *
36  * Author: Chris G. Demetriou
37  *
38  * Permission to use, copy, modify and distribute this software and
39  * its documentation is hereby granted, provided that both the copyright
40  * notice and this permission notice appear in all copies of the
41  * software, derivative works or modified versions, and any portions
42  * thereof, and that both notices appear in supporting documentation.
43  *
44  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
45  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
46  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
47  *
48  * Carnegie Mellon requests users of this software to return to
49  *
50  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
51  *  School of Computer Science
52  *  Carnegie Mellon University
53  *  Pittsburgh PA 15213-3890
54  *
55  * any improvements or extensions that they make and grant Carnegie the
56  * rights to redistribute these changes.
57  */
58 
59 #include "opt_dec_2100_a50.h"
60 #include "opt_dec_eb64plus.h"
61 #include "opt_dec_1000a.h"
62 #include "opt_dec_1000.h"
63 
64 #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
65 
66 __KERNEL_RCSID(0, "$NetBSD: apecs.c,v 1.49 2009/03/14 21:04:02 dsl Exp $");
67 
68 #include <sys/param.h>
69 #include <sys/systm.h>
70 #include <sys/kernel.h>
71 #include <sys/malloc.h>
72 #include <sys/device.h>
73 
74 #include <uvm/uvm_extern.h>
75 
76 #include <machine/autoconf.h>
77 #include <machine/rpb.h>
78 #include <machine/sysarch.h>
79 
80 #include <dev/isa/isareg.h>
81 #include <dev/isa/isavar.h>
82 
83 #include <dev/pci/pcireg.h>
84 #include <dev/pci/pcivar.h>
85 #include <alpha/pci/apecsreg.h>
86 #include <alpha/pci/apecsvar.h>
87 #ifdef DEC_2100_A50
88 #include <alpha/pci/pci_2100_a50.h>
89 #endif
90 #ifdef DEC_EB64PLUS
91 #include <alpha/pci/pci_eb64plus.h>
92 #endif
93 #ifdef DEC_1000A
94 #include <alpha/pci/pci_1000a.h>
95 #endif
96 #ifdef DEC_1000
97 #include <alpha/pci/pci_1000.h>
98 #endif
99 
100 int	apecsmatch(struct device *, struct cfdata *, void *);
101 void	apecsattach(struct device *, struct device *, void *);
102 
103 CFATTACH_DECL(apecs, sizeof(struct apecs_softc),
104     apecsmatch, apecsattach, NULL, NULL);
105 
106 extern struct cfdriver apecs_cd;
107 
108 int	apecs_bus_get_window(int, int,
109 	    struct alpha_bus_space_translation *);
110 
111 /* There can be only one. */
112 int apecsfound;
113 struct apecs_config apecs_configuration;
114 
115 int
116 apecsmatch(struct device *parent, struct cfdata *match, void *aux)
117 {
118 	struct mainbus_attach_args *ma = aux;
119 
120 	/* Make sure that we're looking for an APECS. */
121 	if (strcmp(ma->ma_name, apecs_cd.cd_name) != 0)
122 		return (0);
123 
124 	if (apecsfound)
125 		return (0);
126 
127 	return (1);
128 }
129 
130 /*
131  * Set up the chipset's function pointers.
132  */
133 void
134 apecs_init(struct apecs_config *acp, int mallocsafe)
135 {
136 	acp->ac_comanche_pass2 =
137 	    (REGVAL(COMANCHE_ED) & COMANCHE_ED_PASS2) != 0;
138 	acp->ac_memwidth =
139 	    (REGVAL(COMANCHE_GCR) & COMANCHE_GCR_WIDEMEM) != 0 ? 128 : 64;
140 	acp->ac_epic_pass2 =
141 	    (REGVAL(EPIC_DCSR) & EPIC_DCSR_PASS2) != 0;
142 
143 	acp->ac_haxr1 = REGVAL(EPIC_HAXR1);
144 	acp->ac_haxr2 = REGVAL(EPIC_HAXR2);
145 
146 	if (!acp->ac_initted) {
147 		/* don't do these twice since they set up extents */
148 		apecs_bus_io_init(&acp->ac_iot, acp);
149 		apecs_bus_mem_init(&acp->ac_memt, acp);
150 
151 		/*
152 		 * We have two I/O windows and 3 MEM windows.
153 		 */
154 		alpha_bus_window_count[ALPHA_BUS_TYPE_PCI_IO] = 2;
155 		alpha_bus_window_count[ALPHA_BUS_TYPE_PCI_MEM] = 3;
156 		alpha_bus_get_window = apecs_bus_get_window;
157 	}
158 	acp->ac_mallocsafe = mallocsafe;
159 
160 	apecs_pci_init(&acp->ac_pc, acp);
161 	alpha_pci_chipset = &acp->ac_pc;
162 
163 	acp->ac_initted = 1;
164 }
165 
166 void
167 apecsattach(struct device *parent, struct device *self, void *aux)
168 {
169 	struct apecs_softc *sc = (struct apecs_softc *)self;
170 	struct apecs_config *acp;
171 	struct pcibus_attach_args pba;
172 
173 	/* note that we've attached the chipset; can't have 2 APECSes. */
174 	apecsfound = 1;
175 
176 	/*
177 	 * set up the chipset's info; done once at console init time
178 	 * (maybe), but doesn't hurt to do twice.
179 	 */
180 	acp = sc->sc_acp = &apecs_configuration;
181 	apecs_init(acp, 1);
182 
183 	apecs_dma_init(acp);
184 
185 	printf(": DECchip %s Core Logic chipset\n",
186 	    acp->ac_memwidth == 128 ? "21072" : "21071");
187 	printf("%s: DC21071-CA pass %d, %d-bit memory bus\n",
188 	    self->dv_xname, acp->ac_comanche_pass2 ? 2 : 1, acp->ac_memwidth);
189 	printf("%s: DC21071-DA pass %d\n", self->dv_xname,
190 	    acp->ac_epic_pass2 ? 2 : 1);
191 	/* XXX print bcache size */
192 
193 	if (!acp->ac_epic_pass2)
194 		printf("WARNING: 21071-DA NOT PASS2... NO BETS...\n");
195 
196 	switch (cputype) {
197 #ifdef DEC_2100_A50
198 	case ST_DEC_2100_A50:
199 		pci_2100_a50_pickintr(acp);
200 		break;
201 #endif
202 
203 #ifdef DEC_EB64PLUS
204 	case ST_EB64P:
205 		pci_eb64plus_pickintr(acp);
206 		break;
207 #endif
208 
209 #ifdef DEC_1000A
210 	case ST_DEC_1000A:
211 		pci_1000a_pickintr(acp, &acp->ac_iot, &acp->ac_memt,
212 			&acp->ac_pc);
213 		break;
214 #endif
215 
216 #ifdef DEC_1000
217 	case ST_DEC_1000:
218 		pci_1000_pickintr(acp, &acp->ac_iot, &acp->ac_memt,
219 			&acp->ac_pc);
220 		break;
221 #endif
222 
223 	default:
224 		panic("apecsattach: shouldn't be here, really...");
225 	}
226 
227 	pba.pba_iot = &acp->ac_iot;
228 	pba.pba_memt = &acp->ac_memt;
229 	pba.pba_dmat =
230 	    alphabus_dma_get_tag(&acp->ac_dmat_direct, ALPHA_BUS_PCI);
231 	pba.pba_dmat64 = NULL;
232 	pba.pba_pc = &acp->ac_pc;
233 	pba.pba_bus = 0;
234 	pba.pba_bridgetag = NULL;
235 	pba.pba_flags = PCI_FLAGS_IO_ENABLED | PCI_FLAGS_MEM_ENABLED |
236 	    PCI_FLAGS_MRL_OKAY | PCI_FLAGS_MRM_OKAY | PCI_FLAGS_MWI_OKAY;
237 	config_found_ia(self, "pcibus", &pba, pcibusprint);
238 }
239 
240 int
241 apecs_bus_get_window(int type, int window, struct alpha_bus_space_translation *abst)
242 {
243 	struct apecs_config *acp = &apecs_configuration;
244 	bus_space_tag_t st;
245 
246 	switch (type) {
247 	case ALPHA_BUS_TYPE_PCI_IO:
248 		st = &acp->ac_iot;
249 		break;
250 
251 	case ALPHA_BUS_TYPE_PCI_MEM:
252 		st = &acp->ac_memt;
253 		break;
254 
255 	default:
256 		panic("apecs_bus_get_window");
257 	}
258 
259 	return (alpha_bus_space_get_window(st, window, abst));
260 }
261