1ce3cf70eSThomas Huth /*
2ce3cf70eSThomas Huth * QEMU Cirrus CLGD 54xx VGA Emulator, ISA bus support
3ce3cf70eSThomas Huth *
4ce3cf70eSThomas Huth * Copyright (c) 2004 Fabrice Bellard
5ce3cf70eSThomas Huth * Copyright (c) 2004 Makoto Suzuki (suzu)
6ce3cf70eSThomas Huth *
7ce3cf70eSThomas Huth * Permission is hereby granted, free of charge, to any person obtaining a copy
8ce3cf70eSThomas Huth * of this software and associated documentation files (the "Software"), to deal
9ce3cf70eSThomas Huth * in the Software without restriction, including without limitation the rights
10ce3cf70eSThomas Huth * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11ce3cf70eSThomas Huth * copies of the Software, and to permit persons to whom the Software is
12ce3cf70eSThomas Huth * furnished to do so, subject to the following conditions:
13ce3cf70eSThomas Huth *
14ce3cf70eSThomas Huth * The above copyright notice and this permission notice shall be included in
15ce3cf70eSThomas Huth * all copies or substantial portions of the Software.
16ce3cf70eSThomas Huth *
17ce3cf70eSThomas Huth * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18ce3cf70eSThomas Huth * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19ce3cf70eSThomas Huth * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20ce3cf70eSThomas Huth * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21ce3cf70eSThomas Huth * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22ce3cf70eSThomas Huth * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23ce3cf70eSThomas Huth * THE SOFTWARE.
24ce3cf70eSThomas Huth */
25ce3cf70eSThomas Huth
26ce3cf70eSThomas Huth #include "qemu/osdep.h"
27ce3cf70eSThomas Huth #include "qapi/error.h"
280b8fa32fSMarkus Armbruster #include "qemu/module.h"
29ce3cf70eSThomas Huth #include "hw/loader.h"
30a27bd6c7SMarkus Armbruster #include "hw/qdev-properties.h"
31ce3cf70eSThomas Huth #include "hw/isa/isa.h"
32ce3cf70eSThomas Huth #include "cirrus_vga_internal.h"
33db1015e9SEduardo Habkost #include "qom/object.h"
34*28cf3960SMichael S. Tsirkin #include "ui/console.h"
35ce3cf70eSThomas Huth
36ce3cf70eSThomas Huth #define TYPE_ISA_CIRRUS_VGA "isa-cirrus-vga"
378063396bSEduardo Habkost OBJECT_DECLARE_SIMPLE_TYPE(ISACirrusVGAState, ISA_CIRRUS_VGA)
38ce3cf70eSThomas Huth
39db1015e9SEduardo Habkost struct ISACirrusVGAState {
40ce3cf70eSThomas Huth ISADevice parent_obj;
41ce3cf70eSThomas Huth
42ce3cf70eSThomas Huth CirrusVGAState cirrus_vga;
43db1015e9SEduardo Habkost };
44ce3cf70eSThomas Huth
isa_cirrus_vga_realizefn(DeviceState * dev,Error ** errp)45ce3cf70eSThomas Huth static void isa_cirrus_vga_realizefn(DeviceState *dev, Error **errp)
46ce3cf70eSThomas Huth {
47ce3cf70eSThomas Huth ISADevice *isadev = ISA_DEVICE(dev);
48ce3cf70eSThomas Huth ISACirrusVGAState *d = ISA_CIRRUS_VGA(dev);
49ce3cf70eSThomas Huth VGACommonState *s = &d->cirrus_vga.vga;
50ce3cf70eSThomas Huth
51ce3cf70eSThomas Huth /* follow real hardware, cirrus card emulated has 4 MB video memory.
52ce3cf70eSThomas Huth Also accept 8 MB/16 MB for backward compatibility. */
53ce3cf70eSThomas Huth if (s->vram_size_mb != 4 && s->vram_size_mb != 8 &&
54ce3cf70eSThomas Huth s->vram_size_mb != 16) {
55ce3cf70eSThomas Huth error_setg(errp, "Invalid cirrus_vga ram size '%u'",
56ce3cf70eSThomas Huth s->vram_size_mb);
57ce3cf70eSThomas Huth return;
58ce3cf70eSThomas Huth }
59ce3cf70eSThomas Huth s->global_vmstate = true;
606832deb8SThomas Huth if (!vga_common_init(s, OBJECT(dev), errp)) {
616832deb8SThomas Huth return;
626832deb8SThomas Huth }
63ce3cf70eSThomas Huth cirrus_init_common(&d->cirrus_vga, OBJECT(dev), CIRRUS_ID_CLGD5430, 0,
64ce3cf70eSThomas Huth isa_address_space(isadev),
65ce3cf70eSThomas Huth isa_address_space_io(isadev));
66ce3cf70eSThomas Huth s->con = graphic_console_init(dev, 0, s->hw_ops, s);
67ce3cf70eSThomas Huth rom_add_vga(VGABIOS_CIRRUS_FILENAME);
68ce3cf70eSThomas Huth /* XXX ISA-LFB support */
69ce3cf70eSThomas Huth /* FIXME not qdev yet */
70ce3cf70eSThomas Huth }
71ce3cf70eSThomas Huth
72ce3cf70eSThomas Huth static Property isa_cirrus_vga_properties[] = {
73ce3cf70eSThomas Huth DEFINE_PROP_UINT32("vgamem_mb", struct ISACirrusVGAState,
74ce3cf70eSThomas Huth cirrus_vga.vga.vram_size_mb, 4),
75ce3cf70eSThomas Huth DEFINE_PROP_BOOL("blitter", struct ISACirrusVGAState,
76ce3cf70eSThomas Huth cirrus_vga.enable_blitter, true),
77ce3cf70eSThomas Huth DEFINE_PROP_END_OF_LIST(),
78ce3cf70eSThomas Huth };
79ce3cf70eSThomas Huth
isa_cirrus_vga_class_init(ObjectClass * klass,void * data)80ce3cf70eSThomas Huth static void isa_cirrus_vga_class_init(ObjectClass *klass, void *data)
81ce3cf70eSThomas Huth {
82ce3cf70eSThomas Huth DeviceClass *dc = DEVICE_CLASS(klass);
83ce3cf70eSThomas Huth
84ce3cf70eSThomas Huth dc->vmsd = &vmstate_cirrus_vga;
85ce3cf70eSThomas Huth dc->realize = isa_cirrus_vga_realizefn;
864f67d30bSMarc-André Lureau device_class_set_props(dc, isa_cirrus_vga_properties);
87ce3cf70eSThomas Huth set_bit(DEVICE_CATEGORY_DISPLAY, dc->categories);
88ce3cf70eSThomas Huth }
89ce3cf70eSThomas Huth
90ce3cf70eSThomas Huth static const TypeInfo isa_cirrus_vga_info = {
91ce3cf70eSThomas Huth .name = TYPE_ISA_CIRRUS_VGA,
92ce3cf70eSThomas Huth .parent = TYPE_ISA_DEVICE,
93ce3cf70eSThomas Huth .instance_size = sizeof(ISACirrusVGAState),
94ce3cf70eSThomas Huth .class_init = isa_cirrus_vga_class_init,
95ce3cf70eSThomas Huth };
96ce3cf70eSThomas Huth
cirrus_vga_isa_register_types(void)97ce3cf70eSThomas Huth static void cirrus_vga_isa_register_types(void)
98ce3cf70eSThomas Huth {
99ce3cf70eSThomas Huth type_register_static(&isa_cirrus_vga_info);
100ce3cf70eSThomas Huth }
101ce3cf70eSThomas Huth
102ce3cf70eSThomas Huth type_init(cirrus_vga_isa_register_types)
103