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