platform: msm_shared: Wait for smd channel to be closed.

Appsbl sends channel close signal to rpm and jumps to hlos
without waiting for the channel to be actually closed.
Due to this hlos fails to communicate to rpm over the same
channel. To ensure a proper hand-off make sure to wait for
RPM-SMD channel to be closed before jumping to hlos.

Change-Id: I59efd38b52ef704e97a5e4abf7d2e507e6c7efb9
diff --git a/platform/msm_shared/smd.c b/platform/msm_shared/smd.c
index 980cda0..509ab92 100644
--- a/platform/msm_shared/smd.c
+++ b/platform/msm_shared/smd.c
@@ -30,6 +30,7 @@
 #include <smd.h>
 #include <smem.h>
 #include <debug.h>
+#include <kernel/event.h>
 #include <platform/irqs.h>
 #include <platform/iomap.h>
 #include <platform/interrupts.h>
@@ -38,7 +39,7 @@
 #include <bits.h>
 
 smd_channel_alloc_entry_t *smd_channel_alloc_entry;
-
+static event_t smd_closed;
 
 static void smd_write_state(smd_channel_info_t *ch, uint32_t state)
 {
@@ -139,9 +140,12 @@
 
 void smd_uninit(smd_channel_info_t *ch)
 {
+	event_init(&smd_closed, false, EVENT_FLAG_AUTOUNSIGNAL);
 	smd_set_state(ch, SMD_SS_CLOSING, 1);
 
 	smd_notify_rpm();
+	/* Wait for the SMD-RPM channel to be closed */
+	event_wait(&smd_closed);
 }
 
 bool is_channel_open(smd_channel_info_t *ch)
@@ -390,6 +394,7 @@
 	if(ch->current_state == SMD_SS_CLOSED)
 	{
 		free(smd_channel_alloc_entry);
+		event_signal(&smd_closed, false);
 		return INT_NO_RESCHEDULE;
 	}