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