goldfish/events_device.c: Properly restore IRQ on load.

When restoring a snapshot, the state of the IRQ was not correctly
restored, which could sometimes end up in the inability for the
restored VM to accept any input events.

This patch fixes the issue by always setting the IRQ to the
appropriate level after the load.

+ Formatting

Change-Id: I6dde9a918536d8bb3269e92ec8984defb337a384
diff --git a/hw/android/goldfish/events_device.c b/hw/android/goldfish/events_device.c
index 6672678..4567ab3 100644
--- a/hw/android/goldfish/events_device.c
+++ b/hw/android/goldfish/events_device.c
@@ -116,7 +116,24 @@
     if (version_id != EVENTS_STATE_SAVE_VERSION)
         return -1;
 
-    return qemu_get_struct(f, events_state_fields, s);
+    if (qemu_get_struct(f, events_state_fields, s) < 0)
+        return -1;
+
+    if (s->first == s->last || s->state != STATE_LIVE) {
+        // Ensure IRQ is lowered since there is nothing to signal to the
+        // kernel yet.
+        qemu_irq_lower(s->irq);
+        return 0;
+    }
+
+    // There are buffered events, signal the kernel about it. Note that for
+    // x86, edge-triggered signalling is used, which requires first lowering
+    // the IRQ before raising it.
+#ifdef TARGET_I386
+    qemu_irq_lower(s->irq);
+#endif
+    qemu_irq_raise(s->irq);
+    return 0;
 }
 
 static void enqueue_event(events_state *s, unsigned int type, unsigned int code, int value)
@@ -132,11 +149,11 @@
     }
 
     if(s->first == s->last) {
-	if (s->state == STATE_LIVE)
-	  qemu_irq_raise(s->irq);
-	else {
-	  s->state = STATE_BUFFERED;
-	}
+        if (s->state == STATE_LIVE)
+            qemu_irq_raise(s->irq);
+        else {
+            s->state = STATE_BUFFERED;
+        }
     }
 
     //fprintf(stderr, "##KBD: type=%d code=%d value=%d\n", type, code, value);
@@ -226,9 +243,9 @@
      * as soon as one was buffered!
      */
     if (offset == REG_LEN && s->page == PAGE_ABSDATA) {
-	if (s->state == STATE_BUFFERED)
-	  qemu_irq_raise(s->irq);
-	s->state = STATE_LIVE;
+        if (s->state == STATE_BUFFERED)
+            qemu_irq_raise(s->irq);
+        s->state = STATE_LIVE;
     }
 
     if (offset == REG_READ)