xref: /netbsd-src/sys/arch/or1k/include/cpu.h (revision bdc22b2e01993381dcefeff2bc9b56ca75a4235c)
1 /* $NetBSD: cpu.h,v 1.2 2018/04/19 21:50:07 christos Exp $ */
2 
3 /*-
4  * Copyright (c) 2014 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Matt Thomas of 3am Software Foundry.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #ifndef _OR1K_CPU_H_
33 #define _OR1K_CPU_H_
34 
35 #if defined(_KERNEL) || defined(_KMEMUSER)
36 struct clockframe {
37 	uintptr_t cf_pc;
38 	uint32_t cf_sr;
39 	int cf_intr_depth;
40 };
41 
42 #define CLKF_USERMODE(cf)	(((cf)->cf_sr & 1) == 0)
43 #define CLKF_PC(cf)		((cf)->cf_pc)
44 #define CLKF_INTR(cf)		((cf)->cf_intr_depth > 0)
45 
46 #include <sys/cpu_data.h>
47 #include <sys/device_if.h>
48 #include <sys/intr.h>
49 
50 struct cpu_info {
51 	struct cpu_data ci_data;
52 	device_t ci_dev;
53 	cpuid_t ci_cpuid;
54 	struct lwp *ci_curlwp;
55 	struct lwp *ci_softlwps[SOFTINT_COUNT];
56 
57 	uint64_t ci_lastintr;
58 
59 	int ci_mtx_oldspl;
60 	int ci_mtx_count;
61 
62 	int ci_want_resched;
63 	int ci_cpl;
64 	u_int ci_softints;
65 	volatile u_int ci_intr_depth;
66 };
67 
68 register struct lwp *or1k_curlwp __asm("r10");
69 #define	curlwp		or1k_curlwp
70 
71 static __inline struct cpu_info *
72 curcpu(void)
73 {
74 	return curlwp->l_cpu;
75 }
76 
77 static __inline cpuid_t
78 cpu_number(void)
79 {
80 #ifdef MULTIPROCESSOR
81 	return curcpu()->ci_cpuid;
82 #else
83 	return 0;
84 #endif
85 }
86 
87 void	cpu_set_curpri(int);
88 void	cpu_proc_fork(struct proc *, struct proc *);
89 void	cpu_signotify(struct lwp *);
90 void	cpu_need_proftick(struct lwp *l);
91 void	cpu_boot_secondary_processors(void);
92 
93 #define CPU_INFO_ITERATOR	cpuid_t
94 #ifdef MULTIPROCESSOR
95 #define CPU_INFO_FOREACH(cii, ci) \
96 	(cii) = 0; ((ci) = cpu_infos[cii]) != NULL; (cii)++
97 #else
98 #define CPU_INFO_FOREACH(cii, ci) \
99 	(cii) = 0; (cii) == 0 && (ci) = curcpu(); (cii)++
100 #endif
101 
102 static __inline void
103 cpu_dosoftints(void)
104 {
105 	extern void dosoftints(void);
106         struct cpu_info * const ci = curcpu();
107         if (ci->ci_intr_depth == 0
108 	    && (ci->ci_data.cpu_softints >> ci->ci_cpl) > 0)
109                 dosoftints();
110 }
111 
112 static __inline bool
113 cpu_intr_p(void)
114 {
115 	return curcpu()->ci_intr_depth > 0;
116 }
117 
118 #endif /* _KERNEL || _KMEMUSER */
119 
120 #endif /* _OR1K_CPU_H_ */
121