xref: /minix3/minix/kernel/proto.h (revision 0b98e8aad89f2bd4ba80b523d73cf29e9dd82ce1)
1 /* Function prototypes. */
2 
3 /* FIXME this is a hack how to avoid inclusion conflicts */
4 #ifdef __kernel__
5 
6 #ifndef PROTO_H
7 #define PROTO_H
8 
9 #include <minix/safecopies.h>
10 #include <machine/archtypes.h>
11 #include <machine/signal.h>
12 #include <machine/frame.h>
13 
14 /* Struct declarations. */
15 struct proc;
16 struct ipc_filter_s;
17 
18 /* clock.c */
19 clock_t get_realtime(void);
20 void set_realtime(clock_t);
21 void set_adjtime_delta(int32_t);
22 clock_t get_monotonic(void);
23 void set_kernel_timer(minix_timer_t *tp, clock_t t, tmr_func_t f);
24 void reset_kernel_timer(minix_timer_t *tp);
25 void ser_dump_proc(void);
26 
27 void cycles_accounting_init(void);
28 /*
29  * This functions start and stop accounting for process, kernel or idle cycles.
30  * It inherently have to account for some kernel cycles for process too,
31  * therefore it should be called asap after trapping to kernel and as late as
32  * possible before returning to userspace. These function is architecture
33  * dependent
34  */
35 void context_stop(struct proc * p);
36 /* this is a wrapper to make calling it from assembly easier */
37 void context_stop_idle(void);
38 int restore_fpu(struct proc *);
39 void save_fpu(struct proc *);
40 void save_local_fpu(struct proc *, int retain);
41 void fpu_sigcontext(struct proc *, struct sigframe_sigcontext *fr, struct
42 	sigcontext *sc);
43 
44 /* main.c */
45 #ifndef UNPAGED
46 #define kmain __k_unpaged_kmain
47 #endif
48 void kmain(kinfo_t *cbi);
49 void prepare_shutdown(int how);
50 __dead void minix_shutdown(minix_timer_t *tp);
51 void bsp_finish_booting(void);
52 
53 /* proc.c */
54 
55 int do_ipc(reg_t r1, reg_t r2, reg_t r3);
56 void proc_init(void);
57 int cancel_async(struct proc *src, struct proc *dst);
58 int has_pending_notify(struct proc * caller, int src_p);
59 int has_pending_asend(struct proc * caller, int src_p);
60 void unset_notify_pending(struct proc * caller, int src_p);
61 int mini_notify(const struct proc *src, endpoint_t dst);
62 void vm_suspend(struct proc *caller, const struct proc *target,
63         const vir_bytes linaddr, const vir_bytes len, const int type,
64         const int writeflag);
65 void enqueue(struct proc *rp);
66 void dequeue(struct proc *rp);
67 void switch_to_user(void);
68 void arch_proc_reset(struct proc *rp);
69 void arch_proc_setcontext(struct proc *rp, struct stackframe_s *state,
70 	int user, int restorestyle);
71 struct proc * arch_finish_switch_to_user(void);
72 struct proc *endpoint_lookup(endpoint_t ep);
73 #if DEBUG_ENABLE_IPC_WARNINGS
74 int isokendpt_f(const char *file, int line, endpoint_t e, int *p, int
75 	f);
76 #define isokendpt_d(e, p, f) isokendpt_f(__FILE__, __LINE__, (e), (p), (f))
77 #else
78 int isokendpt_f(endpoint_t e, int *p, int f);
79 #define isokendpt_d(e, p, f) isokendpt_f((e), (p), (f))
80 #endif
81 void proc_no_time(struct proc *p);
82 void reset_proc_accounting(struct proc *p);
83 void increase_proc_signals(struct proc *p);
84 void flag_account(struct proc *p, int flag);
85 int try_deliver_senda(struct proc *caller_ptr, asynmsg_t *table, size_t
86 	size);
87 
88 /* start.c */
89 void cstart();
90 char *env_get(const char *key);
91 
92 /* system.c */
93 int get_priv(register struct proc *rc, int proc_type);
94 void set_sendto_bit(const struct proc *rc, int id);
95 void unset_sendto_bit(const struct proc *rc, int id);
96 void fill_sendto_mask(const struct proc *rc, sys_map_t *map);
97 int send_sig(endpoint_t proc_nr, int sig_nr);
98 void cause_sig(proc_nr_t proc_nr, int sig_nr);
99 void sig_delay_done(struct proc *rp);
100 void send_diag_sig(void);
101 void kernel_call(message *m_user, struct proc * caller);
102 void system_init(void);
103 void clear_endpoint(struct proc *rc);
104 void clear_ipc_refs(struct proc *rc, int caller_ret);
105 void kernel_call_resume(struct proc *p);
106 int sched_proc(struct proc *rp, int priority, int quantum, int cpu);
107 int add_ipc_filter(struct proc *rp, int type,
108     vir_bytes address, size_t length);
109 void clear_ipc_filters(struct proc *rp);
110 int check_ipc_filter(struct ipc_filter_s *ipcf, int fill_flags);
111 int allow_ipc_filtered_msg(struct proc *rp, endpoint_t src_e,
112     vir_bytes m_src_v, message *m_src_p);
113 int allow_ipc_filtered_memreq(struct proc *src_rp, struct proc *dst_rp);
114 int priv_add_irq(struct proc *rp, int irq);
115 int priv_add_io(struct proc *rp, struct io_range *ior);
116 int priv_add_mem(struct proc *rp, struct minix_mem_range *memr);
117 
118 /* system/do_vtimer.c */
119 void vtimer_check(struct proc *rp);
120 
121 /* interrupt.c */
122 void put_irq_handler(irq_hook_t *hook, int irq, irq_handler_t handler);
123 void rm_irq_handler(const irq_hook_t *hook);
124 void enable_irq(const irq_hook_t *hook);
125 int disable_irq(const irq_hook_t *hook);
126 
127 void interrupts_enable(void);
128 void interrupts_disable(void);
129 
130 /* debug.c */
131 int runqueues_ok(void);
132 #ifndef CONFIG_SMP
133 #define runqueues_ok_local runqueues_ok
134 #else
135 #define runqueues_ok_local() runqueues_ok_cpu(cpuid)
136 int runqueues_ok_cpu(unsigned cpu);
137 #endif
138 char *rtsflagstr(u32_t flags);
139 char *miscflagstr(u32_t flags);
140 char *schedulerstr(struct proc *scheduler);
141 /* prints process information */
142 void print_proc(struct proc *pp);
143 /* prints the given process and recursively all processes it depends on */
144 void print_proc_recursive(struct proc *pp);
145 void printmsg(message *msg, struct proc *src, struct proc *dst,
146     char operation, int printparams);
147 #if DEBUG_IPC_HOOK
148 void hook_ipc_msgrecv(message *msg, struct proc *src, struct proc *dst);
149 void hook_ipc_msgsend(message *msg, struct proc *src, struct proc *dst);
150 void hook_ipc_msgkcall(message *msg, struct proc *proc);
151 void hook_ipc_msgkresult(message *msg, struct proc *proc);
152 void hook_ipc_clear(struct proc *proc);
153 #endif
154 
155 /* system/do_safecopy.c */
156 int verify_grant(endpoint_t, endpoint_t, cp_grant_id_t, vir_bytes, int,
157 	vir_bytes, vir_bytes *, endpoint_t *, u32_t *);
158 
159 /* system/do_diagctl.c */
160 int do_diagctl(struct proc * caller, message *m);
161 
162 #if SPROFILE
163 /* profile.c */
164 void init_profile_clock(u32_t);
165 void stop_profile_clock(void);
166 #endif
167 
168 /* functions defined in architecture-dependent files. */
169 void prot_init();
170 void arch_post_init();
171 void arch_set_secondary_ipc_return(struct proc *, u32_t val);
172 phys_bytes phys_copy(phys_bytes source, phys_bytes dest, phys_bytes
173 	count);
174 void phys_copy_fault(void);
175 void phys_copy_fault_in_kernel(void);
176 void memset_fault(void);
177 void memset_fault_in_kernel(void);
178 #define virtual_copy(src, dst, bytes) \
179 				virtual_copy_f(NULL, src, dst, bytes, 0)
180 #define virtual_copy_vmcheck(caller, src, dst, bytes) \
181 				virtual_copy_f(caller, src, dst, bytes, 1)
182 int virtual_copy_f(struct proc * caller, struct vir_addr *src, struct
183 	vir_addr *dst, vir_bytes bytes, int vmcheck);
184 int data_copy(endpoint_t from, vir_bytes from_addr, endpoint_t to,
185 	vir_bytes to_addr, size_t bytes);
186 int data_copy_vmcheck(struct proc *, endpoint_t from, vir_bytes
187 	from_addr, endpoint_t to, vir_bytes to_addr, size_t bytes);
188 phys_bytes umap_virtual(struct proc* rp, int seg, vir_bytes vir_addr,
189 	vir_bytes bytes);
190 phys_bytes seg2phys(u16_t);
191 int vm_memset(struct proc *caller, endpoint_t who, phys_bytes dst,
192 	int pattern, phys_bytes count);
193 int intr_init(int);
194 void halt_cpu(void);
195 void arch_init(void);
196 void arch_boot_proc(struct boot_image *b, struct proc *p);
197 void cpu_identify(void);
198 /* arch dependent FPU initialization per CPU */
199 void fpu_init(void);
200 /* returns true if pfu is present and initialized */
201 int is_fpu(void);
202 void ser_putc(char);
203 __dead void arch_shutdown(int);
204 void restore_user_context(struct proc * p);
205 void read_tsc(u32_t *high, u32_t *low);
206 int arch_init_profile_clock(u32_t freq);
207 void arch_stop_profile_clock(void);
208 void arch_ack_profile_clock(void);
209 void do_ser_debug(void);
210 int arch_get_params(char *parm, int max);
211 void memory_init(void);
212 void mem_clear_mapcache(void);
213 void arch_proc_init(struct proc *pr, u32_t, u32_t, u32_t, char *);
214 int arch_do_vmctl(message *m_ptr, struct proc *p);
215 int vm_contiguous(const struct proc *targetproc, vir_bytes vir_buf,
216 	size_t count);
217 void proc_stacktrace(struct proc *proc);
218 int vm_lookup(const struct proc *proc, vir_bytes virtual, phys_bytes
219 	*result, u32_t *ptent);
220 size_t vm_lookup_range(const struct proc *proc,
221        vir_bytes vir_addr, phys_bytes *phys_addr, size_t bytes);
222 void arch_do_syscall(struct proc *proc);
223 int arch_phys_map(int index, phys_bytes *addr, phys_bytes *len, int
224 	*flags);
225 int arch_phys_map_reply(int index, vir_bytes addr);
226 reg_t arch_get_sp(struct proc *p);
227 int arch_enable_paging(struct proc * caller);
228 int vm_check_range(struct proc *caller,
229        struct proc *target, vir_bytes vir_addr, size_t bytes, int writable);
230 
231 int copy_msg_from_user(message * user_mbuf, message * dst);
232 int copy_msg_to_user(message * src, message * user_mbuf);
233 void switch_address_space(struct proc * p);
234 void release_address_space(struct proc *pr);
235 
236 void enable_fpu_exception(void);
237 void disable_fpu_exception(void);
238 void release_fpu(struct proc * p);
239 void arch_pause(void);
240 short cpu_load(void);
241 void busy_delay_ms(int ms);
242 
243 /* utility.c */
244 void cpu_print_freq(unsigned cpu);
245 #endif /* __kernel__ */
246 
247 #endif /* PROTO_H */
248