Refactor Statistical Profiling Extensions implementation

Factor out SPE operations in a separate file.  Use the publish
subscribe framework to drain the SPE buffers before entering secure
world.  Additionally, enable SPE before entering normal world.

A side effect of this change is that the profiling buffers are now
only drained when a transition from normal world to secure world
happens.  Previously they were drained also on return from secure
world, which is unnecessary as SPE is not supported in S-EL1.

Change-Id: I17582c689b4b525770dbb6db098b3a0b5777b70a
Signed-off-by: Dimitris Papastamos <dimitris.papastamos@arm.com>
diff --git a/plat/arm/board/fvp/fvp_pm.c b/plat/arm/board/fvp/fvp_pm.c
index 0ab5b82..13bd8f2 100644
--- a/plat/arm/board/fvp/fvp_pm.c
+++ b/plat/arm/board/fvp/fvp_pm.c
@@ -14,6 +14,7 @@
 #include <plat_arm.h>
 #include <platform.h>
 #include <psci.h>
+#include <spe.h>
 #include <v2m_def.h>
 #include "drivers/pwrc/fvp_pwrc.h"
 #include "fvp_def.h"
@@ -57,7 +58,7 @@
 	 * On power down we need to disable statistical profiling extensions
 	 * before exiting coherency.
 	 */
-	arm_disable_spe();
+	spe_disable();
 #endif
 
 	/* Disable coherency if this cluster is to be turned off */
diff --git a/plat/arm/common/aarch64/arm_helpers.S b/plat/arm/common/aarch64/arm_helpers.S
index b53e60d..9d3a108 100644
--- a/plat/arm/common/aarch64/arm_helpers.S
+++ b/plat/arm/common/aarch64/arm_helpers.S
@@ -12,7 +12,6 @@
 	.globl	plat_crash_console_putc
 	.globl	plat_crash_console_flush
 	.globl	platform_mem_init
-	.globl	arm_disable_spe
 
 
 	/* -----------------------------------------------------
@@ -88,34 +87,6 @@
 	ret
 endfunc platform_mem_init
 
-	/* -----------------------------------------------------
-	 * void arm_disable_spe (void);
-	 * -----------------------------------------------------
-	 */
-#if ENABLE_SPE_FOR_LOWER_ELS
-func arm_disable_spe
-	/* Detect if SPE is implemented */
-	mrs	x0, id_aa64dfr0_el1
-	ubfx	x0, x0, #ID_AA64DFR0_PMS_SHIFT, #ID_AA64DFR0_PMS_LENGTH
-	cmp	x0, #0x1
-	b.ne	1f
-
-	/* Drain buffered data */
-	.arch	armv8.2-a+profile
-	psb	csync
-	dsb	nsh
-
-	/* Disable Profiling Buffer */
-	mrs	x0, pmblimitr_el1
-	bic	x0, x0, #1
-	msr	pmblimitr_el1, x0
-	isb
-	.arch	armv8-a
-1:
-	ret
-endfunc arm_disable_spe
-#endif
-
 /*
  * Need to use coherent stack when ARM Cryptocell is used to autheticate images
  * since Cryptocell uses DMA to transfer data and it is not coherent with the