xref: /qemu/hw/display/cirrus_vga_isa.c (revision a27bd6c779badb8d76e4430d810ef710a1b98f4e)
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"
30*a27bd6c7SMarkus Armbruster #include "hw/qdev-properties.h"
31ce3cf70eSThomas Huth #include "hw/isa/isa.h"
32ce3cf70eSThomas Huth #include "cirrus_vga_internal.h"
33ce3cf70eSThomas Huth 
34ce3cf70eSThomas Huth #define TYPE_ISA_CIRRUS_VGA "isa-cirrus-vga"
35ce3cf70eSThomas Huth #define ISA_CIRRUS_VGA(obj) \
36ce3cf70eSThomas Huth     OBJECT_CHECK(ISACirrusVGAState, (obj), TYPE_ISA_CIRRUS_VGA)
37ce3cf70eSThomas Huth 
38ce3cf70eSThomas Huth typedef struct ISACirrusVGAState {
39ce3cf70eSThomas Huth     ISADevice parent_obj;
40ce3cf70eSThomas Huth 
41ce3cf70eSThomas Huth     CirrusVGAState cirrus_vga;
42ce3cf70eSThomas Huth } ISACirrusVGAState;
43ce3cf70eSThomas Huth 
44ce3cf70eSThomas Huth static void isa_cirrus_vga_realizefn(DeviceState *dev, Error **errp)
45ce3cf70eSThomas Huth {
46ce3cf70eSThomas Huth     ISADevice *isadev = ISA_DEVICE(dev);
47ce3cf70eSThomas Huth     ISACirrusVGAState *d = ISA_CIRRUS_VGA(dev);
48ce3cf70eSThomas Huth     VGACommonState *s = &d->cirrus_vga.vga;
49ce3cf70eSThomas Huth 
50ce3cf70eSThomas Huth     /* follow real hardware, cirrus card emulated has 4 MB video memory.
51ce3cf70eSThomas Huth        Also accept 8 MB/16 MB for backward compatibility. */
52ce3cf70eSThomas Huth     if (s->vram_size_mb != 4 && s->vram_size_mb != 8 &&
53ce3cf70eSThomas Huth         s->vram_size_mb != 16) {
54ce3cf70eSThomas Huth         error_setg(errp, "Invalid cirrus_vga ram size '%u'",
55ce3cf70eSThomas Huth                    s->vram_size_mb);
56ce3cf70eSThomas Huth         return;
57ce3cf70eSThomas Huth     }
58ce3cf70eSThomas Huth     s->global_vmstate = true;
59ce3cf70eSThomas Huth     vga_common_init(s, OBJECT(dev));
60ce3cf70eSThomas Huth     cirrus_init_common(&d->cirrus_vga, OBJECT(dev), CIRRUS_ID_CLGD5430, 0,
61ce3cf70eSThomas Huth                        isa_address_space(isadev),
62ce3cf70eSThomas Huth                        isa_address_space_io(isadev));
63ce3cf70eSThomas Huth     s->con = graphic_console_init(dev, 0, s->hw_ops, s);
64ce3cf70eSThomas Huth     rom_add_vga(VGABIOS_CIRRUS_FILENAME);
65ce3cf70eSThomas Huth     /* XXX ISA-LFB support */
66ce3cf70eSThomas Huth     /* FIXME not qdev yet */
67ce3cf70eSThomas Huth }
68ce3cf70eSThomas Huth 
69ce3cf70eSThomas Huth static Property isa_cirrus_vga_properties[] = {
70ce3cf70eSThomas Huth     DEFINE_PROP_UINT32("vgamem_mb", struct ISACirrusVGAState,
71ce3cf70eSThomas Huth                        cirrus_vga.vga.vram_size_mb, 4),
72ce3cf70eSThomas Huth     DEFINE_PROP_BOOL("blitter", struct ISACirrusVGAState,
73ce3cf70eSThomas Huth                      cirrus_vga.enable_blitter, true),
74ce3cf70eSThomas Huth     DEFINE_PROP_END_OF_LIST(),
75ce3cf70eSThomas Huth };
76ce3cf70eSThomas Huth 
77ce3cf70eSThomas Huth static void isa_cirrus_vga_class_init(ObjectClass *klass, void *data)
78ce3cf70eSThomas Huth {
79ce3cf70eSThomas Huth     DeviceClass *dc = DEVICE_CLASS(klass);
80ce3cf70eSThomas Huth 
81ce3cf70eSThomas Huth     dc->vmsd  = &vmstate_cirrus_vga;
82ce3cf70eSThomas Huth     dc->realize = isa_cirrus_vga_realizefn;
83ce3cf70eSThomas Huth     dc->props = isa_cirrus_vga_properties;
84ce3cf70eSThomas Huth     set_bit(DEVICE_CATEGORY_DISPLAY, dc->categories);
85ce3cf70eSThomas Huth }
86ce3cf70eSThomas Huth 
87ce3cf70eSThomas Huth static const TypeInfo isa_cirrus_vga_info = {
88ce3cf70eSThomas Huth     .name          = TYPE_ISA_CIRRUS_VGA,
89ce3cf70eSThomas Huth     .parent        = TYPE_ISA_DEVICE,
90ce3cf70eSThomas Huth     .instance_size = sizeof(ISACirrusVGAState),
91ce3cf70eSThomas Huth     .class_init = isa_cirrus_vga_class_init,
92ce3cf70eSThomas Huth };
93ce3cf70eSThomas Huth 
94ce3cf70eSThomas Huth static void cirrus_vga_isa_register_types(void)
95ce3cf70eSThomas Huth {
96ce3cf70eSThomas Huth     type_register_static(&isa_cirrus_vga_info);
97ce3cf70eSThomas Huth }
98ce3cf70eSThomas Huth 
99ce3cf70eSThomas Huth type_init(cirrus_vga_isa_register_types)
100