kvm tools, setup: Create private directory
[linux-2.6/next.git] / tools / kvm / hw / vesa.c
blob22b1652b35bc84ab78650c10d899c42723f09408
1 #include "kvm/vesa.h"
3 #include "kvm/virtio-pci-dev.h"
4 #include "kvm/framebuffer.h"
5 #include "kvm/kvm-cpu.h"
6 #include "kvm/ioport.h"
7 #include "kvm/util.h"
8 #include "kvm/irq.h"
9 #include "kvm/kvm.h"
10 #include "kvm/pci.h"
11 #include <sys/mman.h>
13 #include <sys/types.h>
14 #include <sys/ioctl.h>
15 #include <inttypes.h>
16 #include <unistd.h>
18 static bool vesa_pci_io_in(struct ioport *ioport, struct kvm *kvm, u16 port, void *data, int size)
20 return true;
23 static bool vesa_pci_io_out(struct ioport *ioport, struct kvm *kvm, u16 port, void *data, int size)
25 return true;
28 static struct ioport_operations vesa_io_ops = {
29 .io_in = vesa_pci_io_in,
30 .io_out = vesa_pci_io_out,
33 static struct pci_device_header vesa_pci_device = {
34 .vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET,
35 .device_id = PCI_DEVICE_ID_VESA,
36 .header_type = PCI_HEADER_TYPE_NORMAL,
37 .revision_id = 0,
38 .class = 0x030000,
39 .subsys_vendor_id = PCI_SUBSYSTEM_VENDOR_ID_REDHAT_QUMRANET,
40 .subsys_id = PCI_SUBSYSTEM_ID_VESA,
41 .bar[1] = VESA_MEM_ADDR | PCI_BASE_ADDRESS_SPACE_MEMORY,
42 .bar_size[1] = VESA_MEM_SIZE,
45 static struct framebuffer vesafb;
47 struct framebuffer *vesa__init(struct kvm *kvm)
49 u16 vesa_base_addr;
50 u8 dev, line, pin;
51 char *mem;
53 if (irq__register_device(PCI_DEVICE_ID_VESA, &dev, &pin, &line) < 0)
54 return NULL;
56 vesa_pci_device.irq_pin = pin;
57 vesa_pci_device.irq_line = line;
58 vesa_base_addr = ioport__register(IOPORT_EMPTY, &vesa_io_ops, IOPORT_SIZE, NULL);
59 vesa_pci_device.bar[0] = vesa_base_addr | PCI_BASE_ADDRESS_SPACE_IO;
60 pci__register(&vesa_pci_device, dev);
62 mem = mmap(NULL, VESA_MEM_SIZE, PROT_RW, MAP_ANON_NORESERVE, -1, 0);
63 if (mem == MAP_FAILED)
64 return NULL;
66 kvm__register_mem(kvm, VESA_MEM_ADDR, VESA_MEM_SIZE, mem);
68 vesafb = (struct framebuffer) {
69 .width = VESA_WIDTH,
70 .height = VESA_HEIGHT,
71 .depth = VESA_BPP,
72 .mem = mem,
73 .mem_addr = VESA_MEM_ADDR,
74 .mem_size = VESA_MEM_SIZE,
76 return fb__register(&vesafb);