cpu.c revision 1.3
11.3Sskrll/* $NetBSD: cpu.c,v 1.3 2017/05/19 07:40:58 skrll 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.3Sskrll__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.3 2017/05/19 07:40:58 skrll Exp $"); 401.2Sskrll 411.2Sskrll#include "opt_ingenic.h" 421.2Sskrll#include "opt_multiprocessor.h" 431.1Smacallan 441.1Smacallan#include <sys/param.h> 451.1Smacallan#include <sys/device.h> 461.1Smacallan#include <sys/systm.h> 471.1Smacallan#include <sys/cpu.h> 481.1Smacallan 491.1Smacallan#include <mips/locore.h> 501.1Smacallan#include <mips/asm.h> 511.1Smacallan#include <mips/ingenic/ingenic_regs.h> 521.1Smacallan 531.1Smacallanstatic int cpu_match(device_t, cfdata_t, void *); 541.1Smacallanstatic void cpu_attach(device_t, device_t, void *); 551.1Smacallan 561.1SmacallanCFATTACH_DECL_NEW(cpu, 0, 571.1Smacallan cpu_match, cpu_attach, NULL, NULL); 581.1Smacallan 591.1Smacallanstruct cpu_info *startup_cpu_info; 601.1Smacallanextern void *ingenic_wakeup; 611.1Smacallan 621.1Smacallanstatic int 631.1Smacallancpu_match(device_t parent, cfdata_t match, void *aux) 641.1Smacallan{ 651.1Smacallan struct mainbusdev { 661.1Smacallan const char *md_name; 671.1Smacallan } *aa = aux; 681.1Smacallan if (strcmp(aa->md_name, "cpu") == 0) return 1; 691.1Smacallan return 0; 701.1Smacallan} 711.1Smacallan 721.1Smacallanstatic void 731.1Smacallancpu_attach(device_t parent, device_t self, void *aux) 741.1Smacallan{ 751.1Smacallan struct cpu_info *ci = curcpu(); 761.1Smacallan int unit; 771.1Smacallan 781.1Smacallan if ((unit = device_unit(self)) > 0) { 791.1Smacallan#ifdef MULTIPROCESSOR 801.1Smacallan uint32_t vec, reg; 811.1Smacallan int bail = 10000; 821.3Sskrll 831.1Smacallan startup_cpu_info = cpu_info_alloc(NULL, unit, 0, unit, 0); 841.1Smacallan startup_cpu_info->ci_cpu_freq = ci->ci_cpu_freq; 851.1Smacallan ci = startup_cpu_info; 861.1Smacallan wbflush(); 871.1Smacallan vec = (uint32_t)&ingenic_wakeup; 881.1Smacallan reg = MFC0(12, 4); /* reset entry reg */ 891.1Smacallan reg &= ~REIM_ENTRY_M; 901.1Smacallan reg |= vec; 911.1Smacallan MTC0(reg, 12, 4); 921.1Smacallan reg = MFC0(12, 2); /* core control reg */ 931.1Smacallan reg |= CC_RPC1; /* use our exception vector */ 941.1Smacallan reg &= ~CC_SW_RST1; /* get core 1 out of reset */ 951.1Smacallan MTC0(reg, 12, 2); 961.1Smacallan while ((!kcpuset_isset(cpus_hatched, cpu_index(startup_cpu_info))) && (bail > 0)) { 971.1Smacallan delay(1000); 981.1Smacallan bail--; 991.1Smacallan } 1001.1Smacallan if (!kcpuset_isset(cpus_hatched, cpu_index(startup_cpu_info))) { 1011.1Smacallan aprint_error_dev(self, "did not hatch\n"); 1021.1Smacallan return; 1031.1Smacallan } 1041.1Smacallan#else 1051.1Smacallan aprint_normal_dev(self, 1061.1Smacallan "processor off-line; " 1071.1Smacallan "multiprocessor support not present in kernel\n"); 1081.1Smacallan return; 1091.1Smacallan#endif 1101.1Smacallan 1111.1Smacallan } 1121.1Smacallan ci->ci_dev = self; 1131.1Smacallan self->dv_private = ci; 1141.1Smacallan 1151.1Smacallan aprint_normal(": %lu.%02luMHz (hz cycles = %lu, delay divisor = %lu)\n", 1161.1Smacallan ci->ci_cpu_freq / 1000000, 1171.1Smacallan (ci->ci_cpu_freq % 1000000) / 10000, 1181.1Smacallan ci->ci_cycles_per_hz, ci->ci_divisor_delay); 1191.1Smacallan 1201.1Smacallan aprint_normal_dev(self, ""); 1211.1Smacallan cpu_identify(self); 1221.1Smacallan cpu_attach_common(self, ci); 1231.1Smacallan} 124