1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 28*7c478bd9Sstevel@tonic-gate 29*7c478bd9Sstevel@tonic-gate /* 30*7c478bd9Sstevel@tonic-gate * CPU-specific functions needed by the Kernel-Debugger Interface (KDI). These 31*7c478bd9Sstevel@tonic-gate * functions are invoked directly by the kernel debugger (kmdb) while the system 32*7c478bd9Sstevel@tonic-gate * has been stopped, and as such must not use any kernel facilities that block 33*7c478bd9Sstevel@tonic-gate * or otherwise rely on forward progress by other parts of the kernel. 34*7c478bd9Sstevel@tonic-gate * 35*7c478bd9Sstevel@tonic-gate * These functions may also be called before unix`_start, and as such cannot 36*7c478bd9Sstevel@tonic-gate * use any kernel facilities that must be initialized as part of system start. 37*7c478bd9Sstevel@tonic-gate * An example of such a facility is drv_usecwait(), which relies on a parameter 38*7c478bd9Sstevel@tonic-gate * that is initialized by the unix module. As a result, drv_usecwait() may not 39*7c478bd9Sstevel@tonic-gate * be used by KDI functions. 40*7c478bd9Sstevel@tonic-gate */ 41*7c478bd9Sstevel@tonic-gate 42*7c478bd9Sstevel@tonic-gate #include <sys/types.h> 43*7c478bd9Sstevel@tonic-gate #include <sys/systm.h> 44*7c478bd9Sstevel@tonic-gate #include <sys/archsystm.h> 45*7c478bd9Sstevel@tonic-gate #include <sys/machsystm.h> 46*7c478bd9Sstevel@tonic-gate #include <sys/cpu_module.h> 47*7c478bd9Sstevel@tonic-gate #include <sys/spitregs.h> 48*7c478bd9Sstevel@tonic-gate #include <sys/xc_impl.h> 49*7c478bd9Sstevel@tonic-gate #include <sys/intreg.h> 50*7c478bd9Sstevel@tonic-gate #include <sys/kdi_impl.h> 51*7c478bd9Sstevel@tonic-gate 52*7c478bd9Sstevel@tonic-gate /* 53*7c478bd9Sstevel@tonic-gate * We keep our own copies, used for cache flushing, because we can be called 54*7c478bd9Sstevel@tonic-gate * before cpu_fiximpl(). 55*7c478bd9Sstevel@tonic-gate */ 56*7c478bd9Sstevel@tonic-gate static int kdi_dcache_size; 57*7c478bd9Sstevel@tonic-gate static int kdi_dcache_linesize; 58*7c478bd9Sstevel@tonic-gate static int kdi_icache_size; 59*7c478bd9Sstevel@tonic-gate static int kdi_icache_linesize; 60*7c478bd9Sstevel@tonic-gate 61*7c478bd9Sstevel@tonic-gate /* 62*7c478bd9Sstevel@tonic-gate * Assembly support for spitfire modules in spitfire_asm.s 63*7c478bd9Sstevel@tonic-gate */ 64*7c478bd9Sstevel@tonic-gate extern int idsr_busy(void); 65*7c478bd9Sstevel@tonic-gate extern void init_mondo_nocheck(xcfunc_t *func, uint64_t arg1, uint64_t arg2); 66*7c478bd9Sstevel@tonic-gate extern void shipit(int); 67*7c478bd9Sstevel@tonic-gate extern void kdi_flush_idcache(int, int, int, int); 68*7c478bd9Sstevel@tonic-gate 69*7c478bd9Sstevel@tonic-gate static int 70*7c478bd9Sstevel@tonic-gate kdi_cpu_ready_iter(int (*cb)(int, void *), void *arg) 71*7c478bd9Sstevel@tonic-gate { 72*7c478bd9Sstevel@tonic-gate int rc, i; 73*7c478bd9Sstevel@tonic-gate 74*7c478bd9Sstevel@tonic-gate for (rc = 0, i = 0; i < NCPU; i++) { 75*7c478bd9Sstevel@tonic-gate if (CPU_IN_SET(cpu_ready_set, i)) 76*7c478bd9Sstevel@tonic-gate rc += cb(i, arg); 77*7c478bd9Sstevel@tonic-gate } 78*7c478bd9Sstevel@tonic-gate 79*7c478bd9Sstevel@tonic-gate return (rc); 80*7c478bd9Sstevel@tonic-gate } 81*7c478bd9Sstevel@tonic-gate 82*7c478bd9Sstevel@tonic-gate /* 83*7c478bd9Sstevel@tonic-gate * Sends a cross-call to a specified processor. The caller assumes 84*7c478bd9Sstevel@tonic-gate * responsibility for repetition of cross-calls, as appropriate (MARSA for 85*7c478bd9Sstevel@tonic-gate * debugging). 86*7c478bd9Sstevel@tonic-gate */ 87*7c478bd9Sstevel@tonic-gate static int 88*7c478bd9Sstevel@tonic-gate kdi_xc_one(int cpuid, void (*func)(uintptr_t, uintptr_t), uintptr_t arg1, 89*7c478bd9Sstevel@tonic-gate uintptr_t arg2) 90*7c478bd9Sstevel@tonic-gate { 91*7c478bd9Sstevel@tonic-gate uint64_t idsr; 92*7c478bd9Sstevel@tonic-gate 93*7c478bd9Sstevel@tonic-gate /* 94*7c478bd9Sstevel@tonic-gate * if (idsr_busy()) 95*7c478bd9Sstevel@tonic-gate * return (KDI_XC_RES_ERR); 96*7c478bd9Sstevel@tonic-gate */ 97*7c478bd9Sstevel@tonic-gate 98*7c478bd9Sstevel@tonic-gate init_mondo_nocheck((xcfunc_t *)func, arg1, arg2); 99*7c478bd9Sstevel@tonic-gate 100*7c478bd9Sstevel@tonic-gate shipit(CPUID_TO_UPAID(cpuid)); 101*7c478bd9Sstevel@tonic-gate 102*7c478bd9Sstevel@tonic-gate if ((idsr = getidsr()) == 0) 103*7c478bd9Sstevel@tonic-gate return (KDI_XC_RES_OK); 104*7c478bd9Sstevel@tonic-gate else if (idsr & IDSR_BUSY) 105*7c478bd9Sstevel@tonic-gate return (KDI_XC_RES_BUSY); 106*7c478bd9Sstevel@tonic-gate else 107*7c478bd9Sstevel@tonic-gate return (KDI_XC_RES_NACK); 108*7c478bd9Sstevel@tonic-gate } 109*7c478bd9Sstevel@tonic-gate 110*7c478bd9Sstevel@tonic-gate static void 111*7c478bd9Sstevel@tonic-gate kdi_tickwait(clock_t nticks) 112*7c478bd9Sstevel@tonic-gate { 113*7c478bd9Sstevel@tonic-gate clock_t endtick = gettick() + nticks; 114*7c478bd9Sstevel@tonic-gate 115*7c478bd9Sstevel@tonic-gate while (gettick() < endtick); 116*7c478bd9Sstevel@tonic-gate } 117*7c478bd9Sstevel@tonic-gate 118*7c478bd9Sstevel@tonic-gate static void 119*7c478bd9Sstevel@tonic-gate kdi_cpu_init(int dcache_size, int dcache_linesize, int icache_size, 120*7c478bd9Sstevel@tonic-gate int icache_linesize) 121*7c478bd9Sstevel@tonic-gate { 122*7c478bd9Sstevel@tonic-gate kdi_dcache_size = dcache_size; 123*7c478bd9Sstevel@tonic-gate kdi_dcache_linesize = dcache_linesize; 124*7c478bd9Sstevel@tonic-gate kdi_icache_size = icache_size; 125*7c478bd9Sstevel@tonic-gate kdi_icache_linesize = icache_linesize; 126*7c478bd9Sstevel@tonic-gate } 127*7c478bd9Sstevel@tonic-gate 128*7c478bd9Sstevel@tonic-gate /* used directly by kdi_read/write_phys */ 129*7c478bd9Sstevel@tonic-gate void 130*7c478bd9Sstevel@tonic-gate kdi_flush_caches(void) 131*7c478bd9Sstevel@tonic-gate { 132*7c478bd9Sstevel@tonic-gate kdi_flush_idcache(kdi_dcache_size, kdi_dcache_linesize, 133*7c478bd9Sstevel@tonic-gate kdi_icache_size, kdi_icache_linesize); 134*7c478bd9Sstevel@tonic-gate } 135*7c478bd9Sstevel@tonic-gate 136*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 137*7c478bd9Sstevel@tonic-gate int 138*7c478bd9Sstevel@tonic-gate kdi_get_stick(uint64_t *stickp) 139*7c478bd9Sstevel@tonic-gate { 140*7c478bd9Sstevel@tonic-gate return (-1); 141*7c478bd9Sstevel@tonic-gate } 142*7c478bd9Sstevel@tonic-gate 143*7c478bd9Sstevel@tonic-gate void 144*7c478bd9Sstevel@tonic-gate cpu_kdi_init(kdi_t *kdi) 145*7c478bd9Sstevel@tonic-gate { 146*7c478bd9Sstevel@tonic-gate kdi->kdi_flush_caches = kdi_flush_caches; 147*7c478bd9Sstevel@tonic-gate kdi->mkdi_cpu_init = kdi_cpu_init; 148*7c478bd9Sstevel@tonic-gate kdi->mkdi_cpu_ready_iter = kdi_cpu_ready_iter; 149*7c478bd9Sstevel@tonic-gate kdi->mkdi_xc_one = kdi_xc_one; 150*7c478bd9Sstevel@tonic-gate kdi->mkdi_tickwait = kdi_tickwait; 151*7c478bd9Sstevel@tonic-gate kdi->mkdi_get_stick = kdi_get_stick; 152*7c478bd9Sstevel@tonic-gate } 153