| 1 | /* |
| 2 | * QEMU ISA VGA Emulator. |
| 3 | * |
| 4 | * see docs/specs/standard-vga.rst for virtual hardware specs. |
| 5 | * |
| 6 | * Copyright (c) 2003 Fabrice Bellard |
| 7 | * |
| 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 9 | * of this software and associated documentation files (the "Software"), to deal |
| 10 | * in the Software without restriction, including without limitation the rights |
| 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 12 | * copies of the Software, and to permit persons to whom the Software is |
| 13 | * furnished to do so, subject to the following conditions: |
| 14 | * |
| 15 | * The above copyright notice and this permission notice shall be included in |
| 16 | * all copies or substantial portions of the Software. |
| 17 | * |
| 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 21 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 24 | * THE SOFTWARE. |
| 25 | */ |
| 26 | |
| 27 | #include "qemu/osdep.h" |
| 28 | #include "hw/isa/isa.h" |
| 29 | #include "vga_int.h" |
| 30 | #include "ui/pixel_ops.h" |
| 31 | #include "qemu/module.h" |
| 32 | #include "qemu/timer.h" |
| 33 | #include "hw/core/loader.h" |
| 34 | #include "hw/core/qdev-properties.h" |
| 35 | #include "migration/vmstate.h" |
| 36 | #include "ui/console.h" |
| 37 | #include "qom/object.h" |
| 38 | |
| 39 | #define TYPE_ISA_VGA "isa-vga" |
| 40 | OBJECT_DECLARE_SIMPLE_TYPE(ISAVGAState, ISA_VGA) |
| 41 | |
| 42 | struct ISAVGAState { |
| 43 | ISADevice parent_obj; |
| 44 | |
| 45 | struct VGACommonState state; |
| 46 | PortioList portio_vga; |
| 47 | PortioList portio_vbe; |
| 48 | }; |
| 49 | |
| 50 | static void vga_isa_reset(DeviceState *dev) |
| 51 | { |
| 52 | ISAVGAState *d = ISA_VGA(dev); |
| 53 | VGACommonState *s = &d->state; |
| 54 | |
| 55 | vga_common_reset(s); |
| 56 | } |
| 57 | |
| 58 | static void vga_isa_realizefn(DeviceState *dev, Error **errp) |
| 59 | { |
| 60 | ISADevice *isadev = ISA_DEVICE(dev); |
| 61 | ISAVGAState *d = ISA_VGA(dev); |
| 62 | VGACommonState *s = &d->state; |
| 63 | MemoryRegion *vga_io_memory; |
| 64 | const MemoryRegionPortio *vga_ports, *vbe_ports; |
| 65 | |
| 66 | if (!vga_common_init(s, OBJECT(dev), errp)) { |
| 67 | return; |
| 68 | } |
| 69 | |
| 70 | s->legacy_address_space = isa_address_space(isadev); |
| 71 | vga_io_memory = vga_init_io(s, OBJECT(dev), &vga_ports, &vbe_ports); |
| 72 | isa_register_portio_list(isadev, &d->portio_vga, |
| 73 | 0x3b0, vga_ports, s, "vga"); |
| 74 | if (vbe_ports) { |
| 75 | isa_register_portio_list(isadev, &d->portio_vbe, |
| 76 | 0x1ce, vbe_ports, s, "vbe"); |
| 77 | } |
| 78 | memory_region_add_subregion_overlap(isa_address_space(isadev), |
| 79 | 0x000a0000, |
| 80 | vga_io_memory, 1); |
| 81 | memory_region_set_coalescing(vga_io_memory); |
| 82 | s->con = qemu_graphic_console_create(dev, 0, s->hw_ops, s); |
| 83 | |
| 84 | memory_region_add_subregion(isa_address_space(isadev), |
| 85 | VBE_DISPI_LFB_PHYSICAL_ADDRESS, |
| 86 | &s->vram); |
| 87 | /* ROM BIOS */ |
| 88 | rom_add_vga(VGABIOS_FILENAME); |
| 89 | } |
| 90 | |
| 91 | static const VMStateDescription vmstate_vga_isa = { |
| 92 | .name = "vga-isa", |
| 93 | .version_id = 1, |
| 94 | .fields = (const VMStateField[]) { |
| 95 | VMSTATE_STRUCT(state, ISAVGAState, 0, vmstate_vga_common, VGACommonState), |
| 96 | VMSTATE_END_OF_LIST() |
| 97 | } |
| 98 | }; |
| 99 | |
| 100 | static const Property vga_isa_properties[] = { |
| 101 | DEFINE_PROP_UINT32("vgamem_mb", ISAVGAState, state.vram_size_mb, 8), |
| 102 | }; |
| 103 | |
| 104 | static void vga_isa_class_initfn(ObjectClass *klass, const void *data) |
| 105 | { |
| 106 | DeviceClass *dc = DEVICE_CLASS(klass); |
| 107 | |
| 108 | dc->realize = vga_isa_realizefn; |
| 109 | device_class_set_legacy_reset(dc, vga_isa_reset); |
| 110 | dc->vmsd = &vmstate_vga_isa; |
| 111 | device_class_set_props(dc, vga_isa_properties); |
| 112 | set_bit(DEVICE_CATEGORY_DISPLAY, dc->categories); |
| 113 | } |
| 114 | |
| 115 | static const TypeInfo vga_isa_info = { |
| 116 | .name = TYPE_ISA_VGA, |
| 117 | .parent = TYPE_ISA_DEVICE, |
| 118 | .instance_size = sizeof(ISAVGAState), |
| 119 | .class_init = vga_isa_class_initfn, |
| 120 | }; |
| 121 | |
| 122 | static void vga_isa_register_types(void) |
| 123 | { |
| 124 | type_register_static(&vga_isa_info); |
| 125 | } |
| 126 | |
| 127 | type_init(vga_isa_register_types) |