cpu.c revision 1.1.4.2 1 1.1.4.2 rmind /* $NetBSD: cpu.c,v 1.1.4.2 2014/05/18 17:45:10 rmind Exp $ */
2 1.1.4.2 rmind
3 1.1.4.2 rmind /* $OpenBSD: cpu.c,v 1.29 2009/02/08 18:33:28 miod Exp $ */
4 1.1.4.2 rmind
5 1.1.4.2 rmind /*
6 1.1.4.2 rmind * Copyright (c) 1998-2003 Michael Shalayeff
7 1.1.4.2 rmind * All rights reserved.
8 1.1.4.2 rmind *
9 1.1.4.2 rmind * Redistribution and use in source and binary forms, with or without
10 1.1.4.2 rmind * modification, are permitted provided that the following conditions
11 1.1.4.2 rmind * are met:
12 1.1.4.2 rmind * 1. Redistributions of source code must retain the above copyright
13 1.1.4.2 rmind * notice, this list of conditions and the following disclaimer.
14 1.1.4.2 rmind * 2. Redistributions in binary form must reproduce the above copyright
15 1.1.4.2 rmind * notice, this list of conditions and the following disclaimer in the
16 1.1.4.2 rmind * documentation and/or other materials provided with the distribution.
17 1.1.4.2 rmind *
18 1.1.4.2 rmind * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 1.1.4.2 rmind * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 1.1.4.2 rmind * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 1.1.4.2 rmind * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT,
22 1.1.4.2 rmind * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 1.1.4.2 rmind * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 1.1.4.2 rmind * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 1.1.4.2 rmind * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 1.1.4.2 rmind * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
27 1.1.4.2 rmind * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
28 1.1.4.2 rmind * THE POSSIBILITY OF SUCH DAMAGE.
29 1.1.4.2 rmind */
30 1.1.4.2 rmind
31 1.1.4.2 rmind #include <sys/cdefs.h>
32 1.1.4.2 rmind __KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.1.4.2 2014/05/18 17:45:10 rmind Exp $");
33 1.1.4.2 rmind
34 1.1.4.2 rmind #include "opt_multiprocessor.h"
35 1.1.4.2 rmind
36 1.1.4.2 rmind #include <sys/param.h>
37 1.1.4.2 rmind #include <sys/systm.h>
38 1.1.4.2 rmind #include <sys/device.h>
39 1.1.4.2 rmind #include <sys/atomic.h>
40 1.1.4.2 rmind #include <sys/reboot.h>
41 1.1.4.2 rmind
42 1.1.4.2 rmind #include <uvm/uvm.h>
43 1.1.4.2 rmind
44 1.1.4.2 rmind #include <machine/cpufunc.h>
45 1.1.4.2 rmind #include <machine/pdc.h>
46 1.1.4.2 rmind #include <machine/iomod.h>
47 1.1.4.2 rmind #include <machine/autoconf.h>
48 1.1.4.2 rmind
49 1.1.4.2 rmind #include <hppa/hppa/cpuvar.h>
50 1.1.4.2 rmind #include <hppa/hppa/machdep.h>
51 1.1.4.2 rmind #include <hppa/dev/cpudevs.h>
52 1.1.4.2 rmind
53 1.1.4.2 rmind #ifdef MULTIPROCESSOR
54 1.1.4.2 rmind
55 1.1.4.2 rmind int hppa_ncpu;
56 1.1.4.2 rmind
57 1.1.4.2 rmind struct cpu_info *cpu_hatch_info;
58 1.1.4.2 rmind static volatile int start_secondary_cpu;
59 1.1.4.2 rmind #endif
60 1.1.4.2 rmind
61 1.1.4.2 rmind int cpumatch(device_t, cfdata_t, void *);
62 1.1.4.2 rmind void cpuattach(device_t, device_t, void *);
63 1.1.4.2 rmind
64 1.1.4.2 rmind CFATTACH_DECL_NEW(cpu, sizeof(struct cpu_softc),
65 1.1.4.2 rmind cpumatch, cpuattach, NULL, NULL);
66 1.1.4.2 rmind
67 1.1.4.2 rmind int
68 1.1.4.2 rmind cpumatch(device_t parent, cfdata_t cf, void *aux)
69 1.1.4.2 rmind {
70 1.1.4.2 rmind struct confargs *ca = aux;
71 1.1.4.2 rmind
72 1.1.4.2 rmind /* probe any 1.0, 1.1 or 2.0 */
73 1.1.4.2 rmind if (ca->ca_type.iodc_type != HPPA_TYPE_NPROC ||
74 1.1.4.2 rmind ca->ca_type.iodc_sv_model != HPPA_NPROC_HPPA)
75 1.1.4.2 rmind return 0;
76 1.1.4.2 rmind
77 1.1.4.2 rmind return 1;
78 1.1.4.2 rmind }
79 1.1.4.2 rmind
80 1.1.4.2 rmind void
81 1.1.4.2 rmind cpuattach(device_t parent, device_t self, void *aux)
82 1.1.4.2 rmind {
83 1.1.4.2 rmind /* machdep.c */
84 1.1.4.2 rmind extern struct pdc_cache pdc_cache;
85 1.1.4.2 rmind extern struct pdc_btlb pdc_btlb;
86 1.1.4.2 rmind extern struct pdc_model pdc_model;
87 1.1.4.2 rmind extern u_int cpu_ticksnum, cpu_ticksdenom;
88 1.1.4.2 rmind
89 1.1.4.2 rmind struct cpu_softc *sc = device_private(self);
90 1.1.4.2 rmind struct confargs *ca = aux;
91 1.1.4.2 rmind static const char lvls[4][4] = { "0", "1", "1.5", "2" };
92 1.1.4.2 rmind struct hppa_interrupt_register *ir;
93 1.1.4.2 rmind struct cpu_info *ci;
94 1.1.4.2 rmind u_int mhz = 100 * cpu_ticksnum / cpu_ticksdenom;
95 1.1.4.2 rmind int cpuno = device_unit(self);
96 1.1.4.2 rmind
97 1.1.4.2 rmind #ifdef MULTIPROCESSOR
98 1.1.4.2 rmind struct pglist mlist;
99 1.1.4.2 rmind struct vm_page *m;
100 1.1.4.2 rmind int error;
101 1.1.4.2 rmind #endif
102 1.1.4.2 rmind
103 1.1.4.2 rmind sc->sc_dev = self;
104 1.1.4.2 rmind
105 1.1.4.2 rmind /* Print the CPU chip name, nickname, and rev. */
106 1.1.4.2 rmind aprint_normal(": %s", hppa_cpu_info->hci_chip_name);
107 1.1.4.2 rmind if (hppa_cpu_info->hci_chip_nickname != NULL)
108 1.1.4.2 rmind aprint_normal(" (%s)", hppa_cpu_info->hci_chip_nickname);
109 1.1.4.2 rmind aprint_normal(" rev %d", cpu_revision);
110 1.1.4.2 rmind
111 1.1.4.2 rmind /* sanity against luser amongst config editors */
112 1.1.4.2 rmind if (ca->ca_irq != 31) {
113 1.1.4.2 rmind aprint_error_dev(self, "bad irq number %d\n", ca->ca_irq);
114 1.1.4.2 rmind return;
115 1.1.4.2 rmind }
116 1.1.4.2 rmind
117 1.1.4.2 rmind /* Print the CPU type, spec, level, category, and speed. */
118 1.1.4.2 rmind aprint_normal("\n%s: %s, PA-RISC %s", device_xname(self),
119 1.1.4.2 rmind hppa_cpu_info->hci_chip_type,
120 1.1.4.2 rmind hppa_cpu_info->hci_chip_spec);
121 1.1.4.2 rmind aprint_normal(", lev %s, cat %c, ",
122 1.1.4.2 rmind lvls[pdc_model.pa_lvl], "AB"[pdc_model.mc]);
123 1.1.4.2 rmind
124 1.1.4.2 rmind aprint_normal("%d", mhz / 100);
125 1.1.4.2 rmind if (mhz % 100 > 9)
126 1.1.4.2 rmind aprint_normal(".%02d", mhz % 100);
127 1.1.4.2 rmind
128 1.1.4.2 rmind aprint_normal(" MHz clk\n%s: %s", device_xname(self),
129 1.1.4.2 rmind pdc_model.sh? "shadows, ": "");
130 1.1.4.2 rmind
131 1.1.4.2 rmind if (pdc_cache.dc_conf.cc_fsel)
132 1.1.4.2 rmind aprint_normal("%uK cache", pdc_cache.dc_size / 1024);
133 1.1.4.2 rmind else
134 1.1.4.2 rmind aprint_normal("%uK/%uK D/I caches", pdc_cache.dc_size / 1024,
135 1.1.4.2 rmind pdc_cache.ic_size / 1024);
136 1.1.4.2 rmind if (pdc_cache.dt_conf.tc_sh)
137 1.1.4.2 rmind aprint_normal(", %u shared TLB", pdc_cache.dt_size);
138 1.1.4.2 rmind else
139 1.1.4.2 rmind aprint_normal(", %u/%u D/I TLBs", pdc_cache.dt_size,
140 1.1.4.2 rmind pdc_cache.it_size);
141 1.1.4.2 rmind
142 1.1.4.2 rmind if (pdc_btlb.finfo.num_c)
143 1.1.4.2 rmind aprint_normal(", %u shared BTLB", pdc_btlb.finfo.num_c);
144 1.1.4.2 rmind else {
145 1.1.4.2 rmind aprint_normal(", %u/%u D/I BTLBs", pdc_btlb.finfo.num_i,
146 1.1.4.2 rmind pdc_btlb.finfo.num_d);
147 1.1.4.2 rmind }
148 1.1.4.2 rmind aprint_normal("\n");
149 1.1.4.2 rmind
150 1.1.4.2 rmind /*
151 1.1.4.2 rmind * Describe the floating-point support.
152 1.1.4.2 rmind */
153 1.1.4.2 rmind KASSERT(fpu_present);
154 1.1.4.2 rmind aprint_normal("%s: %s floating point, rev %d\n", device_xname(self),
155 1.1.4.2 rmind hppa_mod_info(HPPA_TYPE_FPU, (fpu_version >> 16) & 0x1f),
156 1.1.4.2 rmind (fpu_version >> 11) & 0x1f);
157 1.1.4.2 rmind
158 1.1.4.2 rmind if (cpuno >= HPPA_MAXCPUS) {
159 1.1.4.2 rmind aprint_normal_dev(self, "not started\n");
160 1.1.4.2 rmind return;
161 1.1.4.2 rmind }
162 1.1.4.2 rmind
163 1.1.4.2 rmind ci = &cpus[cpuno];
164 1.1.4.2 rmind ci->ci_cpuid = cpuno;
165 1.1.4.2 rmind ci->ci_hpa = ca->ca_hpa;
166 1.1.4.2 rmind
167 1.1.4.2 rmind hppa_intr_initialise(ci);
168 1.1.4.2 rmind
169 1.1.4.2 rmind ir = &ci->ci_ir;
170 1.1.4.2 rmind hppa_interrupt_register_establish(ci, ir);
171 1.1.4.2 rmind ir->ir_iscpu = true;
172 1.1.4.2 rmind ir->ir_ci = ci;
173 1.1.4.2 rmind ir->ir_name = device_xname(self);
174 1.1.4.2 rmind
175 1.1.4.2 rmind sc->sc_ihclk = hppa_intr_establish(IPL_CLOCK, clock_intr,
176 1.1.4.2 rmind NULL /*clockframe*/, &ci->ci_ir, 31);
177 1.1.4.2 rmind #ifdef MULTIPROCESSOR
178 1.1.4.2 rmind sc->sc_ihipi = hppa_intr_establish(IPL_HIGH, hppa_ipi_intr,
179 1.1.4.2 rmind NULL /*clockframe*/, &ci->ci_ir, 30);
180 1.1.4.2 rmind #endif
181 1.1.4.2 rmind
182 1.1.4.2 rmind /*
183 1.1.4.2 rmind * Reserve some bits for chips that don't like to be moved
184 1.1.4.2 rmind * around, e.g. lasi and asp.
185 1.1.4.2 rmind */
186 1.1.4.2 rmind ir->ir_rbits = ((1 << 28) | (1 << 27));
187 1.1.4.2 rmind ir->ir_bits &= ~ir->ir_rbits;
188 1.1.4.2 rmind
189 1.1.4.2 rmind #ifdef MULTIPROCESSOR
190 1.1.4.2 rmind /* Allocate stack for spin up and FPU emulation. */
191 1.1.4.2 rmind TAILQ_INIT(&mlist);
192 1.1.4.2 rmind error = uvm_pglistalloc(PAGE_SIZE, 0, -1L, PAGE_SIZE, 0, &mlist, 1, 0);
193 1.1.4.2 rmind
194 1.1.4.2 rmind if (error) {
195 1.1.4.2 rmind aprint_error(": unable to allocate CPU stack!\n");
196 1.1.4.2 rmind return;
197 1.1.4.2 rmind }
198 1.1.4.2 rmind m = TAILQ_FIRST(&mlist);
199 1.1.4.2 rmind ci->ci_stack = VM_PAGE_TO_PHYS(m);
200 1.1.4.2 rmind ci->ci_softc = sc;
201 1.1.4.2 rmind
202 1.1.4.2 rmind if (ci->ci_hpa == hppa_mcpuhpa) {
203 1.1.4.2 rmind ci->ci_flags |= CPUF_PRIMARY|CPUF_RUNNING;
204 1.1.4.2 rmind } else {
205 1.1.4.2 rmind int err;
206 1.1.4.2 rmind
207 1.1.4.2 rmind err = mi_cpu_attach(ci);
208 1.1.4.2 rmind if (err) {
209 1.1.4.2 rmind aprint_error_dev(self,
210 1.1.4.2 rmind "mi_cpu_attach failed with %d\n", err);
211 1.1.4.2 rmind return;
212 1.1.4.2 rmind }
213 1.1.4.2 rmind }
214 1.1.4.2 rmind hppa_ncpu++;
215 1.1.4.2 rmind hppa_ipi_init(ci);
216 1.1.4.2 rmind #endif
217 1.1.4.2 rmind KASSERT(ci->ci_cpl == -1);
218 1.1.4.2 rmind }
219 1.1.4.2 rmind
220 1.1.4.2 rmind #ifdef MULTIPROCESSOR
221 1.1.4.2 rmind void
222 1.1.4.2 rmind cpu_boot_secondary_processors(void)
223 1.1.4.2 rmind {
224 1.1.4.2 rmind struct cpu_info *ci;
225 1.1.4.2 rmind struct iomod *cpu;
226 1.1.4.2 rmind int i, j;
227 1.1.4.2 rmind
228 1.1.4.2 rmind for (i = 0; i < HPPA_MAXCPUS; i++) {
229 1.1.4.2 rmind
230 1.1.4.2 rmind ci = &cpus[i];
231 1.1.4.2 rmind if (ci->ci_cpuid == 0)
232 1.1.4.2 rmind continue;
233 1.1.4.2 rmind
234 1.1.4.2 rmind if (ci->ci_data.cpu_idlelwp == NULL)
235 1.1.4.2 rmind continue;
236 1.1.4.2 rmind
237 1.1.4.2 rmind if (ci->ci_flags & CPUF_PRIMARY)
238 1.1.4.2 rmind continue;
239 1.1.4.2 rmind
240 1.1.4.2 rmind /* Release the specified CPU by triggering an EIR{0}. */
241 1.1.4.2 rmind cpu_hatch_info = ci;
242 1.1.4.2 rmind cpu = (struct iomod *)(ci->ci_hpa);
243 1.1.4.2 rmind cpu->io_eir = 0;
244 1.1.4.2 rmind membar_sync();
245 1.1.4.2 rmind
246 1.1.4.2 rmind /* Wait for CPU to wake up... */
247 1.1.4.2 rmind j = 0;
248 1.1.4.2 rmind while (!(ci->ci_flags & CPUF_RUNNING) && j++ < 10000)
249 1.1.4.2 rmind delay(1000);
250 1.1.4.2 rmind if (!(ci->ci_flags & CPUF_RUNNING))
251 1.1.4.2 rmind printf("failed to hatch cpu %i!\n", ci->ci_cpuid);
252 1.1.4.2 rmind }
253 1.1.4.2 rmind
254 1.1.4.2 rmind /* Release secondary CPUs. */
255 1.1.4.2 rmind start_secondary_cpu = 1;
256 1.1.4.2 rmind membar_sync();
257 1.1.4.2 rmind }
258 1.1.4.2 rmind
259 1.1.4.2 rmind void
260 1.1.4.2 rmind cpu_hw_init(void)
261 1.1.4.2 rmind {
262 1.1.4.2 rmind struct cpu_info *ci = curcpu();
263 1.1.4.2 rmind
264 1.1.4.2 rmind /* Purge TLB and flush caches. */
265 1.1.4.2 rmind ptlball();
266 1.1.4.2 rmind fcacheall();
267 1.1.4.2 rmind
268 1.1.4.2 rmind /* Enable address translations. */
269 1.1.4.2 rmind ci->ci_psw = PSW_I | PSW_Q | PSW_P | PSW_C | PSW_D;
270 1.1.4.2 rmind ci->ci_psw |= (cpus[0].ci_psw & PSW_O);
271 1.1.4.2 rmind
272 1.1.4.2 rmind ci->ci_curlwp = ci->ci_data.cpu_idlelwp;
273 1.1.4.2 rmind }
274 1.1.4.2 rmind
275 1.1.4.2 rmind void
276 1.1.4.2 rmind cpu_hatch(void)
277 1.1.4.2 rmind {
278 1.1.4.2 rmind struct cpu_info *ci = curcpu();
279 1.1.4.2 rmind
280 1.1.4.2 rmind ci->ci_flags |= CPUF_RUNNING;
281 1.1.4.2 rmind
282 1.1.4.2 rmind /* Wait for additional CPUs to spinup. */
283 1.1.4.2 rmind while (!start_secondary_cpu)
284 1.1.4.2 rmind ;
285 1.1.4.2 rmind
286 1.1.4.2 rmind /* Spin for now */
287 1.1.4.2 rmind for (;;)
288 1.1.4.2 rmind ;
289 1.1.4.2 rmind
290 1.1.4.2 rmind }
291 1.1.4.2 rmind #endif
292