qxl.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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. #if SPICE_SERVER_VERSION >= 0x000c06 /* release 0.12.6 */
  83. uint16_t max_outputs;
  84. #endif
  85. /* vram pci bar */
  86. uint64_t vram_size;
  87. MemoryRegion vram_bar;
  88. uint64_t vram32_size;
  89. MemoryRegion vram32_bar;
  90. /* io bar */
  91. MemoryRegion io_bar;
  92. /* user-friendly properties (in megabytes) */
  93. uint32_t ram_size_mb;
  94. uint32_t vram_size_mb;
  95. uint32_t vram32_size_mb;
  96. uint32_t vgamem_size_mb;
  97. uint32_t xres;
  98. uint32_t yres;
  99. /* qxl_render_update state */
  100. int render_update_cookie_num;
  101. int num_dirty_rects;
  102. QXLRect dirty[QXL_NUM_DIRTY_RECTS];
  103. QEMUBH *update_area_bh;
  104. };
  105. #define TYPE_PCI_QXL "pci-qxl"
  106. OBJECT_DECLARE_SIMPLE_TYPE(PCIQXLDevice, PCI_QXL)
  107. #define PANIC_ON(x) if ((x)) { \
  108. printf("%s: PANIC %s failed\n", __func__, #x); \
  109. abort(); \
  110. }
  111. #define dprint(_qxl, _level, _fmt, ...) \
  112. do { \
  113. if (_qxl->debug >= _level) { \
  114. fprintf(stderr, "qxl-%d: ", _qxl->id); \
  115. fprintf(stderr, _fmt, ## __VA_ARGS__); \
  116. } \
  117. } while (0)
  118. #define QXL_DEFAULT_REVISION (QXL_REVISION_STABLE_V12 + 1)
  119. /* qxl.c */
  120. /**
  121. * qxl_phys2virt: Get a pointer within a PCI VRAM memory region.
  122. *
  123. * @qxl: QXL device
  124. * @phys: physical offset of buffer within the VRAM
  125. * @group_id: memory slot group
  126. * @size: size of the buffer
  127. *
  128. * Returns a host pointer to a buffer placed at offset @phys within the
  129. * active slot @group_id of the PCI VGA RAM memory region associated with
  130. * the @qxl device. If the slot is inactive, or the offset + size are out
  131. * of the memory region, returns NULL.
  132. *
  133. * Use with care; by the time this function returns, the returned pointer is
  134. * not protected by RCU anymore. If the caller is not within an RCU critical
  135. * section and does not hold the iothread lock, it must have other means of
  136. * protecting the pointer, such as a reference to the region that includes
  137. * the incoming ram_addr_t.
  138. *
  139. */
  140. void *qxl_phys2virt(PCIQXLDevice *qxl, QXLPHYSICAL phys, int group_id,
  141. size_t size);
  142. void qxl_set_guest_bug(PCIQXLDevice *qxl, const char *msg, ...)
  143. G_GNUC_PRINTF(2, 3);
  144. void qxl_spice_update_area(PCIQXLDevice *qxl, uint32_t surface_id,
  145. struct QXLRect *area, struct QXLRect *dirty_rects,
  146. uint32_t num_dirty_rects,
  147. uint32_t clear_dirty_region,
  148. qxl_async_io async, QXLCookie *cookie);
  149. void qxl_spice_loadvm_commands(PCIQXLDevice *qxl, struct QXLCommandExt *ext,
  150. uint32_t count);
  151. void qxl_spice_oom(PCIQXLDevice *qxl);
  152. void qxl_spice_reset_memslots(PCIQXLDevice *qxl);
  153. void qxl_spice_reset_image_cache(PCIQXLDevice *qxl);
  154. void qxl_spice_reset_cursor(PCIQXLDevice *qxl);
  155. /* qxl-logger.c */
  156. int qxl_log_cmd_cursor(PCIQXLDevice *qxl, QXLCursorCmd *cmd, int group_id);
  157. int qxl_log_command(PCIQXLDevice *qxl, const char *ring, QXLCommandExt *ext);
  158. /* qxl-render.c */
  159. void qxl_render_resize(PCIQXLDevice *qxl);
  160. void qxl_render_update(PCIQXLDevice *qxl);
  161. int qxl_render_cursor(PCIQXLDevice *qxl, QXLCommandExt *ext);
  162. void qxl_render_update_area_done(PCIQXLDevice *qxl, QXLCookie *cookie);
  163. void qxl_render_update_area_bh(void *opaque);
  164. #endif