vga-isa.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. #include "qemu/osdep.h"
  27. #include "hw/isa/isa.h"
  28. #include "vga_int.h"
  29. #include "ui/pixel_ops.h"
  30. #include "qemu/module.h"
  31. #include "qemu/timer.h"
  32. #include "hw/loader.h"
  33. #include "hw/qdev-properties.h"
  34. #include "ui/console.h"
  35. #include "qom/object.h"
  36. #define TYPE_ISA_VGA "isa-vga"
  37. OBJECT_DECLARE_SIMPLE_TYPE(ISAVGAState, ISA_VGA)
  38. struct ISAVGAState {
  39. ISADevice parent_obj;
  40. struct VGACommonState state;
  41. PortioList portio_vga;
  42. PortioList portio_vbe;
  43. };
  44. static void vga_isa_reset(DeviceState *dev)
  45. {
  46. ISAVGAState *d = ISA_VGA(dev);
  47. VGACommonState *s = &d->state;
  48. vga_common_reset(s);
  49. }
  50. static void vga_isa_realizefn(DeviceState *dev, Error **errp)
  51. {
  52. ISADevice *isadev = ISA_DEVICE(dev);
  53. ISAVGAState *d = ISA_VGA(dev);
  54. VGACommonState *s = &d->state;
  55. MemoryRegion *vga_io_memory;
  56. const MemoryRegionPortio *vga_ports, *vbe_ports;
  57. s->global_vmstate = true;
  58. if (!vga_common_init(s, OBJECT(dev), errp)) {
  59. return;
  60. }
  61. s->legacy_address_space = isa_address_space(isadev);
  62. vga_io_memory = vga_init_io(s, OBJECT(dev), &vga_ports, &vbe_ports);
  63. isa_register_portio_list(isadev, &d->portio_vga,
  64. 0x3b0, vga_ports, s, "vga");
  65. if (vbe_ports) {
  66. isa_register_portio_list(isadev, &d->portio_vbe,
  67. 0x1ce, vbe_ports, s, "vbe");
  68. }
  69. memory_region_add_subregion_overlap(isa_address_space(isadev),
  70. 0x000a0000,
  71. vga_io_memory, 1);
  72. memory_region_set_coalescing(vga_io_memory);
  73. s->con = graphic_console_init(dev, 0, s->hw_ops, s);
  74. memory_region_add_subregion(isa_address_space(isadev),
  75. VBE_DISPI_LFB_PHYSICAL_ADDRESS,
  76. &s->vram);
  77. /* ROM BIOS */
  78. rom_add_vga(VGABIOS_FILENAME);
  79. }
  80. static const Property vga_isa_properties[] = {
  81. DEFINE_PROP_UINT32("vgamem_mb", ISAVGAState, state.vram_size_mb, 8),
  82. };
  83. static void vga_isa_class_initfn(ObjectClass *klass, void *data)
  84. {
  85. DeviceClass *dc = DEVICE_CLASS(klass);
  86. dc->realize = vga_isa_realizefn;
  87. device_class_set_legacy_reset(dc, vga_isa_reset);
  88. dc->vmsd = &vmstate_vga_common;
  89. device_class_set_props(dc, vga_isa_properties);
  90. set_bit(DEVICE_CATEGORY_DISPLAY, dc->categories);
  91. }
  92. static const TypeInfo vga_isa_info = {
  93. .name = TYPE_ISA_VGA,
  94. .parent = TYPE_ISA_DEVICE,
  95. .instance_size = sizeof(ISAVGAState),
  96. .class_init = vga_isa_class_initfn,
  97. };
  98. static void vga_isa_register_types(void)
  99. {
  100. type_register_static(&vga_isa_info);
  101. }
  102. type_init(vga_isa_register_types)