summaryrefslogtreecommitdiffstats
path: root/sys/arch/powerpc64/include/cpu.h
blob: 3b27dc0815a8e096d6331c8337455e696c0b0f0d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*	$OpenBSD: cpu.h,v 1.15 2020/06/22 13:52:40 kettenis Exp $	*/

/*
 * Copyright (c) 2020 Mark Kettenis <kettenis@openbsd.org>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#ifndef _MACHINE_CPU_H_
#define _MACHINE_CPU_H_

/*
 * User-visible definitions
 */

/* Nothing yet */

#ifdef _KERNEL

/*
 * Kernel-only definitions
 */

#include <machine/cpufunc.h>
#include <machine/frame.h>
#include <machine/intr.h>
#include <machine/psl.h>
#include <machine/pte.h>

#include <sys/device.h>
#include <sys/sched.h>

struct cpu_info {
	struct device	*ci_dev;
	struct cpu_info	*ci_next;
	struct schedstate_percpu ci_schedstate;

	struct proc	*ci_curproc;
	struct pcb	*ci_curpcb;

	struct slb	ci_kernel_slb[32];

#define CPUSAVE_LEN	9
	register_t	ci_tempsave[CPUSAVE_LEN];

	uint64_t	ci_lasttb;
	uint64_t	ci_nexttimerevent;
	uint64_t	ci_nextstatevent;
	int		ci_statspending;
	
	volatile int 	ci_cpl;
	uint32_t	ci_ipending;
	uint32_t	ci_idepth;
#ifdef DIAGNOSTIC
	int		ci_mutex_level;
#endif
	int		ci_want_resched;

	uint32_t	ci_randseed;
};

extern struct cpu_info cpu_info_primary;

register struct cpu_info *__curcpu asm("r13");
#define curcpu()	__curcpu

#define MAXCPUS			1
#define CPU_IS_PRIMARY(ci)	1
#define CPU_INFO_UNIT(ci)	0
#define CPU_INFO_ITERATOR	int
#define CPU_INFO_FOREACH(cii, ci) \
	for (cii = 0, ci = curcpu(); ci != NULL; ci = NULL)
#define cpu_number()		0

#define CLKF_INTR(frame)	0
#define CLKF_USERMODE(frame)	0
#define CLKF_PC(frame)		0

#define aston(p)		((p)->p_md.md_astpending = 1)
#define need_proftick(p)	aston(p)

#define cpu_kick(ci)
#define cpu_unidle(ci)
#define CPU_BUSY_CYCLE()	do {} while (0)
#define signotify(p)		setsoftast()

#define curpcb			curcpu()->ci_curpcb

static inline unsigned int
cpu_rnd_messybits(void)
{
	uint64_t tb;

	__asm volatile("mftb %0" : "=r" (tb));
	return ((tb > 32) ^ tb);
}

void need_resched(struct cpu_info *);
#define clear_resched(ci)	((ci)->ci_want_resched = 0)

void delay(u_int);
#define DELAY(x)	delay(x)

#define setsoftast()		aston(curcpu()->ci_curproc)

#define PROC_STACK(p)		((p)->p_md.md_regs->fixreg[1])
#define PROC_PC(p)		((p)->p_md.md_regs->srr0)

void	proc_trampoline(void);

static inline void
intr_enable(void)
{
	mtmsr(mfmsr() | PSL_EE);
}

static inline u_long
intr_disable(void)
{
	u_long msr;

	msr = mfmsr();
	mtmsr(msr & ~PSL_EE);
	return msr;
}

static inline void
intr_restore(u_long msr)
{
	mtmsr(msr);
}

#endif /* _KERNEL */

#endif /* _MACHINE_CPU_H_ */