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 #include "vmwgfx_drv.h"
29 #include "ttm/ttm_bo_driver.h"
30 #include "ttm/ttm_placement.h"
32 static uint32_t vram_placement_flags
= TTM_PL_FLAG_VRAM
|
35 static uint32_t vram_ne_placement_flags
= TTM_PL_FLAG_VRAM
|
39 static uint32_t sys_placement_flags
= TTM_PL_FLAG_SYSTEM
|
42 struct ttm_placement vmw_vram_placement
= {
46 .placement
= &vram_placement_flags
,
47 .num_busy_placement
= 1,
48 .busy_placement
= &vram_placement_flags
51 struct ttm_placement vmw_vram_sys_placement
= {
55 .placement
= &vram_placement_flags
,
56 .num_busy_placement
= 1,
57 .busy_placement
= &sys_placement_flags
60 struct ttm_placement vmw_vram_ne_placement
= {
64 .placement
= &vram_ne_placement_flags
,
65 .num_busy_placement
= 1,
66 .busy_placement
= &vram_ne_placement_flags
69 struct ttm_placement vmw_sys_placement
= {
73 .placement
= &sys_placement_flags
,
74 .num_busy_placement
= 1,
75 .busy_placement
= &sys_placement_flags
78 struct vmw_ttm_backend
{
79 struct ttm_backend backend
;
82 static int vmw_ttm_populate(struct ttm_backend
*backend
,
83 unsigned long num_pages
, struct page
**pages
,
84 struct page
*dummy_read_page
)
89 static int vmw_ttm_bind(struct ttm_backend
*backend
, struct ttm_mem_reg
*bo_mem
)
94 static int vmw_ttm_unbind(struct ttm_backend
*backend
)
99 static void vmw_ttm_clear(struct ttm_backend
*backend
)
103 static void vmw_ttm_destroy(struct ttm_backend
*backend
)
105 struct vmw_ttm_backend
*vmw_be
=
106 container_of(backend
, struct vmw_ttm_backend
, backend
);
111 static struct ttm_backend_func vmw_ttm_func
= {
112 .populate
= vmw_ttm_populate
,
113 .clear
= vmw_ttm_clear
,
114 .bind
= vmw_ttm_bind
,
115 .unbind
= vmw_ttm_unbind
,
116 .destroy
= vmw_ttm_destroy
,
119 struct ttm_backend
*vmw_ttm_backend_init(struct ttm_bo_device
*bdev
)
121 struct vmw_ttm_backend
*vmw_be
;
123 vmw_be
= kmalloc(sizeof(*vmw_be
), GFP_KERNEL
);
127 vmw_be
->backend
.func
= &vmw_ttm_func
;
129 return &vmw_be
->backend
;
132 int vmw_invalidate_caches(struct ttm_bo_device
*bdev
, uint32_t flags
)
137 int vmw_init_mem_type(struct ttm_bo_device
*bdev
, uint32_t type
,
138 struct ttm_mem_type_manager
*man
)
140 struct vmw_private
*dev_priv
=
141 container_of(bdev
, struct vmw_private
, bdev
);
147 man
->flags
= TTM_MEMTYPE_FLAG_MAPPABLE
;
148 man
->available_caching
= TTM_PL_MASK_CACHING
;
149 man
->default_caching
= TTM_PL_FLAG_CACHED
;
152 /* "On-card" video ram */
154 man
->io_offset
= dev_priv
->vram_start
;
155 man
->io_size
= dev_priv
->vram_size
;
156 man
->flags
= TTM_MEMTYPE_FLAG_FIXED
|
157 TTM_MEMTYPE_FLAG_NEEDS_IOREMAP
| TTM_MEMTYPE_FLAG_MAPPABLE
;
159 man
->available_caching
= TTM_PL_MASK_CACHING
;
160 man
->default_caching
= TTM_PL_FLAG_WC
;
163 DRM_ERROR("Unsupported memory type %u\n", (unsigned)type
);
169 void vmw_evict_flags(struct ttm_buffer_object
*bo
,
170 struct ttm_placement
*placement
)
172 *placement
= vmw_sys_placement
;
176 * FIXME: Proper access checks on buffers.
179 static int vmw_verify_access(struct ttm_buffer_object
*bo
, struct file
*filp
)
184 static void vmw_move_notify(struct ttm_buffer_object
*bo
,
185 struct ttm_mem_reg
*new_mem
)
187 if (new_mem
->mem_type
!= TTM_PL_SYSTEM
)
188 vmw_dmabuf_gmr_unbind(bo
);
191 static void vmw_swap_notify(struct ttm_buffer_object
*bo
)
193 vmw_dmabuf_gmr_unbind(bo
);
197 * FIXME: We're using the old vmware polling method to sync.
198 * Do this with fences instead.
201 static void *vmw_sync_obj_ref(void *sync_obj
)
206 static void vmw_sync_obj_unref(void **sync_obj
)
211 static int vmw_sync_obj_flush(void *sync_obj
, void *sync_arg
)
213 struct vmw_private
*dev_priv
= (struct vmw_private
*)sync_arg
;
215 mutex_lock(&dev_priv
->hw_mutex
);
216 vmw_write(dev_priv
, SVGA_REG_SYNC
, SVGA_SYNC_GENERIC
);
217 mutex_unlock(&dev_priv
->hw_mutex
);
221 static bool vmw_sync_obj_signaled(void *sync_obj
, void *sync_arg
)
223 struct vmw_private
*dev_priv
= (struct vmw_private
*)sync_arg
;
224 uint32_t sequence
= (unsigned long) sync_obj
;
226 return vmw_fence_signaled(dev_priv
, sequence
);
229 static int vmw_sync_obj_wait(void *sync_obj
, void *sync_arg
,
230 bool lazy
, bool interruptible
)
232 struct vmw_private
*dev_priv
= (struct vmw_private
*)sync_arg
;
233 uint32_t sequence
= (unsigned long) sync_obj
;
235 return vmw_wait_fence(dev_priv
, false, sequence
, false, 3*HZ
);
238 struct ttm_bo_driver vmw_bo_driver
= {
239 .create_ttm_backend_entry
= vmw_ttm_backend_init
,
240 .invalidate_caches
= vmw_invalidate_caches
,
241 .init_mem_type
= vmw_init_mem_type
,
242 .evict_flags
= vmw_evict_flags
,
244 .verify_access
= vmw_verify_access
,
245 .sync_obj_signaled
= vmw_sync_obj_signaled
,
246 .sync_obj_wait
= vmw_sync_obj_wait
,
247 .sync_obj_flush
= vmw_sync_obj_flush
,
248 .sync_obj_unref
= vmw_sync_obj_unref
,
249 .sync_obj_ref
= vmw_sync_obj_ref
,
250 .move_notify
= vmw_move_notify
,
251 .swap_notify
= vmw_swap_notify