Commit | Line | Data |
---|---|---|
fb1d9738 JB |
1 | /************************************************************************** |
2 | * | |
3 | * Copyright © 2009 VMware, Inc., Palo Alto, CA., USA | |
4 | * All Rights Reserved. | |
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 above copyright notice and this permission notice (including the | |
15 | * next paragraph) shall be included in all copies or substantial portions | |
16 | * of the Software. | |
17 | * | |
18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
20 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL | |
21 | * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, | |
22 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | |
23 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE | |
24 | * USE OR OTHER DEALINGS IN THE SOFTWARE. | |
25 | * | |
26 | **************************************************************************/ | |
27 | ||
28 | #ifndef _VMWGFX_DRV_H_ | |
29 | #define _VMWGFX_DRV_H_ | |
30 | ||
31 | #include "vmwgfx_reg.h" | |
32 | #include "drmP.h" | |
33 | #include "vmwgfx_drm.h" | |
34 | #include "drm_hashtab.h" | |
d9f36a00 | 35 | #include "linux/suspend.h" |
fb1d9738 JB |
36 | #include "ttm/ttm_bo_driver.h" |
37 | #include "ttm/ttm_object.h" | |
38 | #include "ttm/ttm_lock.h" | |
39 | #include "ttm/ttm_execbuf_util.h" | |
40 | #include "ttm/ttm_module.h" | |
41 | ||
a87897ed JB |
42 | #define VMWGFX_DRIVER_DATE "20100209" |
43 | #define VMWGFX_DRIVER_MAJOR 1 | |
44 | #define VMWGFX_DRIVER_MINOR 0 | |
f77cef3d | 45 | #define VMWGFX_DRIVER_PATCHLEVEL 0 |
fb1d9738 JB |
46 | #define VMWGFX_FILE_PAGE_OFFSET 0x00100000 |
47 | #define VMWGFX_FIFO_STATIC_SIZE (1024*1024) | |
48 | #define VMWGFX_MAX_RELOCATIONS 2048 | |
49 | #define VMWGFX_MAX_GMRS 2048 | |
50 | ||
51 | struct vmw_fpriv { | |
52 | struct drm_master *locked_master; | |
53 | struct ttm_object_file *tfile; | |
54 | }; | |
55 | ||
56 | struct vmw_dma_buffer { | |
57 | struct ttm_buffer_object base; | |
58 | struct list_head validate_list; | |
59 | struct list_head gmr_lru; | |
60 | uint32_t gmr_id; | |
61 | bool gmr_bound; | |
62 | uint32_t cur_validate_node; | |
63 | bool on_validate_list; | |
64 | }; | |
65 | ||
66 | struct vmw_resource { | |
67 | struct kref kref; | |
68 | struct vmw_private *dev_priv; | |
69 | struct idr *idr; | |
70 | int id; | |
71 | enum ttm_object_type res_type; | |
72 | bool avail; | |
73 | void (*hw_destroy) (struct vmw_resource *res); | |
74 | void (*res_free) (struct vmw_resource *res); | |
75 | ||
76 | /* TODO is a generic snooper needed? */ | |
77 | #if 0 | |
78 | void (*snoop)(struct vmw_resource *res, | |
79 | struct ttm_object_file *tfile, | |
80 | SVGA3dCmdHeader *header); | |
81 | void *snoop_priv; | |
82 | #endif | |
83 | }; | |
84 | ||
85 | struct vmw_cursor_snooper { | |
86 | struct drm_crtc *crtc; | |
87 | size_t age; | |
88 | uint32_t *image; | |
89 | }; | |
90 | ||
91 | struct vmw_surface { | |
92 | struct vmw_resource res; | |
93 | uint32_t flags; | |
94 | uint32_t format; | |
95 | uint32_t mip_levels[DRM_VMW_MAX_SURFACE_FACES]; | |
96 | struct drm_vmw_size *sizes; | |
97 | uint32_t num_sizes; | |
98 | ||
5ffdb658 JB |
99 | bool scanout; |
100 | ||
fb1d9738 JB |
101 | /* TODO so far just a extra pointer */ |
102 | struct vmw_cursor_snooper snooper; | |
103 | }; | |
104 | ||
105 | struct vmw_fifo_state { | |
106 | unsigned long reserved_size; | |
107 | __le32 *dynamic_buffer; | |
108 | __le32 *static_buffer; | |
109 | __le32 *last_buffer; | |
110 | uint32_t last_data_size; | |
111 | uint32_t last_buffer_size; | |
112 | bool last_buffer_add; | |
113 | unsigned long static_buffer_size; | |
114 | bool using_bounce_buffer; | |
115 | uint32_t capabilities; | |
85b9e487 | 116 | struct mutex fifo_mutex; |
fb1d9738 JB |
117 | struct rw_semaphore rwsem; |
118 | }; | |
119 | ||
120 | struct vmw_relocation { | |
121 | SVGAGuestPtr *location; | |
122 | uint32_t index; | |
123 | }; | |
124 | ||
125 | struct vmw_sw_context{ | |
126 | struct ida bo_list; | |
127 | uint32_t last_cid; | |
128 | bool cid_valid; | |
129 | uint32_t last_sid; | |
7a73ba74 | 130 | uint32_t sid_translation; |
fb1d9738 JB |
131 | bool sid_valid; |
132 | struct ttm_object_file *tfile; | |
133 | struct list_head validate_nodes; | |
134 | struct vmw_relocation relocs[VMWGFX_MAX_RELOCATIONS]; | |
135 | uint32_t cur_reloc; | |
136 | struct ttm_validate_buffer val_bufs[VMWGFX_MAX_GMRS]; | |
137 | uint32_t cur_val_buf; | |
138 | }; | |
139 | ||
140 | struct vmw_legacy_display; | |
141 | struct vmw_overlay; | |
142 | ||
143 | struct vmw_master { | |
144 | struct ttm_lock lock; | |
145 | }; | |
146 | ||
147 | struct vmw_private { | |
148 | struct ttm_bo_device bdev; | |
149 | struct ttm_bo_global_ref bo_global_ref; | |
150 | struct ttm_global_reference mem_global_ref; | |
151 | ||
152 | struct vmw_fifo_state fifo; | |
153 | ||
154 | struct drm_device *dev; | |
155 | unsigned long vmw_chipset; | |
156 | unsigned int io_start; | |
157 | uint32_t vram_start; | |
158 | uint32_t vram_size; | |
159 | uint32_t mmio_start; | |
160 | uint32_t mmio_size; | |
161 | uint32_t fb_max_width; | |
162 | uint32_t fb_max_height; | |
163 | __le32 __iomem *mmio_virt; | |
164 | int mmio_mtrr; | |
165 | uint32_t capabilities; | |
166 | uint32_t max_gmr_descriptors; | |
167 | uint32_t max_gmr_ids; | |
168 | struct mutex hw_mutex; | |
169 | ||
170 | /* | |
171 | * VGA registers. | |
172 | */ | |
173 | ||
174 | uint32_t vga_width; | |
175 | uint32_t vga_height; | |
176 | uint32_t vga_depth; | |
177 | uint32_t vga_bpp; | |
178 | uint32_t vga_pseudo; | |
179 | uint32_t vga_red_mask; | |
180 | uint32_t vga_blue_mask; | |
181 | uint32_t vga_green_mask; | |
182 | ||
183 | /* | |
184 | * Framebuffer info. | |
185 | */ | |
186 | ||
187 | void *fb_info; | |
188 | struct vmw_legacy_display *ldu_priv; | |
189 | struct vmw_overlay *overlay_priv; | |
190 | ||
191 | /* | |
192 | * Context and surface management. | |
193 | */ | |
194 | ||
195 | rwlock_t resource_lock; | |
196 | struct idr context_idr; | |
197 | struct idr surface_idr; | |
198 | struct idr stream_idr; | |
199 | ||
200 | /* | |
201 | * Block lastclose from racing with firstopen. | |
202 | */ | |
203 | ||
204 | struct mutex init_mutex; | |
205 | ||
206 | /* | |
207 | * A resource manager for kernel-only surfaces and | |
208 | * contexts. | |
209 | */ | |
210 | ||
211 | struct ttm_object_device *tdev; | |
212 | ||
213 | /* | |
214 | * Fencing and IRQs. | |
215 | */ | |
216 | ||
85b9e487 | 217 | atomic_t fence_seq; |
fb1d9738 JB |
218 | wait_queue_head_t fence_queue; |
219 | wait_queue_head_t fifo_queue; | |
220 | atomic_t fence_queue_waiters; | |
221 | atomic_t fifo_queue_waiters; | |
222 | uint32_t last_read_sequence; | |
223 | spinlock_t irq_lock; | |
224 | ||
225 | /* | |
226 | * Device state | |
227 | */ | |
228 | ||
229 | uint32_t traces_state; | |
230 | uint32_t enable_state; | |
231 | uint32_t config_done_state; | |
232 | ||
233 | /** | |
234 | * Execbuf | |
235 | */ | |
236 | /** | |
237 | * Protected by the cmdbuf mutex. | |
238 | */ | |
239 | ||
240 | struct vmw_sw_context ctx; | |
241 | uint32_t val_seq; | |
242 | struct mutex cmdbuf_mutex; | |
243 | ||
244 | /** | |
245 | * GMR management. Protected by the lru spinlock. | |
246 | */ | |
247 | ||
248 | struct ida gmr_ida; | |
249 | struct list_head gmr_lru; | |
250 | ||
251 | ||
252 | /** | |
253 | * Operating mode. | |
254 | */ | |
255 | ||
256 | bool stealth; | |
257 | bool is_opened; | |
258 | ||
259 | /** | |
260 | * Master management. | |
261 | */ | |
262 | ||
263 | struct vmw_master *active_master; | |
264 | struct vmw_master fbdev_master; | |
d9f36a00 | 265 | struct notifier_block pm_nb; |
fb1d9738 JB |
266 | }; |
267 | ||
268 | static inline struct vmw_private *vmw_priv(struct drm_device *dev) | |
269 | { | |
270 | return (struct vmw_private *)dev->dev_private; | |
271 | } | |
272 | ||
273 | static inline struct vmw_fpriv *vmw_fpriv(struct drm_file *file_priv) | |
274 | { | |
275 | return (struct vmw_fpriv *)file_priv->driver_priv; | |
276 | } | |
277 | ||
278 | static inline struct vmw_master *vmw_master(struct drm_master *master) | |
279 | { | |
280 | return (struct vmw_master *) master->driver_priv; | |
281 | } | |
282 | ||
283 | static inline void vmw_write(struct vmw_private *dev_priv, | |
284 | unsigned int offset, uint32_t value) | |
285 | { | |
286 | outl(offset, dev_priv->io_start + VMWGFX_INDEX_PORT); | |
287 | outl(value, dev_priv->io_start + VMWGFX_VALUE_PORT); | |
288 | } | |
289 | ||
290 | static inline uint32_t vmw_read(struct vmw_private *dev_priv, | |
291 | unsigned int offset) | |
292 | { | |
293 | uint32_t val; | |
294 | ||
295 | outl(offset, dev_priv->io_start + VMWGFX_INDEX_PORT); | |
296 | val = inl(dev_priv->io_start + VMWGFX_VALUE_PORT); | |
297 | return val; | |
298 | } | |
299 | ||
300 | /** | |
301 | * GMR utilities - vmwgfx_gmr.c | |
302 | */ | |
303 | ||
304 | extern int vmw_gmr_bind(struct vmw_private *dev_priv, | |
305 | struct ttm_buffer_object *bo); | |
306 | extern void vmw_gmr_unbind(struct vmw_private *dev_priv, int gmr_id); | |
307 | ||
308 | /** | |
309 | * Resource utilities - vmwgfx_resource.c | |
310 | */ | |
311 | ||
312 | extern struct vmw_resource *vmw_context_alloc(struct vmw_private *dev_priv); | |
313 | extern void vmw_resource_unreference(struct vmw_resource **p_res); | |
314 | extern struct vmw_resource *vmw_resource_reference(struct vmw_resource *res); | |
315 | extern int vmw_context_destroy_ioctl(struct drm_device *dev, void *data, | |
316 | struct drm_file *file_priv); | |
317 | extern int vmw_context_define_ioctl(struct drm_device *dev, void *data, | |
318 | struct drm_file *file_priv); | |
319 | extern int vmw_context_check(struct vmw_private *dev_priv, | |
320 | struct ttm_object_file *tfile, | |
321 | int id); | |
322 | extern void vmw_surface_res_free(struct vmw_resource *res); | |
323 | extern int vmw_surface_init(struct vmw_private *dev_priv, | |
324 | struct vmw_surface *srf, | |
325 | void (*res_free) (struct vmw_resource *res)); | |
7a73ba74 TH |
326 | extern int vmw_user_surface_lookup_handle(struct vmw_private *dev_priv, |
327 | struct ttm_object_file *tfile, | |
328 | uint32_t handle, | |
329 | struct vmw_surface **out); | |
fb1d9738 JB |
330 | extern int vmw_surface_destroy_ioctl(struct drm_device *dev, void *data, |
331 | struct drm_file *file_priv); | |
332 | extern int vmw_surface_define_ioctl(struct drm_device *dev, void *data, | |
333 | struct drm_file *file_priv); | |
334 | extern int vmw_surface_reference_ioctl(struct drm_device *dev, void *data, | |
335 | struct drm_file *file_priv); | |
336 | extern int vmw_surface_check(struct vmw_private *dev_priv, | |
337 | struct ttm_object_file *tfile, | |
7a73ba74 | 338 | uint32_t handle, int *id); |
fb1d9738 JB |
339 | extern void vmw_dmabuf_bo_free(struct ttm_buffer_object *bo); |
340 | extern int vmw_dmabuf_init(struct vmw_private *dev_priv, | |
341 | struct vmw_dma_buffer *vmw_bo, | |
342 | size_t size, struct ttm_placement *placement, | |
343 | bool interuptable, | |
344 | void (*bo_free) (struct ttm_buffer_object *bo)); | |
345 | extern int vmw_dmabuf_alloc_ioctl(struct drm_device *dev, void *data, | |
346 | struct drm_file *file_priv); | |
347 | extern int vmw_dmabuf_unref_ioctl(struct drm_device *dev, void *data, | |
348 | struct drm_file *file_priv); | |
349 | extern uint32_t vmw_dmabuf_validate_node(struct ttm_buffer_object *bo, | |
350 | uint32_t cur_validate_node); | |
351 | extern void vmw_dmabuf_validate_clear(struct ttm_buffer_object *bo); | |
352 | extern int vmw_user_dmabuf_lookup(struct ttm_object_file *tfile, | |
353 | uint32_t id, struct vmw_dma_buffer **out); | |
354 | extern uint32_t vmw_dmabuf_gmr(struct ttm_buffer_object *bo); | |
355 | extern void vmw_dmabuf_set_gmr(struct ttm_buffer_object *bo, uint32_t id); | |
356 | extern int vmw_gmr_id_alloc(struct vmw_private *dev_priv, uint32_t *p_id); | |
357 | extern int vmw_dmabuf_to_start_of_vram(struct vmw_private *vmw_priv, | |
358 | struct vmw_dma_buffer *bo); | |
359 | extern int vmw_dmabuf_from_vram(struct vmw_private *vmw_priv, | |
360 | struct vmw_dma_buffer *bo); | |
effe1105 | 361 | extern void vmw_dmabuf_gmr_unbind(struct ttm_buffer_object *bo); |
fb1d9738 JB |
362 | extern int vmw_stream_claim_ioctl(struct drm_device *dev, void *data, |
363 | struct drm_file *file_priv); | |
364 | extern int vmw_stream_unref_ioctl(struct drm_device *dev, void *data, | |
365 | struct drm_file *file_priv); | |
366 | extern int vmw_user_stream_lookup(struct vmw_private *dev_priv, | |
367 | struct ttm_object_file *tfile, | |
368 | uint32_t *inout_id, | |
369 | struct vmw_resource **out); | |
370 | ||
371 | ||
372 | /** | |
373 | * Misc Ioctl functionality - vmwgfx_ioctl.c | |
374 | */ | |
375 | ||
376 | extern int vmw_getparam_ioctl(struct drm_device *dev, void *data, | |
377 | struct drm_file *file_priv); | |
378 | extern int vmw_fifo_debug_ioctl(struct drm_device *dev, void *data, | |
379 | struct drm_file *file_priv); | |
380 | ||
381 | /** | |
382 | * Fifo utilities - vmwgfx_fifo.c | |
383 | */ | |
384 | ||
385 | extern int vmw_fifo_init(struct vmw_private *dev_priv, | |
386 | struct vmw_fifo_state *fifo); | |
387 | extern void vmw_fifo_release(struct vmw_private *dev_priv, | |
388 | struct vmw_fifo_state *fifo); | |
389 | extern void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes); | |
390 | extern void vmw_fifo_commit(struct vmw_private *dev_priv, uint32_t bytes); | |
391 | extern int vmw_fifo_send_fence(struct vmw_private *dev_priv, | |
392 | uint32_t *sequence); | |
393 | extern void vmw_fifo_ping_host(struct vmw_private *dev_priv, uint32_t reason); | |
394 | extern int vmw_fifo_mmap(struct file *filp, struct vm_area_struct *vma); | |
8e19a951 | 395 | extern bool vmw_fifo_have_3d(struct vmw_private *dev_priv); |
fb1d9738 JB |
396 | |
397 | /** | |
398 | * TTM glue - vmwgfx_ttm_glue.c | |
399 | */ | |
400 | ||
401 | extern int vmw_ttm_global_init(struct vmw_private *dev_priv); | |
402 | extern void vmw_ttm_global_release(struct vmw_private *dev_priv); | |
403 | extern int vmw_mmap(struct file *filp, struct vm_area_struct *vma); | |
404 | ||
405 | /** | |
406 | * TTM buffer object driver - vmwgfx_buffer.c | |
407 | */ | |
408 | ||
409 | extern struct ttm_placement vmw_vram_placement; | |
410 | extern struct ttm_placement vmw_vram_ne_placement; | |
8ba5152a | 411 | extern struct ttm_placement vmw_vram_sys_placement; |
fb1d9738 JB |
412 | extern struct ttm_placement vmw_sys_placement; |
413 | extern struct ttm_bo_driver vmw_bo_driver; | |
414 | extern int vmw_dma_quiescent(struct drm_device *dev); | |
415 | ||
416 | /** | |
417 | * Command submission - vmwgfx_execbuf.c | |
418 | */ | |
419 | ||
420 | extern int vmw_execbuf_ioctl(struct drm_device *dev, void *data, | |
421 | struct drm_file *file_priv); | |
422 | ||
423 | /** | |
424 | * IRQs and wating - vmwgfx_irq.c | |
425 | */ | |
426 | ||
427 | extern irqreturn_t vmw_irq_handler(DRM_IRQ_ARGS); | |
428 | extern int vmw_wait_fence(struct vmw_private *dev_priv, bool lazy, | |
429 | uint32_t sequence, bool interruptible, | |
430 | unsigned long timeout); | |
431 | extern void vmw_irq_preinstall(struct drm_device *dev); | |
432 | extern int vmw_irq_postinstall(struct drm_device *dev); | |
433 | extern void vmw_irq_uninstall(struct drm_device *dev); | |
434 | extern bool vmw_fence_signaled(struct vmw_private *dev_priv, | |
435 | uint32_t sequence); | |
436 | extern int vmw_fence_wait_ioctl(struct drm_device *dev, void *data, | |
437 | struct drm_file *file_priv); | |
438 | extern int vmw_fallback_wait(struct vmw_private *dev_priv, | |
439 | bool lazy, | |
440 | bool fifo_idle, | |
441 | uint32_t sequence, | |
442 | bool interruptible, | |
443 | unsigned long timeout); | |
444 | ||
445 | /** | |
446 | * Kernel framebuffer - vmwgfx_fb.c | |
447 | */ | |
448 | ||
449 | int vmw_fb_init(struct vmw_private *vmw_priv); | |
450 | int vmw_fb_close(struct vmw_private *dev_priv); | |
451 | int vmw_fb_off(struct vmw_private *vmw_priv); | |
452 | int vmw_fb_on(struct vmw_private *vmw_priv); | |
453 | ||
454 | /** | |
455 | * Kernel modesetting - vmwgfx_kms.c | |
456 | */ | |
457 | ||
458 | int vmw_kms_init(struct vmw_private *dev_priv); | |
459 | int vmw_kms_close(struct vmw_private *dev_priv); | |
460 | int vmw_kms_save_vga(struct vmw_private *vmw_priv); | |
461 | int vmw_kms_restore_vga(struct vmw_private *vmw_priv); | |
462 | int vmw_kms_cursor_bypass_ioctl(struct drm_device *dev, void *data, | |
463 | struct drm_file *file_priv); | |
464 | void vmw_kms_cursor_post_execbuf(struct vmw_private *dev_priv); | |
465 | void vmw_kms_cursor_snoop(struct vmw_surface *srf, | |
466 | struct ttm_object_file *tfile, | |
467 | struct ttm_buffer_object *bo, | |
468 | SVGA3dCmdHeader *header); | |
469 | ||
470 | /** | |
471 | * Overlay control - vmwgfx_overlay.c | |
472 | */ | |
473 | ||
474 | int vmw_overlay_init(struct vmw_private *dev_priv); | |
475 | int vmw_overlay_close(struct vmw_private *dev_priv); | |
476 | int vmw_overlay_ioctl(struct drm_device *dev, void *data, | |
477 | struct drm_file *file_priv); | |
478 | int vmw_overlay_stop_all(struct vmw_private *dev_priv); | |
479 | int vmw_overlay_resume_all(struct vmw_private *dev_priv); | |
480 | int vmw_overlay_pause_all(struct vmw_private *dev_priv); | |
481 | int vmw_overlay_claim(struct vmw_private *dev_priv, uint32_t *out); | |
482 | int vmw_overlay_unref(struct vmw_private *dev_priv, uint32_t stream_id); | |
483 | int vmw_overlay_num_overlays(struct vmw_private *dev_priv); | |
484 | int vmw_overlay_num_free_overlays(struct vmw_private *dev_priv); | |
485 | ||
486 | /** | |
487 | * Inline helper functions | |
488 | */ | |
489 | ||
490 | static inline void vmw_surface_unreference(struct vmw_surface **srf) | |
491 | { | |
492 | struct vmw_surface *tmp_srf = *srf; | |
493 | struct vmw_resource *res = &tmp_srf->res; | |
494 | *srf = NULL; | |
495 | ||
496 | vmw_resource_unreference(&res); | |
497 | } | |
498 | ||
499 | static inline struct vmw_surface *vmw_surface_reference(struct vmw_surface *srf) | |
500 | { | |
501 | (void) vmw_resource_reference(&srf->res); | |
502 | return srf; | |
503 | } | |
504 | ||
505 | static inline void vmw_dmabuf_unreference(struct vmw_dma_buffer **buf) | |
506 | { | |
507 | struct vmw_dma_buffer *tmp_buf = *buf; | |
508 | struct ttm_buffer_object *bo = &tmp_buf->base; | |
509 | *buf = NULL; | |
510 | ||
511 | ttm_bo_unref(&bo); | |
512 | } | |
513 | ||
514 | static inline struct vmw_dma_buffer *vmw_dmabuf_reference(struct vmw_dma_buffer *buf) | |
515 | { | |
516 | if (ttm_bo_reference(&buf->base)) | |
517 | return buf; | |
518 | return NULL; | |
519 | } | |
520 | ||
521 | #endif |