vga-isa-mm.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 CPUReadMemoryFunc * const vga_mm_read_ctrl[] = {
  69. &vga_mm_readb,
  70. &vga_mm_readw,
  71. &vga_mm_readl,
  72. };
  73. static CPUWriteMemoryFunc * const vga_mm_write_ctrl[] = {
  74. &vga_mm_writeb,
  75. &vga_mm_writew,
  76. &vga_mm_writel,
  77. };
  78. static void vga_mm_init(ISAVGAMMState *s, target_phys_addr_t vram_base,
  79. target_phys_addr_t ctrl_base, int it_shift)
  80. {
  81. int s_ioport_ctrl, vga_io_memory;
  82. s->it_shift = it_shift;
  83. s_ioport_ctrl = cpu_register_io_memory(vga_mm_read_ctrl, vga_mm_write_ctrl, s,
  84. DEVICE_NATIVE_ENDIAN);
  85. vga_io_memory = cpu_register_io_memory(vga_mem_read, vga_mem_write, s,
  86. DEVICE_NATIVE_ENDIAN);
  87. vmstate_register(NULL, 0, &vmstate_vga_common, s);
  88. cpu_register_physical_memory(ctrl_base, 0x100000, s_ioport_ctrl);
  89. s->vga.bank_offset = 0;
  90. cpu_register_physical_memory(vram_base + 0x000a0000, 0x20000, vga_io_memory);
  91. qemu_register_coalesced_mmio(vram_base + 0x000a0000, 0x20000);
  92. }
  93. int isa_vga_mm_init(target_phys_addr_t vram_base,
  94. target_phys_addr_t ctrl_base, int it_shift)
  95. {
  96. ISAVGAMMState *s;
  97. s = qemu_mallocz(sizeof(*s));
  98. vga_common_init(&s->vga, VGA_RAM_SIZE);
  99. vga_mm_init(s, vram_base, ctrl_base, it_shift);
  100. s->vga.ds = graphic_console_init(s->vga.update, s->vga.invalidate,
  101. s->vga.screen_dump, s->vga.text_update, s);
  102. vga_init_vbe(&s->vga);
  103. return 0;
  104. }