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 2
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
50 #define VMWGFX_MAX_DISPLAYS 16
53 struct drm_master
*locked_master
;
54 struct ttm_object_file
*tfile
;
57 struct vmw_dma_buffer
{
58 struct ttm_buffer_object base
;
59 struct list_head validate_list
;
60 struct list_head gmr_lru
;
63 uint32_t cur_validate_node
;
64 bool on_validate_list
;
69 struct vmw_private
*dev_priv
;
72 enum ttm_object_type res_type
;
74 void (*hw_destroy
) (struct vmw_resource
*res
);
75 void (*res_free
) (struct vmw_resource
*res
);
77 /* TODO is a generic snooper needed? */
80 struct vmw_cursor_snooper
{
81 struct drm_crtc
*crtc
;
87 struct vmw_resource res
;
90 uint32_t mip_levels
[DRM_VMW_MAX_SURFACE_FACES
];
91 struct drm_vmw_size
*sizes
;
96 /* TODO so far just a extra pointer */
97 struct vmw_cursor_snooper snooper
;
100 struct vmw_fence_queue
{
101 struct list_head head
;
103 struct timespec lag_time
;
107 struct vmw_fifo_state
{
108 unsigned long reserved_size
;
109 __le32
*dynamic_buffer
;
110 __le32
*static_buffer
;
112 uint32_t last_data_size
;
113 uint32_t last_buffer_size
;
114 bool last_buffer_add
;
115 unsigned long static_buffer_size
;
116 bool using_bounce_buffer
;
117 uint32_t capabilities
;
118 struct mutex fifo_mutex
;
119 struct rw_semaphore rwsem
;
120 struct vmw_fence_queue fence_queue
;
123 struct vmw_relocation
{
124 SVGAGuestPtr
*location
;
128 struct vmw_sw_context
{
133 uint32_t sid_translation
;
135 struct ttm_object_file
*tfile
;
136 struct list_head validate_nodes
;
137 struct vmw_relocation relocs
[VMWGFX_MAX_RELOCATIONS
];
139 struct ttm_validate_buffer val_bufs
[VMWGFX_MAX_GMRS
];
140 uint32_t cur_val_buf
;
143 struct vmw_legacy_display
;
147 struct ttm_lock lock
;
150 struct vmw_vga_topology_state
{
159 struct ttm_bo_device bdev
;
160 struct ttm_bo_global_ref bo_global_ref
;
161 struct drm_global_reference mem_global_ref
;
163 struct vmw_fifo_state fifo
;
165 struct drm_device
*dev
;
166 unsigned long vmw_chipset
;
167 unsigned int io_start
;
172 uint32_t fb_max_width
;
173 uint32_t fb_max_height
;
174 __le32 __iomem
*mmio_virt
;
176 uint32_t capabilities
;
177 uint32_t max_gmr_descriptors
;
178 uint32_t max_gmr_ids
;
179 struct mutex hw_mutex
;
185 struct vmw_vga_topology_state vga_save
[VMWGFX_MAX_DISPLAYS
];
191 uint32_t vga_red_mask
;
192 uint32_t vga_green_mask
;
193 uint32_t vga_blue_mask
;
195 uint32_t vga_pitchlock
;
197 uint32_t num_displays
;
204 struct vmw_legacy_display
*ldu_priv
;
205 struct vmw_overlay
*overlay_priv
;
208 * Context and surface management.
211 rwlock_t resource_lock
;
212 struct idr context_idr
;
213 struct idr surface_idr
;
214 struct idr stream_idr
;
217 * Block lastclose from racing with firstopen.
220 struct mutex init_mutex
;
223 * A resource manager for kernel-only surfaces and
227 struct ttm_object_device
*tdev
;
234 wait_queue_head_t fence_queue
;
235 wait_queue_head_t fifo_queue
;
236 atomic_t fence_queue_waiters
;
237 atomic_t fifo_queue_waiters
;
238 uint32_t last_read_sequence
;
245 uint32_t traces_state
;
246 uint32_t enable_state
;
247 uint32_t config_done_state
;
253 * Protected by the cmdbuf mutex.
256 struct vmw_sw_context ctx
;
258 struct mutex cmdbuf_mutex
;
261 * GMR management. Protected by the lru spinlock.
265 struct list_head gmr_lru
;
280 struct vmw_master
*active_master
;
281 struct vmw_master fbdev_master
;
282 struct notifier_block pm_nb
;
284 struct mutex release_mutex
;
285 uint32_t num_3d_resources
;
288 static inline struct vmw_private
*vmw_priv(struct drm_device
*dev
)
290 return (struct vmw_private
*)dev
->dev_private
;
293 static inline struct vmw_fpriv
*vmw_fpriv(struct drm_file
*file_priv
)
295 return (struct vmw_fpriv
*)file_priv
->driver_priv
;
298 static inline struct vmw_master
*vmw_master(struct drm_master
*master
)
300 return (struct vmw_master
*) master
->driver_priv
;
303 static inline void vmw_write(struct vmw_private
*dev_priv
,
304 unsigned int offset
, uint32_t value
)
306 outl(offset
, dev_priv
->io_start
+ VMWGFX_INDEX_PORT
);
307 outl(value
, dev_priv
->io_start
+ VMWGFX_VALUE_PORT
);
310 static inline uint32_t vmw_read(struct vmw_private
*dev_priv
,
315 outl(offset
, dev_priv
->io_start
+ VMWGFX_INDEX_PORT
);
316 val
= inl(dev_priv
->io_start
+ VMWGFX_VALUE_PORT
);
320 int vmw_3d_resource_inc(struct vmw_private
*dev_priv
);
321 void vmw_3d_resource_dec(struct vmw_private
*dev_priv
);
324 * GMR utilities - vmwgfx_gmr.c
327 extern int vmw_gmr_bind(struct vmw_private
*dev_priv
,
328 struct ttm_buffer_object
*bo
);
329 extern void vmw_gmr_unbind(struct vmw_private
*dev_priv
, int gmr_id
);
332 * Resource utilities - vmwgfx_resource.c
335 extern struct vmw_resource
*vmw_context_alloc(struct vmw_private
*dev_priv
);
336 extern void vmw_resource_unreference(struct vmw_resource
**p_res
);
337 extern struct vmw_resource
*vmw_resource_reference(struct vmw_resource
*res
);
338 extern int vmw_context_destroy_ioctl(struct drm_device
*dev
, void *data
,
339 struct drm_file
*file_priv
);
340 extern int vmw_context_define_ioctl(struct drm_device
*dev
, void *data
,
341 struct drm_file
*file_priv
);
342 extern int vmw_context_check(struct vmw_private
*dev_priv
,
343 struct ttm_object_file
*tfile
,
345 extern void vmw_surface_res_free(struct vmw_resource
*res
);
346 extern int vmw_surface_init(struct vmw_private
*dev_priv
,
347 struct vmw_surface
*srf
,
348 void (*res_free
) (struct vmw_resource
*res
));
349 extern int vmw_user_surface_lookup_handle(struct vmw_private
*dev_priv
,
350 struct ttm_object_file
*tfile
,
352 struct vmw_surface
**out
);
353 extern int vmw_surface_destroy_ioctl(struct drm_device
*dev
, void *data
,
354 struct drm_file
*file_priv
);
355 extern int vmw_surface_define_ioctl(struct drm_device
*dev
, void *data
,
356 struct drm_file
*file_priv
);
357 extern int vmw_surface_reference_ioctl(struct drm_device
*dev
, void *data
,
358 struct drm_file
*file_priv
);
359 extern int vmw_surface_check(struct vmw_private
*dev_priv
,
360 struct ttm_object_file
*tfile
,
361 uint32_t handle
, int *id
);
362 extern void vmw_dmabuf_bo_free(struct ttm_buffer_object
*bo
);
363 extern int vmw_dmabuf_init(struct vmw_private
*dev_priv
,
364 struct vmw_dma_buffer
*vmw_bo
,
365 size_t size
, struct ttm_placement
*placement
,
367 void (*bo_free
) (struct ttm_buffer_object
*bo
));
368 extern int vmw_dmabuf_alloc_ioctl(struct drm_device
*dev
, void *data
,
369 struct drm_file
*file_priv
);
370 extern int vmw_dmabuf_unref_ioctl(struct drm_device
*dev
, void *data
,
371 struct drm_file
*file_priv
);
372 extern uint32_t vmw_dmabuf_validate_node(struct ttm_buffer_object
*bo
,
373 uint32_t cur_validate_node
);
374 extern void vmw_dmabuf_validate_clear(struct ttm_buffer_object
*bo
);
375 extern int vmw_user_dmabuf_lookup(struct ttm_object_file
*tfile
,
376 uint32_t id
, struct vmw_dma_buffer
**out
);
377 extern uint32_t vmw_dmabuf_gmr(struct ttm_buffer_object
*bo
);
378 extern void vmw_dmabuf_set_gmr(struct ttm_buffer_object
*bo
, uint32_t id
);
379 extern int vmw_gmr_id_alloc(struct vmw_private
*dev_priv
, uint32_t *p_id
);
380 extern int vmw_dmabuf_to_start_of_vram(struct vmw_private
*vmw_priv
,
381 struct vmw_dma_buffer
*bo
);
382 extern int vmw_dmabuf_from_vram(struct vmw_private
*vmw_priv
,
383 struct vmw_dma_buffer
*bo
);
384 extern void vmw_dmabuf_gmr_unbind(struct ttm_buffer_object
*bo
);
385 extern int vmw_stream_claim_ioctl(struct drm_device
*dev
, void *data
,
386 struct drm_file
*file_priv
);
387 extern int vmw_stream_unref_ioctl(struct drm_device
*dev
, void *data
,
388 struct drm_file
*file_priv
);
389 extern int vmw_user_stream_lookup(struct vmw_private
*dev_priv
,
390 struct ttm_object_file
*tfile
,
392 struct vmw_resource
**out
);
396 * Misc Ioctl functionality - vmwgfx_ioctl.c
399 extern int vmw_getparam_ioctl(struct drm_device
*dev
, void *data
,
400 struct drm_file
*file_priv
);
401 extern int vmw_fifo_debug_ioctl(struct drm_device
*dev
, void *data
,
402 struct drm_file
*file_priv
);
405 * Fifo utilities - vmwgfx_fifo.c
408 extern int vmw_fifo_init(struct vmw_private
*dev_priv
,
409 struct vmw_fifo_state
*fifo
);
410 extern void vmw_fifo_release(struct vmw_private
*dev_priv
,
411 struct vmw_fifo_state
*fifo
);
412 extern void *vmw_fifo_reserve(struct vmw_private
*dev_priv
, uint32_t bytes
);
413 extern void vmw_fifo_commit(struct vmw_private
*dev_priv
, uint32_t bytes
);
414 extern int vmw_fifo_send_fence(struct vmw_private
*dev_priv
,
416 extern void vmw_fifo_ping_host(struct vmw_private
*dev_priv
, uint32_t reason
);
417 extern int vmw_fifo_mmap(struct file
*filp
, struct vm_area_struct
*vma
);
418 extern bool vmw_fifo_have_3d(struct vmw_private
*dev_priv
);
419 extern bool vmw_fifo_have_pitchlock(struct vmw_private
*dev_priv
);
422 * TTM glue - vmwgfx_ttm_glue.c
425 extern int vmw_ttm_global_init(struct vmw_private
*dev_priv
);
426 extern void vmw_ttm_global_release(struct vmw_private
*dev_priv
);
427 extern int vmw_mmap(struct file
*filp
, struct vm_area_struct
*vma
);
430 * TTM buffer object driver - vmwgfx_buffer.c
433 extern struct ttm_placement vmw_vram_placement
;
434 extern struct ttm_placement vmw_vram_ne_placement
;
435 extern struct ttm_placement vmw_vram_sys_placement
;
436 extern struct ttm_placement vmw_sys_placement
;
437 extern struct ttm_bo_driver vmw_bo_driver
;
438 extern int vmw_dma_quiescent(struct drm_device
*dev
);
441 * Command submission - vmwgfx_execbuf.c
444 extern int vmw_execbuf_ioctl(struct drm_device
*dev
, void *data
,
445 struct drm_file
*file_priv
);
448 * IRQs and wating - vmwgfx_irq.c
451 extern irqreturn_t
vmw_irq_handler(DRM_IRQ_ARGS
);
452 extern int vmw_wait_fence(struct vmw_private
*dev_priv
, bool lazy
,
453 uint32_t sequence
, bool interruptible
,
454 unsigned long timeout
);
455 extern void vmw_irq_preinstall(struct drm_device
*dev
);
456 extern int vmw_irq_postinstall(struct drm_device
*dev
);
457 extern void vmw_irq_uninstall(struct drm_device
*dev
);
458 extern bool vmw_fence_signaled(struct vmw_private
*dev_priv
,
460 extern int vmw_fence_wait_ioctl(struct drm_device
*dev
, void *data
,
461 struct drm_file
*file_priv
);
462 extern int vmw_fallback_wait(struct vmw_private
*dev_priv
,
467 unsigned long timeout
);
468 extern void vmw_update_sequence(struct vmw_private
*dev_priv
,
469 struct vmw_fifo_state
*fifo_state
);
473 * Rudimentary fence objects currently used only for throttling -
477 extern void vmw_fence_queue_init(struct vmw_fence_queue
*queue
);
478 extern void vmw_fence_queue_takedown(struct vmw_fence_queue
*queue
);
479 extern int vmw_fence_push(struct vmw_fence_queue
*queue
,
481 extern int vmw_fence_pull(struct vmw_fence_queue
*queue
,
482 uint32_t signaled_sequence
);
483 extern int vmw_wait_lag(struct vmw_private
*dev_priv
,
484 struct vmw_fence_queue
*queue
, uint32_t us
);
487 * Kernel framebuffer - vmwgfx_fb.c
490 int vmw_fb_init(struct vmw_private
*vmw_priv
);
491 int vmw_fb_close(struct vmw_private
*dev_priv
);
492 int vmw_fb_off(struct vmw_private
*vmw_priv
);
493 int vmw_fb_on(struct vmw_private
*vmw_priv
);
496 * Kernel modesetting - vmwgfx_kms.c
499 int vmw_kms_init(struct vmw_private
*dev_priv
);
500 int vmw_kms_close(struct vmw_private
*dev_priv
);
501 int vmw_kms_save_vga(struct vmw_private
*vmw_priv
);
502 int vmw_kms_restore_vga(struct vmw_private
*vmw_priv
);
503 int vmw_kms_cursor_bypass_ioctl(struct drm_device
*dev
, void *data
,
504 struct drm_file
*file_priv
);
505 void vmw_kms_cursor_post_execbuf(struct vmw_private
*dev_priv
);
506 void vmw_kms_cursor_snoop(struct vmw_surface
*srf
,
507 struct ttm_object_file
*tfile
,
508 struct ttm_buffer_object
*bo
,
509 SVGA3dCmdHeader
*header
);
510 void vmw_kms_write_svga(struct vmw_private
*vmw_priv
,
511 unsigned width
, unsigned height
, unsigned pitch
,
512 unsigned bbp
, unsigned depth
);
513 int vmw_kms_update_layout_ioctl(struct drm_device
*dev
, void *data
,
514 struct drm_file
*file_priv
);
515 u32
vmw_get_vblank_counter(struct drm_device
*dev
, int crtc
);
518 * Overlay control - vmwgfx_overlay.c
521 int vmw_overlay_init(struct vmw_private
*dev_priv
);
522 int vmw_overlay_close(struct vmw_private
*dev_priv
);
523 int vmw_overlay_ioctl(struct drm_device
*dev
, void *data
,
524 struct drm_file
*file_priv
);
525 int vmw_overlay_stop_all(struct vmw_private
*dev_priv
);
526 int vmw_overlay_resume_all(struct vmw_private
*dev_priv
);
527 int vmw_overlay_pause_all(struct vmw_private
*dev_priv
);
528 int vmw_overlay_claim(struct vmw_private
*dev_priv
, uint32_t *out
);
529 int vmw_overlay_unref(struct vmw_private
*dev_priv
, uint32_t stream_id
);
530 int vmw_overlay_num_overlays(struct vmw_private
*dev_priv
);
531 int vmw_overlay_num_free_overlays(struct vmw_private
*dev_priv
);
534 * Inline helper functions
537 static inline void vmw_surface_unreference(struct vmw_surface
**srf
)
539 struct vmw_surface
*tmp_srf
= *srf
;
540 struct vmw_resource
*res
= &tmp_srf
->res
;
543 vmw_resource_unreference(&res
);
546 static inline struct vmw_surface
*vmw_surface_reference(struct vmw_surface
*srf
)
548 (void) vmw_resource_reference(&srf
->res
);
552 static inline void vmw_dmabuf_unreference(struct vmw_dma_buffer
**buf
)
554 struct vmw_dma_buffer
*tmp_buf
= *buf
;
555 struct ttm_buffer_object
*bo
= &tmp_buf
->base
;
561 static inline struct vmw_dma_buffer
*vmw_dmabuf_reference(struct vmw_dma_buffer
*buf
)
563 if (ttm_bo_reference(&buf
->base
))