modesetting.c 3.5 KB

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