cpu.h revision 1.3
1/* $NetBSD: cpu.h,v 1.3 2019/11/21 19:24:01 ad 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)
36struct 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
50struct 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
68register struct lwp *or1k_curlwp __asm("r10");
69#define	curlwp		or1k_curlwp
70
71static __inline struct cpu_info *
72curcpu(void)
73{
74	return curlwp->l_cpu;
75}
76
77static __inline cpuid_t
78cpu_number(void)
79{
80#ifdef MULTIPROCESSOR
81	return curcpu()->ci_cpuid;
82#else
83	return 0;
84#endif
85}
86
87void	cpu_proc_fork(struct proc *, struct proc *);
88void	cpu_signotify(struct lwp *);
89void	cpu_need_proftick(struct lwp *l);
90void	cpu_boot_secondary_processors(void);
91
92#define CPU_INFO_ITERATOR	cpuid_t
93#ifdef MULTIPROCESSOR
94#define CPU_INFO_FOREACH(cii, ci) \
95	(cii) = 0; ((ci) = cpu_infos[cii]) != NULL; (cii)++
96#else
97#define CPU_INFO_FOREACH(cii, ci) \
98	(cii) = 0; (cii) == 0 && (ci) = curcpu(); (cii)++
99#endif
100
101static __inline void
102cpu_dosoftints(void)
103{
104	extern void dosoftints(void);
105        struct cpu_info * const ci = curcpu();
106        if (ci->ci_intr_depth == 0
107	    && (ci->ci_data.cpu_softints >> ci->ci_cpl) > 0)
108                dosoftints();
109}
110
111static __inline bool
112cpu_intr_p(void)
113{
114	return curcpu()->ci_intr_depth > 0;
115}
116
117#endif /* _KERNEL || _KMEMUSER */
118
119#endif /* _OR1K_CPU_H_ */
120