All of lore.kernel.org
 help / color / mirror / Atom feed
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 1/3] kvm tools, ui: Add framebuffer infrastructure
Date: Fri,  3 Jun 2011 18:59:37 +0300	[thread overview]
Message-ID: <1307116779-572-1-git-send-email-penberg@kernel.org> (raw)

This patch introduces 'struct framebuffer' and related API as a preparational
step to killing libvnc dependency from hw/vesa.c.

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                  |    1 +
 tools/kvm/framebuffer.c             |   87 +++++++++++++++++++++++++++++++++++
 tools/kvm/include/kvm/framebuffer.h |   35 ++++++++++++++
 3 files changed, 123 insertions(+), 0 deletions(-)
 create mode 100644 tools/kvm/framebuffer.c
 create mode 100644 tools/kvm/include/kvm/framebuffer.h

diff --git a/tools/kvm/Makefile b/tools/kvm/Makefile
index a05a6b1..3f06dab 100644
--- a/tools/kvm/Makefile
+++ b/tools/kvm/Makefile
@@ -17,6 +17,7 @@ TAGS = ctags
 
 OBJS	+= cpuid.o
 OBJS	+= disk/core.o
+OBJS	+= framebuffer.o
 OBJS	+= hw/rtc.o
 OBJS	+= hw/serial.o
 OBJS	+= interrupt.o
diff --git a/tools/kvm/framebuffer.c b/tools/kvm/framebuffer.c
new file mode 100644
index 0000000..eae0a92
--- /dev/null
+++ b/tools/kvm/framebuffer.c
@@ -0,0 +1,87 @@
+#include "kvm/framebuffer.h"
+
+#include <linux/kernel.h>
+#include <linux/list.h>
+#include <stdlib.h>
+
+static LIST_HEAD(framebuffers);
+
+struct framebuffer *fb__register(struct framebuffer *fb)
+{
+	INIT_LIST_HEAD(&fb->node);
+	list_add(&fb->node, &framebuffers);
+
+	return fb;
+}
+
+int fb__attach(struct framebuffer *fb, struct fb_target_operations *ops)
+{
+	if (fb->nr_targets >= FB_MAX_TARGETS)
+		return -1;
+
+	fb->targets[fb->nr_targets++] = ops;
+
+	return 0;
+}
+
+static int start_targets(struct framebuffer *fb)
+{
+	unsigned long i;
+
+	for (i = 0; i < fb->nr_targets; i++) {
+		struct fb_target_operations *ops = fb->targets[i];
+		int err = 0;
+
+		if (ops->start)
+			err = ops->start(fb);
+
+		if (err)
+			return err;
+	}
+
+	return 0;
+}
+
+int fb__start(void)
+{
+	struct framebuffer *fb;
+
+	list_for_each_entry(fb, &framebuffers, node) {
+		int err;
+
+		err = start_targets(fb);
+		if (err)
+			return err;
+	}
+
+	return 0;
+}
+
+void fb__stop(void)
+{
+	struct framebuffer *fb;
+
+	list_for_each_entry(fb, &framebuffers, node) {
+		free(fb->mem);
+	}
+}
+
+static void write_to_targets(struct framebuffer *fb, u64 addr, u8 *data, u32 len)
+{
+	unsigned long i;
+
+	for (i = 0; i < fb->nr_targets; i++) {
+		struct fb_target_operations *ops = fb->targets[i];
+
+		ops->write(fb, addr, data, len);
+	}
+}
+
+void fb__write(u64 addr, u8 *data, u32 len)
+{
+	struct framebuffer *fb;
+
+	list_for_each_entry(fb, &framebuffers, node) {
+		write_to_targets(fb, addr, data, len);
+	}
+}
diff --git a/tools/kvm/include/kvm/framebuffer.h b/tools/kvm/include/kvm/framebuffer.h
new file mode 100644
index 0000000..e2273c5
--- /dev/null
+++ b/tools/kvm/include/kvm/framebuffer.h
@@ -0,0 +1,35 @@
+#ifndef KVM__FRAMEBUFFER_H
+#define KVM__FRAMEBUFFER_H
+
+#include <linux/types.h>
+#include <linux/list.h>
+
+struct framebuffer;
+
+struct fb_target_operations {
+	int (*start)(struct framebuffer *fb);
+	void (*write)(struct framebuffer *fb, u64 addr, u8 *data, u32 len);
+};
+
+#define FB_MAX_TARGETS			2
+
+struct framebuffer {
+	u32				width;
+	u32				height;
+	u8				depth;
+	char				*mem;
+	u64				mem_addr;
+
+	unsigned long			nr_targets;
+	struct fb_target_operations	*targets[FB_MAX_TARGETS];
+
+	struct list_head		node;
+};
+
+struct framebuffer *fb__register(struct framebuffer *fb);
+int fb__attach(struct framebuffer *fb, struct fb_target_operations *ops);
+int fb__start(void);
+void fb__stop(void);
+void fb__write(u64 addr, u8 *data, u32 len);
+
+#endif /* KVM__FRAMEBUFFER_H */
-- 
1.7.0.4


             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 Pekka Enberg [this message]
2011-06-03 15:59 ` [PATCH 2/3] kvm tools, ui: Move VNC specific framebuffer code to ui/vnc.c Pekka Enberg
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-1-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.