2 * QEMU MMIO VGA Emulator.
4 * Copyright (c) 2003 Fabrice Bellard
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:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
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
25 #include "qemu/osdep.h"
26 #include "qapi/error.h"
27 #include "hw/sysbus.h"
28 #include "hw/display/vga.h"
29 #include "hw/qdev-properties.h"
34 * + sysbus MMIO region 0: VGA I/O registers
35 * + sysbus MMIO region 1: VGA MMIO registers
36 * + sysbus MMIO region 2: VGA memory
39 OBJECT_DECLARE_SIMPLE_TYPE(VGAMmioState
, VGA_MMIO
)
43 SysBusDevice parent_obj
;
53 static uint64_t vga_mm_read(void *opaque
, hwaddr addr
, unsigned size
)
55 VGAMmioState
*s
= opaque
;
57 return vga_ioport_read(&s
->vga
, addr
>> s
->it_shift
) &
58 MAKE_64BIT_MASK(0, size
* 8);
61 static void vga_mm_write(void *opaque
, hwaddr addr
, uint64_t value
,
64 VGAMmioState
*s
= opaque
;
66 vga_ioport_write(&s
->vga
, addr
>> s
->it_shift
,
67 value
& MAKE_64BIT_MASK(0, size
* 8));
70 static const MemoryRegionOps vga_mm_ctrl_ops
= {
72 .write
= vga_mm_write
,
73 .valid
.min_access_size
= 1,
74 .valid
.max_access_size
= 4,
75 .impl
.min_access_size
= 1,
76 .impl
.max_access_size
= 4,
77 .endianness
= DEVICE_NATIVE_ENDIAN
,
80 static void vga_mmio_reset(DeviceState
*dev
)
82 VGAMmioState
*s
= VGA_MMIO(dev
);
84 vga_common_reset(&s
->vga
);
87 static void vga_mmio_realizefn(DeviceState
*dev
, Error
**errp
)
89 VGAMmioState
*s
= VGA_MMIO(dev
);
90 SysBusDevice
*sbd
= SYS_BUS_DEVICE(dev
);
92 memory_region_init_io(&s
->iomem
, OBJECT(dev
), &vga_mm_ctrl_ops
, s
,
93 "vga-mmio", 0x100000);
94 memory_region_set_flush_coalesced(&s
->iomem
);
95 sysbus_init_mmio(sbd
, &s
->iomem
);
97 /* XXX: endianness? */
98 memory_region_init_io(&s
->lowmem
, OBJECT(dev
), &vga_mem_ops
, &s
->vga
,
99 "vga-lowmem", 0x20000);
100 memory_region_set_coalescing(&s
->lowmem
);
101 sysbus_init_mmio(sbd
, &s
->lowmem
);
103 s
->vga
.bank_offset
= 0;
104 s
->vga
.global_vmstate
= true;
105 if (!vga_common_init(&s
->vga
, OBJECT(dev
), errp
)) {
109 sysbus_init_mmio(sbd
, &s
->vga
.vram
);
110 s
->vga
.con
= graphic_console_init(dev
, 0, s
->vga
.hw_ops
, &s
->vga
);
113 static Property vga_mmio_properties
[] = {
114 DEFINE_PROP_UINT8("it_shift", VGAMmioState
, it_shift
, 0),
115 DEFINE_PROP_UINT32("vgamem_mb", VGAMmioState
, vga
.vram_size_mb
, 8),
116 DEFINE_PROP_END_OF_LIST(),
119 static void vga_mmio_class_initfn(ObjectClass
*klass
, void *data
)
121 DeviceClass
*dc
= DEVICE_CLASS(klass
);
123 dc
->realize
= vga_mmio_realizefn
;
124 dc
->reset
= vga_mmio_reset
;
125 dc
->vmsd
= &vmstate_vga_common
;
126 device_class_set_props(dc
, vga_mmio_properties
);
127 set_bit(DEVICE_CATEGORY_DISPLAY
, dc
->categories
);
130 static const TypeInfo vga_mmio_info
= {
131 .name
= TYPE_VGA_MMIO
,
132 .parent
= TYPE_SYS_BUS_DEVICE
,
133 .instance_size
= sizeof(VGAMmioState
),
134 .class_init
= vga_mmio_class_initfn
,
137 static void vga_mmio_register_types(void)
139 type_register_static(&vga_mmio_info
);
142 type_init(vga_mmio_register_types
)