1 /*
2  * Copyright 2020 The Hafnium Authors.
3  *
4  * Use of this source code is governed by a BSD-style
5  * license that can be found in the LICENSE file or at
6  * https://opensource.org/licenses/BSD-3-Clause.
7  */
8 
9 #include "hf/arch/plat/psci.h"
10 
11 #include "hf/cpu.h"
12 #include "hf/dlog.h"
13 #include "hf/vm.h"
14 
15 #include "psci.h"
16 
17 static uint32_t el3_psci_version;
18 
19 /**
20  * Returns the PSCI version gathered from the EL3 PSCI layer during init.
21  */
plat_psci_version_get(void)22 uint32_t plat_psci_version_get(void)
23 {
24 	return el3_psci_version;
25 }
26 
27 /**
28  * Initialize the platform power managment module in context of
29  * running the Hypervisor. In particular it gathers the PSCI version
30  * from the EL3 PSCI firmware.
31  */
plat_psci_init(void)32 void plat_psci_init(void)
33 {
34 	struct ffa_value smc_res =
35 		smc32(PSCI_VERSION, 0, 0, 0, 0, 0, 0, SMCCC_CALLER_HYPERVISOR);
36 
37 	el3_psci_version = smc_res.func;
38 
39 	/* Check there's nothing unexpected about PSCI. */
40 	switch (el3_psci_version) {
41 	case PSCI_VERSION_0_2:
42 	case PSCI_VERSION_1_0:
43 	case PSCI_VERSION_1_1:
44 		/* Supported EL3 PSCI version. */
45 		dlog_info("Found PSCI version: %#x\n", el3_psci_version);
46 		break;
47 
48 	default:
49 		/* Unsupported EL3 PSCI version. Log a warning but continue. */
50 		dlog_warning("Unknown PSCI version: %#x\n", el3_psci_version);
51 		el3_psci_version = 0;
52 		break;
53 	}
54 }
55 
plat_psci_cpu_suspend(uint32_t power_state)56 void plat_psci_cpu_suspend(uint32_t power_state)
57 {
58 	(void)power_state;
59 }
60 
plat_psci_cpu_resume(struct cpu * c)61 struct vcpu *plat_psci_cpu_resume(struct cpu *c)
62 {
63 	struct vcpu *vcpu = vcpu_get_boot_vcpu();
64 
65 	vcpu = vm_get_vcpu(vcpu->vm, cpu_index(c));
66 	vcpu->cpu = c;
67 
68 	arch_cpu_init(c);
69 
70 	/* Reset the registers to give a clean start for vCPU. */
71 	arch_regs_reset(vcpu);
72 
73 	/* TODO: call plat_ffa_sri_init? */
74 
75 	return vcpu;
76 }
77