apecs.c revision 1.26 1 /* $NetBSD: apecs.c,v 1.26 1997/09/02 13:19:08 thorpej Exp $ */
2
3 /*
4 * Copyright (c) 1995, 1996 Carnegie-Mellon University.
5 * All rights reserved.
6 *
7 * Author: Chris G. Demetriou
8 *
9 * Permission to use, copy, modify and distribute this software and
10 * its documentation is hereby granted, provided that both the copyright
11 * notice and this permission notice appear in all copies of the
12 * software, derivative works or modified versions, and any portions
13 * thereof, and that both notices appear in supporting documentation.
14 *
15 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
16 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
17 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
18 *
19 * Carnegie Mellon requests users of this software to return to
20 *
21 * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU
22 * School of Computer Science
23 * Carnegie Mellon University
24 * Pittsburgh PA 15213-3890
25 *
26 * any improvements or extensions that they make and grant Carnegie the
27 * rights to redistribute these changes.
28 */
29
30 #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
31
32 __KERNEL_RCSID(0, "$NetBSD: apecs.c,v 1.26 1997/09/02 13:19:08 thorpej Exp $");
33
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/kernel.h>
37 #include <sys/malloc.h>
38 #include <sys/device.h>
39 #include <vm/vm.h>
40
41 #include <machine/autoconf.h>
42 #include <machine/rpb.h>
43
44 #include <dev/isa/isareg.h>
45 #include <dev/isa/isavar.h>
46
47 #include <dev/pci/pcireg.h>
48 #include <dev/pci/pcivar.h>
49 #include <alpha/pci/apecsreg.h>
50 #include <alpha/pci/apecsvar.h>
51 #ifdef DEC_2100_A50
52 #include <alpha/pci/pci_2100_a50.h>
53 #endif
54
55 int apecsmatch __P((struct device *, struct cfdata *, void *));
56 void apecsattach __P((struct device *, struct device *, void *));
57
58 struct cfattach apecs_ca = {
59 sizeof(struct apecs_softc), apecsmatch, apecsattach,
60 };
61
62 struct cfdriver apecs_cd = {
63 NULL, "apecs", DV_DULL,
64 };
65
66 static int apecsprint __P((void *, const char *pnp));
67
68 /* There can be only one. */
69 int apecsfound;
70 struct apecs_config apecs_configuration;
71
72 int
73 apecsmatch(parent, match, aux)
74 struct device *parent;
75 struct cfdata *match;
76 void *aux;
77 {
78 struct confargs *ca = aux;
79
80 /* Make sure that we're looking for an APECS. */
81 if (strcmp(ca->ca_name, apecs_cd.cd_name) != 0)
82 return (0);
83
84 if (apecsfound)
85 return (0);
86
87 return (1);
88 }
89
90 /*
91 * Set up the chipset's function pointers.
92 */
93 void
94 apecs_init(acp, mallocsafe)
95 struct apecs_config *acp;
96 int mallocsafe;
97 {
98 acp->ac_comanche_pass2 =
99 (REGVAL(COMANCHE_ED) & COMANCHE_ED_PASS2) != 0;
100 acp->ac_memwidth =
101 (REGVAL(COMANCHE_GCR) & COMANCHE_GCR_WIDEMEM) != 0 ? 128 : 64;
102 acp->ac_epic_pass2 =
103 (REGVAL(EPIC_DCSR) & EPIC_DCSR_PASS2) != 0;
104
105 acp->ac_haxr1 = REGVAL(EPIC_HAXR1);
106 acp->ac_haxr2 = REGVAL(EPIC_HAXR2);
107
108 if (!acp->ac_initted) {
109 /* don't do these twice since they set up extents */
110 apecs_bus_io_init(&acp->ac_iot, acp);
111 apecs_bus_mem_init(&acp->ac_memt, acp);
112 }
113 acp->ac_mallocsafe = mallocsafe;
114
115 apecs_pci_init(&acp->ac_pc, acp);
116
117 apecs_dma_init(acp);
118
119 acp->ac_initted = 1;
120 }
121
122 void
123 apecsattach(parent, self, aux)
124 struct device *parent, *self;
125 void *aux;
126 {
127 struct apecs_softc *sc = (struct apecs_softc *)self;
128 struct apecs_config *acp;
129 struct pcibus_attach_args pba;
130
131 /* note that we've attached the chipset; can't have 2 APECSes. */
132 apecsfound = 1;
133
134 /*
135 * set up the chipset's info; done once at console init time
136 * (maybe), but doesn't hurt to do twice.
137 */
138 acp = sc->sc_acp = &apecs_configuration;
139 apecs_init(acp, 1);
140
141 /* XXX SGMAP FOO */
142
143 printf(": DECchip %s Core Logic chipset\n",
144 acp->ac_memwidth == 128 ? "21072" : "21071");
145 printf("%s: DC21071-CA pass %d, %d-bit memory bus\n",
146 self->dv_xname, acp->ac_comanche_pass2 ? 2 : 1, acp->ac_memwidth);
147 printf("%s: DC21071-DA pass %d\n", self->dv_xname,
148 acp->ac_epic_pass2 ? 2 : 1);
149 /* XXX print bcache size */
150
151 if (!acp->ac_epic_pass2)
152 printf("WARNING: 21071-DA NOT PASS2... NO BETS...\n");
153
154 switch (hwrpb->rpb_type) {
155 #ifdef DEC_2100_A50
156 case ST_DEC_2100_A50:
157 pci_2100_a50_pickintr(acp);
158 break;
159 #endif
160
161 default:
162 panic("apecsattach: shouldn't be here, really...");
163 }
164
165 pba.pba_busname = "pci";
166 pba.pba_iot = &acp->ac_iot;
167 pba.pba_memt = &acp->ac_memt;
168 pba.pba_dmat = &acp->ac_dmat_direct;
169 pba.pba_pc = &acp->ac_pc;
170 pba.pba_bus = 0;
171 pba.pba_flags = PCI_FLAGS_IO_ENABLED | PCI_FLAGS_MEM_ENABLED;
172 config_found(self, &pba, apecsprint);
173 }
174
175 static int
176 apecsprint(aux, pnp)
177 void *aux;
178 const char *pnp;
179 {
180 register struct pcibus_attach_args *pba = aux;
181
182 /* only PCIs can attach to APECSes; easy. */
183 if (pnp)
184 printf("%s at %s", pba->pba_busname, pnp);
185 printf(" bus %d", pba->pba_bus);
186 return (UNCONF);
187 }
188