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 2005 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/xc_impl.h>
48*7c478bd9Sstevel@tonic-gate #include <sys/intreg.h>
49*7c478bd9Sstevel@tonic-gate #include <sys/kdi_impl.h>
50*7c478bd9Sstevel@tonic-gate
51*7c478bd9Sstevel@tonic-gate /*
52*7c478bd9Sstevel@tonic-gate * We keep our own copies, used for cache flushing, because we can be called
53*7c478bd9Sstevel@tonic-gate * before cpu_fiximpl().
54*7c478bd9Sstevel@tonic-gate */
55*7c478bd9Sstevel@tonic-gate static int kdi_dcache_size;
56*7c478bd9Sstevel@tonic-gate static int kdi_dcache_linesize;
57*7c478bd9Sstevel@tonic-gate static int kdi_icache_size;
58*7c478bd9Sstevel@tonic-gate static int kdi_icache_linesize;
59*7c478bd9Sstevel@tonic-gate
60*7c478bd9Sstevel@tonic-gate /*
61*7c478bd9Sstevel@tonic-gate * Assembly support for cheetah modules in cheetah_asm.s
62*7c478bd9Sstevel@tonic-gate */
63*7c478bd9Sstevel@tonic-gate extern int idsr_busy(void);
64*7c478bd9Sstevel@tonic-gate extern void init_mondo_nocheck(xcfunc_t *func, uint64_t arg1, uint64_t arg2);
65*7c478bd9Sstevel@tonic-gate extern void shipit(int, int);
66*7c478bd9Sstevel@tonic-gate extern void kdi_flush_idcache(int, int, int, int);
67*7c478bd9Sstevel@tonic-gate extern int kdi_get_stick(uint64_t *);
68*7c478bd9Sstevel@tonic-gate
69*7c478bd9Sstevel@tonic-gate static int
kdi_cpu_ready_iter(int (* cb)(int,void *),void * arg)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
kdi_xc_one(int cpuid,void (* func)(uintptr_t,uintptr_t),uintptr_t arg1,uintptr_t arg2)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 uint64_t busymask;
93*7c478bd9Sstevel@tonic-gate
94*7c478bd9Sstevel@tonic-gate /*
95*7c478bd9Sstevel@tonic-gate * if (idsr_busy())
96*7c478bd9Sstevel@tonic-gate * return (KDI_XC_RES_ERR);
97*7c478bd9Sstevel@tonic-gate */
98*7c478bd9Sstevel@tonic-gate
99*7c478bd9Sstevel@tonic-gate init_mondo_nocheck((xcfunc_t *)func, arg1, arg2);
100*7c478bd9Sstevel@tonic-gate
101*7c478bd9Sstevel@tonic-gate shipit(cpuid, 0);
102*7c478bd9Sstevel@tonic-gate
103*7c478bd9Sstevel@tonic-gate #if defined(JALAPENO) || defined(SERRANO)
104*7c478bd9Sstevel@tonic-gate /*
105*7c478bd9Sstevel@tonic-gate * Lower 2 bits of the agent ID determine which BUSY/NACK pair
106*7c478bd9Sstevel@tonic-gate * will be used for dispatching interrupt. For now, assume
107*7c478bd9Sstevel@tonic-gate * there are no more than IDSR_BN_SETS CPUs, hence no aliasing
108*7c478bd9Sstevel@tonic-gate * issues with respect to BUSY/NACK pair usage.
109*7c478bd9Sstevel@tonic-gate */
110*7c478bd9Sstevel@tonic-gate busymask = IDSR_BUSY_BIT(cpuid);
111*7c478bd9Sstevel@tonic-gate #else /* JALAPENO || SERRANO */
112*7c478bd9Sstevel@tonic-gate busymask = IDSR_BUSY;
113*7c478bd9Sstevel@tonic-gate #endif /* JALAPENO || SERRANO */
114*7c478bd9Sstevel@tonic-gate
115*7c478bd9Sstevel@tonic-gate if ((idsr = getidsr()) == 0)
116*7c478bd9Sstevel@tonic-gate return (KDI_XC_RES_OK);
117*7c478bd9Sstevel@tonic-gate else if (idsr & busymask)
118*7c478bd9Sstevel@tonic-gate return (KDI_XC_RES_BUSY);
119*7c478bd9Sstevel@tonic-gate else
120*7c478bd9Sstevel@tonic-gate return (KDI_XC_RES_NACK);
121*7c478bd9Sstevel@tonic-gate }
122*7c478bd9Sstevel@tonic-gate
123*7c478bd9Sstevel@tonic-gate static void
kdi_tickwait(clock_t nticks)124*7c478bd9Sstevel@tonic-gate kdi_tickwait(clock_t nticks)
125*7c478bd9Sstevel@tonic-gate {
126*7c478bd9Sstevel@tonic-gate clock_t endtick = gettick() + nticks;
127*7c478bd9Sstevel@tonic-gate
128*7c478bd9Sstevel@tonic-gate while (gettick() < endtick);
129*7c478bd9Sstevel@tonic-gate }
130*7c478bd9Sstevel@tonic-gate
131*7c478bd9Sstevel@tonic-gate static void
kdi_cpu_init(int dcache_size,int dcache_linesize,int icache_size,int icache_linesize)132*7c478bd9Sstevel@tonic-gate kdi_cpu_init(int dcache_size, int dcache_linesize, int icache_size,
133*7c478bd9Sstevel@tonic-gate int icache_linesize)
134*7c478bd9Sstevel@tonic-gate {
135*7c478bd9Sstevel@tonic-gate kdi_dcache_size = dcache_size;
136*7c478bd9Sstevel@tonic-gate kdi_dcache_linesize = dcache_linesize;
137*7c478bd9Sstevel@tonic-gate kdi_icache_size = icache_size;
138*7c478bd9Sstevel@tonic-gate kdi_icache_linesize = icache_linesize;
139*7c478bd9Sstevel@tonic-gate }
140*7c478bd9Sstevel@tonic-gate
141*7c478bd9Sstevel@tonic-gate /* used directly by kdi_read/write_phys */
142*7c478bd9Sstevel@tonic-gate void
kdi_flush_caches(void)143*7c478bd9Sstevel@tonic-gate kdi_flush_caches(void)
144*7c478bd9Sstevel@tonic-gate {
145*7c478bd9Sstevel@tonic-gate kdi_flush_idcache(kdi_dcache_size, kdi_dcache_linesize,
146*7c478bd9Sstevel@tonic-gate kdi_icache_size, kdi_icache_linesize);
147*7c478bd9Sstevel@tonic-gate }
148*7c478bd9Sstevel@tonic-gate
149*7c478bd9Sstevel@tonic-gate void
cpu_kdi_init(kdi_t * kdi)150*7c478bd9Sstevel@tonic-gate cpu_kdi_init(kdi_t *kdi)
151*7c478bd9Sstevel@tonic-gate {
152*7c478bd9Sstevel@tonic-gate kdi->kdi_flush_caches = kdi_flush_caches;
153*7c478bd9Sstevel@tonic-gate kdi->mkdi_cpu_init = kdi_cpu_init;
154*7c478bd9Sstevel@tonic-gate kdi->mkdi_cpu_ready_iter = kdi_cpu_ready_iter;
155*7c478bd9Sstevel@tonic-gate kdi->mkdi_xc_one = kdi_xc_one;
156*7c478bd9Sstevel@tonic-gate kdi->mkdi_tickwait = kdi_tickwait;
157*7c478bd9Sstevel@tonic-gate kdi->mkdi_get_stick = kdi_get_stick;
158*7c478bd9Sstevel@tonic-gate }
159