1 // © 2021 Qualcomm Innovation Center, Inc. All rights reserved.
2 //
3 // SPDX-License-Identifier: BSD-3-Clause
4 
5 #include <assert.h>
6 #include <hyptypes.h>
7 
8 #include <bitmap.h>
9 #include <panic.h>
10 #include <platform_cpu.h>
11 #include <platform_security.h>
12 #include <smccc_platform.h>
13 
14 #include "event_handlers.h"
15 
16 bool
platform_security_state_debug_disabled(void)17 platform_security_state_debug_disabled(void)
18 {
19 	return false;
20 }
21 
22 uint32_t
platform_cpu_stack_size(void)23 platform_cpu_stack_size(void)
24 {
25 	return 0;
26 }
27 
28 bool
smccc_handle_smc_platform_call(register_t args[7],bool is_hvc)29 smccc_handle_smc_platform_call(register_t args[7], bool is_hvc)
30 	EXCLUDE_PREEMPT_DISABLED
31 {
32 	(void)is_hvc;
33 	args[0] = (register_t)SMCCC_UNKNOWN_FUNCTION64;
34 	return true;
35 }
36 
37 // Overrides the weak imlementation in core_id.c
38 core_id_t
platform_cpu_get_coreid(MIDR_EL1_t midr)39 platform_cpu_get_coreid(MIDR_EL1_t midr)
40 {
41 	(void)midr;
42 	return CORE_ID_QEMU;
43 }
44 
45 #if !defined(UNIT_TESTS)
46 static _Atomic BITMAP_DECLARE(PLATFORM_MAX_CORES, hlos_vm_cpus);
47 
48 bool
soc_qemu_handle_vcpu_activate_thread(thread_t * thread,vcpu_option_flags_t options)49 soc_qemu_handle_vcpu_activate_thread(thread_t		*thread,
50 				     vcpu_option_flags_t options)
51 {
52 	bool ret = true;
53 
54 	assert(thread != NULL);
55 	assert(thread->kind == THREAD_KIND_VCPU);
56 
57 	if (vcpu_option_flags_get_hlos_vm(&options)) {
58 		bool already_set = bitmap_atomic_test_and_set(
59 			hlos_vm_cpus, thread->scheduler_affinity,
60 			memory_order_relaxed);
61 		if (already_set) {
62 			ret = false;
63 			goto out;
64 		}
65 
66 		// Validated, set the flag in the thread
67 		vcpu_option_flags_set_hlos_vm(&thread->vcpu_options, true);
68 	}
69 
70 out:
71 	return ret;
72 }
73 #endif
74