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