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