Loading...
1/*
2 * Copyright 2013 Red Hat Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 *
22 * Authors: Dave Airlie
23 * Alon Levy
24 */
25
26#include <linux/delay.h>
27
28#include <drm/drm.h>
29#include <drm/drm_file.h>
30#include <drm/drm_debugfs.h>
31#include <drm/qxl_drm.h>
32#include <drm/ttm/ttm_bo_api.h>
33#include <drm/ttm/ttm_bo_driver.h>
34#include <drm/ttm/ttm_module.h>
35#include <drm/ttm/ttm_page_alloc.h>
36#include <drm/ttm/ttm_placement.h>
37
38#include "qxl_drv.h"
39#include "qxl_object.h"
40
41static struct qxl_device *qxl_get_qdev(struct ttm_bo_device *bdev)
42{
43 struct qxl_mman *mman;
44 struct qxl_device *qdev;
45
46 mman = container_of(bdev, struct qxl_mman, bdev);
47 qdev = container_of(mman, struct qxl_device, mman);
48 return qdev;
49}
50
51static struct vm_operations_struct qxl_ttm_vm_ops;
52static const struct vm_operations_struct *ttm_vm_ops;
53
54static vm_fault_t qxl_ttm_fault(struct vm_fault *vmf)
55{
56 struct ttm_buffer_object *bo;
57 vm_fault_t ret;
58
59 bo = (struct ttm_buffer_object *)vmf->vma->vm_private_data;
60 if (bo == NULL)
61 return VM_FAULT_NOPAGE;
62 ret = ttm_vm_ops->fault(vmf);
63 return ret;
64}
65
66int qxl_mmap(struct file *filp, struct vm_area_struct *vma)
67{
68 int r;
69 struct drm_file *file_priv = filp->private_data;
70 struct qxl_device *qdev = file_priv->minor->dev->dev_private;
71
72 if (qdev == NULL) {
73 DRM_ERROR(
74 "filp->private_data->minor->dev->dev_private == NULL\n");
75 return -EINVAL;
76 }
77 DRM_DEBUG_DRIVER("filp->private_data = 0x%p, vma->vm_pgoff = %lx\n",
78 filp->private_data, vma->vm_pgoff);
79
80 r = ttm_bo_mmap(filp, vma, &qdev->mman.bdev);
81 if (unlikely(r != 0))
82 return r;
83 if (unlikely(ttm_vm_ops == NULL)) {
84 ttm_vm_ops = vma->vm_ops;
85 qxl_ttm_vm_ops = *ttm_vm_ops;
86 qxl_ttm_vm_ops.fault = &qxl_ttm_fault;
87 }
88 vma->vm_ops = &qxl_ttm_vm_ops;
89 return 0;
90}
91
92static int qxl_invalidate_caches(struct ttm_bo_device *bdev, uint32_t flags)
93{
94 return 0;
95}
96
97static int qxl_init_mem_type(struct ttm_bo_device *bdev, uint32_t type,
98 struct ttm_mem_type_manager *man)
99{
100 struct qxl_device *qdev = qxl_get_qdev(bdev);
101 unsigned int gpu_offset_shift =
102 64 - (qdev->rom->slot_gen_bits + qdev->rom->slot_id_bits + 8);
103 struct qxl_memslot *slot;
104
105 switch (type) {
106 case TTM_PL_SYSTEM:
107 /* System memory */
108 man->flags = TTM_MEMTYPE_FLAG_MAPPABLE;
109 man->available_caching = TTM_PL_MASK_CACHING;
110 man->default_caching = TTM_PL_FLAG_CACHED;
111 break;
112 case TTM_PL_VRAM:
113 case TTM_PL_PRIV:
114 /* "On-card" video ram */
115 slot = (type == TTM_PL_VRAM) ?
116 &qdev->main_slot : &qdev->surfaces_slot;
117 slot->gpu_offset = (uint64_t)type << gpu_offset_shift;
118 man->func = &ttm_bo_manager_func;
119 man->gpu_offset = slot->gpu_offset;
120 man->flags = TTM_MEMTYPE_FLAG_FIXED |
121 TTM_MEMTYPE_FLAG_MAPPABLE;
122 man->available_caching = TTM_PL_MASK_CACHING;
123 man->default_caching = TTM_PL_FLAG_CACHED;
124 break;
125 default:
126 DRM_ERROR("Unsupported memory type %u\n", (unsigned int)type);
127 return -EINVAL;
128 }
129 return 0;
130}
131
132static void qxl_evict_flags(struct ttm_buffer_object *bo,
133 struct ttm_placement *placement)
134{
135 struct qxl_bo *qbo;
136 static const struct ttm_place placements = {
137 .fpfn = 0,
138 .lpfn = 0,
139 .flags = TTM_PL_MASK_CACHING | TTM_PL_FLAG_SYSTEM
140 };
141
142 if (!qxl_ttm_bo_is_qxl_bo(bo)) {
143 placement->placement = &placements;
144 placement->busy_placement = &placements;
145 placement->num_placement = 1;
146 placement->num_busy_placement = 1;
147 return;
148 }
149 qbo = to_qxl_bo(bo);
150 qxl_ttm_placement_from_domain(qbo, QXL_GEM_DOMAIN_CPU, false);
151 *placement = qbo->placement;
152}
153
154static int qxl_verify_access(struct ttm_buffer_object *bo, struct file *filp)
155{
156 struct qxl_bo *qbo = to_qxl_bo(bo);
157
158 return drm_vma_node_verify_access(&qbo->tbo.base.vma_node,
159 filp->private_data);
160}
161
162static int qxl_ttm_io_mem_reserve(struct ttm_bo_device *bdev,
163 struct ttm_mem_reg *mem)
164{
165 struct ttm_mem_type_manager *man = &bdev->man[mem->mem_type];
166 struct qxl_device *qdev = qxl_get_qdev(bdev);
167
168 mem->bus.addr = NULL;
169 mem->bus.offset = 0;
170 mem->bus.size = mem->num_pages << PAGE_SHIFT;
171 mem->bus.base = 0;
172 mem->bus.is_iomem = false;
173 if (!(man->flags & TTM_MEMTYPE_FLAG_MAPPABLE))
174 return -EINVAL;
175 switch (mem->mem_type) {
176 case TTM_PL_SYSTEM:
177 /* system memory */
178 return 0;
179 case TTM_PL_VRAM:
180 mem->bus.is_iomem = true;
181 mem->bus.base = qdev->vram_base;
182 mem->bus.offset = mem->start << PAGE_SHIFT;
183 break;
184 case TTM_PL_PRIV:
185 mem->bus.is_iomem = true;
186 mem->bus.base = qdev->surfaceram_base;
187 mem->bus.offset = mem->start << PAGE_SHIFT;
188 break;
189 default:
190 return -EINVAL;
191 }
192 return 0;
193}
194
195static void qxl_ttm_io_mem_free(struct ttm_bo_device *bdev,
196 struct ttm_mem_reg *mem)
197{
198}
199
200/*
201 * TTM backend functions.
202 */
203struct qxl_ttm_tt {
204 struct ttm_tt ttm;
205 struct qxl_device *qdev;
206 u64 offset;
207};
208
209static int qxl_ttm_backend_bind(struct ttm_tt *ttm,
210 struct ttm_mem_reg *bo_mem)
211{
212 struct qxl_ttm_tt *gtt = (void *)ttm;
213
214 gtt->offset = (unsigned long)(bo_mem->start << PAGE_SHIFT);
215 if (!ttm->num_pages) {
216 WARN(1, "nothing to bind %lu pages for mreg %p back %p!\n",
217 ttm->num_pages, bo_mem, ttm);
218 }
219 /* Not implemented */
220 return -1;
221}
222
223static int qxl_ttm_backend_unbind(struct ttm_tt *ttm)
224{
225 /* Not implemented */
226 return -1;
227}
228
229static void qxl_ttm_backend_destroy(struct ttm_tt *ttm)
230{
231 struct qxl_ttm_tt *gtt = (void *)ttm;
232
233 ttm_tt_fini(>t->ttm);
234 kfree(gtt);
235}
236
237static struct ttm_backend_func qxl_backend_func = {
238 .bind = &qxl_ttm_backend_bind,
239 .unbind = &qxl_ttm_backend_unbind,
240 .destroy = &qxl_ttm_backend_destroy,
241};
242
243static struct ttm_tt *qxl_ttm_tt_create(struct ttm_buffer_object *bo,
244 uint32_t page_flags)
245{
246 struct qxl_device *qdev;
247 struct qxl_ttm_tt *gtt;
248
249 qdev = qxl_get_qdev(bo->bdev);
250 gtt = kzalloc(sizeof(struct qxl_ttm_tt), GFP_KERNEL);
251 if (gtt == NULL)
252 return NULL;
253 gtt->ttm.func = &qxl_backend_func;
254 gtt->qdev = qdev;
255 if (ttm_tt_init(>t->ttm, bo, page_flags)) {
256 kfree(gtt);
257 return NULL;
258 }
259 return >t->ttm;
260}
261
262static void qxl_move_null(struct ttm_buffer_object *bo,
263 struct ttm_mem_reg *new_mem)
264{
265 struct ttm_mem_reg *old_mem = &bo->mem;
266
267 BUG_ON(old_mem->mm_node != NULL);
268 *old_mem = *new_mem;
269 new_mem->mm_node = NULL;
270}
271
272static int qxl_bo_move(struct ttm_buffer_object *bo, bool evict,
273 struct ttm_operation_ctx *ctx,
274 struct ttm_mem_reg *new_mem)
275{
276 struct ttm_mem_reg *old_mem = &bo->mem;
277 int ret;
278
279 ret = ttm_bo_wait(bo, ctx->interruptible, ctx->no_wait_gpu);
280 if (ret)
281 return ret;
282
283 if (old_mem->mem_type == TTM_PL_SYSTEM && bo->ttm == NULL) {
284 qxl_move_null(bo, new_mem);
285 return 0;
286 }
287 return ttm_bo_move_memcpy(bo, ctx, new_mem);
288}
289
290static void qxl_bo_move_notify(struct ttm_buffer_object *bo,
291 bool evict,
292 struct ttm_mem_reg *new_mem)
293{
294 struct qxl_bo *qbo;
295 struct qxl_device *qdev;
296
297 if (!qxl_ttm_bo_is_qxl_bo(bo))
298 return;
299 qbo = to_qxl_bo(bo);
300 qdev = qbo->tbo.base.dev->dev_private;
301
302 if (bo->mem.mem_type == TTM_PL_PRIV && qbo->surface_id)
303 qxl_surface_evict(qdev, qbo, new_mem ? true : false);
304}
305
306static struct ttm_bo_driver qxl_bo_driver = {
307 .ttm_tt_create = &qxl_ttm_tt_create,
308 .invalidate_caches = &qxl_invalidate_caches,
309 .init_mem_type = &qxl_init_mem_type,
310 .eviction_valuable = ttm_bo_eviction_valuable,
311 .evict_flags = &qxl_evict_flags,
312 .move = &qxl_bo_move,
313 .verify_access = &qxl_verify_access,
314 .io_mem_reserve = &qxl_ttm_io_mem_reserve,
315 .io_mem_free = &qxl_ttm_io_mem_free,
316 .move_notify = &qxl_bo_move_notify,
317};
318
319int qxl_ttm_init(struct qxl_device *qdev)
320{
321 int r;
322 int num_io_pages; /* != rom->num_io_pages, we include surface0 */
323
324 /* No others user of address space so set it to 0 */
325 r = ttm_bo_device_init(&qdev->mman.bdev,
326 &qxl_bo_driver,
327 qdev->ddev.anon_inode->i_mapping,
328 false);
329 if (r) {
330 DRM_ERROR("failed initializing buffer object driver(%d).\n", r);
331 return r;
332 }
333 /* NOTE: this includes the framebuffer (aka surface 0) */
334 num_io_pages = qdev->rom->ram_header_offset / PAGE_SIZE;
335 r = ttm_bo_init_mm(&qdev->mman.bdev, TTM_PL_VRAM,
336 num_io_pages);
337 if (r) {
338 DRM_ERROR("Failed initializing VRAM heap.\n");
339 return r;
340 }
341 r = ttm_bo_init_mm(&qdev->mman.bdev, TTM_PL_PRIV,
342 qdev->surfaceram_size / PAGE_SIZE);
343 if (r) {
344 DRM_ERROR("Failed initializing Surfaces heap.\n");
345 return r;
346 }
347 DRM_INFO("qxl: %uM of VRAM memory size\n",
348 (unsigned int)qdev->vram_size / (1024 * 1024));
349 DRM_INFO("qxl: %luM of IO pages memory ready (VRAM domain)\n",
350 ((unsigned int)num_io_pages * PAGE_SIZE) / (1024 * 1024));
351 DRM_INFO("qxl: %uM of Surface memory size\n",
352 (unsigned int)qdev->surfaceram_size / (1024 * 1024));
353 return 0;
354}
355
356void qxl_ttm_fini(struct qxl_device *qdev)
357{
358 ttm_bo_clean_mm(&qdev->mman.bdev, TTM_PL_VRAM);
359 ttm_bo_clean_mm(&qdev->mman.bdev, TTM_PL_PRIV);
360 ttm_bo_device_release(&qdev->mman.bdev);
361 DRM_INFO("qxl: ttm finalized\n");
362}
363
364#define QXL_DEBUGFS_MEM_TYPES 2
365
366#if defined(CONFIG_DEBUG_FS)
367static int qxl_mm_dump_table(struct seq_file *m, void *data)
368{
369 struct drm_info_node *node = (struct drm_info_node *)m->private;
370 struct drm_mm *mm = (struct drm_mm *)node->info_ent->data;
371 struct drm_device *dev = node->minor->dev;
372 struct qxl_device *rdev = dev->dev_private;
373 struct ttm_bo_global *glob = rdev->mman.bdev.glob;
374 struct drm_printer p = drm_seq_file_printer(m);
375
376 spin_lock(&glob->lru_lock);
377 drm_mm_print(mm, &p);
378 spin_unlock(&glob->lru_lock);
379 return 0;
380}
381#endif
382
383int qxl_ttm_debugfs_init(struct qxl_device *qdev)
384{
385#if defined(CONFIG_DEBUG_FS)
386 static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES];
387 static char qxl_mem_types_names[QXL_DEBUGFS_MEM_TYPES][32];
388 unsigned int i;
389
390 for (i = 0; i < QXL_DEBUGFS_MEM_TYPES; i++) {
391 if (i == 0)
392 sprintf(qxl_mem_types_names[i], "qxl_mem_mm");
393 else
394 sprintf(qxl_mem_types_names[i], "qxl_surf_mm");
395 qxl_mem_types_list[i].name = qxl_mem_types_names[i];
396 qxl_mem_types_list[i].show = &qxl_mm_dump_table;
397 qxl_mem_types_list[i].driver_features = 0;
398 if (i == 0)
399 qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
400 else
401 qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_PRIV].priv;
402
403 }
404 return qxl_debugfs_add_files(qdev, qxl_mem_types_list, i);
405#else
406 return 0;
407#endif
408}
1/*
2 * Copyright 2013 Red Hat Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 *
22 * Authors: Dave Airlie
23 * Alon Levy
24 */
25
26#include <linux/delay.h>
27
28#include <drm/drm.h>
29#include <drm/drm_file.h>
30#include <drm/drm_debugfs.h>
31#include <drm/qxl_drm.h>
32#include <drm/ttm/ttm_bo.h>
33#include <drm/ttm/ttm_placement.h>
34#include <drm/ttm/ttm_range_manager.h>
35#include <drm/ttm/ttm_tt.h>
36
37#include "qxl_drv.h"
38#include "qxl_object.h"
39
40static struct qxl_device *qxl_get_qdev(struct ttm_device *bdev)
41{
42 struct qxl_mman *mman;
43 struct qxl_device *qdev;
44
45 mman = container_of(bdev, struct qxl_mman, bdev);
46 qdev = container_of(mman, struct qxl_device, mman);
47 return qdev;
48}
49
50static void qxl_evict_flags(struct ttm_buffer_object *bo,
51 struct ttm_placement *placement)
52{
53 struct qxl_bo *qbo;
54 static const struct ttm_place placements = {
55 .fpfn = 0,
56 .lpfn = 0,
57 .mem_type = TTM_PL_SYSTEM,
58 .flags = 0
59 };
60
61 if (!qxl_ttm_bo_is_qxl_bo(bo)) {
62 placement->placement = &placements;
63 placement->busy_placement = &placements;
64 placement->num_placement = 1;
65 placement->num_busy_placement = 1;
66 return;
67 }
68 qbo = to_qxl_bo(bo);
69 qxl_ttm_placement_from_domain(qbo, QXL_GEM_DOMAIN_CPU);
70 *placement = qbo->placement;
71}
72
73int qxl_ttm_io_mem_reserve(struct ttm_device *bdev,
74 struct ttm_resource *mem)
75{
76 struct qxl_device *qdev = qxl_get_qdev(bdev);
77
78 switch (mem->mem_type) {
79 case TTM_PL_SYSTEM:
80 /* system memory */
81 return 0;
82 case TTM_PL_VRAM:
83 mem->bus.is_iomem = true;
84 mem->bus.offset = (mem->start << PAGE_SHIFT) + qdev->vram_base;
85 mem->bus.caching = ttm_write_combined;
86 break;
87 case TTM_PL_PRIV:
88 mem->bus.is_iomem = true;
89 mem->bus.offset = (mem->start << PAGE_SHIFT) +
90 qdev->surfaceram_base;
91 mem->bus.caching = ttm_write_combined;
92 break;
93 default:
94 return -EINVAL;
95 }
96 return 0;
97}
98
99/*
100 * TTM backend functions.
101 */
102static void qxl_ttm_backend_destroy(struct ttm_device *bdev, struct ttm_tt *ttm)
103{
104 ttm_tt_fini(ttm);
105 kfree(ttm);
106}
107
108static struct ttm_tt *qxl_ttm_tt_create(struct ttm_buffer_object *bo,
109 uint32_t page_flags)
110{
111 struct ttm_tt *ttm;
112
113 ttm = kzalloc(sizeof(struct ttm_tt), GFP_KERNEL);
114 if (ttm == NULL)
115 return NULL;
116 if (ttm_tt_init(ttm, bo, page_flags, ttm_cached, 0)) {
117 kfree(ttm);
118 return NULL;
119 }
120 return ttm;
121}
122
123static void qxl_bo_move_notify(struct ttm_buffer_object *bo,
124 struct ttm_resource *new_mem)
125{
126 struct qxl_bo *qbo;
127 struct qxl_device *qdev;
128
129 if (!qxl_ttm_bo_is_qxl_bo(bo) || !bo->resource)
130 return;
131 qbo = to_qxl_bo(bo);
132 qdev = to_qxl(qbo->tbo.base.dev);
133
134 if (bo->resource->mem_type == TTM_PL_PRIV && qbo->surface_id)
135 qxl_surface_evict(qdev, qbo, new_mem ? true : false);
136}
137
138static int qxl_bo_move(struct ttm_buffer_object *bo, bool evict,
139 struct ttm_operation_ctx *ctx,
140 struct ttm_resource *new_mem,
141 struct ttm_place *hop)
142{
143 struct ttm_resource *old_mem = bo->resource;
144 int ret;
145
146 if (!old_mem) {
147 if (new_mem->mem_type != TTM_PL_SYSTEM) {
148 hop->mem_type = TTM_PL_SYSTEM;
149 hop->flags = TTM_PL_FLAG_TEMPORARY;
150 return -EMULTIHOP;
151 }
152
153 ttm_bo_move_null(bo, new_mem);
154 return 0;
155 }
156
157 qxl_bo_move_notify(bo, new_mem);
158
159 ret = ttm_bo_wait_ctx(bo, ctx);
160 if (ret)
161 return ret;
162
163 if (old_mem->mem_type == TTM_PL_SYSTEM && bo->ttm == NULL) {
164 ttm_bo_move_null(bo, new_mem);
165 return 0;
166 }
167 return ttm_bo_move_memcpy(bo, ctx, new_mem);
168}
169
170static void qxl_bo_delete_mem_notify(struct ttm_buffer_object *bo)
171{
172 qxl_bo_move_notify(bo, NULL);
173}
174
175static struct ttm_device_funcs qxl_bo_driver = {
176 .ttm_tt_create = &qxl_ttm_tt_create,
177 .ttm_tt_destroy = &qxl_ttm_backend_destroy,
178 .eviction_valuable = ttm_bo_eviction_valuable,
179 .evict_flags = &qxl_evict_flags,
180 .move = &qxl_bo_move,
181 .io_mem_reserve = &qxl_ttm_io_mem_reserve,
182 .delete_mem_notify = &qxl_bo_delete_mem_notify,
183};
184
185static int qxl_ttm_init_mem_type(struct qxl_device *qdev,
186 unsigned int type,
187 uint64_t size)
188{
189 return ttm_range_man_init(&qdev->mman.bdev, type, false, size);
190}
191
192int qxl_ttm_init(struct qxl_device *qdev)
193{
194 int r;
195 int num_io_pages; /* != rom->num_io_pages, we include surface0 */
196
197 /* No others user of address space so set it to 0 */
198 r = ttm_device_init(&qdev->mman.bdev, &qxl_bo_driver, NULL,
199 qdev->ddev.anon_inode->i_mapping,
200 qdev->ddev.vma_offset_manager,
201 false, false);
202 if (r) {
203 DRM_ERROR("failed initializing buffer object driver(%d).\n", r);
204 return r;
205 }
206 /* NOTE: this includes the framebuffer (aka surface 0) */
207 num_io_pages = qdev->rom->ram_header_offset / PAGE_SIZE;
208 r = qxl_ttm_init_mem_type(qdev, TTM_PL_VRAM, num_io_pages);
209 if (r) {
210 DRM_ERROR("Failed initializing VRAM heap.\n");
211 return r;
212 }
213 r = qxl_ttm_init_mem_type(qdev, TTM_PL_PRIV,
214 qdev->surfaceram_size / PAGE_SIZE);
215 if (r) {
216 DRM_ERROR("Failed initializing Surfaces heap.\n");
217 return r;
218 }
219 DRM_INFO("qxl: %uM of VRAM memory size\n",
220 (unsigned int)qdev->vram_size / (1024 * 1024));
221 DRM_INFO("qxl: %luM of IO pages memory ready (VRAM domain)\n",
222 ((unsigned int)num_io_pages * PAGE_SIZE) / (1024 * 1024));
223 DRM_INFO("qxl: %uM of Surface memory size\n",
224 (unsigned int)qdev->surfaceram_size / (1024 * 1024));
225 return 0;
226}
227
228void qxl_ttm_fini(struct qxl_device *qdev)
229{
230 ttm_range_man_fini(&qdev->mman.bdev, TTM_PL_VRAM);
231 ttm_range_man_fini(&qdev->mman.bdev, TTM_PL_PRIV);
232 ttm_device_fini(&qdev->mman.bdev);
233 DRM_INFO("qxl: ttm finalized\n");
234}
235
236void qxl_ttm_debugfs_init(struct qxl_device *qdev)
237{
238#if defined(CONFIG_DEBUG_FS)
239 ttm_resource_manager_create_debugfs(ttm_manager_type(&qdev->mman.bdev,
240 TTM_PL_VRAM),
241 qdev->ddev.primary->debugfs_root, "qxl_mem_mm");
242 ttm_resource_manager_create_debugfs(ttm_manager_type(&qdev->mman.bdev,
243 TTM_PL_PRIV),
244 qdev->ddev.primary->debugfs_root, "qxl_surf_mm");
245#endif
246}