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#include "ui/console.h"
36#include "qom/object.h"
37
38#define TYPE_ISA_VGA "isa-vga"
39OBJECT_DECLARE_SIMPLE_TYPE(ISAVGAState, ISA_VGA)
40
41struct ISAVGAState {
42 ISADevice parent_obj;
43
44 struct VGACommonState state;
45 PortioList portio_vga;
46 PortioList portio_vbe;
47};
48
49static void vga_isa_reset(DeviceState *dev)
50{
51 ISAVGAState *d = ISA_VGA(dev);
52 VGACommonState *s = &d->state;
53
54 vga_common_reset(s);
55}
56
57static void vga_isa_realizefn(DeviceState *dev, Error **errp)
58{
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;
64
65 s->global_vmstate = true;
66 if (!vga_common_init(s, OBJECT(dev), errp)) {
67 return;
68 }
69
70 s->legacy_address_space = isa_address_space(isadev);
71 vga_io_memory = vga_init_io(s, OBJECT(dev), &vga_ports, &vbe_ports);
72 isa_register_portio_list(isadev, &d->portio_vga,
73 0x3b0, vga_ports, s, "vga");
74 if (vbe_ports) {
75 isa_register_portio_list(isadev, &d->portio_vbe,
76 0x1ce, vbe_ports, s, "vbe");
77 }
78 memory_region_add_subregion_overlap(isa_address_space(isadev),
79 0x000a0000,
80 vga_io_memory, 1);
81 memory_region_set_coalescing(vga_io_memory);
82 s->con = graphic_console_init(dev, 0, s->hw_ops, s);
83
84 memory_region_add_subregion(isa_address_space(isadev),
85 VBE_DISPI_LFB_PHYSICAL_ADDRESS,
86 &s->vram);
87
88 rom_add_vga(VGABIOS_FILENAME);
89}
90
91static Property vga_isa_properties[] = {
92 DEFINE_PROP_UINT32("vgamem_mb", ISAVGAState, state.vram_size_mb, 8),
93 DEFINE_PROP_END_OF_LIST(),
94};
95
96static void vga_isa_class_initfn(ObjectClass *klass, void *data)
97{
98 DeviceClass *dc = DEVICE_CLASS(klass);
99
100 dc->realize = vga_isa_realizefn;
101 dc->reset = vga_isa_reset;
102 dc->vmsd = &vmstate_vga_common;
103 device_class_set_props(dc, vga_isa_properties);
104 set_bit(DEVICE_CATEGORY_DISPLAY, dc->categories);
105}
106
107static const TypeInfo vga_isa_info = {
108 .name = TYPE_ISA_VGA,
109 .parent = TYPE_ISA_DEVICE,
110 .instance_size = sizeof(ISAVGAState),
111 .class_init = vga_isa_class_initfn,
112};
113
114static void vga_isa_register_types(void)
115{
116 type_register_static(&vga_isa_info);
117}
118
119type_init(vga_isa_register_types)
120