tsc.c revision 1.3 1 /* $NetBSD: tsc.c,v 1.3 2000/06/25 19:17:40 thorpej Exp $ */
2
3 /*-
4 * Copyright (c) 1999 by Ross Harvey. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by Ross Harvey.
17 * 4. The name of Ross Harvey may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY ROSS HARVEY ``AS IS'' AND ANY EXPRESS
21 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURP0SE
23 * ARE DISCLAIMED. IN NO EVENT SHALL ROSS HARVEY BE LIABLE FOR ANY
24 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 *
32 */
33
34 #include "opt_dec_6600.h"
35
36 #include <sys/cdefs.h>
37
38 __KERNEL_RCSID(0, "$NetBSD: tsc.c,v 1.3 2000/06/25 19:17:40 thorpej Exp $");
39
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/device.h>
43 #include <sys/malloc.h>
44
45 #include <machine/autoconf.h>
46 #include <machine/rpb.h>
47 #include <machine/sysarch.h>
48
49 #include <dev/isa/isareg.h>
50 #include <dev/isa/isavar.h>
51 #include <dev/pci/pcireg.h>
52 #include <dev/pci/pcivar.h>
53 #include <alpha/pci/tsreg.h>
54 #include <alpha/pci/tsvar.h>
55
56 #ifdef DEC_6600
57 #include <alpha/pci/pci_6600.h>
58 #endif
59
60 #define tsc() { Generate ctags(1) key. }
61
62 int tscmatch __P((struct device *, struct cfdata *, void *));
63 void tscattach __P((struct device *, struct device *, void *));
64
65 struct cfattach tsc_ca = {
66 sizeof(struct tsc_softc), tscmatch, tscattach,
67 };
68
69 extern struct cfdriver tsc_cd;
70
71 struct tsp_config tsp_configuration[2];
72
73 static int tscprint __P((void *, const char *pnp));
74
75 int tspmatch __P((struct device *, struct cfdata *, void *));
76 void tspattach __P((struct device *, struct device *, void *));
77
78 struct cfattach tsp_ca = {
79 sizeof(struct tsp_softc), tspmatch, tspattach,
80 };
81
82 extern struct cfdriver tsp_cd;
83
84 static int tspprint __P((void *, const char *pnp));
85
86 static int tsp_bus_get_window __P((int, int,
87 struct alpha_bus_space_translation *));
88
89 /* There can be only one */
90 static int tscfound;
91
92 /* Which hose is the display console connected to? */
93 int tsp_console_hose;
94
95 int
96 tscmatch(parent, match, aux)
97 struct device *parent;
98 struct cfdata *match;
99 void *aux;
100 {
101 struct mainbus_attach_args *ma = aux;
102
103 return cputype == ST_DEC_6600
104 && strcmp(ma->ma_name, tsc_cd.cd_name) == 0
105 && !tscfound;
106 }
107
108 void tscattach(parent, self, aux)
109 struct device *parent, *self;
110 void *aux;
111 {
112 int i;
113 int nbus;
114 u_int64_t csc, aar;
115 struct tsp_attach_args tsp;
116 struct mainbus_attach_args *ma = aux;
117
118 tscfound = 1;
119
120 csc = LDQP(TS_C_CSC);
121
122 nbus = 1 + (CSC_BC(csc) >= 2);
123 printf(": 21272 Core Logic Chipset, Cchip rev %d\n"
124 "%s%d: %c Dchips, %d memory bus%s of %d bytes\n",
125 (int)MISC_REV(LDQP(TS_C_MISC)),
126 ma->ma_name, ma->ma_slot, "2448"[CSC_BC(csc)],
127 nbus, nbus > 1 ? "es" : "", 16 + 16 * ((csc & CSC_AW) != 0));
128 printf("%s%d: arrays present: ", ma->ma_name, ma->ma_slot);
129 for(i = 0; i < 4; ++i) {
130 aar = LDQP(TS_C_AAR0 + i * TS_STEP);
131 printf("%s%dMB%s", i ? ", " : "", (8 << AAR_ASIZ(aar)) & ~0xf,
132 aar & AAR_SPLIT ? " (split)" : "");
133 }
134 printf(", Dchip 0 rev %d\n", (int)LDQP(TS_D_DREV) & 0xf);
135
136 bzero(&tsp, sizeof tsp);
137 tsp.tsp_name = "tsp";
138 config_found(self, &tsp, NULL);
139
140 if(LDQP(TS_C_CSC) & CSC_P1P) {
141 ++tsp.tsp_slot;
142 config_found(self, &tsp, tscprint);
143 }
144 }
145
146 static int
147 tscprint(aux, p)
148 void *aux;
149 const char *p;
150 {
151 register struct tsp_attach_args *tsp = aux;
152
153 if(p)
154 printf("%s%d at %s", tsp->tsp_name, tsp->tsp_slot, p);
155 return UNCONF;
156 }
157
158 #define tsp() { Generate ctags(1) key. }
159
160 int
161 tspmatch(parent, match, aux)
162 struct device *parent;
163 struct cfdata *match;
164 void *aux;
165 {
166 struct tsp_attach_args *t = aux;
167
168 return cputype == ST_DEC_6600
169 && strcmp(t->tsp_name, tsp_cd.cd_name) == 0;
170 }
171
172 void
173 tspattach(parent, self, aux)
174 struct device *parent, *self;
175 void *aux;
176 {
177 struct pcibus_attach_args pba;
178 struct tsp_attach_args *t = aux;
179 struct tsp_config *pcp;
180
181 printf("\n");
182 pcp = tsp_init(1, t->tsp_slot);
183 tsp_dma_init(pcp);
184 pci_6600_pickintr(pcp);
185 pba.pba_busname = "pci";
186 pba.pba_iot = &pcp->pc_iot;
187 pba.pba_memt = &pcp->pc_memt;
188 pba.pba_dmat =
189 alphabus_dma_get_tag(&pcp->pc_dmat_direct, ALPHA_BUS_PCI);
190 pba.pba_pc = &pcp->pc_pc;
191 pba.pba_bus = 0;
192 pba.pba_flags = PCI_FLAGS_IO_ENABLED | PCI_FLAGS_MEM_ENABLED |
193 PCI_FLAGS_MRL_OKAY | PCI_FLAGS_MRM_OKAY | PCI_FLAGS_MWI_OKAY;
194 config_found(self, &pba, tspprint);
195 }
196
197 struct tsp_config *
198 tsp_init(mallocsafe, n)
199 int mallocsafe;
200 int n; /* Pchip number */
201 {
202 struct tsp_config *pcp;
203
204 KASSERT((n | 1) == 1);
205 pcp = &tsp_configuration[n];
206 pcp->pc_pslot = n;
207 pcp->pc_iobase = TS_Pn(n, 0);
208 pcp->pc_csr = S_PAGE(TS_Pn(n, P_CSRBASE));
209 if (!pcp->pc_initted) {
210 tsp_bus_io_init(&pcp->pc_iot, pcp);
211 tsp_bus_mem_init(&pcp->pc_memt, pcp);
212
213 alpha_bus_window_count[ALPHA_BUS_TYPE_PCI_IO] = 1;
214 alpha_bus_window_count[ALPHA_BUS_TYPE_PCI_MEM] = 1;
215
216 alpha_bus_get_window = tsp_bus_get_window;
217 }
218 pcp->pc_mallocsafe = mallocsafe;
219 tsp_pci_init(&pcp->pc_pc, pcp);
220 pcp->pc_initted = 1;
221 return pcp;
222 }
223
224 static int
225 tspprint(aux, p)
226 void *aux;
227 const char *p;
228 {
229 register struct pcibus_attach_args *pci = aux;
230
231 if(p)
232 printf("%s at %s", pci->pba_busname, p);
233 printf(" bus %d", pci->pba_bus);
234 return UNCONF;
235 }
236
237 static int
238 tsp_bus_get_window(type, window, abst)
239 int type, window;
240 struct alpha_bus_space_translation *abst;
241 {
242 struct tsp_config *tsp = &tsp_configuration[tsp_console_hose];
243 bus_space_tag_t st;
244
245 switch (type) {
246 case ALPHA_BUS_TYPE_PCI_IO:
247 st = &tsp->pc_iot;
248 break;
249
250 case ALPHA_BUS_TYPE_PCI_MEM:
251 st = &tsp->pc_memt;
252 break;
253
254 default:
255 panic("tsp_bus_get_window");
256 }
257
258 return (alpha_bus_space_get_window(st, window, abst));
259 }
260