1 #include "kvm/vesa.h" 2 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> 12 13 #include <sys/types.h> 14 #include <sys/ioctl.h> 15 #include <inttypes.h> 16 #include <unistd.h> 17 18 static bool vesa_pci_io_in(struct ioport *ioport, struct kvm *kvm, u16 port, void *data, int size) 19 { 20 return true; 21 } 22 23 static bool vesa_pci_io_out(struct ioport *ioport, struct kvm *kvm, u16 port, void *data, int size) 24 { 25 return true; 26 } 27 28 static struct ioport_operations vesa_io_ops = { 29 .io_in = vesa_pci_io_in, 30 .io_out = vesa_pci_io_out, 31 }; 32 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, 43 }; 44 45 static struct framebuffer vesafb; 46 47 struct framebuffer *vesa__init(struct kvm *kvm) 48 { 49 u16 vesa_base_addr; 50 u8 dev, line, pin; 51 char *mem; 52 53 if (irq__register_device(PCI_DEVICE_ID_VESA, &dev, &pin, &line) < 0) 54 return NULL; 55 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); 61 62 mem = mmap(NULL, VESA_MEM_SIZE, PROT_RW, MAP_ANON_NORESERVE, -1, 0); 63 if (mem == MAP_FAILED) 64 return NULL; 65 66 kvm__register_mem(kvm, VESA_MEM_ADDR, VESA_MEM_SIZE, mem); 67 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, 75 }; 76 return fb__register(&vesafb); 77 } 78