]> git.proxmox.com Git - mirror_qemu.git/blame - hw/display/vga-isa-mm.c
Merge remote-tracking branch 'remotes/vivier2/tags/trivial-patches-pull-request'...
[mirror_qemu.git] / hw / display / vga-isa-mm.c
CommitLineData
79b97bf2
JQ
1/*
2 * QEMU ISA MM VGA Emulator.
3 *
4 * Copyright (c) 2003 Fabrice Bellard
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
47df5154 24#include "qemu/osdep.h"
f0353b0d 25#include "qemu/units.h"
83c9f4ca 26#include "hw/hw.h"
866e2b37 27#include "hw/display/vga.h"
47b43a1f 28#include "vga_int.h"
28ecbaee 29#include "ui/pixel_ops.h"
79b97bf2 30
f0353b0d 31#define VGA_RAM_SIZE (8 * MiB)
4a1e244e 32
79b97bf2
JQ
33typedef struct ISAVGAMMState {
34 VGACommonState vga;
35 int it_shift;
36} ISAVGAMMState;
37
38/* Memory mapped interface */
5f927998 39static uint64_t vga_mm_read(void *opaque, hwaddr addr, unsigned size)
79b97bf2
JQ
40{
41 ISAVGAMMState *s = opaque;
42
5f927998
PM
43 return vga_ioport_read(&s->vga, addr >> s->it_shift) &
44 MAKE_64BIT_MASK(0, size * 8);
79b97bf2
JQ
45}
46
5f927998
PM
47static void vga_mm_write(void *opaque, hwaddr addr, uint64_t value,
48 unsigned size)
79b97bf2
JQ
49{
50 ISAVGAMMState *s = opaque;
51
5f927998
PM
52 vga_ioport_write(&s->vga, addr >> s->it_shift,
53 value & MAKE_64BIT_MASK(0, size * 8));
79b97bf2
JQ
54}
55
b1950430 56static const MemoryRegionOps vga_mm_ctrl_ops = {
5f927998
PM
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,
b1950430 63 .endianness = DEVICE_NATIVE_ENDIAN,
79b97bf2
JQ
64};
65
a8170e5e
AK
66static void vga_mm_init(ISAVGAMMState *s, hwaddr vram_base,
67 hwaddr ctrl_base, int it_shift,
be20f9e9 68 MemoryRegion *address_space)
79b97bf2 69{
b1950430 70 MemoryRegion *s_ioport_ctrl, *vga_io_memory;
79b97bf2
JQ
71
72 s->it_shift = it_shift;
7267c094 73 s_ioport_ctrl = g_malloc(sizeof(*s_ioport_ctrl));
2c9b15ca 74 memory_region_init_io(s_ioport_ctrl, NULL, &vga_mm_ctrl_ops, s,
b1950430 75 "vga-mm-ctrl", 0x100000);
bd8f2f5d 76 memory_region_set_flush_coalesced(s_ioport_ctrl);
b1950430 77
7267c094 78 vga_io_memory = g_malloc(sizeof(*vga_io_memory));
b1950430 79 /* XXX: endianness? */
2c9b15ca 80 memory_region_init_io(vga_io_memory, NULL, &vga_mem_ops, &s->vga,
b1950430 81 "vga-mem", 0x20000);
79b97bf2 82
0be71e32 83 vmstate_register(NULL, 0, &vmstate_vga_common, s);
79b97bf2 84
be20f9e9 85 memory_region_add_subregion(address_space, ctrl_base, s_ioport_ctrl);
79b97bf2 86 s->vga.bank_offset = 0;
be20f9e9 87 memory_region_add_subregion(address_space,
b1950430
AK
88 vram_base + 0x000a0000, vga_io_memory);
89 memory_region_set_coalescing(vga_io_memory);
79b97bf2
JQ
90}
91
a8170e5e
AK
92int isa_vga_mm_init(hwaddr vram_base,
93 hwaddr ctrl_base, int it_shift,
be20f9e9 94 MemoryRegion *address_space)
79b97bf2
JQ
95{
96 ISAVGAMMState *s;
97
7267c094 98 s = g_malloc0(sizeof(*s));
79b97bf2 99
f0353b0d 100 s->vga.vram_size_mb = VGA_RAM_SIZE / MiB;
1fcfdc43
GH
101 s->vga.global_vmstate = true;
102 vga_common_init(&s->vga, NULL);
be20f9e9 103 vga_mm_init(s, vram_base, ctrl_base, it_shift, address_space);
79b97bf2 104
5643706a 105 s->vga.con = graphic_console_init(NULL, 0, s->vga.hw_ops, s);
79b97bf2 106
83118327 107 vga_init_vbe(&s->vga, NULL, address_space);
79b97bf2
JQ
108 return 0;
109}