PSA FF-A: map secondary VM memory/device regions in its stage-2 mapping

Add support for mapping secondary VM's memory/device regions in its
stage-2 translation along with unmapping it from primary VM as all the
regions are by default mapped in primary VM's translation regime.

As per PSA FF-A EAC spec, if memory-region does not have base-address
specified, the memory-region of given size is allocated inside the
partition's translation regime. This patch allocates memory-region at
the end of VM's memory. At the max half the VM's memory can be allocated
to memory regions.

When base-address is present this field specify a PA, VA (for S-EL0
partitions) or IPA (for S-EL1 and EL1 partitions). In both cases this
patch identity maps the region.

Change-Id: Id53e66d2109f05e76f8b8dbe85e64c84eabd5a5d
Signed-off-by: Manish Pandey <manish.pandey2@arm.com>
diff --git a/src/manifest.c b/src/manifest.c
index 9c98b5f..da25156 100644
--- a/src/manifest.c
+++ b/src/manifest.c
@@ -306,10 +306,10 @@
 
 static enum manifest_return_code parse_ffa_memory_region_node(
 	struct fdt_node *mem_node, struct memory_region *mem_regions,
-	struct rx_tx *rxtx)
+	uint8_t *count, struct rx_tx *rxtx)
 {
 	uint32_t phandle;
-	unsigned int i = 0;
+	uint8_t i = 0;
 
 	dlog_verbose("  Partition memory regions\n");
 
@@ -360,17 +360,18 @@
 		i++;
 	} while (fdt_next_sibling(mem_node) && (i < SP_MAX_MEMORY_REGIONS));
 
-	dlog_verbose("    Total %u memory regions found\n", i);
+	*count = i;
 
 	return MANIFEST_SUCCESS;
 }
 
 static enum manifest_return_code parse_ffa_device_region_node(
-	struct fdt_node *dev_node, struct device_region *dev_regions)
+	struct fdt_node *dev_node, struct device_region *dev_regions,
+	uint8_t *count)
 {
 	struct uint32list_iter list;
-	unsigned int i = 0;
-	unsigned int j = 0;
+	uint8_t i = 0;
+	uint8_t j = 0;
 
 	dlog_verbose("  Partition Device Regions\n");
 
@@ -461,7 +462,7 @@
 		i++;
 	} while (fdt_next_sibling(dev_node) && (i < SP_MAX_DEVICE_REGIONS));
 
-	dlog_verbose("    Total %u device regions found\n", i);
+	*count = i;
 
 	return MANIFEST_SUCCESS;
 }
@@ -552,15 +553,20 @@
 	ffa_node = root;
 	if (fdt_find_child(&ffa_node, &mem_region_node_name)) {
 		TRY(parse_ffa_memory_region_node(&ffa_node, vm->sp.mem_regions,
+						 &vm->sp.mem_region_count,
 						 &vm->sp.rxtx));
 	}
+	dlog_verbose("  Total %u memory regions found\n",
+		     vm->sp.mem_region_count);
 
 	/* Parse Device-regions */
 	ffa_node = root;
 	if (fdt_find_child(&ffa_node, &dev_region_node_name)) {
-		TRY(parse_ffa_device_region_node(&ffa_node,
-						 vm->sp.dev_regions));
+		TRY(parse_ffa_device_region_node(&ffa_node, vm->sp.dev_regions,
+						 &vm->sp.dev_region_count));
 	}
+	dlog_verbose("  Total %u device regions found\n",
+		     vm->sp.dev_region_count);
 
 	return MANIFEST_SUCCESS;
 }