2 * QEMU ISA VGA Emulator.
4 * see docs/specs/standard-vga.txt for virtual hardware specs.
6 * Copyright (c) 2003 Fabrice Bellard
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27 #include "qemu/osdep.h"
28 #include "hw/isa/isa.h"
30 #include "ui/pixel_ops.h"
31 #include "qemu/module.h"
32 #include "qemu/timer.h"
33 #include "hw/loader.h"
34 #include "hw/qdev-properties.h"
35 #include "qom/object.h"
36 #include "qapi/error.h"
38 #define TYPE_ISA_VGA "isa-vga"
39 OBJECT_DECLARE_SIMPLE_TYPE(ISAVGAState
, ISA_VGA
)
44 struct VGACommonState state
;
45 PortioList portio_vga
;
46 PortioList portio_vbe
;
49 static void vga_isa_reset(DeviceState
*dev
)
51 ISAVGAState
*d
= ISA_VGA(dev
);
52 VGACommonState
*s
= &d
->state
;
57 static void vga_isa_realizefn(DeviceState
*dev
, Error
**errp
)
59 ISADevice
*isadev
= ISA_DEVICE(dev
);
60 ISAVGAState
*d
= ISA_VGA(dev
);
61 VGACommonState
*s
= &d
->state
;
62 MemoryRegion
*vga_io_memory
;
63 const MemoryRegionPortio
*vga_ports
, *vbe_ports
;
66 * make sure this device is not being added twice, if so
67 * exit without crashing qemu
69 if (object_resolve_path_type("", TYPE_ISA_VGA
, NULL
)) {
70 error_setg(errp
, "at most one %s device is permitted", TYPE_ISA_VGA
);
74 s
->global_vmstate
= true;
75 vga_common_init(s
, OBJECT(dev
));
76 s
->legacy_address_space
= isa_address_space(isadev
);
77 vga_io_memory
= vga_init_io(s
, OBJECT(dev
), &vga_ports
, &vbe_ports
);
78 isa_register_portio_list(isadev
, &d
->portio_vga
,
79 0x3b0, vga_ports
, s
, "vga");
81 isa_register_portio_list(isadev
, &d
->portio_vbe
,
82 0x1ce, vbe_ports
, s
, "vbe");
84 memory_region_add_subregion_overlap(isa_address_space(isadev
),
87 memory_region_set_coalescing(vga_io_memory
);
88 s
->con
= graphic_console_init(dev
, 0, s
->hw_ops
, s
);
90 memory_region_add_subregion(isa_address_space(isadev
),
91 VBE_DISPI_LFB_PHYSICAL_ADDRESS
,
94 rom_add_vga(VGABIOS_FILENAME
);
97 static Property vga_isa_properties
[] = {
98 DEFINE_PROP_UINT32("vgamem_mb", ISAVGAState
, state
.vram_size_mb
, 8),
99 DEFINE_PROP_END_OF_LIST(),
102 static void vga_isa_class_initfn(ObjectClass
*klass
, void *data
)
104 DeviceClass
*dc
= DEVICE_CLASS(klass
);
106 dc
->realize
= vga_isa_realizefn
;
107 dc
->reset
= vga_isa_reset
;
108 dc
->vmsd
= &vmstate_vga_common
;
109 device_class_set_props(dc
, vga_isa_properties
);
110 set_bit(DEVICE_CATEGORY_DISPLAY
, dc
->categories
);
113 static const TypeInfo vga_isa_info
= {
114 .name
= TYPE_ISA_VGA
,
115 .parent
= TYPE_ISA_DEVICE
,
116 .instance_size
= sizeof(ISAVGAState
),
117 .class_init
= vga_isa_class_initfn
,
120 static void vga_isa_register_types(void)
122 type_register_static(&vga_isa_info
);
125 type_init(vga_isa_register_types
)