modesetting.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. // SPDX-License-Identifier: MIT
  2. /* Copyright (C) 2006-2017 Oracle Corporation */
  3. #include <linux/vbox_err.h>
  4. #include "vbox_drv.h"
  5. #include "vboxvideo_guest.h"
  6. #include "vboxvideo_vbe.h"
  7. #include "hgsmi_channels.h"
  8. /**
  9. * hgsmi_process_display_info - Set a video mode via an HGSMI request.
  10. * The views must have been initialised first
  11. * using @a VBoxHGSMISendViewInfo and if the mode
  12. * is being set on the first display then it must
  13. * be set first using registers.
  14. * @ctx: The context containing the heap to use.
  15. * @display: The screen number.
  16. * @origin_x: The horizontal displacement relative to the first scrn.
  17. * @origin_y: The vertical displacement relative to the first screen.
  18. * @start_offset: The offset of the visible area of the framebuffer
  19. * relative to the framebuffer start.
  20. * @pitch: The offset in bytes between the starts of two adjecent
  21. * scan lines in video RAM.
  22. * @width: The mode width.
  23. * @height: The mode height.
  24. * @bpp: The colour depth of the mode.
  25. * @flags: Flags.
  26. */
  27. void hgsmi_process_display_info(struct gen_pool *ctx, u32 display,
  28. s32 origin_x, s32 origin_y, u32 start_offset,
  29. u32 pitch, u32 width, u32 height,
  30. u16 bpp, u16 flags)
  31. {
  32. struct vbva_infoscreen *p;
  33. p = hgsmi_buffer_alloc(ctx, sizeof(*p), HGSMI_CH_VBVA,
  34. VBVA_INFO_SCREEN);
  35. if (!p)
  36. return;
  37. p->view_index = display;
  38. p->origin_x = origin_x;
  39. p->origin_y = origin_y;
  40. p->start_offset = start_offset;
  41. p->line_size = pitch;
  42. p->width = width;
  43. p->height = height;
  44. p->bits_per_pixel = bpp;
  45. p->flags = flags;
  46. hgsmi_buffer_submit(ctx, p);
  47. hgsmi_buffer_free(ctx, p);
  48. }
  49. /**
  50. * hgsmi_update_input_mapping - Report the rectangle relative to which absolute
  51. * pointer events should be expressed. This
  52. * information remains valid until the next VBVA
  53. * resize event for any screen, at which time it is
  54. * reset to the bounding rectangle of all virtual
  55. * screens.
  56. * Return: 0 or negative errno value.
  57. * @ctx: The context containing the heap to use.
  58. * @origin_x: Upper left X co-ordinate relative to the first screen.
  59. * @origin_y: Upper left Y co-ordinate relative to the first screen.
  60. * @width: Rectangle width.
  61. * @height: Rectangle height.
  62. */
  63. int hgsmi_update_input_mapping(struct gen_pool *ctx, s32 origin_x, s32 origin_y,
  64. u32 width, u32 height)
  65. {
  66. struct vbva_report_input_mapping *p;
  67. p = hgsmi_buffer_alloc(ctx, sizeof(*p), HGSMI_CH_VBVA,
  68. VBVA_REPORT_INPUT_MAPPING);
  69. if (!p)
  70. return -ENOMEM;
  71. p->x = origin_x;
  72. p->y = origin_y;
  73. p->cx = width;
  74. p->cy = height;
  75. hgsmi_buffer_submit(ctx, p);
  76. hgsmi_buffer_free(ctx, p);
  77. return 0;
  78. }
  79. /**
  80. * hgsmi_get_mode_hints - Get most recent video mode hints.
  81. * Return: 0 or negative errno value.
  82. * @ctx: The context containing the heap to use.
  83. * @screens: The number of screens to query hints for, starting at 0.
  84. * @hints: Array of vbva_modehint structures for receiving the hints.
  85. */
  86. int hgsmi_get_mode_hints(struct gen_pool *ctx, unsigned int screens,
  87. struct vbva_modehint *hints)
  88. {
  89. struct vbva_query_mode_hints *p;
  90. size_t size;
  91. if (WARN_ON(!hints))
  92. return -EINVAL;
  93. size = screens * sizeof(struct vbva_modehint);
  94. p = hgsmi_buffer_alloc(ctx, sizeof(*p) + size, HGSMI_CH_VBVA,
  95. VBVA_QUERY_MODE_HINTS);
  96. if (!p)
  97. return -ENOMEM;
  98. p->hints_queried_count = screens;
  99. p->hint_structure_guest_size = sizeof(struct vbva_modehint);
  100. p->rc = VERR_NOT_SUPPORTED;
  101. hgsmi_buffer_submit(ctx, p);
  102. if (p->rc < 0) {
  103. hgsmi_buffer_free(ctx, p);
  104. return -EIO;
  105. }
  106. memcpy(hints, ((u8 *)p) + sizeof(struct vbva_query_mode_hints), size);
  107. hgsmi_buffer_free(ctx, p);
  108. return 0;
  109. }