ka88.c revision 1.2
11.2Sthorpej/* $NetBSD: ka88.c,v 1.2 2001/04/12 06:12:17 thorpej Exp $ */ 21.1Sragge 31.1Sragge/* 41.1Sragge * Copyright (c) 2000 Ludd, University of Lule}, Sweden. All rights reserved. 51.1Sragge * 61.1Sragge * Redistribution and use in source and binary forms, with or without 71.1Sragge * modification, are permitted provided that the following conditions 81.1Sragge * are met: 91.1Sragge * 1. Redistributions of source code must retain the above copyright 101.1Sragge * notice, this list of conditions and the following disclaimer. 111.1Sragge * 2. Redistributions in binary form must reproduce the above copyright 121.1Sragge * notice, this list of conditions and the following disclaimer in the 131.1Sragge * documentation and/or other materials provided with the distribution. 141.1Sragge * 3. All advertising materials mentioning features or use of this software 151.1Sragge * must display the following acknowledgement: 161.1Sragge * This product includes software developed at Ludd, University of 171.1Sragge * Lule}, Sweden and its contributors. 181.1Sragge * 4. The name of the author may not be used to endorse or promote products 191.1Sragge * derived from this software without specific prior written permission 201.1Sragge * 211.1Sragge * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 221.1Sragge * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 231.1Sragge * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 241.1Sragge * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 251.1Sragge * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 261.1Sragge * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 271.1Sragge * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 281.1Sragge * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 291.1Sragge * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 301.1Sragge * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 311.1Sragge */ 321.1Sragge 331.1Sragge/* 341.1Sragge * KA88 specific CPU code. 351.1Sragge */ 361.1Sragge/* 371.1Sragge * TODO: 381.1Sragge * - Machine check code 391.1Sragge */ 401.1Sragge 411.1Sragge#include "opt_multiprocessor.h" 421.1Sragge 431.1Sragge#include <sys/param.h> 441.1Sragge#include <sys/time.h> 451.1Sragge#include <sys/kernel.h> 461.1Sragge#include <sys/device.h> 471.1Sragge#include <sys/systm.h> 481.1Sragge#include <sys/conf.h> 491.1Sragge 501.1Sragge#include <machine/cpu.h> 511.1Sragge#include <machine/mtpr.h> 521.1Sragge#include <machine/nexus.h> 531.1Sragge#include <machine/clock.h> 541.1Sragge#include <machine/scb.h> 551.1Sragge#include <machine/bus.h> 561.1Sragge#include <machine/sid.h> 571.1Sragge#include <machine/rpb.h> 581.1Sragge#include <machine/ka88.h> 591.1Sragge 601.1Sragge#include <vax/vax/gencons.h> 611.1Sragge 621.1Sragge#include "ioconf.h" 631.1Sragge#include "locators.h" 641.1Sragge 651.1Sraggestatic void ka88_memerr(void); 661.1Sraggestatic void ka88_conf(void); 671.1Sraggestatic int ka88_mchk(caddr_t); 681.1Sraggestatic void ka88_steal_pages(void); 691.1Sraggestatic int ka88_clkread(time_t); 701.1Sraggestatic void ka88_clkwrite(void); 711.1Sraggestatic void ka88_badaddr(void); 721.1Sragge#if defined(MULTIPROCESSOR) 731.1Sraggestatic void ka88_startslave(struct device *, struct cpu_info *); 741.1Sraggestatic void ka88_txrx(int, char *, int); 751.1Sraggestatic void ka88_sendstr(int, char *); 761.1Sraggestatic void ka88_sergeant(int); 771.1Sraggestatic int rxchar(void); 781.1Sraggestatic void ka88_putc(int); 791.1Sraggestatic void ka88_cnintr(void); 801.1Sraggecons_decl(gen); 811.1Sragge#endif 821.1Sragge 831.1Sraggestatic long *ka88_mcl; 841.1Sraggestatic int mastercpu; 851.1Sragge 861.1Sraggestruct cpu_dep ka88_calls = { 871.1Sragge ka88_steal_pages, 881.1Sragge ka88_mchk, 891.1Sragge ka88_memerr, 901.1Sragge ka88_conf, 911.1Sragge ka88_clkread, 921.1Sragge ka88_clkwrite, 931.1Sragge 6, /* ~VUPS */ 941.1Sragge 64, /* SCB pages */ 951.1Sragge 0, 961.1Sragge 0, 971.1Sragge 0, 981.1Sragge 0, 991.1Sragge 0, 1001.1Sragge#if defined(MULTIPROCESSOR) 1011.1Sragge ka88_startslave, 1021.1Sragge#endif 1031.1Sragge ka88_badaddr, 1041.1Sragge}; 1051.1Sragge 1061.1Sraggestruct ka88_softc { 1071.1Sragge struct device sc_dev; 1081.1Sragge int sc_slot; 1091.1Sragge}; 1101.1Sragge 1111.1Sraggestatic void 1121.1Sraggeka88_conf(void) 1131.1Sragge{ 1141.1Sragge ka88_mcl = (void *)vax_map_physmem(0x3e000000, 1); 1151.1Sragge printf("Serial number %d, rev %d\n", 1161.1Sragge mfpr(PR_SID) & 65535, (mfpr(PR_SID) >> 16) & 127); 1171.1Sragge} 1181.1Sragge 1191.1Sraggestatic int 1201.1Sraggeka88_match(struct device *parent, struct cfdata *cf, void *aux) 1211.1Sragge{ 1221.1Sragge struct nmi_attach_args *na = aux; 1231.1Sragge 1241.1Sragge if (cf->cf_loc[NMICF_SLOT] != NMICF_SLOT_DEFAULT && 1251.1Sragge cf->cf_loc[NMICF_SLOT] != na->slot) 1261.1Sragge return 0; 1271.1Sragge if (na->slot >= 20) 1281.1Sragge return 1; 1291.1Sragge return 0; 1301.1Sragge} 1311.1Sragge 1321.1Sraggestatic void 1331.1Sraggeka88_attach(struct device *parent, struct device *self, void *aux) 1341.1Sragge{ 1351.1Sragge struct ka88_softc *sc = (void *)self; 1361.1Sragge struct nmi_attach_args *na = aux; 1371.1Sragge char *ms, *lr; 1381.1Sragge 1391.1Sragge if (((ka88_confdata & KA88_LEFTPRIM) && (na->slot == 20)) || 1401.1Sragge ((ka88_confdata & KA88_LEFTPRIM) == 0 && (na->slot != 20))) 1411.1Sragge lr = "left"; 1421.1Sragge else 1431.1Sragge lr = "right"; 1441.1Sragge ms = na->slot == 20 ? "master" : "slave"; 1451.1Sragge 1461.1Sragge printf(": ka88 (%s) (%s)\n", lr, ms); 1471.1Sragge sc->sc_slot = na->slot; 1481.1Sragge if (na->slot != mastercpu) { 1491.1Sragge#if defined(MULTIPROCESSOR) 1501.1Sragge sc->sc_ci = cpu_slavesetup(self); 1511.1Sragge v_putc = ka88_putc; /* Need special console handling */ 1521.1Sragge#endif 1531.1Sragge return; 1541.1Sragge } 1551.1Sragge curcpu()->ci_dev = self; 1561.1Sragge} 1571.1Sragge 1581.1Sraggestruct cfattach cpu_nmi_ca = { 1591.1Sragge sizeof(struct ka88_softc), ka88_match, ka88_attach 1601.1Sragge}; 1611.1Sragge 1621.1Sraggestruct mem_nmi_softc { 1631.1Sragge struct device sc_dev; 1641.1Sragge bus_space_tag_t sc_iot; 1651.1Sragge bus_space_handle_t sc_ioh; 1661.1Sragge}; 1671.1Sragge 1681.1Sraggestatic int 1691.1Sraggems88_match(struct device *parent, struct cfdata *cf, void *aux) 1701.1Sragge{ 1711.1Sragge struct nmi_attach_args *na = aux; 1721.1Sragge 1731.1Sragge if (cf->cf_loc[NMICF_SLOT] != NMICF_SLOT_DEFAULT && 1741.1Sragge cf->cf_loc[NMICF_SLOT] != na->slot) 1751.1Sragge return 0; 1761.1Sragge if (na->slot != 10) 1771.1Sragge return 0; 1781.1Sragge return 1; 1791.1Sragge} 1801.1Sragge 1811.1Sraggestatic void 1821.1Sraggems88_attach(struct device *parent, struct device *self, void *aux) 1831.1Sragge{ 1841.1Sragge printf("\n"); 1851.1Sragge} 1861.1Sragge 1871.1Sraggestruct cfattach mem_nmi_ca = { 1881.1Sragge sizeof(struct mem_nmi_softc), ms88_match, ms88_attach 1891.1Sragge}; 1901.1Sragge 1911.1Sraggestatic void 1921.1Sraggeka88_badaddr(void) 1931.1Sragge{ 1941.1Sragge volatile int hej; 1951.1Sragge /* 1961.1Sragge * This is some magic to clear the NMI faults, described 1971.1Sragge * in section 7.9 in the VAX 8800 System Maintenance Guide. 1981.1Sragge */ 1991.1Sragge hej = ka88_mcl[5]; 2001.1Sragge hej = ka88_mcl[0]; 2011.1Sragge ka88_mcl[0] = 0x04000000; 2021.1Sragge mtpr(1, 0x88); 2031.1Sragge} 2041.1Sragge 2051.1Sraggestatic void 2061.1Sraggeka88_memerr() 2071.1Sragge{ 2081.1Sragge printf("ka88_memerr\n"); 2091.1Sragge} 2101.1Sragge 2111.1Sraggestruct mc88frame { 2121.1Sragge int mc64_summary; /* summary parameter */ 2131.1Sragge int mc64_va; /* va register */ 2141.1Sragge int mc64_vb; /* memory address */ 2151.1Sragge int mc64_sisr; /* status word */ 2161.1Sragge int mc64_state; /* error pc */ 2171.1Sragge int mc64_sc; /* micro pc */ 2181.1Sragge int mc64_pc; /* current pc */ 2191.1Sragge int mc64_psl; /* current psl */ 2201.1Sragge}; 2211.1Sragge 2221.1Sraggestatic int 2231.1Sraggeka88_mchk(caddr_t cmcf) 2241.1Sragge{ 2251.1Sragge return (MCHK_PANIC); 2261.1Sragge} 2271.1Sragge 2281.1Sragge#if defined(MULTIPROCESSOR) 2291.1Sragge#define RXBUF 80 2301.1Sraggestatic char rxbuf[RXBUF]; 2311.1Sraggestatic int got = 0, taken = 0; 2321.1Sraggestatic int expect = 0; 2331.1Sragge#endif 2341.1Sragge#if 0 2351.1Sragge/* 2361.1Sragge * Receive a character from logical console. 2371.1Sragge */ 2381.1Sraggestatic void 2391.1Sraggerxcdintr(void *arg) 2401.1Sragge{ 2411.1Sragge int c = mfpr(PR_RXCD); 2421.1Sragge 2431.1Sragge if (c == 0) 2441.1Sragge return; 2451.1Sragge 2461.1Sragge#if defined(MULTIPROCESSOR) 2471.1Sragge if ((c & 0xff) == 0) { 2481.1Sragge if (curcpu()->ci_flags & CI_MASTERCPU) 2491.1Sragge ka88_cnintr(); 2501.1Sragge return; 2511.1Sragge } 2521.1Sragge 2531.1Sragge if (expect == ((c >> 8) & 0xf)) 2541.1Sragge rxbuf[got++] = c & 0xff; 2551.1Sragge 2561.1Sragge if (got == RXBUF) 2571.1Sragge got = 0; 2581.1Sragge#endif 2591.1Sragge} 2601.1Sragge#endif 2611.1Sragge 2621.1Sraggestatic void 2631.1Sraggetocons(int val) 2641.1Sragge{ 2651.2Sthorpej int s = splhigh(); 2661.1Sragge 2671.1Sragge while ((mfpr(PR_TXCS) & GC_RDY) == 0) /* Wait until xmit ready */ 2681.1Sragge ; 2691.1Sragge mtpr(val, PR_TXDB); /* xmit character */ 2701.1Sragge splx(s); 2711.1Sragge} 2721.1Sragge 2731.1Sraggestatic int 2741.1Sraggefromcons(int func) 2751.1Sragge{ 2761.2Sthorpej int ret, s = splhigh(); 2771.1Sragge 2781.1Sragge while (1) { 2791.1Sragge while ((mfpr(PR_RXCS) & GC_DON) == 0) 2801.1Sragge ; 2811.1Sragge ret = mfpr(PR_RXDB); 2821.1Sragge if ((ret & 0xf00) == func) 2831.1Sragge break; 2841.1Sragge } 2851.1Sragge splx(s); 2861.1Sragge return ret; 2871.1Sragge} 2881.1Sragge 2891.1Sraggestatic int 2901.1Sraggeka88_clkread(time_t base) 2911.1Sragge{ 2921.1Sragge union {u_int ret;u_char r[4];} u; 2931.2Sthorpej int i, s = splhigh(); 2941.1Sragge 2951.1Sragge tocons(KA88_COMM|KA88_TOYREAD); 2961.1Sragge for (i = 0; i < 4; i++) { 2971.1Sragge u.r[i] = fromcons(KA88_TOY) & 255; 2981.1Sragge } 2991.1Sragge splx(s); 3001.1Sragge return u.ret; 3011.1Sragge} 3021.1Sragge 3031.1Sraggestatic void 3041.1Sraggeka88_clkwrite(void) 3051.1Sragge{ 3061.1Sragge union {u_int ret;u_char r[4];} u; 3071.2Sthorpej int i, s = splhigh(); 3081.1Sragge 3091.1Sragge u.ret = time.tv_sec - yeartonum(numtoyear(time.tv_sec)); 3101.1Sragge tocons(KA88_COMM|KA88_TOYWRITE); 3111.1Sragge for (i = 0; i < 4; i++) 3121.1Sragge tocons(KA88_TOY|u.r[i]); 3131.1Sragge splx(s); 3141.1Sragge} 3151.1Sragge 3161.1Sraggevoid 3171.1Sraggeka88_steal_pages(void) 3181.1Sragge{ 3191.1Sragge mtpr(1, PR_COR); /* Cache on */ 3201.1Sragge strcpy(cpu_model, "VAX 8800"); 3211.1Sragge tocons(KA88_COMM|KA88_GETCONF); 3221.1Sragge ka88_confdata = fromcons(KA88_CONFDATA); 3231.1Sragge ka88_confdata = mfpr(PR_RXDB); 3241.1Sragge mastercpu = 20; 3251.1Sragge if (vax_cputype == VAX_TYP_8NN) { 3261.1Sragge if (ka88_confdata & KA88_SMALL) { 3271.1Sragge cpu_model[5] = '5'; 3281.1Sragge if (ka88_confdata & KA88_SLOW) { 3291.1Sragge vax_boardtype = VAX_BTYP_8500; 3301.1Sragge cpu_model[6] = '3'; 3311.1Sragge } else { 3321.1Sragge vax_boardtype = VAX_BTYP_8550; 3331.1Sragge cpu_model[6] = '5'; 3341.1Sragge } 3351.1Sragge } else if (ka88_confdata & KA88_SINGLE) { 3361.1Sragge vax_boardtype = VAX_BTYP_8700; 3371.1Sragge cpu_model[5] = '7'; 3381.1Sragge } 3391.1Sragge } 3401.1Sragge} 3411.1Sragge 3421.1Sragge 3431.1Sragge#if defined(MULTIPROCESSOR) && 0 3441.1Sraggeint 3451.1Sraggerxchar() 3461.1Sragge{ 3471.1Sragge int ret; 3481.1Sragge 3491.1Sragge if (got == taken) 3501.1Sragge return 0; 3511.1Sragge 3521.1Sragge ret = rxbuf[taken++]; 3531.1Sragge if (taken == RXBUF) 3541.1Sragge taken = 0; 3551.1Sragge return ret; 3561.1Sragge} 3571.1Sragge 3581.1Sraggestatic void 3591.1Sraggeka88_startslave(struct device *dev, struct cpu_info *ci) 3601.1Sragge{ 3611.1Sragge struct ka88_softc *sc = (void *)dev; 3621.1Sragge int id = sc->sc_binid; 3631.1Sragge int i; 3641.1Sragge 3651.1Sragge expect = sc->sc_binid; 3661.1Sragge /* First empty queue */ 3671.1Sragge for (i = 0; i < 10000; i++) 3681.1Sragge if (rxchar()) 3691.1Sragge i = 0; 3701.1Sragge ka88_txrx(id, "\020", 0); /* Send ^P to get attention */ 3711.1Sragge ka88_txrx(id, "I\r", 0); /* Init other end */ 3721.1Sragge ka88_txrx(id, "D/I 4 %x\r", ci->ci_istack); /* Interrupt stack */ 3731.1Sragge ka88_txrx(id, "D/I C %x\r", mfpr(PR_SBR)); /* SBR */ 3741.1Sragge ka88_txrx(id, "D/I D %x\r", mfpr(PR_SLR)); /* SLR */ 3751.1Sragge ka88_txrx(id, "D/I 10 %x\r", (int)ci->ci_pcb); /* PCB for idle proc */ 3761.1Sragge ka88_txrx(id, "D/I 11 %x\r", mfpr(PR_SCBB)); /* SCB */ 3771.1Sragge ka88_txrx(id, "D/I 38 %x\r", mfpr(PR_MAPEN)); /* Enable MM */ 3781.1Sragge ka88_txrx(id, "S %x\r", (int)&tramp); /* Start! */ 3791.1Sragge expect = 0; 3801.1Sragge for (i = 0; i < 10000; i++) 3811.1Sragge if ((volatile)ci->ci_flags & CI_RUNNING) 3821.1Sragge break; 3831.1Sragge if (i == 10000) 3841.1Sragge printf("%s: (ID %d) failed starting??!!??\n", 3851.1Sragge dev->dv_xname, sc->sc_binid); 3861.1Sragge} 3871.1Sragge 3881.1Sraggevoid 3891.1Sraggeka88_txrx(int id, char *fmt, int arg) 3901.1Sragge{ 3911.1Sragge char buf[20]; 3921.1Sragge 3931.1Sragge sprintf(buf, fmt, arg); 3941.1Sragge ka88_sendstr(id, buf); 3951.1Sragge ka88_sergeant(id); 3961.1Sragge} 3971.1Sragge 3981.1Sraggevoid 3991.1Sraggeka88_sendstr(int id, char *buf) 4001.1Sragge{ 4011.1Sragge register u_int utchr; /* Ends up in R11 with PCC */ 4021.1Sragge int ch, i; 4031.1Sragge 4041.1Sragge while (*buf) { 4051.1Sragge utchr = *buf | id << 8; 4061.1Sragge 4071.1Sragge /* 4081.1Sragge * It seems like mtpr to TXCD sets the V flag if it fails. 4091.1Sragge * Cannot check that flag in C... 4101.1Sragge */ 4111.1Sragge#ifdef __GNUC__ 4121.1Sragge asm("1:;mtpr %0,$92;bvs 1b" :: "g"(utchr)); 4131.1Sragge#else 4141.1Sragge asm("1:;mtpr r11,$92;bvs 1b"); 4151.1Sragge#endif 4161.1Sragge buf++; 4171.1Sragge i = 30000; 4181.1Sragge while ((ch = rxchar()) == 0 && --i) 4191.1Sragge ; 4201.1Sragge if (ch == 0) 4211.1Sragge continue; /* failed */ 4221.1Sragge } 4231.1Sragge} 4241.1Sragge 4251.1Sraggevoid 4261.1Sraggeka88_sergeant(int id) 4271.1Sragge{ 4281.1Sragge int i, ch, nserg; 4291.1Sragge 4301.1Sragge nserg = 0; 4311.1Sragge for (i = 0; i < 30000; i++) { 4321.1Sragge if ((ch = rxchar()) == 0) 4331.1Sragge continue; 4341.1Sragge if (ch == '>') 4351.1Sragge nserg++; 4361.1Sragge else 4371.1Sragge nserg = 0; 4381.1Sragge i = 0; 4391.1Sragge if (nserg == 3) 4401.1Sragge break; 4411.1Sragge } 4421.1Sragge /* What to do now??? */ 4431.1Sragge} 4441.1Sragge 4451.1Sragge/* 4461.1Sragge * Write to master console. 4471.1Sragge * Need no locking here; done in the print functions. 4481.1Sragge */ 4491.1Sraggestatic volatile int ch = 0; 4501.1Sragge 4511.1Sraggevoid 4521.1Sraggeka88_putc(int c) 4531.1Sragge{ 4541.1Sragge if (curcpu()->ci_flags & CI_MASTERCPU) { 4551.1Sragge gencnputc(0, c); 4561.1Sragge return; 4571.1Sragge } 4581.1Sragge ch = c; 4591.1Sragge mtpr(mastercpu << 8, PR_RXCD); /* Send IPI to mastercpu */ 4601.1Sragge while (ch != 0) 4611.1Sragge ; /* Wait for master to handle */ 4621.1Sragge} 4631.1Sragge 4641.1Sragge/* 4651.1Sragge * Got character IPI. 4661.1Sragge */ 4671.1Sraggevoid 4681.1Sraggeka88_cnintr() 4691.1Sragge{ 4701.1Sragge if (ch != 0) 4711.1Sragge gencnputc(0, ch); 4721.1Sragge ch = 0; /* Release slavecpu */ 4731.1Sragge} 4741.1Sragge#endif 475