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