fix(s2tt): RMM_DATA_CREATE_UNKNOWN sets RIPAS to RAM

According to the latest TF-RMM spec, RMM_DATA_CREATE_UNKNOWN does
not change the RIPAS of the s2tte where the data granule is mapped,
yet the current implementation sets it to RAM. This patch fixes
that by keeping the RIPAS state unaltered.

This patch also fixes a bug in smc_data_destroy in which the case
for HIPAS == ASSIGNED and RIPAS == DESTROYED was not taken into
account.

Signed-off-by: Javier Almansa Sobrino <javier.almansasobrino@arm.com>
Change-Id: I98330dedca6951ddb29a19e8e38760c0b31f01b1
diff --git a/lib/realm/src/s2tt.c b/lib/realm/src/s2tt.c
index c24c451..c36655c 100644
--- a/lib/realm/src/s2tt.c
+++ b/lib/realm/src/s2tt.c
@@ -459,6 +459,28 @@
 }
 
 /*
+ * Creates an assigned s2tte with output address @pa and the same
+ * RIPAS as passed on @s2tte.
+ */
+unsigned long s2tte_create_assigned_unchanged(unsigned long s2tte,
+					      unsigned long pa,
+					      long level)
+{
+	unsigned long current_ripas = s2tte & S2TTE_INVALID_RIPAS_MASK;
+
+	assert(level >= RTT_MIN_BLOCK_LEVEL);
+	assert(addr_is_level_aligned(pa, level));
+	assert(EXTRACT(S2TTE_INVALID_RIPAS, current_ripas) <=
+	       EXTRACT(S2TTE_INVALID_RIPAS, S2TTE_INVALID_RIPAS_DESTROYED));
+
+	if (current_ripas != S2TTE_INVALID_RIPAS_RAM) {
+		return (pa | S2TTE_INVALID_HIPAS_ASSIGNED | current_ripas);
+	}
+
+	return s2tte_create_assigned_ram(pa, level);
+}
+
+/*
  * Creates an unassigned_ns s2tte.
  */
 unsigned long s2tte_create_unassigned_ns(void)