vga-isa.c 3.5 KB
Newer Older
1 2 3
/*
 * QEMU ISA VGA Emulator.
 *
G
Gerd Hoffmann 已提交
4 5
 * see docs/specs/standard-vga.txt for virtual hardware specs.
 *
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
 * 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.
 */
P
Peter Maydell 已提交
26
#include "qemu/osdep.h"
27
#include "hw/hw.h"
28
#include "ui/console.h"
P
Paolo Bonzini 已提交
29
#include "hw/i386/pc.h"
30
#include "vga_int.h"
31
#include "ui/pixel_ops.h"
32
#include "qemu/timer.h"
33
#include "hw/loader.h"
34

A
Andreas Färber 已提交
35 36 37
#define TYPE_ISA_VGA "isa-vga"
#define ISA_VGA(obj) OBJECT_CHECK(ISAVGAState, (obj), TYPE_ISA_VGA)

B
Blue Swirl 已提交
38
typedef struct ISAVGAState {
A
Andreas Färber 已提交
39 40
    ISADevice parent_obj;

B
Blue Swirl 已提交
41 42 43
    struct VGACommonState state;
} ISAVGAState;

A
Andreas Färber 已提交
44
static void vga_isa_reset(DeviceState *dev)
45
{
A
Andreas Färber 已提交
46
    ISAVGAState *d = ISA_VGA(dev);
B
Blue Swirl 已提交
47
    VGACommonState *s = &d->state;
48

B
Blue Swirl 已提交
49 50
    vga_common_reset(s);
}
51

52
static void vga_isa_realizefn(DeviceState *dev, Error **errp)
B
Blue Swirl 已提交
53
{
54
    ISADevice *isadev = ISA_DEVICE(dev);
A
Andreas Färber 已提交
55
    ISAVGAState *d = ISA_VGA(dev);
B
Blue Swirl 已提交
56
    VGACommonState *s = &d->state;
57
    MemoryRegion *vga_io_memory;
58
    const MemoryRegionPortio *vga_ports, *vbe_ports;
59

G
Gerd Hoffmann 已提交
60
    vga_common_init(s, OBJECT(dev), true);
61
    s->legacy_address_space = isa_address_space(isadev);
P
Paolo Bonzini 已提交
62
    vga_io_memory = vga_init_io(s, OBJECT(dev), &vga_ports, &vbe_ports);
63
    isa_register_portio_list(isadev, 0x3b0, vga_ports, s, "vga");
64
    if (vbe_ports) {
65
        isa_register_portio_list(isadev, 0x1ce, vbe_ports, s, "vbe");
66
    }
67
    memory_region_add_subregion_overlap(isa_address_space(isadev),
68
                                        0x000a0000,
69 70
                                        vga_io_memory, 1);
    memory_region_set_coalescing(vga_io_memory);
71
    s->con = graphic_console_init(DEVICE(dev), 0, s->hw_ops, s);
72

P
Paolo Bonzini 已提交
73
    vga_init_vbe(s, OBJECT(dev), isa_address_space(isadev));
74 75
    /* ROM BIOS */
    rom_add_vga(VGABIOS_FILENAME);
76
}
B
Blue Swirl 已提交
77

G
Gerd Hoffmann 已提交
78 79 80 81 82
static Property vga_isa_properties[] = {
    DEFINE_PROP_UINT32("vgamem_mb", ISAVGAState, state.vram_size_mb, 8),
    DEFINE_PROP_END_OF_LIST(),
};

A
Andreas Färber 已提交
83
static void vga_isa_class_initfn(ObjectClass *klass, void *data)
84
{
85
    DeviceClass *dc = DEVICE_CLASS(klass);
A
Andreas Färber 已提交
86

87
    dc->realize = vga_isa_realizefn;
A
Andreas Färber 已提交
88
    dc->reset = vga_isa_reset;
89
    dc->vmsd = &vmstate_vga_common;
G
Gerd Hoffmann 已提交
90
    dc->props = vga_isa_properties;
91
    set_bit(DEVICE_CATEGORY_DISPLAY, dc->categories);
92 93
}

A
Andreas Färber 已提交
94 95
static const TypeInfo vga_isa_info = {
    .name          = TYPE_ISA_VGA,
96 97
    .parent        = TYPE_ISA_DEVICE,
    .instance_size = sizeof(ISAVGAState),
A
Andreas Färber 已提交
98
    .class_init    = vga_isa_class_initfn,
B
Blue Swirl 已提交
99 100
};

A
Andreas Färber 已提交
101
static void vga_isa_register_types(void)
B
Blue Swirl 已提交
102
{
A
Andreas Färber 已提交
103
    type_register_static(&vga_isa_info);
B
Blue Swirl 已提交
104
}
A
Andreas Färber 已提交
105

A
Andreas Färber 已提交
106
type_init(vga_isa_register_types)