fix(realm): make PCIe tests default for testing

This patch moves the PCIe DOE test to the default realm world
testsuite.

Also fixes some build issues and hardens the PCIe functions.

Note that FVP_Base_RevC model needs to have the following
options enabled for the PCIe tests to work :

    -C pci.pcie_rc.ahci0.endpoint.doe_supported=1
    -C pci.pcie_rc.ahci0.endpoint.ide_supported=1


Change-Id: Icfd6b68799b0bacb44299c6a3cf99a3c425f833d
Signed-off-by: Soby Mathew <soby.mathew@arm.com>
diff --git a/lib/pcie/pcie.c b/lib/pcie/pcie.c
index c3906d5..5f8c97f 100644
--- a/lib/pcie/pcie.c
+++ b/lib/pcie/pcie.c
@@ -11,13 +11,12 @@
 #include <mmio.h>
 #include <pcie.h>
 #include <pcie_spec.h>
+#include <platform.h>
 #include <tftf_lib.h>
 
-#include <platform_pcie.h>
-
 #define PCIE_DEBUG	VERBOSE
 
-const pcie_info_table_t *g_pcie_info_table;
+const struct pcie_info_table *g_pcie_info_table;
 pcie_device_bdf_table_t *g_pcie_bdf_table;
 
 pcie_device_bdf_table_t pcie_bdf_table[PCIE_DEVICE_BDF_TABLE_SZ];
@@ -256,6 +255,8 @@
 		return 1;
 	}
 
+	assert(g_pcie_bdf_table != NULL);
+
 	while (index < g_pcie_bdf_table->num_entries) {
 		*rp_bdf = g_pcie_bdf_table->device[index++].bdf;
 
@@ -294,6 +295,8 @@
 	uint32_t bdf, rp_bdf;
 	pcie_device_bdf_table_t *bdf_tbl_ptr = g_pcie_bdf_table;
 
+	assert(bdf_tbl_ptr != NULL);
+
 	for (unsigned int tbl_index = 0; tbl_index < bdf_tbl_ptr->num_entries;
 								tbl_index++) {
 		bdf = bdf_tbl_ptr->device[tbl_index].bdf;
@@ -317,6 +320,8 @@
  */
 pcie_device_bdf_table_t *pcie_get_bdf_table(void)
 {
+	assert(g_pcie_bdf_table != NULL);
+
 	return g_pcie_bdf_table;
 }
 
@@ -336,6 +341,8 @@
 	assert(g_pcie_bdf_table != NULL);
 
 	g_pcie_bdf_table->num_entries = 0;
+
+	assert(g_pcie_info_table != NULL);
 	assert(g_pcie_info_table->num_entries != 0);
 
 	for (ecam_index = 0; ecam_index < g_pcie_info_table->num_entries; ecam_index++) {
@@ -420,6 +427,8 @@
 	uint32_t reg_value;
 	uintptr_t ecam_base = 0;
 
+	assert(g_pcie_info_table != NULL);
+
 	while (ecam_index < g_pcie_info_table->num_entries) {
 		/* Derive ECAM specific information */
 		const pcie_info_block_t *block = &g_pcie_info_table->block[ecam_index];
@@ -462,13 +471,15 @@
 	uint32_t ecam_index = 0;
 	uint32_t ecam_base, ecam_start_bus, ecam_end_bus;
 	pcie_device_bdf_table_t *bdf_tbl_ptr = g_pcie_bdf_table;
-	uint32_t num_rciep = 0, num_rcec = 0;
-	uint32_t num_iep = 0, num_irp = 0;
-	uint32_t num_ep = 0, num_rp = 0;
-	uint32_t num_dp = 0, num_up = 0;
-	uint32_t num_pcie_pci = 0, num_pci_pcie = 0;
+	uint32_t num_rciep __unused = 0, num_rcec __unused = 0;
+	uint32_t num_iep __unused = 0, num_irp __unused = 0;
+	uint32_t num_ep __unused = 0, num_rp __unused = 0;
+	uint32_t num_dp __unused = 0, num_up __unused = 0;
+	uint32_t num_pcie_pci __unused = 0, num_pci_pcie __unused = 0;
 	uint32_t bdf_counter;
 
+	assert(bdf_tbl_ptr != NULL);
+
 	if (bdf_tbl_ptr->num_entries == 0) {
 		INFO("BDF Table: No RCiEP or iEP found\n");
 		return;
@@ -525,6 +536,8 @@
 	INFO("Number of PCI/PCIe Bridge: %u\n", num_pci_pcie);
 	INFO("Number of PCIe/PCI Bridge: %u\n", num_pcie_pci);
 
+	assert(g_pcie_info_table != NULL);
+
 	while (ecam_index < g_pcie_info_table->num_entries) {
 
 		/* Derive ECAM specific information */
@@ -540,7 +553,7 @@
 
 		while (tbl_index < bdf_tbl_ptr->num_entries) {
 			uint32_t seg_num, bus_num, dev_num, func_num;
-			uint32_t device_id, vendor_id, reg_value;
+			uint32_t device_id __unused, vendor_id __unused, reg_value;
 			uint32_t bdf, dev_ecam_base;
 
 			bdf = bdf_tbl_ptr->device[tbl_index++].bdf;
@@ -588,12 +601,18 @@
 	INFO("Creating PCIe info table\n");
 
 	g_pcie_info_table = plat_pcie_get_info_table();
+	if (g_pcie_info_table == NULL) {
+		ERROR("PCIe info not returned by platform\n");
+		panic();
+	}
+
 	g_pcie_bdf_table = pcie_bdf_table;
 
 	num_ecam = g_pcie_info_table->num_entries;
 	INFO("Number of ECAM regions   : %u\n", num_ecam);
-	if (num_ecam == 0) {
-		return;
+	if ((num_ecam == 0) || (num_ecam > MAX_PCIE_INFO_ENTRIES)) {
+		ERROR("PCIe info entries invalid\n");
+		panic();
 	}
 	pcie_create_device_bdf_table();
 	pcie_print_device_info();