Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
script3r
GitHub Repository: script3r/os161
Path: blob/master/kern/include/cpu.h
2093 views
1
/*
2
* Copyright (c) 2009
3
* The President and Fellows of Harvard College.
4
*
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions
7
* are met:
8
* 1. Redistributions of source code must retain the above copyright
9
* notice, this list of conditions and the following disclaimer.
10
* 2. Redistributions in binary form must reproduce the above copyright
11
* notice, this list of conditions and the following disclaimer in the
12
* documentation and/or other materials provided with the distribution.
13
* 3. Neither the name of the University nor the names of its contributors
14
* may be used to endorse or promote products derived from this software
15
* without specific prior written permission.
16
*
17
* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
18
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20
* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
21
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27
* SUCH DAMAGE.
28
*/
29
30
#ifndef _CPU_H_
31
#define _CPU_H_
32
33
34
#include <spinlock.h>
35
#include <threadlist.h>
36
#include <machine/vm.h> /* for TLBSHOOTDOWN_MAX */
37
38
39
/*
40
* Per-cpu structure
41
*
42
* Note: curcpu is defined by <current.h>.
43
*
44
* cpu->c_self should always be used when *using* the address of curcpu
45
* (as opposed to merely dereferencing it) in case curcpu is defined as
46
* a pointer with a fixed address and a per-cpu mapping in the MMU.
47
*/
48
49
struct cpu {
50
/*
51
* Fixed after allocation.
52
*/
53
struct cpu *c_self; /* Canonical address of this struct */
54
unsigned c_number; /* This cpu's cpu number */
55
unsigned c_hardware_number; /* Hardware-defined cpu number */
56
57
/*
58
* Accessed only by this cpu.
59
*/
60
struct thread *c_curthread; /* Current thread on cpu */
61
struct threadlist c_zombies; /* List of exited threads */
62
unsigned c_hardclocks; /* Counter of hardclock() calls */
63
64
/**
65
* ASST3 related
66
*/
67
struct addrspace *c_lastas; /* last as loaded inside the tlb of this cpu */
68
69
/*
70
* Accessed by other cpus.
71
* Protected by the runqueue lock.
72
*/
73
bool c_isidle; /* True if this cpu is idle */
74
struct threadlist c_runqueue; /* Run queue for this cpu */
75
struct spinlock c_runqueue_lock;
76
77
/*
78
* Accessed by other cpus.
79
* Protected by the IPI lock.
80
*
81
* If c_numshootdown is -1 (TLBSHOOTDOWN_ALL), all mappings
82
* should be invalidated. This is used if more than
83
* TLBSHOOTDOWN_MAX mappings are going to be invalidated at
84
* once. TLBSHOOTDOWN_MAX is MD and chosen based on when it
85
* becomes more efficient just to flush the whole TLB.
86
*
87
* struct tlbshootdown is machine-dependent and might
88
* reasonably be either an address space and vaddr pair, or a
89
* paddr, or something else.
90
*/
91
uint32_t c_ipi_pending; /* One bit for each IPI number */
92
struct tlbshootdown c_shootdown[TLBSHOOTDOWN_MAX];
93
int c_numshootdown;
94
struct spinlock c_ipi_lock;
95
};
96
97
#define TLBSHOOTDOWN_ALL (-1)
98
99
/*
100
* Initialization functions.
101
*
102
* cpu_create creates a cpu; it is suitable for calling from driver-
103
* or bus-specific code that looks for secondary CPUs.
104
*
105
* cpu_create calls cpu_machdep_init.
106
*
107
* cpu_start_secondary is the platform-dependent assembly language
108
* entry point for new CPUs; it can be found in start.S. It calls
109
* cpu_hatch after having claimed the startup stack and thread created
110
* for the cpu.
111
*/
112
struct cpu *cpu_create(unsigned hardware_number);
113
void cpu_machdep_init(struct cpu *);
114
/*ASMLINKAGE*/ void cpu_start_secondary(void);
115
void cpu_hatch(unsigned software_number);
116
117
/*
118
* Return a string describing the CPU type.
119
*/
120
const char *cpu_identify(void);
121
122
/*
123
* Hardware-level interrupt on/off, for the current CPU.
124
*
125
* These should only be used by the spl code.
126
*/
127
void cpu_irqoff(void);
128
void cpu_irqon(void);
129
130
/*
131
* Idle or shut down (respectively) the processor.
132
*
133
* cpu_idle() sits around (in a low-power state if possible) until it
134
* thinks something interesting may have happened, such as an
135
* interrupt. Then it returns. (It may be wrong, so it should always
136
* be called in a loop checking some other condition.) It must be
137
* called with interrupts off to avoid race conditions, although
138
* interrupts may be delivered before it returns.
139
*
140
* cpu_halt sits around (in a low-power state if possible) until the
141
* external reset is pushed. Interrupts should be disabled. It does
142
* not return. It should not allow interrupts to be delivered.
143
*/
144
void cpu_idle(void);
145
void cpu_halt(void);
146
147
/*
148
* Interprocessor interrupts.
149
*
150
* From time to time it is necessary to poke another CPU. System
151
* boards of multiprocessor machines provide a way to do this.
152
*
153
* TLB shootdown is done by the VM system when more than one processor
154
* has (or may have) a page mapped in the MMU and it is being changed
155
* or otherwise needs to be invalidated across all CPUs.
156
*
157
* ipi_send sends an IPI to one CPU.
158
* ipi_broadcast sends an IPI to all CPUs except the current one.
159
* ipi_tlbshootdown is like ipi_send but carries TLB shootdown data.
160
*
161
* interprocessor_interrupt is called on the target CPU when an IPI is
162
* received.
163
*/
164
165
/* IPI types */
166
#define IPI_PANIC 0 /* System has called panic() */
167
#define IPI_OFFLINE 1 /* CPU is requested to go offline */
168
#define IPI_UNIDLE 2 /* Runnable threads are available */
169
#define IPI_TLBSHOOTDOWN 3 /* MMU mapping(s) need invalidation */
170
171
void ipi_send(struct cpu *target, int code);
172
void ipi_broadcast(int code);
173
void ipi_tlbshootdown(struct cpu *target, const struct tlbshootdown *mapping);
174
void interprocessor_interrupt(void);
175
176
void ipi_tlbshootdown_by_num( unsigned, const struct tlbshootdown *);
177
#endif /* _CPU_H_ */
178
179