xref: /qemu/hw/display/vga-isa.c (revision aa2beaa1f57ca329cfceece08cc19d52368e6a8f)
176323919SJuan Quintela /*
276323919SJuan Quintela  * QEMU ISA VGA Emulator.
376323919SJuan Quintela  *
4cc228248SGerd Hoffmann  * see docs/specs/standard-vga.txt for virtual hardware specs.
5cc228248SGerd Hoffmann  *
676323919SJuan Quintela  * Copyright (c) 2003 Fabrice Bellard
776323919SJuan Quintela  *
876323919SJuan Quintela  * Permission is hereby granted, free of charge, to any person obtaining a copy
976323919SJuan Quintela  * of this software and associated documentation files (the "Software"), to deal
1076323919SJuan Quintela  * in the Software without restriction, including without limitation the rights
1176323919SJuan Quintela  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1276323919SJuan Quintela  * copies of the Software, and to permit persons to whom the Software is
1376323919SJuan Quintela  * furnished to do so, subject to the following conditions:
1476323919SJuan Quintela  *
1576323919SJuan Quintela  * The above copyright notice and this permission notice shall be included in
1676323919SJuan Quintela  * all copies or substantial portions of the Software.
1776323919SJuan Quintela  *
1876323919SJuan Quintela  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1976323919SJuan Quintela  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
2076323919SJuan Quintela  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
2176323919SJuan Quintela  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2276323919SJuan Quintela  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2376323919SJuan Quintela  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2476323919SJuan Quintela  * THE SOFTWARE.
2576323919SJuan Quintela  */
2683c9f4caSPaolo Bonzini #include "hw/hw.h"
2728ecbaeeSPaolo Bonzini #include "ui/console.h"
280d09e41aSPaolo Bonzini #include "hw/i386/pc.h"
2947b43a1fSPaolo Bonzini #include "vga_int.h"
3028ecbaeeSPaolo Bonzini #include "ui/pixel_ops.h"
311de7afc9SPaolo Bonzini #include "qemu/timer.h"
3283c9f4caSPaolo Bonzini #include "hw/loader.h"
3376323919SJuan Quintela 
347435b791SBlue Swirl typedef struct ISAVGAState {
357435b791SBlue Swirl     ISADevice dev;
367435b791SBlue Swirl     struct VGACommonState state;
377435b791SBlue Swirl } ISAVGAState;
3876323919SJuan Quintela 
397435b791SBlue Swirl static void vga_reset_isa(DeviceState *dev)
407435b791SBlue Swirl {
417435b791SBlue Swirl     ISAVGAState *d = container_of(dev, ISAVGAState, dev.qdev);
427435b791SBlue Swirl     VGACommonState *s = &d->state;
437435b791SBlue Swirl 
447435b791SBlue Swirl     vga_common_reset(s);
457435b791SBlue Swirl }
467435b791SBlue Swirl 
477435b791SBlue Swirl static int vga_initfn(ISADevice *dev)
487435b791SBlue Swirl {
497435b791SBlue Swirl     ISAVGAState *d = DO_UPCAST(ISAVGAState, dev, dev);
507435b791SBlue Swirl     VGACommonState *s = &d->state;
51b1950430SAvi Kivity     MemoryRegion *vga_io_memory;
520a039dc7SRichard Henderson     const MemoryRegionPortio *vga_ports, *vbe_ports;
5376323919SJuan Quintela 
544a1e244eSGerd Hoffmann     vga_common_init(s);
5553d6e682SJan Kiszka     s->legacy_address_space = isa_address_space(dev);
560a039dc7SRichard Henderson     vga_io_memory = vga_init_io(s, &vga_ports, &vbe_ports);
570a039dc7SRichard Henderson     isa_register_portio_list(dev, 0x3b0, vga_ports, s, "vga");
580a039dc7SRichard Henderson     if (vbe_ports) {
590a039dc7SRichard Henderson         isa_register_portio_list(dev, 0x1ce, vbe_ports, s, "vbe");
600a039dc7SRichard Henderson     }
61be20f9e9SAvi Kivity     memory_region_add_subregion_overlap(isa_address_space(dev),
62b1950430SAvi Kivity                                         isa_mem_base + 0x000a0000,
63b1950430SAvi Kivity                                         vga_io_memory, 1);
64b1950430SAvi Kivity     memory_region_set_coalescing(vga_io_memory);
65*aa2beaa1SGerd Hoffmann     s->con = graphic_console_init(DEVICE(dev), s->hw_ops, s);
6676323919SJuan Quintela 
67be20f9e9SAvi Kivity     vga_init_vbe(s, isa_address_space(dev));
685245d57aSGerd Hoffmann     /* ROM BIOS */
695245d57aSGerd Hoffmann     rom_add_vga(VGABIOS_FILENAME);
7076323919SJuan Quintela     return 0;
7176323919SJuan Quintela }
727435b791SBlue Swirl 
734a1e244eSGerd Hoffmann static Property vga_isa_properties[] = {
744a1e244eSGerd Hoffmann     DEFINE_PROP_UINT32("vgamem_mb", ISAVGAState, state.vram_size_mb, 8),
754a1e244eSGerd Hoffmann     DEFINE_PROP_END_OF_LIST(),
764a1e244eSGerd Hoffmann };
774a1e244eSGerd Hoffmann 
788f04ee08SAnthony Liguori static void vga_class_initfn(ObjectClass *klass, void *data)
798f04ee08SAnthony Liguori {
8039bffca2SAnthony Liguori     DeviceClass *dc = DEVICE_CLASS(klass);
818f04ee08SAnthony Liguori     ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
828f04ee08SAnthony Liguori     ic->init = vga_initfn;
8339bffca2SAnthony Liguori     dc->reset = vga_reset_isa;
8439bffca2SAnthony Liguori     dc->vmsd = &vmstate_vga_common;
854a1e244eSGerd Hoffmann     dc->props = vga_isa_properties;
868f04ee08SAnthony Liguori }
878f04ee08SAnthony Liguori 
888c43a6f0SAndreas Färber static const TypeInfo vga_info = {
898f04ee08SAnthony Liguori     .name          = "isa-vga",
9039bffca2SAnthony Liguori     .parent        = TYPE_ISA_DEVICE,
9139bffca2SAnthony Liguori     .instance_size = sizeof(ISAVGAState),
928f04ee08SAnthony Liguori     .class_init    = vga_class_initfn,
937435b791SBlue Swirl };
947435b791SBlue Swirl 
9583f7d43aSAndreas Färber static void vga_register_types(void)
967435b791SBlue Swirl {
9739bffca2SAnthony Liguori     type_register_static(&vga_info);
987435b791SBlue Swirl }
9983f7d43aSAndreas Färber 
10083f7d43aSAndreas Färber type_init(vga_register_types)
101