refactor(realm): define PCIe helpers

This patch refactors the existing PCIe and DOE
helpers to define generic helpers to make them
reusable across more tests.

Signed-off-by: Soby Mathew <soby.mathew@arm.com>
Change-Id: I56a9f5c59715c7916f3f737ed6d3af94b0e3679f
diff --git a/include/lib/pcie/pcie.h b/include/lib/pcie/pcie.h
index 3ce6986..65e0202 100644
--- a/include/lib/pcie/pcie.h
+++ b/include/lib/pcie/pcie.h
@@ -99,6 +99,7 @@
 #define CC_SUB_SHIFT	16
 #define CC_BASE_SHIFT	24
 
+void pcie_init(void);
 void pcie_create_info_table(void);
 pcie_device_bdf_table_t *pcie_get_bdf_table(void);
 uint32_t pcie_find_capability(uint32_t bdf, uint32_t cid_type, uint32_t cid,
diff --git a/include/lib/pcie/pcie_doe.h b/include/lib/pcie/pcie_doe.h
index 4e12afd..bac0dbf 100644
--- a/include/lib/pcie/pcie_doe.h
+++ b/include/lib/pcie/pcie_doe.h
@@ -8,6 +8,11 @@
 #ifndef PCIE_DOE_H
 #define PCIE_DOE_H
 
+#include <stdbool.h>
+#include <stddef.h>
+#include <pcie.h>
+#include <test_helpers.h>
+
 /* DOE Extended Capability */
 #define DOE_CAP_ID			0x002E
 
@@ -86,10 +91,45 @@
 	uint8_t next_index;
 } pcie_doe_disc_resp_t;
 
+/* Skip test if DA is not supported in RMI features */
+#define CHECK_DA_SUPPORT_IN_RMI(_reg0)						\
+	do {									\
+		SKIP_TEST_IF_RME_NOT_SUPPORTED_OR_RMM_IS_TRP();			\
+		/* Get feature register0 */					\
+		if (host_rmi_features(0UL, &_reg0) != REALM_SUCCESS) {		\
+			ERROR("Failed to get RMI feat_reg0\n");			\
+			return TEST_RESULT_FAIL;				\
+		}								\
+										\
+		/* DA not supported in RMI features? */				\
+		if ((_reg0 & RMI_FEATURE_REGISTER_0_DA_EN) == 0UL) {		\
+			WARN("DA not in RMI features, skipping\n");		\
+			return TEST_RESULT_SKIPPED;				\
+		}								\
+	} while (false)
+
+#define SKIP_TEST_IF_DOE_NOT_SUPPORTED(_bdf, _doe_cap_base)			\
+	do {									\
+		/* Test PCIe DOE only for RME */				\
+		if (!get_armv9_2_feat_rme_support()) {				\
+			tftf_testcase_printf("FEAT_RME not supported\n");	\
+			return TEST_RESULT_SKIPPED;				\
+		}								\
+										\
+		pcie_init();							\
+		if (pcie_find_doe_device(&(_bdf), &(_doe_cap_base)) != 0) {		\
+			tftf_testcase_printf("PCIe DOE not supported\n");	\
+			return TEST_RESULT_SKIPPED;				\
+		}								\
+	} while (false)
+
 void print_doe_disc(pcie_doe_disc_resp_t *data);
 int pcie_doe_send_req(uint32_t header, uint32_t bdf, uint32_t doe_cap_base,
 			uint32_t *req_addr, uint32_t req_len);
 int pcie_doe_recv_resp(uint32_t bdf, uint32_t doe_cap_base,
 			uint32_t *resp_addr, uint32_t *resp_len);
+int pcie_doe_communicate(uint32_t header, uint32_t bdf, uint32_t doe_cap_base, void *req_buf,
+			 size_t req_sz, void *rsp_buf, size_t *rsp_sz);
+int pcie_find_doe_device(uint32_t *bdf_ptr, uint32_t *cap_base_ptr);
 
 #endif /* PCIE_DOE_H */