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