qxl.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. #ifndef HW_QXL_H
  2. #define HW_QXL_H
  3. #include "hw/pci/pci_device.h"
  4. #include "vga_int.h"
  5. #include "qemu/thread.h"
  6. #include "ui/qemu-spice.h"
  7. #include "ui/spice-display.h"
  8. #include "qom/object.h"
  9. enum qxl_mode {
  10. QXL_MODE_UNDEFINED,
  11. QXL_MODE_VGA,
  12. QXL_MODE_COMPAT, /* spice 0.4.x */
  13. QXL_MODE_NATIVE,
  14. };
  15. #ifndef QXL_VRAM64_RANGE_INDEX
  16. #define QXL_VRAM64_RANGE_INDEX 4
  17. #endif
  18. #define QXL_UNDEFINED_IO UINT32_MAX
  19. #define QXL_NUM_DIRTY_RECTS 64
  20. #define QXL_PAGE_BITS 12
  21. #define QXL_PAGE_SIZE (1 << QXL_PAGE_BITS);
  22. struct PCIQXLDevice {
  23. PCIDevice pci;
  24. PortioList vga_port_list;
  25. SimpleSpiceDisplay ssd;
  26. int id;
  27. bool have_vga;
  28. uint32_t debug;
  29. uint32_t guestdebug;
  30. uint32_t cmdlog;
  31. uint32_t guest_bug;
  32. enum qxl_mode mode;
  33. uint32_t cmdflags;
  34. uint32_t revision;
  35. int32_t num_memslots;
  36. uint32_t current_async;
  37. QemuMutex async_lock;
  38. struct guest_slots {
  39. QXLMemSlot slot;
  40. MemoryRegion *mr;
  41. uint64_t offset;
  42. uint64_t size;
  43. uint64_t delta;
  44. uint32_t active;
  45. } guest_slots[NUM_MEMSLOTS];
  46. struct guest_primary {
  47. QXLSurfaceCreate surface;
  48. uint32_t commands;
  49. uint32_t resized;
  50. int32_t qxl_stride;
  51. uint32_t abs_stride;
  52. uint32_t bits_pp;
  53. uint32_t bytes_pp;
  54. uint8_t *data;
  55. } guest_primary;
  56. struct surfaces {
  57. QXLPHYSICAL *cmds;
  58. uint32_t count;
  59. uint32_t max;
  60. } guest_surfaces;
  61. QXLPHYSICAL guest_cursor;
  62. QXLPHYSICAL guest_monitors_config;
  63. uint32_t guest_head0_width;
  64. uint32_t guest_head0_height;
  65. QemuMutex track_lock;
  66. /* thread signaling */
  67. QEMUBH *update_irq;
  68. /* ram pci bar */
  69. QXLRam *ram;
  70. VGACommonState vga;
  71. uint32_t num_free_res;
  72. QXLReleaseInfo *last_release;
  73. uint32_t last_release_offset;
  74. uint32_t oom_running;
  75. uint32_t vgamem_size;
  76. /* rom pci bar */
  77. QXLRom shadow_rom;
  78. QXLRom *rom;
  79. QXLModes *modes;
  80. uint32_t rom_size;
  81. MemoryRegion rom_bar;
  82. uint16_t max_outputs;
  83. /* vram pci bar */
  84. uint64_t vram_size;
  85. MemoryRegion vram_bar;
  86. uint64_t vram32_size;
  87. MemoryRegion vram32_bar;
  88. /* io bar */
  89. MemoryRegion io_bar;
  90. /* user-friendly properties (in megabytes) */
  91. uint32_t ram_size_mb;
  92. uint32_t vram_size_mb;
  93. uint32_t vram32_size_mb;
  94. uint32_t vgamem_size_mb;
  95. uint32_t xres;
  96. uint32_t yres;
  97. /* qxl_render_update state */
  98. int render_update_cookie_num;
  99. int num_dirty_rects;
  100. QXLRect dirty[QXL_NUM_DIRTY_RECTS];
  101. QEMUBH *update_area_bh;
  102. };
  103. #define TYPE_PCI_QXL "pci-qxl"
  104. OBJECT_DECLARE_SIMPLE_TYPE(PCIQXLDevice, PCI_QXL)
  105. #define PANIC_ON(x) if ((x)) { \
  106. printf("%s: PANIC %s failed\n", __func__, #x); \
  107. abort(); \
  108. }
  109. #define dprint(_qxl, _level, _fmt, ...) \
  110. do { \
  111. if (_qxl->debug >= _level) { \
  112. fprintf(stderr, "qxl-%d: ", _qxl->id); \
  113. fprintf(stderr, _fmt, ## __VA_ARGS__); \
  114. } \
  115. } while (0)
  116. #define QXL_DEFAULT_REVISION (QXL_REVISION_STABLE_V12 + 1)
  117. /* qxl.c */
  118. /**
  119. * qxl_phys2virt: Get a pointer within a PCI VRAM memory region.
  120. *
  121. * @qxl: QXL device
  122. * @phys: physical offset of buffer within the VRAM
  123. * @group_id: memory slot group
  124. * @size: size of the buffer
  125. *
  126. * Returns a host pointer to a buffer placed at offset @phys within the
  127. * active slot @group_id of the PCI VGA RAM memory region associated with
  128. * the @qxl device. If the slot is inactive, or the offset + size are out
  129. * of the memory region, returns NULL.
  130. *
  131. * Use with care; by the time this function returns, the returned pointer is
  132. * not protected by RCU anymore. If the caller is not within an RCU critical
  133. * section and does not hold the iothread lock, it must have other means of
  134. * protecting the pointer, such as a reference to the region that includes
  135. * the incoming ram_addr_t.
  136. *
  137. */
  138. void *qxl_phys2virt(PCIQXLDevice *qxl, QXLPHYSICAL phys, int group_id,
  139. size_t size);
  140. void qxl_set_guest_bug(PCIQXLDevice *qxl, const char *msg, ...)
  141. G_GNUC_PRINTF(2, 3);
  142. void qxl_spice_update_area(PCIQXLDevice *qxl, uint32_t surface_id,
  143. struct QXLRect *area, struct QXLRect *dirty_rects,
  144. uint32_t num_dirty_rects,
  145. uint32_t clear_dirty_region,
  146. qxl_async_io async, QXLCookie *cookie);
  147. void qxl_spice_loadvm_commands(PCIQXLDevice *qxl, struct QXLCommandExt *ext,
  148. uint32_t count);
  149. void qxl_spice_oom(PCIQXLDevice *qxl);
  150. void qxl_spice_reset_memslots(PCIQXLDevice *qxl);
  151. void qxl_spice_reset_image_cache(PCIQXLDevice *qxl);
  152. void qxl_spice_reset_cursor(PCIQXLDevice *qxl);
  153. /* qxl-logger.c */
  154. int qxl_log_cmd_cursor(PCIQXLDevice *qxl, QXLCursorCmd *cmd, int group_id);
  155. int qxl_log_command(PCIQXLDevice *qxl, const char *ring, QXLCommandExt *ext);
  156. /* qxl-render.c */
  157. void qxl_render_resize(PCIQXLDevice *qxl);
  158. void qxl_render_update(PCIQXLDevice *qxl);
  159. int qxl_render_cursor(PCIQXLDevice *qxl, QXLCommandExt *ext);
  160. void qxl_render_update_area_done(PCIQXLDevice *qxl, QXLCookie *cookie);
  161. void qxl_render_update_area_bh(void *opaque);
  162. #endif