From: Pekka Enberg <penberg@kernel.org>
To: kvm@vger.kernel.org
Cc: Pekka Enberg <penberg@kernel.org>,
Cyrill Gorcunov <gorcunov@gmail.com>, Ingo Molnar <mingo@elte.hu>,
John Floren <john@jfloren.net>,
Sasha Levin <levinsasha928@gmail.com>
Subject: [PATCH 2/3] kvm tools, ui: Move VNC specific framebuffer code to ui/vnc.c
Date: Fri, 3 Jun 2011 18:59:38 +0300 [thread overview]
Message-ID: <1307116779-572-2-git-send-email-penberg@kernel.org> (raw)
In-Reply-To: <1307116779-572-1-git-send-email-penberg@kernel.org>
This patch makes use of 'struct framebuffer' and moves the VNC code to ui/vnc.c
in preparation for other framebuffer output targets.
Cc: Cyrill Gorcunov <gorcunov@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: John Floren <john@jfloren.net>
Cc: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
---
tools/kvm/Makefile | 3 +-
tools/kvm/hw/vesa.c | 72 ++++++++++++-----------------------------
tools/kvm/include/kvm/i8042.h | 2 +
tools/kvm/include/kvm/vesa.h | 8 +----
tools/kvm/include/kvm/vnc.h | 14 ++++++++
tools/kvm/kvm-run.c | 14 +++++++-
tools/kvm/ui/vnc.c | 68 ++++++++++++++++++++++++++++++++++++++
7 files changed, 120 insertions(+), 61 deletions(-)
create mode 100644 tools/kvm/include/kvm/vnc.h
create mode 100644 tools/kvm/ui/vnc.c
diff --git a/tools/kvm/Makefile b/tools/kvm/Makefile
index 3f06dab..17c795b 100644
--- a/tools/kvm/Makefile
+++ b/tools/kvm/Makefile
@@ -51,6 +51,7 @@ OBJS += util/parse-options.o
OBJS += util/rbtree-interval.o
OBJS += util/strbuf.o
OBJS += virtio/9p.o
+OBJS += hw/vesa.o
FLAGS_BFD=$(CFLAGS) -lbfd
@@ -64,8 +65,8 @@ endif
FLAGS_VNCSERVER=$(CFLAGS) -lvncserver
has_vncserver := $(call try-cc,$(SOURCE_VNCSERVER),$(FLAGS_VNCSERVER))
ifeq ($(has_vncserver),y)
+ OBJS += ui/vnc.o
CFLAGS += -DCONFIG_HAS_VNCSERVER
- OBJS += hw/vesa.o
OBJS += hw/i8042.o
LIBS += -lvncserver
endif
diff --git a/tools/kvm/hw/vesa.c b/tools/kvm/hw/vesa.c
index b99f2de..ad12d08 100644
--- a/tools/kvm/hw/vesa.c
+++ b/tools/kvm/hw/vesa.c
@@ -1,32 +1,19 @@
#include "kvm/vesa.h"
#include "kvm/virtio-pci-dev.h"
+#include "kvm/framebuffer.h"
#include "kvm/kvm-cpu.h"
#include "kvm/ioport.h"
#include "kvm/util.h"
#include "kvm/irq.h"
#include "kvm/kvm.h"
#include "kvm/pci.h"
-#include "kvm/i8042.h"
#include <sys/types.h>
#include <sys/ioctl.h>
#include <inttypes.h>
#include <unistd.h>
-#include <rfb/rfb.h>
-
-#define VESA_QUEUE_SIZE 128
-#define VESA_IRQ 14
-
-/*
- * This "6000" value is pretty much the result of experimentation
- * It seems that around this value, things update pretty smoothly
- */
-#define VESA_UPDATE_TIME 6000
-
-static char videomem[VESA_MEM_SIZE];
-
static bool vesa_pci_io_in(struct ioport *ioport, struct kvm *kvm, u16 port, void *data, int size, u32 count)
{
return true;
@@ -53,23 +40,24 @@ static struct pci_device_header vesa_pci_device = {
.bar[1] = VESA_MEM_ADDR | PCI_BASE_ADDRESS_SPACE_MEMORY,
};
-
-void vesa_mmio_callback(u64 addr, u8 *data, u32 len, u8 is_write)
+static void vesa_mmio_callback(u64 addr, u8 *data, u32 len, u8 is_write)
{
if (!is_write)
return;
- memcpy(&videomem[addr - VESA_MEM_ADDR], data, len);
+ fb__write(addr, data, len);
}
-void vesa__init(struct kvm *kvm)
+static struct framebuffer vesafb;
+
+struct framebuffer *vesa__init(struct kvm *kvm)
{
- u8 dev, line, pin;
- pthread_t thread;
u16 vesa_base_addr;
+ u8 dev, line, pin;
+ char *mem;
if (irq__register_device(PCI_DEVICE_ID_VESA, &dev, &pin, &line) < 0)
- return;
+ return NULL;
vesa_pci_device.irq_pin = pin;
vesa_pci_device.irq_line = line;
@@ -79,34 +67,16 @@ void vesa__init(struct kvm *kvm)
kvm__register_mmio(VESA_MEM_ADDR, VESA_MEM_SIZE, &vesa_mmio_callback);
- pthread_create(&thread, NULL, vesa__dovnc, kvm);
-}
-
-/*
- * This starts a VNC server to display the framebuffer.
- * It's not altogether clear this belongs here rather than in kvm-run.c
- */
-void *vesa__dovnc(void *v)
-{
- /*
- * Make a fake argc and argv because the getscreen function
- * seems to want it.
- */
- char argv[1][1] = {{0}};
- int argc = 1;
-
- rfbScreenInfoPtr server;
-
- server = rfbGetScreen(&argc, (char **) argv, VESA_WIDTH, VESA_HEIGHT, 8, 3, 4);
- server->frameBuffer = videomem;
- server->alwaysShared = TRUE;
- server->kbdAddEvent = kbd_handle_key;
- server->ptrAddEvent = kbd_handle_ptr;
- rfbInitServer(server);
-
- while (rfbIsActive(server)) {
- rfbMarkRectAsModified(server, 0, 0, VESA_WIDTH, VESA_HEIGHT);
- rfbProcessEvents(server, server->deferUpdateTime * VESA_UPDATE_TIME);
- }
- return NULL;
+ mem = calloc(1, VESA_MEM_SIZE);
+ if (!mem)
+ return NULL;
+
+ vesafb = (struct framebuffer) {
+ .width = VESA_WIDTH,
+ .height = VESA_HEIGHT,
+ .depth = VESA_BPP,
+ .mem = mem,
+ .mem_addr = VESA_MEM_ADDR,
+ };
+ return fb__register(&vesafb);
}
diff --git a/tools/kvm/include/kvm/i8042.h b/tools/kvm/include/kvm/i8042.h
index 3416b64..066a8cc 100644
--- a/tools/kvm/include/kvm/i8042.h
+++ b/tools/kvm/include/kvm/i8042.h
@@ -1,6 +1,8 @@
#ifndef KVM__PCKBD_H
#define KVM__PCKBD_H
+struct kvm;
+
void kbd__init(struct kvm *kvm);
#ifdef CONFIG_HAS_VNCSERVER
diff --git a/tools/kvm/include/kvm/vesa.h b/tools/kvm/include/kvm/vesa.h
index e9522a5..6621f68 100644
--- a/tools/kvm/include/kvm/vesa.h
+++ b/tools/kvm/include/kvm/vesa.h
@@ -13,13 +13,7 @@
struct kvm;
struct int10_args;
-void vesa_mmio_callback(u64, u8*, u32, u8);
-void vesa__init(struct kvm *self);
-void *vesa__dovnc(void *);
+struct framebuffer *vesa__init(struct kvm *self);
void int10_handler(struct int10_args *args);
-#ifndef CONFIG_HAS_VNCSERVER
-void vesa__init(struct kvm *self) { }
-#endif
-
#endif
diff --git a/tools/kvm/include/kvm/vnc.h b/tools/kvm/include/kvm/vnc.h
new file mode 100644
index 0000000..da2f635
--- /dev/null
+++ b/tools/kvm/include/kvm/vnc.h
@@ -0,0 +1,14 @@
+#ifndef KVM__VNC_H
+#define KVM__VNC_H
+
+struct framebuffer;
+
+#ifdef CONFIG_HAS_VNCSERVER
+void vnc__init(struct framebuffer *fb);
+#else
+static inline void vnc__init(struct framebuffer *fb)
+{
+}
+#endif
+
+#endif /* KVM__VNC_H */
diff --git a/tools/kvm/kvm-run.c b/tools/kvm/kvm-run.c
index 034a3ba..e6e180b 100644
--- a/tools/kvm/kvm-run.c
+++ b/tools/kvm/kvm-run.c
@@ -31,6 +31,8 @@
#include <kvm/vesa.h>
#include <kvm/ioeventfd.h>
#include <kvm/i8042.h>
+#include <kvm/vnc.h>
+#include <kvm/framebuffer.h>
/* header files for gitish interface */
#include <kvm/kvm-run.h>
@@ -426,13 +428,14 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix)
{
struct virtio_net_parameters net_params;
static char real_cmdline[2048];
+ struct framebuffer *fb = NULL;
unsigned int nr_online_cpus;
int exit_code = 0;
+ u16 vidmode = 0;
int max_cpus;
char *hi;
int i;
void *ret;
- u16 vidmode = 0;
signal(SIGALRM, handle_sigalrm);
signal(SIGQUIT, handle_sigquit);
@@ -629,9 +632,14 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix)
if (vnc) {
kbd__init(kvm);
- vesa__init(kvm);
+ fb = vesa__init(kvm);
}
+ if (fb)
+ vnc__init(fb);
+
+ fb__start();
+
thread_pool__init(nr_online_cpus);
ioeventfd__start();
@@ -653,6 +661,8 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix)
exit_code = 1;
}
+ fb__stop();
+
virtio_blk__delete_all(kvm);
virtio_rng__delete_all(kvm);
diff --git a/tools/kvm/ui/vnc.c b/tools/kvm/ui/vnc.c
new file mode 100644
index 0000000..086cf82
--- /dev/null
+++ b/tools/kvm/ui/vnc.c
@@ -0,0 +1,68 @@
+#include "kvm/vnc.h"
+
+#include "kvm/framebuffer.h"
+#include "kvm/i8042.h"
+
+#include <linux/types.h>
+#include <rfb/rfb.h>
+#include <pthread.h>
+
+#define VESA_QUEUE_SIZE 128
+#define VESA_IRQ 14
+
+/*
+ * This "6000" value is pretty much the result of experimentation
+ * It seems that around this value, things update pretty smoothly
+ */
+#define VESA_UPDATE_TIME 6000
+
+static void vnc__write(struct framebuffer *fb, u64 addr, u8 *data, u32 len)
+{
+ memcpy(&fb->mem[addr - fb->mem_addr], data, len);
+}
+
+static void *vnc__thread(void *p)
+{
+ struct framebuffer *fb = p;
+ /*
+ * Make a fake argc and argv because the getscreen function
+ * seems to want it.
+ */
+ char argv[1][1] = {{0}};
+ int argc = 1;
+
+ rfbScreenInfoPtr server;
+
+ server = rfbGetScreen(&argc, (char **) argv, fb->width, fb->height, 8, 3, 4);
+ server->frameBuffer = fb->mem;
+ server->alwaysShared = TRUE;
+ server->kbdAddEvent = kbd_handle_key;
+ server->ptrAddEvent = kbd_handle_ptr;
+ rfbInitServer(server);
+
+ while (rfbIsActive(server)) {
+ rfbMarkRectAsModified(server, 0, 0, fb->width, fb->height);
+ rfbProcessEvents(server, server->deferUpdateTime * VESA_UPDATE_TIME);
+ }
+ return NULL;
+}
+
+static int vnc__start(struct framebuffer *fb)
+{
+ pthread_t thread;
+
+ if (pthread_create(&thread, NULL, vnc__thread, fb) != 0)
+ return -1;
+
+ return 0;
+}
+
+static struct fb_target_operations vnc_ops = {
+ .start = vnc__start,
+ .write = vnc__write,
+};
+
+void vnc__init(struct framebuffer *fb)
+{
+ fb__attach(fb, &vnc_ops);
+}
--
1.7.0.4
next prev parent reply other threads:[~2011-06-03 15:59 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-06-03 15:59 [PATCH 1/3] kvm tools, ui: Add framebuffer infrastructure Pekka Enberg
2011-06-03 15:59 ` Pekka Enberg [this message]
2011-06-03 15:59 ` [PATCH 3/3] kvm tools, ui: Add support for SDL framebuffer output target Pekka Enberg
2011-06-03 16:26 ` Ingo Molnar
2011-06-03 16:28 ` Ingo Molnar
2011-06-03 16:33 ` Ingo Molnar
2011-06-03 16:37 ` Pekka Enberg
2011-06-03 16:40 ` Ingo Molnar
2011-06-03 16:44 ` Pekka Enberg
2011-06-03 16:45 ` Ingo Molnar
2011-06-03 16:46 ` Pekka Enberg
2011-06-03 16:52 ` Ingo Molnar
2011-06-03 16:54 ` Pekka Enberg
2011-06-03 16:58 ` Ingo Molnar
2011-06-03 16:54 ` Ingo Molnar
2011-06-03 16:56 ` Ingo Molnar
2011-06-03 16:30 ` Pekka Enberg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1307116779-572-2-git-send-email-penberg@kernel.org \
--to=penberg@kernel.org \
--cc=gorcunov@gmail.com \
--cc=john@jfloren.net \
--cc=kvm@vger.kernel.org \
--cc=levinsasha928@gmail.com \
--cc=mingo@elte.hu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.