aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c
diff options
context:
space:
mode:
authorJerome Glisse <jglisse@redhat.com>2011-11-01 20:46:13 -0400
committerDave Airlie <airlied@redhat.com>2011-12-06 05:39:17 -0500
commit649bf3ca77343e3be1e0af8e21356fa569b1abd9 (patch)
tree01ad6a5f3f74b087cb791f5965d3190916975789 /drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c
parent822c4d9ae0d55a4fcea9f0a462bc6406a06692e2 (diff)
drm/ttm: merge ttm_backend and ttm_tt V5
ttm_backend will only exist with a ttm_tt, and ttm_tt will only be of interest when bound to a backend. Merge them to avoid code and data duplication. V2 Rebase on top of memory accounting overhaul V3 Rebase on top of more memory accounting changes V4 Rebase on top of no memory account changes (where/when is my delorean when i need it ?) V5 make sure ttm is unbound before destroying, change commit message on suggestion from Tormod Volden Signed-off-by: Jerome Glisse <jglisse@redhat.com> Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> Reviewed-by: Thomas Hellstrom <thellstrom@vmware.com>
Diffstat (limited to 'drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c')
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c66
1 files changed, 21 insertions, 45 deletions
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c b/drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c
index 5a72ed90823..cc724359242 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c
@@ -139,85 +139,61 @@ struct ttm_placement vmw_srf_placement = {
139 .busy_placement = gmr_vram_placement_flags 139 .busy_placement = gmr_vram_placement_flags
140}; 140};
141 141
142struct vmw_ttm_backend { 142struct vmw_ttm_tt {
143 struct ttm_backend backend; 143 struct ttm_tt ttm;
144 struct page **pages;
145 unsigned long num_pages;
146 struct vmw_private *dev_priv; 144 struct vmw_private *dev_priv;
147 int gmr_id; 145 int gmr_id;
148}; 146};
149 147
150static int vmw_ttm_populate(struct ttm_backend *backend, 148static int vmw_ttm_bind(struct ttm_tt *ttm, struct ttm_mem_reg *bo_mem)
151 unsigned long num_pages, struct page **pages,
152 struct page *dummy_read_page,
153 dma_addr_t *dma_addrs)
154{ 149{
155 struct vmw_ttm_backend *vmw_be = 150 struct vmw_ttm_tt *vmw_be = container_of(ttm, struct vmw_ttm_tt, ttm);
156 container_of(backend, struct vmw_ttm_backend, backend);
157
158 vmw_be->pages = pages;
159 vmw_be->num_pages = num_pages;
160
161 return 0;
162}
163
164static int vmw_ttm_bind(struct ttm_backend *backend, struct ttm_mem_reg *bo_mem)
165{
166 struct vmw_ttm_backend *vmw_be =
167 container_of(backend, struct vmw_ttm_backend, backend);
168 151
169 vmw_be->gmr_id = bo_mem->start; 152 vmw_be->gmr_id = bo_mem->start;
170 153
171 return vmw_gmr_bind(vmw_be->dev_priv, vmw_be->pages, 154 return vmw_gmr_bind(vmw_be->dev_priv, ttm->pages,
172 vmw_be->num_pages, vmw_be->gmr_id); 155 ttm->num_pages, vmw_be->gmr_id);
173} 156}
174 157
175static int vmw_ttm_unbind(struct ttm_backend *backend) 158static int vmw_ttm_unbind(struct ttm_tt *ttm)
176{ 159{
177 struct vmw_ttm_backend *vmw_be = 160 struct vmw_ttm_tt *vmw_be = container_of(ttm, struct vmw_ttm_tt, ttm);
178 container_of(backend, struct vmw_ttm_backend, backend);
179 161
180 vmw_gmr_unbind(vmw_be->dev_priv, vmw_be->gmr_id); 162 vmw_gmr_unbind(vmw_be->dev_priv, vmw_be->gmr_id);
181 return 0; 163 return 0;
182} 164}
183 165
184static void vmw_ttm_clear(struct ttm_backend *backend) 166static void vmw_ttm_destroy(struct ttm_tt *ttm)
185{ 167{
186 struct vmw_ttm_backend *vmw_be = 168 struct vmw_ttm_tt *vmw_be = container_of(ttm, struct vmw_ttm_tt, ttm);
187 container_of(backend, struct vmw_ttm_backend, backend);
188
189 vmw_be->pages = NULL;
190 vmw_be->num_pages = 0;
191}
192
193static void vmw_ttm_destroy(struct ttm_backend *backend)
194{
195 struct vmw_ttm_backend *vmw_be =
196 container_of(backend, struct vmw_ttm_backend, backend);
197 169
198 kfree(vmw_be); 170 kfree(vmw_be);
199} 171}
200 172
201static struct ttm_backend_func vmw_ttm_func = { 173static struct ttm_backend_func vmw_ttm_func = {
202 .populate = vmw_ttm_populate,
203 .clear = vmw_ttm_clear,
204 .bind = vmw_ttm_bind, 174 .bind = vmw_ttm_bind,
205 .unbind = vmw_ttm_unbind, 175 .unbind = vmw_ttm_unbind,
206 .destroy = vmw_ttm_destroy, 176 .destroy = vmw_ttm_destroy,
207}; 177};
208 178
209struct ttm_backend *vmw_ttm_backend_init(struct ttm_bo_device *bdev) 179struct ttm_tt *vmw_ttm_tt_create(struct ttm_bo_device *bdev,
180 unsigned long size, uint32_t page_flags,
181 struct page *dummy_read_page)
210{ 182{
211 struct vmw_ttm_backend *vmw_be; 183 struct vmw_ttm_tt *vmw_be;
212 184
213 vmw_be = kmalloc(sizeof(*vmw_be), GFP_KERNEL); 185 vmw_be = kmalloc(sizeof(*vmw_be), GFP_KERNEL);
214 if (!vmw_be) 186 if (!vmw_be)
215 return NULL; 187 return NULL;
216 188
217 vmw_be->backend.func = &vmw_ttm_func; 189 vmw_be->ttm.func = &vmw_ttm_func;
218 vmw_be->dev_priv = container_of(bdev, struct vmw_private, bdev); 190 vmw_be->dev_priv = container_of(bdev, struct vmw_private, bdev);
219 191
220 return &vmw_be->backend; 192 if (ttm_tt_init(&vmw_be->ttm, bdev, size, page_flags, dummy_read_page)) {
193 return NULL;
194 }
195
196 return &vmw_be->ttm;
221} 197}
222 198
223int vmw_invalidate_caches(struct ttm_bo_device *bdev, uint32_t flags) 199int vmw_invalidate_caches(struct ttm_bo_device *bdev, uint32_t flags)
@@ -357,7 +333,7 @@ static int vmw_sync_obj_wait(void *sync_obj, void *sync_arg,
357} 333}
358 334
359struct ttm_bo_driver vmw_bo_driver = { 335struct ttm_bo_driver vmw_bo_driver = {
360 .create_ttm_backend_entry = vmw_ttm_backend_init, 336 .ttm_tt_create = &vmw_ttm_tt_create,
361 .invalidate_caches = vmw_invalidate_caches, 337 .invalidate_caches = vmw_invalidate_caches,
362 .init_mem_type = vmw_init_mem_type, 338 .init_mem_type = vmw_init_mem_type,
363 .evict_flags = vmw_evict_flags, 339 .evict_flags = vmw_evict_flags,