dec_3min.c revision 1.11
1/* $NetBSD: dec_3min.c,v 1.11 1999/03/02 12:23:58 jonathan Exp $ */ 2 3/* 4 * Copyright (c) 1998 Jonathan Stone. 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 Jonathan Stone for 17 * the NetBSD Project. 18 * 4. The name of the author 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 THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33/* 34 * Copyright (c) 1988 University of Utah. 35 * Copyright (c) 1992, 1993 36 * The Regents of the University of California. All rights reserved. 37 * 38 * This code is derived from software contributed to Berkeley by 39 * the Systems Programming Group of the University of Utah Computer 40 * Science Department, The Mach Operating System project at 41 * Carnegie-Mellon University and Ralph Campbell. 42 * 43 * Redistribution and use in source and binary forms, with or without 44 * modification, are permitted provided that the following conditions 45 * are met: 46 * 1. Redistributions of source code must retain the above copyright 47 * notice, this list of conditions and the following disclaimer. 48 * 2. Redistributions in binary form must reproduce the above copyright 49 * notice, this list of conditions and the following disclaimer in the 50 * documentation and/or other materials provided with the distribution. 51 * 3. All advertising materials mentioning features or use of this software 52 * must display the following acknowledgement: 53 * This product includes software developed by the University of 54 * California, Berkeley and its contributors. 55 * 4. Neither the name of the University nor the names of its contributors 56 * may be used to endorse or promote products derived from this software 57 * without specific prior written permission. 58 * 59 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 60 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 61 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 62 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 63 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 64 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 65 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 66 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 67 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 68 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 69 * SUCH DAMAGE. 70 * 71 * @(#)machdep.c 8.3 (Berkeley) 1/12/94 72 */ 73 74#include <sys/cdefs.h> /* RCS ID & Copyright macro defns */ 75 76__KERNEL_RCSID(0, "$NetBSD: dec_3min.c,v 1.11 1999/03/02 12:23:58 jonathan Exp $"); 77 78 79#include <sys/types.h> 80#include <sys/systm.h> 81 82#include <machine/cpu.h> 83#include <machine/intr.h> 84#include <machine/reg.h> 85#include <machine/psl.h> 86#include <machine/locore.h> /* wbflush() */ 87#include <machine/autoconf.h> /* intr_arg_t */ 88#include <machine/sysconf.h> 89 90#include <mips/mips_param.h> /* hokey spl()s */ 91#include <mips/mips/mips_mcclock.h> /* mcclock CPUspeed estimation */ 92 93/* all these to get ioasic_base */ 94#include <sys/device.h> /* struct cfdata for.. */ 95#include <dev/tc/tcvar.h> /* tc type definitions for.. */ 96#include <dev/tc/ioasicreg.h> /* ioasic interrrupt masks */ 97#include <dev/tc/ioasicvar.h> /* ioasic_base */ 98 99#include <pmax/pmax/clockreg.h> 100#include <pmax/pmax/turbochannel.h> 101#include <pmax/pmax/pmaxtype.h> 102 103#include <pmax/pmax/machdep.h> /* XXXjrs replace with vectors */ 104 105#include <pmax/pmax/kmin.h> /* 3min baseboard addresses */ 106#include <pmax/pmax/dec_kn02_subr.h> /* 3min/maxine memory errors */ 107 108 109/* 110 * forward declarations 111 */ 112void dec_3min_init __P((void)); 113void dec_3min_os_init __P((void)); 114void dec_3min_bus_reset __P((void)); 115void dec_3maxplus_device_register __P((struct device *, void *)); 116 117void dec_3min_enable_intr 118 __P ((u_int slotno, int (*handler) __P((intr_arg_t sc)), 119 intr_arg_t sc, int onoff)); 120int dec_3min_intr __P((u_int mask, u_int pc, 121 u_int statusReg, u_int causeReg)); 122 123void dec_3min_device_register __P((struct device *, void *)); 124void dec_3min_cons_init __P((void)); 125 126 127/* 128 * Local declarations. 129 */ 130void dec_3min_mcclock_cpuspeed __P((volatile struct chiptime *mcclock_addr, 131 int clockmask)); 132u_long kmin_tc3_imask; 133 134 135/* 136 * Fill in platform struct. 137 */ 138void 139dec_3min_init() 140{ 141 142 platform.iobus = "tcbus"; 143 144 platform.os_init = dec_3min_os_init; 145 platform.bus_reset = dec_3min_bus_reset; 146 platform.cons_init = dec_3min_cons_init; 147 platform.device_register = dec_3min_device_register; 148 149 dec_3min_os_init(); 150 151 sprintf(cpu_model, "DECstation 5000/1%d (3MIN)", cpu_mhz); 152} 153 154 155/* 156 * Initalize the memory system and I/O buses. 157 */ 158void 159dec_3min_bus_reset() 160{ 161 162 /* 163 * Reset interrupts, clear any errors from newconf probes 164 */ 165 166 *(volatile u_int *)MIPS_PHYS_TO_KSEG1(KMIN_REG_TIMEOUT) = 0; 167 wbflush(); 168 169 *(volatile u_int *)IOASIC_REG_INTR(ioasic_base) = 0; 170 wbflush(); 171 172} 173 174 175void 176dec_3min_os_init() 177{ 178 ioasic_base = MIPS_PHYS_TO_KSEG1(KMIN_SYS_ASIC); 179 mips_hardware_intr = dec_3min_intr; 180 tc_enable_interrupt = dec_3min_enable_intr; 181 kmin_tc3_imask = (KMIN_INTR_CLOCK | KMIN_INTR_PSWARN | 182 KMIN_INTR_TIMEOUT); 183 184 /* 185 * All the baseboard interrupts come through the I/O ASIC 186 * (at INT_MASK_3), so it has to be turned off for all the spls. 187 * Since we don't know what kinds of devices are in the 188 * turbochannel option slots, just block them all. 189 */ 190 Mach_splbio = cpu_spl3; 191 Mach_splnet = cpu_spl3; 192 Mach_spltty = cpu_spl3; 193 Mach_splimp = cpu_spl3; 194 Mach_splclock = cpu_spl3; 195 Mach_splstatclock = cpu_spl3; 196 mcclock_addr = (volatile struct chiptime *) 197 MIPS_PHYS_TO_KSEG1(KMIN_SYS_CLOCK); 198 dec_3min_mcclock_cpuspeed(mcclock_addr, MIPS_INT_MASK_3); 199 200 /* 201 * Initialize interrupts. 202 */ 203 *(u_int *)IOASIC_REG_IMSK(ioasic_base) = KMIN_IM0; 204 *(u_int *)IOASIC_REG_INTR(ioasic_base) = 0; 205 206 /* clear any memory errors from probes */ 207 208 *(volatile u_int *)MIPS_PHYS_TO_KSEG1(KMIN_REG_TIMEOUT) = 0; 209 wbflush(); 210 211 /* 212 * The kmin memory hardware seems to wrap memory addresses 213 * with 4Mbyte SIMMs, which causes the physmem computation 214 * to lose. Find out how big the SIMMS are and set 215 * max_ physmem accordingly. 216 */ 217 physmem_boardmax = KMIN_PHYS_MEMORY_END + 1; 218 if ((*(int*)(MIPS_PHYS_TO_KSEG1(KMIN_REG_MSR)) & 219 KMIN_MSR_SIZE_16Mb) == 0) 220 physmem_boardmax = physmem_boardmax >> 2; 221 physmem_boardmax = MIPS_PHYS_TO_KSEG1(physmem_boardmax); 222 223 * (volatile u_int *)MIPS_PHYS_TO_KSEG1(KMIN_REG_IMSK) = 224 kmin_tc3_imask | 225 (KMIN_IM0 & ~(KN03_INTR_TC_0|KN03_INTR_TC_1|KN03_INTR_TC_2)); 226} 227 228 229void 230dec_3min_cons_init() 231{ 232 /* notyet */ 233} 234 235 236void 237dec_3min_device_register(dev, aux) 238 struct device *dev; 239 void *aux; 240{ 241 panic("dec_3min_device_register unimplemented"); 242} 243 244 245void 246dec_3min_enable_intr(slotno, handler, sc, on) 247 register unsigned int slotno; 248 int (*handler) __P((void* softc)); 249 void *sc; 250 int on; 251{ 252 register unsigned mask; 253 254 switch (slotno) { 255 /* slots 0-2 don't interrupt through the IOASIC. */ 256 case 0: 257 mask = MIPS_INT_MASK_0; break; 258 case 1: 259 mask = MIPS_INT_MASK_1; break; 260 case 2: 261 mask = MIPS_INT_MASK_2; break; 262 263 case KMIN_SCSI_SLOT: 264 mask = (IOASIC_INTR_SCSI | IOASIC_INTR_SCSI_PTR_LOAD | 265 IOASIC_INTR_SCSI_OVRUN | IOASIC_INTR_SCSI_READ_E); 266 break; 267 268 case KMIN_LANCE_SLOT: 269 mask = KMIN_INTR_LANCE; 270 break; 271 case KMIN_SCC0_SLOT: 272 mask = KMIN_INTR_SCC_0; 273 break; 274 case KMIN_SCC1_SLOT: 275 mask = KMIN_INTR_SCC_1; 276 break; 277 case KMIN_ASIC_SLOT: 278 mask = KMIN_INTR_ASIC; 279 break; 280 default: 281 return; 282 } 283 284#if defined(DEBUG) || defined(DIAGNOSTIC) 285 printf("3MIN: imask %lx, %sabling slot %d, sc %p handler %p\n", 286 kmin_tc3_imask, (on? "en" : "dis"), slotno, sc, handler); 287#endif 288 289 /* 290 * Enable the interrupt handler, and if it's an IOASIC 291 * slot, set the IOASIC interrupt mask. 292 * Otherwise, set the appropriate spl level in the R3000 293 * register. 294 * Be careful to set handlers before enabling, and disable 295 * interrupts before clearing handlers. 296 */ 297 298 if (on) { 299 /* Set the interrupt handler and argument ... */ 300 tc_slot_info[slotno].intr = handler; 301 tc_slot_info[slotno].sc = sc; 302 303 /* ... and set the relevant mask */ 304 if (slotno <= 2) { 305 /* it's an option slot */ 306 int s = splhigh(); 307 s |= mask; 308 splx(s); 309 } else { 310 /* it's a baseboard device going via the ASIC */ 311 kmin_tc3_imask |= mask; 312 } 313 } else { 314 /* Clear the relevant mask... */ 315 if (slotno <= 2) { 316 /* it's an option slot */ 317 int s = splhigh(); 318 printf("kmin_intr: cannot disable option slot %d\n", 319 slotno); 320 s &= ~mask; 321 splx(s); 322 } else { 323 /* it's a baseboard device going via the ASIC */ 324 kmin_tc3_imask &= ~mask; 325 } 326 /* ... and clear the handler */ 327 tc_slot_info[slotno].intr = 0; 328 tc_slot_info[slotno].sc = 0; 329 } 330} 331 332 333 334/* 335 * 3min hardware interrupts. (DECstation 5000/1xx) 336 */ 337int 338dec_3min_intr(mask, pc, statusReg, causeReg) 339 unsigned mask; 340 unsigned pc; 341 unsigned statusReg; 342 unsigned causeReg; 343{ 344 register u_int intr; 345 register volatile struct chiptime *c = 346 (volatile struct chiptime *) MIPS_PHYS_TO_KSEG1(KMIN_SYS_CLOCK); 347 volatile u_int * const imaskp = 348 (volatile u_int *)MIPS_PHYS_TO_KSEG1(KMIN_REG_IMSK); 349 volatile u_int * const intrp = 350 (volatile u_int *)MIPS_PHYS_TO_KSEG1(KMIN_REG_INTR); 351 unsigned int old_mask; 352 struct clockframe cf; 353 int temp; 354 static int user_warned = 0; 355 356 static int intr_depth = 0; 357 intr_depth++; 358 359 old_mask = *imaskp; 360 361 if (mask & MIPS_INT_MASK_4) 362 prom_haltbutton(); 363 364 if (mask & MIPS_INT_MASK_3) { 365 /* NB: status & MIPS_INT_MASK3 must also be set */ 366 /* masked interrupts are still observable */ 367 intr = *intrp & old_mask & kmin_tc3_imask; 368 369 if (intr & IOASIC_INTR_SCSI_PTR_LOAD) { 370 *intrp &= ~IOASIC_INTR_SCSI_PTR_LOAD; 371#ifdef notdef 372 asc_dma_intr(); 373#endif 374 } 375 376 if (intr & (IOASIC_INTR_SCSI_OVRUN | IOASIC_INTR_SCSI_READ_E)) 377 *intrp &= ~(IOASIC_INTR_SCSI_OVRUN | IOASIC_INTR_SCSI_READ_E); 378 379 if (intr & IOASIC_INTR_LANCE_READ_E) 380 *intrp &= ~IOASIC_INTR_LANCE_READ_E; 381 382 if (intr & KMIN_INTR_TIMEOUT) 383 kn02ba_errintr(); 384 385 if (intr & KMIN_INTR_CLOCK) { 386 extern u_int32_t mips3_cycle_count __P((void)); 387 388 temp = c->regc; /* XXX clear interrupt bits */ 389 cf.pc = pc; 390 cf.sr = statusReg; 391#ifdef MIPS3 392 if (CPUISMIPS3) { 393 latched_cycle_cnt = mips3_cycle_count(); 394 } 395#endif 396 hardclock(&cf); 397 intrcnt[HARDCLOCK]++; 398 } 399 400 /* If clock interrups were enabled, re-enable them ASAP. */ 401 if (old_mask & KMIN_INTR_CLOCK) { 402 /* ioctl interrupt mask to splclock and higher */ 403 *imaskp = old_mask & 404 ~(KMIN_INTR_SCC_0|KMIN_INTR_SCC_1 | 405 IOASIC_INTR_LANCE|IOASIC_INTR_SCSI); 406 wbflush(); 407 splx(MIPS_SR_INT_ENA_CUR | (statusReg & MIPS_INT_MASK_3)); 408 } 409 410 if (intr_depth > 1) 411 goto done; 412 413 if ((intr & KMIN_INTR_SCC_0) && 414 tc_slot_info[KMIN_SCC0_SLOT].intr) { 415 (*(tc_slot_info[KMIN_SCC0_SLOT].intr)) 416 (tc_slot_info[KMIN_SCC0_SLOT].sc); 417 intrcnt[SERIAL0_INTR]++; 418 } 419 420 if ((intr & KMIN_INTR_SCC_1) && 421 tc_slot_info[KMIN_SCC1_SLOT].intr) { 422 (*(tc_slot_info[KMIN_SCC1_SLOT].intr)) 423 (tc_slot_info[KMIN_SCC1_SLOT].sc); 424 intrcnt[SERIAL1_INTR]++; 425 } 426 427#ifdef notyet /* untested */ 428 /* If tty interrupts were enabled, re-enable them ASAP. */ 429 if ((old_mask & (KMIN_INTR_SCC_1|KMIN_INTR_SCC_0)) == 430 (KMIN_INTR_SCC_1|KMIN_INTR_SCC_0)) { 431 *imaskp = old_mask & 432 ~(KMIN_INTR_SCC_0|KMIN_INTR_SCC_1 | 433 IOASIC_INTR_LANCE|IOASIC_INTR_SCSI); 434 wbflush(); 435 } 436 437 /* XXX until we know about SPLs of TC options. */ 438 if (intr_depth > 1) 439 goto done; 440#endif 441 if ((intr & IOASIC_INTR_LANCE) && 442 tc_slot_info[KMIN_LANCE_SLOT].intr) { 443 (*(tc_slot_info[KMIN_LANCE_SLOT].intr)) 444 (tc_slot_info[KMIN_LANCE_SLOT].sc); 445 intrcnt[LANCE_INTR]++; 446 } 447 448 if ((intr & IOASIC_INTR_SCSI) && 449 tc_slot_info[KMIN_SCSI_SLOT].intr) { 450 (*(tc_slot_info[KMIN_SCSI_SLOT].intr)) 451 (tc_slot_info[KMIN_SCSI_SLOT].sc); 452 intrcnt[SCSI_INTR]++; 453 } 454 455 if (user_warned && ((intr & KMIN_INTR_PSWARN) == 0)) { 456 printf("%s\n", "Power supply ok now."); 457 user_warned = 0; 458 } 459 if ((intr & KMIN_INTR_PSWARN) && (user_warned < 3)) { 460 user_warned++; 461 printf("%s\n", "Power supply overheating"); 462 } 463 } 464 if ((mask & MIPS_INT_MASK_0) && tc_slot_info[0].intr) { 465 (*tc_slot_info[0].intr)(tc_slot_info[0].sc); 466 intrcnt[SLOT0_INTR]++; 467 } 468 469 if ((mask & MIPS_INT_MASK_1) && tc_slot_info[1].intr) { 470 (*tc_slot_info[1].intr)(tc_slot_info[1].sc); 471 intrcnt[SLOT1_INTR]++; 472 } 473 if ((mask & MIPS_INT_MASK_2) && tc_slot_info[2].intr) { 474 (*tc_slot_info[2].intr)(tc_slot_info[2].sc); 475 intrcnt[SLOT2_INTR]++; 476 } 477 478done: 479 /* restore entry state */ 480 splhigh(); 481 intr_depth--; 482 *imaskp = old_mask; 483 484 return ((statusReg & ~causeReg & MIPS_HARD_INT_MASK) | 485 MIPS_SR_INT_ENA_CUR); 486} 487 488 489 490/* 491 ************************************************************************ 492 * Extra functions 493 ************************************************************************ 494 */ 495 496 497 498 499/* 500 * Count instructions between 4ms mcclock interrupt requests, 501 * using the ioasic clock-interrupt-pending bit to determine 502 * when clock ticks occur. 503 * Set up iosiac to allow only clock interrupts, then 504 * call 505 */ 506void 507dec_3min_mcclock_cpuspeed(mcclock_addr, clockmask) 508 volatile struct chiptime *mcclock_addr; 509 int clockmask; 510{ 511 register volatile u_int * ioasic_intrmaskp = 512 (volatile u_int *)MIPS_PHYS_TO_KSEG1(KMIN_REG_IMSK); 513 514 register int saved_imask = *ioasic_intrmaskp; 515 516 /* Allow only clock interrupts through ioasic. */ 517 *ioasic_intrmaskp = KMIN_INTR_CLOCK; 518 wbflush(); 519 520 mc_cpuspeed(mcclock_addr, clockmask); 521 522 *ioasic_intrmaskp = saved_imask; 523 wbflush(); 524} 525