vga-isa-mm.c 4.3 KB
Newer Older
J
Juan Quintela 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*
 * QEMU ISA MM VGA Emulator.
 *
 * Copyright (c) 2003 Fabrice Bellard
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
24
#include "hw/hw.h"
25
#include "ui/console.h"
P
Paolo Bonzini 已提交
26
#include "hw/i386/pc.h"
27
#include "hw/vga_int.h"
28
#include "ui/pixel_ops.h"
29
#include "qemu/timer.h"
J
Juan Quintela 已提交
30

G
Gerd Hoffmann 已提交
31 32
#define VGA_RAM_SIZE (8192 * 1024)

J
Juan Quintela 已提交
33 34 35 36 37 38
typedef struct ISAVGAMMState {
    VGACommonState vga;
    int it_shift;
} ISAVGAMMState;

/* Memory mapped interface */
A
Avi Kivity 已提交
39
static uint32_t vga_mm_readb (void *opaque, hwaddr addr)
J
Juan Quintela 已提交
40 41 42 43 44 45 46
{
    ISAVGAMMState *s = opaque;

    return vga_ioport_read(&s->vga, addr >> s->it_shift) & 0xff;
}

static void vga_mm_writeb (void *opaque,
A
Avi Kivity 已提交
47
                           hwaddr addr, uint32_t value)
J
Juan Quintela 已提交
48 49 50 51 52 53
{
    ISAVGAMMState *s = opaque;

    vga_ioport_write(&s->vga, addr >> s->it_shift, value & 0xff);
}

A
Avi Kivity 已提交
54
static uint32_t vga_mm_readw (void *opaque, hwaddr addr)
J
Juan Quintela 已提交
55 56 57 58 59 60 61
{
    ISAVGAMMState *s = opaque;

    return vga_ioport_read(&s->vga, addr >> s->it_shift) & 0xffff;
}

static void vga_mm_writew (void *opaque,
A
Avi Kivity 已提交
62
                           hwaddr addr, uint32_t value)
J
Juan Quintela 已提交
63 64 65 66 67 68
{
    ISAVGAMMState *s = opaque;

    vga_ioport_write(&s->vga, addr >> s->it_shift, value & 0xffff);
}

A
Avi Kivity 已提交
69
static uint32_t vga_mm_readl (void *opaque, hwaddr addr)
J
Juan Quintela 已提交
70 71 72 73 74 75 76
{
    ISAVGAMMState *s = opaque;

    return vga_ioport_read(&s->vga, addr >> s->it_shift);
}

static void vga_mm_writel (void *opaque,
A
Avi Kivity 已提交
77
                           hwaddr addr, uint32_t value)
J
Juan Quintela 已提交
78 79 80 81 82 83
{
    ISAVGAMMState *s = opaque;

    vga_ioport_write(&s->vga, addr >> s->it_shift, value);
}

84 85 86 87 88 89 90 91 92 93 94 95 96 97
static const MemoryRegionOps vga_mm_ctrl_ops = {
    .old_mmio = {
        .read = {
            vga_mm_readb,
            vga_mm_readw,
            vga_mm_readl,
        },
        .write = {
            vga_mm_writeb,
            vga_mm_writew,
            vga_mm_writel,
        },
    },
    .endianness = DEVICE_NATIVE_ENDIAN,
J
Juan Quintela 已提交
98 99
};

A
Avi Kivity 已提交
100 101
static void vga_mm_init(ISAVGAMMState *s, hwaddr vram_base,
                        hwaddr ctrl_base, int it_shift,
102
                        MemoryRegion *address_space)
J
Juan Quintela 已提交
103
{
104
    MemoryRegion *s_ioport_ctrl, *vga_io_memory;
J
Juan Quintela 已提交
105 106

    s->it_shift = it_shift;
107
    s_ioport_ctrl = g_malloc(sizeof(*s_ioport_ctrl));
108 109
    memory_region_init_io(s_ioport_ctrl, &vga_mm_ctrl_ops, s,
                          "vga-mm-ctrl", 0x100000);
110
    memory_region_set_flush_coalesced(s_ioport_ctrl);
111

112
    vga_io_memory = g_malloc(sizeof(*vga_io_memory));
113 114 115
    /* XXX: endianness? */
    memory_region_init_io(vga_io_memory, &vga_mem_ops, &s->vga,
                          "vga-mem", 0x20000);
J
Juan Quintela 已提交
116

A
Alex Williamson 已提交
117
    vmstate_register(NULL, 0, &vmstate_vga_common, s);
J
Juan Quintela 已提交
118

119
    memory_region_add_subregion(address_space, ctrl_base, s_ioport_ctrl);
J
Juan Quintela 已提交
120
    s->vga.bank_offset = 0;
121
    memory_region_add_subregion(address_space,
122 123
                                vram_base + 0x000a0000, vga_io_memory);
    memory_region_set_coalescing(vga_io_memory);
J
Juan Quintela 已提交
124 125
}

A
Avi Kivity 已提交
126 127
int isa_vga_mm_init(hwaddr vram_base,
                    hwaddr ctrl_base, int it_shift,
128
                    MemoryRegion *address_space)
J
Juan Quintela 已提交
129 130 131
{
    ISAVGAMMState *s;

132
    s = g_malloc0(sizeof(*s));
J
Juan Quintela 已提交
133

G
Gerd Hoffmann 已提交
134 135
    s->vga.vram_size_mb = VGA_RAM_SIZE >> 20;
    vga_common_init(&s->vga);
136
    vga_mm_init(s, vram_base, ctrl_base, it_shift, address_space);
J
Juan Quintela 已提交
137

138 139 140
    s->vga.con = graphic_console_init(s->vga.update, s->vga.invalidate,
                                      s->vga.screen_dump, s->vga.text_update,
                                      s);
J
Juan Quintela 已提交
141

142
    vga_init_vbe(&s->vga, address_space);
J
Juan Quintela 已提交
143 144
    return 0;
}