kvm tools, setup: Create private directory
[linux-2.6/next.git] / tools / kvm / framebuffer.c
blobb6eb1acee962880fd0fb255d6d951cf5ca438406
1 #include "kvm/framebuffer.h"
3 #include <linux/kernel.h>
4 #include <linux/list.h>
5 #include <stdlib.h>
6 #include <sys/mman.h>
8 static LIST_HEAD(framebuffers);
10 struct framebuffer *fb__register(struct framebuffer *fb)
12 INIT_LIST_HEAD(&fb->node);
13 list_add(&fb->node, &framebuffers);
15 return fb;
18 int fb__attach(struct framebuffer *fb, struct fb_target_operations *ops)
20 if (fb->nr_targets >= FB_MAX_TARGETS)
21 return -1;
23 fb->targets[fb->nr_targets++] = ops;
25 return 0;
28 static int start_targets(struct framebuffer *fb)
30 unsigned long i;
32 for (i = 0; i < fb->nr_targets; i++) {
33 struct fb_target_operations *ops = fb->targets[i];
34 int err = 0;
36 if (ops->start)
37 err = ops->start(fb);
39 if (err)
40 return err;
43 return 0;
46 int fb__start(void)
48 struct framebuffer *fb;
50 list_for_each_entry(fb, &framebuffers, node) {
51 int err;
53 err = start_targets(fb);
54 if (err)
55 return err;
58 return 0;
61 void fb__stop(void)
63 struct framebuffer *fb;
65 list_for_each_entry(fb, &framebuffers, node) {
66 munmap(fb->mem, fb->mem_size);