3c2278d5544ae03b5fe04f0a753d08031f9d0f17
[sdk/emulator/qemu.git] / hw / vga-pci.c
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 "pci.h"
27 #include "vga-pci.h"
28 #include "vga_int.h"
29 #include "pixel_ops.h"
30 #include "qemu-timer.h"
31 #include "loader.h"
32 #ifdef CONFIG_MARU
33 #include "../tizen/src/hw/maru_device_ids.h"
34 #include "../tizen/src/hw/maru_vga_int.h"
35 #endif
36
37 typedef struct PCIVGAState {
38     PCIDevice dev;
39     VGACommonState vga;
40 } PCIVGAState;
41
42 static const VMStateDescription vmstate_vga_pci = {
43     .name = "vga",
44     .version_id = 2,
45     .minimum_version_id = 2,
46     .minimum_version_id_old = 2,
47     .fields      = (VMStateField []) {
48         VMSTATE_PCI_DEVICE(dev, PCIVGAState),
49         VMSTATE_STRUCT(vga, PCIVGAState, 0, vmstate_vga_common, VGACommonState),
50         VMSTATE_END_OF_LIST()
51     }
52 };
53
54 static int pci_vga_initfn(PCIDevice *dev)
55 {
56      PCIVGAState *d = DO_UPCAST(PCIVGAState, dev, dev);
57      VGACommonState *s = &d->vga;
58
59      // vga + console init
60      vga_common_init(s);
61      vga_init(s, pci_address_space(dev), pci_address_space_io(dev), true);
62
63      s->ds = graphic_console_init(s->update, s->invalidate,
64                                   s->screen_dump, s->text_update, s);
65
66      /* XXX: VGA_RAM_SIZE must be a power of two */
67      pci_register_bar(&d->dev, 0, PCI_BASE_ADDRESS_MEM_PREFETCH, &s->vram);
68
69      if (!dev->rom_bar) {
70          /* compatibility with pc-0.13 and older */
71          vga_init_vbe(s, pci_address_space(dev));
72      }
73
74      return 0;
75 }
76
77 DeviceState *pci_vga_init(PCIBus *bus)
78 {
79     return &pci_create_simple(bus, -1, "VGA")->qdev;
80 }
81
82 static Property vga_pci_properties[] = {
83     DEFINE_PROP_UINT32("vgamem_mb", PCIVGAState, vga.vram_size_mb, 16),
84     DEFINE_PROP_END_OF_LIST(),
85 };
86
87 static void vga_class_init(ObjectClass *klass, void *data)
88 {
89     DeviceClass *dc = DEVICE_CLASS(klass);
90     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
91
92     k->no_hotplug = 1;
93     k->init = pci_vga_initfn;
94     k->romfile = "vgabios-stdvga.bin";
95     k->vendor_id = PCI_VENDOR_ID_QEMU;
96     k->device_id = PCI_DEVICE_ID_QEMU_VGA;
97     k->class_id = PCI_CLASS_DISPLAY_VGA;
98     dc->vmsd = &vmstate_vga_pci;
99     dc->props = vga_pci_properties;
100 }
101
102 static TypeInfo vga_info = {
103     .name          = "VGA",
104     .parent        = TYPE_PCI_DEVICE,
105     .instance_size = sizeof(PCIVGAState),
106     .class_init    = vga_class_init,
107 };
108
109 #ifdef CONFIG_MARU
110
111 DeviceState *pci_maru_vga_init(PCIBus *bus)
112 {
113     return &pci_create_simple(bus, -1, "MARU_VGA")->qdev;
114 }
115
116 static int maru_pci_vga_initfn(PCIDevice *dev)
117 {
118      PCIVGAState *d = DO_UPCAST(PCIVGAState, dev, dev);
119      VGACommonState *s = &d->vga;
120
121      // vga + console init
122      maru_vga_common_init(s);
123      vga_init(s, pci_address_space(dev), pci_address_space_io(dev), true);
124
125      s->ds = graphic_console_init(s->update, s->invalidate,
126                                   s->screen_dump, s->text_update, s);
127
128      /* XXX: VGA_RAM_SIZE must be a power of two */
129      pci_register_bar(&d->dev, 0, PCI_BASE_ADDRESS_MEM_PREFETCH, &s->vram);
130
131      if (!dev->rom_bar) {
132          /* compatibility with pc-0.13 and older */
133          vga_init_vbe(s, pci_address_space(dev));
134      }
135
136      return 0;
137 }
138
139 static void maru_pci_vga_classinit(ObjectClass *klass, void *data)
140 {
141     DeviceClass *dc = DEVICE_CLASS(klass);
142     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
143
144     k->no_hotplug = 1;
145     k->init = maru_pci_vga_initfn;
146     k->romfile = "vgabios-maruvga.bin";
147     k->vendor_id = PCI_VENDOR_ID_QEMU;
148     k->device_id = PCI_DEVICE_ID_QEMU_VGA;
149     k->class_id = PCI_CLASS_DISPLAY_VGA;
150     dc->vmsd = &vmstate_vga_pci;
151     dc->props = vga_pci_properties;
152 }
153
154 static TypeInfo maru_vga_info = {
155     .name = "MARU_VGA",
156     .parent = TYPE_PCI_DEVICE,
157     .instance_size = sizeof(PCIVGAState),
158     .class_init = maru_pci_vga_classinit,
159 };
160
161 #endif // CONFIG_MARU
162
163 static void vga_register_types(void)
164 {
165     type_register_static(&vga_info);
166 #ifdef CONFIG_MARU
167     type_register_static(&maru_vga_info);
168 #endif
169 }
170
171 type_init(vga_register_types)