]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - drivers/staging/vboxvideo/vbox_drv.h
Merge tag 'for-linus-20170825' of git://git.infradead.org/linux-mtd
[mirror_ubuntu-artful-kernel.git] / drivers / staging / vboxvideo / vbox_drv.h
1 /*
2 * Copyright (C) 2013-2017 Oracle Corporation
3 * This file is based on ast_drv.h
4 * Copyright 2012 Red Hat Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
18 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 * USE OR OTHER DEALINGS IN THE SOFTWARE.
21 *
22 * The above copyright notice and this permission notice (including the
23 * next paragraph) shall be included in all copies or substantial portions
24 * of the Software.
25 *
26 * Authors: Dave Airlie <airlied@redhat.com>
27 * Michael Thayer <michael.thayer@oracle.com,
28 * Hans de Goede <hdegoede@redhat.com>
29 */
30 #ifndef __VBOX_DRV_H__
31 #define __VBOX_DRV_H__
32
33 #include <linux/genalloc.h>
34 #include <linux/io.h>
35 #include <linux/string.h>
36 #include <linux/version.h>
37
38 #include <drm/drmP.h>
39 #include <drm/drm_encoder.h>
40 #include <drm/drm_fb_helper.h>
41 #include <drm/drm_gem.h>
42
43 #include <drm/ttm/ttm_bo_api.h>
44 #include <drm/ttm/ttm_bo_driver.h>
45 #include <drm/ttm/ttm_placement.h>
46 #include <drm/ttm/ttm_memory.h>
47 #include <drm/ttm/ttm_module.h>
48
49 #include "vboxvideo_guest.h"
50 #include "vboxvideo_vbe.h"
51 #include "hgsmi_ch_setup.h"
52
53 #define DRIVER_NAME "vboxvideo"
54 #define DRIVER_DESC "Oracle VM VirtualBox Graphics Card"
55 #define DRIVER_DATE "20130823"
56
57 #define DRIVER_MAJOR 1
58 #define DRIVER_MINOR 0
59 #define DRIVER_PATCHLEVEL 0
60
61 #define VBOX_MAX_CURSOR_WIDTH 64
62 #define VBOX_MAX_CURSOR_HEIGHT 64
63 #define CURSOR_PIXEL_COUNT (VBOX_MAX_CURSOR_WIDTH * VBOX_MAX_CURSOR_HEIGHT)
64 #define CURSOR_DATA_SIZE (CURSOR_PIXEL_COUNT * 4 + CURSOR_PIXEL_COUNT / 8)
65
66 #define VBOX_MAX_SCREENS 32
67
68 #define GUEST_HEAP_OFFSET(vbox) ((vbox)->full_vram_size - \
69 VBVA_ADAPTER_INFORMATION_SIZE)
70 #define GUEST_HEAP_SIZE VBVA_ADAPTER_INFORMATION_SIZE
71 #define GUEST_HEAP_USABLE_SIZE (VBVA_ADAPTER_INFORMATION_SIZE - \
72 sizeof(struct hgsmi_host_flags))
73 #define HOST_FLAGS_OFFSET GUEST_HEAP_USABLE_SIZE
74
75 struct vbox_fbdev;
76
77 struct vbox_private {
78 struct drm_device *dev;
79
80 u8 __iomem *guest_heap;
81 u8 __iomem *vbva_buffers;
82 struct gen_pool *guest_pool;
83 struct vbva_buf_ctx *vbva_info;
84 bool any_pitch;
85 u32 num_crtcs;
86 /** Amount of available VRAM, including space used for buffers. */
87 u32 full_vram_size;
88 /** Amount of available VRAM, not including space used for buffers. */
89 u32 available_vram_size;
90 /** Array of structures for receiving mode hints. */
91 struct vbva_modehint *last_mode_hints;
92
93 struct vbox_fbdev *fbdev;
94
95 int fb_mtrr;
96
97 struct {
98 struct drm_global_reference mem_global_ref;
99 struct ttm_bo_global_ref bo_global_ref;
100 struct ttm_bo_device bdev;
101 } ttm;
102
103 struct mutex hw_mutex; /* protects modeset and accel/vbva accesses */
104 /**
105 * We decide whether or not user-space supports display hot-plug
106 * depending on whether they react to a hot-plug event after the initial
107 * mode query.
108 */
109 bool initial_mode_queried;
110 struct work_struct hotplug_work;
111 u32 input_mapping_width;
112 u32 input_mapping_height;
113 /**
114 * Is user-space using an X.Org-style layout of one large frame-buffer
115 * encompassing all screen ones or is the fbdev console active?
116 */
117 bool single_framebuffer;
118 u32 cursor_width;
119 u32 cursor_height;
120 u32 cursor_hot_x;
121 u32 cursor_hot_y;
122 size_t cursor_data_size;
123 u8 cursor_data[CURSOR_DATA_SIZE];
124 };
125
126 #undef CURSOR_PIXEL_COUNT
127 #undef CURSOR_DATA_SIZE
128
129 int vbox_driver_load(struct drm_device *dev, unsigned long flags);
130 void vbox_driver_unload(struct drm_device *dev);
131 void vbox_driver_lastclose(struct drm_device *dev);
132
133 struct vbox_gem_object;
134
135 struct vbox_connector {
136 struct drm_connector base;
137 char name[32];
138 struct vbox_crtc *vbox_crtc;
139 struct {
140 u16 width;
141 u16 height;
142 bool disconnected;
143 } mode_hint;
144 };
145
146 struct vbox_crtc {
147 struct drm_crtc base;
148 bool blanked;
149 bool disconnected;
150 unsigned int crtc_id;
151 u32 fb_offset;
152 bool cursor_enabled;
153 u16 x_hint;
154 u16 y_hint;
155 };
156
157 struct vbox_encoder {
158 struct drm_encoder base;
159 };
160
161 struct vbox_framebuffer {
162 struct drm_framebuffer base;
163 struct drm_gem_object *obj;
164 };
165
166 struct vbox_fbdev {
167 struct drm_fb_helper helper;
168 struct vbox_framebuffer afb;
169 int size;
170 struct ttm_bo_kmap_obj mapping;
171 int x1, y1, x2, y2; /* dirty rect */
172 spinlock_t dirty_lock;
173 };
174
175 #define to_vbox_crtc(x) container_of(x, struct vbox_crtc, base)
176 #define to_vbox_connector(x) container_of(x, struct vbox_connector, base)
177 #define to_vbox_encoder(x) container_of(x, struct vbox_encoder, base)
178 #define to_vbox_framebuffer(x) container_of(x, struct vbox_framebuffer, base)
179
180 int vbox_mode_init(struct drm_device *dev);
181 void vbox_mode_fini(struct drm_device *dev);
182
183 #define DRM_MODE_FB_CMD drm_mode_fb_cmd2
184 #define CRTC_FB(crtc) ((crtc)->primary->fb)
185
186 void vbox_enable_accel(struct vbox_private *vbox);
187 void vbox_disable_accel(struct vbox_private *vbox);
188 void vbox_report_caps(struct vbox_private *vbox);
189
190 void vbox_framebuffer_dirty_rectangles(struct drm_framebuffer *fb,
191 struct drm_clip_rect *rects,
192 unsigned int num_rects);
193
194 int vbox_framebuffer_init(struct drm_device *dev,
195 struct vbox_framebuffer *vbox_fb,
196 const struct DRM_MODE_FB_CMD *mode_cmd,
197 struct drm_gem_object *obj);
198
199 int vbox_fbdev_init(struct drm_device *dev);
200 void vbox_fbdev_fini(struct drm_device *dev);
201 void vbox_fbdev_set_base(struct vbox_private *vbox, unsigned long gpu_addr);
202
203 struct vbox_bo {
204 struct ttm_buffer_object bo;
205 struct ttm_placement placement;
206 struct ttm_bo_kmap_obj kmap;
207 struct drm_gem_object gem;
208 struct ttm_place placements[3];
209 int pin_count;
210 };
211
212 #define gem_to_vbox_bo(gobj) container_of((gobj), struct vbox_bo, gem)
213
214 static inline struct vbox_bo *vbox_bo(struct ttm_buffer_object *bo)
215 {
216 return container_of(bo, struct vbox_bo, bo);
217 }
218
219 #define to_vbox_obj(x) container_of(x, struct vbox_gem_object, base)
220
221 int vbox_dumb_create(struct drm_file *file,
222 struct drm_device *dev,
223 struct drm_mode_create_dumb *args);
224
225 void vbox_gem_free_object(struct drm_gem_object *obj);
226 int vbox_dumb_mmap_offset(struct drm_file *file,
227 struct drm_device *dev,
228 u32 handle, u64 *offset);
229
230 #define DRM_FILE_PAGE_OFFSET (0x10000000ULL >> PAGE_SHIFT)
231
232 int vbox_mm_init(struct vbox_private *vbox);
233 void vbox_mm_fini(struct vbox_private *vbox);
234
235 int vbox_bo_create(struct drm_device *dev, int size, int align,
236 u32 flags, struct vbox_bo **pvboxbo);
237
238 int vbox_gem_create(struct drm_device *dev,
239 u32 size, bool iskernel, struct drm_gem_object **obj);
240
241 int vbox_bo_pin(struct vbox_bo *bo, u32 pl_flag, u64 *gpu_addr);
242 int vbox_bo_unpin(struct vbox_bo *bo);
243
244 static inline int vbox_bo_reserve(struct vbox_bo *bo, bool no_wait)
245 {
246 int ret;
247
248 ret = ttm_bo_reserve(&bo->bo, true, no_wait, NULL);
249 if (ret) {
250 if (ret != -ERESTARTSYS && ret != -EBUSY)
251 DRM_ERROR("reserve failed %p\n", bo);
252 return ret;
253 }
254 return 0;
255 }
256
257 static inline void vbox_bo_unreserve(struct vbox_bo *bo)
258 {
259 ttm_bo_unreserve(&bo->bo);
260 }
261
262 void vbox_ttm_placement(struct vbox_bo *bo, int domain);
263 int vbox_bo_push_sysram(struct vbox_bo *bo);
264 int vbox_mmap(struct file *filp, struct vm_area_struct *vma);
265
266 /* vbox_prime.c */
267 int vbox_gem_prime_pin(struct drm_gem_object *obj);
268 void vbox_gem_prime_unpin(struct drm_gem_object *obj);
269 struct sg_table *vbox_gem_prime_get_sg_table(struct drm_gem_object *obj);
270 struct drm_gem_object *vbox_gem_prime_import_sg_table(
271 struct drm_device *dev, struct dma_buf_attachment *attach,
272 struct sg_table *table);
273 void *vbox_gem_prime_vmap(struct drm_gem_object *obj);
274 void vbox_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr);
275 int vbox_gem_prime_mmap(struct drm_gem_object *obj,
276 struct vm_area_struct *area);
277
278 /* vbox_irq.c */
279 int vbox_irq_init(struct vbox_private *vbox);
280 void vbox_irq_fini(struct vbox_private *vbox);
281 void vbox_report_hotplug(struct vbox_private *vbox);
282 irqreturn_t vbox_irq_handler(int irq, void *arg);
283
284 /* vbox_hgsmi.c */
285 void *hgsmi_buffer_alloc(struct gen_pool *guest_pool, size_t size,
286 u8 channel, u16 channel_info);
287 void hgsmi_buffer_free(struct gen_pool *guest_pool, void *buf);
288 int hgsmi_buffer_submit(struct gen_pool *guest_pool, void *buf);
289
290 static inline void vbox_write_ioport(u16 index, u16 data)
291 {
292 outw(index, VBE_DISPI_IOPORT_INDEX);
293 outw(data, VBE_DISPI_IOPORT_DATA);
294 }
295
296 #endif