xref: /haiku/src/system/kernel/arch/riscv64/arch_cpu.cpp (revision 3d4afef9cba2f328e238089d4609d00d4b1524f3)
1 /*
2  * Copyright 2019, Adrien Destugues, pulkomandy@pulkomandy.tk.
3  * Distributed under the terms of the MIT License.
4  */
5 
6 
7 #include <KernelExport.h>
8 
9 #include <arch/cpu.h>
10 #include <boot/kernel_args.h>
11 #include <vm/VMAddressSpace.h>
12 #include <commpage.h>
13 #include <elf.h>
14 #include <Htif.h>
15 #include <platform/sbi/sbi_syscalls.h>
16 
17 
18 extern uint32 gPlatform;
19 
20 
21 status_t
22 arch_cpu_preboot_init_percpu(kernel_args *args, int curr_cpu)
23 {
24 	return B_OK;
25 }
26 
27 
28 status_t
29 arch_cpu_init_percpu(kernel_args *args, int curr_cpu)
30 {
31 	//detect_cpu(curr_cpu);
32 
33 	// we only support one anyway...
34 	return 0;
35 }
36 
37 
38 status_t
39 arch_cpu_init(kernel_args *args)
40 {
41 /*
42 	uint64 conversionFactor
43 		= (1LL << 32) * 1000000LL / args->arch_args.timerFrequency;
44 
45 	__riscv64_setup_system_time(conversionFactor);
46 */
47 	return B_OK;
48 }
49 
50 
51 status_t
52 arch_cpu_init_post_vm(kernel_args *args)
53 {
54 	// Set address space ownership to currently running threads
55 	for (uint32 i = 0; i < args->num_cpus; i++) {
56 		VMAddressSpace::Kernel()->Get();
57 	}
58 
59 	return B_OK;
60 }
61 
62 
63 status_t
64 arch_cpu_init_post_modules(kernel_args *args)
65 {
66 	return B_OK;
67 }
68 
69 
70 void
71 arch_cpu_sync_icache(void *address, size_t len)
72 {
73 }
74 
75 
76 void
77 arch_cpu_memory_read_barrier(void)
78 {
79 }
80 
81 
82 void
83 arch_cpu_memory_write_barrier(void)
84 {
85 }
86 
87 
88 void
89 arch_cpu_invalidate_TLB_range(addr_t start, addr_t end)
90 {
91 }
92 
93 
94 void
95 arch_cpu_invalidate_TLB_list(addr_t pages[], int num_pages)
96 {
97 }
98 
99 
100 void
101 arch_cpu_global_TLB_invalidate(void)
102 {
103 }
104 
105 
106 void
107 arch_cpu_user_TLB_invalidate(void)
108 {
109 }
110 
111 
112 status_t
113 arch_cpu_shutdown(bool reboot)
114 {
115 	if (gPlatform == kPlatformSbi) {
116 		sbi_system_reset(
117 			reboot ? SBI_RESET_TYPE_COLD_REBOOT : SBI_RESET_TYPE_SHUTDOWN,
118 			SBI_RESET_REASON_NONE);
119 	}
120 
121 	HtifShutdown();
122 	return B_ERROR;
123 }
124