2009-08-31 18:07:18 +04:00
|
|
|
/*
|
2021-12-07 01:45:25 +03:00
|
|
|
* QEMU MMIO VGA Emulator.
|
2009-08-31 18:07:18 +04:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2019-08-12 08:23:45 +03:00
|
|
|
|
2016-01-26 21:17:13 +03:00
|
|
|
#include "qemu/osdep.h"
|
2021-12-07 01:45:27 +03:00
|
|
|
#include "qapi/error.h"
|
|
|
|
#include "hw/sysbus.h"
|
|
|
|
#include "hw/display/vga.h"
|
|
|
|
#include "hw/qdev-properties.h"
|
2022-11-10 01:21:23 +03:00
|
|
|
#include "ui/console.h"
|
2013-03-18 20:36:02 +04:00
|
|
|
#include "vga_int.h"
|
2009-08-31 18:07:18 +04:00
|
|
|
|
2021-12-07 01:45:27 +03:00
|
|
|
/*
|
|
|
|
* QEMU interface:
|
|
|
|
* + sysbus MMIO region 0: VGA I/O registers
|
|
|
|
* + sysbus MMIO region 1: VGA MMIO registers
|
|
|
|
* + sysbus MMIO region 2: VGA memory
|
|
|
|
*/
|
|
|
|
|
|
|
|
OBJECT_DECLARE_SIMPLE_TYPE(VGAMmioState, VGA_MMIO)
|
2012-05-24 11:59:44 +04:00
|
|
|
|
2021-12-07 01:45:27 +03:00
|
|
|
struct VGAMmioState {
|
|
|
|
/*< private >*/
|
|
|
|
SysBusDevice parent_obj;
|
|
|
|
|
|
|
|
/*< public >*/
|
2009-08-31 18:07:18 +04:00
|
|
|
VGACommonState vga;
|
2021-12-07 01:45:27 +03:00
|
|
|
MemoryRegion iomem;
|
|
|
|
MemoryRegion lowmem;
|
|
|
|
|
|
|
|
uint8_t it_shift;
|
|
|
|
};
|
2009-08-31 18:07:18 +04:00
|
|
|
|
2018-08-02 18:51:46 +03:00
|
|
|
static uint64_t vga_mm_read(void *opaque, hwaddr addr, unsigned size)
|
2009-08-31 18:07:18 +04:00
|
|
|
{
|
2021-12-07 01:45:25 +03:00
|
|
|
VGAMmioState *s = opaque;
|
2009-08-31 18:07:18 +04:00
|
|
|
|
2018-08-02 18:51:46 +03:00
|
|
|
return vga_ioport_read(&s->vga, addr >> s->it_shift) &
|
|
|
|
MAKE_64BIT_MASK(0, size * 8);
|
2009-08-31 18:07:18 +04:00
|
|
|
}
|
|
|
|
|
2018-08-02 18:51:46 +03:00
|
|
|
static void vga_mm_write(void *opaque, hwaddr addr, uint64_t value,
|
|
|
|
unsigned size)
|
2009-08-31 18:07:18 +04:00
|
|
|
{
|
2021-12-07 01:45:25 +03:00
|
|
|
VGAMmioState *s = opaque;
|
2009-08-31 18:07:18 +04:00
|
|
|
|
2018-08-02 18:51:46 +03:00
|
|
|
vga_ioport_write(&s->vga, addr >> s->it_shift,
|
|
|
|
value & MAKE_64BIT_MASK(0, size * 8));
|
2009-08-31 18:07:18 +04:00
|
|
|
}
|
|
|
|
|
2011-08-08 17:08:57 +04:00
|
|
|
static const MemoryRegionOps vga_mm_ctrl_ops = {
|
2018-08-02 18:51:46 +03:00
|
|
|
.read = vga_mm_read,
|
|
|
|
.write = vga_mm_write,
|
|
|
|
.valid.min_access_size = 1,
|
|
|
|
.valid.max_access_size = 4,
|
|
|
|
.impl.min_access_size = 1,
|
|
|
|
.impl.max_access_size = 4,
|
2011-08-08 17:08:57 +04:00
|
|
|
.endianness = DEVICE_NATIVE_ENDIAN,
|
2009-08-31 18:07:18 +04:00
|
|
|
};
|
|
|
|
|
2021-12-07 01:45:27 +03:00
|
|
|
static void vga_mmio_reset(DeviceState *dev)
|
|
|
|
{
|
|
|
|
VGAMmioState *s = VGA_MMIO(dev);
|
|
|
|
|
|
|
|
vga_common_reset(&s->vga);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void vga_mmio_realizefn(DeviceState *dev, Error **errp)
|
|
|
|
{
|
|
|
|
VGAMmioState *s = VGA_MMIO(dev);
|
|
|
|
SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
|
|
|
|
|
|
|
|
memory_region_init_io(&s->iomem, OBJECT(dev), &vga_mm_ctrl_ops, s,
|
|
|
|
"vga-mmio", 0x100000);
|
|
|
|
memory_region_set_flush_coalesced(&s->iomem);
|
|
|
|
sysbus_init_mmio(sbd, &s->iomem);
|
2009-08-31 18:07:18 +04:00
|
|
|
|
2021-12-07 01:45:27 +03:00
|
|
|
/* XXX: endianness? */
|
|
|
|
memory_region_init_io(&s->lowmem, OBJECT(dev), &vga_mem_ops, &s->vga,
|
|
|
|
"vga-lowmem", 0x20000);
|
|
|
|
memory_region_set_coalescing(&s->lowmem);
|
|
|
|
sysbus_init_mmio(sbd, &s->lowmem);
|
2009-08-31 18:07:18 +04:00
|
|
|
|
|
|
|
s->vga.bank_offset = 0;
|
2021-12-07 01:45:27 +03:00
|
|
|
s->vga.global_vmstate = true;
|
2022-03-17 11:30:25 +03:00
|
|
|
if (!vga_common_init(&s->vga, OBJECT(dev), errp)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-12-07 01:45:27 +03:00
|
|
|
sysbus_init_mmio(sbd, &s->vga.vram);
|
|
|
|
s->vga.con = graphic_console_init(dev, 0, s->vga.hw_ops, &s->vga);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Property vga_mmio_properties[] = {
|
|
|
|
DEFINE_PROP_UINT8("it_shift", VGAMmioState, it_shift, 0),
|
|
|
|
DEFINE_PROP_UINT32("vgamem_mb", VGAMmioState, vga.vram_size_mb, 8),
|
|
|
|
DEFINE_PROP_END_OF_LIST(),
|
|
|
|
};
|
2009-08-31 18:07:18 +04:00
|
|
|
|
2021-12-07 01:45:27 +03:00
|
|
|
static void vga_mmio_class_initfn(ObjectClass *klass, void *data)
|
|
|
|
{
|
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
2009-08-31 18:07:18 +04:00
|
|
|
|
2021-12-07 01:45:27 +03:00
|
|
|
dc->realize = vga_mmio_realizefn;
|
|
|
|
dc->reset = vga_mmio_reset;
|
|
|
|
dc->vmsd = &vmstate_vga_common;
|
|
|
|
device_class_set_props(dc, vga_mmio_properties);
|
|
|
|
set_bit(DEVICE_CATEGORY_DISPLAY, dc->categories);
|
|
|
|
}
|
2019-12-09 16:30:08 +03:00
|
|
|
|
2021-12-07 01:45:27 +03:00
|
|
|
static const TypeInfo vga_mmio_info = {
|
|
|
|
.name = TYPE_VGA_MMIO,
|
|
|
|
.parent = TYPE_SYS_BUS_DEVICE,
|
|
|
|
.instance_size = sizeof(VGAMmioState),
|
|
|
|
.class_init = vga_mmio_class_initfn,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void vga_mmio_register_types(void)
|
|
|
|
{
|
|
|
|
type_register_static(&vga_mmio_info);
|
2009-08-31 18:07:18 +04:00
|
|
|
}
|
2021-12-07 01:45:27 +03:00
|
|
|
|
|
|
|
type_init(vga_mmio_register_types)
|