Juan Quintela | 47d37dd | 2009-08-31 16:07:15 +0200 | [diff] [blame] | 1 | /* |
| 2 | * QEMU PCI VGA Emulator. |
| 3 | * |
| 4 | * Copyright (c) 2003 Fabrice Bellard |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | * of this software and associated documentation files (the "Software"), to deal |
| 8 | * in the Software without restriction, including without limitation the rights |
| 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | * copies of the Software, and to permit persons to whom the Software is |
| 11 | * furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in |
| 14 | * all copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 22 | * THE SOFTWARE. |
| 23 | */ |
| 24 | #include "hw.h" |
| 25 | #include "console.h" |
| 26 | #include "pc.h" |
| 27 | #include "pci.h" |
| 28 | #include "vga_int.h" |
| 29 | #include "pixel_ops.h" |
| 30 | #include "qemu-timer.h" |
Gerd Hoffmann | 5245d57 | 2009-10-26 12:18:26 +0100 | [diff] [blame] | 31 | #include "loader.h" |
Juan Quintela | 47d37dd | 2009-08-31 16:07:15 +0200 | [diff] [blame] | 32 | |
| 33 | typedef struct PCIVGAState { |
| 34 | PCIDevice dev; |
| 35 | VGACommonState vga; |
| 36 | } PCIVGAState; |
| 37 | |
Juan Quintela | a4f9631 | 2009-10-14 15:42:44 +0200 | [diff] [blame] | 38 | static const VMStateDescription vmstate_vga_pci = { |
| 39 | .name = "vga", |
| 40 | .version_id = 2, |
| 41 | .minimum_version_id = 2, |
| 42 | .minimum_version_id_old = 2, |
| 43 | .fields = (VMStateField []) { |
| 44 | VMSTATE_PCI_DEVICE(dev, PCIVGAState), |
| 45 | VMSTATE_STRUCT(vga, PCIVGAState, 0, vmstate_vga_common, VGACommonState), |
| 46 | VMSTATE_END_OF_LIST() |
Juan Quintela | 47d37dd | 2009-08-31 16:07:15 +0200 | [diff] [blame] | 47 | } |
Juan Quintela | a4f9631 | 2009-10-14 15:42:44 +0200 | [diff] [blame] | 48 | }; |
Juan Quintela | 47d37dd | 2009-08-31 16:07:15 +0200 | [diff] [blame] | 49 | |
Juan Quintela | 47d37dd | 2009-08-31 16:07:15 +0200 | [diff] [blame] | 50 | static void vga_map(PCIDevice *pci_dev, int region_num, |
Isaku Yamahata | 6e355d9 | 2009-10-30 21:21:08 +0900 | [diff] [blame] | 51 | pcibus_t addr, pcibus_t size, int type) |
Juan Quintela | 47d37dd | 2009-08-31 16:07:15 +0200 | [diff] [blame] | 52 | { |
| 53 | PCIVGAState *d = (PCIVGAState *)pci_dev; |
| 54 | VGACommonState *s = &d->vga; |
Gerd Hoffmann | 7889542 | 2010-10-15 11:45:13 +0200 | [diff] [blame] | 55 | |
| 56 | cpu_register_physical_memory(addr, s->vram_size, s->vram_offset); |
| 57 | s->map_addr = addr; |
| 58 | s->map_end = addr + s->vram_size; |
| 59 | vga_dirty_log_start(s); |
Juan Quintela | 47d37dd | 2009-08-31 16:07:15 +0200 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | static void pci_vga_write_config(PCIDevice *d, |
| 63 | uint32_t address, uint32_t val, int len) |
| 64 | { |
| 65 | PCIVGAState *pvs = container_of(d, PCIVGAState, dev); |
| 66 | VGACommonState *s = &pvs->vga; |
| 67 | |
| 68 | pci_default_write_config(d, address, val, len); |
| 69 | if (s->map_addr && pvs->dev.io_regions[0].addr == -1) |
| 70 | s->map_addr = 0; |
| 71 | } |
| 72 | |
| 73 | static int pci_vga_initfn(PCIDevice *dev) |
| 74 | { |
| 75 | PCIVGAState *d = DO_UPCAST(PCIVGAState, dev, dev); |
| 76 | VGACommonState *s = &d->vga; |
| 77 | uint8_t *pci_conf = d->dev.config; |
| 78 | |
| 79 | // vga + console init |
| 80 | vga_common_init(s, VGA_RAM_SIZE); |
| 81 | vga_init(s); |
Juan Quintela | 47d37dd | 2009-08-31 16:07:15 +0200 | [diff] [blame] | 82 | |
| 83 | s->ds = graphic_console_init(s->update, s->invalidate, |
| 84 | s->screen_dump, s->text_update, s); |
| 85 | |
| 86 | // dummy VGA (same as Bochs ID) |
| 87 | pci_config_set_vendor_id(pci_conf, PCI_VENDOR_ID_QEMU); |
| 88 | pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_QEMU_VGA); |
| 89 | pci_config_set_class(pci_conf, PCI_CLASS_DISPLAY_VGA); |
Juan Quintela | 47d37dd | 2009-08-31 16:07:15 +0200 | [diff] [blame] | 90 | |
| 91 | /* XXX: VGA_RAM_SIZE must be a power of two */ |
| 92 | pci_register_bar(&d->dev, 0, VGA_RAM_SIZE, |
Isaku Yamahata | 0392a01 | 2009-10-30 21:21:03 +0900 | [diff] [blame] | 93 | PCI_BASE_ADDRESS_MEM_PREFETCH, vga_map); |
Juan Quintela | 47d37dd | 2009-08-31 16:07:15 +0200 | [diff] [blame] | 94 | |
Gerd Hoffmann | 281a26b | 2010-11-17 12:06:44 +0100 | [diff] [blame] | 95 | if (!dev->rom_bar) { |
| 96 | /* compatibility with pc-0.13 and older */ |
| 97 | vga_init_vbe(s); |
| 98 | } |
| 99 | |
Juan Quintela | 47d37dd | 2009-08-31 16:07:15 +0200 | [diff] [blame] | 100 | return 0; |
| 101 | } |
| 102 | |
Gerd Hoffmann | 7889542 | 2010-10-15 11:45:13 +0200 | [diff] [blame] | 103 | int pci_vga_init(PCIBus *bus) |
Juan Quintela | 47d37dd | 2009-08-31 16:07:15 +0200 | [diff] [blame] | 104 | { |
Gerd Hoffmann | 7889542 | 2010-10-15 11:45:13 +0200 | [diff] [blame] | 105 | pci_create_simple(bus, -1, "VGA"); |
Juan Quintela | 47d37dd | 2009-08-31 16:07:15 +0200 | [diff] [blame] | 106 | return 0; |
| 107 | } |
| 108 | |
| 109 | static PCIDeviceInfo vga_info = { |
| 110 | .qdev.name = "VGA", |
| 111 | .qdev.size = sizeof(PCIVGAState), |
Juan Quintela | be73cfe | 2009-12-02 12:36:46 +0100 | [diff] [blame] | 112 | .qdev.vmsd = &vmstate_vga_pci, |
Juan Quintela | 47d37dd | 2009-08-31 16:07:15 +0200 | [diff] [blame] | 113 | .init = pci_vga_initfn, |
| 114 | .config_write = pci_vga_write_config, |
Gerd Hoffmann | 7889542 | 2010-10-15 11:45:13 +0200 | [diff] [blame] | 115 | .romfile = "vgabios-stdvga.bin", |
Juan Quintela | 47d37dd | 2009-08-31 16:07:15 +0200 | [diff] [blame] | 116 | }; |
| 117 | |
| 118 | static void vga_register(void) |
| 119 | { |
| 120 | pci_qdev_register(&vga_info); |
| 121 | } |
| 122 | device_init(vga_register); |