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 0
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_fifo_state
{
106 unsigned long reserved_size
;
107 __le32
*dynamic_buffer
;
108 __le32
*static_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
;
116 struct mutex fifo_mutex
;
117 struct rw_semaphore rwsem
;
120 struct vmw_relocation
{
121 SVGAGuestPtr
*location
;
125 struct vmw_sw_context
{
130 uint32_t sid_translation
;
132 struct ttm_object_file
*tfile
;
133 struct list_head validate_nodes
;
134 struct vmw_relocation relocs
[VMWGFX_MAX_RELOCATIONS
];
136 struct ttm_validate_buffer val_bufs
[VMWGFX_MAX_GMRS
];
137 uint32_t cur_val_buf
;
140 struct vmw_legacy_display
;
144 struct ttm_lock lock
;
148 struct ttm_bo_device bdev
;
149 struct ttm_bo_global_ref bo_global_ref
;
150 struct ttm_global_reference mem_global_ref
;
152 struct vmw_fifo_state fifo
;
154 struct drm_device
*dev
;
155 unsigned long vmw_chipset
;
156 unsigned int io_start
;
161 uint32_t fb_max_width
;
162 uint32_t fb_max_height
;
163 __le32 __iomem
*mmio_virt
;
165 uint32_t capabilities
;
166 uint32_t max_gmr_descriptors
;
167 uint32_t max_gmr_ids
;
168 struct mutex hw_mutex
;
179 uint32_t vga_red_mask
;
180 uint32_t vga_blue_mask
;
181 uint32_t vga_green_mask
;
188 struct vmw_legacy_display
*ldu_priv
;
189 struct vmw_overlay
*overlay_priv
;
192 * Context and surface management.
195 rwlock_t resource_lock
;
196 struct idr context_idr
;
197 struct idr surface_idr
;
198 struct idr stream_idr
;
201 * Block lastclose from racing with firstopen.
204 struct mutex init_mutex
;
207 * A resource manager for kernel-only surfaces and
211 struct ttm_object_device
*tdev
;
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
;
229 uint32_t traces_state
;
230 uint32_t enable_state
;
231 uint32_t config_done_state
;
237 * Protected by the cmdbuf mutex.
240 struct vmw_sw_context ctx
;
242 struct mutex cmdbuf_mutex
;
245 * GMR management. Protected by the lru spinlock.
249 struct list_head gmr_lru
;
263 struct vmw_master
*active_master
;
264 struct vmw_master fbdev_master
;
265 struct notifier_block pm_nb
;
268 static inline struct vmw_private
*vmw_priv(struct drm_device
*dev
)
270 return (struct vmw_private
*)dev
->dev_private
;
273 static inline struct vmw_fpriv
*vmw_fpriv(struct drm_file
*file_priv
)
275 return (struct vmw_fpriv
*)file_priv
->driver_priv
;
278 static inline struct vmw_master
*vmw_master(struct drm_master
*master
)
280 return (struct vmw_master
*) master
->driver_priv
;
283 static inline void vmw_write(struct vmw_private
*dev_priv
,
284 unsigned int offset
, uint32_t value
)
286 outl(offset
, dev_priv
->io_start
+ VMWGFX_INDEX_PORT
);
287 outl(value
, dev_priv
->io_start
+ VMWGFX_VALUE_PORT
);
290 static inline uint32_t vmw_read(struct vmw_private
*dev_priv
,
295 outl(offset
, dev_priv
->io_start
+ VMWGFX_INDEX_PORT
);
296 val
= inl(dev_priv
->io_start
+ VMWGFX_VALUE_PORT
);
301 * GMR utilities - vmwgfx_gmr.c
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
);
309 * Resource utilities - vmwgfx_resource.c
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
,
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
));
326 extern int vmw_user_surface_lookup_handle(struct vmw_private
*dev_priv
,
327 struct ttm_object_file
*tfile
,
329 struct vmw_surface
**out
);
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
,
338 uint32_t handle
, int *id
);
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
,
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
);
361 extern void vmw_dmabuf_gmr_unbind(struct ttm_buffer_object
*bo
);
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
,
369 struct vmw_resource
**out
);
373 * Misc Ioctl functionality - vmwgfx_ioctl.c
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
);
382 * Fifo utilities - vmwgfx_fifo.c
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
,
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
);
395 extern bool vmw_fifo_have_3d(struct vmw_private
*dev_priv
);
398 * TTM glue - vmwgfx_ttm_glue.c
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
);
406 * TTM buffer object driver - vmwgfx_buffer.c
409 extern struct ttm_placement vmw_vram_placement
;
410 extern struct ttm_placement vmw_vram_ne_placement
;
411 extern struct ttm_placement vmw_vram_sys_placement
;
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
);
417 * Command submission - vmwgfx_execbuf.c
420 extern int vmw_execbuf_ioctl(struct drm_device
*dev
, void *data
,
421 struct drm_file
*file_priv
);
424 * IRQs and wating - vmwgfx_irq.c
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
,
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
,
443 unsigned long timeout
);
446 * Kernel framebuffer - vmwgfx_fb.c
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
);
455 * Kernel modesetting - vmwgfx_kms.c
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
);
471 * Overlay control - vmwgfx_overlay.c
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
);
487 * Inline helper functions
490 static inline void vmw_surface_unreference(struct vmw_surface
**srf
)
492 struct vmw_surface
*tmp_srf
= *srf
;
493 struct vmw_resource
*res
= &tmp_srf
->res
;
496 vmw_resource_unreference(&res
);
499 static inline struct vmw_surface
*vmw_surface_reference(struct vmw_surface
*srf
)
501 (void) vmw_resource_reference(&srf
->res
);
505 static inline void vmw_dmabuf_unreference(struct vmw_dma_buffer
**buf
)
507 struct vmw_dma_buffer
*tmp_buf
= *buf
;
508 struct ttm_buffer_object
*bo
= &tmp_buf
->base
;
514 static inline struct vmw_dma_buffer
*vmw_dmabuf_reference(struct vmw_dma_buffer
*buf
)
516 if (ttm_bo_reference(&buf
->base
))