1 /* $NetBSD: mainbus.c,v 1.10 2026/08/09 22:21:41 andvar Exp $ */ 2 3 /*- 4 * Copyright (c) 2014 Michael Lorenz 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 * POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 #include <sys/cdefs.h> 30 __KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.10 2026/08/09 22:21:41 andvar Exp $"); 31 32 #include "opt_ingenic.h" 33 #include "opt_multiprocessor.h" 34 35 #include <sys/param.h> 36 #include <sys/systm.h> 37 #include <sys/device.h> 38 39 #include <mips/cache.h> 40 #include <mips/cpuregs.h> 41 42 #include <mips/ingenic/ingenic_regs.h> 43 #ifdef INGENIC_DEBUG 44 #include <mips/ingenic/ingenic_var.h> 45 #endif 46 47 #include "locators.h" 48 49 static int mainbus_match(device_t, cfdata_t, void *); 50 static void mainbus_attach(device_t, device_t, void *); 51 static int mainbus_print(void *, const char *); 52 53 CFATTACH_DECL_NEW(mainbus, 0, 54 mainbus_match, mainbus_attach, NULL, NULL); 55 56 /* There can be only one. */ 57 int mainbus_found = 0; 58 59 struct mainbusdev { 60 const char *md_name; 61 }; 62 63 struct mainbusdev mainbusdevs[] = { 64 { "cpu", }, 65 #ifdef MULTIPROCESSOR 66 { "cpu", }, 67 #endif 68 { "apbus", }, 69 { NULL, } 70 }; 71 72 static int 73 mainbus_match(device_t parent, cfdata_t match, void *aux) 74 { 75 76 if (mainbus_found) 77 return (0); 78 79 return (1); 80 } 81 82 static void 83 mainbus_attach(device_t parent, device_t self, void *aux) 84 { 85 const struct mainbusdev *md; 86 87 mainbus_found = 1; 88 printf("\n"); 89 90 for (md = mainbusdevs; md->md_name != NULL; md++) { 91 struct mainbusdev ma = *md; 92 config_found(self, &ma, mainbus_print, CFARGS_NONE); 93 } 94 95 #ifdef INGENIC_DEBUG 96 printf("TFR: %08x\n", readreg(JZ_TC_TFR)); 97 printf("TMR: %08x\n", readreg(JZ_TC_TMR)); 98 99 /* send ourselves an IPI */ 100 mips_cp0_corembox_write(0x12345678, 0); 101 delay(1000); 102 103 /* send the other core an IPI */ 104 mips_cp0_corembox_write(0x12345678, 1); 105 delay(1000); 106 #endif 107 } 108 109 static int 110 mainbus_print(void *aux, const char *pnp) 111 { 112 113 return (QUIET); 114 } 115