]> xenbits.xensource.com Git - mini-os.git/commitdiff
Save/Restore Support: Add suspend/restore support for console
authorBruno Alvisio <bruno.alvisio@gmail.com>
Mon, 11 Dec 2017 16:09:21 +0000 (08:09 -0800)
committerWei Liu <wei.liu2@citrix.com>
Wed, 21 Mar 2018 09:16:49 +0000 (09:16 +0000)
Signed-off-by: Bruno Alvisio <bruno.alvisio@gmail.com>
Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
console/console.c
console/xenbus.c
console/xencons_ring.c
include/console.h
kernel.c
lib/sys.c

index 6a0b923b4b9b3a8ebf577d4e14e4621ca1f4a933..c6f6010865e80ecb8c665e7739c3c9dfd151b6a9 100644 (file)
@@ -47,6 +47,7 @@
 
 /* If console not initialised the printk will be sent to xen serial line 
    NOTE: you need to enable verbose in xen/Rules.mk for it to work. */
+static struct consfront_dev* xen_console = NULL;
 static int console_initialised = 0;
 
 __attribute__((weak)) void console_input(char * buf, unsigned len)
@@ -157,8 +158,20 @@ void xprintk(const char *fmt, ...)
 void init_console(void)
 {   
     printk("Initialising console ... ");
-    xencons_ring_init();    
+    xen_console = xencons_ring_init();
     console_initialised = 1;
     /* This is also required to notify the daemon */
     printk("done.\n");
 }
+
+void suspend_console(void)
+{
+    console_initialised = 0;
+    xencons_ring_fini(xen_console);
+}
+
+void resume_console(void)
+{
+    xencons_ring_resume(xen_console);
+    console_initialised = 1;
+}
\ No newline at end of file
index 1c9a59055aa988b94a4f11980ead7713f09636ff..654b4699cce1204dee2e90cb90991d8b11eadd07 100644 (file)
@@ -188,8 +188,7 @@ error:
     return NULL;
 }
 
-void fini_console(struct consfront_dev *dev)
+void fini_consfront(struct consfront_dev *dev)
 {
     if (dev) free_consfront(dev);
 }
-
index dd64a413e76e92673eb342e41ec9495f9598f074..b6db74e9cc40eb7a8bdcd72fb8e0ede5b26b032c 100644 (file)
@@ -19,6 +19,8 @@ DECLARE_WAIT_QUEUE_HEAD(console_queue);
 static struct xencons_interface *console_ring;
 uint32_t console_evtchn;
 
+static struct consfront_dev* resume_xen_console(struct consfront_dev* dev);
+
 #ifdef CONFIG_PARAVIRT
 void get_console(void *p)
 {
@@ -32,10 +34,12 @@ void get_console(void *p)
 {
     uint64_t v = -1;
 
-    hvm_get_parameter(HVM_PARAM_CONSOLE_EVTCHN, &v);
+    if (hvm_get_parameter(HVM_PARAM_CONSOLE_EVTCHN, &v))
+        BUG();
     console_evtchn = v;
 
-    hvm_get_parameter(HVM_PARAM_CONSOLE_PFN, &v);
+    if (hvm_get_parameter(HVM_PARAM_CONSOLE_PFN, &v))
+        BUG();
     console_ring = (struct xencons_interface *)map_frame_virt(v);
 }
 #endif
@@ -89,9 +93,7 @@ int xencons_ring_send(struct consfront_dev *dev, const char *data, unsigned len)
     notify_daemon(dev);
 
     return sent;
-}      
-
-
+}
 
 void console_handle_input(evtchn_port_t port, struct pt_regs *regs, void *data)
 {
@@ -177,41 +179,60 @@ int xencons_ring_recv(struct consfront_dev *dev, char *data, unsigned len)
 
 struct consfront_dev *xencons_ring_init(void)
 {
-       int err;
-       struct consfront_dev *dev;
+    struct consfront_dev *dev;
 
-       if (!console_evtchn)
-               return 0;
+    if (!console_evtchn)
+        return 0;
 
-       dev = malloc(sizeof(struct consfront_dev));
-       memset(dev, 0, sizeof(struct consfront_dev));
-       dev->nodename = "device/console";
-       dev->dom = 0;
-       dev->backend = 0;
-       dev->ring_ref = 0;
+    dev = malloc(sizeof(struct consfront_dev));
+    memset(dev, 0, sizeof(struct consfront_dev));
+    dev->nodename = "device/console";
+    dev->dom = 0;
+    dev->backend = 0;
+    dev->ring_ref = 0;
 
 #ifdef HAVE_LIBC
-       dev->fd = -1;
+    dev->fd = -1;
 #endif
-       dev->evtchn = console_evtchn;
-       dev->ring = xencons_interface();
-
-       err = bind_evtchn(dev->evtchn, console_handle_input, dev);
-       if (err <= 0) {
-               printk("XEN console request chn bind failed %i\n", err);
-                free(dev);
-               return NULL;
-       }
-        unmask_evtchn(dev->evtchn);
 
-       /* In case we have in-flight data after save/restore... */
-       notify_daemon(dev);
+    return resume_xen_console(dev);
+}
+
+static struct consfront_dev* resume_xen_console(struct consfront_dev* dev)
+{
+    int err;
 
-       return dev;
+    dev->evtchn = console_evtchn;
+    dev->ring = xencons_interface();
+
+    err = bind_evtchn(dev->evtchn, console_handle_input, dev);
+    if (err <= 0) {
+        printk("XEN console request chn bind failed %i\n", err);
+        free(dev);
+        return NULL;
+    }
+    unmask_evtchn(dev->evtchn);
+
+    /* In case we have in-flight data after save/restore... */
+    notify_daemon(dev);
+
+    return dev;
 }
 
-void xencons_resume(void)
+void xencons_ring_fini(struct consfront_dev* dev)
 {
-       (void)xencons_ring_init();
+    if (dev)
+        mask_evtchn(dev->evtchn);
 }
 
+void xencons_ring_resume(struct consfront_dev* dev)
+{
+    if (dev) {
+#if CONFIG_PARAVIRT
+        get_console(&start_info);
+#else
+        get_console(0);
+#endif
+        resume_xen_console(dev);
+    }
+}
index 539cccd90d8ff7275612dfd840511342d826c04d..0d7bf07790b8500e6dffc41f8069e424f1b2c08c 100644 (file)
@@ -78,11 +78,15 @@ void xencons_tx(void);
 void get_console(void *p);
 void init_console(void);
 void console_print(struct consfront_dev *dev, char *data, int length);
-void fini_console(struct consfront_dev *dev);
+void fini_consfront(struct consfront_dev *dev);
+void suspend_console(void);
+void resume_console(void);
 
 /* Low level functions defined in xencons_ring.c */
 extern struct wait_queue_head console_queue;
 struct consfront_dev *xencons_ring_init(void);
+void xencons_ring_fini(struct consfront_dev* dev);
+void xencons_ring_resume(struct consfront_dev* dev);
 struct consfront_dev *init_consfront(char *_nodename);
 int xencons_ring_send(struct consfront_dev *dev, const char *data, unsigned len);
 int xencons_ring_send_no_notify(struct consfront_dev *dev, const char *data, unsigned len);
index 3564af33f833a5755dc805a54493c8a49a4e920a..2fb69bf1ea6420efe659026116fbe3e96de2f18c 100644 (file)
--- a/kernel.c
+++ b/kernel.c
@@ -122,10 +122,14 @@ void pre_suspend(void)
     local_irq_disable();
 
     fini_time();
+
+    suspend_console();
 }
 
 void post_suspend(int canceled)
 {
+    resume_console();
+
     init_time();
 
     local_irq_enable();
index 23dc2a567d0e82b74fd6ef90fd4d691b6347225c..da434fc000a3905a9b0b6e6201480987b0d2f41e 100644 (file)
--- a/lib/sys.c
+++ b/lib/sys.c
@@ -487,7 +487,7 @@ int close(int fd)
 #ifdef CONFIG_CONSFRONT
         case FTYPE_SAVEFILE:
         case FTYPE_CONSOLE:
-            fini_console(files[fd].cons.dev);
+            fini_consfront(files[fd].cons.dev);
             files[fd].type = FTYPE_NONE;
             return 0;
 #endif