1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24#include "qemu/osdep.h"
25#include "qemu/units.h"
26#include "hw/hw.h"
27#include "hw/display/vga.h"
28#include "vga_int.h"
29#include "ui/pixel_ops.h"
30
31#define VGA_RAM_SIZE (8 * MiB)
32
33typedef struct ISAVGAMMState {
34 VGACommonState vga;
35 int it_shift;
36} ISAVGAMMState;
37
38
39static uint64_t vga_mm_read(void *opaque, hwaddr addr, unsigned size)
40{
41 ISAVGAMMState *s = opaque;
42
43 return vga_ioport_read(&s->vga, addr >> s->it_shift) &
44 MAKE_64BIT_MASK(0, size * 8);
45}
46
47static void vga_mm_write(void *opaque, hwaddr addr, uint64_t value,
48 unsigned size)
49{
50 ISAVGAMMState *s = opaque;
51
52 vga_ioport_write(&s->vga, addr >> s->it_shift,
53 value & MAKE_64BIT_MASK(0, size * 8));
54}
55
56static const MemoryRegionOps vga_mm_ctrl_ops = {
57 .read = vga_mm_read,
58 .write = vga_mm_write,
59 .valid.min_access_size = 1,
60 .valid.max_access_size = 4,
61 .impl.min_access_size = 1,
62 .impl.max_access_size = 4,
63 .endianness = DEVICE_NATIVE_ENDIAN,
64};
65
66static void vga_mm_init(ISAVGAMMState *s, hwaddr vram_base,
67 hwaddr ctrl_base, int it_shift,
68 MemoryRegion *address_space)
69{
70 MemoryRegion *s_ioport_ctrl, *vga_io_memory;
71
72 s->it_shift = it_shift;
73 s_ioport_ctrl = g_malloc(sizeof(*s_ioport_ctrl));
74 memory_region_init_io(s_ioport_ctrl, NULL, &vga_mm_ctrl_ops, s,
75 "vga-mm-ctrl", 0x100000);
76 memory_region_set_flush_coalesced(s_ioport_ctrl);
77
78 vga_io_memory = g_malloc(sizeof(*vga_io_memory));
79
80 memory_region_init_io(vga_io_memory, NULL, &vga_mem_ops, &s->vga,
81 "vga-mem", 0x20000);
82
83 vmstate_register(NULL, 0, &vmstate_vga_common, s);
84
85 memory_region_add_subregion(address_space, ctrl_base, s_ioport_ctrl);
86 s->vga.bank_offset = 0;
87 memory_region_add_subregion(address_space,
88 vram_base + 0x000a0000, vga_io_memory);
89 memory_region_set_coalescing(vga_io_memory);
90}
91
92int isa_vga_mm_init(hwaddr vram_base,
93 hwaddr ctrl_base, int it_shift,
94 MemoryRegion *address_space)
95{
96 ISAVGAMMState *s;
97
98 s = g_malloc0(sizeof(*s));
99
100 s->vga.vram_size_mb = VGA_RAM_SIZE / MiB;
101 s->vga.global_vmstate = true;
102 vga_common_init(&s->vga, NULL);
103 vga_mm_init(s, vram_base, ctrl_base, it_shift, address_space);
104
105 s->vga.con = graphic_console_init(NULL, 0, s->vga.hw_ops, s);
106
107 vga_init_vbe(&s->vga, NULL, address_space);
108 return 0;
109}
110