Trusted Firmware-A Tests, version 2.0
This is the first public version of the tests for the Trusted
Firmware-A project. Please see the documentation provided in the
source tree for more details.
Change-Id: I6f3452046a1351ac94a71b3525c30a4ca8db7867
Signed-off-by: Sandrine Bailleux <sandrine.bailleux@arm.com>
Co-authored-by: amobal01 <amol.balasokamble@arm.com>
Co-authored-by: Antonio Nino Diaz <antonio.ninodiaz@arm.com>
Co-authored-by: Asha R <asha.r@arm.com>
Co-authored-by: Chandni Cherukuri <chandni.cherukuri@arm.com>
Co-authored-by: David Cunado <david.cunado@arm.com>
Co-authored-by: Dimitris Papastamos <dimitris.papastamos@arm.com>
Co-authored-by: Douglas Raillard <douglas.raillard@arm.com>
Co-authored-by: dp-arm <dimitris.papastamos@arm.com>
Co-authored-by: Jeenu Viswambharan <jeenu.viswambharan@arm.com>
Co-authored-by: Jonathan Wright <jonathan.wright@arm.com>
Co-authored-by: Kévin Petit <kevin.petit@arm.com>
Co-authored-by: Roberto Vargas <roberto.vargas@arm.com>
Co-authored-by: Sathees Balya <sathees.balya@arm.com>
Co-authored-by: Shawon Roy <Shawon.Roy@arm.com>
Co-authored-by: Soby Mathew <soby.mathew@arm.com>
Co-authored-by: Thomas Abraham <thomas.abraham@arm.com>
Co-authored-by: Vikram Kanigiri <vikram.kanigiri@arm.com>
Co-authored-by: Yatharth Kochar <yatharth.kochar@arm.com>
diff --git a/lib/events/events.c b/lib/events/events.c
new file mode 100644
index 0000000..42130d5
--- /dev/null
+++ b/lib/events/events.c
@@ -0,0 +1,85 @@
+/*
+ * Copyright (c) 2018, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <arch_helpers.h>
+#include <assert.h>
+#include <debug.h>
+#include <events.h>
+#include <platform_def.h>
+#include <tftf.h>
+#include <tftf_lib.h>
+
+void tftf_init_event(event_t *event)
+{
+ assert(event != NULL);
+ event->cnt = 0;
+ event->lock.lock = 0;
+}
+
+static void send_event_common(event_t *event, unsigned int inc)
+{
+ spin_lock(&event->lock);
+ event->cnt += inc;
+ spin_unlock(&event->lock);
+
+ sev();
+}
+
+void tftf_send_event(event_t *event)
+{
+ VERBOSE("Sending event %p\n", (void *) event);
+ send_event_common(event, 1);
+}
+
+void tftf_send_event_to_all(event_t *event)
+{
+ VERBOSE("Sending event %p to all CPUs\n", (void *) event);
+ send_event_common(event, PLATFORM_CORE_COUNT);
+}
+
+void tftf_send_event_to(event_t *event, unsigned int cpus_count)
+{
+ assert(cpus_count <= PLATFORM_CORE_COUNT);
+ VERBOSE("Sending event %p to %u CPUs\n", (void *) event, cpus_count);
+ send_event_common(event, cpus_count);
+}
+
+void tftf_wait_for_event(event_t *event)
+{
+ unsigned int event_received = 0;
+
+ VERBOSE("Waiting for event %p\n", (void *) event);
+ while (!event_received) {
+
+ dsbsy();
+ /* Wait for someone to send an event */
+ if (!event->cnt) {
+ wfe();
+ } else {
+ spin_lock(&event->lock);
+
+ /*
+ * Check that the event is still pending and that no
+ * one stole it from us while we were trying to
+ * acquire the lock.
+ */
+ if (event->cnt != 0) {
+ event_received = 1;
+ --event->cnt;
+ }
+ /*
+ * No memory barrier is needed here because spin_unlock()
+ * issues a Store-Release instruction, which guarantees
+ * that loads and stores appearing in program order
+ * before the Store-Release are observed before the
+ * Store-Release itself.
+ */
+ spin_unlock(&event->lock);
+ }
+ }
+
+ VERBOSE("Received event %p\n", (void *) event);
+}