Reduce deep nesting of header files

Reduce the number of header files included from other header
files as much as possible without splitting the files. Use forward
declarations where possible. This allows removal of some unnecessary
"#ifndef __ASSEMBLY__" statements.

Also, review the .c and .S files for which header files really need
including and reorder the #include statements alphabetically.

Fixes ARM-software/tf-issues#31

Change-Id: Iec92fb976334c77453e010b60bcf56f3be72bd3e
diff --git a/plat/fvp/aarch64/bl1_plat_helpers.S b/plat/fvp/aarch64/bl1_plat_helpers.S
index 64f230d..92075ea 100644
--- a/plat/fvp/aarch64/bl1_plat_helpers.S
+++ b/plat/fvp/aarch64/bl1_plat_helpers.S
@@ -29,9 +29,9 @@
  */
 
 #include <arch.h>
-#include <platform.h>
-#include <gic_v2.h>
 #include <asm_macros.S>
+#include <gic_v2.h>
+#include <platform.h>
 #include "../drivers/pwrc/fvp_pwrc.h"
 
 	.globl	platform_get_entrypoint
diff --git a/plat/fvp/aarch64/plat_common.c b/plat/fvp/aarch64/plat_common.c
index 40e6b32..c8e529d 100644
--- a/plat/fvp/aarch64/plat_common.c
+++ b/plat/fvp/aarch64/plat_common.c
@@ -28,9 +28,12 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include <assert.h>
+#include <arch.h>
 #include <arch_helpers.h>
+#include <assert.h>
+#include <bl_common.h>
 #include <debug.h>
+#include <mmio.h>
 #include <platform.h>
 #include <xlat_tables.h>
 
diff --git a/plat/fvp/aarch64/plat_helpers.S b/plat/fvp/aarch64/plat_helpers.S
index ab826f4..0057903 100644
--- a/plat/fvp/aarch64/plat_helpers.S
+++ b/plat/fvp/aarch64/plat_helpers.S
@@ -29,8 +29,9 @@
  */
 
 #include <arch.h>
-#include <platform.h>
 #include <asm_macros.S>
+#include <bl_common.h>
+#include <platform.h>
 
 	.globl	plat_report_exception
 
diff --git a/plat/fvp/bl1_plat_setup.c b/plat/fvp/bl1_plat_setup.c
index 818c4e3..e92303d 100644
--- a/plat/fvp/bl1_plat_setup.c
+++ b/plat/fvp/bl1_plat_setup.c
@@ -28,12 +28,14 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include <assert.h>
 #include <arch_helpers.h>
-#include <platform.h>
+#include <assert.h>
+#include <bl_common.h>
 #include <bl1.h>
 #include <console.h>
 #include <cci400.h>
+#include <mmio.h>
+#include <platform.h>
 
 /*******************************************************************************
  * Declarations of linker defined symbols which will help us find the layout
diff --git a/plat/fvp/bl2_plat_setup.c b/plat/fvp/bl2_plat_setup.c
index 8517497..a4960aa 100644
--- a/plat/fvp/bl2_plat_setup.c
+++ b/plat/fvp/bl2_plat_setup.c
@@ -28,12 +28,12 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include <assert.h>
 #include <arch_helpers.h>
-#include <platform.h>
-#include <bl2.h>
+#include <assert.h>
 #include <bl_common.h>
+#include <bl2.h>
 #include <console.h>
+#include <platform.h>
 
 /*******************************************************************************
  * Declarations of linker defined symbols which will help us find the layout
diff --git a/plat/fvp/bl31_plat_setup.c b/plat/fvp/bl31_plat_setup.c
index 5abe236..aa7b2d8 100644
--- a/plat/fvp/bl31_plat_setup.c
+++ b/plat/fvp/bl31_plat_setup.c
@@ -28,9 +28,13 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include <platform.h>
 #include <arch.h>
+#include <bl_common.h>
+#include <bl31.h>
 #include <console.h>
+#include <mmio.h>
+#include <platform.h>
+#include <stddef.h>
 #include "drivers/pwrc/fvp_pwrc.h"
 
 /*******************************************************************************
diff --git a/plat/fvp/bl32_plat_setup.c b/plat/fvp/bl32_plat_setup.c
index 3226ea2..b71800e 100644
--- a/plat/fvp/bl32_plat_setup.c
+++ b/plat/fvp/bl32_plat_setup.c
@@ -28,13 +28,11 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include <string.h>
-#include <assert.h>
 #include <arch_helpers.h>
-#include <platform.h>
-#include <bl32.h>
 #include <bl_common.h>
+#include <bl32.h>
 #include <console.h>
+#include <platform.h>
 
 /*******************************************************************************
  * Declarations of linker defined symbols which will help us find the layout
diff --git a/plat/fvp/drivers/pwrc/fvp_pwrc.c b/plat/fvp/drivers/pwrc/fvp_pwrc.c
index 175d41c..7a7f516 100644
--- a/plat/fvp/drivers/pwrc/fvp_pwrc.c
+++ b/plat/fvp/drivers/pwrc/fvp_pwrc.c
@@ -28,13 +28,8 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include <string.h>
-#include <stdio.h>
-#include <errno.h>
-#include <assert.h>
-#include <arch_helpers.h>
-#include <platform.h>
 #include <bakery_lock.h>
+#include <mmio.h>
 #include "fvp_pwrc.h"
 
 /*
diff --git a/plat/fvp/plat_gic.c b/plat/fvp/plat_gic.c
index be892ac..8457af1 100644
--- a/plat/fvp/plat_gic.c
+++ b/plat/fvp/plat_gic.c
@@ -28,12 +28,12 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include <stdint.h>
 #include <arch_helpers.h>
-#include <platform.h>
+#include <debug.h>
 #include <gic_v2.h>
 #include <gic_v3.h>
-#include <debug.h>
+#include <platform.h>
+#include <stdint.h>
 
 
 /*******************************************************************************
diff --git a/plat/fvp/plat_io_storage.c b/plat/fvp/plat_io_storage.c
index 371f567..3727d26 100644
--- a/plat/fvp/plat_io_storage.c
+++ b/plat/fvp/plat_io_storage.c
@@ -29,15 +29,15 @@
  */
 
 #include <assert.h>
-#include <string.h>
-#include <platform.h>
-#include <io_storage.h>
+#include <debug.h>
 #include <io_driver.h>
-#include <io_semihosting.h>
-#include <semihosting.h>	/* For FOPEN_MODE_... */
 #include <io_fip.h>
 #include <io_memmap.h>
-#include <debug.h>
+#include <io_storage.h>
+#include <io_semihosting.h>
+#include <platform.h>
+#include <semihosting.h>	/* For FOPEN_MODE_... */
+#include <string.h>
 
 /* IO devices */
 static io_plat_data_t io_data;
diff --git a/plat/fvp/plat_pm.c b/plat/fvp/plat_pm.c
index da940c1..c80d315 100644
--- a/plat/fvp/plat_pm.c
+++ b/plat/fvp/plat_pm.c
@@ -28,18 +28,12 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include <stdio.h>
-#include <string.h>
-#include <assert.h>
 #include <arch_helpers.h>
-#include <console.h>
-#include <platform.h>
-#include <bl_common.h>
-#include <bl31.h>
+#include <assert.h>
 #include <bakery_lock.h>
 #include <cci400.h>
-#include <gic_v2.h>
-/* Only included for error codes */
+#include <mmio.h>
+#include <platform.h>
 #include <psci.h>
 #include "drivers/pwrc/fvp_pwrc.h"
 
diff --git a/plat/fvp/plat_topology.c b/plat/fvp/plat_topology.c
index 99f3259..04b409e 100644
--- a/plat/fvp/plat_topology.c
+++ b/plat/fvp/plat_topology.c
@@ -28,7 +28,6 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include <string.h>
 #include <assert.h>
 #include <platform.h>
 /* TODO: Reusing psci error codes & state information. Get our own! */
diff --git a/plat/fvp/platform.h b/plat/fvp/platform.h
index 098f499..1ffdc98 100644
--- a/plat/fvp/platform.h
+++ b/plat/fvp/platform.h
@@ -32,10 +32,6 @@
 #define __PLATFORM_H__
 
 #include <arch.h>
-#include <mmio.h>
-#include <psci.h>
-#include <bl_common.h>
-#include <io_storage.h>
 
 
 /*******************************************************************************
@@ -340,12 +336,22 @@
 
 #ifndef __ASSEMBLY__
 
+#include <stdint.h>
+
+
 typedef volatile struct mailbox {
 	unsigned long value
 	__attribute__((__aligned__(CACHE_WRITEBACK_GRANULE)));
 } mailbox_t;
 
 /*******************************************************************************
+ * Forward declarations
+ ******************************************************************************/
+struct plat_pm_ops;
+struct meminfo;
+struct io_dev_info;
+
+/*******************************************************************************
  * Function and variable prototypes
  ******************************************************************************/
 extern unsigned long *bl1_normal_ram_base;
@@ -364,11 +370,11 @@
 extern void bl1_plat_arch_setup(void);
 extern void bl2_plat_arch_setup(void);
 extern void bl31_plat_arch_setup(void);
-extern int platform_setup_pm(plat_pm_ops_t **);
+extern int platform_setup_pm(struct plat_pm_ops **);
 extern unsigned int platform_get_core_pos(unsigned long mpidr);
 extern void disable_mmu(void);
 extern void enable_mmu(void);
-extern void configure_mmu(meminfo_t *,
+extern void configure_mmu(struct meminfo *,
 			  unsigned long,
 			  unsigned long,
 			  unsigned long,
@@ -395,7 +401,7 @@
 /* Declarations for plat_io_storage.c */
 extern void io_setup(void);
 extern int plat_get_image_source(const char *image_name,
-		io_dev_handle *dev_handle, void **image_spec);
+		struct io_dev_info **dev_handle, void **image_spec);
 
 /* Declarations for plat_security.c */
 extern void plat_security_setup(void);