cactus: ivy: Add sleep service
This service sleeps for a number of milliseconds.
Change-Id: Ib7f17142d22c8313dedc5f8037874bacbf8ed5f4
Signed-off-by: Antonio Nino Diaz <antonio.ninodiaz@arm.com>
diff --git a/spm/cactus/cactus_def.h b/spm/cactus/cactus_def.h
index ef813d2..13b5dac 100644
--- a/spm/cactus/cactus_def.h
+++ b/spm/cactus/cactus_def.h
@@ -52,6 +52,8 @@
#define CACTUS_PRINT_MAGIC U(1)
/* Return a magic number unique to Cactus */
#define CACTUS_GET_MAGIC U(2)
+/* Sleep for a number of milliseconds */
+#define CACTUS_SLEEP_MS U(3)
#define CACTUS_MAGIC_NUMBER U(0x12481369)
diff --git a/spm/cactus/cactus_main.c b/spm/cactus/cactus_main.c
index bfbfa48..a062ef0 100644
--- a/spm/cactus/cactus_main.c
+++ b/spm/cactus/cactus_main.c
@@ -12,6 +12,7 @@
#include <pl011.h>
#include <plat_arm.h>
#include <platform_def.h>
+#include <sp_helpers.h>
#include <sprt_client.h>
#include <sprt_svc.h>
#include <std_svc.h>
@@ -70,6 +71,11 @@
ret0 = SPRT_SUCCESS;
break;
+ case CACTUS_SLEEP_MS:
+ sp_sleep(message->args[2]);
+ ret0 = SPRT_SUCCESS;
+ break;
+
default:
NOTICE("Cactus: Unhandled Service ID 0x%x\n",
(unsigned int)message->args[1]);
diff --git a/spm/common/sp_helpers.c b/spm/common/sp_helpers.c
index cccaf8b..5aec977 100644
--- a/spm/common/sp_helpers.c
+++ b/spm/common/sp_helpers.c
@@ -55,17 +55,15 @@
INFO("Test \"%s\" passed.\n", test_desc);
}
-void sp_sleep(uint32_t duration_sec)
+void sp_sleep(uint32_t ms)
{
- uint32_t timer_freq = mmio_read_32(SYS_CNT_CONTROL_BASE + CNTFID_OFF);
- VERBOSE("%s: Timer frequency = %u\n", __func__, timer_freq);
+ uint64_t timer_freq = mmio_read_32(SYS_CNT_CONTROL_BASE + CNTFID_OFF);
+ VERBOSE("%s: Timer frequency = %llu\n", __func__, timer_freq);
- INFO("%s: Sleeping for %u seconds...\n", __func__, duration_sec);
+ VERBOSE("%s: Sleeping for %u milliseconds...\n", __func__, ms);
uint64_t time1 = mmio_read_64(SYS_CNT_READ_BASE);
volatile uint64_t time2 = time1;
- while ((time2 - time1) < duration_sec * timer_freq) {
+ while ((time2 - time1) < ((ms * timer_freq) / 1000U)) {
time2 = mmio_read_64(SYS_CNT_READ_BASE);
}
-
- INFO("%s: Done\n", __func__);
}
diff --git a/spm/common/sp_helpers.h b/spm/common/sp_helpers.h
index ab6415d..fb2d8ac 100644
--- a/spm/common/sp_helpers.h
+++ b/spm/common/sp_helpers.h
@@ -55,7 +55,7 @@
void announce_test_start(const char *test_desc);
void announce_test_end(const char *test_desc);
-/* Sleep for at least 'duration_sec' seconds then return. */
-void sp_sleep(uint32_t duration_sec);
+/* Sleep for at least 'ms' milliseconds. */
+void sp_sleep(uint32_t ms);
#endif /* SP_HELPERS_H */
diff --git a/spm/ivy/ivy_def.h b/spm/ivy/ivy_def.h
index 11eeacf..729c46d 100644
--- a/spm/ivy/ivy_def.h
+++ b/spm/ivy/ivy_def.h
@@ -41,6 +41,8 @@
#define IVY_PRINT_MAGIC U(1001)
/* Return a magic number unique to IVY */
#define IVY_GET_MAGIC U(1002)
+/* Sleep for a number of milliseconds */
+#define IVY_SLEEP_MS U(1003)
#define IVY_MAGIC_NUMBER U(0x97531842)
diff --git a/spm/ivy/ivy_main.c b/spm/ivy/ivy_main.c
index cd81e88..1f1c5e4 100644
--- a/spm/ivy/ivy_main.c
+++ b/spm/ivy/ivy_main.c
@@ -12,6 +12,7 @@
#include <pl011.h>
#include <plat_arm.h>
#include <platform_def.h>
+#include <sp_helpers.h>
#include <sprt_client.h>
#include <sprt_svc.h>
@@ -64,6 +65,11 @@
ret0 = SPRT_SUCCESS;
break;
+ case IVY_SLEEP_MS:
+ sp_sleep(message->args[2]);
+ ret0 = SPRT_SUCCESS;
+ break;
+
default:
NOTICE("IVY: Unhandled Service ID 0x%x\n",
(unsigned int)message->args[1]);