Add tests for Errata management firmware interface.
Add tests to confirm that the em_version, em_features and
em_cpu_erratum_features calls conform to the errata abi spec.
Signed-off-by: Sona Mathew <SonaRebecca.Mathew@arm.com>
Change-Id: I8395026acc004a10d8c2c17ec689f4e0752143d8
diff --git a/include/lib/aarch32/arch.h b/include/lib/aarch32/arch.h
index 53ef4ba..6f41db9 100644
--- a/include/lib/aarch32/arch.h
+++ b/include/lib/aarch32/arch.h
@@ -20,6 +20,8 @@
#define MIDR_REV_BITS U(4)
#define MIDR_PN_MASK U(0xfff)
#define MIDR_PN_SHIFT U(4)
+#define MIDR_VAR_MASK U(0xf0)
+#define MIDR_REV_MASK U(0xf)
/*******************************************************************************
* MPIDR macros
diff --git a/include/lib/aarch64/arch.h b/include/lib/aarch64/arch.h
index 0e2903e..f3ff0ca 100644
--- a/include/lib/aarch64/arch.h
+++ b/include/lib/aarch64/arch.h
@@ -16,7 +16,7 @@
#define MIDR_IMPL_SHIFT U(0x18)
#define MIDR_VAR_SHIFT U(20)
#define MIDR_VAR_BITS U(4)
-#define MIDR_VAR_MASK U(0xf)
+#define MIDR_VAR_MASK U(0xf0)
#define MIDR_REV_SHIFT U(0)
#define MIDR_REV_BITS U(4)
#define MIDR_REV_MASK U(0xf)
diff --git a/include/lib/aarch64/arch_helpers.h b/include/lib/aarch64/arch_helpers.h
index 7c3ffc5..b7c0418 100644
--- a/include/lib/aarch64/arch_helpers.h
+++ b/include/lib/aarch64/arch_helpers.h
@@ -397,6 +397,8 @@
#define clr_cntp_ctl_enable(x) ((x) &= ~(U(1) << CNTP_CTL_ENABLE_SHIFT))
#define clr_cntp_ctl_imask(x) ((x) &= ~(U(1) << CNTP_CTL_IMASK_SHIFT))
+#define read_midr() read_midr_el1()
+
DEFINE_SYSREG_RW_FUNCS(tpidr_el3)
DEFINE_SYSREG_RW_FUNCS(cntvoff_el2)
diff --git a/include/runtime_services/errata_abi.h b/include/runtime_services/errata_abi.h
new file mode 100644
index 0000000..363564e
--- /dev/null
+++ b/include/runtime_services/errata_abi.h
@@ -0,0 +1,87 @@
+/*
+ * Copyright (c) 2023, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+/*
+ * Definitions related to the Errata ABI feature
+ * as per the SMC Calling Convention.
+ */
+
+#ifndef __ERRATA_ABI_H__
+#define __ERRATA_ABI_H__
+
+#ifndef __ASSEMBLY__
+#include <stdbool.h>
+#include <stdint.h>
+#include <tftf_lib.h>
+#include <platform_def.h>
+#endif
+
+/*******************************************************************************
+ * Macro to create the array entry for EM_ABI_functions[]
+ ******************************************************************************/
+#define DEFINE_EM_FUNC(_func_id, _mandatory) \
+ { EM_##_func_id, _mandatory, "SMC_" # _func_id }
+
+/*******************************************************************************
+ * Errata ABI feature supported function ids
+ ******************************************************************************/
+#define EM_VERSION 0x840000F0
+#define EM_FEATURES 0x840000F1
+#define EM_CPU_ERRATUM_FEATURES 0x840000F2
+
+/*
+ * Number of EM ABI calls defined in the specification.
+ */
+#define TOTAL_ABI_CALLS (3U)
+
+#define ERRATA_COUNT (17U)
+
+typedef struct {
+ uint32_t id;
+ bool mandatory;
+ const char *str;
+} em_function_t;
+
+typedef struct em_cpu_errata {
+ int em_errata_id;
+ unsigned int rxpx_low;
+ unsigned int rxpx_high;
+} em_cpu_errata_t;
+
+typedef struct em_cpu{
+ uint16_t cpu_pn;
+ em_cpu_errata_t cpu_errata[ERRATA_COUNT];
+}em_cpu_t;
+
+extern const em_function_t em_functions[TOTAL_ABI_CALLS];
+int32_t tftf_em_abi_version(void);
+bool tftf_em_abi_feature_implemented(uint32_t id);
+smc_ret_values tftf_em_abi_cpu_feature_implemented(uint32_t cpu_erratum, uint32_t forward_flag);
+
+
+#define IN_RANGE(x, y, z) (((x >= y) && (x <= z)) ? true : false)
+
+/*******************************************************************************
+ * Errata ABI Version
+ ******************************************************************************/
+#define EM_MAJOR_VER_SHIFT (16)
+#define EM_MAJOR_VER_MASK (0xFFFF)
+#define EM_MINOR_VER_SHIFT (0)
+#define EM_MINOR_VER_MASK (0xFFFF)
+#define EM_ABI_VERSION(major, minor) (((major & EM_MAJOR_VER_MASK) << EM_MAJOR_VER_SHIFT) \
+ | ((minor & EM_MINOR_VER_MASK) << EM_MINOR_VER_SHIFT))
+/*******************************************************************************
+ * Error codes
+ ******************************************************************************/
+#define EM_HIGHER_EL_MITIGATION (3)
+#define EM_NOT_AFFECTED (2)
+#define EM_AFFECTED (1)
+#define EM_SUCCESS (0)
+#define EM_NOT_SUPPORTED (-1)
+#define EM_INVALID_PARAMETERS (-2)
+#define EM_UNKNOWN_ERRATUM (-3)
+#endif /* __ERRATA_ABI_H__ */
+