This patch adds a fbdev monitor command to enable/disable
the fbdev display at runtime to both qmp and hmp.

qmp: framebuffer-display enable=on|off scale=on|off device=/dev/fb<n>
hmp: framebuffer-display on|off

Signed-off-by: Gerd Hoffmann <kra...@redhat.com>
---
 hmp-commands.hx  |   15 +++++++++++++++
 hmp.c            |    9 +++++++++
 hmp.h            |    1 +
 qapi-schema.json |   20 ++++++++++++++++++++
 qmp-commands.hx  |    6 ++++++
 qmp.c            |   22 ++++++++++++++++++++++
 6 files changed, 73 insertions(+)

diff --git a/hmp-commands.hx b/hmp-commands.hx
index 9cea415..a5057b1 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -1551,6 +1551,21 @@ Removes the chardev @var{id}.
 ETEXI
 
     {
+        .name       = "framebuffer-display",
+        .args_type  = "enable:b",
+        .params     = "on|off",
+        .help       = "enable/disable linux console framebuffer display",
+        .mhandler.cmd = hmp_framebuffer_display,
+    },
+
+STEXI
+@item framebuffer-display on | off
+@findex framebuffer-display
+
+enable/disable linux console framebuffer display.
+ETEXI
+
+    {
         .name       = "info",
         .args_type  = "item:s?",
         .params     = "[subcommand]",
diff --git a/hmp.c b/hmp.c
index 4fb76ec..da8af79 100644
--- a/hmp.c
+++ b/hmp.c
@@ -1425,3 +1425,12 @@ void hmp_chardev_remove(Monitor *mon, const QDict *qdict)
     qmp_chardev_remove(qdict_get_str(qdict, "id"), &local_err);
     hmp_handle_error(mon, &local_err);
 }
+
+void hmp_framebuffer_display(Monitor *mon, const QDict *qdict)
+{
+    int enable = qdict_get_bool(qdict, "enable");
+    Error *errp = NULL;
+
+    qmp_framebuffer_display(enable, false, false, false, NULL, &errp);
+    hmp_handle_error(mon, &errp);
+}
diff --git a/hmp.h b/hmp.h
index 95fe76e..ce4d6d1 100644
--- a/hmp.h
+++ b/hmp.h
@@ -85,5 +85,6 @@ void hmp_nbd_server_add(Monitor *mon, const QDict *qdict);
 void hmp_nbd_server_stop(Monitor *mon, const QDict *qdict);
 void hmp_chardev_add(Monitor *mon, const QDict *qdict);
 void hmp_chardev_remove(Monitor *mon, const QDict *qdict);
+void hmp_framebuffer_display(Monitor *mon, const QDict *qdict);
 
 #endif
diff --git a/qapi-schema.json b/qapi-schema.json
index ef1f657..083fb43 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -3618,3 +3618,23 @@
             '*cpuid-input-ecx': 'int',
             'cpuid-register': 'X86CPURegister32',
             'features': 'int' } }
+
+##
+# @framebuffer-display:
+#
+# Enable/disable linux console framebuffer display.
+#
+# @enable: whenever the framebuffer display should be enabled or disabled.
+#
+# @scale: #optional enables display scaling, default: off
+#
+# @device: #optional specifies framebuffer device, default: /dev/fb0
+#
+# Returns: Nothing.
+#
+# Since: 1.6
+#
+##
+{ 'command': 'framebuffer-display', 'data': {'enable'  : 'bool',
+                                             '*scale'  : 'bool',
+                                             '*device' : 'str' } }
diff --git a/qmp-commands.hx b/qmp-commands.hx
index ffd130e..7832142 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -2932,3 +2932,9 @@ Example:
 <- { "return": {} }
 
 EQMP
+
+    {
+        .name       = "framebuffer-display",
+        .args_type  = "enable:b,scale:b?,device:s?",
+        .mhandler.cmd_new = qmp_marshal_input_framebuffer_display,
+    },
diff --git a/qmp.c b/qmp.c
index 4c149b3..9db1e05 100644
--- a/qmp.c
+++ b/qmp.c
@@ -404,6 +404,28 @@ void qmp_change(const char *device, const char *target,
     }
 }
 
+void qmp_framebuffer_display(bool enable,
+                             bool has_scale, bool scale,
+                             bool has_device, const char *device,
+                             Error **errp)
+{
+#if defined(CONFIG_FBDEV)
+    if (enable) {
+        if (fbdev_display_init(has_device ? device : NULL,
+                               has_scale  ? scale  : false,
+                               errp) != 0) {
+            if (!error_is_set(errp)) {
+                error_setg(errp, "fbdev initialization failed");
+            }
+        }
+    } else {
+        fbdev_display_uninit();
+    }
+#else
+    error_setg(errp, "fbdev support disabled at compile time");
+#endif
+}
+
 static void qom_list_types_tramp(ObjectClass *klass, void *data)
 {
     ObjectTypeInfoList *e, **pret = data;
-- 
1.7.9.7


Reply via email to