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" |
Juan Quintela | 47d37dd | 2009-08-31 16:07:15 +0200 | [diff] [blame] | 26 | #include "pci.h" |
zhlcindy@gmail.com | c1195d1 | 2012-08-06 16:41:59 +0000 | [diff] [blame] | 27 | #include "vga-pci.h" |
Juan Quintela | 47d37dd | 2009-08-31 16:07:15 +0200 | [diff] [blame] | 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 int pci_vga_initfn(PCIDevice *dev) |
| 51 | { |
| 52 | PCIVGAState *d = DO_UPCAST(PCIVGAState, dev, dev); |
| 53 | VGACommonState *s = &d->vga; |
Juan Quintela | 47d37dd | 2009-08-31 16:07:15 +0200 | [diff] [blame] | 54 | |
| 55 | // vga + console init |
Gerd Hoffmann | 4a1e244 | 2012-05-24 09:59:44 +0200 | [diff] [blame] | 56 | vga_common_init(s); |
Richard Henderson | 0a039dc | 2011-08-16 08:27:39 -0700 | [diff] [blame] | 57 | vga_init(s, pci_address_space(dev), pci_address_space_io(dev), true); |
Juan Quintela | 47d37dd | 2009-08-31 16:07:15 +0200 | [diff] [blame] | 58 | |
| 59 | s->ds = graphic_console_init(s->update, s->invalidate, |
| 60 | s->screen_dump, s->text_update, s); |
| 61 | |
Juan Quintela | 47d37dd | 2009-08-31 16:07:15 +0200 | [diff] [blame] | 62 | /* XXX: VGA_RAM_SIZE must be a power of two */ |
Avi Kivity | e824b2c | 2011-08-08 16:09:31 +0300 | [diff] [blame] | 63 | pci_register_bar(&d->dev, 0, PCI_BASE_ADDRESS_MEM_PREFETCH, &s->vram); |
Juan Quintela | 47d37dd | 2009-08-31 16:07:15 +0200 | [diff] [blame] | 64 | |
Gerd Hoffmann | 281a26b | 2010-11-17 12:06:44 +0100 | [diff] [blame] | 65 | if (!dev->rom_bar) { |
| 66 | /* compatibility with pc-0.13 and older */ |
Avi Kivity | be20f9e | 2011-08-15 17:17:37 +0300 | [diff] [blame] | 67 | vga_init_vbe(s, pci_address_space(dev)); |
Gerd Hoffmann | 281a26b | 2010-11-17 12:06:44 +0100 | [diff] [blame] | 68 | } |
| 69 | |
Juan Quintela | 47d37dd | 2009-08-31 16:07:15 +0200 | [diff] [blame] | 70 | return 0; |
| 71 | } |
| 72 | |
Anthony Liguori | ad6d45f | 2011-12-12 14:29:41 -0600 | [diff] [blame] | 73 | DeviceState *pci_vga_init(PCIBus *bus) |
Juan Quintela | 47d37dd | 2009-08-31 16:07:15 +0200 | [diff] [blame] | 74 | { |
Anthony Liguori | ad6d45f | 2011-12-12 14:29:41 -0600 | [diff] [blame] | 75 | return &pci_create_simple(bus, -1, "VGA")->qdev; |
Juan Quintela | 47d37dd | 2009-08-31 16:07:15 +0200 | [diff] [blame] | 76 | } |
| 77 | |
Gerd Hoffmann | 4a1e244 | 2012-05-24 09:59:44 +0200 | [diff] [blame] | 78 | static Property vga_pci_properties[] = { |
Gerd Hoffmann | 9e56edc | 2012-06-11 10:42:53 +0200 | [diff] [blame] | 79 | DEFINE_PROP_UINT32("vgamem_mb", PCIVGAState, vga.vram_size_mb, 16), |
Gerd Hoffmann | 4a1e244 | 2012-05-24 09:59:44 +0200 | [diff] [blame] | 80 | DEFINE_PROP_END_OF_LIST(), |
| 81 | }; |
| 82 | |
Anthony Liguori | 40021f0 | 2011-12-04 12:22:06 -0600 | [diff] [blame] | 83 | static void vga_class_init(ObjectClass *klass, void *data) |
| 84 | { |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 85 | DeviceClass *dc = DEVICE_CLASS(klass); |
Anthony Liguori | 40021f0 | 2011-12-04 12:22:06 -0600 | [diff] [blame] | 86 | PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); |
Isaku Yamahata | 3290277 | 2011-05-25 10:58:31 +0900 | [diff] [blame] | 87 | |
Anthony Liguori | 40021f0 | 2011-12-04 12:22:06 -0600 | [diff] [blame] | 88 | k->no_hotplug = 1; |
| 89 | k->init = pci_vga_initfn; |
| 90 | k->romfile = "vgabios-stdvga.bin"; |
| 91 | k->vendor_id = PCI_VENDOR_ID_QEMU; |
| 92 | k->device_id = PCI_DEVICE_ID_QEMU_VGA; |
| 93 | k->class_id = PCI_CLASS_DISPLAY_VGA; |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 94 | dc->vmsd = &vmstate_vga_pci; |
Gerd Hoffmann | 4a1e244 | 2012-05-24 09:59:44 +0200 | [diff] [blame] | 95 | dc->props = vga_pci_properties; |
Anthony Liguori | 40021f0 | 2011-12-04 12:22:06 -0600 | [diff] [blame] | 96 | } |
| 97 | |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 98 | static TypeInfo vga_info = { |
| 99 | .name = "VGA", |
| 100 | .parent = TYPE_PCI_DEVICE, |
| 101 | .instance_size = sizeof(PCIVGAState), |
| 102 | .class_init = vga_class_init, |
Juan Quintela | 47d37dd | 2009-08-31 16:07:15 +0200 | [diff] [blame] | 103 | }; |
| 104 | |
Andreas Färber | 83f7d43 | 2012-02-09 15:20:55 +0100 | [diff] [blame] | 105 | static void vga_register_types(void) |
Juan Quintela | 47d37dd | 2009-08-31 16:07:15 +0200 | [diff] [blame] | 106 | { |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 107 | type_register_static(&vga_info); |
Juan Quintela | 47d37dd | 2009-08-31 16:07:15 +0200 | [diff] [blame] | 108 | } |
Andreas Färber | 83f7d43 | 2012-02-09 15:20:55 +0100 | [diff] [blame] | 109 | |
| 110 | type_init(vga_register_types) |