feat(hftest): primary and secondary VMs are FF-A endpoints

The test setup "primary_with_secondaries" VMs were not configured as
being FF-A endpoints in the hypervisor manifest. As a result, they had a
different load and initialization than those of SPs on top of the SPMC.
This patch makes them FF-A enabled, and they now possess a partition
manifest. The intent is to make secondary VMs as similar as possible to
SPs, such that we reduce discrepancies in instructing Secondary VMs and
SPs from the Primary VM (VM in charge of driving test execution).

The Secondary VMs were also assigned with a different uuid. The UUIDs
are to configure a similar setup using SPs instead of VMs. This
should allow for test partitions (dubbed services) to be referenced
through the uuid and not an ID. UUIDs are generic, whereas FF-A
IDs contain a bit related with the endpoint's world.

QEMU setups have been updated to run with 8 cores to reduce
descripancies with the FVP model run.

Change-Id: Iec356de859be6e586ef1c113e217eb11b29b6162
Signed-off-by: J-Alves <joao.alves@arm.com>
diff --git a/test/hftest/hftest.py b/test/hftest/hftest.py
index 140dccf..22eb5f9 100755
--- a/test/hftest/hftest.py
+++ b/test/hftest/hftest.py
@@ -225,7 +225,7 @@
             "timeout", "--foreground", time_limit,
             os.path.abspath("prebuilts/linux-x64/qemu/qemu-system-aarch64"),
             "-no-reboot", "-machine", "virt,virtualization=on,gic-version=3",
-            "-cpu", cpu, "-smp", "4", "-m", "1G",
+            "-cpu", cpu, "-smp", "8", "-m", "1G",
             "-nographic", "-nodefaults", "-serial", "stdio",
             "-d", "unimp", "-kernel", os.path.abspath(self.args.hypervisor),
         ]
diff --git a/test/vmapi/primary_with_secondaries/BUILD.gn b/test/vmapi/primary_with_secondaries/BUILD.gn
index a005bd0..07d76fa 100644
--- a/test/vmapi/primary_with_secondaries/BUILD.gn
+++ b/test/vmapi/primary_with_secondaries/BUILD.gn
@@ -109,9 +109,19 @@
   overlay = hftest_manifest_overlay
 }
 
-device_tree("secondary_dtb") {
-  source = "secondary.dts"
-  output = "$target_out_dir/secondary.dtb"
+device_tree("service1_dtb") {
+  source = "service1.dts"
+  output = "$target_out_dir/service1.dtb"
+}
+
+device_tree("service2_dtb") {
+  source = "service2.dts"
+  output = "$target_out_dir/service2.dtb"
+}
+
+device_tree("service3_dtb") {
+  source = "service3.dts"
+  output = "$target_out_dir/service3.dtb"
 }
 
 initrd("primary_with_secondaries_test") {
@@ -144,9 +154,19 @@
       "service_vm3.bin",
     ],
     [
-      "secondary.dtb",
-      ":secondary_dtb",
-      "secondary.dtb",
+      "service1.dtb",
+      ":service1_dtb",
+      "service1.dtb",
+    ],
+    [
+      "service2.dtb",
+      ":service2_dtb",
+      "service2.dtb",
+    ],
+    [
+      "service3.dtb",
+      ":service3_dtb",
+      "service3.dtb",
     ],
   ]
 }
diff --git a/test/vmapi/primary_with_secondaries/inc/primary_with_secondary.h b/test/vmapi/primary_with_secondaries/inc/primary_with_secondary.h
index 598819c..937d23a 100644
--- a/test/vmapi/primary_with_secondaries/inc/primary_with_secondary.h
+++ b/test/vmapi/primary_with_secondaries/inc/primary_with_secondary.h
@@ -10,6 +10,42 @@
 
 #include <stddef.h>
 
+#include "test/vmapi/ffa.h"
+
+/*
+ * FF-A UUIDs related to the test partitions providing test services to the
+ * Primary VM. These service partitions can either be SPs or VMs, and should
+ * be used only once for either an SP or VM.
+ * This allows for the PVM to communicate with the service partition, regardless
+ * of the ID, which has a bit related to the security state of the partition.
+ * The PVM should use the UUID to retrieve the FF-A ID of the partition, before
+ * attempting to communicate with it. Thus, the code for the PVM becomes
+ * portable between setups where the test service is either a VM or an SP.
+ */
+#define SERVICE1                                                        \
+	&(struct ffa_uuid)                                              \
+	{                                                               \
+		{                                                       \
+			0xb4b5671e, 0x4a904fe1, 0xb81ffb13, 0xdae1dacb, \
+		}                                                       \
+	}
+
+#define SERVICE2                                               \
+	&(struct ffa_uuid)                                     \
+	{                                                      \
+		{                                              \
+			0x5d45882e, 0xf637, 0xa720, 0xe8669dc, \
+		}                                              \
+	}
+
+#define SERVICE3                                             \
+	&(struct ffa_uuid)                                   \
+	{                                                    \
+		{                                            \
+			0xcbd4482f, 0xcbab, 0x4dba, 0x0738d, \
+		}                                            \
+	}
+
 #define SERVICE_VM1 (HF_VM_ID_OFFSET + 1)
 #define SERVICE_VM2 (HF_VM_ID_OFFSET + 2)
 #define SERVICE_VM3 (HF_VM_ID_OFFSET + 3)
diff --git a/test/vmapi/primary_with_secondaries/manifest.dts b/test/vmapi/primary_with_secondaries/manifest.dts
index bd07edd..33e07b1 100644
--- a/test/vmapi/primary_with_secondaries/manifest.dts
+++ b/test/vmapi/primary_with_secondaries/manifest.dts
@@ -17,27 +17,33 @@
 		};
 
 		vm2 {
+			is_ffa_partition;
+			hyp_loaded;
 			debug_name = "services1";
-			vcpu_count = <1>;
+			vcpu_count = <8>;
 			mem_size = <0x100000>;
 			kernel_filename = "services1";
-			fdt_filename = "secondary.dtb";
+			fdt_filename = "service1.dtb";
 		};
 
 		vm3 {
+			is_ffa_partition;
+			hyp_loaded;
 			debug_name = "services2";
-			vcpu_count = <1>;
+			vcpu_count = <8>;
 			mem_size = <0x100000>;
 			kernel_filename = "services2";
-			fdt_filename = "secondary.dtb";
+			fdt_filename = "service2.dtb";
 		};
 
 		vm4 {
+			is_ffa_partition;
+			hyp_loaded;
 			debug_name = "services3";
-			vcpu_count = <2>;
+			vcpu_count = <8>;
 			mem_size = <0x100000>;
 			kernel_filename = "services3";
-			fdt_filename = "secondary.dtb";
+			fdt_filename = "service3.dtb";
 		};
 	};
 };
diff --git a/test/vmapi/primary_with_secondaries/no_services.c b/test/vmapi/primary_with_secondaries/no_services.c
index 940413b..d06ee3c 100644
--- a/test/vmapi/primary_with_secondaries/no_services.c
+++ b/test/vmapi/primary_with_secondaries/no_services.c
@@ -75,9 +75,9 @@
 	EXPECT_EQ(partitions[0].vm_id, hf_vm_get_id());
 
 	/* The first two secondary VMs should have 1 vCPU, the other one 2. */
-	EXPECT_EQ(partitions[1].vcpu_count, 1);
-	EXPECT_EQ(partitions[2].vcpu_count, 1);
-	EXPECT_EQ(partitions[3].vcpu_count, 2);
+	EXPECT_EQ(partitions[1].vcpu_count, 8);
+	EXPECT_EQ(partitions[2].vcpu_count, 8);
+	EXPECT_EQ(partitions[3].vcpu_count, 8);
 
 	EXPECT_EQ(ffa_rx_release().func, FFA_SUCCESS_32);
 }
@@ -130,9 +130,9 @@
 	EXPECT_EQ(partitions[0].vm_id, hf_vm_get_id());
 
 	/* The first two secondary VMs should have 1 vCPU, the other one 2. */
-	EXPECT_EQ(partitions[1].vcpu_count, 1);
-	EXPECT_EQ(partitions[2].vcpu_count, 1);
-	EXPECT_EQ(partitions[3].vcpu_count, 2);
+	EXPECT_EQ(partitions[1].vcpu_count, 8);
+	EXPECT_EQ(partitions[2].vcpu_count, 8);
+	EXPECT_EQ(partitions[3].vcpu_count, 8);
 
 	EXPECT_EQ(ffa_rx_release().func, FFA_SUCCESS_32);
 }
diff --git a/test/vmapi/primary_with_secondaries/secondary.dts b/test/vmapi/primary_with_secondaries/secondary.dts
deleted file mode 100644
index 12a762e..0000000
--- a/test/vmapi/primary_with_secondaries/secondary.dts
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright 2020 The Hafnium Authors.
- *
- * Use of this source code is governed by a BSD-style
- * license that can be found in the LICENSE file or at
- * https://opensource.org/licenses/BSD-3-Clause.
- */
-
-/* A minimal FDT for the unit tests to work. */
-
-/dts-v1/;
-
-/ {
-        #size-cells = <0x02>;
-        #address-cells = <0x02>;
-        compatible = "linux,dummy-virt";
-
-        psci {
-                #size-cells = <0x01>;
-                #address-cells = <0x01>;
-                migrate = <0xc4000005>;
-                cpu_on = <0xc4000003>;
-                cpu_off = <0x84000002>;
-                cpu_suspend = <0xc4000001>;
-                method = "smc";
-                compatible = "arm,psci-1.1\0arm,psci";
-        };
-
-        cpus {
-                #size-cells = <0>;
-                #address-cells = <1>;
-
-                cpu@0 {
-                        reg = <0>;
-                        enable-method = "psci";
-                        compatible = "arm,cortex-a57";
-                        device_type = "cpu";
-                };
-        };
-};
diff --git a/test/vmapi/primary_with_secondaries/service1.dts b/test/vmapi/primary_with_secondaries/service1.dts
new file mode 100644
index 0000000..78b00af
--- /dev/null
+++ b/test/vmapi/primary_with_secondaries/service1.dts
@@ -0,0 +1,26 @@
+/*
+ * Copyright 2022 The Hafnium Authors.
+ *
+ * Use of this source code is governed by a BSD-style
+ * license that can be found in the LICENSE file or at
+ * https://opensource.org/licenses/BSD-3-Clause.
+ */
+
+/dts-v1/;
+
+/ {
+        compatible = "arm,ffa-manifest-1.0";
+        debug_name = "Service1";
+
+        /* FF-A Properties */
+        ffa-version = <0x00010001>; /* 31:16 - Major, 15:0 - Minor */
+        uuid = <0xb4b5671e 0x4a904fe1 0xb81ffb13 0xdae1dacb>;
+        execution-ctx-count = <8>;
+        exception-level = <0>; /* EL1 */
+        execution-state = <0>; /* AARCH64 */
+        load-address = <0x90000000>; /* To make parsing of manifest happy. it is not yet used. */
+        entrypoint-offset = <0x0>;
+        xlat-granule = <0>; /* 4KiB */
+        messaging-method = <0x7>; /* Supports direct and indirect requests. */
+        notification-support; /* Receipt of notifications. */
+};
diff --git a/test/vmapi/primary_with_secondaries/service2.dts b/test/vmapi/primary_with_secondaries/service2.dts
new file mode 100644
index 0000000..a9e6f02
--- /dev/null
+++ b/test/vmapi/primary_with_secondaries/service2.dts
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2022 The Hafnium Authors.
+ *
+ * Use of this source code is governed by a BSD-style
+ * license that can be found in the LICENSE file or at
+ * https://opensource.org/licenses/BSD-3-Clause.
+ */
+
+/dts-v1/;
+
+/ {
+        compatible = "arm,ffa-manifest-1.0";
+        debug_name = "Service2";
+
+        /* FF-A Properties */
+        ffa-version = <0x00010001>; /* 31:16 - Major, 15:0 - Minor */
+        uuid = <0x5d45882e 0xf637 0xa720 0xe8669dc>;
+        execution-ctx-count = <8>;
+        exception-level = <0>; /* EL1 */
+        execution-state = <0>; /* AARCH64 */
+        load-address = <0x90000000>; /* To make parsing of manifest happy. it is not yet used. */
+        entrypoint-offset = <0x0>;
+        xlat-granule = <0>; /* 4KiB */
+        messaging-method = <0x7>; /* Supports direct and indirect requests. */
+        notification-support; /* Receipt of notifications. */
+
+};
diff --git a/test/vmapi/primary_with_secondaries/service3.dts b/test/vmapi/primary_with_secondaries/service3.dts
new file mode 100644
index 0000000..2b39af0
--- /dev/null
+++ b/test/vmapi/primary_with_secondaries/service3.dts
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2022 The Hafnium Authors.
+ *
+ * Use of this source code is governed by a BSD-style
+ * license that can be found in the LICENSE file or at
+ * https://opensource.org/licenses/BSD-3-Clause.
+ */
+
+/dts-v1/;
+
+/ {
+        compatible = "arm,ffa-manifest-1.0";
+        debug_name = "Service3";
+
+        /* FF-A Properties */
+        ffa-version = <0x00010001>; /* 31:16 - Major, 15:0 - Minor */
+        uuid = <0xcbd4482f 0xcbab 0x4dba 0x0738d>;
+        execution-ctx-count = <8>;
+        exception-level = <0>; /* EL1 */
+        execution-state = <0>; /* AARCH64 */
+        load-address = <0x90000000>; /* To make parsing of manifest happy. it is not yet used. */
+        entrypoint-offset = <0x0>;
+        xlat-granule = <0>; /* 4KiB */
+        messaging-method = <0x7>; /* Supports direct and indirect requests. */
+        notification-support; /* Receipt of notifications. */
+
+};