125cf1a30Sjl139090 /*
225cf1a30Sjl139090 * CDDL HEADER START
325cf1a30Sjl139090 *
425cf1a30Sjl139090 * The contents of this file are subject to the terms of the
525cf1a30Sjl139090 * Common Development and Distribution License (the "License").
625cf1a30Sjl139090 * You may not use this file except in compliance with the License.
725cf1a30Sjl139090 *
825cf1a30Sjl139090 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
925cf1a30Sjl139090 * or http://www.opensolaris.org/os/licensing.
1025cf1a30Sjl139090 * See the License for the specific language governing permissions
1125cf1a30Sjl139090 * and limitations under the License.
1225cf1a30Sjl139090 *
1325cf1a30Sjl139090 * When distributing Covered Code, include this CDDL HEADER in each
1425cf1a30Sjl139090 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1525cf1a30Sjl139090 * If applicable, add the following below this CDDL HEADER, with the
1625cf1a30Sjl139090 * fields enclosed by brackets "[]" replaced with your own identifying
1725cf1a30Sjl139090 * information: Portions Copyright [yyyy] [name of copyright owner]
1825cf1a30Sjl139090 *
1925cf1a30Sjl139090 * CDDL HEADER END
2025cf1a30Sjl139090 */
2125cf1a30Sjl139090 /*
2225cf1a30Sjl139090 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
2325cf1a30Sjl139090 * Use is subject to license terms.
2425cf1a30Sjl139090 */
2525cf1a30Sjl139090
2625cf1a30Sjl139090 /*
2725cf1a30Sjl139090 * CPU-specific functions needed by the Kernel-Debugger Interface (KDI). These
2825cf1a30Sjl139090 * functions are invoked directly by the kernel debugger (kmdb) while the system
2925cf1a30Sjl139090 * has been stopped, and as such must not use any kernel facilities that block
3025cf1a30Sjl139090 * or otherwise rely on forward progress by other parts of the kernel.
3125cf1a30Sjl139090 *
3225cf1a30Sjl139090 * These functions may also be called before unix`_start, and as such cannot
3325cf1a30Sjl139090 * use any kernel facilities that must be initialized as part of system start.
3425cf1a30Sjl139090 * An example of such a facility is drv_usecwait(), which relies on a parameter
3525cf1a30Sjl139090 * that is initialized by the unix module. As a result, drv_usecwait() may not
3625cf1a30Sjl139090 * be used by KDI functions.
3725cf1a30Sjl139090 */
3825cf1a30Sjl139090
3925cf1a30Sjl139090 #include <sys/types.h>
4025cf1a30Sjl139090 #include <sys/systm.h>
4125cf1a30Sjl139090 #include <sys/archsystm.h>
4225cf1a30Sjl139090 #include <sys/machsystm.h>
4325cf1a30Sjl139090 #include <sys/cpu_module.h>
4425cf1a30Sjl139090 #include <sys/xc_impl.h>
4525cf1a30Sjl139090 #include <sys/intreg.h>
4625cf1a30Sjl139090 #include <sys/kdi_impl.h>
4725cf1a30Sjl139090
4825cf1a30Sjl139090 /*
4925cf1a30Sjl139090 * We keep our own copies, used for cache flushing, because we can be called
5025cf1a30Sjl139090 * before cpu_fiximpl().
5125cf1a30Sjl139090 */
5225cf1a30Sjl139090 static int kdi_dcache_size;
5325cf1a30Sjl139090 static int kdi_dcache_linesize;
5425cf1a30Sjl139090 static int kdi_icache_size;
5525cf1a30Sjl139090 static int kdi_icache_linesize;
5625cf1a30Sjl139090
5725cf1a30Sjl139090 /*
5825cf1a30Sjl139090 * Assembly support for SPARC64-VI modules in opl_olympus_asm.s
5925cf1a30Sjl139090 */
6025cf1a30Sjl139090 extern int idsr_busy(void);
6125cf1a30Sjl139090 extern void init_mondo_nocheck(xcfunc_t *func, uint64_t arg1, uint64_t arg2);
6225cf1a30Sjl139090 extern void shipit(int, int);
6325cf1a30Sjl139090 extern void kdi_flush_idcache(int, int, int, int);
6425cf1a30Sjl139090 extern int kdi_get_stick(uint64_t *);
6525cf1a30Sjl139090
66*8682d1efSRichard Lowe static void kdi_tickwait(clock_t);
67*8682d1efSRichard Lowe
6825cf1a30Sjl139090 static int
kdi_cpu_ready_iter(int (* cb)(int,void *),void * arg)6925cf1a30Sjl139090 kdi_cpu_ready_iter(int (*cb)(int, void *), void *arg)
7025cf1a30Sjl139090 {
7125cf1a30Sjl139090 int rc, i;
7225cf1a30Sjl139090
7325cf1a30Sjl139090 for (rc = 0, i = 0; i < NCPU; i++) {
7425cf1a30Sjl139090 if (CPU_IN_SET(cpu_ready_set, i))
7525cf1a30Sjl139090 rc += cb(i, arg);
7625cf1a30Sjl139090 }
7725cf1a30Sjl139090
7825cf1a30Sjl139090 return (rc);
7925cf1a30Sjl139090 }
8025cf1a30Sjl139090
8125cf1a30Sjl139090 /*
8225cf1a30Sjl139090 * Sends a cross-call to a specified processor. The caller assumes
8325cf1a30Sjl139090 * responsibility for repetition of cross-calls, as appropriate (MARSA for
8425cf1a30Sjl139090 * debugging).
8525cf1a30Sjl139090 */
8625cf1a30Sjl139090 static int
kdi_xc_one(int cpuid,void (* func)(uintptr_t,uintptr_t),uintptr_t arg1,uintptr_t arg2)8725cf1a30Sjl139090 kdi_xc_one(int cpuid, void (*func)(uintptr_t, uintptr_t), uintptr_t arg1,
8825cf1a30Sjl139090 uintptr_t arg2)
8925cf1a30Sjl139090 {
9025cf1a30Sjl139090 uint64_t idsr;
9125cf1a30Sjl139090 uint64_t endtick, tick;
9225cf1a30Sjl139090
9325cf1a30Sjl139090 init_mondo_nocheck((xcfunc_t *)func, arg1, arg2);
9425cf1a30Sjl139090
9525cf1a30Sjl139090 shipit(cpuid, 0);
9625cf1a30Sjl139090
9725cf1a30Sjl139090 /* Spin for at most 1 second for checking */
9825cf1a30Sjl139090 endtick = gettick() + (uint64_t)sys_tick_freq;
9925cf1a30Sjl139090
10025cf1a30Sjl139090 idsr = getidsr();
10125cf1a30Sjl139090
10225cf1a30Sjl139090 if (idsr & IDSR_BUSY) {
10325cf1a30Sjl139090 do {
10425cf1a30Sjl139090 idsr = getidsr();
10525cf1a30Sjl139090 tick = gettick();
10625cf1a30Sjl139090 if (tick > endtick) {
10725cf1a30Sjl139090 return (KDI_XC_RES_BUSY);
10825cf1a30Sjl139090 }
10925cf1a30Sjl139090 } while (idsr & IDSR_BUSY);
11025cf1a30Sjl139090 }
11125cf1a30Sjl139090
11225cf1a30Sjl139090 kdi_tickwait(20000);
11325cf1a30Sjl139090
11425cf1a30Sjl139090 if (idsr & IDSR_NACK)
11525cf1a30Sjl139090 return (KDI_XC_RES_NACK);
11625cf1a30Sjl139090 else
11725cf1a30Sjl139090 return (KDI_XC_RES_OK);
11825cf1a30Sjl139090 }
11925cf1a30Sjl139090
12025cf1a30Sjl139090 static void
kdi_tickwait(clock_t nticks)12125cf1a30Sjl139090 kdi_tickwait(clock_t nticks)
12225cf1a30Sjl139090 {
12325cf1a30Sjl139090 clock_t endtick = gettick() + nticks;
12425cf1a30Sjl139090
125*8682d1efSRichard Lowe while (gettick() < endtick)
126*8682d1efSRichard Lowe ;
12725cf1a30Sjl139090 }
12825cf1a30Sjl139090
12925cf1a30Sjl139090 static void
kdi_cpu_init(int dcache_size,int dcache_linesize,int icache_size,int icache_linesize)13025cf1a30Sjl139090 kdi_cpu_init(int dcache_size, int dcache_linesize, int icache_size,
13125cf1a30Sjl139090 int icache_linesize)
13225cf1a30Sjl139090 {
13325cf1a30Sjl139090 kdi_dcache_size = dcache_size;
13425cf1a30Sjl139090 kdi_dcache_linesize = dcache_linesize;
13525cf1a30Sjl139090 kdi_icache_size = icache_size;
13625cf1a30Sjl139090 kdi_icache_linesize = icache_linesize;
13725cf1a30Sjl139090 }
13825cf1a30Sjl139090
13925cf1a30Sjl139090 /* used directly by kdi_read/write_phys */
14025cf1a30Sjl139090 void
kdi_flush_caches(void)14125cf1a30Sjl139090 kdi_flush_caches(void)
14225cf1a30Sjl139090 {
14325cf1a30Sjl139090 kdi_flush_idcache(kdi_dcache_size, kdi_dcache_linesize,
14425cf1a30Sjl139090 kdi_icache_size, kdi_icache_linesize);
14525cf1a30Sjl139090 }
14625cf1a30Sjl139090
14725cf1a30Sjl139090 void
cpu_kdi_init(kdi_t * kdi)14825cf1a30Sjl139090 cpu_kdi_init(kdi_t *kdi)
14925cf1a30Sjl139090 {
15025cf1a30Sjl139090 kdi->kdi_flush_caches = kdi_flush_caches;
15125cf1a30Sjl139090 kdi->mkdi_cpu_init = kdi_cpu_init;
15225cf1a30Sjl139090 kdi->mkdi_cpu_ready_iter = kdi_cpu_ready_iter;
15325cf1a30Sjl139090 kdi->mkdi_xc_one = kdi_xc_one;
15425cf1a30Sjl139090 kdi->mkdi_tickwait = kdi_tickwait;
15525cf1a30Sjl139090 kdi->mkdi_get_stick = kdi_get_stick;
15625cf1a30Sjl139090 }
157