blob: 4903b91d7fe43abfc6be48e140ea40c740f38926 [file] [log] [blame]
Hans de Goedeacc962c2018-10-18 17:03:32 +02001/* SPDX-License-Identifier: MIT */
Hans de Goededd55d442017-07-06 16:06:01 +02002/*
3 * Copyright (C) 2013-2017 Oracle Corporation
4 * This file is based on ast_drv.h
5 * Copyright 2012 Red Hat Inc.
Hans de Goededd55d442017-07-06 16:06:01 +02006 * Authors: Dave Airlie <airlied@redhat.com>
7 * Michael Thayer <michael.thayer@oracle.com,
8 * Hans de Goede <hdegoede@redhat.com>
9 */
10#ifndef __VBOX_DRV_H__
11#define __VBOX_DRV_H__
12
13#include <linux/genalloc.h>
14#include <linux/io.h>
Hans de Goede0a2bca12018-10-22 16:57:45 +020015#include <linux/irqreturn.h>
Hans de Goededd55d442017-07-06 16:06:01 +020016#include <linux/string.h>
Hans de Goededd55d442017-07-06 16:06:01 +020017
Hans de Goededd55d442017-07-06 16:06:01 +020018#include <drm/drm_encoder.h>
Hans de Goededd55d442017-07-06 16:06:01 +020019#include <drm/drm_gem.h>
Thomas Zimmermann5e6b9252019-05-08 10:26:27 +020020#include <drm/drm_gem_vram_helper.h>
Hans de Goededd55d442017-07-06 16:06:01 +020021
Hans de Goededd55d442017-07-06 16:06:01 +020022#include "vboxvideo_guest.h"
23#include "vboxvideo_vbe.h"
24#include "hgsmi_ch_setup.h"
25
26#define DRIVER_NAME "vboxvideo"
27#define DRIVER_DESC "Oracle VM VirtualBox Graphics Card"
28#define DRIVER_DATE "20130823"
29
30#define DRIVER_MAJOR 1
31#define DRIVER_MINOR 0
32#define DRIVER_PATCHLEVEL 0
33
34#define VBOX_MAX_CURSOR_WIDTH 64
35#define VBOX_MAX_CURSOR_HEIGHT 64
36#define CURSOR_PIXEL_COUNT (VBOX_MAX_CURSOR_WIDTH * VBOX_MAX_CURSOR_HEIGHT)
37#define CURSOR_DATA_SIZE (CURSOR_PIXEL_COUNT * 4 + CURSOR_PIXEL_COUNT / 8)
38
39#define VBOX_MAX_SCREENS 32
40
41#define GUEST_HEAP_OFFSET(vbox) ((vbox)->full_vram_size - \
42 VBVA_ADAPTER_INFORMATION_SIZE)
43#define GUEST_HEAP_SIZE VBVA_ADAPTER_INFORMATION_SIZE
44#define GUEST_HEAP_USABLE_SIZE (VBVA_ADAPTER_INFORMATION_SIZE - \
45 sizeof(struct hgsmi_host_flags))
46#define HOST_FLAGS_OFFSET GUEST_HEAP_USABLE_SIZE
47
Hans de Goededd55d442017-07-06 16:06:01 +020048struct vbox_private {
Hans de Goede01648892018-09-18 19:44:30 +020049 /* Must be first; or we must define our own release callback */
50 struct drm_device ddev;
Hans de Goededd55d442017-07-06 16:06:01 +020051
52 u8 __iomem *guest_heap;
53 u8 __iomem *vbva_buffers;
54 struct gen_pool *guest_pool;
55 struct vbva_buf_ctx *vbva_info;
56 bool any_pitch;
57 u32 num_crtcs;
Hans de Goedecd76c282018-10-18 17:03:31 +020058 /* Amount of available VRAM, including space used for buffers. */
Hans de Goededd55d442017-07-06 16:06:01 +020059 u32 full_vram_size;
Hans de Goedecd76c282018-10-18 17:03:31 +020060 /* Amount of available VRAM, not including space used for buffers. */
Hans de Goededd55d442017-07-06 16:06:01 +020061 u32 available_vram_size;
Hans de Goedecd76c282018-10-18 17:03:31 +020062 /* Array of structures for receiving mode hints. */
Hans de Goededd55d442017-07-06 16:06:01 +020063 struct vbva_modehint *last_mode_hints;
64
Hans de Goededd55d442017-07-06 16:06:01 +020065 int fb_mtrr;
66
Hans de Goededd55d442017-07-06 16:06:01 +020067 struct mutex hw_mutex; /* protects modeset and accel/vbva accesses */
Hans de Goededd55d442017-07-06 16:06:01 +020068 struct work_struct hotplug_work;
69 u32 input_mapping_width;
70 u32 input_mapping_height;
Hans de Goedecd76c282018-10-18 17:03:31 +020071 /*
Hans de Goededd55d442017-07-06 16:06:01 +020072 * Is user-space using an X.Org-style layout of one large frame-buffer
73 * encompassing all screen ones or is the fbdev console active?
74 */
75 bool single_framebuffer;
Hans de Goededd55d442017-07-06 16:06:01 +020076 u8 cursor_data[CURSOR_DATA_SIZE];
77};
78
79#undef CURSOR_PIXEL_COUNT
80#undef CURSOR_DATA_SIZE
81
Hans de Goededd55d442017-07-06 16:06:01 +020082struct vbox_connector {
83 struct drm_connector base;
84 char name[32];
85 struct vbox_crtc *vbox_crtc;
86 struct {
Hans de Goedece10d7b2017-10-12 20:10:25 +020087 u32 width;
88 u32 height;
Hans de Goededd55d442017-07-06 16:06:01 +020089 bool disconnected;
90 } mode_hint;
91};
92
93struct vbox_crtc {
94 struct drm_crtc base;
Hans de Goededd55d442017-07-06 16:06:01 +020095 bool disconnected;
96 unsigned int crtc_id;
97 u32 fb_offset;
98 bool cursor_enabled;
Hans de Goedece10d7b2017-10-12 20:10:25 +020099 u32 x_hint;
100 u32 y_hint;
Hans de Goedee2f958d2018-09-29 14:18:14 +0200101 /*
102 * When setting a mode we not only pass the mode to the hypervisor,
103 * but also information on how to map / translate input coordinates
104 * for the emulated USB tablet. This input-mapping may change when
105 * the mode on *another* crtc changes.
106 *
107 * This means that sometimes we must do a modeset on other crtc-s then
108 * the one being changed to update the input-mapping. Including crtc-s
109 * which may be disabled inside the guest (shown as a black window
110 * on the host unless closed by the user).
111 *
112 * With atomic modesetting the mode-info of disabled crtcs gets zeroed
113 * yet we need it when updating the input-map to avoid resizing the
114 * window as a side effect of a mode_set on another crtc. Therefor we
115 * cache the info of the last mode below.
116 */
117 u32 width;
118 u32 height;
119 u32 x;
120 u32 y;
Hans de Goededd55d442017-07-06 16:06:01 +0200121};
122
123struct vbox_encoder {
124 struct drm_encoder base;
125};
126
Hans de Goededd55d442017-07-06 16:06:01 +0200127#define to_vbox_crtc(x) container_of(x, struct vbox_crtc, base)
128#define to_vbox_connector(x) container_of(x, struct vbox_connector, base)
129#define to_vbox_encoder(x) container_of(x, struct vbox_encoder, base)
Daniel Vetterdd9a6892020-04-15 09:39:39 +0200130#define to_vbox_dev(x) container_of(x, struct vbox_private, ddev)
Hans de Goededd55d442017-07-06 16:06:01 +0200131
Hans de Goeded4670902018-09-18 19:44:29 +0200132bool vbox_check_supported(u16 id);
133int vbox_hw_init(struct vbox_private *vbox);
134void vbox_hw_fini(struct vbox_private *vbox);
135
Hans de Goede01648892018-09-18 19:44:30 +0200136int vbox_mode_init(struct vbox_private *vbox);
137void vbox_mode_fini(struct vbox_private *vbox);
Hans de Goededd55d442017-07-06 16:06:01 +0200138
Hans de Goededd55d442017-07-06 16:06:01 +0200139void vbox_report_caps(struct vbox_private *vbox);
140
Hans de Goededd55d442017-07-06 16:06:01 +0200141int vbox_mm_init(struct vbox_private *vbox);
142void vbox_mm_fini(struct vbox_private *vbox);
143
Hans de Goededd55d442017-07-06 16:06:01 +0200144/* vbox_irq.c */
145int vbox_irq_init(struct vbox_private *vbox);
146void vbox_irq_fini(struct vbox_private *vbox);
147void vbox_report_hotplug(struct vbox_private *vbox);
Hans de Goededd55d442017-07-06 16:06:01 +0200148
149/* vbox_hgsmi.c */
150void *hgsmi_buffer_alloc(struct gen_pool *guest_pool, size_t size,
151 u8 channel, u16 channel_info);
152void hgsmi_buffer_free(struct gen_pool *guest_pool, void *buf);
153int hgsmi_buffer_submit(struct gen_pool *guest_pool, void *buf);
154
155static inline void vbox_write_ioport(u16 index, u16 data)
156{
157 outw(index, VBE_DISPI_IOPORT_INDEX);
158 outw(data, VBE_DISPI_IOPORT_DATA);
159}
160
161#endif