xref: /netbsd/sys/arch/vax/vax/ka660.c (revision 886bdb01)
1 /*	$NetBSD: ka660.c,v 1.12 2017/05/22 16:46:15 ragge Exp $	*/
2 /*
3  * Copyright (c) 2000 Ludd, University of Lule}, Sweden.
4  * 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  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  */
26 
27 #include <sys/cdefs.h>
28 __KERNEL_RCSID(0, "$NetBSD: ka660.c,v 1.12 2017/05/22 16:46:15 ragge Exp $");
29 
30 #include <sys/param.h>
31 #include <sys/systm.h>
32 #include <sys/cpu.h>
33 #include <sys/device.h>
34 #include <sys/kernel.h>
35 
36 #include <machine/sid.h>
37 #include <machine/nexus.h>
38 #include <machine/ka410.h>
39 #include <machine/ka420.h>
40 #include <machine/clock.h>
41 #include <machine/vsbus.h>
42 
43 #define KA660_CCR	37		/* Cache Control Register */
44 #define KA660_CTAG	0x20150000	/* Cache Tags */
45 #define KA660_CDATA	0x20150400	/* Cache Data */
46 #define KA660_BEHR	0x20150800	/* Bank Enable/Hit Register */
47 #define CCR_WWP		8	/* Write Wrong Parity */
48 #define CCR_ENA		4	/* Cache Enable */
49 #define CCR_FLU 2	/* Cache Flush */
50 #define CCR_DIA 1	/* Diagnostic mode */
51 
52 static void ka660_conf(void);
53 static void ka660_memerr(void);
54 static void ka660_cache_enable(void);
55 static void ka660_attach_cpu(device_t);
56 static int ka660_mchk(void *);
57 
58 static const char * const ka660_devs[] = { "cpu", "sgec", "shac", "uba", NULL };
59 
60 /*
61  * Declaration of 660-specific calls.
62  */
63 const struct cpu_dep ka660_calls = {
64 	.cpu_steal_pages = ka660_cache_enable,	/* ewww */
65 	.cpu_mchk	= ka660_mchk,
66 	.cpu_memerr	= ka660_memerr,
67 	.cpu_conf	= ka660_conf,
68 	.cpu_gettime	= generic_gettime,
69 	.cpu_settime	= generic_settime,
70 	.cpu_vups	= 6,	/* ~VUPS */
71 	.cpu_scbsz	= 2,	/* SCB pages */
72 	.cpu_halt	= generic_halt,
73 	.cpu_reboot	= generic_reboot,
74 	.cpu_devs	= ka660_devs,
75 	.cpu_attach_cpu	= ka660_attach_cpu,
76 };
77 
78 
79 void
ka660_conf(void)80 ka660_conf(void)
81 {
82 	cpmbx = (struct cpmbx *)vax_map_physmem(0x20140400, 1);
83 }
84 
85 void
ka660_attach_cpu(device_t self)86 ka660_attach_cpu(device_t self)
87 {
88 	aprint_normal(
89 	    ": %s, SOC (ucode rev. %d), 6KB L1 cache\n",
90 	    "KA660",
91 	    vax_cpudata & 0377);
92 }
93 
94 void
ka660_cache_enable(void)95 ka660_cache_enable(void)
96 {
97 	unsigned int *p;
98 	int cnt, bnk, behrtmp;
99 
100 	mtpr(0, KA660_CCR);	/* Disable cache */
101 	mtpr(CCR_DIA, KA660_CCR);	/* Switch to diag mode */
102 	bnk = 1;
103 	behrtmp = 0;
104 	while(bnk <= 0x80)
105 	{
106 		*(int *)KA660_BEHR = bnk;
107 		p = (int *)KA660_CDATA;
108 		*p = 0x55aaff00L;
109 		if(*p == 0x55aaff00L) behrtmp |= bnk;
110 		*p = 0xffaa0055L;
111 		if(*p != 0xffaa0055L) behrtmp &= ~bnk;
112 		cnt = 256;
113 		while(cnt--) *p++ = 0L;
114 		p = (int *) KA660_CTAG;
115 		cnt =128;
116 		while(cnt--) { *p++ = 0x80000000L; p++; }
117 		bnk <<= 1;
118 	}
119 	*(int *)KA660_BEHR = behrtmp;
120 
121 	mtpr(CCR_DIA|CCR_FLU, KA660_CCR);	/* Flush tags */
122 	mtpr(CCR_ENA, KA660_CCR);	/* Enable cache */
123 }
124 
125 void
ka660_memerr(void)126 ka660_memerr(void)
127 {
128 	printf("Memory err!\n");
129 }
130 
131 int
ka660_mchk(void * addr)132 ka660_mchk(void *addr)
133 {
134 	panic("Machine check");
135 	return 0;
136 }
137