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