Juan Quintela | 7632391 | 2009-08-31 16:07:16 +0200 | [diff] [blame] | 1 | /* |
| 2 | * QEMU ISA VGA Emulator. |
| 3 | * |
Gerd Hoffmann | cc22824 | 2012-10-15 08:02:56 +0200 | [diff] [blame] | 4 | * see docs/specs/standard-vga.txt for virtual hardware specs. |
| 5 | * |
Juan Quintela | 7632391 | 2009-08-31 16:07:16 +0200 | [diff] [blame] | 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 | #include "hw.h" |
Paolo Bonzini | 28ecbae | 2012-11-28 12:06:30 +0100 | [diff] [blame] | 27 | #include "ui/console.h" |
Juan Quintela | 7632391 | 2009-08-31 16:07:16 +0200 | [diff] [blame] | 28 | #include "pc.h" |
| 29 | #include "vga_int.h" |
Paolo Bonzini | 28ecbae | 2012-11-28 12:06:30 +0100 | [diff] [blame] | 30 | #include "ui/pixel_ops.h" |
Paolo Bonzini | 1de7afc | 2012-12-17 18:20:00 +0100 | [diff] [blame] | 31 | #include "qemu/timer.h" |
Gerd Hoffmann | 5245d57 | 2009-10-26 12:18:26 +0100 | [diff] [blame] | 32 | #include "loader.h" |
Juan Quintela | 7632391 | 2009-08-31 16:07:16 +0200 | [diff] [blame] | 33 | |
Blue Swirl | 7435b79 | 2011-02-13 14:01:05 +0000 | [diff] [blame] | 34 | typedef struct ISAVGAState { |
| 35 | ISADevice dev; |
| 36 | struct VGACommonState state; |
| 37 | } ISAVGAState; |
Juan Quintela | 7632391 | 2009-08-31 16:07:16 +0200 | [diff] [blame] | 38 | |
Blue Swirl | 7435b79 | 2011-02-13 14:01:05 +0000 | [diff] [blame] | 39 | static void vga_reset_isa(DeviceState *dev) |
| 40 | { |
| 41 | ISAVGAState *d = container_of(dev, ISAVGAState, dev.qdev); |
| 42 | VGACommonState *s = &d->state; |
| 43 | |
| 44 | vga_common_reset(s); |
| 45 | } |
| 46 | |
| 47 | static int vga_initfn(ISADevice *dev) |
| 48 | { |
| 49 | ISAVGAState *d = DO_UPCAST(ISAVGAState, dev, dev); |
| 50 | VGACommonState *s = &d->state; |
Avi Kivity | b195043 | 2011-08-08 16:08:57 +0300 | [diff] [blame] | 51 | MemoryRegion *vga_io_memory; |
Richard Henderson | 0a039dc | 2011-08-16 08:27:39 -0700 | [diff] [blame] | 52 | const MemoryRegionPortio *vga_ports, *vbe_ports; |
Juan Quintela | 7632391 | 2009-08-31 16:07:16 +0200 | [diff] [blame] | 53 | |
Gerd Hoffmann | 4a1e244 | 2012-05-24 09:59:44 +0200 | [diff] [blame] | 54 | vga_common_init(s); |
Jan Kiszka | 53d6e68 | 2011-09-21 20:49:31 +0200 | [diff] [blame] | 55 | s->legacy_address_space = isa_address_space(dev); |
Richard Henderson | 0a039dc | 2011-08-16 08:27:39 -0700 | [diff] [blame] | 56 | vga_io_memory = vga_init_io(s, &vga_ports, &vbe_ports); |
| 57 | isa_register_portio_list(dev, 0x3b0, vga_ports, s, "vga"); |
| 58 | if (vbe_ports) { |
| 59 | isa_register_portio_list(dev, 0x1ce, vbe_ports, s, "vbe"); |
| 60 | } |
Avi Kivity | be20f9e | 2011-08-15 17:17:37 +0300 | [diff] [blame] | 61 | memory_region_add_subregion_overlap(isa_address_space(dev), |
Avi Kivity | b195043 | 2011-08-08 16:08:57 +0300 | [diff] [blame] | 62 | isa_mem_base + 0x000a0000, |
| 63 | vga_io_memory, 1); |
| 64 | memory_region_set_coalescing(vga_io_memory); |
Juan Quintela | 7632391 | 2009-08-31 16:07:16 +0200 | [diff] [blame] | 65 | s->ds = graphic_console_init(s->update, s->invalidate, |
| 66 | s->screen_dump, s->text_update, s); |
| 67 | |
Avi Kivity | be20f9e | 2011-08-15 17:17:37 +0300 | [diff] [blame] | 68 | vga_init_vbe(s, isa_address_space(dev)); |
Gerd Hoffmann | 5245d57 | 2009-10-26 12:18:26 +0100 | [diff] [blame] | 69 | /* ROM BIOS */ |
| 70 | rom_add_vga(VGABIOS_FILENAME); |
Juan Quintela | 7632391 | 2009-08-31 16:07:16 +0200 | [diff] [blame] | 71 | return 0; |
| 72 | } |
Blue Swirl | 7435b79 | 2011-02-13 14:01:05 +0000 | [diff] [blame] | 73 | |
Gerd Hoffmann | 4a1e244 | 2012-05-24 09:59:44 +0200 | [diff] [blame] | 74 | static Property vga_isa_properties[] = { |
| 75 | DEFINE_PROP_UINT32("vgamem_mb", ISAVGAState, state.vram_size_mb, 8), |
| 76 | DEFINE_PROP_END_OF_LIST(), |
| 77 | }; |
| 78 | |
Anthony Liguori | 8f04ee0 | 2011-12-04 11:52:49 -0600 | [diff] [blame] | 79 | static void vga_class_initfn(ObjectClass *klass, void *data) |
| 80 | { |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 81 | DeviceClass *dc = DEVICE_CLASS(klass); |
Anthony Liguori | 8f04ee0 | 2011-12-04 11:52:49 -0600 | [diff] [blame] | 82 | ISADeviceClass *ic = ISA_DEVICE_CLASS(klass); |
| 83 | ic->init = vga_initfn; |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 84 | dc->reset = vga_reset_isa; |
| 85 | dc->vmsd = &vmstate_vga_common; |
Gerd Hoffmann | 4a1e244 | 2012-05-24 09:59:44 +0200 | [diff] [blame] | 86 | dc->props = vga_isa_properties; |
Anthony Liguori | 8f04ee0 | 2011-12-04 11:52:49 -0600 | [diff] [blame] | 87 | } |
| 88 | |
Andreas Färber | 8c43a6f | 2013-01-10 16:19:07 +0100 | [diff] [blame] | 89 | static const TypeInfo vga_info = { |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 90 | .name = "isa-vga", |
| 91 | .parent = TYPE_ISA_DEVICE, |
| 92 | .instance_size = sizeof(ISAVGAState), |
| 93 | .class_init = vga_class_initfn, |
Blue Swirl | 7435b79 | 2011-02-13 14:01:05 +0000 | [diff] [blame] | 94 | }; |
| 95 | |
Andreas Färber | 83f7d43 | 2012-02-09 15:20:55 +0100 | [diff] [blame] | 96 | static void vga_register_types(void) |
Blue Swirl | 7435b79 | 2011-02-13 14:01:05 +0000 | [diff] [blame] | 97 | { |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 98 | type_register_static(&vga_info); |
Blue Swirl | 7435b79 | 2011-02-13 14:01:05 +0000 | [diff] [blame] | 99 | } |
Andreas Färber | 83f7d43 | 2012-02-09 15:20:55 +0100 | [diff] [blame] | 100 | |
| 101 | type_init(vga_register_types) |