vga-mmio.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. * QEMU MMIO VGA Emulator.
  3. *
  4. * Copyright (c) 2003 Fabrice Bellard
  5. *
  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:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  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
  22. * THE SOFTWARE.
  23. */
  24. #include "qemu/osdep.h"
  25. #include "qapi/error.h"
  26. #include "hw/sysbus.h"
  27. #include "hw/display/vga.h"
  28. #include "hw/qdev-properties.h"
  29. #include "ui/console.h"
  30. #include "vga_int.h"
  31. /*
  32. * QEMU interface:
  33. * + sysbus MMIO region 0: VGA I/O registers
  34. * + sysbus MMIO region 1: VGA MMIO registers
  35. * + sysbus MMIO region 2: VGA memory
  36. */
  37. OBJECT_DECLARE_SIMPLE_TYPE(VGAMmioState, VGA_MMIO)
  38. struct VGAMmioState {
  39. /*< private >*/
  40. SysBusDevice parent_obj;
  41. /*< public >*/
  42. VGACommonState vga;
  43. MemoryRegion iomem;
  44. MemoryRegion lowmem;
  45. uint8_t it_shift;
  46. };
  47. static uint64_t vga_mm_read(void *opaque, hwaddr addr, unsigned size)
  48. {
  49. VGAMmioState *s = opaque;
  50. return vga_ioport_read(&s->vga, addr >> s->it_shift) &
  51. MAKE_64BIT_MASK(0, size * 8);
  52. }
  53. static void vga_mm_write(void *opaque, hwaddr addr, uint64_t value,
  54. unsigned size)
  55. {
  56. VGAMmioState *s = opaque;
  57. vga_ioport_write(&s->vga, addr >> s->it_shift,
  58. value & MAKE_64BIT_MASK(0, size * 8));
  59. }
  60. static const MemoryRegionOps vga_mm_ctrl_ops = {
  61. .read = vga_mm_read,
  62. .write = vga_mm_write,
  63. .valid.min_access_size = 1,
  64. .valid.max_access_size = 4,
  65. .impl.min_access_size = 1,
  66. .impl.max_access_size = 4,
  67. .endianness = DEVICE_NATIVE_ENDIAN,
  68. };
  69. static void vga_mmio_reset(DeviceState *dev)
  70. {
  71. VGAMmioState *s = VGA_MMIO(dev);
  72. vga_common_reset(&s->vga);
  73. }
  74. static void vga_mmio_realizefn(DeviceState *dev, Error **errp)
  75. {
  76. VGAMmioState *s = VGA_MMIO(dev);
  77. SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
  78. memory_region_init_io(&s->iomem, OBJECT(dev), &vga_mm_ctrl_ops, s,
  79. "vga-mmio", 0x100000);
  80. memory_region_set_flush_coalesced(&s->iomem);
  81. sysbus_init_mmio(sbd, &s->iomem);
  82. /* XXX: endianness? */
  83. memory_region_init_io(&s->lowmem, OBJECT(dev), &vga_mem_ops, &s->vga,
  84. "vga-lowmem", 0x20000);
  85. memory_region_set_coalescing(&s->lowmem);
  86. sysbus_init_mmio(sbd, &s->lowmem);
  87. s->vga.bank_offset = 0;
  88. s->vga.global_vmstate = true;
  89. if (!vga_common_init(&s->vga, OBJECT(dev), errp)) {
  90. return;
  91. }
  92. sysbus_init_mmio(sbd, &s->vga.vram);
  93. s->vga.con = graphic_console_init(dev, 0, s->vga.hw_ops, &s->vga);
  94. }
  95. static Property vga_mmio_properties[] = {
  96. DEFINE_PROP_UINT8("it_shift", VGAMmioState, it_shift, 0),
  97. DEFINE_PROP_UINT32("vgamem_mb", VGAMmioState, vga.vram_size_mb, 8),
  98. DEFINE_PROP_END_OF_LIST(),
  99. };
  100. static void vga_mmio_class_initfn(ObjectClass *klass, void *data)
  101. {
  102. DeviceClass *dc = DEVICE_CLASS(klass);
  103. dc->realize = vga_mmio_realizefn;
  104. dc->reset = vga_mmio_reset;
  105. dc->vmsd = &vmstate_vga_common;
  106. device_class_set_props(dc, vga_mmio_properties);
  107. set_bit(DEVICE_CATEGORY_DISPLAY, dc->categories);
  108. }
  109. static const TypeInfo vga_mmio_info = {
  110. .name = TYPE_VGA_MMIO,
  111. .parent = TYPE_SYS_BUS_DEVICE,
  112. .instance_size = sizeof(VGAMmioState),
  113. .class_init = vga_mmio_class_initfn,
  114. };
  115. static void vga_mmio_register_types(void)
  116. {
  117. type_register_static(&vga_mmio_info);
  118. }
  119. type_init(vga_mmio_register_types)