vboxguest_core.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /* SPDX-License-Identifier: (GPL-2.0 OR CDDL-1.0) */
  2. /* Copyright (C) 2010-2016 Oracle Corporation */
  3. #ifndef __VBOXGUEST_CORE_H__
  4. #define __VBOXGUEST_CORE_H__
  5. #include <linux/input.h>
  6. #include <linux/interrupt.h>
  7. #include <linux/kernel.h>
  8. #include <linux/list.h>
  9. #include <linux/miscdevice.h>
  10. #include <linux/spinlock.h>
  11. #include <linux/wait.h>
  12. #include <linux/workqueue.h>
  13. #include <linux/vboxguest.h>
  14. #include "vmmdev.h"
  15. struct vbg_session;
  16. /** VBox guest memory balloon. */
  17. struct vbg_mem_balloon {
  18. /** Work handling VMMDEV_EVENT_BALLOON_CHANGE_REQUEST events */
  19. struct work_struct work;
  20. /** Pre-allocated vmmdev_memballoon_info req for query */
  21. struct vmmdev_memballoon_info *get_req;
  22. /** Pre-allocated vmmdev_memballoon_change req for inflate / deflate */
  23. struct vmmdev_memballoon_change *change_req;
  24. /** The current number of chunks in the balloon. */
  25. u32 chunks;
  26. /** The maximum number of chunks in the balloon. */
  27. u32 max_chunks;
  28. /**
  29. * Array of pointers to page arrays. A page * array is allocated for
  30. * each chunk when inflating, and freed when the deflating.
  31. */
  32. struct page ***pages;
  33. };
  34. /**
  35. * Per bit usage tracker for a u32 mask.
  36. *
  37. * Used for optimal handling of guest properties and event filter.
  38. */
  39. struct vbg_bit_usage_tracker {
  40. /** Per bit usage counters. */
  41. u32 per_bit_usage[32];
  42. /** The current mask according to per_bit_usage. */
  43. u32 mask;
  44. };
  45. /** VBox guest device (data) extension. */
  46. struct vbg_dev {
  47. struct device *dev;
  48. /** The base of the adapter I/O ports. */
  49. u16 io_port;
  50. /** Pointer to the mapping of the VMMDev adapter memory. */
  51. struct vmmdev_memory *mmio;
  52. /** Host version */
  53. char host_version[64];
  54. /** Host features */
  55. unsigned int host_features;
  56. /**
  57. * Dummy page and vmap address for reserved kernel virtual-address
  58. * space for the guest mappings, only used on hosts lacking vtx.
  59. */
  60. struct page *guest_mappings_dummy_page;
  61. void *guest_mappings;
  62. /** Spinlock protecting pending_events. */
  63. spinlock_t event_spinlock;
  64. /** Preallocated struct vmmdev_events for the IRQ handler. */
  65. struct vmmdev_events *ack_events_req;
  66. /** Wait-for-event list for threads waiting for multiple events. */
  67. wait_queue_head_t event_wq;
  68. /** Mask of pending events. */
  69. u32 pending_events;
  70. /** Wait-for-event list for threads waiting on HGCM async completion. */
  71. wait_queue_head_t hgcm_wq;
  72. /** Pre-allocated hgcm cancel2 req. for cancellation on timeout */
  73. struct vmmdev_hgcm_cancel2 *cancel_req;
  74. /** Mutex protecting cancel_req accesses */
  75. struct mutex cancel_req_mutex;
  76. /** Pre-allocated mouse-status request for the input-device handling. */
  77. struct vmmdev_mouse_status *mouse_status_req;
  78. /** Input device for reporting abs mouse coordinates to the guest. */
  79. struct input_dev *input;
  80. /** Memory balloon information. */
  81. struct vbg_mem_balloon mem_balloon;
  82. /** Lock for session related items in vbg_dev and vbg_session */
  83. struct mutex session_mutex;
  84. /** Events we won't permit anyone to filter out. */
  85. u32 fixed_events;
  86. /**
  87. * Usage counters for the host events (excludes fixed events),
  88. * Protected by session_mutex.
  89. */
  90. struct vbg_bit_usage_tracker event_filter_tracker;
  91. /**
  92. * The event filter last reported to the host (or UINT32_MAX).
  93. * Protected by session_mutex.
  94. */
  95. u32 event_filter_host;
  96. /**
  97. * Usage counters for guest capabilities. Indexed by capability bit
  98. * number, one count per session using a capability.
  99. * Protected by session_mutex.
  100. */
  101. struct vbg_bit_usage_tracker guest_caps_tracker;
  102. /**
  103. * The guest capabilities last reported to the host (or UINT32_MAX).
  104. * Protected by session_mutex.
  105. */
  106. u32 guest_caps_host;
  107. /**
  108. * Heartbeat timer which fires with interval
  109. * cNsHearbeatInterval and its handler sends
  110. * VMMDEVREQ_GUEST_HEARTBEAT to VMMDev.
  111. */
  112. struct timer_list heartbeat_timer;
  113. /** Heartbeat timer interval in ms. */
  114. int heartbeat_interval_ms;
  115. /** Preallocated VMMDEVREQ_GUEST_HEARTBEAT request. */
  116. struct vmmdev_request_header *guest_heartbeat_req;
  117. /** "vboxguest" char-device */
  118. struct miscdevice misc_device;
  119. /** "vboxuser" char-device */
  120. struct miscdevice misc_device_user;
  121. };
  122. /** The VBoxGuest per session data. */
  123. struct vbg_session {
  124. /** Pointer to the device extension. */
  125. struct vbg_dev *gdev;
  126. /**
  127. * Array containing HGCM client IDs associated with this session.
  128. * These will be automatically disconnected when the session is closed.
  129. * Protected by vbg_gdev.session_mutex.
  130. */
  131. u32 hgcm_client_ids[64];
  132. /**
  133. * Host events requested by the session.
  134. * An event type requested in any guest session will be added to the
  135. * host filter. Protected by vbg_gdev.session_mutex.
  136. */
  137. u32 event_filter;
  138. /**
  139. * Guest capabilities for this session.
  140. * A capability claimed by any guest session will be reported to the
  141. * host. Protected by vbg_gdev.session_mutex.
  142. */
  143. u32 guest_caps;
  144. /** Does this session belong to a root process or a user one? */
  145. bool user_session;
  146. /** Set on CANCEL_ALL_WAITEVENTS, protected by vbg_devevent_spinlock. */
  147. bool cancel_waiters;
  148. };
  149. int vbg_core_init(struct vbg_dev *gdev, u32 fixed_events);
  150. void vbg_core_exit(struct vbg_dev *gdev);
  151. struct vbg_session *vbg_core_open_session(struct vbg_dev *gdev, bool user);
  152. void vbg_core_close_session(struct vbg_session *session);
  153. int vbg_core_ioctl(struct vbg_session *session, unsigned int req, void *data);
  154. int vbg_core_set_mouse_status(struct vbg_dev *gdev, u32 features);
  155. irqreturn_t vbg_core_isr(int irq, void *dev_id);
  156. void vbg_linux_mouse_event(struct vbg_dev *gdev);
  157. /* Private (non exported) functions form vboxguest_utils.c */
  158. void *vbg_req_alloc(size_t len, enum vmmdev_request_type req_type);
  159. void vbg_req_free(void *req, size_t len);
  160. int vbg_req_perform(struct vbg_dev *gdev, void *req);
  161. int vbg_hgcm_call32(
  162. struct vbg_dev *gdev, u32 client_id, u32 function, u32 timeout_ms,
  163. struct vmmdev_hgcm_function_parameter32 *parm32, u32 parm_count,
  164. int *vbox_status);
  165. #endif