cpu.c revision 1.1
11.1Smacallan/*	$NetBSD: cpu.c,v 1.1 2016/01/29 01:54:14 macallan Exp $	*/
21.1Smacallan
31.1Smacallan/*
41.1Smacallan * Copyright 2002 Wasabi Systems, Inc.
51.1Smacallan * All rights reserved.
61.1Smacallan *
71.1Smacallan * Written by Simon Burge for Wasabi Systems, Inc.
81.1Smacallan *
91.1Smacallan * Redistribution and use in source and binary forms, with or without
101.1Smacallan * modification, are permitted provided that the following conditions
111.1Smacallan * are met:
121.1Smacallan * 1. Redistributions of source code must retain the above copyright
131.1Smacallan *    notice, this list of conditions and the following disclaimer.
141.1Smacallan * 2. Redistributions in binary form must reproduce the above copyright
151.1Smacallan *    notice, this list of conditions and the following disclaimer in the
161.1Smacallan *    documentation and/or other materials provided with the distribution.
171.1Smacallan * 3. All advertising materials mentioning features or use of this software
181.1Smacallan *    must display the following acknowledgement:
191.1Smacallan *      This product includes software developed for the NetBSD Project by
201.1Smacallan *      Wasabi Systems, Inc.
211.1Smacallan * 4. The name of Wasabi Systems, Inc. may not be used to endorse
221.1Smacallan *    or promote products derived from this software without specific prior
231.1Smacallan *    written permission.
241.1Smacallan *
251.1Smacallan * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
261.1Smacallan * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
271.1Smacallan * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
281.1Smacallan * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
291.1Smacallan * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
301.1Smacallan * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
311.1Smacallan * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
321.1Smacallan * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
331.1Smacallan * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
341.1Smacallan * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
351.1Smacallan * POSSIBILITY OF SUCH DAMAGE.
361.1Smacallan */
371.1Smacallan
381.1Smacallan#include <sys/cdefs.h>
391.1Smacallan__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.1 2016/01/29 01:54:14 macallan Exp $");
401.1Smacallan
411.1Smacallan#include <sys/param.h>
421.1Smacallan#include <sys/device.h>
431.1Smacallan#include <sys/systm.h>
441.1Smacallan#include <sys/cpu.h>
451.1Smacallan
461.1Smacallan#include <mips/locore.h>
471.1Smacallan#include <mips/asm.h>
481.1Smacallan#include <mips/ingenic/ingenic_regs.h>
491.1Smacallan
501.1Smacallan#include "opt_ingenic.h"
511.1Smacallan
521.1Smacallanstatic int	cpu_match(device_t, cfdata_t, void *);
531.1Smacallanstatic void	cpu_attach(device_t, device_t, void *);
541.1Smacallan
551.1SmacallanCFATTACH_DECL_NEW(cpu, 0,
561.1Smacallan    cpu_match, cpu_attach, NULL, NULL);
571.1Smacallan
581.1Smacallanstruct cpu_info *startup_cpu_info;
591.1Smacallanextern void *ingenic_wakeup;
601.1Smacallan
611.1Smacallanstatic int
621.1Smacallancpu_match(device_t parent, cfdata_t match, void *aux)
631.1Smacallan{
641.1Smacallan	struct mainbusdev {
651.1Smacallan		const char *md_name;
661.1Smacallan	} *aa = aux;
671.1Smacallan	if (strcmp(aa->md_name, "cpu") == 0) return 1;
681.1Smacallan	return 0;
691.1Smacallan}
701.1Smacallan
711.1Smacallanstatic void
721.1Smacallancpu_attach(device_t parent, device_t self, void *aux)
731.1Smacallan{
741.1Smacallan	struct cpu_info *ci = curcpu();
751.1Smacallan	int unit;
761.1Smacallan
771.1Smacallan	if ((unit = device_unit(self)) > 0) {
781.1Smacallan#ifdef MULTIPROCESSOR
791.1Smacallan		uint32_t vec, reg;
801.1Smacallan		int bail = 10000;
811.1Smacallan
821.1Smacallan		startup_cpu_info = cpu_info_alloc(NULL, unit, 0, unit, 0);
831.1Smacallan		startup_cpu_info->ci_cpu_freq = ci->ci_cpu_freq;
841.1Smacallan		ci = startup_cpu_info;
851.1Smacallan		wbflush();
861.1Smacallan		vec = (uint32_t)&ingenic_wakeup;
871.1Smacallan		reg = MFC0(12, 4);	/* reset entry reg */
881.1Smacallan		reg &= ~REIM_ENTRY_M;
891.1Smacallan		reg |= vec;
901.1Smacallan		MTC0(reg, 12, 4);
911.1Smacallan		reg = MFC0(12, 2);	/* core control reg */
921.1Smacallan		reg |= CC_RPC1;		/* use our exception vector */
931.1Smacallan		reg &= ~CC_SW_RST1;	/* get core 1 out of reset */
941.1Smacallan		MTC0(reg, 12, 2);
951.1Smacallan		while ((!kcpuset_isset(cpus_hatched, cpu_index(startup_cpu_info))) && (bail > 0)) {
961.1Smacallan			delay(1000);
971.1Smacallan			bail--;
981.1Smacallan		}
991.1Smacallan		if (!kcpuset_isset(cpus_hatched, cpu_index(startup_cpu_info))) {
1001.1Smacallan			aprint_error_dev(self, "did not hatch\n");
1011.1Smacallan			return;
1021.1Smacallan		}
1031.1Smacallan#else
1041.1Smacallan		aprint_normal_dev(self,
1051.1Smacallan		    "processor off-line; "
1061.1Smacallan		    "multiprocessor support not present in kernel\n");
1071.1Smacallan		return;
1081.1Smacallan#endif
1091.1Smacallan
1101.1Smacallan	}
1111.1Smacallan	ci->ci_dev = self;
1121.1Smacallan	self->dv_private = ci;
1131.1Smacallan
1141.1Smacallan	aprint_normal(": %lu.%02luMHz (hz cycles = %lu, delay divisor = %lu)\n",
1151.1Smacallan	    ci->ci_cpu_freq / 1000000,
1161.1Smacallan	    (ci->ci_cpu_freq % 1000000) / 10000,
1171.1Smacallan	    ci->ci_cycles_per_hz, ci->ci_divisor_delay);
1181.1Smacallan
1191.1Smacallan	aprint_normal_dev(self, "");
1201.1Smacallan	cpu_identify(self);
1211.1Smacallan	cpu_attach_common(self, ci);
1221.1Smacallan}
123