feat(mm): fix FEAT_LPA workaround

In commit da72173c3721 ("feat(mm): handle 52-bit PA (FEAT_LPA/2) as
48-bit.") the PA size is downgraded to 48 bits if a 52-bit PA
configuration is found. However, this isn't enough, for complete
downgrade the tcr_el2.ps field must be updated accordingly. So fix this
by setting tcr_el2.ps to 0x5 when downgrading to 48-bit PA size.

Introduce arch_mm_get_pa_range which returns the pa range index as read
from the ID register and arch_mm_get_pa_bits converting the index to the
implemented physical address size in bits. The 48 bits restriction when
FEAT_LPA is implemented is localized to arch_mm_get_pa_range.

Fix an issue with TCR_EL2 when VHE is implemented, where the physical
address size is forced to 40 bits.

Fixes: da72173c3721 ("feat(mm): handle 52-bit PA (FEAT_LPA/2) as 48-bit.")
Reported-by: Jens Wiklander <jens.wiklander@linaro.org>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
Signed-off-by: Olivier Deprez <olivier.deprez@arm.com>
Change-Id: Ibd1a5fdf4f0d6d7b0b5e5b4ed588a12a1c97e76e
diff --git a/inc/hf/arch/mm.h b/inc/hf/arch/mm.h
index c524ef7..ed7d690 100644
--- a/inc/hf/arch/mm.h
+++ b/inc/hf/arch/mm.h
@@ -181,9 +181,14 @@
 void arch_mm_sync_table_writes(void);
 
 /**
+ * Returns the maximum supported PA Range index.
+ */
+uint64_t arch_mm_get_pa_range(void);
+
+/**
  * Returns the maximum supported PA Range in bits.
  */
-uint32_t arch_mm_get_pa_range(void);
+uint32_t arch_mm_get_pa_bits(uint64_t pa_range);
 
 /**
  * Returns VTCR_EL2 configured in arch_mm_init.