1 /**************************************************************************
3 * Copyright © 2009 VMware, Inc., Palo Alto, CA., USA
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
28 #ifndef _VMWGFX_DRV_H_
29 #define _VMWGFX_DRV_H_
31 #include "vmwgfx_reg.h"
33 #include "vmwgfx_drm.h"
34 #include "drm_hashtab.h"
35 #include "linux/suspend.h"
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"
42 #define VMWGFX_DRIVER_DATE "20100209"
43 #define VMWGFX_DRIVER_MAJOR 1
44 #define VMWGFX_DRIVER_MINOR 1
45 #define VMWGFX_DRIVER_PATCHLEVEL 0
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
52 struct drm_master *locked_master;
53 struct ttm_object_file *tfile;
56 struct vmw_dma_buffer {
57 struct ttm_buffer_object base;
58 struct list_head validate_list;
59 struct list_head gmr_lru;
62 uint32_t cur_validate_node;
63 bool on_validate_list;
68 struct vmw_private *dev_priv;
71 enum ttm_object_type res_type;
73 void (*hw_destroy) (struct vmw_resource *res);
74 void (*res_free) (struct vmw_resource *res);
76 /* TODO is a generic snooper needed? */
78 void (*snoop)(struct vmw_resource *res,
79 struct ttm_object_file *tfile,
80 SVGA3dCmdHeader *header);
85 struct vmw_cursor_snooper {
86 struct drm_crtc *crtc;
92 struct vmw_resource res;
95 uint32_t mip_levels[DRM_VMW_MAX_SURFACE_FACES];
96 struct drm_vmw_size *sizes;
101 /* TODO so far just a extra pointer */
102 struct vmw_cursor_snooper snooper;
105 struct vmw_fence_queue {
106 struct list_head head;
108 struct timespec lag_time;
112 struct vmw_fifo_state {
113 unsigned long reserved_size;
114 __le32 *dynamic_buffer;
115 __le32 *static_buffer;
117 uint32_t last_data_size;
118 uint32_t last_buffer_size;
119 bool last_buffer_add;
120 unsigned long static_buffer_size;
121 bool using_bounce_buffer;
122 uint32_t capabilities;
123 struct mutex fifo_mutex;
124 struct rw_semaphore rwsem;
125 struct vmw_fence_queue fence_queue;
128 struct vmw_relocation {
129 SVGAGuestPtr *location;
133 struct vmw_sw_context{
138 uint32_t sid_translation;
140 struct ttm_object_file *tfile;
141 struct list_head validate_nodes;
142 struct vmw_relocation relocs[VMWGFX_MAX_RELOCATIONS];
144 struct ttm_validate_buffer val_bufs[VMWGFX_MAX_GMRS];
145 uint32_t cur_val_buf;
148 struct vmw_legacy_display;
152 struct ttm_lock lock;
156 struct ttm_bo_device bdev;
157 struct ttm_bo_global_ref bo_global_ref;
158 struct ttm_global_reference mem_global_ref;
160 struct vmw_fifo_state fifo;
162 struct drm_device *dev;
163 unsigned long vmw_chipset;
164 unsigned int io_start;
169 uint32_t fb_max_width;
170 uint32_t fb_max_height;
171 __le32 __iomem *mmio_virt;
173 uint32_t capabilities;
174 uint32_t max_gmr_descriptors;
175 uint32_t max_gmr_ids;
176 struct mutex hw_mutex;
187 uint32_t vga_red_mask;
188 uint32_t vga_blue_mask;
189 uint32_t vga_green_mask;
196 struct vmw_legacy_display *ldu_priv;
197 struct vmw_overlay *overlay_priv;
200 * Context and surface management.
203 rwlock_t resource_lock;
204 struct idr context_idr;
205 struct idr surface_idr;
206 struct idr stream_idr;
209 * Block lastclose from racing with firstopen.
212 struct mutex init_mutex;
215 * A resource manager for kernel-only surfaces and
219 struct ttm_object_device *tdev;
226 wait_queue_head_t fence_queue;
227 wait_queue_head_t fifo_queue;
228 atomic_t fence_queue_waiters;
229 atomic_t fifo_queue_waiters;
230 uint32_t last_read_sequence;
237 uint32_t traces_state;
238 uint32_t enable_state;
239 uint32_t config_done_state;
245 * Protected by the cmdbuf mutex.
248 struct vmw_sw_context ctx;
250 struct mutex cmdbuf_mutex;
253 * GMR management. Protected by the lru spinlock.
257 struct list_head gmr_lru;
271 struct vmw_master *active_master;
272 struct vmw_master fbdev_master;
273 struct notifier_block pm_nb;
276 static inline struct vmw_private *vmw_priv(struct drm_device *dev)
278 return (struct vmw_private *)dev->dev_private;
281 static inline struct vmw_fpriv *vmw_fpriv(struct drm_file *file_priv)
283 return (struct vmw_fpriv *)file_priv->driver_priv;
286 static inline struct vmw_master *vmw_master(struct drm_master *master)
288 return (struct vmw_master *) master->driver_priv;
291 static inline void vmw_write(struct vmw_private *dev_priv,
292 unsigned int offset, uint32_t value)
294 outl(offset, dev_priv->io_start + VMWGFX_INDEX_PORT);
295 outl(value, dev_priv->io_start + VMWGFX_VALUE_PORT);
298 static inline uint32_t vmw_read(struct vmw_private *dev_priv,
303 outl(offset, dev_priv->io_start + VMWGFX_INDEX_PORT);
304 val = inl(dev_priv->io_start + VMWGFX_VALUE_PORT);
309 * GMR utilities - vmwgfx_gmr.c
312 extern int vmw_gmr_bind(struct vmw_private *dev_priv,
313 struct ttm_buffer_object *bo);
314 extern void vmw_gmr_unbind(struct vmw_private *dev_priv, int gmr_id);
317 * Resource utilities - vmwgfx_resource.c
320 extern struct vmw_resource *vmw_context_alloc(struct vmw_private *dev_priv);
321 extern void vmw_resource_unreference(struct vmw_resource **p_res);
322 extern struct vmw_resource *vmw_resource_reference(struct vmw_resource *res);
323 extern int vmw_context_destroy_ioctl(struct drm_device *dev, void *data,
324 struct drm_file *file_priv);
325 extern int vmw_context_define_ioctl(struct drm_device *dev, void *data,
326 struct drm_file *file_priv);
327 extern int vmw_context_check(struct vmw_private *dev_priv,
328 struct ttm_object_file *tfile,
330 extern void vmw_surface_res_free(struct vmw_resource *res);
331 extern int vmw_surface_init(struct vmw_private *dev_priv,
332 struct vmw_surface *srf,
333 void (*res_free) (struct vmw_resource *res));
334 extern int vmw_user_surface_lookup_handle(struct vmw_private *dev_priv,
335 struct ttm_object_file *tfile,
337 struct vmw_surface **out);
338 extern int vmw_surface_destroy_ioctl(struct drm_device *dev, void *data,
339 struct drm_file *file_priv);
340 extern int vmw_surface_define_ioctl(struct drm_device *dev, void *data,
341 struct drm_file *file_priv);
342 extern int vmw_surface_reference_ioctl(struct drm_device *dev, void *data,
343 struct drm_file *file_priv);
344 extern int vmw_surface_check(struct vmw_private *dev_priv,
345 struct ttm_object_file *tfile,
346 uint32_t handle, int *id);
347 extern void vmw_dmabuf_bo_free(struct ttm_buffer_object *bo);
348 extern int vmw_dmabuf_init(struct vmw_private *dev_priv,
349 struct vmw_dma_buffer *vmw_bo,
350 size_t size, struct ttm_placement *placement,
352 void (*bo_free) (struct ttm_buffer_object *bo));
353 extern int vmw_dmabuf_alloc_ioctl(struct drm_device *dev, void *data,
354 struct drm_file *file_priv);
355 extern int vmw_dmabuf_unref_ioctl(struct drm_device *dev, void *data,
356 struct drm_file *file_priv);
357 extern uint32_t vmw_dmabuf_validate_node(struct ttm_buffer_object *bo,
358 uint32_t cur_validate_node);
359 extern void vmw_dmabuf_validate_clear(struct ttm_buffer_object *bo);
360 extern int vmw_user_dmabuf_lookup(struct ttm_object_file *tfile,
361 uint32_t id, struct vmw_dma_buffer **out);
362 extern uint32_t vmw_dmabuf_gmr(struct ttm_buffer_object *bo);
363 extern void vmw_dmabuf_set_gmr(struct ttm_buffer_object *bo, uint32_t id);
364 extern int vmw_gmr_id_alloc(struct vmw_private *dev_priv, uint32_t *p_id);
365 extern int vmw_dmabuf_to_start_of_vram(struct vmw_private *vmw_priv,
366 struct vmw_dma_buffer *bo);
367 extern int vmw_dmabuf_from_vram(struct vmw_private *vmw_priv,
368 struct vmw_dma_buffer *bo);
369 extern void vmw_dmabuf_gmr_unbind(struct ttm_buffer_object *bo);
370 extern int vmw_stream_claim_ioctl(struct drm_device *dev, void *data,
371 struct drm_file *file_priv);
372 extern int vmw_stream_unref_ioctl(struct drm_device *dev, void *data,
373 struct drm_file *file_priv);
374 extern int vmw_user_stream_lookup(struct vmw_private *dev_priv,
375 struct ttm_object_file *tfile,
377 struct vmw_resource **out);
381 * Misc Ioctl functionality - vmwgfx_ioctl.c
384 extern int vmw_getparam_ioctl(struct drm_device *dev, void *data,
385 struct drm_file *file_priv);
386 extern int vmw_fifo_debug_ioctl(struct drm_device *dev, void *data,
387 struct drm_file *file_priv);
390 * Fifo utilities - vmwgfx_fifo.c
393 extern int vmw_fifo_init(struct vmw_private *dev_priv,
394 struct vmw_fifo_state *fifo);
395 extern void vmw_fifo_release(struct vmw_private *dev_priv,
396 struct vmw_fifo_state *fifo);
397 extern void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes);
398 extern void vmw_fifo_commit(struct vmw_private *dev_priv, uint32_t bytes);
399 extern int vmw_fifo_send_fence(struct vmw_private *dev_priv,
401 extern void vmw_fifo_ping_host(struct vmw_private *dev_priv, uint32_t reason);
402 extern int vmw_fifo_mmap(struct file *filp, struct vm_area_struct *vma);
403 extern bool vmw_fifo_have_3d(struct vmw_private *dev_priv);
406 * TTM glue - vmwgfx_ttm_glue.c
409 extern int vmw_ttm_global_init(struct vmw_private *dev_priv);
410 extern void vmw_ttm_global_release(struct vmw_private *dev_priv);
411 extern int vmw_mmap(struct file *filp, struct vm_area_struct *vma);
414 * TTM buffer object driver - vmwgfx_buffer.c
417 extern struct ttm_placement vmw_vram_placement;
418 extern struct ttm_placement vmw_vram_ne_placement;
419 extern struct ttm_placement vmw_vram_sys_placement;
420 extern struct ttm_placement vmw_sys_placement;
421 extern struct ttm_bo_driver vmw_bo_driver;
422 extern int vmw_dma_quiescent(struct drm_device *dev);
425 * Command submission - vmwgfx_execbuf.c
428 extern int vmw_execbuf_ioctl(struct drm_device *dev, void *data,
429 struct drm_file *file_priv);
432 * IRQs and wating - vmwgfx_irq.c
435 extern irqreturn_t vmw_irq_handler(DRM_IRQ_ARGS);
436 extern int vmw_wait_fence(struct vmw_private *dev_priv, bool lazy,
437 uint32_t sequence, bool interruptible,
438 unsigned long timeout);
439 extern void vmw_irq_preinstall(struct drm_device *dev);
440 extern int vmw_irq_postinstall(struct drm_device *dev);
441 extern void vmw_irq_uninstall(struct drm_device *dev);
442 extern bool vmw_fence_signaled(struct vmw_private *dev_priv,
444 extern int vmw_fence_wait_ioctl(struct drm_device *dev, void *data,
445 struct drm_file *file_priv);
446 extern int vmw_fallback_wait(struct vmw_private *dev_priv,
451 unsigned long timeout);
452 extern void vmw_update_sequence(struct vmw_private *dev_priv,
453 struct vmw_fifo_state *fifo_state);
457 * Rudimentary fence objects currently used only for throttling -
461 extern void vmw_fence_queue_init(struct vmw_fence_queue *queue);
462 extern void vmw_fence_queue_takedown(struct vmw_fence_queue *queue);
463 extern int vmw_fence_push(struct vmw_fence_queue *queue,
465 extern int vmw_fence_pull(struct vmw_fence_queue *queue,
466 uint32_t signaled_sequence);
467 extern int vmw_wait_lag(struct vmw_private *dev_priv,
468 struct vmw_fence_queue *queue, uint32_t us);
471 * Kernel framebuffer - vmwgfx_fb.c
474 int vmw_fb_init(struct vmw_private *vmw_priv);
475 int vmw_fb_close(struct vmw_private *dev_priv);
476 int vmw_fb_off(struct vmw_private *vmw_priv);
477 int vmw_fb_on(struct vmw_private *vmw_priv);
480 * Kernel modesetting - vmwgfx_kms.c
483 int vmw_kms_init(struct vmw_private *dev_priv);
484 int vmw_kms_close(struct vmw_private *dev_priv);
485 int vmw_kms_save_vga(struct vmw_private *vmw_priv);
486 int vmw_kms_restore_vga(struct vmw_private *vmw_priv);
487 int vmw_kms_cursor_bypass_ioctl(struct drm_device *dev, void *data,
488 struct drm_file *file_priv);
489 void vmw_kms_cursor_post_execbuf(struct vmw_private *dev_priv);
490 void vmw_kms_cursor_snoop(struct vmw_surface *srf,
491 struct ttm_object_file *tfile,
492 struct ttm_buffer_object *bo,
493 SVGA3dCmdHeader *header);
496 * Overlay control - vmwgfx_overlay.c
499 int vmw_overlay_init(struct vmw_private *dev_priv);
500 int vmw_overlay_close(struct vmw_private *dev_priv);
501 int vmw_overlay_ioctl(struct drm_device *dev, void *data,
502 struct drm_file *file_priv);
503 int vmw_overlay_stop_all(struct vmw_private *dev_priv);
504 int vmw_overlay_resume_all(struct vmw_private *dev_priv);
505 int vmw_overlay_pause_all(struct vmw_private *dev_priv);
506 int vmw_overlay_claim(struct vmw_private *dev_priv, uint32_t *out);
507 int vmw_overlay_unref(struct vmw_private *dev_priv, uint32_t stream_id);
508 int vmw_overlay_num_overlays(struct vmw_private *dev_priv);
509 int vmw_overlay_num_free_overlays(struct vmw_private *dev_priv);
512 * Inline helper functions
515 static inline void vmw_surface_unreference(struct vmw_surface **srf)
517 struct vmw_surface *tmp_srf = *srf;
518 struct vmw_resource *res = &tmp_srf->res;
521 vmw_resource_unreference(&res);
524 static inline struct vmw_surface *vmw_surface_reference(struct vmw_surface *srf)
526 (void) vmw_resource_reference(&srf->res);
530 static inline void vmw_dmabuf_unreference(struct vmw_dma_buffer **buf)
532 struct vmw_dma_buffer *tmp_buf = *buf;
533 struct ttm_buffer_object *bo = &tmp_buf->base;
539 static inline struct vmw_dma_buffer *vmw_dmabuf_reference(struct vmw_dma_buffer *buf)
541 if (ttm_bo_reference(&buf->base))