1
2
3
4
5
6
7
8
9
10#ifndef __VBOX_DRV_H__
11#define __VBOX_DRV_H__
12
13#include <linux/genalloc.h>
14#include <linux/io.h>
15#include <linux/irqreturn.h>
16#include <linux/string.h>
17#include <linux/version.h>
18
19#include <drm/drm_encoder.h>
20#include <drm/drm_fb_helper.h>
21#include <drm/drm_gem.h>
22
23#include <drm/ttm/ttm_bo_api.h>
24#include <drm/ttm/ttm_bo_driver.h>
25#include <drm/ttm/ttm_placement.h>
26#include <drm/ttm/ttm_memory.h>
27#include <drm/ttm/ttm_module.h>
28
29#include "vboxvideo_guest.h"
30#include "vboxvideo_vbe.h"
31#include "hgsmi_ch_setup.h"
32
33#define DRIVER_NAME "vboxvideo"
34#define DRIVER_DESC "Oracle VM VirtualBox Graphics Card"
35#define DRIVER_DATE "20130823"
36
37#define DRIVER_MAJOR 1
38#define DRIVER_MINOR 0
39#define DRIVER_PATCHLEVEL 0
40
41#define VBOX_MAX_CURSOR_WIDTH 64
42#define VBOX_MAX_CURSOR_HEIGHT 64
43#define CURSOR_PIXEL_COUNT (VBOX_MAX_CURSOR_WIDTH * VBOX_MAX_CURSOR_HEIGHT)
44#define CURSOR_DATA_SIZE (CURSOR_PIXEL_COUNT * 4 + CURSOR_PIXEL_COUNT / 8)
45
46#define VBOX_MAX_SCREENS 32
47
48#define GUEST_HEAP_OFFSET(vbox) ((vbox)->full_vram_size - \
49 VBVA_ADAPTER_INFORMATION_SIZE)
50#define GUEST_HEAP_SIZE VBVA_ADAPTER_INFORMATION_SIZE
51#define GUEST_HEAP_USABLE_SIZE (VBVA_ADAPTER_INFORMATION_SIZE - \
52 sizeof(struct hgsmi_host_flags))
53#define HOST_FLAGS_OFFSET GUEST_HEAP_USABLE_SIZE
54
55struct vbox_framebuffer {
56 struct drm_framebuffer base;
57 struct drm_gem_object *obj;
58};
59
60struct vbox_private {
61
62 struct drm_device ddev;
63 struct drm_fb_helper fb_helper;
64 struct vbox_framebuffer afb;
65
66 u8 __iomem *guest_heap;
67 u8 __iomem *vbva_buffers;
68 struct gen_pool *guest_pool;
69 struct vbva_buf_ctx *vbva_info;
70 bool any_pitch;
71 u32 num_crtcs;
72
73 u32 full_vram_size;
74
75 u32 available_vram_size;
76
77 struct vbva_modehint *last_mode_hints;
78
79 int fb_mtrr;
80
81 struct {
82 struct ttm_bo_device bdev;
83 } ttm;
84
85 struct mutex hw_mutex;
86
87
88
89
90
91 bool initial_mode_queried;
92 struct work_struct hotplug_work;
93 u32 input_mapping_width;
94 u32 input_mapping_height;
95
96
97
98
99 bool single_framebuffer;
100 u8 cursor_data[CURSOR_DATA_SIZE];
101};
102
103#undef CURSOR_PIXEL_COUNT
104#undef CURSOR_DATA_SIZE
105
106struct vbox_gem_object;
107
108struct vbox_connector {
109 struct drm_connector base;
110 char name[32];
111 struct vbox_crtc *vbox_crtc;
112 struct {
113 u32 width;
114 u32 height;
115 bool disconnected;
116 } mode_hint;
117};
118
119struct vbox_crtc {
120 struct drm_crtc base;
121 bool disconnected;
122 unsigned int crtc_id;
123 u32 fb_offset;
124 bool cursor_enabled;
125 u32 x_hint;
126 u32 y_hint;
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143 u32 width;
144 u32 height;
145 u32 x;
146 u32 y;
147};
148
149struct vbox_encoder {
150 struct drm_encoder base;
151};
152
153#define to_vbox_crtc(x) container_of(x, struct vbox_crtc, base)
154#define to_vbox_connector(x) container_of(x, struct vbox_connector, base)
155#define to_vbox_encoder(x) container_of(x, struct vbox_encoder, base)
156#define to_vbox_framebuffer(x) container_of(x, struct vbox_framebuffer, base)
157
158bool vbox_check_supported(u16 id);
159int vbox_hw_init(struct vbox_private *vbox);
160void vbox_hw_fini(struct vbox_private *vbox);
161
162int vbox_mode_init(struct vbox_private *vbox);
163void vbox_mode_fini(struct vbox_private *vbox);
164
165void vbox_report_caps(struct vbox_private *vbox);
166
167void vbox_framebuffer_dirty_rectangles(struct drm_framebuffer *fb,
168 struct drm_clip_rect *rects,
169 unsigned int num_rects);
170
171int vbox_framebuffer_init(struct vbox_private *vbox,
172 struct vbox_framebuffer *vbox_fb,
173 const struct drm_mode_fb_cmd2 *mode_cmd,
174 struct drm_gem_object *obj);
175
176int vboxfb_create(struct drm_fb_helper *helper,
177 struct drm_fb_helper_surface_size *sizes);
178void vbox_fbdev_fini(struct vbox_private *vbox);
179
180struct vbox_bo {
181 struct ttm_buffer_object bo;
182 struct ttm_placement placement;
183 struct ttm_bo_kmap_obj kmap;
184 struct drm_gem_object gem;
185 struct ttm_place placements[3];
186 int pin_count;
187};
188
189#define gem_to_vbox_bo(gobj) container_of((gobj), struct vbox_bo, gem)
190
191static inline struct vbox_bo *vbox_bo(struct ttm_buffer_object *bo)
192{
193 return container_of(bo, struct vbox_bo, bo);
194}
195
196#define to_vbox_obj(x) container_of(x, struct vbox_gem_object, base)
197
198static inline u64 vbox_bo_gpu_offset(struct vbox_bo *bo)
199{
200 return bo->bo.offset;
201}
202
203int vbox_dumb_create(struct drm_file *file,
204 struct drm_device *dev,
205 struct drm_mode_create_dumb *args);
206
207void vbox_gem_free_object(struct drm_gem_object *obj);
208int vbox_dumb_mmap_offset(struct drm_file *file,
209 struct drm_device *dev,
210 u32 handle, u64 *offset);
211
212#define DRM_FILE_PAGE_OFFSET (0x10000000ULL >> PAGE_SHIFT)
213
214int vbox_mm_init(struct vbox_private *vbox);
215void vbox_mm_fini(struct vbox_private *vbox);
216
217int vbox_bo_create(struct vbox_private *vbox, int size, int align,
218 u32 flags, struct vbox_bo **pvboxbo);
219
220int vbox_gem_create(struct vbox_private *vbox,
221 u32 size, bool iskernel, struct drm_gem_object **obj);
222
223int vbox_bo_pin(struct vbox_bo *bo, u32 pl_flag);
224int vbox_bo_unpin(struct vbox_bo *bo);
225
226static inline int vbox_bo_reserve(struct vbox_bo *bo, bool no_wait)
227{
228 int ret;
229
230 ret = ttm_bo_reserve(&bo->bo, true, no_wait, NULL);
231 if (ret) {
232 if (ret != -ERESTARTSYS && ret != -EBUSY)
233 DRM_ERROR("reserve failed %p\n", bo);
234 return ret;
235 }
236 return 0;
237}
238
239static inline void vbox_bo_unreserve(struct vbox_bo *bo)
240{
241 ttm_bo_unreserve(&bo->bo);
242}
243
244void vbox_ttm_placement(struct vbox_bo *bo, int domain);
245int vbox_bo_push_sysram(struct vbox_bo *bo);
246int vbox_mmap(struct file *filp, struct vm_area_struct *vma);
247void *vbox_bo_kmap(struct vbox_bo *bo);
248void vbox_bo_kunmap(struct vbox_bo *bo);
249
250
251int vbox_gem_prime_pin(struct drm_gem_object *obj);
252void vbox_gem_prime_unpin(struct drm_gem_object *obj);
253struct sg_table *vbox_gem_prime_get_sg_table(struct drm_gem_object *obj);
254struct drm_gem_object *vbox_gem_prime_import_sg_table(
255 struct drm_device *dev, struct dma_buf_attachment *attach,
256 struct sg_table *table);
257void *vbox_gem_prime_vmap(struct drm_gem_object *obj);
258void vbox_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr);
259int vbox_gem_prime_mmap(struct drm_gem_object *obj,
260 struct vm_area_struct *area);
261
262
263int vbox_irq_init(struct vbox_private *vbox);
264void vbox_irq_fini(struct vbox_private *vbox);
265void vbox_report_hotplug(struct vbox_private *vbox);
266irqreturn_t vbox_irq_handler(int irq, void *arg);
267
268
269void *hgsmi_buffer_alloc(struct gen_pool *guest_pool, size_t size,
270 u8 channel, u16 channel_info);
271void hgsmi_buffer_free(struct gen_pool *guest_pool, void *buf);
272int hgsmi_buffer_submit(struct gen_pool *guest_pool, void *buf);
273
274static inline void vbox_write_ioport(u16 index, u16 data)
275{
276 outw(index, VBE_DISPI_IOPORT_INDEX);
277 outw(data, VBE_DISPI_IOPORT_DATA);
278}
279
280#endif
281