11.9Sthorpej/* $NetBSD: mainbus.c,v 1.9 2021/08/07 16:18:51 thorpej Exp $ */ 21.1Smacallan 31.1Smacallan/*- 41.1Smacallan * Copyright (c) 2014 Michael Lorenz 51.1Smacallan * All rights reserved. 61.1Smacallan * 71.1Smacallan * Redistribution and use in source and binary forms, with or without 81.1Smacallan * modification, are permitted provided that the following conditions 91.1Smacallan * are met: 101.1Smacallan * 1. Redistributions of source code must retain the above copyright 111.1Smacallan * notice, this list of conditions and the following disclaimer. 121.1Smacallan * 2. Redistributions in binary form must reproduce the above copyright 131.1Smacallan * notice, this list of conditions and the following disclaimer in the 141.1Smacallan * documentation and/or other materials provided with the distribution. 151.1Smacallan * 161.1Smacallan * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 171.1Smacallan * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 181.1Smacallan * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 191.1Smacallan * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 201.1Smacallan * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 211.1Smacallan * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 221.1Smacallan * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 231.1Smacallan * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 241.1Smacallan * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 251.1Smacallan * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 261.1Smacallan * POSSIBILITY OF SUCH DAMAGE. 271.1Smacallan */ 281.6Sskrll 291.1Smacallan#include <sys/cdefs.h> 301.9Sthorpej__KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.9 2021/08/07 16:18:51 thorpej Exp $"); 311.5Smacallan 321.5Smacallan#include "opt_multiprocessor.h" 331.1Smacallan 341.1Smacallan#include <sys/param.h> 351.1Smacallan#include <sys/systm.h> 361.1Smacallan#include <sys/device.h> 371.1Smacallan 381.1Smacallan#include <mips/cache.h> 391.1Smacallan#include <mips/cpuregs.h> 401.1Smacallan 411.2Smacallan#include <mips/ingenic/ingenic_regs.h> 421.2Smacallan 431.3Smacallan#include "opt_ingenic.h" 441.3Smacallan 451.1Smacallan#include "locators.h" 461.1Smacallan 471.1Smacallanstatic int mainbus_match(device_t, cfdata_t, void *); 481.1Smacallanstatic void mainbus_attach(device_t, device_t, void *); 491.1Smacallanstatic int mainbus_print(void *, const char *); 501.1Smacallan 511.1SmacallanCFATTACH_DECL_NEW(mainbus, 0, 521.1Smacallan mainbus_match, mainbus_attach, NULL, NULL); 531.1Smacallan 541.1Smacallan/* There can be only one. */ 551.1Smacallanint mainbus_found = 0; 561.1Smacallan 571.1Smacallanstruct mainbusdev { 581.1Smacallan const char *md_name; 591.1Smacallan}; 601.1Smacallan 611.1Smacallanstruct mainbusdev mainbusdevs[] = { 621.1Smacallan { "cpu", }, 631.5Smacallan#ifdef MULTIPROCESSOR 641.5Smacallan { "cpu", }, 651.5Smacallan#endif 661.2Smacallan { "apbus", }, 671.1Smacallan { NULL, } 681.1Smacallan}; 691.1Smacallan 701.1Smacallanstatic int 711.1Smacallanmainbus_match(device_t parent, cfdata_t match, void *aux) 721.1Smacallan{ 731.1Smacallan 741.1Smacallan if (mainbus_found) 751.1Smacallan return (0); 761.1Smacallan 771.1Smacallan return (1); 781.1Smacallan} 791.1Smacallan 801.1Smacallanstatic void 811.1Smacallanmainbus_attach(device_t parent, device_t self, void *aux) 821.1Smacallan{ 831.1Smacallan const struct mainbusdev *md; 841.1Smacallan 851.1Smacallan mainbus_found = 1; 861.1Smacallan printf("\n"); 871.1Smacallan 881.1Smacallan for (md = mainbusdevs; md->md_name != NULL; md++) { 891.1Smacallan struct mainbusdev ma = *md; 901.9Sthorpej config_found(self, &ma, mainbus_print, CFARGS_NONE); 911.1Smacallan } 921.2Smacallan 931.2Smacallan#ifdef INGENIC_DEBUG 941.2Smacallan printf("TFR: %08x\n", readreg(JZ_TC_TFR)); 951.2Smacallan printf("TMR: %08x\n", readreg(JZ_TC_TMR)); 961.2Smacallan 971.2Smacallan /* send ourselves an IPI */ 981.7Sskrll mips_cp0_corembox_write(0x12345678, 0); 991.2Smacallan delay(1000); 1001.4Smacallan 1011.4Smacallan /* send the other core an IPI */ 1021.7Sskrll mips_cp0_corembox_write(0x12345678, 1); 1031.4Smacallan delay(1000); 1041.2Smacallan#endif 1051.1Smacallan} 1061.1Smacallan 1071.1Smacallanstatic int 1081.1Smacallanmainbus_print(void *aux, const char *pnp) 1091.1Smacallan{ 1101.1Smacallan 1111.1Smacallan return (QUIET); 1121.1Smacallan} 113