vbox_drv.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /* SPDX-License-Identifier: MIT */
  2. /*
  3. * Copyright (C) 2013-2017 Oracle Corporation
  4. * This file is based on ast_drv.h
  5. * Copyright 2012 Red Hat Inc.
  6. * Authors: Dave Airlie <airlied@redhat.com>
  7. * Michael Thayer <michael.thayer@oracle.com,
  8. * Hans de Goede <hdegoede@redhat.com>
  9. */
  10. #ifndef __VBOX_DRV_H__
  11. #define __VBOX_DRV_H__
  12. #include <linux/genalloc.h>
  13. #include <linux/io.h>
  14. #include <linux/irqreturn.h>
  15. #include <linux/string.h>
  16. #include <drm/drm_encoder.h>
  17. #include <drm/drm_gem.h>
  18. #include <drm/drm_gem_vram_helper.h>
  19. #include "vboxvideo_guest.h"
  20. #include "vboxvideo_vbe.h"
  21. #include "hgsmi_ch_setup.h"
  22. #define DRIVER_NAME "vboxvideo"
  23. #define DRIVER_DESC "Oracle VM VirtualBox Graphics Card"
  24. #define DRIVER_DATE "20130823"
  25. #define DRIVER_MAJOR 1
  26. #define DRIVER_MINOR 0
  27. #define DRIVER_PATCHLEVEL 0
  28. #define VBOX_MAX_CURSOR_WIDTH 64
  29. #define VBOX_MAX_CURSOR_HEIGHT 64
  30. #define CURSOR_PIXEL_COUNT (VBOX_MAX_CURSOR_WIDTH * VBOX_MAX_CURSOR_HEIGHT)
  31. #define CURSOR_DATA_SIZE (CURSOR_PIXEL_COUNT * 4 + CURSOR_PIXEL_COUNT / 8)
  32. #define VBOX_MAX_SCREENS 32
  33. #define GUEST_HEAP_OFFSET(vbox) ((vbox)->full_vram_size - \
  34. VBVA_ADAPTER_INFORMATION_SIZE)
  35. #define GUEST_HEAP_SIZE VBVA_ADAPTER_INFORMATION_SIZE
  36. #define GUEST_HEAP_USABLE_SIZE (VBVA_ADAPTER_INFORMATION_SIZE - \
  37. sizeof(struct hgsmi_host_flags))
  38. #define HOST_FLAGS_OFFSET GUEST_HEAP_USABLE_SIZE
  39. struct vbox_private {
  40. /* Must be first; or we must define our own release callback */
  41. struct drm_device ddev;
  42. u8 __iomem *guest_heap;
  43. u8 __iomem *vbva_buffers;
  44. struct gen_pool *guest_pool;
  45. struct vbva_buf_ctx *vbva_info;
  46. bool any_pitch;
  47. u32 num_crtcs;
  48. /* Amount of available VRAM, including space used for buffers. */
  49. u32 full_vram_size;
  50. /* Amount of available VRAM, not including space used for buffers. */
  51. u32 available_vram_size;
  52. /* Array of structures for receiving mode hints. */
  53. struct vbva_modehint *last_mode_hints;
  54. int fb_mtrr;
  55. struct mutex hw_mutex; /* protects modeset and accel/vbva accesses */
  56. struct work_struct hotplug_work;
  57. u32 input_mapping_width;
  58. u32 input_mapping_height;
  59. /*
  60. * Is user-space using an X.Org-style layout of one large frame-buffer
  61. * encompassing all screen ones or is the fbdev console active?
  62. */
  63. bool single_framebuffer;
  64. u8 cursor_data[CURSOR_DATA_SIZE];
  65. };
  66. #undef CURSOR_PIXEL_COUNT
  67. #undef CURSOR_DATA_SIZE
  68. struct vbox_connector {
  69. struct drm_connector base;
  70. char name[32];
  71. struct vbox_crtc *vbox_crtc;
  72. struct {
  73. u32 width;
  74. u32 height;
  75. bool disconnected;
  76. } mode_hint;
  77. };
  78. struct vbox_crtc {
  79. struct drm_crtc base;
  80. bool disconnected;
  81. unsigned int crtc_id;
  82. u32 fb_offset;
  83. bool cursor_enabled;
  84. u32 x_hint;
  85. u32 y_hint;
  86. /*
  87. * When setting a mode we not only pass the mode to the hypervisor,
  88. * but also information on how to map / translate input coordinates
  89. * for the emulated USB tablet. This input-mapping may change when
  90. * the mode on *another* crtc changes.
  91. *
  92. * This means that sometimes we must do a modeset on other crtc-s then
  93. * the one being changed to update the input-mapping. Including crtc-s
  94. * which may be disabled inside the guest (shown as a black window
  95. * on the host unless closed by the user).
  96. *
  97. * With atomic modesetting the mode-info of disabled crtcs gets zeroed
  98. * yet we need it when updating the input-map to avoid resizing the
  99. * window as a side effect of a mode_set on another crtc. Therefor we
  100. * cache the info of the last mode below.
  101. */
  102. u32 width;
  103. u32 height;
  104. u32 x;
  105. u32 y;
  106. };
  107. struct vbox_encoder {
  108. struct drm_encoder base;
  109. };
  110. #define to_vbox_crtc(x) container_of(x, struct vbox_crtc, base)
  111. #define to_vbox_connector(x) container_of(x, struct vbox_connector, base)
  112. #define to_vbox_encoder(x) container_of(x, struct vbox_encoder, base)
  113. #define to_vbox_dev(x) container_of(x, struct vbox_private, ddev)
  114. bool vbox_check_supported(u16 id);
  115. int vbox_hw_init(struct vbox_private *vbox);
  116. void vbox_hw_fini(struct vbox_private *vbox);
  117. int vbox_mode_init(struct vbox_private *vbox);
  118. void vbox_mode_fini(struct vbox_private *vbox);
  119. void vbox_report_caps(struct vbox_private *vbox);
  120. int vbox_mm_init(struct vbox_private *vbox);
  121. void vbox_mm_fini(struct vbox_private *vbox);
  122. /* vbox_irq.c */
  123. int vbox_irq_init(struct vbox_private *vbox);
  124. void vbox_irq_fini(struct vbox_private *vbox);
  125. void vbox_report_hotplug(struct vbox_private *vbox);
  126. irqreturn_t vbox_irq_handler(int irq, void *arg);
  127. /* vbox_hgsmi.c */
  128. void *hgsmi_buffer_alloc(struct gen_pool *guest_pool, size_t size,
  129. u8 channel, u16 channel_info);
  130. void hgsmi_buffer_free(struct gen_pool *guest_pool, void *buf);
  131. int hgsmi_buffer_submit(struct gen_pool *guest_pool, void *buf);
  132. static inline void vbox_write_ioport(u16 index, u16 data)
  133. {
  134. outw(index, VBE_DISPI_IOPORT_INDEX);
  135. outw(data, VBE_DISPI_IOPORT_DATA);
  136. }
  137. #endif