vga-isa-mm.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * QEMU ISA MM 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 "qemu/bitops.h"
  26. #include "qemu/units.h"
  27. #include "migration/vmstate.h"
  28. #include "hw/display/vga.h"
  29. #include "vga_int.h"
  30. #include "ui/pixel_ops.h"
  31. #define VGA_RAM_SIZE (8 * MiB)
  32. typedef struct ISAVGAMMState {
  33. VGACommonState vga;
  34. int it_shift;
  35. } ISAVGAMMState;
  36. /* Memory mapped interface */
  37. static uint64_t vga_mm_read(void *opaque, hwaddr addr, unsigned size)
  38. {
  39. ISAVGAMMState *s = opaque;
  40. return vga_ioport_read(&s->vga, addr >> s->it_shift) &
  41. MAKE_64BIT_MASK(0, size * 8);
  42. }
  43. static void vga_mm_write(void *opaque, hwaddr addr, uint64_t value,
  44. unsigned size)
  45. {
  46. ISAVGAMMState *s = opaque;
  47. vga_ioport_write(&s->vga, addr >> s->it_shift,
  48. value & MAKE_64BIT_MASK(0, size * 8));
  49. }
  50. static const MemoryRegionOps vga_mm_ctrl_ops = {
  51. .read = vga_mm_read,
  52. .write = vga_mm_write,
  53. .valid.min_access_size = 1,
  54. .valid.max_access_size = 4,
  55. .impl.min_access_size = 1,
  56. .impl.max_access_size = 4,
  57. .endianness = DEVICE_NATIVE_ENDIAN,
  58. };
  59. static void vga_mm_init(ISAVGAMMState *s, hwaddr vram_base,
  60. hwaddr ctrl_base, int it_shift,
  61. MemoryRegion *address_space)
  62. {
  63. MemoryRegion *s_ioport_ctrl, *vga_io_memory;
  64. s->it_shift = it_shift;
  65. s_ioport_ctrl = g_malloc(sizeof(*s_ioport_ctrl));
  66. memory_region_init_io(s_ioport_ctrl, NULL, &vga_mm_ctrl_ops, s,
  67. "vga-mm-ctrl", 0x100000);
  68. memory_region_set_flush_coalesced(s_ioport_ctrl);
  69. vga_io_memory = g_malloc(sizeof(*vga_io_memory));
  70. /* XXX: endianness? */
  71. memory_region_init_io(vga_io_memory, NULL, &vga_mem_ops, &s->vga,
  72. "vga-mem", 0x20000);
  73. vmstate_register(NULL, 0, &vmstate_vga_common, s);
  74. memory_region_add_subregion(address_space, ctrl_base, s_ioport_ctrl);
  75. s->vga.bank_offset = 0;
  76. memory_region_add_subregion(address_space,
  77. vram_base + 0x000a0000, vga_io_memory);
  78. memory_region_set_coalescing(vga_io_memory);
  79. }
  80. int isa_vga_mm_init(hwaddr vram_base,
  81. hwaddr ctrl_base, int it_shift,
  82. MemoryRegion *address_space)
  83. {
  84. ISAVGAMMState *s;
  85. s = g_malloc0(sizeof(*s));
  86. s->vga.vram_size_mb = VGA_RAM_SIZE / MiB;
  87. s->vga.global_vmstate = true;
  88. vga_common_init(&s->vga, NULL);
  89. vga_mm_init(s, vram_base, ctrl_base, it_shift, address_space);
  90. s->vga.con = graphic_console_init(NULL, 0, s->vga.hw_ops, s);
  91. vga_init_vbe(&s->vga, NULL, address_space);
  92. return 0;
  93. }