Subversion Repositories Kolibri OS

Rev

Rev 4111 | Rev 5078 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4075 Serge 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 
33
#include 
34
#include 
4569 Serge 35
#include 
4075 Serge 36
//#include 
37
#include 
38
#include 
39
//#include 
40
#include 
41
//#include 
42
#include "vmwgfx_fence.h"
43
 
4569 Serge 44
#define VMWGFX_DRIVER_DATE "20121114"
4075 Serge 45
#define VMWGFX_DRIVER_MAJOR 2
4569 Serge 46
#define VMWGFX_DRIVER_MINOR 5
4075 Serge 47
#define VMWGFX_DRIVER_PATCHLEVEL 0
48
#define VMWGFX_FILE_PAGE_OFFSET 0x00100000
49
#define VMWGFX_FIFO_STATIC_SIZE (1024*1024)
50
#define VMWGFX_MAX_RELOCATIONS 2048
51
#define VMWGFX_MAX_VALIDATIONS 2048
52
#define VMWGFX_MAX_DISPLAYS 16
53
#define VMWGFX_CMD_BOUNCE_INIT_SIZE 32768
4569 Serge 54
#define VMWGFX_ENABLE_SCREEN_TARGET_OTABLE 0
4075 Serge 55
 
4569 Serge 56
/*
57
 * Perhaps we should have sysfs entries for these.
58
 */
59
#define VMWGFX_NUM_GB_CONTEXT 256
60
#define VMWGFX_NUM_GB_SHADER 20000
61
#define VMWGFX_NUM_GB_SURFACE 32768
62
#define VMWGFX_NUM_GB_SCREEN_TARGET VMWGFX_MAX_DISPLAYS
63
#define VMWGFX_NUM_MOB (VMWGFX_NUM_GB_CONTEXT +\
64
			VMWGFX_NUM_GB_SHADER +\
65
			VMWGFX_NUM_GB_SURFACE +\
66
			VMWGFX_NUM_GB_SCREEN_TARGET)
67
 
4075 Serge 68
#define VMW_PL_GMR TTM_PL_PRIV0
69
#define VMW_PL_FLAG_GMR TTM_PL_FLAG_PRIV0
4569 Serge 70
#define VMW_PL_MOB TTM_PL_PRIV1
71
#define VMW_PL_FLAG_MOB TTM_PL_FLAG_PRIV1
4075 Serge 72
 
73
#define VMW_RES_CONTEXT ttm_driver_type0
74
#define VMW_RES_SURFACE ttm_driver_type1
75
#define VMW_RES_STREAM ttm_driver_type2
76
#define VMW_RES_FENCE ttm_driver_type3
4569 Serge 77
#define VMW_RES_SHADER ttm_driver_type4
4075 Serge 78
 
79
#define ioread32(addr)          readl(addr)
80
 
81
static inline void outl(u32 v, u16 port)
82
{
83
    asm volatile("outl %0,%1" : : "a" (v), "dN" (port));
84
}
85
static inline u32 inl(u16 port)
86
{
87
    u32 v;
88
    asm volatile("inl %1,%0" : "=a" (v) : "dN" (port));
89
    return v;
90
}
91
 
92
struct ttm_lock{};
93
struct ww_acquire_ctx{};
94
 
95
struct vmw_fpriv {
96
//   struct drm_master *locked_master;
97
   struct ttm_object_file *tfile;
98
   struct list_head fence_events;
99
};
100
 
101
struct vmw_dma_buffer {
102
   struct ttm_buffer_object base;
103
   struct list_head res_list;
104
};
105
 
106
/**
107
 * struct vmw_validate_buffer - Carries validation info about buffers.
108
 *
109
 * @base: Validation info for TTM.
110
 * @hash: Hash entry for quick lookup of the TTM buffer object.
111
 *
112
 * This structure contains also driver private validation info
113
 * on top of the info needed by TTM.
114
 */
115
struct vmw_validate_buffer {
116
   struct ttm_validate_buffer base;
117
   struct drm_hash_item hash;
4569 Serge 118
	bool validate_as_mob;
4075 Serge 119
};
120
 
121
struct vmw_res_func;
122
struct vmw_resource {
123
	struct kref kref;
124
	struct vmw_private *dev_priv;
125
	int id;
126
	bool avail;
127
	unsigned long backup_size;
128
	bool res_dirty; /* Protected by backup buffer reserved */
129
	bool backup_dirty; /* Protected by backup buffer reserved */
130
    struct vmw_dma_buffer *backup;
131
	unsigned long backup_offset;
132
	const struct vmw_res_func *func;
133
	struct list_head lru_head; /* Protected by the resource lock */
134
	struct list_head mob_head; /* Protected by @backup reserved */
4569 Serge 135
	struct list_head binding_head; /* Protected by binding_mutex */
4075 Serge 136
	void (*res_free) (struct vmw_resource *res);
137
	void (*hw_destroy) (struct vmw_resource *res);
138
};
139
 
140
enum vmw_res_type {
141
	vmw_res_context,
142
	vmw_res_surface,
143
	vmw_res_stream,
4569 Serge 144
	vmw_res_shader,
4075 Serge 145
	vmw_res_max
146
};
147
 
148
struct vmw_cursor_snooper {
149
	struct drm_crtc *crtc;
150
	size_t age;
151
	uint32_t *image;
152
};
153
 
154
struct vmw_framebuffer;
155
struct vmw_surface_offset;
156
 
157
struct vmw_surface {
158
    struct vmw_resource res;
159
	uint32_t flags;
160
	uint32_t format;
161
	uint32_t mip_levels[DRM_VMW_MAX_SURFACE_FACES];
162
	struct drm_vmw_size base_size;
163
	struct drm_vmw_size *sizes;
164
	uint32_t num_sizes;
165
	bool scanout;
166
	/* TODO so far just a extra pointer */
167
	struct vmw_cursor_snooper snooper;
168
	struct vmw_surface_offset *offsets;
169
	SVGA3dTextureFilter autogen_filter;
170
	uint32_t multisample_count;
171
};
172
 
173
struct vmw_marker_queue {
174
	struct list_head head;
175
	struct timespec lag;
176
	struct timespec lag_time;
177
	spinlock_t lock;
178
};
179
 
180
struct vmw_fifo_state {
181
	unsigned long reserved_size;
182
	__le32 *dynamic_buffer;
183
	__le32 *static_buffer;
184
	unsigned long static_buffer_size;
185
	bool using_bounce_buffer;
186
	uint32_t capabilities;
187
	struct mutex fifo_mutex;
188
	struct rw_semaphore rwsem;
189
	struct vmw_marker_queue marker_queue;
190
};
191
 
192
struct vmw_relocation {
4569 Serge 193
	SVGAMobId *mob_loc;
4075 Serge 194
	SVGAGuestPtr *location;
195
	uint32_t index;
196
};
197
 
198
/**
199
 * struct vmw_res_cache_entry - resource information cache entry
200
 *
201
 * @valid: Whether the entry is valid, which also implies that the execbuf
202
 * code holds a reference to the resource, and it's placed on the
203
 * validation list.
204
 * @handle: User-space handle of a resource.
205
 * @res: Non-ref-counted pointer to the resource.
206
 *
207
 * Used to avoid frequent repeated user-space handle lookups of the
208
 * same resource.
209
 */
210
struct vmw_res_cache_entry {
211
	bool valid;
212
	uint32_t handle;
213
	struct vmw_resource *res;
214
	struct vmw_resource_val_node *node;
215
};
216
 
4569 Serge 217
/**
218
 * enum vmw_dma_map_mode - indicate how to perform TTM page dma mappings.
219
 */
220
enum vmw_dma_map_mode {
221
	vmw_dma_phys,           /* Use physical page addresses */
222
	vmw_dma_alloc_coherent, /* Use TTM coherent pages */
223
	vmw_dma_map_populate,   /* Unmap from DMA just after unpopulate */
224
	vmw_dma_map_bind,       /* Unmap from DMA just before unbind */
225
	vmw_dma_map_max
226
};
227
 
228
/**
229
 * struct vmw_sg_table - Scatter/gather table for binding, with additional
230
 * device-specific information.
231
 *
232
 * @sgt: Pointer to a struct sg_table with binding information
233
 * @num_regions: Number of regions with device-address contigous pages
234
 */
235
struct vmw_sg_table {
236
	enum vmw_dma_map_mode mode;
237
	struct page **pages;
238
	const dma_addr_t *addrs;
239
	struct sg_table *sgt;
240
	unsigned long num_regions;
241
	unsigned long num_pages;
242
};
243
 
244
/**
245
 * struct vmw_piter - Page iterator that iterates over a list of pages
246
 * and DMA addresses that could be either a scatter-gather list or
247
 * arrays
248
 *
249
 * @pages: Array of page pointers to the pages.
250
 * @addrs: DMA addresses to the pages if coherent pages are used.
251
 * @iter: Scatter-gather page iterator. Current position in SG list.
252
 * @i: Current position in arrays.
253
 * @num_pages: Number of pages total.
254
 * @next: Function to advance the iterator. Returns false if past the list
255
 * of pages, true otherwise.
256
 * @dma_address: Function to return the DMA address of the current page.
257
 */
258
struct vmw_piter {
259
	struct page **pages;
260
	const dma_addr_t *addrs;
261
	struct sg_page_iter iter;
262
	unsigned long i;
263
	unsigned long num_pages;
264
	bool (*next)(struct vmw_piter *);
265
	dma_addr_t (*dma_address)(struct vmw_piter *);
266
	struct page *(*page)(struct vmw_piter *);
267
};
268
 
269
/*
270
 * enum vmw_ctx_binding_type - abstract resource to context binding types
271
 */
272
enum vmw_ctx_binding_type {
273
	vmw_ctx_binding_shader,
274
	vmw_ctx_binding_rt,
275
	vmw_ctx_binding_tex,
276
	vmw_ctx_binding_max
277
};
278
 
279
/**
280
 * struct vmw_ctx_bindinfo - structure representing a single context binding
281
 *
282
 * @ctx: Pointer to the context structure. NULL means the binding is not
283
 * active.
284
 * @res: Non ref-counted pointer to the bound resource.
285
 * @bt: The binding type.
286
 * @i1: Union of information needed to unbind.
287
 */
288
struct vmw_ctx_bindinfo {
289
	struct vmw_resource *ctx;
290
	struct vmw_resource *res;
291
	enum vmw_ctx_binding_type bt;
292
	union {
293
		SVGA3dShaderType shader_type;
294
		SVGA3dRenderTargetType rt_type;
295
		uint32 texture_stage;
296
	} i1;
297
};
298
 
299
/**
300
 * struct vmw_ctx_binding - structure representing a single context binding
301
 *                        - suitable for tracking in a context
302
 *
303
 * @ctx_list: List head for context.
304
 * @res_list: List head for bound resource.
305
 * @bi: Binding info
306
 */
307
struct vmw_ctx_binding {
308
	struct list_head ctx_list;
309
	struct list_head res_list;
310
	struct vmw_ctx_bindinfo bi;
311
};
312
 
313
 
314
/**
315
 * struct vmw_ctx_binding_state - context binding state
316
 *
317
 * @list: linked list of individual bindings.
318
 * @render_targets: Render target bindings.
319
 * @texture_units: Texture units/samplers bindings.
320
 * @shaders: Shader bindings.
321
 *
322
 * Note that this structure also provides storage space for the individual
323
 * struct vmw_ctx_binding objects, so that no dynamic allocation is needed
324
 * for individual bindings.
325
 *
326
 */
327
struct vmw_ctx_binding_state {
328
	struct list_head list;
329
	struct vmw_ctx_binding render_targets[SVGA3D_RT_MAX];
330
	struct vmw_ctx_binding texture_units[SVGA3D_NUM_TEXTURE_UNITS];
331
	struct vmw_ctx_binding shaders[SVGA3D_SHADERTYPE_MAX];
332
};
333
 
4075 Serge 334
struct vmw_sw_context{
335
	struct drm_open_hash res_ht;
336
	bool res_ht_initialized;
337
	bool kernel; /**< is the called made from the kernel */
338
	struct ttm_object_file *tfile;
339
	struct list_head validate_nodes;
340
	struct vmw_relocation relocs[VMWGFX_MAX_RELOCATIONS];
341
	uint32_t cur_reloc;
342
    struct vmw_validate_buffer val_bufs[VMWGFX_MAX_VALIDATIONS];
343
	uint32_t cur_val_buf;
344
	uint32_t *cmd_bounce;
345
	uint32_t cmd_bounce_size;
346
	struct list_head resource_list;
347
	uint32_t fence_flags;
348
	struct ttm_buffer_object *cur_query_bo;
349
	struct list_head res_relocations;
350
	uint32_t *buf_start;
351
	struct vmw_res_cache_entry res_cache[vmw_res_max];
352
	struct vmw_resource *last_query_ctx;
353
	bool needs_post_query_barrier;
354
	struct vmw_resource *error_resource;
4569 Serge 355
	struct vmw_ctx_binding_state staged_bindings;
4075 Serge 356
};
357
 
358
struct vmw_legacy_display;
359
struct vmw_overlay;
360
 
361
struct vmw_master {
362
    struct ttm_lock lock;
363
	struct mutex fb_surf_mutex;
364
	struct list_head fb_surf;
365
};
366
 
367
struct vmw_vga_topology_state {
368
	uint32_t width;
369
	uint32_t height;
370
	uint32_t primary;
371
	uint32_t pos_x;
372
	uint32_t pos_y;
373
};
374
 
375
struct vmw_private {
376
    struct ttm_bo_device bdev;
377
    struct ttm_bo_global_ref bo_global_ref;
378
    struct drm_global_reference mem_global_ref;
379
 
380
	struct vmw_fifo_state fifo;
381
 
382
	struct drm_device *dev;
383
	unsigned long vmw_chipset;
384
	unsigned int io_start;
385
	uint32_t vram_start;
386
	uint32_t vram_size;
4569 Serge 387
	uint32_t prim_bb_mem;
4075 Serge 388
	uint32_t mmio_start;
389
	uint32_t mmio_size;
390
	uint32_t fb_max_width;
391
	uint32_t fb_max_height;
392
	uint32_t initial_width;
393
	uint32_t initial_height;
394
	__le32 __iomem *mmio_virt;
395
	int mmio_mtrr;
396
	uint32_t capabilities;
397
	uint32_t max_gmr_ids;
398
	uint32_t max_gmr_pages;
4569 Serge 399
	uint32_t max_mob_pages;
4075 Serge 400
	uint32_t memory_size;
401
	bool has_gmr;
4569 Serge 402
	bool has_mob;
4075 Serge 403
	struct mutex hw_mutex;
404
 
405
	/*
406
	 * VGA registers.
407
	 */
408
 
409
	struct vmw_vga_topology_state vga_save[VMWGFX_MAX_DISPLAYS];
410
	uint32_t vga_width;
411
	uint32_t vga_height;
412
	uint32_t vga_bpp;
413
	uint32_t vga_bpl;
414
	uint32_t vga_pitchlock;
415
 
416
	uint32_t num_displays;
417
 
418
	/*
419
	 * Framebuffer info.
420
	 */
421
 
422
	void *fb_info;
423
	struct vmw_legacy_display *ldu_priv;
424
	struct vmw_screen_object_display *sou_priv;
425
	struct vmw_overlay *overlay_priv;
426
 
427
	/*
428
	 * Context and surface management.
429
	 */
430
 
431
	rwlock_t resource_lock;
432
	struct idr res_idr[vmw_res_max];
433
	/*
434
	 * Block lastclose from racing with firstopen.
435
	 */
436
 
437
	struct mutex init_mutex;
438
 
439
	/*
440
	 * A resource manager for kernel-only surfaces and
441
	 * contexts.
442
	 */
443
 
444
	struct ttm_object_device *tdev;
445
 
446
	/*
447
	 * Fencing and IRQs.
448
	 */
449
 
450
	atomic_t marker_seq;
451
	wait_queue_head_t fence_queue;
452
	wait_queue_head_t fifo_queue;
453
	int fence_queue_waiters; /* Protected by hw_mutex */
454
	int goal_queue_waiters; /* Protected by hw_mutex */
455
	atomic_t fifo_queue_waiters;
456
	uint32_t last_read_seqno;
457
	spinlock_t irq_lock;
458
	struct vmw_fence_manager *fman;
459
	uint32_t irq_mask;
460
 
461
	/*
462
	 * Device state
463
	 */
464
 
465
	uint32_t traces_state;
466
	uint32_t enable_state;
467
	uint32_t config_done_state;
468
 
469
	/**
470
	 * Execbuf
471
	 */
472
	/**
473
	 * Protected by the cmdbuf mutex.
474
	 */
475
 
476
	struct vmw_sw_context ctx;
477
	struct mutex cmdbuf_mutex;
4569 Serge 478
	struct mutex binding_mutex;
4075 Serge 479
 
480
	/**
481
	 * Operating mode.
482
	 */
483
 
484
	bool stealth;
485
	bool enable_fb;
486
 
487
	/**
488
	 * Master management.
489
	 */
490
 
4569 Serge 491
	struct vmw_master *active_master;
492
	struct vmw_master fbdev_master;
493
//	struct notifier_block pm_nb;
4075 Serge 494
	bool suspended;
495
 
496
	struct mutex release_mutex;
497
	uint32_t num_3d_resources;
498
 
499
	/*
500
	 * Query processing. These members
501
	 * are protected by the cmdbuf mutex.
502
	 */
503
 
504
    struct ttm_buffer_object *dummy_query_bo;
505
    struct ttm_buffer_object *pinned_bo;
506
	uint32_t query_cid;
507
	uint32_t query_cid_valid;
508
	bool dummy_query_bo_pinned;
509
 
510
	/*
511
	 * Surface swapping. The "surface_lru" list is protected by the
512
	 * resource lock in order to be able to destroy a surface and take
513
	 * it off the lru atomically. "used_memory_size" is currently
514
	 * protected by the cmdbuf mutex for simplicity.
515
	 */
516
 
517
	struct list_head res_lru[vmw_res_max];
518
	uint32_t used_memory_size;
4569 Serge 519
 
520
	/*
521
	 * DMA mapping stuff.
522
	 */
523
	enum vmw_dma_map_mode map_mode;
524
 
525
	/*
526
	 * Guest Backed stuff
527
	 */
528
	struct ttm_buffer_object *otable_bo;
529
	struct vmw_otable *otables;
4075 Serge 530
};
531
 
532
static inline struct vmw_surface *vmw_res_to_srf(struct vmw_resource *res)
533
{
534
	return container_of(res, struct vmw_surface, res);
535
}
536
 
537
static inline struct vmw_private *vmw_priv(struct drm_device *dev)
538
{
539
	return (struct vmw_private *)dev->dev_private;
540
}
541
 
542
static inline struct vmw_fpriv *vmw_fpriv(struct drm_file *file_priv)
543
{
544
	return (struct vmw_fpriv *)file_priv->driver_priv;
545
}
546
 
547
static inline struct vmw_master *vmw_master(struct drm_master *master)
548
{
549
	return (struct vmw_master *) master->driver_priv;
550
}
551
 
552
static inline void vmw_write(struct vmw_private *dev_priv,
553
			     unsigned int offset, uint32_t value)
554
{
555
	outl(offset, dev_priv->io_start + VMWGFX_INDEX_PORT);
556
	outl(value, dev_priv->io_start + VMWGFX_VALUE_PORT);
557
}
558
 
559
static inline uint32_t vmw_read(struct vmw_private *dev_priv,
560
				unsigned int offset)
561
{
562
	uint32_t val;
563
 
564
	outl(offset, dev_priv->io_start + VMWGFX_INDEX_PORT);
565
	val = inl(dev_priv->io_start + VMWGFX_VALUE_PORT);
566
	return val;
567
}
568
 
569
int vmw_3d_resource_inc(struct vmw_private *dev_priv, bool unhide_svga);
570
void vmw_3d_resource_dec(struct vmw_private *dev_priv, bool hide_svga);
571
 
572
/**
573
 * GMR utilities - vmwgfx_gmr.c
574
 */
575
 
576
extern int vmw_gmr_bind(struct vmw_private *dev_priv,
4569 Serge 577
			const struct vmw_sg_table *vsgt,
4075 Serge 578
			unsigned long num_pages,
579
			int gmr_id);
580
extern void vmw_gmr_unbind(struct vmw_private *dev_priv, int gmr_id);
581
 
582
/**
583
 * Resource utilities - vmwgfx_resource.c
584
 */
585
struct vmw_user_resource_conv;
586
 
587
extern void vmw_resource_unreference(struct vmw_resource **p_res);
588
extern struct vmw_resource *vmw_resource_reference(struct vmw_resource *res);
589
extern int vmw_resource_validate(struct vmw_resource *res);
590
extern int vmw_resource_reserve(struct vmw_resource *res, bool no_backup);
591
extern bool vmw_resource_needs_backup(const struct vmw_resource *res);
592
extern int vmw_user_lookup_handle(struct vmw_private *dev_priv,
593
				  struct ttm_object_file *tfile,
594
				  uint32_t handle,
595
				  struct vmw_surface **out_surf,
596
				  struct vmw_dma_buffer **out_buf);
597
extern int vmw_user_resource_lookup_handle(
598
	struct vmw_private *dev_priv,
599
	struct ttm_object_file *tfile,
600
	uint32_t handle,
601
	const struct vmw_user_resource_conv *converter,
602
	struct vmw_resource **p_res);
603
extern void vmw_dmabuf_bo_free(struct ttm_buffer_object *bo);
604
extern int vmw_dmabuf_init(struct vmw_private *dev_priv,
605
			   struct vmw_dma_buffer *vmw_bo,
606
			   size_t size, struct ttm_placement *placement,
607
			   bool interuptable,
608
			   void (*bo_free) (struct ttm_buffer_object *bo));
609
extern int vmw_user_dmabuf_verify_access(struct ttm_buffer_object *bo,
610
				  struct ttm_object_file *tfile);
4569 Serge 611
extern int vmw_user_dmabuf_alloc(struct vmw_private *dev_priv,
612
				 struct ttm_object_file *tfile,
613
				 uint32_t size,
614
				 bool shareable,
615
				 uint32_t *handle,
616
				 struct vmw_dma_buffer **p_dma_buf);
617
extern int vmw_user_dmabuf_reference(struct ttm_object_file *tfile,
618
				     struct vmw_dma_buffer *dma_buf,
619
				     uint32_t *handle);
4075 Serge 620
extern int vmw_dmabuf_alloc_ioctl(struct drm_device *dev, void *data,
621
				  struct drm_file *file_priv);
622
extern int vmw_dmabuf_unref_ioctl(struct drm_device *dev, void *data,
623
				  struct drm_file *file_priv);
4569 Serge 624
extern int vmw_user_dmabuf_synccpu_ioctl(struct drm_device *dev, void *data,
625
					 struct drm_file *file_priv);
4075 Serge 626
extern uint32_t vmw_dmabuf_validate_node(struct ttm_buffer_object *bo,
627
					 uint32_t cur_validate_node);
628
extern void vmw_dmabuf_validate_clear(struct ttm_buffer_object *bo);
629
extern int vmw_user_dmabuf_lookup(struct ttm_object_file *tfile,
630
				  uint32_t id, struct vmw_dma_buffer **out);
631
extern int vmw_stream_claim_ioctl(struct drm_device *dev, void *data,
632
				  struct drm_file *file_priv);
633
extern int vmw_stream_unref_ioctl(struct drm_device *dev, void *data,
634
				  struct drm_file *file_priv);
635
extern int vmw_user_stream_lookup(struct vmw_private *dev_priv,
636
				  struct ttm_object_file *tfile,
637
				  uint32_t *inout_id,
638
				  struct vmw_resource **out);
639
extern void vmw_resource_unreserve(struct vmw_resource *res,
640
				   struct vmw_dma_buffer *new_backup,
641
				   unsigned long new_backup_offset);
642
extern void vmw_resource_move_notify(struct ttm_buffer_object *bo,
643
				     struct ttm_mem_reg *mem);
644
extern void vmw_fence_single_bo(struct ttm_buffer_object *bo,
645
				struct vmw_fence_obj *fence);
646
extern void vmw_resource_evict_all(struct vmw_private *dev_priv);
647
 
648
/**
649
 * DMA buffer helper routines - vmwgfx_dmabuf.c
650
 */
651
extern int vmw_dmabuf_to_placement(struct vmw_private *vmw_priv,
652
				   struct vmw_dma_buffer *bo,
653
				   struct ttm_placement *placement,
654
				   bool interruptible);
655
extern int vmw_dmabuf_to_vram(struct vmw_private *dev_priv,
656
			      struct vmw_dma_buffer *buf,
657
			      bool pin, bool interruptible);
658
extern int vmw_dmabuf_to_vram_or_gmr(struct vmw_private *dev_priv,
659
				     struct vmw_dma_buffer *buf,
660
				     bool pin, bool interruptible);
661
extern int vmw_dmabuf_to_start_of_vram(struct vmw_private *vmw_priv,
662
				       struct vmw_dma_buffer *bo,
663
				       bool pin, bool interruptible);
664
extern int vmw_dmabuf_unpin(struct vmw_private *vmw_priv,
665
			    struct vmw_dma_buffer *bo,
666
			    bool interruptible);
667
extern void vmw_bo_get_guest_ptr(const struct ttm_buffer_object *buf,
668
				 SVGAGuestPtr *ptr);
669
extern void vmw_bo_pin(struct ttm_buffer_object *bo, bool pin);
670
 
671
/**
672
 * Misc Ioctl functionality - vmwgfx_ioctl.c
673
 */
674
 
675
extern int vmw_getparam_ioctl(struct drm_device *dev, void *data,
676
			      struct drm_file *file_priv);
677
extern int vmw_get_cap_3d_ioctl(struct drm_device *dev, void *data,
678
				struct drm_file *file_priv);
679
extern int vmw_present_ioctl(struct drm_device *dev, void *data,
680
			     struct drm_file *file_priv);
681
extern int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
682
				      struct drm_file *file_priv);
683
extern ssize_t vmw_fops_read(struct file *filp, char __user *buffer,
684
			     size_t count, loff_t *offset);
685
 
686
/**
687
 * Fifo utilities - vmwgfx_fifo.c
688
 */
689
 
690
extern int vmw_fifo_init(struct vmw_private *dev_priv,
691
			 struct vmw_fifo_state *fifo);
692
extern void vmw_fifo_release(struct vmw_private *dev_priv,
693
			     struct vmw_fifo_state *fifo);
694
extern void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes);
695
extern void vmw_fifo_commit(struct vmw_private *dev_priv, uint32_t bytes);
696
extern int vmw_fifo_send_fence(struct vmw_private *dev_priv,
697
			       uint32_t *seqno);
698
extern void vmw_fifo_ping_host(struct vmw_private *dev_priv, uint32_t reason);
699
extern bool vmw_fifo_have_3d(struct vmw_private *dev_priv);
700
extern bool vmw_fifo_have_pitchlock(struct vmw_private *dev_priv);
701
extern int vmw_fifo_emit_dummy_query(struct vmw_private *dev_priv,
702
				     uint32_t cid);
703
 
704
/**
705
 * TTM glue - vmwgfx_ttm_glue.c
706
 */
707
 
708
extern int vmw_ttm_global_init(struct vmw_private *dev_priv);
709
extern void vmw_ttm_global_release(struct vmw_private *dev_priv);
710
extern int vmw_mmap(struct file *filp, struct vm_area_struct *vma);
711
 
712
/**
713
 * TTM buffer object driver - vmwgfx_buffer.c
714
 */
715
 
4569 Serge 716
extern const size_t vmw_tt_size;
4075 Serge 717
extern struct ttm_placement vmw_vram_placement;
718
extern struct ttm_placement vmw_vram_ne_placement;
719
extern struct ttm_placement vmw_vram_sys_placement;
720
extern struct ttm_placement vmw_vram_gmr_placement;
721
extern struct ttm_placement vmw_vram_gmr_ne_placement;
722
extern struct ttm_placement vmw_sys_placement;
4569 Serge 723
extern struct ttm_placement vmw_sys_ne_placement;
4075 Serge 724
extern struct ttm_placement vmw_evictable_placement;
725
extern struct ttm_placement vmw_srf_placement;
4569 Serge 726
extern struct ttm_placement vmw_mob_placement;
4075 Serge 727
extern struct ttm_bo_driver vmw_bo_driver;
728
extern int vmw_dma_quiescent(struct drm_device *dev);
4569 Serge 729
extern int vmw_bo_map_dma(struct ttm_buffer_object *bo);
730
extern void vmw_bo_unmap_dma(struct ttm_buffer_object *bo);
731
extern const struct vmw_sg_table *
732
vmw_bo_sg_table(struct ttm_buffer_object *bo);
733
extern void vmw_piter_start(struct vmw_piter *viter,
734
			    const struct vmw_sg_table *vsgt,
735
			    unsigned long p_offs);
4075 Serge 736
 
737
/**
4569 Serge 738
 * vmw_piter_next - Advance the iterator one page.
739
 *
740
 * @viter: Pointer to the iterator to advance.
741
 *
742
 * Returns false if past the list of pages, true otherwise.
743
 */
744
static inline bool vmw_piter_next(struct vmw_piter *viter)
745
{
746
	return viter->next(viter);
747
}
748
 
749
/**
750
 * vmw_piter_dma_addr - Return the DMA address of the current page.
751
 *
752
 * @viter: Pointer to the iterator
753
 *
754
 * Returns the DMA address of the page pointed to by @viter.
755
 */
756
static inline dma_addr_t vmw_piter_dma_addr(struct vmw_piter *viter)
757
{
758
	return viter->dma_address(viter);
759
}
760
 
761
/**
762
 * vmw_piter_page - Return a pointer to the current page.
763
 *
764
 * @viter: Pointer to the iterator
765
 *
766
 * Returns the DMA address of the page pointed to by @viter.
767
 */
768
static inline struct page *vmw_piter_page(struct vmw_piter *viter)
769
{
770
	return viter->page(viter);
771
}
772
 
773
/**
4075 Serge 774
 * Command submission - vmwgfx_execbuf.c
775
 */
776
 
777
extern int vmw_execbuf_ioctl(struct drm_device *dev, void *data,
778
			     struct drm_file *file_priv);
779
extern int vmw_execbuf_process(struct drm_file *file_priv,
780
			       struct vmw_private *dev_priv,
781
			       void __user *user_commands,
782
			       void *kernel_commands,
783
			       uint32_t command_size,
784
			       uint64_t throttle_us,
785
			       struct drm_vmw_fence_rep __user
786
			       *user_fence_rep,
787
			       struct vmw_fence_obj **out_fence);
788
extern void __vmw_execbuf_release_pinned_bo(struct vmw_private *dev_priv,
789
					    struct vmw_fence_obj *fence);
790
extern void vmw_execbuf_release_pinned_bo(struct vmw_private *dev_priv);
791
 
792
extern int vmw_execbuf_fence_commands(struct drm_file *file_priv,
793
				      struct vmw_private *dev_priv,
794
				      struct vmw_fence_obj **p_fence,
795
				      uint32_t *p_handle);
796
extern void vmw_execbuf_copy_fence_user(struct vmw_private *dev_priv,
797
					struct vmw_fpriv *vmw_fp,
798
					int ret,
799
					struct drm_vmw_fence_rep __user
800
					*user_fence_rep,
801
					struct vmw_fence_obj *fence,
802
					uint32_t fence_handle);
803
 
804
/**
805
 * IRQs and wating - vmwgfx_irq.c
806
 */
807
 
4569 Serge 808
extern irqreturn_t vmw_irq_handler(int irq, void *arg);
4075 Serge 809
extern int vmw_wait_seqno(struct vmw_private *dev_priv, bool lazy,
810
			     uint32_t seqno, bool interruptible,
811
			     unsigned long timeout);
812
extern void vmw_irq_preinstall(struct drm_device *dev);
813
extern int vmw_irq_postinstall(struct drm_device *dev);
814
extern void vmw_irq_uninstall(struct drm_device *dev);
815
extern bool vmw_seqno_passed(struct vmw_private *dev_priv,
816
				uint32_t seqno);
817
extern int vmw_fallback_wait(struct vmw_private *dev_priv,
818
			     bool lazy,
819
			     bool fifo_idle,
820
			     uint32_t seqno,
821
			     bool interruptible,
822
			     unsigned long timeout);
823
extern void vmw_update_seqno(struct vmw_private *dev_priv,
824
				struct vmw_fifo_state *fifo_state);
825
extern void vmw_seqno_waiter_add(struct vmw_private *dev_priv);
826
extern void vmw_seqno_waiter_remove(struct vmw_private *dev_priv);
827
extern void vmw_goal_waiter_add(struct vmw_private *dev_priv);
828
extern void vmw_goal_waiter_remove(struct vmw_private *dev_priv);
829
 
830
/**
831
 * Rudimentary fence-like objects currently used only for throttling -
832
 * vmwgfx_marker.c
833
 */
834
 
835
extern void vmw_marker_queue_init(struct vmw_marker_queue *queue);
836
extern void vmw_marker_queue_takedown(struct vmw_marker_queue *queue);
837
extern int vmw_marker_push(struct vmw_marker_queue *queue,
838
			  uint32_t seqno);
839
extern int vmw_marker_pull(struct vmw_marker_queue *queue,
840
			  uint32_t signaled_seqno);
841
extern int vmw_wait_lag(struct vmw_private *dev_priv,
842
			struct vmw_marker_queue *queue, uint32_t us);
843
 
844
/**
845
 * Kernel framebuffer - vmwgfx_fb.c
846
 */
847
 
848
int vmw_fb_init(struct vmw_private *vmw_priv);
849
int vmw_fb_close(struct vmw_private *dev_priv);
850
int vmw_fb_off(struct vmw_private *vmw_priv);
851
int vmw_fb_on(struct vmw_private *vmw_priv);
852
 
853
/**
854
 * Kernel modesetting - vmwgfx_kms.c
855
 */
856
 
857
int vmw_kms_init(struct vmw_private *dev_priv);
858
int vmw_kms_close(struct vmw_private *dev_priv);
859
int vmw_kms_save_vga(struct vmw_private *vmw_priv);
860
int vmw_kms_restore_vga(struct vmw_private *vmw_priv);
861
int vmw_kms_cursor_bypass_ioctl(struct drm_device *dev, void *data,
862
				struct drm_file *file_priv);
863
void vmw_kms_cursor_post_execbuf(struct vmw_private *dev_priv);
864
void vmw_kms_cursor_snoop(struct vmw_surface *srf,
865
			  struct ttm_object_file *tfile,
866
			  struct ttm_buffer_object *bo,
867
			  SVGA3dCmdHeader *header);
868
int vmw_kms_write_svga(struct vmw_private *vmw_priv,
869
		       unsigned width, unsigned height, unsigned pitch,
870
		       unsigned bpp, unsigned depth);
871
void vmw_kms_idle_workqueues(struct vmw_master *vmaster);
872
bool vmw_kms_validate_mode_vram(struct vmw_private *dev_priv,
873
				uint32_t pitch,
874
				uint32_t height);
875
u32 vmw_get_vblank_counter(struct drm_device *dev, int crtc);
876
int vmw_enable_vblank(struct drm_device *dev, int crtc);
877
void vmw_disable_vblank(struct drm_device *dev, int crtc);
878
int vmw_kms_present(struct vmw_private *dev_priv,
879
		    struct drm_file *file_priv,
880
		    struct vmw_framebuffer *vfb,
881
		    struct vmw_surface *surface,
882
		    uint32_t sid, int32_t destX, int32_t destY,
883
		    struct drm_vmw_rect *clips,
884
		    uint32_t num_clips);
885
int vmw_kms_readback(struct vmw_private *dev_priv,
886
		     struct drm_file *file_priv,
887
		     struct vmw_framebuffer *vfb,
888
		     struct drm_vmw_fence_rep __user *user_fence_rep,
889
		     struct drm_vmw_rect *clips,
890
		     uint32_t num_clips);
891
int vmw_kms_update_layout_ioctl(struct drm_device *dev, void *data,
892
				struct drm_file *file_priv);
893
 
894
int vmw_dumb_create(struct drm_file *file_priv,
895
		    struct drm_device *dev,
896
		    struct drm_mode_create_dumb *args);
897
 
898
int vmw_dumb_map_offset(struct drm_file *file_priv,
899
			struct drm_device *dev, uint32_t handle,
900
			uint64_t *offset);
901
int vmw_dumb_destroy(struct drm_file *file_priv,
902
		     struct drm_device *dev,
903
		     uint32_t handle);
904
/**
905
 * Overlay control - vmwgfx_overlay.c
906
 */
907
 
908
int vmw_overlay_init(struct vmw_private *dev_priv);
909
int vmw_overlay_close(struct vmw_private *dev_priv);
910
int vmw_overlay_ioctl(struct drm_device *dev, void *data,
911
		      struct drm_file *file_priv);
912
int vmw_overlay_stop_all(struct vmw_private *dev_priv);
913
int vmw_overlay_resume_all(struct vmw_private *dev_priv);
914
int vmw_overlay_pause_all(struct vmw_private *dev_priv);
915
int vmw_overlay_claim(struct vmw_private *dev_priv, uint32_t *out);
916
int vmw_overlay_unref(struct vmw_private *dev_priv, uint32_t stream_id);
917
int vmw_overlay_num_overlays(struct vmw_private *dev_priv);
918
int vmw_overlay_num_free_overlays(struct vmw_private *dev_priv);
919
 
920
/**
921
 * GMR Id manager
922
 */
923
 
924
extern const struct ttm_mem_type_manager_func vmw_gmrid_manager_func;
925
 
926
/**
4569 Serge 927
/*
928
 * MemoryOBject management -  vmwgfx_mob.c
929
 */
930
struct vmw_mob;
931
extern int vmw_mob_bind(struct vmw_private *dev_priv, struct vmw_mob *mob,
932
			const struct vmw_sg_table *vsgt,
933
			unsigned long num_data_pages, int32_t mob_id);
934
extern void vmw_mob_unbind(struct vmw_private *dev_priv,
935
			   struct vmw_mob *mob);
936
extern void vmw_mob_destroy(struct vmw_mob *mob);
937
extern struct vmw_mob *vmw_mob_create(unsigned long data_pages);
938
extern int vmw_otables_setup(struct vmw_private *dev_priv);
939
extern void vmw_otables_takedown(struct vmw_private *dev_priv);
940
 
941
/*
942
 * Context management - vmwgfx_context.c
943
 */
944
 
945
extern const struct vmw_user_resource_conv *user_context_converter;
946
 
947
extern struct vmw_resource *vmw_context_alloc(struct vmw_private *dev_priv);
948
 
949
extern int vmw_context_check(struct vmw_private *dev_priv,
950
			     struct ttm_object_file *tfile,
951
			     int id,
952
			     struct vmw_resource **p_res);
953
extern int vmw_context_define_ioctl(struct drm_device *dev, void *data,
954
				    struct drm_file *file_priv);
955
extern int vmw_context_destroy_ioctl(struct drm_device *dev, void *data,
956
				     struct drm_file *file_priv);
957
extern int vmw_context_binding_add(struct vmw_ctx_binding_state *cbs,
958
				   const struct vmw_ctx_bindinfo *ci);
959
extern void
960
vmw_context_binding_state_transfer(struct vmw_resource *res,
961
				   struct vmw_ctx_binding_state *cbs);
962
extern void vmw_context_binding_res_list_kill(struct list_head *head);
963
 
964
/*
965
 * Surface management - vmwgfx_surface.c
966
 */
967
 
968
extern const struct vmw_user_resource_conv *user_surface_converter;
969
 
970
extern void vmw_surface_res_free(struct vmw_resource *res);
971
extern int vmw_surface_check(struct vmw_private *dev_priv,
972
			     struct ttm_object_file *tfile,
973
			     uint32_t handle, int *id);
974
extern int vmw_surface_validate(struct vmw_private *dev_priv,
975
				struct vmw_surface *srf);
976
 
977
/*
978
 * Shader management - vmwgfx_shader.c
979
 */
980
 
981
extern const struct vmw_user_resource_conv *user_shader_converter;
982
/**
4075 Serge 983
 * Inline helper functions
984
 */
985
 
986
static inline void vmw_surface_unreference(struct vmw_surface **srf)
987
{
988
	struct vmw_surface *tmp_srf = *srf;
989
	struct vmw_resource *res = &tmp_srf->res;
990
	*srf = NULL;
991
 
992
	vmw_resource_unreference(&res);
993
}
994
 
995
static inline struct vmw_surface *vmw_surface_reference(struct vmw_surface *srf)
996
{
997
	(void) vmw_resource_reference(&srf->res);
998
	return srf;
999
}
1000
 
1001
static inline void vmw_dmabuf_unreference(struct vmw_dma_buffer **buf)
1002
{
1003
	struct vmw_dma_buffer *tmp_buf = *buf;
1004
 
1005
	*buf = NULL;
1006
	if (tmp_buf != NULL) {
1007
		struct ttm_buffer_object *bo = &tmp_buf->base;
1008
 
1009
		ttm_bo_unref(&bo);
1010
	}
1011
}
1012
 
1013
static inline struct vmw_dma_buffer *vmw_dmabuf_reference(struct vmw_dma_buffer *buf)
1014
{
1015
	if (ttm_bo_reference(&buf->base))
1016
		return buf;
1017
	return NULL;
1018
}
1019
 
1020
static inline struct ttm_mem_global *vmw_mem_glob(struct vmw_private *dev_priv)
1021
{
1022
	return (struct ttm_mem_global *) dev_priv->mem_global_ref.object;
1023
}
1024
 
4111 Serge 1025
extern struct drm_device *main_device;
1026
extern struct drm_file   *drm_file_handlers[256];
1027
 
4080 Serge 1028
typedef struct
1029
{
1030
  int width;
1031
  int height;
1032
  int bpp;
1033
  int freq;
1034
}videomode_t;
4075 Serge 1035
 
1036
#endif