vga-pci.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * QEMU PCI 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 "pci.h"
  28. #include "vga_int.h"
  29. #include "pixel_ops.h"
  30. #include "qemu-timer.h"
  31. #include "loader.h"
  32. typedef struct PCIVGAState {
  33. PCIDevice dev;
  34. VGACommonState vga;
  35. } PCIVGAState;
  36. static const VMStateDescription vmstate_vga_pci = {
  37. .name = "vga",
  38. .version_id = 2,
  39. .minimum_version_id = 2,
  40. .minimum_version_id_old = 2,
  41. .fields = (VMStateField []) {
  42. VMSTATE_PCI_DEVICE(dev, PCIVGAState),
  43. VMSTATE_STRUCT(vga, PCIVGAState, 0, vmstate_vga_common, VGACommonState),
  44. VMSTATE_END_OF_LIST()
  45. }
  46. };
  47. static void vga_map(PCIDevice *pci_dev, int region_num,
  48. pcibus_t addr, pcibus_t size, int type)
  49. {
  50. PCIVGAState *d = (PCIVGAState *)pci_dev;
  51. VGACommonState *s = &d->vga;
  52. cpu_register_physical_memory(addr, s->vram_size, s->vram_offset);
  53. s->map_addr = addr;
  54. s->map_end = addr + s->vram_size;
  55. vga_dirty_log_start(s);
  56. }
  57. static void pci_vga_write_config(PCIDevice *d,
  58. uint32_t address, uint32_t val, int len)
  59. {
  60. PCIVGAState *pvs = container_of(d, PCIVGAState, dev);
  61. VGACommonState *s = &pvs->vga;
  62. pci_default_write_config(d, address, val, len);
  63. if (s->map_addr && pvs->dev.io_regions[0].addr == -1)
  64. s->map_addr = 0;
  65. }
  66. static int pci_vga_initfn(PCIDevice *dev)
  67. {
  68. PCIVGAState *d = DO_UPCAST(PCIVGAState, dev, dev);
  69. VGACommonState *s = &d->vga;
  70. // vga + console init
  71. vga_common_init(s, VGA_RAM_SIZE);
  72. vga_init(s);
  73. s->ds = graphic_console_init(s->update, s->invalidate,
  74. s->screen_dump, s->text_update, s);
  75. /* XXX: VGA_RAM_SIZE must be a power of two */
  76. pci_register_bar(&d->dev, 0, VGA_RAM_SIZE,
  77. PCI_BASE_ADDRESS_MEM_PREFETCH, vga_map);
  78. if (!dev->rom_bar) {
  79. /* compatibility with pc-0.13 and older */
  80. vga_init_vbe(s);
  81. }
  82. return 0;
  83. }
  84. int pci_vga_init(PCIBus *bus)
  85. {
  86. pci_create_simple(bus, -1, "VGA");
  87. return 0;
  88. }
  89. static PCIDeviceInfo vga_info = {
  90. .qdev.name = "VGA",
  91. .qdev.size = sizeof(PCIVGAState),
  92. .qdev.vmsd = &vmstate_vga_pci,
  93. .no_hotplug = 1,
  94. .init = pci_vga_initfn,
  95. .config_write = pci_vga_write_config,
  96. .romfile = "vgabios-stdvga.bin",
  97. /* dummy VGA (same as Bochs ID) */
  98. .vendor_id = PCI_VENDOR_ID_QEMU,
  99. .device_id = PCI_DEVICE_ID_QEMU_VGA,
  100. .class_id = PCI_CLASS_DISPLAY_VGA,
  101. };
  102. static void vga_register(void)
  103. {
  104. pci_qdev_register(&vga_info);
  105. }
  106. device_init(vga_register);