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 2004 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/spitregs.h>
48 #include <sys/xc_impl.h>
49 #include <sys/intreg.h>
50 #include <sys/kdi_impl.h>
51
52 /*
53 * We keep our own copies, used for cache flushing, because we can be called
54 * before cpu_fiximpl().
55 */
56 static int kdi_dcache_size;
57 static int kdi_dcache_linesize;
58 static int kdi_icache_size;
59 static int kdi_icache_linesize;
60
61 /*
62 * Assembly support for spitfire modules in spitfire_asm.s
63 */
64 extern int idsr_busy(void);
65 extern void init_mondo_nocheck(xcfunc_t *func, uint64_t arg1, uint64_t arg2);
66 extern void shipit(int);
67 extern void kdi_flush_idcache(int, int, int, int);
68
69 static int
kdi_cpu_ready_iter(int (* cb)(int,void *),void * arg)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
kdi_xc_one(int cpuid,void (* func)(uintptr_t,uintptr_t),uintptr_t arg1,uintptr_t arg2)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
93 /*
94 * if (idsr_busy())
95 * return (KDI_XC_RES_ERR);
96 */
97
98 init_mondo_nocheck((xcfunc_t *)func, arg1, arg2);
99
100 shipit(CPUID_TO_UPAID(cpuid));
101
102 if ((idsr = getidsr()) == 0)
103 return (KDI_XC_RES_OK);
104 else if (idsr & IDSR_BUSY)
105 return (KDI_XC_RES_BUSY);
106 else
107 return (KDI_XC_RES_NACK);
108 }
109
110 static void
kdi_tickwait(clock_t nticks)111 kdi_tickwait(clock_t nticks)
112 {
113 clock_t endtick = gettick() + nticks;
114
115 while (gettick() < endtick);
116 }
117
118 static void
kdi_cpu_init(int dcache_size,int dcache_linesize,int icache_size,int icache_linesize)119 kdi_cpu_init(int dcache_size, int dcache_linesize, int icache_size,
120 int icache_linesize)
121 {
122 kdi_dcache_size = dcache_size;
123 kdi_dcache_linesize = dcache_linesize;
124 kdi_icache_size = icache_size;
125 kdi_icache_linesize = icache_linesize;
126 }
127
128 /* used directly by kdi_read/write_phys */
129 void
kdi_flush_caches(void)130 kdi_flush_caches(void)
131 {
132 kdi_flush_idcache(kdi_dcache_size, kdi_dcache_linesize,
133 kdi_icache_size, kdi_icache_linesize);
134 }
135
136 /*ARGSUSED*/
137 int
kdi_get_stick(uint64_t * stickp)138 kdi_get_stick(uint64_t *stickp)
139 {
140 return (-1);
141 }
142
143 void
cpu_kdi_init(kdi_t * kdi)144 cpu_kdi_init(kdi_t *kdi)
145 {
146 kdi->kdi_flush_caches = kdi_flush_caches;
147 kdi->mkdi_cpu_init = kdi_cpu_init;
148 kdi->mkdi_cpu_ready_iter = kdi_cpu_ready_iter;
149 kdi->mkdi_xc_one = kdi_xc_one;
150 kdi->mkdi_tickwait = kdi_tickwait;
151 kdi->mkdi_get_stick = kdi_get_stick;
152 }
153