vbox_drv.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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_MAJOR 1
  25. #define DRIVER_MINOR 0
  26. #define DRIVER_PATCHLEVEL 0
  27. #define VBOX_MAX_CURSOR_WIDTH 64
  28. #define VBOX_MAX_CURSOR_HEIGHT 64
  29. #define CURSOR_PIXEL_COUNT (VBOX_MAX_CURSOR_WIDTH * VBOX_MAX_CURSOR_HEIGHT)
  30. #define CURSOR_DATA_SIZE (CURSOR_PIXEL_COUNT * 4 + CURSOR_PIXEL_COUNT / 8)
  31. #define VBOX_MAX_SCREENS 32
  32. #define GUEST_HEAP_OFFSET(vbox) ((vbox)->full_vram_size - \
  33. VBVA_ADAPTER_INFORMATION_SIZE)
  34. #define GUEST_HEAP_SIZE VBVA_ADAPTER_INFORMATION_SIZE
  35. #define GUEST_HEAP_USABLE_SIZE (VBVA_ADAPTER_INFORMATION_SIZE - \
  36. sizeof(struct hgsmi_host_flags))
  37. #define HOST_FLAGS_OFFSET GUEST_HEAP_USABLE_SIZE
  38. struct vbox_private {
  39. /* Must be first; or we must define our own release callback */
  40. struct drm_device ddev;
  41. u8 __iomem *guest_heap;
  42. u8 __iomem *vbva_buffers;
  43. struct gen_pool *guest_pool;
  44. struct vbva_buf_ctx *vbva_info;
  45. bool any_pitch;
  46. u32 num_crtcs;
  47. /* Amount of available VRAM, including space used for buffers. */
  48. u32 full_vram_size;
  49. /* Amount of available VRAM, not including space used for buffers. */
  50. u32 available_vram_size;
  51. /* Array of structures for receiving mode hints. */
  52. struct vbva_modehint *last_mode_hints;
  53. int fb_mtrr;
  54. struct mutex hw_mutex; /* protects modeset and accel/vbva accesses */
  55. struct work_struct hotplug_work;
  56. u32 input_mapping_width;
  57. u32 input_mapping_height;
  58. /*
  59. * Is user-space using an X.Org-style layout of one large frame-buffer
  60. * encompassing all screen ones or is the fbdev console active?
  61. */
  62. bool single_framebuffer;
  63. u8 cursor_data[CURSOR_DATA_SIZE];
  64. };
  65. #undef CURSOR_PIXEL_COUNT
  66. #undef CURSOR_DATA_SIZE
  67. struct vbox_connector {
  68. struct drm_connector base;
  69. char name[32];
  70. struct vbox_crtc *vbox_crtc;
  71. struct {
  72. u32 width;
  73. u32 height;
  74. bool disconnected;
  75. } mode_hint;
  76. };
  77. struct vbox_crtc {
  78. struct drm_crtc base;
  79. bool disconnected;
  80. unsigned int crtc_id;
  81. u32 fb_offset;
  82. bool cursor_enabled;
  83. u32 x_hint;
  84. u32 y_hint;
  85. /*
  86. * When setting a mode we not only pass the mode to the hypervisor,
  87. * but also information on how to map / translate input coordinates
  88. * for the emulated USB tablet. This input-mapping may change when
  89. * the mode on *another* crtc changes.
  90. *
  91. * This means that sometimes we must do a modeset on other crtc-s then
  92. * the one being changed to update the input-mapping. Including crtc-s
  93. * which may be disabled inside the guest (shown as a black window
  94. * on the host unless closed by the user).
  95. *
  96. * With atomic modesetting the mode-info of disabled crtcs gets zeroed
  97. * yet we need it when updating the input-map to avoid resizing the
  98. * window as a side effect of a mode_set on another crtc. Therefor we
  99. * cache the info of the last mode below.
  100. */
  101. u32 width;
  102. u32 height;
  103. u32 x;
  104. u32 y;
  105. };
  106. struct vbox_encoder {
  107. struct drm_encoder base;
  108. };
  109. #define to_vbox_crtc(x) container_of(x, struct vbox_crtc, base)
  110. #define to_vbox_connector(x) container_of(x, struct vbox_connector, base)
  111. #define to_vbox_encoder(x) container_of(x, struct vbox_encoder, base)
  112. #define to_vbox_dev(x) container_of(x, struct vbox_private, ddev)
  113. bool vbox_check_supported(u16 id);
  114. int vbox_hw_init(struct vbox_private *vbox);
  115. void vbox_hw_fini(struct vbox_private *vbox);
  116. int vbox_mode_init(struct vbox_private *vbox);
  117. void vbox_mode_fini(struct vbox_private *vbox);
  118. void vbox_report_caps(struct vbox_private *vbox);
  119. int vbox_mm_init(struct vbox_private *vbox);
  120. /* vbox_irq.c */
  121. int vbox_irq_init(struct vbox_private *vbox);
  122. void vbox_irq_fini(struct vbox_private *vbox);
  123. void vbox_report_hotplug(struct vbox_private *vbox);
  124. /* vbox_hgsmi.c */
  125. void *hgsmi_buffer_alloc(struct gen_pool *guest_pool, size_t size,
  126. u8 channel, u16 channel_info);
  127. void hgsmi_buffer_free(struct gen_pool *guest_pool, void *buf);
  128. int hgsmi_buffer_submit(struct gen_pool *guest_pool, void *buf);
  129. static inline void vbox_write_ioport(u16 index, u16 data)
  130. {
  131. outw(index, VBE_DISPI_IOPORT_INDEX);
  132. outw(data, VBE_DISPI_IOPORT_DATA);
  133. }
  134. #endif