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