vga-isa-mm.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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 "hw.h"
  25. #include "console.h"
  26. #include "pc.h"
  27. #include "vga_int.h"
  28. #include "pixel_ops.h"
  29. #include "qemu-timer.h"
  30. typedef struct ISAVGAMMState {
  31. VGACommonState vga;
  32. int it_shift;
  33. } ISAVGAMMState;
  34. /* Memory mapped interface */
  35. static uint32_t vga_mm_readb (void *opaque, target_phys_addr_t addr)
  36. {
  37. ISAVGAMMState *s = opaque;
  38. return vga_ioport_read(&s->vga, addr >> s->it_shift) & 0xff;
  39. }
  40. static void vga_mm_writeb (void *opaque,
  41. target_phys_addr_t addr, uint32_t value)
  42. {
  43. ISAVGAMMState *s = opaque;
  44. vga_ioport_write(&s->vga, addr >> s->it_shift, value & 0xff);
  45. }
  46. static uint32_t vga_mm_readw (void *opaque, target_phys_addr_t addr)
  47. {
  48. ISAVGAMMState *s = opaque;
  49. return vga_ioport_read(&s->vga, addr >> s->it_shift) & 0xffff;
  50. }
  51. static void vga_mm_writew (void *opaque,
  52. target_phys_addr_t addr, uint32_t value)
  53. {
  54. ISAVGAMMState *s = opaque;
  55. vga_ioport_write(&s->vga, addr >> s->it_shift, value & 0xffff);
  56. }
  57. static uint32_t vga_mm_readl (void *opaque, target_phys_addr_t addr)
  58. {
  59. ISAVGAMMState *s = opaque;
  60. return vga_ioport_read(&s->vga, addr >> s->it_shift);
  61. }
  62. static void vga_mm_writel (void *opaque,
  63. target_phys_addr_t addr, uint32_t value)
  64. {
  65. ISAVGAMMState *s = opaque;
  66. vga_ioport_write(&s->vga, addr >> s->it_shift, value);
  67. }
  68. static const MemoryRegionOps vga_mm_ctrl_ops = {
  69. .old_mmio = {
  70. .read = {
  71. vga_mm_readb,
  72. vga_mm_readw,
  73. vga_mm_readl,
  74. },
  75. .write = {
  76. vga_mm_writeb,
  77. vga_mm_writew,
  78. vga_mm_writel,
  79. },
  80. },
  81. .endianness = DEVICE_NATIVE_ENDIAN,
  82. };
  83. static void vga_mm_init(ISAVGAMMState *s, target_phys_addr_t vram_base,
  84. target_phys_addr_t ctrl_base, int it_shift,
  85. MemoryRegion *address_space)
  86. {
  87. MemoryRegion *s_ioport_ctrl, *vga_io_memory;
  88. s->it_shift = it_shift;
  89. s_ioport_ctrl = g_malloc(sizeof(*s_ioport_ctrl));
  90. memory_region_init_io(s_ioport_ctrl, &vga_mm_ctrl_ops, s,
  91. "vga-mm-ctrl", 0x100000);
  92. vga_io_memory = g_malloc(sizeof(*vga_io_memory));
  93. /* XXX: endianness? */
  94. memory_region_init_io(vga_io_memory, &vga_mem_ops, &s->vga,
  95. "vga-mem", 0x20000);
  96. vmstate_register(NULL, 0, &vmstate_vga_common, s);
  97. memory_region_add_subregion(address_space, ctrl_base, s_ioport_ctrl);
  98. s->vga.bank_offset = 0;
  99. memory_region_add_subregion(address_space,
  100. vram_base + 0x000a0000, vga_io_memory);
  101. memory_region_set_coalescing(vga_io_memory);
  102. }
  103. int isa_vga_mm_init(target_phys_addr_t vram_base,
  104. target_phys_addr_t ctrl_base, int it_shift,
  105. MemoryRegion *address_space)
  106. {
  107. ISAVGAMMState *s;
  108. s = g_malloc0(sizeof(*s));
  109. vga_common_init(&s->vga, VGA_RAM_SIZE);
  110. vga_mm_init(s, vram_base, ctrl_base, it_shift, address_space);
  111. s->vga.ds = graphic_console_init(s->vga.update, s->vga.invalidate,
  112. s->vga.screen_dump, s->vga.text_update, s);
  113. vga_init_vbe(&s->vga, address_space);
  114. return 0;
  115. }