2
0

vga-pci.c 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 int pci_vga_initfn(PCIDevice *dev)
  48. {
  49. PCIVGAState *d = DO_UPCAST(PCIVGAState, dev, dev);
  50. VGACommonState *s = &d->vga;
  51. // vga + console init
  52. vga_common_init(s, VGA_RAM_SIZE);
  53. vga_init(s, pci_address_space(dev), pci_address_space_io(dev), true);
  54. s->ds = graphic_console_init(s->update, s->invalidate,
  55. s->screen_dump, s->text_update, s);
  56. /* XXX: VGA_RAM_SIZE must be a power of two */
  57. pci_register_bar(&d->dev, 0, PCI_BASE_ADDRESS_MEM_PREFETCH, &s->vram);
  58. if (!dev->rom_bar) {
  59. /* compatibility with pc-0.13 and older */
  60. vga_init_vbe(s, pci_address_space(dev));
  61. }
  62. return 0;
  63. }
  64. int pci_vga_init(PCIBus *bus)
  65. {
  66. pci_create_simple(bus, -1, "VGA");
  67. return 0;
  68. }
  69. static PCIDeviceInfo vga_info = {
  70. .qdev.name = "VGA",
  71. .qdev.size = sizeof(PCIVGAState),
  72. .qdev.vmsd = &vmstate_vga_pci,
  73. .no_hotplug = 1,
  74. .init = pci_vga_initfn,
  75. .romfile = "vgabios-stdvga.bin",
  76. /* dummy VGA (same as Bochs ID) */
  77. .vendor_id = PCI_VENDOR_ID_QEMU,
  78. .device_id = PCI_DEVICE_ID_QEMU_VGA,
  79. .class_id = PCI_CLASS_DISPLAY_VGA,
  80. };
  81. static void vga_register(void)
  82. {
  83. pci_qdev_register(&vga_info);
  84. }
  85. device_init(vga_register);