blob: 9abbada8f17a8737814c1de48e6c16e3cd95c514 [file] [log] [blame]
Juan Quintela47d37dd2009-08-31 16:07:15 +02001/*
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 Quintela47d37dd2009-08-31 16:07:15 +020026#include "pci.h"
zhlcindy@gmail.comc1195d12012-08-06 16:41:59 +000027#include "vga-pci.h"
Juan Quintela47d37dd2009-08-31 16:07:15 +020028#include "vga_int.h"
29#include "pixel_ops.h"
30#include "qemu-timer.h"
Gerd Hoffmann5245d572009-10-26 12:18:26 +010031#include "loader.h"
Juan Quintela47d37dd2009-08-31 16:07:15 +020032
33typedef struct PCIVGAState {
34 PCIDevice dev;
35 VGACommonState vga;
36} PCIVGAState;
37
Juan Quintelaa4f96312009-10-14 15:42:44 +020038static 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 Quintela47d37dd2009-08-31 16:07:15 +020047 }
Juan Quintelaa4f96312009-10-14 15:42:44 +020048};
Juan Quintela47d37dd2009-08-31 16:07:15 +020049
Juan Quintela47d37dd2009-08-31 16:07:15 +020050static int pci_vga_initfn(PCIDevice *dev)
51{
52 PCIVGAState *d = DO_UPCAST(PCIVGAState, dev, dev);
53 VGACommonState *s = &d->vga;
Juan Quintela47d37dd2009-08-31 16:07:15 +020054
55 // vga + console init
Gerd Hoffmann4a1e2442012-05-24 09:59:44 +020056 vga_common_init(s);
Richard Henderson0a039dc2011-08-16 08:27:39 -070057 vga_init(s, pci_address_space(dev), pci_address_space_io(dev), true);
Juan Quintela47d37dd2009-08-31 16:07:15 +020058
59 s->ds = graphic_console_init(s->update, s->invalidate,
60 s->screen_dump, s->text_update, s);
61
Juan Quintela47d37dd2009-08-31 16:07:15 +020062 /* XXX: VGA_RAM_SIZE must be a power of two */
Avi Kivitye824b2c2011-08-08 16:09:31 +030063 pci_register_bar(&d->dev, 0, PCI_BASE_ADDRESS_MEM_PREFETCH, &s->vram);
Juan Quintela47d37dd2009-08-31 16:07:15 +020064
Gerd Hoffmann281a26b2010-11-17 12:06:44 +010065 if (!dev->rom_bar) {
66 /* compatibility with pc-0.13 and older */
Avi Kivitybe20f9e2011-08-15 17:17:37 +030067 vga_init_vbe(s, pci_address_space(dev));
Gerd Hoffmann281a26b2010-11-17 12:06:44 +010068 }
69
Juan Quintela47d37dd2009-08-31 16:07:15 +020070 return 0;
71}
72
Anthony Liguoriad6d45f2011-12-12 14:29:41 -060073DeviceState *pci_vga_init(PCIBus *bus)
Juan Quintela47d37dd2009-08-31 16:07:15 +020074{
Anthony Liguoriad6d45f2011-12-12 14:29:41 -060075 return &pci_create_simple(bus, -1, "VGA")->qdev;
Juan Quintela47d37dd2009-08-31 16:07:15 +020076}
77
Gerd Hoffmann4a1e2442012-05-24 09:59:44 +020078static Property vga_pci_properties[] = {
Gerd Hoffmann9e56edc2012-06-11 10:42:53 +020079 DEFINE_PROP_UINT32("vgamem_mb", PCIVGAState, vga.vram_size_mb, 16),
Gerd Hoffmann4a1e2442012-05-24 09:59:44 +020080 DEFINE_PROP_END_OF_LIST(),
81};
82
Anthony Liguori40021f02011-12-04 12:22:06 -060083static void vga_class_init(ObjectClass *klass, void *data)
84{
Anthony Liguori39bffca2011-12-07 21:34:16 -060085 DeviceClass *dc = DEVICE_CLASS(klass);
Anthony Liguori40021f02011-12-04 12:22:06 -060086 PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
Isaku Yamahata32902772011-05-25 10:58:31 +090087
Anthony Liguori40021f02011-12-04 12:22:06 -060088 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 Liguori39bffca2011-12-07 21:34:16 -060094 dc->vmsd = &vmstate_vga_pci;
Gerd Hoffmann4a1e2442012-05-24 09:59:44 +020095 dc->props = vga_pci_properties;
Anthony Liguori40021f02011-12-04 12:22:06 -060096}
97
Anthony Liguori39bffca2011-12-07 21:34:16 -060098static TypeInfo vga_info = {
99 .name = "VGA",
100 .parent = TYPE_PCI_DEVICE,
101 .instance_size = sizeof(PCIVGAState),
102 .class_init = vga_class_init,
Juan Quintela47d37dd2009-08-31 16:07:15 +0200103};
104
Andreas Färber83f7d432012-02-09 15:20:55 +0100105static void vga_register_types(void)
Juan Quintela47d37dd2009-08-31 16:07:15 +0200106{
Anthony Liguori39bffca2011-12-07 21:34:16 -0600107 type_register_static(&vga_info);
Juan Quintela47d37dd2009-08-31 16:07:15 +0200108}
Andreas Färber83f7d432012-02-09 15:20:55 +0100109
110type_init(vga_register_types)