1 /*
2 * Copyright (c) 1998 Ludd, University of Lule}, Sweden.
3 * All rights reserved.
4 *
5 * This code is derived from software contributed to Ludd by Bertram Barth.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28 /*** needs to be completed MK-990306 ***/
29
30 #include <sys/cdefs.h>
31 __KERNEL_RCSID(0, "$NetBSD: ka48.c,v 1.22 2017/05/22 16:46:15 ragge Exp $");
32
33 #include <sys/param.h>
34 #include <sys/systm.h>
35 #include <sys/cpu.h>
36 #include <sys/device.h>
37 #include <sys/kernel.h>
38
39 #include <machine/sid.h>
40 #include <machine/nexus.h>
41 #include <machine/ka410.h>
42 #include <machine/ka420.h>
43 #include <machine/ka48.h>
44 #include <machine/clock.h>
45 #include <machine/vsbus.h>
46
47 static void ka48_conf(void);
48 static void ka48_steal_pages(void);
49 static void ka48_memerr(void);
50 static int ka48_mchk(void *);
51 static void ka48_halt(void);
52 static void ka48_reboot(int);
53 static void ka48_cache_enable(void);
54
55 struct vs_cpu *ka48_cpu;
56
57 static const char * const ka48_devs[] = { "cpu", "vsbus", NULL };
58
59 /*
60 * Declaration of 48-specific calls.
61 */
62 const struct cpu_dep ka48_calls = {
63 .cpu_steal_pages = ka48_steal_pages,
64 .cpu_mchk = ka48_mchk,
65 .cpu_memerr = ka48_memerr,
66 .cpu_conf = ka48_conf,
67 .cpu_gettime = chip_gettime,
68 .cpu_settime = chip_settime,
69 .cpu_vups = 6, /* ~VUPS */
70 .cpu_scbsz = 2, /* SCB pages */
71 .cpu_halt = ka48_halt,
72 .cpu_reboot = ka48_reboot,
73 .cpu_devs = ka48_devs,
74 .cpu_flags = CPU_RAISEIPL,
75 };
76
77
78 void
ka48_conf(void)79 ka48_conf(void)
80 {
81 curcpu()->ci_cpustr = "KA48, SOC, 6KB L1 cache";
82
83 ka48_cpu = (void *)vax_map_physmem(VS_REGS, 1);
84 mtpr(2, PR_ACCS); /* Enable floating points */
85 /*
86 * Setup parameters necessary to read time from clock chip.
87 */
88 clk_adrshift = 1; /* Addressed at long's... */
89 clk_tweak = 2; /* ...and shift two */
90 clk_page = (short *)vax_map_physmem(VS_CLOCK, 1);
91 }
92
93 void
ka48_cache_enable(void)94 ka48_cache_enable(void)
95 {
96 int i, *tmp;
97 long *par_ctl = (long *)KA48_PARCTL;
98
99 /* Disable cache */
100 mtpr(0, PR_CADR); /* disable */
101 *par_ctl &= ~KA48_PARCTL_INVENA; /* clear ? invalid enable */
102 mtpr(2, PR_CADR); /* flush */
103
104 /* Clear caches */
105 tmp = (void *)KA48_INVFLT; /* inv filter */
106 for (i = 0; i < KA48_INVFLTSZ / sizeof(int); i++)
107 tmp[i] = 0;
108 *par_ctl |= KA48_PARCTL_INVENA; /* Enable ???? */
109 mtpr(4, PR_CADR); /* enable cache */
110 *par_ctl |= (KA48_PARCTL_AGS | /* AGS? */
111 KA48_PARCTL_NPEN | /* N? Parity Enable */
112 KA48_PARCTL_CPEN); /* CPU parity enable */
113 }
114
115 void
ka48_memerr(void)116 ka48_memerr(void)
117 {
118 printf("Memory err!\n");
119 }
120
121 int
ka48_mchk(void * addr)122 ka48_mchk(void *addr)
123 {
124 panic("Machine check");
125 return 0;
126 }
127
128 void
ka48_steal_pages(void)129 ka48_steal_pages(void)
130 {
131 /* Turn on caches (to speed up execution a bit) */
132 ka48_cache_enable();
133 }
134
135 #define KA48_CPMBX 0x38
136 #define KA48_HLT_HALT 0xcf /* 11001111 */
137 #define KA48_HLT_BOOT 0x8b /* 10001011 */
138
139 void
ka48_halt(void)140 ka48_halt(void)
141 {
142 ((volatile uint8_t *) clk_page)[KA48_CPMBX] = KA48_HLT_HALT;
143 __asm("halt");
144 }
145
146 void
ka48_reboot(int arg)147 ka48_reboot(int arg)
148 {
149 ((volatile uint8_t *) clk_page)[KA48_CPMBX] = KA48_HLT_BOOT;
150 __asm("halt");
151 }
152