msm:pm: Fix for race condition of starting cpu1 when cpu0 in PC.

There is a window where core sends ipi to secondary core and
wait for it to come online for 1 second. This would allow
core0 to go power collapse in a rare condition where core1
started booting and doesn't become online yet.

Fix this by not allowing power collapse on core0
if hot plug operation is in progress.

CRs-fixed: 545714.
Change-Id: I1ca503a2f09cd9a65c2fdcd41eb54466a1e486c5
Signed-off-by: Anil kumar mamidala <amami@codeaurora.org>
diff --git a/arch/arm/mach-msm/pm-8x60.c b/arch/arm/mach-msm/pm-8x60.c
index cd988dc..fc4c334 100644
--- a/arch/arm/mach-msm/pm-8x60.c
+++ b/arch/arm/mach-msm/pm-8x60.c
@@ -19,6 +19,7 @@
 #include <linux/interrupt.h>
 #include <linux/io.h>
 #include <linux/ktime.h>
+#include <linux/cpu.h>
 #include <linux/pm.h>
 #include <linux/pm_qos.h>
 #include <linux/smp.h>
@@ -801,7 +802,7 @@
 
 		switch (mode) {
 		case MSM_PM_SLEEP_MODE_POWER_COLLAPSE:
-			if (num_online_cpus() > 1) {
+			if (num_online_cpus() > 1 || cpu_maps_is_updating()) {
 				allow = false;
 				break;
 			}
diff --git a/include/linux/cpu.h b/include/linux/cpu.h
index 11dd01b..d7e2a5a 100644
--- a/include/linux/cpu.h
+++ b/include/linux/cpu.h
@@ -145,6 +145,7 @@
 int cpu_up(unsigned int cpu);
 void notify_cpu_starting(unsigned int cpu);
 extern void cpu_maps_update_begin(void);
+int cpu_maps_is_updating(void);
 extern void cpu_maps_update_done(void);
 
 #else	/* CONFIG_SMP */
@@ -164,6 +165,11 @@
 {
 }
 
+static inline int cpu_maps_is_updating(void)
+{
+	return 0;
+}
+
 static inline void cpu_maps_update_done(void)
 {
 }
diff --git a/kernel/cpu.c b/kernel/cpu.c
index fb4a5ac..fe76a32 100644
--- a/kernel/cpu.c
+++ b/kernel/cpu.c
@@ -30,6 +30,11 @@
 	mutex_lock(&cpu_add_remove_lock);
 }
 
+int cpu_maps_is_updating(void)
+{
+	return mutex_is_locked(&cpu_add_remove_lock);
+}
+
 void cpu_maps_update_done(void)
 {
 	mutex_unlock(&cpu_add_remove_lock);