1*ee918b29Sragge /* $NetBSD: ka660.c,v 1.12 2017/05/22 16:46:15 ragge Exp $ */
2282320f7Sragge /*
3282320f7Sragge * Copyright (c) 2000 Ludd, University of Lule}, Sweden.
4282320f7Sragge * All rights reserved.
5282320f7Sragge *
6282320f7Sragge * Redistribution and use in source and binary forms, with or without
7282320f7Sragge * modification, are permitted provided that the following conditions
8282320f7Sragge * are met:
9282320f7Sragge * 1. Redistributions of source code must retain the above copyright
10282320f7Sragge * notice, this list of conditions and the following disclaimer.
11282320f7Sragge * 2. Redistributions in binary form must reproduce the above copyright
12282320f7Sragge * notice, this list of conditions and the following disclaimer in the
13282320f7Sragge * documentation and/or other materials provided with the distribution.
14282320f7Sragge *
15282320f7Sragge * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16282320f7Sragge * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17282320f7Sragge * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18282320f7Sragge * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19282320f7Sragge * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20282320f7Sragge * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21282320f7Sragge * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22282320f7Sragge * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23282320f7Sragge * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24282320f7Sragge * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25282320f7Sragge */
26282320f7Sragge
273b4fb6d0Slukem #include <sys/cdefs.h>
28*ee918b29Sragge __KERNEL_RCSID(0, "$NetBSD: ka660.c,v 1.12 2017/05/22 16:46:15 ragge Exp $");
293b4fb6d0Slukem
30282320f7Sragge #include <sys/param.h>
3108173673Smatt #include <sys/systm.h>
3208173673Smatt #include <sys/cpu.h>
33282320f7Sragge #include <sys/device.h>
34282320f7Sragge #include <sys/kernel.h>
35282320f7Sragge
36282320f7Sragge #include <machine/sid.h>
37282320f7Sragge #include <machine/nexus.h>
38282320f7Sragge #include <machine/ka410.h>
39282320f7Sragge #include <machine/ka420.h>
40282320f7Sragge #include <machine/clock.h>
41282320f7Sragge #include <machine/vsbus.h>
42282320f7Sragge
43282320f7Sragge #define KA660_CCR 37 /* Cache Control Register */
44282320f7Sragge #define KA660_CTAG 0x20150000 /* Cache Tags */
45282320f7Sragge #define KA660_CDATA 0x20150400 /* Cache Data */
46282320f7Sragge #define KA660_BEHR 0x20150800 /* Bank Enable/Hit Register */
47282320f7Sragge #define CCR_WWP 8 /* Write Wrong Parity */
48282320f7Sragge #define CCR_ENA 4 /* Cache Enable */
49282320f7Sragge #define CCR_FLU 2 /* Cache Flush */
50282320f7Sragge #define CCR_DIA 1 /* Diagnostic mode */
51282320f7Sragge
52282320f7Sragge static void ka660_conf(void);
53282320f7Sragge static void ka660_memerr(void);
54282320f7Sragge static void ka660_cache_enable(void);
55dfba8166Smatt static void ka660_attach_cpu(device_t);
56dfba8166Smatt static int ka660_mchk(void *);
57282320f7Sragge
5836f91343Sragge static const char * const ka660_devs[] = { "cpu", "sgec", "shac", "uba", NULL };
59282320f7Sragge
60282320f7Sragge /*
61282320f7Sragge * Declaration of 660-specific calls.
62282320f7Sragge */
63dfba8166Smatt const struct cpu_dep ka660_calls = {
64dfba8166Smatt .cpu_steal_pages = ka660_cache_enable, /* ewww */
65dfba8166Smatt .cpu_mchk = ka660_mchk,
66dfba8166Smatt .cpu_memerr = ka660_memerr,
67dfba8166Smatt .cpu_conf = ka660_conf,
68dfba8166Smatt .cpu_gettime = generic_gettime,
69dfba8166Smatt .cpu_settime = generic_settime,
70dfba8166Smatt .cpu_vups = 6, /* ~VUPS */
71dfba8166Smatt .cpu_scbsz = 2, /* SCB pages */
72dfba8166Smatt .cpu_halt = generic_halt,
73dfba8166Smatt .cpu_reboot = generic_reboot,
74dfba8166Smatt .cpu_devs = ka660_devs,
75dfba8166Smatt .cpu_attach_cpu = ka660_attach_cpu,
76282320f7Sragge };
77282320f7Sragge
78282320f7Sragge
79282320f7Sragge void
ka660_conf(void)80dfba8166Smatt ka660_conf(void)
81282320f7Sragge {
82780401f9Sragge cpmbx = (struct cpmbx *)vax_map_physmem(0x20140400, 1);
83282320f7Sragge }
84282320f7Sragge
85282320f7Sragge void
ka660_attach_cpu(device_t self)86dfba8166Smatt ka660_attach_cpu(device_t self)
87dfba8166Smatt {
88dfba8166Smatt aprint_normal(
8936f91343Sragge ": %s, SOC (ucode rev. %d), 6KB L1 cache\n",
90dfba8166Smatt "KA660",
91dfba8166Smatt vax_cpudata & 0377);
92dfba8166Smatt }
93dfba8166Smatt
94dfba8166Smatt void
ka660_cache_enable(void)95dfba8166Smatt ka660_cache_enable(void)
96282320f7Sragge {
97282320f7Sragge unsigned int *p;
98282320f7Sragge int cnt, bnk, behrtmp;
99282320f7Sragge
100282320f7Sragge mtpr(0, KA660_CCR); /* Disable cache */
101282320f7Sragge mtpr(CCR_DIA, KA660_CCR); /* Switch to diag mode */
102282320f7Sragge bnk = 1;
103282320f7Sragge behrtmp = 0;
104282320f7Sragge while(bnk <= 0x80)
105282320f7Sragge {
106282320f7Sragge *(int *)KA660_BEHR = bnk;
107282320f7Sragge p = (int *)KA660_CDATA;
108282320f7Sragge *p = 0x55aaff00L;
109282320f7Sragge if(*p == 0x55aaff00L) behrtmp |= bnk;
110282320f7Sragge *p = 0xffaa0055L;
111282320f7Sragge if(*p != 0xffaa0055L) behrtmp &= ~bnk;
112282320f7Sragge cnt = 256;
113282320f7Sragge while(cnt--) *p++ = 0L;
114282320f7Sragge p = (int *) KA660_CTAG;
115282320f7Sragge cnt =128;
116282320f7Sragge while(cnt--) { *p++ = 0x80000000L; p++; }
117282320f7Sragge bnk <<= 1;
118282320f7Sragge }
119282320f7Sragge *(int *)KA660_BEHR = behrtmp;
120282320f7Sragge
121282320f7Sragge mtpr(CCR_DIA|CCR_FLU, KA660_CCR); /* Flush tags */
122282320f7Sragge mtpr(CCR_ENA, KA660_CCR); /* Enable cache */
123282320f7Sragge }
124282320f7Sragge
125282320f7Sragge void
ka660_memerr(void)126dfba8166Smatt ka660_memerr(void)
127282320f7Sragge {
128282320f7Sragge printf("Memory err!\n");
129282320f7Sragge }
130282320f7Sragge
131282320f7Sragge int
ka660_mchk(void * addr)132dfba8166Smatt ka660_mchk(void *addr)
133282320f7Sragge {
134282320f7Sragge panic("Machine check");
135282320f7Sragge return 0;
136282320f7Sragge }
137