xref: /netbsd/sys/arch/vax/vax/ka46.c (revision 6550d01e)
1 /*	$NetBSD: ka46.c,v 1.25 2010/12/14 23:44:49 matt Exp $ */
2 /*
3  * Copyright (c) 1998 Ludd, University of Lule}, Sweden.
4  * All rights reserved.
5  *
6  * This code is derived from software contributed to Ludd by Bertram Barth.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. All advertising materials mentioning features or use of this software
17  *    must display the following acknowledgement:
18  *	This product includes software developed at Ludd, University of
19  *	Lule}, Sweden and its contributors.
20  * 4. The name of the author may not be used to endorse or promote products
21  *    derived from this software without specific prior written permission
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  */
34 
35 #include <sys/cdefs.h>
36 __KERNEL_RCSID(0, "$NetBSD: ka46.c,v 1.25 2010/12/14 23:44:49 matt Exp $");
37 
38 #include <sys/param.h>
39 #include <sys/systm.h>
40 #include <sys/cpu.h>
41 #include <sys/device.h>
42 #include <sys/kernel.h>
43 
44 #include <machine/sid.h>
45 #include <machine/nexus.h>
46 #include <machine/ka410.h>
47 #include <machine/ka420.h>
48 #include <machine/ka46.h>
49 #include <machine/clock.h>
50 #include <machine/vsbus.h>
51 
52 static	void	ka46_conf(void);
53 static	void	ka46_steal_pages(void);
54 static	void	ka46_memerr(void);
55 static	int	ka46_mchk(void *);
56 static	void	ka46_halt(void);
57 static	void	ka46_reboot(int);
58 static	void	ka46_cache_enable(void);
59 
60 static const char * const ka46_devs[] = { "cpu", "vsbus", NULL };
61 
62 struct	vs_cpu *ka46_cpu;
63 
64 /*
65  * Declaration of 46-specific calls.
66  */
67 const struct cpu_dep ka46_calls = {
68 	.cpu_steal_pages = ka46_steal_pages,
69 	.cpu_mchk	= ka46_mchk,
70 	.cpu_memerr	= ka46_memerr,
71 	.cpu_conf	= ka46_conf,
72 	.cpu_gettime	= chip_gettime,
73 	.cpu_settime	= chip_settime,
74 	.cpu_vups	= 12,      /* ~VUPS */
75 	.cpu_scbsz	= 2,	/* SCB pages */
76 	.cpu_halt	= ka46_halt,
77 	.cpu_reboot	= ka46_reboot,
78 	.cpu_devs	= ka46_devs,
79 	.cpu_flags	= CPU_RAISEIPL,
80 };
81 
82 static const char * const ka46_cpustrs[4] = {
83 	[0] = "unknown KA46 type 0",
84 	[1] = "KA47, Mariah, 2KB L1 cache, 256KB L2 cache",
85 	[2] = "KA46, Mariah, 2KB L1 cache, 256KB L2 cache",
86 	[3] = "unknown KA46 type 3",
87 };
88 
89 void
90 ka46_conf(void)
91 {
92 	curcpu()->ci_cpustr = ka46_cpustrs[vax_siedata & 0x3];
93 	ka46_cpu = (void *)vax_map_physmem(VS_REGS, 1);
94 	mtpr(2, PR_ACCS); /* Enable floating points */
95 	/*
96 	 * Setup parameters necessary to read time from clock chip.
97 	 */
98 	clk_adrshift = 1;       /* Addressed at long's... */
99 	clk_tweak = 2;          /* ...and shift two */
100 	clk_page = (short *)vax_map_physmem(VS_CLOCK, 1);
101 }
102 
103 void
104 ka46_cache_enable(void)
105 {
106 	int i, *tmp;
107 
108 	/* Disable caches */
109 	*(int *)KA46_CCR &= ~CCR_SPECIO;/* secondary */
110 	mtpr(PCSTS_FLUSH, PR_PCSTS);	/* primary */
111 	*(int *)KA46_BWF0 &= ~BWF0_FEN; /* invalidate filter */
112 
113 	/* Clear caches */
114 	tmp = (void *)KA46_INVFLT;	/* inv filter */
115 	for (i = 0; i < 32768; i++)
116 		tmp[i] = 0;
117 
118 	/* Write valid parity to all primary cache entries */
119 	for (i = 0; i < 256; i++) {
120 		mtpr(i << 3, PR_PCIDX);
121 		mtpr(PCTAG_PARITY, PR_PCTAG);
122 	}
123 
124 	/* Secondary cache */
125 	tmp = (void *)KA46_TAGST;
126 	for (i = 0; i < KA46_TAGSZ*2; i+=2)
127 		tmp[i] = 0;
128 
129 	/* Enable cache */
130 	*(int *)KA46_BWF0 |= BWF0_FEN; /* invalidate filter */
131 	mtpr(PCSTS_ENABLE, PR_PCSTS);
132 	*(int *)KA46_CCR = CCR_SPECIO | CCR_CENA;
133 }
134 
135 void
136 ka46_memerr(void)
137 {
138 	printf("Memory err!\n");
139 }
140 
141 int
142 ka46_mchk(void *addr)
143 {
144 	panic("Machine check");
145 	return 0;
146 }
147 
148 void
149 ka46_steal_pages(void)
150 {
151 
152 	/* Turn on caches (to speed up execution a bit) */
153 	ka46_cache_enable();
154 }
155 
156 #define	KA46_CPMBX	0x38
157 #define KA46_HLT_HALT	0xcf
158 #define KA46_HLT_BOOT	0x8b
159 
160 void
161 ka46_halt(void)
162 {
163 	((volatile uint8_t *) clk_page)[KA46_CPMBX] = KA46_HLT_HALT;
164 	__asm("halt");
165 }
166 
167 void
168 ka46_reboot(int arg)
169 {
170 	((volatile uint8_t *) clk_page)[KA46_CPMBX] = KA46_HLT_BOOT;
171 	__asm("halt");
172 }
173