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/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);
+	}
+}