apecs.c revision 1.41
1/* $NetBSD: apecs.c,v 1.41 2002/10/02 04:06:39 thorpej 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 * 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/*
40 * Copyright (c) 1995, 1996 Carnegie-Mellon University.
41 * All rights reserved.
42 *
43 * Author: Chris G. Demetriou
44 *
45 * Permission to use, copy, modify and distribute this software and
46 * its documentation is hereby granted, provided that both the copyright
47 * notice and this permission notice appear in all copies of the
48 * software, derivative works or modified versions, and any portions
49 * thereof, and that both notices appear in supporting documentation.
50 *
51 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
52 * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
53 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
54 *
55 * Carnegie Mellon requests users of this software to return to
56 *
57 *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
58 *  School of Computer Science
59 *  Carnegie Mellon University
60 *  Pittsburgh PA 15213-3890
61 *
62 * any improvements or extensions that they make and grant Carnegie the
63 * rights to redistribute these changes.
64 */
65
66#include "opt_dec_2100_a50.h"
67#include "opt_dec_eb64plus.h"
68#include "opt_dec_1000a.h"
69#include "opt_dec_1000.h"
70
71#include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
72
73__KERNEL_RCSID(0, "$NetBSD: apecs.c,v 1.41 2002/10/02 04:06:39 thorpej Exp $");
74
75#include <sys/param.h>
76#include <sys/systm.h>
77#include <sys/kernel.h>
78#include <sys/malloc.h>
79#include <sys/device.h>
80
81#include <uvm/uvm_extern.h>
82
83#include <machine/autoconf.h>
84#include <machine/rpb.h>
85#include <machine/sysarch.h>
86
87#include <dev/isa/isareg.h>
88#include <dev/isa/isavar.h>
89
90#include <dev/pci/pcireg.h>
91#include <dev/pci/pcivar.h>
92#include <alpha/pci/apecsreg.h>
93#include <alpha/pci/apecsvar.h>
94#ifdef DEC_2100_A50
95#include <alpha/pci/pci_2100_a50.h>
96#endif
97#ifdef DEC_EB64PLUS
98#include <alpha/pci/pci_eb64plus.h>
99#endif
100#ifdef DEC_1000A
101#include <alpha/pci/pci_1000a.h>
102#endif
103#ifdef DEC_1000
104#include <alpha/pci/pci_1000.h>
105#endif
106
107int	apecsmatch __P((struct device *, struct cfdata *, void *));
108void	apecsattach __P((struct device *, struct device *, void *));
109
110CFATTACH_DECL(apecs, sizeof(struct apecs_softc),
111    apecsmatch, apecsattach, NULL, NULL);
112
113extern struct cfdriver apecs_cd;
114
115static int	apecsprint __P((void *, const char *pnp));
116
117int	apecs_bus_get_window __P((int, int,
118	    struct alpha_bus_space_translation *));
119
120/* There can be only one. */
121int apecsfound;
122struct apecs_config apecs_configuration;
123
124int
125apecsmatch(parent, match, aux)
126	struct device *parent;
127	struct cfdata *match;
128	void *aux;
129{
130	struct mainbus_attach_args *ma = aux;
131
132	/* Make sure that we're looking for an APECS. */
133	if (strcmp(ma->ma_name, apecs_cd.cd_name) != 0)
134		return (0);
135
136	if (apecsfound)
137		return (0);
138
139	return (1);
140}
141
142/*
143 * Set up the chipset's function pointers.
144 */
145void
146apecs_init(acp, mallocsafe)
147	struct apecs_config *acp;
148	int mallocsafe;
149{
150	acp->ac_comanche_pass2 =
151	    (REGVAL(COMANCHE_ED) & COMANCHE_ED_PASS2) != 0;
152	acp->ac_memwidth =
153	    (REGVAL(COMANCHE_GCR) & COMANCHE_GCR_WIDEMEM) != 0 ? 128 : 64;
154	acp->ac_epic_pass2 =
155	    (REGVAL(EPIC_DCSR) & EPIC_DCSR_PASS2) != 0;
156
157	acp->ac_haxr1 = REGVAL(EPIC_HAXR1);
158	acp->ac_haxr2 = REGVAL(EPIC_HAXR2);
159
160	if (!acp->ac_initted) {
161		/* don't do these twice since they set up extents */
162		apecs_bus_io_init(&acp->ac_iot, acp);
163		apecs_bus_mem_init(&acp->ac_memt, acp);
164
165		/*
166		 * We have two I/O windows and 3 MEM windows.
167		 */
168		alpha_bus_window_count[ALPHA_BUS_TYPE_PCI_IO] = 2;
169		alpha_bus_window_count[ALPHA_BUS_TYPE_PCI_MEM] = 3;
170		alpha_bus_get_window = apecs_bus_get_window;
171	}
172	acp->ac_mallocsafe = mallocsafe;
173
174	apecs_pci_init(&acp->ac_pc, acp);
175	alpha_pci_chipset = &acp->ac_pc;
176
177	acp->ac_initted = 1;
178}
179
180void
181apecsattach(parent, self, aux)
182	struct device *parent, *self;
183	void *aux;
184{
185	struct apecs_softc *sc = (struct apecs_softc *)self;
186	struct apecs_config *acp;
187	struct pcibus_attach_args pba;
188
189	/* note that we've attached the chipset; can't have 2 APECSes. */
190	apecsfound = 1;
191
192	/*
193	 * set up the chipset's info; done once at console init time
194	 * (maybe), but doesn't hurt to do twice.
195	 */
196	acp = sc->sc_acp = &apecs_configuration;
197	apecs_init(acp, 1);
198
199	apecs_dma_init(acp);
200
201	printf(": DECchip %s Core Logic chipset\n",
202	    acp->ac_memwidth == 128 ? "21072" : "21071");
203	printf("%s: DC21071-CA pass %d, %d-bit memory bus\n",
204	    self->dv_xname, acp->ac_comanche_pass2 ? 2 : 1, acp->ac_memwidth);
205	printf("%s: DC21071-DA pass %d\n", self->dv_xname,
206	    acp->ac_epic_pass2 ? 2 : 1);
207	/* XXX print bcache size */
208
209	if (!acp->ac_epic_pass2)
210		printf("WARNING: 21071-DA NOT PASS2... NO BETS...\n");
211
212	switch (cputype) {
213#ifdef DEC_2100_A50
214	case ST_DEC_2100_A50:
215		pci_2100_a50_pickintr(acp);
216		break;
217#endif
218
219#ifdef DEC_EB64PLUS
220	case ST_EB64P:
221		pci_eb64plus_pickintr(acp);
222		break;
223#endif
224
225#ifdef DEC_1000A
226	case ST_DEC_1000A:
227		pci_1000a_pickintr(acp, &acp->ac_iot, &acp->ac_memt,
228			&acp->ac_pc);
229		break;
230#endif
231
232#ifdef DEC_1000
233	case ST_DEC_1000:
234		pci_1000_pickintr(acp, &acp->ac_iot, &acp->ac_memt,
235			&acp->ac_pc);
236		break;
237#endif
238
239	default:
240		panic("apecsattach: shouldn't be here, really...");
241	}
242
243	pba.pba_busname = "pci";
244	pba.pba_iot = &acp->ac_iot;
245	pba.pba_memt = &acp->ac_memt;
246	pba.pba_dmat =
247	    alphabus_dma_get_tag(&acp->ac_dmat_direct, ALPHA_BUS_PCI);
248	pba.pba_pc = &acp->ac_pc;
249	pba.pba_bus = 0;
250	pba.pba_bridgetag = NULL;
251	pba.pba_flags = PCI_FLAGS_IO_ENABLED | PCI_FLAGS_MEM_ENABLED |
252	    PCI_FLAGS_MRL_OKAY | PCI_FLAGS_MRM_OKAY | PCI_FLAGS_MWI_OKAY;
253	config_found(self, &pba, apecsprint);
254}
255
256static int
257apecsprint(aux, pnp)
258	void *aux;
259	const char *pnp;
260{
261	register struct pcibus_attach_args *pba = aux;
262
263	/* only PCIs can attach to APECSes; easy. */
264	if (pnp)
265		printf("%s at %s", pba->pba_busname, pnp);
266	printf(" bus %d", pba->pba_bus);
267	return (UNCONF);
268}
269
270int
271apecs_bus_get_window(type, window, abst)
272	int type, window;
273	struct alpha_bus_space_translation *abst;
274{
275	struct apecs_config *acp = &apecs_configuration;
276	bus_space_tag_t st;
277
278	switch (type) {
279	case ALPHA_BUS_TYPE_PCI_IO:
280		st = &acp->ac_iot;
281		break;
282
283	case ALPHA_BUS_TYPE_PCI_MEM:
284		st = &acp->ac_memt;
285		break;
286
287	default:
288		panic("apecs_bus_get_window");
289	}
290
291	return (alpha_bus_space_get_window(st, window, abst));
292}
293