1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27#include "qemu/osdep.h"
28#include "hw/isa/isa.h"
29#include "vga_int.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
36#define TYPE_ISA_VGA "isa-vga"
37#define ISA_VGA(obj) OBJECT_CHECK(ISAVGAState, (obj), TYPE_ISA_VGA)
38
39typedef struct ISAVGAState {
40 ISADevice parent_obj;
41
42 struct VGACommonState state;
43 PortioList portio_vga;
44 PortioList portio_vbe;
45} ISAVGAState;
46
47static void vga_isa_reset(DeviceState *dev)
48{
49 ISAVGAState *d = ISA_VGA(dev);
50 VGACommonState *s = &d->state;
51
52 vga_common_reset(s);
53}
54
55static void vga_isa_realizefn(DeviceState *dev, Error **errp)
56{
57 ISADevice *isadev = ISA_DEVICE(dev);
58 ISAVGAState *d = ISA_VGA(dev);
59 VGACommonState *s = &d->state;
60 MemoryRegion *vga_io_memory;
61 const MemoryRegionPortio *vga_ports, *vbe_ports;
62
63 s->global_vmstate = true;
64 vga_common_init(s, OBJECT(dev));
65 s->legacy_address_space = isa_address_space(isadev);
66 vga_io_memory = vga_init_io(s, OBJECT(dev), &vga_ports, &vbe_ports);
67 isa_register_portio_list(isadev, &d->portio_vga,
68 0x3b0, vga_ports, s, "vga");
69 if (vbe_ports) {
70 isa_register_portio_list(isadev, &d->portio_vbe,
71 0x1ce, vbe_ports, s, "vbe");
72 }
73 memory_region_add_subregion_overlap(isa_address_space(isadev),
74 0x000a0000,
75 vga_io_memory, 1);
76 memory_region_set_coalescing(vga_io_memory);
77 s->con = graphic_console_init(dev, 0, s->hw_ops, s);
78
79 memory_region_add_subregion(isa_address_space(isadev),
80 VBE_DISPI_LFB_PHYSICAL_ADDRESS,
81 &s->vram);
82
83 rom_add_vga(VGABIOS_FILENAME);
84}
85
86static Property vga_isa_properties[] = {
87 DEFINE_PROP_UINT32("vgamem_mb", ISAVGAState, state.vram_size_mb, 8),
88 DEFINE_PROP_END_OF_LIST(),
89};
90
91static void vga_isa_class_initfn(ObjectClass *klass, void *data)
92{
93 DeviceClass *dc = DEVICE_CLASS(klass);
94
95 dc->realize = vga_isa_realizefn;
96 dc->reset = vga_isa_reset;
97 dc->vmsd = &vmstate_vga_common;
98 device_class_set_props(dc, vga_isa_properties);
99 set_bit(DEVICE_CATEGORY_DISPLAY, dc->categories);
100}
101
102static const TypeInfo vga_isa_info = {
103 .name = TYPE_ISA_VGA,
104 .parent = TYPE_ISA_DEVICE,
105 .instance_size = sizeof(ISAVGAState),
106 .class_init = vga_isa_class_initfn,
107};
108
109static void vga_isa_register_types(void)
110{
111 type_register_static(&vga_isa_info);
112}
113
114type_init(vga_isa_register_types)
115