summaryrefslogtreecommitdiff
path: root/drivers/gpu/drm/vboxvideo/modesetting.c
blob: 7580b90023792b854a06d38ff3a9a9c924e5bfc2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// SPDX-License-Identifier: MIT
/* Copyright (C) 2006-2017 Oracle Corporation */

#include <linux/vbox_err.h>
#include "vbox_drv.h"
#include "vboxvideo_guest.h"
#include "vboxvideo_vbe.h"
#include "hgsmi_channels.h"

/**
 * Set a video mode via an HGSMI request.  The views must have been
 * initialised first using @a VBoxHGSMISendViewInfo and if the mode is being
 * set on the first display then it must be set first using registers.
 * @ctx:           The context containing the heap to use.
 * @display:       The screen number.
 * @origin_x:      The horizontal displacement relative to the first scrn.
 * @origin_y:      The vertical displacement relative to the first screen.
 * @start_offset:  The offset of the visible area of the framebuffer
 *                 relative to the framebuffer start.
 * @pitch:         The offset in bytes between the starts of two adjecent
 *                 scan lines in video RAM.
 * @width:         The mode width.
 * @height:        The mode height.
 * @bpp:           The colour depth of the mode.
 * @flags:         Flags.
 */
void hgsmi_process_display_info(struct gen_pool *ctx, u32 display,
				s32 origin_x, s32 origin_y, u32 start_offset,
				u32 pitch, u32 width, u32 height,
				u16 bpp, u16 flags)
{
	struct vbva_infoscreen *p;

	p = hgsmi_buffer_alloc(ctx, sizeof(*p), HGSMI_CH_VBVA,
			       VBVA_INFO_SCREEN);
	if (!p)
		return;

	p->view_index = display;
	p->origin_x = origin_x;
	p->origin_y = origin_y;
	p->start_offset = start_offset;
	p->line_size = pitch;
	p->width = width;
	p->height = height;
	p->bits_per_pixel = bpp;
	p->flags = flags;

	hgsmi_buffer_submit(ctx, p);
	hgsmi_buffer_free(ctx, p);
}

/**
 * Report the rectangle relative to which absolute pointer events should be
 * expressed.  This information remains valid until the next VBVA resize event
 * for any screen, at which time it is reset to the bounding rectangle of all
 * virtual screens.
 * Return: 0 or negative errno value.
 * @ctx:       The context containing the heap to use.
 * @origin_x:  Upper left X co-ordinate relative to the first screen.
 * @origin_y:  Upper left Y co-ordinate relative to the first screen.
 * @width:     Rectangle width.
 * @height:    Rectangle height.
 */
int hgsmi_update_input_mapping(struct gen_pool *ctx, s32 origin_x, s32 origin_y,
			       u32 width, u32 height)
{
	struct vbva_report_input_mapping *p;

	p = hgsmi_buffer_alloc(ctx, sizeof(*p), HGSMI_CH_VBVA,
			       VBVA_REPORT_INPUT_MAPPING);
	if (!p)
		return -ENOMEM;

	p->x = origin_x;
	p->y = origin_y;
	p->cx = width;
	p->cy = height;

	hgsmi_buffer_submit(ctx, p);
	hgsmi_buffer_free(ctx, p);

	return 0;
}

/**
 * Get most recent video mode hints.
 * Return: 0 or negative errno value.
 * @ctx:      The context containing the heap to use.
 * @screens:  The number of screens to query hints for, starting at 0.
 * @hints:    Array of vbva_modehint structures for receiving the hints.
 */
int hgsmi_get_mode_hints(struct gen_pool *ctx, unsigned int screens,
			 struct vbva_modehint *hints)
{
	struct vbva_query_mode_hints *p;
	size_t size;

	if (WARN_ON(!hints))
		return -EINVAL;

	size = screens * sizeof(struct vbva_modehint);
	p = hgsmi_buffer_alloc(ctx, sizeof(*p) + size, HGSMI_CH_VBVA,
			       VBVA_QUERY_MODE_HINTS);
	if (!p)
		return -ENOMEM;

	p->hints_queried_count = screens;
	p->hint_structure_guest_size = sizeof(struct vbva_modehint);
	p->rc = VERR_NOT_SUPPORTED;

	hgsmi_buffer_submit(ctx, p);

	if (p->rc < 0) {
		hgsmi_buffer_free(ctx, p);
		return -EIO;
	}

	memcpy(hints, ((u8 *)p) + sizeof(struct vbva_query_mode_hints), size);
	hgsmi_buffer_free(ctx, p);

	return 0;
}