xref: /haiku/headers/private/kernel/cpu.h (revision 03187b607b2b5eec7ee059f1ead09bdba14991fb)
1 /*
2  * Copyright 2002-2006, Haiku Inc. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Copyright 2002, Travis Geiselbrecht. All rights reserved.
6  * Distributed under the terms of the NewOS License.
7  */
8 #ifndef _KERNEL_CPU_H
9 #define _KERNEL_CPU_H
10 
11 
12 #include <setjmp.h>
13 
14 #include <smp.h>
15 #include <timer.h>
16 #include <boot/kernel_args.h>
17 #include <arch/cpu.h>
18 
19 
20 // define PAUSE, if not done in arch/cpu.h
21 #ifndef PAUSE
22 #	define PAUSE()
23 #endif
24 
25 
26 /* CPU local data structure */
27 
28 typedef struct cpu_ent {
29 	int			cpu_num;
30 
31 	// thread.c: used to force a reschedule at quantum expiration time
32 	int			preempted;
33 	timer		quantum_timer;
34 
35 	// keeping track of CPU activity
36 	bigtime_t	active_time;
37 	bigtime_t	last_kernel_time;
38 	bigtime_t	last_user_time;
39 
40 	// used in the kernel debugger
41 	addr_t		fault_handler;
42 	addr_t		fault_handler_stack_pointer;
43 	jmp_buf		fault_jump_buffer;
44 
45 	bool		invoke_scheduler;
46 	bool		disabled;
47 
48 	// arch-specific stuff
49 	arch_cpu_info arch;
50 } cpu_ent __attribute__((aligned(64)));
51 
52 
53 extern cpu_ent gCPU[MAX_BOOT_CPUS];
54 
55 
56 #ifdef __cplusplus
57 extern "C" {
58 #endif
59 
60 status_t cpu_preboot_init_percpu(struct kernel_args *args, int curr_cpu);
61 status_t cpu_init(struct kernel_args *args);
62 status_t cpu_init_percpu(kernel_args *ka, int curr_cpu);
63 status_t cpu_init_post_vm(struct kernel_args *args);
64 status_t cpu_init_post_modules(struct kernel_args *args);
65 bigtime_t cpu_get_active_time(int32 cpu);
66 
67 cpu_ent *get_cpu_struct(void);
68 extern inline cpu_ent *get_cpu_struct(void) { return &gCPU[smp_get_current_cpu()]; }
69 
70 void _user_clear_caches(void *address, size_t length, uint32 flags);
71 bool _user_cpu_enabled(int32 cpu);
72 status_t _user_set_cpu_enabled(int32 cpu, bool enabled);
73 
74 #ifdef __cplusplus
75 }
76 #endif
77 
78 #endif	/* _KERNEL_CPU_H */
79