drm/vmwgfx: Update the user-space interface.
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / gpu / drm / vmwgfx / vmwgfx_drv.h
blob0eaf68273eaf332b1ebafed88270afc94c1e7fdc
1 /**************************************************************************
3 * Copyright © 2009 VMware, Inc., Palo Alto, CA., USA
4 * All Rights Reserved.
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
16 * of the Software.
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"
32 #include "drmP.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 "20100118"
43 #define VMWGFX_DRIVER_MAJOR 0
44 #define VMWGFX_DRIVER_MINOR 9
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
51 struct vmw_fpriv {
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;
60 uint32_t gmr_id;
61 bool gmr_bound;
62 uint32_t cur_validate_node;
63 bool on_validate_list;
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);
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
85 struct vmw_cursor_snooper {
86 struct drm_crtc *crtc;
87 size_t age;
88 uint32_t *image;
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;
99 bool scanout;
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;
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;
116 struct rw_semaphore rwsem;
119 struct vmw_relocation {
120 SVGAGuestPtr *location;
121 uint32_t index;
124 struct vmw_sw_context{
125 struct ida bo_list;
126 uint32_t last_cid;
127 bool cid_valid;
128 uint32_t last_sid;
129 uint32_t sid_translation;
130 bool sid_valid;
131 struct ttm_object_file *tfile;
132 struct list_head validate_nodes;
133 struct vmw_relocation relocs[VMWGFX_MAX_RELOCATIONS];
134 uint32_t cur_reloc;
135 struct ttm_validate_buffer val_bufs[VMWGFX_MAX_GMRS];
136 uint32_t cur_val_buf;
139 struct vmw_legacy_display;
140 struct vmw_overlay;
142 struct vmw_master {
143 struct ttm_lock lock;
146 struct vmw_private {
147 struct ttm_bo_device bdev;
148 struct ttm_bo_global_ref bo_global_ref;
149 struct ttm_global_reference mem_global_ref;
151 struct vmw_fifo_state fifo;
153 struct drm_device *dev;
154 unsigned long vmw_chipset;
155 unsigned int io_start;
156 uint32_t vram_start;
157 uint32_t vram_size;
158 uint32_t mmio_start;
159 uint32_t mmio_size;
160 uint32_t fb_max_width;
161 uint32_t fb_max_height;
162 __le32 __iomem *mmio_virt;
163 int mmio_mtrr;
164 uint32_t capabilities;
165 uint32_t max_gmr_descriptors;
166 uint32_t max_gmr_ids;
167 struct mutex hw_mutex;
170 * VGA registers.
173 uint32_t vga_width;
174 uint32_t vga_height;
175 uint32_t vga_depth;
176 uint32_t vga_bpp;
177 uint32_t vga_pseudo;
178 uint32_t vga_red_mask;
179 uint32_t vga_blue_mask;
180 uint32_t vga_green_mask;
183 * Framebuffer info.
186 void *fb_info;
187 struct vmw_legacy_display *ldu_priv;
188 struct vmw_overlay *overlay_priv;
191 * Context and surface management.
194 rwlock_t resource_lock;
195 struct idr context_idr;
196 struct idr surface_idr;
197 struct idr stream_idr;
200 * Block lastclose from racing with firstopen.
203 struct mutex init_mutex;
206 * A resource manager for kernel-only surfaces and
207 * contexts.
210 struct ttm_object_device *tdev;
213 * Fencing and IRQs.
216 uint32_t fence_seq;
217 wait_queue_head_t fence_queue;
218 wait_queue_head_t fifo_queue;
219 atomic_t fence_queue_waiters;
220 atomic_t fifo_queue_waiters;
221 uint32_t last_read_sequence;
222 spinlock_t irq_lock;
225 * Device state
228 uint32_t traces_state;
229 uint32_t enable_state;
230 uint32_t config_done_state;
233 * Execbuf
236 * Protected by the cmdbuf mutex.
239 struct vmw_sw_context ctx;
240 uint32_t val_seq;
241 struct mutex cmdbuf_mutex;
244 * GMR management. Protected by the lru spinlock.
247 struct ida gmr_ida;
248 struct list_head gmr_lru;
252 * Operating mode.
255 bool stealth;
256 bool is_opened;
259 * Master management.
262 struct vmw_master *active_master;
263 struct vmw_master fbdev_master;
264 struct notifier_block pm_nb;
267 static inline struct vmw_private *vmw_priv(struct drm_device *dev)
269 return (struct vmw_private *)dev->dev_private;
272 static inline struct vmw_fpriv *vmw_fpriv(struct drm_file *file_priv)
274 return (struct vmw_fpriv *)file_priv->driver_priv;
277 static inline struct vmw_master *vmw_master(struct drm_master *master)
279 return (struct vmw_master *) master->driver_priv;
282 static inline void vmw_write(struct vmw_private *dev_priv,
283 unsigned int offset, uint32_t value)
285 outl(offset, dev_priv->io_start + VMWGFX_INDEX_PORT);
286 outl(value, dev_priv->io_start + VMWGFX_VALUE_PORT);
289 static inline uint32_t vmw_read(struct vmw_private *dev_priv,
290 unsigned int offset)
292 uint32_t val;
294 outl(offset, dev_priv->io_start + VMWGFX_INDEX_PORT);
295 val = inl(dev_priv->io_start + VMWGFX_VALUE_PORT);
296 return val;
300 * GMR utilities - vmwgfx_gmr.c
303 extern int vmw_gmr_bind(struct vmw_private *dev_priv,
304 struct ttm_buffer_object *bo);
305 extern void vmw_gmr_unbind(struct vmw_private *dev_priv, int gmr_id);
308 * Resource utilities - vmwgfx_resource.c
311 extern struct vmw_resource *vmw_context_alloc(struct vmw_private *dev_priv);
312 extern void vmw_resource_unreference(struct vmw_resource **p_res);
313 extern struct vmw_resource *vmw_resource_reference(struct vmw_resource *res);
314 extern int vmw_context_destroy_ioctl(struct drm_device *dev, void *data,
315 struct drm_file *file_priv);
316 extern int vmw_context_define_ioctl(struct drm_device *dev, void *data,
317 struct drm_file *file_priv);
318 extern int vmw_context_check(struct vmw_private *dev_priv,
319 struct ttm_object_file *tfile,
320 int id);
321 extern void vmw_surface_res_free(struct vmw_resource *res);
322 extern int vmw_surface_init(struct vmw_private *dev_priv,
323 struct vmw_surface *srf,
324 void (*res_free) (struct vmw_resource *res));
325 extern int vmw_user_surface_lookup_handle(struct vmw_private *dev_priv,
326 struct ttm_object_file *tfile,
327 uint32_t handle,
328 struct vmw_surface **out);
329 extern int vmw_surface_destroy_ioctl(struct drm_device *dev, void *data,
330 struct drm_file *file_priv);
331 extern int vmw_surface_define_ioctl(struct drm_device *dev, void *data,
332 struct drm_file *file_priv);
333 extern int vmw_surface_reference_ioctl(struct drm_device *dev, void *data,
334 struct drm_file *file_priv);
335 extern int vmw_surface_check(struct vmw_private *dev_priv,
336 struct ttm_object_file *tfile,
337 uint32_t handle, int *id);
338 extern void vmw_dmabuf_bo_free(struct ttm_buffer_object *bo);
339 extern int vmw_dmabuf_init(struct vmw_private *dev_priv,
340 struct vmw_dma_buffer *vmw_bo,
341 size_t size, struct ttm_placement *placement,
342 bool interuptable,
343 void (*bo_free) (struct ttm_buffer_object *bo));
344 extern int vmw_dmabuf_alloc_ioctl(struct drm_device *dev, void *data,
345 struct drm_file *file_priv);
346 extern int vmw_dmabuf_unref_ioctl(struct drm_device *dev, void *data,
347 struct drm_file *file_priv);
348 extern uint32_t vmw_dmabuf_validate_node(struct ttm_buffer_object *bo,
349 uint32_t cur_validate_node);
350 extern void vmw_dmabuf_validate_clear(struct ttm_buffer_object *bo);
351 extern int vmw_user_dmabuf_lookup(struct ttm_object_file *tfile,
352 uint32_t id, struct vmw_dma_buffer **out);
353 extern uint32_t vmw_dmabuf_gmr(struct ttm_buffer_object *bo);
354 extern void vmw_dmabuf_set_gmr(struct ttm_buffer_object *bo, uint32_t id);
355 extern int vmw_gmr_id_alloc(struct vmw_private *dev_priv, uint32_t *p_id);
356 extern int vmw_dmabuf_to_start_of_vram(struct vmw_private *vmw_priv,
357 struct vmw_dma_buffer *bo);
358 extern int vmw_dmabuf_from_vram(struct vmw_private *vmw_priv,
359 struct vmw_dma_buffer *bo);
360 extern void vmw_dmabuf_gmr_unbind(struct ttm_buffer_object *bo);
361 extern int vmw_stream_claim_ioctl(struct drm_device *dev, void *data,
362 struct drm_file *file_priv);
363 extern int vmw_stream_unref_ioctl(struct drm_device *dev, void *data,
364 struct drm_file *file_priv);
365 extern int vmw_user_stream_lookup(struct vmw_private *dev_priv,
366 struct ttm_object_file *tfile,
367 uint32_t *inout_id,
368 struct vmw_resource **out);
372 * Misc Ioctl functionality - vmwgfx_ioctl.c
375 extern int vmw_getparam_ioctl(struct drm_device *dev, void *data,
376 struct drm_file *file_priv);
377 extern int vmw_fifo_debug_ioctl(struct drm_device *dev, void *data,
378 struct drm_file *file_priv);
381 * Fifo utilities - vmwgfx_fifo.c
384 extern int vmw_fifo_init(struct vmw_private *dev_priv,
385 struct vmw_fifo_state *fifo);
386 extern void vmw_fifo_release(struct vmw_private *dev_priv,
387 struct vmw_fifo_state *fifo);
388 extern void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes);
389 extern void vmw_fifo_commit(struct vmw_private *dev_priv, uint32_t bytes);
390 extern int vmw_fifo_send_fence(struct vmw_private *dev_priv,
391 uint32_t *sequence);
392 extern void vmw_fifo_ping_host(struct vmw_private *dev_priv, uint32_t reason);
393 extern int vmw_fifo_mmap(struct file *filp, struct vm_area_struct *vma);
394 extern bool vmw_fifo_have_3d(struct vmw_private *dev_priv);
397 * TTM glue - vmwgfx_ttm_glue.c
400 extern int vmw_ttm_global_init(struct vmw_private *dev_priv);
401 extern void vmw_ttm_global_release(struct vmw_private *dev_priv);
402 extern int vmw_mmap(struct file *filp, struct vm_area_struct *vma);
405 * TTM buffer object driver - vmwgfx_buffer.c
408 extern struct ttm_placement vmw_vram_placement;
409 extern struct ttm_placement vmw_vram_ne_placement;
410 extern struct ttm_placement vmw_vram_sys_placement;
411 extern struct ttm_placement vmw_sys_placement;
412 extern struct ttm_bo_driver vmw_bo_driver;
413 extern int vmw_dma_quiescent(struct drm_device *dev);
416 * Command submission - vmwgfx_execbuf.c
419 extern int vmw_execbuf_ioctl(struct drm_device *dev, void *data,
420 struct drm_file *file_priv);
423 * IRQs and wating - vmwgfx_irq.c
426 extern irqreturn_t vmw_irq_handler(DRM_IRQ_ARGS);
427 extern int vmw_wait_fence(struct vmw_private *dev_priv, bool lazy,
428 uint32_t sequence, bool interruptible,
429 unsigned long timeout);
430 extern void vmw_irq_preinstall(struct drm_device *dev);
431 extern int vmw_irq_postinstall(struct drm_device *dev);
432 extern void vmw_irq_uninstall(struct drm_device *dev);
433 extern bool vmw_fence_signaled(struct vmw_private *dev_priv,
434 uint32_t sequence);
435 extern int vmw_fence_wait_ioctl(struct drm_device *dev, void *data,
436 struct drm_file *file_priv);
437 extern int vmw_fallback_wait(struct vmw_private *dev_priv,
438 bool lazy,
439 bool fifo_idle,
440 uint32_t sequence,
441 bool interruptible,
442 unsigned long timeout);
445 * Kernel framebuffer - vmwgfx_fb.c
448 int vmw_fb_init(struct vmw_private *vmw_priv);
449 int vmw_fb_close(struct vmw_private *dev_priv);
450 int vmw_fb_off(struct vmw_private *vmw_priv);
451 int vmw_fb_on(struct vmw_private *vmw_priv);
454 * Kernel modesetting - vmwgfx_kms.c
457 int vmw_kms_init(struct vmw_private *dev_priv);
458 int vmw_kms_close(struct vmw_private *dev_priv);
459 int vmw_kms_save_vga(struct vmw_private *vmw_priv);
460 int vmw_kms_restore_vga(struct vmw_private *vmw_priv);
461 int vmw_kms_cursor_bypass_ioctl(struct drm_device *dev, void *data,
462 struct drm_file *file_priv);
463 void vmw_kms_cursor_post_execbuf(struct vmw_private *dev_priv);
464 void vmw_kms_cursor_snoop(struct vmw_surface *srf,
465 struct ttm_object_file *tfile,
466 struct ttm_buffer_object *bo,
467 SVGA3dCmdHeader *header);
470 * Overlay control - vmwgfx_overlay.c
473 int vmw_overlay_init(struct vmw_private *dev_priv);
474 int vmw_overlay_close(struct vmw_private *dev_priv);
475 int vmw_overlay_ioctl(struct drm_device *dev, void *data,
476 struct drm_file *file_priv);
477 int vmw_overlay_stop_all(struct vmw_private *dev_priv);
478 int vmw_overlay_resume_all(struct vmw_private *dev_priv);
479 int vmw_overlay_pause_all(struct vmw_private *dev_priv);
480 int vmw_overlay_claim(struct vmw_private *dev_priv, uint32_t *out);
481 int vmw_overlay_unref(struct vmw_private *dev_priv, uint32_t stream_id);
482 int vmw_overlay_num_overlays(struct vmw_private *dev_priv);
483 int vmw_overlay_num_free_overlays(struct vmw_private *dev_priv);
486 * Inline helper functions
489 static inline void vmw_surface_unreference(struct vmw_surface **srf)
491 struct vmw_surface *tmp_srf = *srf;
492 struct vmw_resource *res = &tmp_srf->res;
493 *srf = NULL;
495 vmw_resource_unreference(&res);
498 static inline struct vmw_surface *vmw_surface_reference(struct vmw_surface *srf)
500 (void) vmw_resource_reference(&srf->res);
501 return srf;
504 static inline void vmw_dmabuf_unreference(struct vmw_dma_buffer **buf)
506 struct vmw_dma_buffer *tmp_buf = *buf;
507 struct ttm_buffer_object *bo = &tmp_buf->base;
508 *buf = NULL;
510 ttm_bo_unref(&bo);
513 static inline struct vmw_dma_buffer *vmw_dmabuf_reference(struct vmw_dma_buffer *buf)
515 if (ttm_bo_reference(&buf->base))
516 return buf;
517 return NULL;
520 #endif