Be clear about which SMC calling convention is being used.
Change-Id: I3b8f2e55f9a3baeb462d59effc9a99ac56aeaa7d
diff --git a/src/arch/aarch64/BUILD.gn b/src/arch/aarch64/BUILD.gn
index 58072b8..9f29b72 100644
--- a/src/arch/aarch64/BUILD.gn
+++ b/src/arch/aarch64/BUILD.gn
@@ -43,6 +43,7 @@
# Make a call to the secure monitor.
source_set("smc") {
sources = [
- "smc.S",
+ "smc.c",
+ "smc_internal.S",
]
}
diff --git a/src/arch/aarch64/hftest/power_mgmt.c b/src/arch/aarch64/hftest/power_mgmt.c
index 7d0893d..7abe4d9 100644
--- a/src/arch/aarch64/hftest/power_mgmt.c
+++ b/src/arch/aarch64/hftest/power_mgmt.c
@@ -72,7 +72,7 @@
s.arg = arg;
/* Try to start the CPU. */
- if (smc(PSCI_CPU_ON, id, (size_t)&vm_cpu_entry_raw, (size_t)&s) !=
+ if (smc32(PSCI_CPU_ON, id, (size_t)&vm_cpu_entry_raw, (size_t)&s) !=
PSCI_RETURN_SUCCESS) {
return false;
}
@@ -91,7 +91,7 @@
*/
noreturn void cpu_stop(void)
{
- smc(PSCI_CPU_OFF, 0, 0, 0);
+ smc32(PSCI_CPU_OFF, 0, 0, 0);
for (;;) {
/* This should never be reached. */
}
@@ -116,7 +116,7 @@
* as the PSCI_RETURN_* values. The static_asserts above validate that
* this is the case.
*/
- return smc(PSCI_AFFINITY_INFO, cpu_id, lowest_affinity_level, 0);
+ return smc32(PSCI_AFFINITY_INFO, cpu_id, lowest_affinity_level, 0);
}
/**
@@ -124,7 +124,7 @@
*/
noreturn void arch_power_off(void)
{
- smc(PSCI_SYSTEM_OFF, 0, 0, 0);
+ smc32(PSCI_SYSTEM_OFF, 0, 0, 0);
for (;;) {
/* This should never be reached. */
}
diff --git a/src/arch/aarch64/hypervisor/psci_handler.c b/src/arch/aarch64/hypervisor/psci_handler.c
index 5c87589..b98dd22 100644
--- a/src/arch/aarch64/hypervisor/psci_handler.c
+++ b/src/arch/aarch64/hypervisor/psci_handler.c
@@ -37,7 +37,7 @@
/* Performs arch specific boot time initialisation. */
void arch_one_time_init(void)
{
- el3_psci_version = smc(PSCI_VERSION, 0, 0, 0);
+ el3_psci_version = smc32(PSCI_VERSION, 0, 0, 0);
/* Check there's nothing unexpected about PSCI. */
switch (el3_psci_version) {
@@ -100,7 +100,7 @@
*ret = 0;
} else {
/* PSCI 1.x only defines two feature bits. */
- *ret = smc(func, arg0, 0, 0) & 0x3;
+ *ret = smc32(func, arg0, 0, 0) & 0x3;
}
break;
@@ -123,12 +123,12 @@
break;
case PSCI_SYSTEM_OFF:
- smc(PSCI_SYSTEM_OFF, 0, 0, 0);
+ smc32(PSCI_SYSTEM_OFF, 0, 0, 0);
panic("System off failed");
break;
case PSCI_SYSTEM_RESET:
- smc(PSCI_SYSTEM_RESET, 0, 0, 0);
+ smc32(PSCI_SYSTEM_RESET, 0, 0, 0);
panic("System reset failed");
break;
@@ -161,14 +161,14 @@
* vcpu registers will be ignored.
*/
arch_regs_set_pc_arg(&vcpu->regs, ipa_init(arg1), arg2);
- *ret = smc(PSCI_CPU_SUSPEND | SMCCC_64_BIT, arg0,
- (uintreg_t)&cpu_entry, (uintreg_t)vcpu->cpu);
+ *ret = smc64(PSCI_CPU_SUSPEND, arg0, (uintreg_t)&cpu_entry,
+ (uintreg_t)vcpu->cpu);
break;
}
case PSCI_CPU_OFF:
cpu_off(vcpu->cpu);
- smc(PSCI_CPU_OFF, 0, 0, 0);
+ smc32(PSCI_CPU_OFF, 0, 0, 0);
panic("CPU off failed");
break;
@@ -191,8 +191,8 @@
* itself off).
*/
do {
- *ret = smc(PSCI_CPU_ON | SMCCC_64_BIT, arg0,
- (uintreg_t)&cpu_entry, (uintreg_t)c);
+ *ret = smc64(PSCI_CPU_ON, arg0, (uintreg_t)&cpu_entry,
+ (uintreg_t)c);
} while (*ret == PSCI_ERROR_ALREADY_ON);
if (*ret != PSCI_RETURN_SUCCESS) {
diff --git a/src/arch/aarch64/psci.h b/src/arch/aarch64/psci.h
index eef3fc0..355c618 100644
--- a/src/arch/aarch64/psci.h
+++ b/src/arch/aarch64/psci.h
@@ -16,31 +16,10 @@
#pragma once
+#include "smc.h"
+
/* clang-format off */
-#define SMCCC_CALL_TYPE_MASK 0x80000000
-#define SMCCC_YIELDING_CALL 0x00000000
-#define SMCCC_FAST_CALL 0x80000000
-
-#define SMCCC_CONVENTION_MASK 0x40000000
-#define SMCCC_32_BIT 0x00000000
-#define SMCCC_64_BIT 0x40000000
-
-#define SMCCC_SERVICE_CALL_MASK 0x3f000000
-#define SMCCC_ARM_ARCHITECTURE_CALL 0x00000000
-#define SMCCC_CPU_SERVICE_CALL 0x01000000
-#define SMCCC_SIP_SERVICE_CALL 0x02000000
-#define SMCCC_OEM_SERVICE_CALL 0x03000000
-#define SMCCC_STANDARD_SECURE_SERVICE_CALL 0x04000000
-#define SMCCC_STANDARD_HYPERVISOR_SERVICE_CALL 0x05000000
-#define SMCCC_VENDOR_HYPERVISOR_SERVICE_CALL 0x06000000
-/*
- * TODO: Trusted application call: 0x30000000 - 0x31000000
- * TODO: Trusted OS call: 0x32000000 - 0x3f000000
- */
-
-#define SMCCC_ERROR_UNKNOWN (-1)
-
/* The following are PSCI version codes. */
#define PSCI_VERSION_0_2 0x00000002
#define PSCI_VERSION_1_0 0x00010000
diff --git a/src/arch/aarch64/smc.S b/src/arch/aarch64/smc.c
similarity index 64%
copy from src/arch/aarch64/smc.S
copy to src/arch/aarch64/smc.c
index f49955d..4a9d980 100644
--- a/src/arch/aarch64/smc.S
+++ b/src/arch/aarch64/smc.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2018 The Hafnium Authors.
+ * Copyright 2019 The Hafnium Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,8 +14,14 @@
* limitations under the License.
*/
-.section .text.smc, "ax"
-.global smc
-smc:
- smc #0
- ret
+#include "smc.h"
+
+#include <stdint.h>
+
+uint64_t smc64_internal(uint64_t func, uint64_t arg0, uint64_t arg1,
+ uint64_t arg2);
+
+uint64_t smc64(uint32_t func, uint64_t arg0, uint64_t arg1, uint64_t arg2)
+{
+ return smc64_internal(func | SMCCC_64_BIT, arg0, arg1, arg2);
+}
diff --git a/src/arch/aarch64/smc.h b/src/arch/aarch64/smc.h
index 5a6acd9..1cc5ba3 100644
--- a/src/arch/aarch64/smc.h
+++ b/src/arch/aarch64/smc.h
@@ -16,6 +16,34 @@
#pragma once
-#include "hf/arch/cpu.h"
+#include <stdint.h>
-int32_t smc(uintreg_t arg0, uintreg_t arg1, uintreg_t arg2, uintreg_t arg3);
+/* clang-format off */
+
+#define SMCCC_CALL_TYPE_MASK 0x80000000
+#define SMCCC_YIELDING_CALL 0x00000000
+#define SMCCC_FAST_CALL 0x80000000
+
+#define SMCCC_CONVENTION_MASK 0x40000000
+#define SMCCC_32_BIT 0x00000000
+#define SMCCC_64_BIT 0x40000000
+
+#define SMCCC_SERVICE_CALL_MASK 0x3f000000
+#define SMCCC_ARM_ARCHITECTURE_CALL 0x00000000
+#define SMCCC_CPU_SERVICE_CALL 0x01000000
+#define SMCCC_SIP_SERVICE_CALL 0x02000000
+#define SMCCC_OEM_SERVICE_CALL 0x03000000
+#define SMCCC_STANDARD_SECURE_SERVICE_CALL 0x04000000
+#define SMCCC_STANDARD_HYPERVISOR_SERVICE_CALL 0x05000000
+#define SMCCC_VENDOR_HYPERVISOR_SERVICE_CALL 0x06000000
+/*
+ * TODO: Trusted application call: 0x30000000 - 0x31000000
+ * TODO: Trusted OS call: 0x32000000 - 0x3f000000
+ */
+
+#define SMCCC_ERROR_UNKNOWN (-1)
+
+/* clang-format on */
+
+uint32_t smc32(uint32_t func, uint32_t arg0, uint32_t arg1, uint32_t arg2);
+uint64_t smc64(uint32_t func, uint64_t arg0, uint64_t arg1, uint64_t arg2);
diff --git a/src/arch/aarch64/smc.S b/src/arch/aarch64/smc_internal.S
similarity index 91%
rename from src/arch/aarch64/smc.S
rename to src/arch/aarch64/smc_internal.S
index f49955d..9350fd1 100644
--- a/src/arch/aarch64/smc.S
+++ b/src/arch/aarch64/smc_internal.S
@@ -15,7 +15,9 @@
*/
.section .text.smc, "ax"
-.global smc
-smc:
+.global smc32
+.global smc64_internal
+smc32:
+smc64_internal:
smc #0
ret