xref: /minix3/minix/kernel/proto.h (revision cfd712b4245f67a5631cc14e950ce43b18455602)
1433d6423SLionel Sambuc /* Function prototypes. */
2433d6423SLionel Sambuc 
3433d6423SLionel Sambuc /* FIXME this is a hack how to avoid inclusion conflicts */
4433d6423SLionel Sambuc #ifdef __kernel__
5433d6423SLionel Sambuc 
6433d6423SLionel Sambuc #ifndef PROTO_H
7433d6423SLionel Sambuc #define PROTO_H
8433d6423SLionel Sambuc 
9433d6423SLionel Sambuc #include <minix/safecopies.h>
10433d6423SLionel Sambuc #include <machine/archtypes.h>
11433d6423SLionel Sambuc #include <machine/signal.h>
12433d6423SLionel Sambuc #include <machine/frame.h>
13433d6423SLionel Sambuc 
14433d6423SLionel Sambuc /* Struct declarations. */
15433d6423SLionel Sambuc struct proc;
16c8a9900bSCristiano Giuffrida struct ipc_filter_s;
17433d6423SLionel Sambuc 
18433d6423SLionel Sambuc /* clock.c */
19d91f738bSDavid van Moolenbroek void init_clock(void);
20433d6423SLionel Sambuc clock_t get_realtime(void);
21433d6423SLionel Sambuc void set_realtime(clock_t);
22433d6423SLionel Sambuc void set_adjtime_delta(int32_t);
23433d6423SLionel Sambuc clock_t get_monotonic(void);
24d91f738bSDavid van Moolenbroek void set_boottime(time_t);
25d91f738bSDavid van Moolenbroek time_t get_boottime(void);
26*cfd712b4SDavid van Moolenbroek void set_kernel_timer(minix_timer_t *tp, clock_t t, tmr_func_t f, int arg);
27433d6423SLionel Sambuc void reset_kernel_timer(minix_timer_t *tp);
28433d6423SLionel Sambuc void ser_dump_proc(void);
29433d6423SLionel Sambuc 
30433d6423SLionel Sambuc void cycles_accounting_init(void);
31433d6423SLionel Sambuc /*
32433d6423SLionel Sambuc  * This functions start and stop accounting for process, kernel or idle cycles.
33433d6423SLionel Sambuc  * It inherently have to account for some kernel cycles for process too,
34433d6423SLionel Sambuc  * therefore it should be called asap after trapping to kernel and as late as
35433d6423SLionel Sambuc  * possible before returning to userspace. These function is architecture
36433d6423SLionel Sambuc  * dependent
37433d6423SLionel Sambuc  */
38433d6423SLionel Sambuc void context_stop(struct proc * p);
39433d6423SLionel Sambuc /* this is a wrapper to make calling it from assembly easier */
40433d6423SLionel Sambuc void context_stop_idle(void);
41366d18b2SDavid van Moolenbroek void get_cpu_ticks(unsigned int cpu, uint64_t ticks[MINIX_CPUSTATES]);
42433d6423SLionel Sambuc int restore_fpu(struct proc *);
43433d6423SLionel Sambuc void save_fpu(struct proc *);
44433d6423SLionel Sambuc void save_local_fpu(struct proc *, int retain);
45433d6423SLionel Sambuc void fpu_sigcontext(struct proc *, struct sigframe_sigcontext *fr, struct
46433d6423SLionel Sambuc 	sigcontext *sc);
47433d6423SLionel Sambuc 
48433d6423SLionel Sambuc /* main.c */
49433d6423SLionel Sambuc #ifndef UNPAGED
50433d6423SLionel Sambuc #define kmain __k_unpaged_kmain
51433d6423SLionel Sambuc #endif
52433d6423SLionel Sambuc void kmain(kinfo_t *cbi);
53433d6423SLionel Sambuc void prepare_shutdown(int how);
54*cfd712b4SDavid van Moolenbroek __dead void minix_shutdown(int how);
55433d6423SLionel Sambuc void bsp_finish_booting(void);
56433d6423SLionel Sambuc 
57433d6423SLionel Sambuc /* proc.c */
58433d6423SLionel Sambuc 
59433d6423SLionel Sambuc int do_ipc(reg_t r1, reg_t r2, reg_t r3);
60433d6423SLionel Sambuc void proc_init(void);
61433d6423SLionel Sambuc int cancel_async(struct proc *src, struct proc *dst);
62433d6423SLionel Sambuc int has_pending_notify(struct proc * caller, int src_p);
63433d6423SLionel Sambuc int has_pending_asend(struct proc * caller, int src_p);
64433d6423SLionel Sambuc void unset_notify_pending(struct proc * caller, int src_p);
65433d6423SLionel Sambuc int mini_notify(const struct proc *src, endpoint_t dst);
668bab0dfaSBen Gras void vm_suspend(struct proc *caller, const struct proc *target,
678bab0dfaSBen Gras         const vir_bytes linaddr, const vir_bytes len, const int type,
688bab0dfaSBen Gras         const int writeflag);
69433d6423SLionel Sambuc void enqueue(struct proc *rp);
70433d6423SLionel Sambuc void dequeue(struct proc *rp);
71433d6423SLionel Sambuc void switch_to_user(void);
72433d6423SLionel Sambuc void arch_proc_reset(struct proc *rp);
73433d6423SLionel Sambuc void arch_proc_setcontext(struct proc *rp, struct stackframe_s *state,
74433d6423SLionel Sambuc 	int user, int restorestyle);
75433d6423SLionel Sambuc struct proc * arch_finish_switch_to_user(void);
76433d6423SLionel Sambuc struct proc *endpoint_lookup(endpoint_t ep);
77433d6423SLionel Sambuc #if DEBUG_ENABLE_IPC_WARNINGS
78433d6423SLionel Sambuc int isokendpt_f(const char *file, int line, endpoint_t e, int *p, int
79433d6423SLionel Sambuc 	f);
80433d6423SLionel Sambuc #define isokendpt_d(e, p, f) isokendpt_f(__FILE__, __LINE__, (e), (p), (f))
81433d6423SLionel Sambuc #else
82433d6423SLionel Sambuc int isokendpt_f(endpoint_t e, int *p, int f);
83433d6423SLionel Sambuc #define isokendpt_d(e, p, f) isokendpt_f((e), (p), (f))
84433d6423SLionel Sambuc #endif
85433d6423SLionel Sambuc void proc_no_time(struct proc *p);
86433d6423SLionel Sambuc void reset_proc_accounting(struct proc *p);
87433d6423SLionel Sambuc void flag_account(struct proc *p, int flag);
88433d6423SLionel Sambuc int try_deliver_senda(struct proc *caller_ptr, asynmsg_t *table, size_t
89433d6423SLionel Sambuc 	size);
90433d6423SLionel Sambuc 
91433d6423SLionel Sambuc /* start.c */
926077d1adSDr. Florian Grätz void cstart(void);
93433d6423SLionel Sambuc char *env_get(const char *key);
94433d6423SLionel Sambuc 
95433d6423SLionel Sambuc /* system.c */
96433d6423SLionel Sambuc int get_priv(register struct proc *rc, int proc_type);
97433d6423SLionel Sambuc void set_sendto_bit(const struct proc *rc, int id);
98433d6423SLionel Sambuc void unset_sendto_bit(const struct proc *rc, int id);
99433d6423SLionel Sambuc void fill_sendto_mask(const struct proc *rc, sys_map_t *map);
100433d6423SLionel Sambuc int send_sig(endpoint_t proc_nr, int sig_nr);
101433d6423SLionel Sambuc void cause_sig(proc_nr_t proc_nr, int sig_nr);
102433d6423SLionel Sambuc void sig_delay_done(struct proc *rp);
103433d6423SLionel Sambuc void send_diag_sig(void);
104433d6423SLionel Sambuc void kernel_call(message *m_user, struct proc * caller);
105433d6423SLionel Sambuc void system_init(void);
106433d6423SLionel Sambuc void clear_endpoint(struct proc *rc);
107433d6423SLionel Sambuc void clear_ipc_refs(struct proc *rc, int caller_ret);
108433d6423SLionel Sambuc void kernel_call_resume(struct proc *p);
109366d18b2SDavid van Moolenbroek int sched_proc(struct proc *rp, int priority, int quantum, int cpu, int niced);
110c8a9900bSCristiano Giuffrida int add_ipc_filter(struct proc *rp, int type,
111c8a9900bSCristiano Giuffrida     vir_bytes address, size_t length);
112c8a9900bSCristiano Giuffrida void clear_ipc_filters(struct proc *rp);
113c8a9900bSCristiano Giuffrida int check_ipc_filter(struct ipc_filter_s *ipcf, int fill_flags);
114c8a9900bSCristiano Giuffrida int allow_ipc_filtered_msg(struct proc *rp, endpoint_t src_e,
115c8a9900bSCristiano Giuffrida     vir_bytes m_src_v, message *m_src_p);
1163779ed93SDavid van Moolenbroek int allow_ipc_filtered_memreq(struct proc *src_rp, struct proc *dst_rp);
11756e56d2aSCristiano Giuffrida int priv_add_irq(struct proc *rp, int irq);
11856e56d2aSCristiano Giuffrida int priv_add_io(struct proc *rp, struct io_range *ior);
11956e56d2aSCristiano Giuffrida int priv_add_mem(struct proc *rp, struct minix_mem_range *memr);
120433d6423SLionel Sambuc 
121433d6423SLionel Sambuc /* system/do_vtimer.c */
122433d6423SLionel Sambuc void vtimer_check(struct proc *rp);
123433d6423SLionel Sambuc 
124433d6423SLionel Sambuc /* interrupt.c */
125433d6423SLionel Sambuc void put_irq_handler(irq_hook_t *hook, int irq, irq_handler_t handler);
126433d6423SLionel Sambuc void rm_irq_handler(const irq_hook_t *hook);
127433d6423SLionel Sambuc void enable_irq(const irq_hook_t *hook);
128433d6423SLionel Sambuc int disable_irq(const irq_hook_t *hook);
129433d6423SLionel Sambuc 
130433d6423SLionel Sambuc void interrupts_enable(void);
131433d6423SLionel Sambuc void interrupts_disable(void);
132433d6423SLionel Sambuc 
133433d6423SLionel Sambuc /* debug.c */
134433d6423SLionel Sambuc int runqueues_ok(void);
135433d6423SLionel Sambuc #ifndef CONFIG_SMP
136433d6423SLionel Sambuc #define runqueues_ok_local runqueues_ok
137433d6423SLionel Sambuc #else
138433d6423SLionel Sambuc #define runqueues_ok_local() runqueues_ok_cpu(cpuid)
139433d6423SLionel Sambuc int runqueues_ok_cpu(unsigned cpu);
140433d6423SLionel Sambuc #endif
141433d6423SLionel Sambuc char *rtsflagstr(u32_t flags);
142433d6423SLionel Sambuc char *miscflagstr(u32_t flags);
143433d6423SLionel Sambuc char *schedulerstr(struct proc *scheduler);
144433d6423SLionel Sambuc /* prints process information */
145433d6423SLionel Sambuc void print_proc(struct proc *pp);
146433d6423SLionel Sambuc /* prints the given process and recursively all processes it depends on */
147433d6423SLionel Sambuc void print_proc_recursive(struct proc *pp);
148c8a9900bSCristiano Giuffrida void printmsg(message *msg, struct proc *src, struct proc *dst,
149c8a9900bSCristiano Giuffrida     char operation, int printparams);
150433d6423SLionel Sambuc #if DEBUG_IPC_HOOK
151433d6423SLionel Sambuc void hook_ipc_msgrecv(message *msg, struct proc *src, struct proc *dst);
152433d6423SLionel Sambuc void hook_ipc_msgsend(message *msg, struct proc *src, struct proc *dst);
153433d6423SLionel Sambuc void hook_ipc_msgkcall(message *msg, struct proc *proc);
154433d6423SLionel Sambuc void hook_ipc_msgkresult(message *msg, struct proc *proc);
155433d6423SLionel Sambuc void hook_ipc_clear(struct proc *proc);
156433d6423SLionel Sambuc #endif
157433d6423SLionel Sambuc 
158433d6423SLionel Sambuc /* system/do_safecopy.c */
15910b7016bSDavid van Moolenbroek struct cp_sfinfo; /* external callers may only provide NULL */
160433d6423SLionel Sambuc int verify_grant(endpoint_t, endpoint_t, cp_grant_id_t, vir_bytes, int,
16110b7016bSDavid van Moolenbroek 	vir_bytes, vir_bytes *, endpoint_t *, struct cp_sfinfo *);
162433d6423SLionel Sambuc 
163433d6423SLionel Sambuc /* system/do_diagctl.c */
164433d6423SLionel Sambuc int do_diagctl(struct proc * caller, message *m);
165433d6423SLionel Sambuc 
166433d6423SLionel Sambuc #if SPROFILE
167433d6423SLionel Sambuc /* profile.c */
168433d6423SLionel Sambuc void init_profile_clock(u32_t);
169433d6423SLionel Sambuc void stop_profile_clock(void);
170433d6423SLionel Sambuc #endif
171433d6423SLionel Sambuc 
172433d6423SLionel Sambuc /* functions defined in architecture-dependent files. */
1736077d1adSDr. Florian Grätz void prot_init(void);
1746077d1adSDr. Florian Grätz void arch_post_init(void);
175433d6423SLionel Sambuc void arch_set_secondary_ipc_return(struct proc *, u32_t val);
176433d6423SLionel Sambuc phys_bytes phys_copy(phys_bytes source, phys_bytes dest, phys_bytes
177433d6423SLionel Sambuc 	count);
178433d6423SLionel Sambuc void phys_copy_fault(void);
179433d6423SLionel Sambuc void phys_copy_fault_in_kernel(void);
180433d6423SLionel Sambuc void memset_fault(void);
181433d6423SLionel Sambuc void memset_fault_in_kernel(void);
182433d6423SLionel Sambuc #define virtual_copy(src, dst, bytes) \
183433d6423SLionel Sambuc 				virtual_copy_f(NULL, src, dst, bytes, 0)
184433d6423SLionel Sambuc #define virtual_copy_vmcheck(caller, src, dst, bytes) \
185433d6423SLionel Sambuc 				virtual_copy_f(caller, src, dst, bytes, 1)
186433d6423SLionel Sambuc int virtual_copy_f(struct proc * caller, struct vir_addr *src, struct
187433d6423SLionel Sambuc 	vir_addr *dst, vir_bytes bytes, int vmcheck);
188433d6423SLionel Sambuc int data_copy(endpoint_t from, vir_bytes from_addr, endpoint_t to,
189433d6423SLionel Sambuc 	vir_bytes to_addr, size_t bytes);
190433d6423SLionel Sambuc int data_copy_vmcheck(struct proc *, endpoint_t from, vir_bytes
191433d6423SLionel Sambuc 	from_addr, endpoint_t to, vir_bytes to_addr, size_t bytes);
192433d6423SLionel Sambuc phys_bytes umap_virtual(struct proc* rp, int seg, vir_bytes vir_addr,
193433d6423SLionel Sambuc 	vir_bytes bytes);
194433d6423SLionel Sambuc phys_bytes seg2phys(u16_t);
195433d6423SLionel Sambuc int vm_memset(struct proc *caller, endpoint_t who, phys_bytes dst,
196433d6423SLionel Sambuc 	int pattern, phys_bytes count);
197433d6423SLionel Sambuc int intr_init(int);
198433d6423SLionel Sambuc void halt_cpu(void);
199433d6423SLionel Sambuc void arch_init(void);
200433d6423SLionel Sambuc void arch_boot_proc(struct boot_image *b, struct proc *p);
201433d6423SLionel Sambuc void cpu_identify(void);
202433d6423SLionel Sambuc /* arch dependent FPU initialization per CPU */
203433d6423SLionel Sambuc void fpu_init(void);
204433d6423SLionel Sambuc /* returns true if pfu is present and initialized */
205433d6423SLionel Sambuc int is_fpu(void);
206433d6423SLionel Sambuc void ser_putc(char);
207433d6423SLionel Sambuc __dead void arch_shutdown(int);
208433d6423SLionel Sambuc void restore_user_context(struct proc * p);
209433d6423SLionel Sambuc void read_tsc(u32_t *high, u32_t *low);
210433d6423SLionel Sambuc int arch_init_profile_clock(u32_t freq);
211433d6423SLionel Sambuc void arch_stop_profile_clock(void);
212433d6423SLionel Sambuc void arch_ack_profile_clock(void);
213433d6423SLionel Sambuc void do_ser_debug(void);
214433d6423SLionel Sambuc int arch_get_params(char *parm, int max);
215433d6423SLionel Sambuc void memory_init(void);
216433d6423SLionel Sambuc void mem_clear_mapcache(void);
217433d6423SLionel Sambuc void arch_proc_init(struct proc *pr, u32_t, u32_t, u32_t, char *);
218433d6423SLionel Sambuc int arch_do_vmctl(message *m_ptr, struct proc *p);
219433d6423SLionel Sambuc int vm_contiguous(const struct proc *targetproc, vir_bytes vir_buf,
220433d6423SLionel Sambuc 	size_t count);
221433d6423SLionel Sambuc void proc_stacktrace(struct proc *proc);
222433d6423SLionel Sambuc int vm_lookup(const struct proc *proc, vir_bytes virtual, phys_bytes
223433d6423SLionel Sambuc 	*result, u32_t *ptent);
224433d6423SLionel Sambuc size_t vm_lookup_range(const struct proc *proc,
225433d6423SLionel Sambuc        vir_bytes vir_addr, phys_bytes *phys_addr, size_t bytes);
226433d6423SLionel Sambuc void arch_do_syscall(struct proc *proc);
227433d6423SLionel Sambuc int arch_phys_map(int index, phys_bytes *addr, phys_bytes *len, int
228433d6423SLionel Sambuc 	*flags);
229433d6423SLionel Sambuc int arch_phys_map_reply(int index, vir_bytes addr);
230433d6423SLionel Sambuc reg_t arch_get_sp(struct proc *p);
231433d6423SLionel Sambuc int arch_enable_paging(struct proc * caller);
232433d6423SLionel Sambuc int vm_check_range(struct proc *caller,
233433d6423SLionel Sambuc        struct proc *target, vir_bytes vir_addr, size_t bytes, int writable);
234433d6423SLionel Sambuc 
235433d6423SLionel Sambuc int copy_msg_from_user(message * user_mbuf, message * dst);
236433d6423SLionel Sambuc int copy_msg_to_user(message * src, message * user_mbuf);
237433d6423SLionel Sambuc void switch_address_space(struct proc * p);
238433d6423SLionel Sambuc void release_address_space(struct proc *pr);
239433d6423SLionel Sambuc 
240433d6423SLionel Sambuc void enable_fpu_exception(void);
241433d6423SLionel Sambuc void disable_fpu_exception(void);
242433d6423SLionel Sambuc void release_fpu(struct proc * p);
243433d6423SLionel Sambuc void arch_pause(void);
244433d6423SLionel Sambuc short cpu_load(void);
245433d6423SLionel Sambuc void busy_delay_ms(int ms);
246433d6423SLionel Sambuc 
247433d6423SLionel Sambuc /* utility.c */
248433d6423SLionel Sambuc void cpu_print_freq(unsigned cpu);
249433d6423SLionel Sambuc #endif /* __kernel__ */
250433d6423SLionel Sambuc 
251433d6423SLionel Sambuc #endif /* PROTO_H */
252