test: map MMIO regions from device region nodes
Partitions shall parse their manifest to obtain information about
device region nodes and map the corresponding MMIO regions.
With this change, there is no need for explicit helper commands to
map MMIO address space of peripherals such as Trusted Watchdog.
Signed-off-by: Madhukar Pappireddy <madhukar.pappireddy@arm.com>
Change-Id: I5d30adf08867c24408915c78cf954cef14cd4130
diff --git a/test/hftest/mm.c b/test/hftest/mm.c
index 18fe8dd..a6c1bc4 100644
--- a/test/hftest/mm.c
+++ b/test/hftest/mm.c
@@ -11,7 +11,7 @@
#include "test/hftest.h"
/* Number of pages reserved for page tables. Increase if necessary. */
-#define PTABLE_PAGES 5
+#define PTABLE_PAGES 10
/**
* Start address space mapping at 0x1000 for the mm to create a L2 table to
diff --git a/test/hftest/service_common.c b/test/hftest/service_common.c
index 1ab491f..e90e944 100644
--- a/test/hftest/service_common.c
+++ b/test/hftest/service_common.c
@@ -102,8 +102,7 @@
* initialized.
* TODO: Parse other fields as needed.
*/
-static void hftest_parse_ffa_manifest(struct hftest_context *ctx,
- struct fdt *fdt)
+void hftest_parse_ffa_manifest(struct hftest_context *ctx, struct fdt *fdt)
{
struct fdt_node root;
struct fdt_node ffa_node;
@@ -373,3 +372,30 @@
struct hftest_context *ctx = hftest_get_context();
ctx->dir_req_source_id = id;
}
+
+void hftest_map_device_regions(struct hftest_context *ctx)
+{
+ struct device_region *dev_region;
+ uint32_t dev_region_count;
+
+ /*
+ * The running partition must have received and parsed its own
+ * partition manifest by now.
+ */
+ if (!ctx || !ctx->is_ffa_manifest_parsed) {
+ panic("Partition manifest not parsed.\n");
+ }
+
+ dev_region_count = ctx->partition_manifest.dev_region_count;
+
+ /* Map the MMIO address space of the devices. */
+ for (uint32_t i = 0; i < dev_region_count; i++) {
+ dev_region = &ctx->partition_manifest.dev_regions[i];
+
+ hftest_mm_identity_map(
+ // NOLINTNEXTLINE(performance-no-int-to-ptr)
+ (const void *)dev_region->base_address,
+ dev_region->page_count * PAGE_SIZE,
+ dev_region->attributes);
+ }
+}
diff --git a/test/inc/test/hftest.h b/test/inc/test/hftest.h
index 472379b..9c5b500 100644
--- a/test/inc/test/hftest.h
+++ b/test/inc/test/hftest.h
@@ -206,3 +206,7 @@
#include "hftest_impl.h"
void hftest_context_init(struct hftest_context *ctx, void *send, void *recv);
+
+void hftest_parse_ffa_manifest(struct hftest_context *ctx, struct fdt *fdt);
+
+void hftest_map_device_regions(struct hftest_context *ctx);
diff --git a/test/vmapi/ffa_secure_partitions/secure_interrupts.c b/test/vmapi/ffa_secure_partitions/secure_interrupts.c
index 0f5e3ce..5bb984e 100644
--- a/test/vmapi/ffa_secure_partitions/secure_interrupts.c
+++ b/test/vmapi/ffa_secure_partitions/secure_interrupts.c
@@ -63,11 +63,6 @@
/* Enable trusted watchdog interrupt as vIRQ in the secure side. */
enable_trusted_wdog_interrupt(own_id, receiver_id);
- res = sp_twdog_map_cmd_send(own_id, receiver_id);
-
- EXPECT_EQ(res.func, FFA_MSG_SEND_DIRECT_RESP_32);
- EXPECT_EQ(sp_resp(res), SP_SUCCESS);
-
/*
* Send a message to the SP through direct messaging requesting it to
* start the trusted watchdog timer.
diff --git a/test/vmapi/ffa_secure_partitions/services/arch/aarch64/secure/el0/partition_manifest_service_sp_second.dts b/test/vmapi/ffa_secure_partitions/services/arch/aarch64/secure/el0/partition_manifest_service_sp_second.dts
index bd4435b..0a5ac01 100644
--- a/test/vmapi/ffa_secure_partitions/services/arch/aarch64/secure/el0/partition_manifest_service_sp_second.dts
+++ b/test/vmapi/ffa_secure_partitions/services/arch/aarch64/secure/el0/partition_manifest_service_sp_second.dts
@@ -25,6 +25,13 @@
ns-interrupts-action = <2>; /* NS interrupts are signaled */
boot-order = <4>;
notification-support; /* Receipt of notifications. */
+ gp-register-num = <0>;
+
+ /* Boot Info */
+ boot-info {
+ compatible = "arm,ffa-manifest-boot-info";
+ ffa_manifest;
+ };
device-regions {
compatible = "arm,ffa-manifest-device-regions";
diff --git a/test/vmapi/ffa_secure_partitions/services/arch/aarch64/secure/inc/partition_services.h b/test/vmapi/ffa_secure_partitions/services/arch/aarch64/secure/inc/partition_services.h
index d03ab63..dea727c 100644
--- a/test/vmapi/ffa_secure_partitions/services/arch/aarch64/secure/inc/partition_services.h
+++ b/test/vmapi/ffa_secure_partitions/services/arch/aarch64/secure/inc/partition_services.h
@@ -120,12 +120,6 @@
SP_TWDOG_START_CMD,
/**
- * Request SP to map MMIO region of Trusted Watchdog peripheral into
- * it's Stage-1 address space.
- */
- SP_TWDOG_MAP_CMD,
-
- /**
* Request SP to return the last serviced secure virtual interrupt.
*/
SP_LAST_INTERRUPT_SERVICED_CMD,
@@ -431,19 +425,6 @@
struct ffa_value sp_twdog_cmd(ffa_id_t source, uint64_t time);
/**
- * Request SP to map MMIO region of Trusted Watchdog peripheral into it's
- * Stage-1 address space.
- */
-static inline struct ffa_value sp_twdog_map_cmd_send(ffa_id_t source,
- ffa_id_t dest)
-{
- return ffa_msg_send_direct_req(source, dest, SP_TWDOG_MAP_CMD, 0, 0, 0,
- 0);
-}
-
-struct ffa_value sp_twdog_map_cmd(ffa_id_t source);
-
-/**
* Request SP to return the last serviced secure virtual interrupt.
*/
static inline struct ffa_value sp_get_last_interrupt_cmd_send(ffa_id_t source,
diff --git a/test/vmapi/ffa_secure_partitions/services/arch/aarch64/secure/message_loop.c b/test/vmapi/ffa_secure_partitions/services/arch/aarch64/secure/message_loop.c
index f796720..690c446 100644
--- a/test/vmapi/ffa_secure_partitions/services/arch/aarch64/secure/message_loop.c
+++ b/test/vmapi/ffa_secure_partitions/services/arch/aarch64/secure/message_loop.c
@@ -6,6 +6,9 @@
* https://opensource.org/licenses/BSD-3-Clause.
*/
+#include "hf/fdt_handler.h"
+#include "hf/mm.h"
+
#include "vmapi/hf/call.h"
#include "partition_services.h"
@@ -93,9 +96,6 @@
case SP_TWDOG_START_CMD:
res = sp_twdog_cmd(ffa_sender(res), res.arg4);
break;
- case SP_TWDOG_MAP_CMD:
- res = sp_twdog_map_cmd(ffa_sender(res));
- break;
case SP_LAST_INTERRUPT_SERVICED_CMD:
res = sp_get_last_interrupt_cmd(ffa_sender(res));
break;
@@ -154,13 +154,47 @@
*/
noreturn void test_main_sp(bool is_boot_vcpu)
{
+ /* Use FF-A v1.1 EAC0 boot protocol to retrieve the FDT. */
+ static struct ffa_boot_info_desc* fdt_info;
struct mailbox_buffers mb;
struct hftest_context* ctx = hftest_get_context();
struct ffa_value res;
if (is_boot_vcpu) {
+ struct fdt fdt;
+ void* fdt_ptr;
+ struct ffa_boot_info_header* boot_info_header;
+
mb = set_up_mailbox();
hftest_context_init(ctx, mb.send, mb.recv);
+ boot_info_header = get_boot_info_header();
+
+ fdt_info = get_boot_info_desc(boot_info_header,
+ FFA_BOOT_INFO_TYPE_STD,
+ FFA_BOOT_INFO_TYPE_ID_FDT);
+
+ // NOLINTNEXTLINE(performance-no-int-to-ptr)
+ fdt_ptr = (void*)fdt_info->content;
+
+ if (!fdt_struct_from_ptr(fdt_ptr, &fdt)) {
+ HFTEST_LOG(HFTEST_LOG_INDENT
+ "Unable to access the FDT");
+ abort();
+ }
+
+ hftest_parse_ffa_manifest(ctx, &fdt);
+
+ /*
+ * Map MMIO address space of peripherals (such as secure
+ * watchdog timer) described as device region nodes in partition
+ * manifest.
+ */
+ hftest_map_device_regions(ctx);
+ } else {
+ /*
+ * Primary core should have initialized the fdt_info structure.
+ */
+ assert(fdt_info != NULL);
}
res = ffa_msg_wait();
diff --git a/test/vmapi/ffa_secure_partitions/services/arch/aarch64/secure/partition_manifest_service_sp_first.dts b/test/vmapi/ffa_secure_partitions/services/arch/aarch64/secure/partition_manifest_service_sp_first.dts
index 11940f8..a7a8735 100644
--- a/test/vmapi/ffa_secure_partitions/services/arch/aarch64/secure/partition_manifest_service_sp_first.dts
+++ b/test/vmapi/ffa_secure_partitions/services/arch/aarch64/secure/partition_manifest_service_sp_first.dts
@@ -33,4 +33,11 @@
managed-exit-virq;
boot-order = <1>;
notification-support; /* Receipt of notifications. */
+ gp-register-num = <0>;
+
+ /* Boot Info */
+ boot-info {
+ compatible = "arm,ffa-manifest-boot-info";
+ ffa_manifest;
+ };
};
diff --git a/test/vmapi/ffa_secure_partitions/services/arch/aarch64/secure/partition_manifest_service_sp_second.dts b/test/vmapi/ffa_secure_partitions/services/arch/aarch64/secure/partition_manifest_service_sp_second.dts
index 114aa57..0db81cd 100644
--- a/test/vmapi/ffa_secure_partitions/services/arch/aarch64/secure/partition_manifest_service_sp_second.dts
+++ b/test/vmapi/ffa_secure_partitions/services/arch/aarch64/secure/partition_manifest_service_sp_second.dts
@@ -25,6 +25,13 @@
ns-interrupts-action = <2>; /* Non secure interrupts are signaled. */
boot-order = <2>;
notification-support; /* Receipt of notifications. */
+ gp-register-num = <0>;
+
+ /* Boot Info */
+ boot-info {
+ compatible = "arm,ffa-manifest-boot-info";
+ ffa_manifest;
+ };
device-regions {
compatible = "arm,ffa-manifest-device-regions";
diff --git a/test/vmapi/ffa_secure_partitions/services/arch/aarch64/secure/partition_manifest_service_sp_third.dts b/test/vmapi/ffa_secure_partitions/services/arch/aarch64/secure/partition_manifest_service_sp_third.dts
index 9e3d923..641e469 100644
--- a/test/vmapi/ffa_secure_partitions/services/arch/aarch64/secure/partition_manifest_service_sp_third.dts
+++ b/test/vmapi/ffa_secure_partitions/services/arch/aarch64/secure/partition_manifest_service_sp_third.dts
@@ -26,4 +26,11 @@
notification-support; /* Receipt of notifications. */
ns-interrupts-action = <0>; /* Non secure interrupts are queued. */
other-s-interrupts-action = <0>; /* Other S-Interrupts are queued. */
+ gp-register-num = <0>;
+
+ /* Boot Info */
+ boot-info {
+ compatible = "arm,ffa-manifest-boot-info";
+ ffa_manifest;
+ };
};
diff --git a/test/vmapi/ffa_secure_partitions/services/arch/aarch64/secure/secure_interrupts.c b/test/vmapi/ffa_secure_partitions/services/arch/aarch64/secure/secure_interrupts.c
index 55b1fda..cec813f 100644
--- a/test/vmapi/ffa_secure_partitions/services/arch/aarch64/secure/secure_interrupts.c
+++ b/test/vmapi/ffa_secure_partitions/services/arch/aarch64/secure/secure_interrupts.c
@@ -127,17 +127,6 @@
return sp_success(own_id, test_source, time);
}
-struct ffa_value sp_twdog_map_cmd(ffa_id_t test_source)
-{
- ffa_id_t own_id = hf_vm_get_id();
-
- /* Map peripheral(such as secure watchdog timer) address space. */
- hftest_mm_identity_map((void *)PLAT_ARM_TWDOG_BASE, PLAT_ARM_TWDOG_SIZE,
- MM_MODE_R | MM_MODE_W | MM_MODE_D);
-
- return sp_success(own_id, test_source, 0);
-}
-
struct ffa_value sp_get_last_interrupt_cmd(ffa_id_t test_source)
{
ffa_id_t own_id = hf_vm_get_id();
diff --git a/test/vmapi/primary_with_secondaries/services/arch/aarch64/secure/secure_interrupts.c b/test/vmapi/primary_with_secondaries/services/arch/aarch64/secure/secure_interrupts.c
index 97ffde2..ad087ce 100644
--- a/test/vmapi/primary_with_secondaries/services/arch/aarch64/secure/secure_interrupts.c
+++ b/test/vmapi/primary_with_secondaries/services/arch/aarch64/secure/secure_interrupts.c
@@ -93,28 +93,13 @@
void *send_buf = SERVICE_SEND_BUFFER();
void *recv_buf = SERVICE_RECV_BUFFER();
struct hftest_context *ctx = hftest_get_context();
- struct device_region *dev_region;
- uint32_t dev_region_count;
- if (!ctx->is_ffa_manifest_parsed) {
- panic("This test requires the running partition to have "
- "received and parsed its own FF-A manifest.\n");
- }
-
- dev_region_count = ctx->partition_manifest.dev_region_count;
-
- ASSERT_TRUE(dev_region_count != 0U);
-
- /* Map the MMIO address space of the devices. */
- for (uint32_t i = 0; i < dev_region_count; i++) {
- dev_region = &ctx->partition_manifest.dev_regions[i];
-
- hftest_mm_identity_map(
- // NOLINTNEXTLINE(performance-no-int-to-ptr)
- (const void *)dev_region->base_address,
- dev_region->page_count * PAGE_SIZE,
- dev_region->attributes);
- }
+ /*
+ * Map MMIO address space of peripherals (such as secure
+ * watchdog timer) described as device region nodes in partition
+ * manifest.
+ */
+ hftest_map_device_regions(ctx);
/*
* Setup handling of known interrupts including Secure Watchdog timer