modesetting.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. * Copyright (C) 2006-2017 Oracle Corporation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  18. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. * OTHER DEALINGS IN THE SOFTWARE.
  21. */
  22. #include "vbox_drv.h"
  23. #include "vbox_err.h"
  24. #include "vboxvideo_guest.h"
  25. #include "vboxvideo_vbe.h"
  26. #include "hgsmi_channels.h"
  27. /**
  28. * Set a video mode via an HGSMI request. The views must have been
  29. * initialised first using @a VBoxHGSMISendViewInfo and if the mode is being
  30. * set on the first display then it must be set first using registers.
  31. * @param ctx The context containing the heap to use
  32. * @param display The screen number
  33. * @param origin_x The horizontal displacement relative to the first scrn
  34. * @param origin_y The vertical displacement relative to the first screen
  35. * @param start_offset The offset of the visible area of the framebuffer
  36. * relative to the framebuffer start
  37. * @param pitch The offset in bytes between the starts of two adjecent
  38. * scan lines in video RAM
  39. * @param width The mode width
  40. * @param height The mode height
  41. * @param bpp The colour depth of the mode
  42. * @param flags Flags
  43. */
  44. void hgsmi_process_display_info(struct gen_pool *ctx, u32 display,
  45. s32 origin_x, s32 origin_y, u32 start_offset,
  46. u32 pitch, u32 width, u32 height,
  47. u16 bpp, u16 flags)
  48. {
  49. struct vbva_infoscreen *p;
  50. p = hgsmi_buffer_alloc(ctx, sizeof(*p), HGSMI_CH_VBVA,
  51. VBVA_INFO_SCREEN);
  52. if (!p)
  53. return;
  54. p->view_index = display;
  55. p->origin_x = origin_x;
  56. p->origin_y = origin_y;
  57. p->start_offset = start_offset;
  58. p->line_size = pitch;
  59. p->width = width;
  60. p->height = height;
  61. p->bits_per_pixel = bpp;
  62. p->flags = flags;
  63. hgsmi_buffer_submit(ctx, p);
  64. hgsmi_buffer_free(ctx, p);
  65. }
  66. /**
  67. * Report the rectangle relative to which absolute pointer events should be
  68. * expressed. This information remains valid until the next VBVA resize event
  69. * for any screen, at which time it is reset to the bounding rectangle of all
  70. * virtual screens.
  71. * @param ctx The context containing the heap to use.
  72. * @param origin_x Upper left X co-ordinate relative to the first screen.
  73. * @param origin_y Upper left Y co-ordinate relative to the first screen.
  74. * @param width Rectangle width.
  75. * @param height Rectangle height.
  76. * @returns 0 on success, -errno on failure
  77. */
  78. int hgsmi_update_input_mapping(struct gen_pool *ctx, s32 origin_x, s32 origin_y,
  79. u32 width, u32 height)
  80. {
  81. struct vbva_report_input_mapping *p;
  82. p = hgsmi_buffer_alloc(ctx, sizeof(*p), HGSMI_CH_VBVA,
  83. VBVA_REPORT_INPUT_MAPPING);
  84. if (!p)
  85. return -ENOMEM;
  86. p->x = origin_x;
  87. p->y = origin_y;
  88. p->cx = width;
  89. p->cy = height;
  90. hgsmi_buffer_submit(ctx, p);
  91. hgsmi_buffer_free(ctx, p);
  92. return 0;
  93. }
  94. /**
  95. * Get most recent video mode hints.
  96. * @param ctx The context containing the heap to use.
  97. * @param screens The number of screens to query hints for, starting at 0.
  98. * @param hints Array of vbva_modehint structures for receiving the hints.
  99. * @returns 0 on success, -errno on failure
  100. */
  101. int hgsmi_get_mode_hints(struct gen_pool *ctx, unsigned int screens,
  102. struct vbva_modehint *hints)
  103. {
  104. struct vbva_query_mode_hints *p;
  105. size_t size;
  106. if (WARN_ON(!hints))
  107. return -EINVAL;
  108. size = screens * sizeof(struct vbva_modehint);
  109. p = hgsmi_buffer_alloc(ctx, sizeof(*p) + size, HGSMI_CH_VBVA,
  110. VBVA_QUERY_MODE_HINTS);
  111. if (!p)
  112. return -ENOMEM;
  113. p->hints_queried_count = screens;
  114. p->hint_structure_guest_size = sizeof(struct vbva_modehint);
  115. p->rc = VERR_NOT_SUPPORTED;
  116. hgsmi_buffer_submit(ctx, p);
  117. if (RT_FAILURE(p->rc)) {
  118. hgsmi_buffer_free(ctx, p);
  119. return -EIO;
  120. }
  121. memcpy(hints, ((u8 *)p) + sizeof(struct vbva_query_mode_hints), size);
  122. hgsmi_buffer_free(ctx, p);
  123. return 0;
  124. }