| .. | .. |
|---|
| 23 | 23 | * Alon Levy |
|---|
| 24 | 24 | */ |
|---|
| 25 | 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> |
|---|
| 26 | 32 | #include <drm/ttm/ttm_bo_api.h> |
|---|
| 27 | 33 | #include <drm/ttm/ttm_bo_driver.h> |
|---|
| 28 | | -#include <drm/ttm/ttm_placement.h> |
|---|
| 29 | | -#include <drm/ttm/ttm_page_alloc.h> |
|---|
| 30 | 34 | #include <drm/ttm/ttm_module.h> |
|---|
| 31 | | -#include <drm/drmP.h> |
|---|
| 32 | | -#include <drm/drm.h> |
|---|
| 33 | | -#include <drm/qxl_drm.h> |
|---|
| 35 | +#include <drm/ttm/ttm_page_alloc.h> |
|---|
| 36 | +#include <drm/ttm/ttm_placement.h> |
|---|
| 37 | + |
|---|
| 34 | 38 | #include "qxl_drv.h" |
|---|
| 35 | 39 | #include "qxl_object.h" |
|---|
| 36 | | - |
|---|
| 37 | | -#include <linux/delay.h> |
|---|
| 38 | 40 | |
|---|
| 39 | 41 | static struct qxl_device *qxl_get_qdev(struct ttm_bo_device *bdev) |
|---|
| 40 | 42 | { |
|---|
| .. | .. |
|---|
| 46 | 48 | return qdev; |
|---|
| 47 | 49 | } |
|---|
| 48 | 50 | |
|---|
| 49 | | -static int qxl_ttm_mem_global_init(struct drm_global_reference *ref) |
|---|
| 50 | | -{ |
|---|
| 51 | | - return ttm_mem_global_init(ref->object); |
|---|
| 52 | | -} |
|---|
| 53 | | - |
|---|
| 54 | | -static void qxl_ttm_mem_global_release(struct drm_global_reference *ref) |
|---|
| 55 | | -{ |
|---|
| 56 | | - ttm_mem_global_release(ref->object); |
|---|
| 57 | | -} |
|---|
| 58 | | - |
|---|
| 59 | | -static int qxl_ttm_global_init(struct qxl_device *qdev) |
|---|
| 60 | | -{ |
|---|
| 61 | | - struct drm_global_reference *global_ref; |
|---|
| 62 | | - int r; |
|---|
| 63 | | - |
|---|
| 64 | | - qdev->mman.mem_global_referenced = false; |
|---|
| 65 | | - global_ref = &qdev->mman.mem_global_ref; |
|---|
| 66 | | - global_ref->global_type = DRM_GLOBAL_TTM_MEM; |
|---|
| 67 | | - global_ref->size = sizeof(struct ttm_mem_global); |
|---|
| 68 | | - global_ref->init = &qxl_ttm_mem_global_init; |
|---|
| 69 | | - global_ref->release = &qxl_ttm_mem_global_release; |
|---|
| 70 | | - |
|---|
| 71 | | - r = drm_global_item_ref(global_ref); |
|---|
| 72 | | - if (r != 0) { |
|---|
| 73 | | - DRM_ERROR("Failed setting up TTM memory accounting " |
|---|
| 74 | | - "subsystem.\n"); |
|---|
| 75 | | - return r; |
|---|
| 76 | | - } |
|---|
| 77 | | - |
|---|
| 78 | | - qdev->mman.bo_global_ref.mem_glob = |
|---|
| 79 | | - qdev->mman.mem_global_ref.object; |
|---|
| 80 | | - global_ref = &qdev->mman.bo_global_ref.ref; |
|---|
| 81 | | - global_ref->global_type = DRM_GLOBAL_TTM_BO; |
|---|
| 82 | | - global_ref->size = sizeof(struct ttm_bo_global); |
|---|
| 83 | | - global_ref->init = &ttm_bo_global_init; |
|---|
| 84 | | - global_ref->release = &ttm_bo_global_release; |
|---|
| 85 | | - r = drm_global_item_ref(global_ref); |
|---|
| 86 | | - if (r != 0) { |
|---|
| 87 | | - DRM_ERROR("Failed setting up TTM BO subsystem.\n"); |
|---|
| 88 | | - drm_global_item_unref(&qdev->mman.mem_global_ref); |
|---|
| 89 | | - return r; |
|---|
| 90 | | - } |
|---|
| 91 | | - |
|---|
| 92 | | - qdev->mman.mem_global_referenced = true; |
|---|
| 93 | | - return 0; |
|---|
| 94 | | -} |
|---|
| 95 | | - |
|---|
| 96 | | -static void qxl_ttm_global_fini(struct qxl_device *qdev) |
|---|
| 97 | | -{ |
|---|
| 98 | | - if (qdev->mman.mem_global_referenced) { |
|---|
| 99 | | - drm_global_item_unref(&qdev->mman.bo_global_ref.ref); |
|---|
| 100 | | - drm_global_item_unref(&qdev->mman.mem_global_ref); |
|---|
| 101 | | - qdev->mman.mem_global_referenced = false; |
|---|
| 102 | | - } |
|---|
| 103 | | -} |
|---|
| 104 | | - |
|---|
| 105 | | -static struct vm_operations_struct qxl_ttm_vm_ops; |
|---|
| 106 | | -static const struct vm_operations_struct *ttm_vm_ops; |
|---|
| 107 | | - |
|---|
| 108 | | -static vm_fault_t qxl_ttm_fault(struct vm_fault *vmf) |
|---|
| 109 | | -{ |
|---|
| 110 | | - struct ttm_buffer_object *bo; |
|---|
| 111 | | - vm_fault_t ret; |
|---|
| 112 | | - |
|---|
| 113 | | - bo = (struct ttm_buffer_object *)vmf->vma->vm_private_data; |
|---|
| 114 | | - if (bo == NULL) |
|---|
| 115 | | - return VM_FAULT_NOPAGE; |
|---|
| 116 | | - ret = ttm_vm_ops->fault(vmf); |
|---|
| 117 | | - return ret; |
|---|
| 118 | | -} |
|---|
| 119 | | - |
|---|
| 120 | | -int qxl_mmap(struct file *filp, struct vm_area_struct *vma) |
|---|
| 121 | | -{ |
|---|
| 122 | | - struct drm_file *file_priv; |
|---|
| 123 | | - struct qxl_device *qdev; |
|---|
| 124 | | - int r; |
|---|
| 125 | | - |
|---|
| 126 | | - if (unlikely(vma->vm_pgoff < DRM_FILE_PAGE_OFFSET)) |
|---|
| 127 | | - return -EINVAL; |
|---|
| 128 | | - |
|---|
| 129 | | - file_priv = filp->private_data; |
|---|
| 130 | | - qdev = file_priv->minor->dev->dev_private; |
|---|
| 131 | | - if (qdev == NULL) { |
|---|
| 132 | | - DRM_ERROR( |
|---|
| 133 | | - "filp->private_data->minor->dev->dev_private == NULL\n"); |
|---|
| 134 | | - return -EINVAL; |
|---|
| 135 | | - } |
|---|
| 136 | | - DRM_DEBUG_DRIVER("filp->private_data = 0x%p, vma->vm_pgoff = %lx\n", |
|---|
| 137 | | - filp->private_data, vma->vm_pgoff); |
|---|
| 138 | | - |
|---|
| 139 | | - r = ttm_bo_mmap(filp, vma, &qdev->mman.bdev); |
|---|
| 140 | | - if (unlikely(r != 0)) |
|---|
| 141 | | - return r; |
|---|
| 142 | | - if (unlikely(ttm_vm_ops == NULL)) { |
|---|
| 143 | | - ttm_vm_ops = vma->vm_ops; |
|---|
| 144 | | - qxl_ttm_vm_ops = *ttm_vm_ops; |
|---|
| 145 | | - qxl_ttm_vm_ops.fault = &qxl_ttm_fault; |
|---|
| 146 | | - } |
|---|
| 147 | | - vma->vm_ops = &qxl_ttm_vm_ops; |
|---|
| 148 | | - return 0; |
|---|
| 149 | | -} |
|---|
| 150 | | - |
|---|
| 151 | | -static int qxl_invalidate_caches(struct ttm_bo_device *bdev, uint32_t flags) |
|---|
| 152 | | -{ |
|---|
| 153 | | - return 0; |
|---|
| 154 | | -} |
|---|
| 155 | | - |
|---|
| 156 | | -static int qxl_init_mem_type(struct ttm_bo_device *bdev, uint32_t type, |
|---|
| 157 | | - struct ttm_mem_type_manager *man) |
|---|
| 158 | | -{ |
|---|
| 159 | | - switch (type) { |
|---|
| 160 | | - case TTM_PL_SYSTEM: |
|---|
| 161 | | - /* System memory */ |
|---|
| 162 | | - man->flags = TTM_MEMTYPE_FLAG_MAPPABLE; |
|---|
| 163 | | - man->available_caching = TTM_PL_MASK_CACHING; |
|---|
| 164 | | - man->default_caching = TTM_PL_FLAG_CACHED; |
|---|
| 165 | | - break; |
|---|
| 166 | | - case TTM_PL_VRAM: |
|---|
| 167 | | - case TTM_PL_PRIV: |
|---|
| 168 | | - /* "On-card" video ram */ |
|---|
| 169 | | - man->func = &ttm_bo_manager_func; |
|---|
| 170 | | - man->gpu_offset = 0; |
|---|
| 171 | | - man->flags = TTM_MEMTYPE_FLAG_FIXED | |
|---|
| 172 | | - TTM_MEMTYPE_FLAG_MAPPABLE; |
|---|
| 173 | | - man->available_caching = TTM_PL_MASK_CACHING; |
|---|
| 174 | | - man->default_caching = TTM_PL_FLAG_CACHED; |
|---|
| 175 | | - break; |
|---|
| 176 | | - default: |
|---|
| 177 | | - DRM_ERROR("Unsupported memory type %u\n", (unsigned)type); |
|---|
| 178 | | - return -EINVAL; |
|---|
| 179 | | - } |
|---|
| 180 | | - return 0; |
|---|
| 181 | | -} |
|---|
| 182 | | - |
|---|
| 183 | 51 | static void qxl_evict_flags(struct ttm_buffer_object *bo, |
|---|
| 184 | 52 | struct ttm_placement *placement) |
|---|
| 185 | 53 | { |
|---|
| .. | .. |
|---|
| 187 | 55 | static const struct ttm_place placements = { |
|---|
| 188 | 56 | .fpfn = 0, |
|---|
| 189 | 57 | .lpfn = 0, |
|---|
| 190 | | - .flags = TTM_PL_MASK_CACHING | TTM_PL_FLAG_SYSTEM |
|---|
| 58 | + .mem_type = TTM_PL_SYSTEM, |
|---|
| 59 | + .flags = TTM_PL_MASK_CACHING |
|---|
| 191 | 60 | }; |
|---|
| 192 | 61 | |
|---|
| 193 | 62 | if (!qxl_ttm_bo_is_qxl_bo(bo)) { |
|---|
| .. | .. |
|---|
| 202 | 71 | *placement = qbo->placement; |
|---|
| 203 | 72 | } |
|---|
| 204 | 73 | |
|---|
| 205 | | -static int qxl_verify_access(struct ttm_buffer_object *bo, struct file *filp) |
|---|
| 74 | +int qxl_ttm_io_mem_reserve(struct ttm_bo_device *bdev, |
|---|
| 75 | + struct ttm_resource *mem) |
|---|
| 206 | 76 | { |
|---|
| 207 | | - struct qxl_bo *qbo = to_qxl_bo(bo); |
|---|
| 208 | | - |
|---|
| 209 | | - return drm_vma_node_verify_access(&qbo->gem_base.vma_node, |
|---|
| 210 | | - filp->private_data); |
|---|
| 211 | | -} |
|---|
| 212 | | - |
|---|
| 213 | | -static int qxl_ttm_io_mem_reserve(struct ttm_bo_device *bdev, |
|---|
| 214 | | - struct ttm_mem_reg *mem) |
|---|
| 215 | | -{ |
|---|
| 216 | | - struct ttm_mem_type_manager *man = &bdev->man[mem->mem_type]; |
|---|
| 217 | 77 | struct qxl_device *qdev = qxl_get_qdev(bdev); |
|---|
| 218 | 78 | |
|---|
| 219 | | - mem->bus.addr = NULL; |
|---|
| 220 | | - mem->bus.offset = 0; |
|---|
| 221 | | - mem->bus.size = mem->num_pages << PAGE_SHIFT; |
|---|
| 222 | | - mem->bus.base = 0; |
|---|
| 223 | | - mem->bus.is_iomem = false; |
|---|
| 224 | | - if (!(man->flags & TTM_MEMTYPE_FLAG_MAPPABLE)) |
|---|
| 225 | | - return -EINVAL; |
|---|
| 226 | 79 | switch (mem->mem_type) { |
|---|
| 227 | 80 | case TTM_PL_SYSTEM: |
|---|
| 228 | 81 | /* system memory */ |
|---|
| 229 | 82 | return 0; |
|---|
| 230 | 83 | case TTM_PL_VRAM: |
|---|
| 231 | 84 | mem->bus.is_iomem = true; |
|---|
| 232 | | - mem->bus.base = qdev->vram_base; |
|---|
| 233 | | - mem->bus.offset = mem->start << PAGE_SHIFT; |
|---|
| 85 | + mem->bus.offset = (mem->start << PAGE_SHIFT) + qdev->vram_base; |
|---|
| 234 | 86 | break; |
|---|
| 235 | 87 | case TTM_PL_PRIV: |
|---|
| 236 | 88 | mem->bus.is_iomem = true; |
|---|
| 237 | | - mem->bus.base = qdev->surfaceram_base; |
|---|
| 238 | | - mem->bus.offset = mem->start << PAGE_SHIFT; |
|---|
| 89 | + mem->bus.offset = (mem->start << PAGE_SHIFT) + |
|---|
| 90 | + qdev->surfaceram_base; |
|---|
| 239 | 91 | break; |
|---|
| 240 | 92 | default: |
|---|
| 241 | 93 | return -EINVAL; |
|---|
| .. | .. |
|---|
| 243 | 95 | return 0; |
|---|
| 244 | 96 | } |
|---|
| 245 | 97 | |
|---|
| 246 | | -static void qxl_ttm_io_mem_free(struct ttm_bo_device *bdev, |
|---|
| 247 | | - struct ttm_mem_reg *mem) |
|---|
| 248 | | -{ |
|---|
| 249 | | -} |
|---|
| 250 | | - |
|---|
| 251 | 98 | /* |
|---|
| 252 | 99 | * TTM backend functions. |
|---|
| 253 | 100 | */ |
|---|
| 254 | 101 | struct qxl_ttm_tt { |
|---|
| 255 | | - struct ttm_dma_tt ttm; |
|---|
| 102 | + struct ttm_tt ttm; |
|---|
| 256 | 103 | struct qxl_device *qdev; |
|---|
| 257 | 104 | u64 offset; |
|---|
| 258 | 105 | }; |
|---|
| 259 | 106 | |
|---|
| 260 | | -static int qxl_ttm_backend_bind(struct ttm_tt *ttm, |
|---|
| 261 | | - struct ttm_mem_reg *bo_mem) |
|---|
| 107 | +static int qxl_ttm_backend_bind(struct ttm_bo_device *bdev, |
|---|
| 108 | + struct ttm_tt *ttm, |
|---|
| 109 | + struct ttm_resource *bo_mem) |
|---|
| 262 | 110 | { |
|---|
| 263 | 111 | struct qxl_ttm_tt *gtt = (void *)ttm; |
|---|
| 264 | 112 | |
|---|
| .. | .. |
|---|
| 271 | 119 | return -1; |
|---|
| 272 | 120 | } |
|---|
| 273 | 121 | |
|---|
| 274 | | -static int qxl_ttm_backend_unbind(struct ttm_tt *ttm) |
|---|
| 122 | +static void qxl_ttm_backend_unbind(struct ttm_bo_device *bdev, |
|---|
| 123 | + struct ttm_tt *ttm) |
|---|
| 275 | 124 | { |
|---|
| 276 | 125 | /* Not implemented */ |
|---|
| 277 | | - return -1; |
|---|
| 278 | 126 | } |
|---|
| 279 | 127 | |
|---|
| 280 | | -static void qxl_ttm_backend_destroy(struct ttm_tt *ttm) |
|---|
| 128 | +static void qxl_ttm_backend_destroy(struct ttm_bo_device *bdev, |
|---|
| 129 | + struct ttm_tt *ttm) |
|---|
| 281 | 130 | { |
|---|
| 282 | 131 | struct qxl_ttm_tt *gtt = (void *)ttm; |
|---|
| 283 | 132 | |
|---|
| 284 | | - ttm_dma_tt_fini(>t->ttm); |
|---|
| 133 | + ttm_tt_destroy_common(bdev, ttm); |
|---|
| 134 | + ttm_tt_fini(>t->ttm); |
|---|
| 285 | 135 | kfree(gtt); |
|---|
| 286 | 136 | } |
|---|
| 287 | | - |
|---|
| 288 | | -static struct ttm_backend_func qxl_backend_func = { |
|---|
| 289 | | - .bind = &qxl_ttm_backend_bind, |
|---|
| 290 | | - .unbind = &qxl_ttm_backend_unbind, |
|---|
| 291 | | - .destroy = &qxl_ttm_backend_destroy, |
|---|
| 292 | | -}; |
|---|
| 293 | 137 | |
|---|
| 294 | 138 | static struct ttm_tt *qxl_ttm_tt_create(struct ttm_buffer_object *bo, |
|---|
| 295 | 139 | uint32_t page_flags) |
|---|
| .. | .. |
|---|
| 301 | 145 | gtt = kzalloc(sizeof(struct qxl_ttm_tt), GFP_KERNEL); |
|---|
| 302 | 146 | if (gtt == NULL) |
|---|
| 303 | 147 | return NULL; |
|---|
| 304 | | - gtt->ttm.ttm.func = &qxl_backend_func; |
|---|
| 305 | 148 | gtt->qdev = qdev; |
|---|
| 306 | | - if (ttm_dma_tt_init(>t->ttm, bo, page_flags)) { |
|---|
| 149 | + if (ttm_tt_init(>t->ttm, bo, page_flags)) { |
|---|
| 307 | 150 | kfree(gtt); |
|---|
| 308 | 151 | return NULL; |
|---|
| 309 | 152 | } |
|---|
| 310 | | - return >t->ttm.ttm; |
|---|
| 311 | | -} |
|---|
| 312 | | - |
|---|
| 313 | | -static void qxl_move_null(struct ttm_buffer_object *bo, |
|---|
| 314 | | - struct ttm_mem_reg *new_mem) |
|---|
| 315 | | -{ |
|---|
| 316 | | - struct ttm_mem_reg *old_mem = &bo->mem; |
|---|
| 317 | | - |
|---|
| 318 | | - BUG_ON(old_mem->mm_node != NULL); |
|---|
| 319 | | - *old_mem = *new_mem; |
|---|
| 320 | | - new_mem->mm_node = NULL; |
|---|
| 153 | + return >t->ttm; |
|---|
| 321 | 154 | } |
|---|
| 322 | 155 | |
|---|
| 323 | 156 | static int qxl_bo_move(struct ttm_buffer_object *bo, bool evict, |
|---|
| 324 | 157 | struct ttm_operation_ctx *ctx, |
|---|
| 325 | | - struct ttm_mem_reg *new_mem) |
|---|
| 158 | + struct ttm_resource *new_mem) |
|---|
| 326 | 159 | { |
|---|
| 327 | | - struct ttm_mem_reg *old_mem = &bo->mem; |
|---|
| 160 | + struct ttm_resource *old_mem = &bo->mem; |
|---|
| 328 | 161 | int ret; |
|---|
| 329 | 162 | |
|---|
| 330 | 163 | ret = ttm_bo_wait(bo, ctx->interruptible, ctx->no_wait_gpu); |
|---|
| 331 | 164 | if (ret) |
|---|
| 332 | 165 | return ret; |
|---|
| 333 | 166 | |
|---|
| 334 | | - |
|---|
| 335 | 167 | if (old_mem->mem_type == TTM_PL_SYSTEM && bo->ttm == NULL) { |
|---|
| 336 | | - qxl_move_null(bo, new_mem); |
|---|
| 168 | + ttm_bo_move_null(bo, new_mem); |
|---|
| 337 | 169 | return 0; |
|---|
| 338 | 170 | } |
|---|
| 339 | 171 | return ttm_bo_move_memcpy(bo, ctx, new_mem); |
|---|
| .. | .. |
|---|
| 341 | 173 | |
|---|
| 342 | 174 | static void qxl_bo_move_notify(struct ttm_buffer_object *bo, |
|---|
| 343 | 175 | bool evict, |
|---|
| 344 | | - struct ttm_mem_reg *new_mem) |
|---|
| 176 | + struct ttm_resource *new_mem) |
|---|
| 345 | 177 | { |
|---|
| 346 | 178 | struct qxl_bo *qbo; |
|---|
| 347 | 179 | struct qxl_device *qdev; |
|---|
| .. | .. |
|---|
| 349 | 181 | if (!qxl_ttm_bo_is_qxl_bo(bo)) |
|---|
| 350 | 182 | return; |
|---|
| 351 | 183 | qbo = to_qxl_bo(bo); |
|---|
| 352 | | - qdev = qbo->gem_base.dev->dev_private; |
|---|
| 184 | + qdev = to_qxl(qbo->tbo.base.dev); |
|---|
| 353 | 185 | |
|---|
| 354 | 186 | if (bo->mem.mem_type == TTM_PL_PRIV && qbo->surface_id) |
|---|
| 355 | 187 | qxl_surface_evict(qdev, qbo, new_mem ? true : false); |
|---|
| .. | .. |
|---|
| 357 | 189 | |
|---|
| 358 | 190 | static struct ttm_bo_driver qxl_bo_driver = { |
|---|
| 359 | 191 | .ttm_tt_create = &qxl_ttm_tt_create, |
|---|
| 360 | | - .invalidate_caches = &qxl_invalidate_caches, |
|---|
| 361 | | - .init_mem_type = &qxl_init_mem_type, |
|---|
| 192 | + .ttm_tt_bind = &qxl_ttm_backend_bind, |
|---|
| 193 | + .ttm_tt_destroy = &qxl_ttm_backend_destroy, |
|---|
| 194 | + .ttm_tt_unbind = &qxl_ttm_backend_unbind, |
|---|
| 362 | 195 | .eviction_valuable = ttm_bo_eviction_valuable, |
|---|
| 363 | 196 | .evict_flags = &qxl_evict_flags, |
|---|
| 364 | 197 | .move = &qxl_bo_move, |
|---|
| 365 | | - .verify_access = &qxl_verify_access, |
|---|
| 366 | 198 | .io_mem_reserve = &qxl_ttm_io_mem_reserve, |
|---|
| 367 | | - .io_mem_free = &qxl_ttm_io_mem_free, |
|---|
| 368 | 199 | .move_notify = &qxl_bo_move_notify, |
|---|
| 369 | 200 | }; |
|---|
| 201 | + |
|---|
| 202 | +static int qxl_ttm_init_mem_type(struct qxl_device *qdev, |
|---|
| 203 | + unsigned int type, |
|---|
| 204 | + uint64_t size) |
|---|
| 205 | +{ |
|---|
| 206 | + return ttm_range_man_init(&qdev->mman.bdev, type, false, size); |
|---|
| 207 | +} |
|---|
| 370 | 208 | |
|---|
| 371 | 209 | int qxl_ttm_init(struct qxl_device *qdev) |
|---|
| 372 | 210 | { |
|---|
| 373 | 211 | int r; |
|---|
| 374 | 212 | int num_io_pages; /* != rom->num_io_pages, we include surface0 */ |
|---|
| 375 | 213 | |
|---|
| 376 | | - r = qxl_ttm_global_init(qdev); |
|---|
| 377 | | - if (r) |
|---|
| 378 | | - return r; |
|---|
| 379 | 214 | /* No others user of address space so set it to 0 */ |
|---|
| 380 | 215 | r = ttm_bo_device_init(&qdev->mman.bdev, |
|---|
| 381 | | - qdev->mman.bo_global_ref.ref.object, |
|---|
| 382 | 216 | &qxl_bo_driver, |
|---|
| 383 | 217 | qdev->ddev.anon_inode->i_mapping, |
|---|
| 384 | | - DRM_FILE_PAGE_OFFSET, 0); |
|---|
| 218 | + qdev->ddev.vma_offset_manager, |
|---|
| 219 | + false); |
|---|
| 385 | 220 | if (r) { |
|---|
| 386 | 221 | DRM_ERROR("failed initializing buffer object driver(%d).\n", r); |
|---|
| 387 | 222 | return r; |
|---|
| 388 | 223 | } |
|---|
| 389 | 224 | /* NOTE: this includes the framebuffer (aka surface 0) */ |
|---|
| 390 | 225 | num_io_pages = qdev->rom->ram_header_offset / PAGE_SIZE; |
|---|
| 391 | | - r = ttm_bo_init_mm(&qdev->mman.bdev, TTM_PL_VRAM, |
|---|
| 392 | | - num_io_pages); |
|---|
| 226 | + r = qxl_ttm_init_mem_type(qdev, TTM_PL_VRAM, num_io_pages); |
|---|
| 393 | 227 | if (r) { |
|---|
| 394 | 228 | DRM_ERROR("Failed initializing VRAM heap.\n"); |
|---|
| 395 | 229 | return r; |
|---|
| 396 | 230 | } |
|---|
| 397 | | - r = ttm_bo_init_mm(&qdev->mman.bdev, TTM_PL_PRIV, |
|---|
| 398 | | - qdev->surfaceram_size / PAGE_SIZE); |
|---|
| 231 | + r = qxl_ttm_init_mem_type(qdev, TTM_PL_PRIV, |
|---|
| 232 | + qdev->surfaceram_size / PAGE_SIZE); |
|---|
| 399 | 233 | if (r) { |
|---|
| 400 | 234 | DRM_ERROR("Failed initializing Surfaces heap.\n"); |
|---|
| 401 | 235 | return r; |
|---|
| 402 | 236 | } |
|---|
| 403 | 237 | DRM_INFO("qxl: %uM of VRAM memory size\n", |
|---|
| 404 | | - (unsigned)qdev->vram_size / (1024 * 1024)); |
|---|
| 238 | + (unsigned int)qdev->vram_size / (1024 * 1024)); |
|---|
| 405 | 239 | DRM_INFO("qxl: %luM of IO pages memory ready (VRAM domain)\n", |
|---|
| 406 | | - ((unsigned)num_io_pages * PAGE_SIZE) / (1024 * 1024)); |
|---|
| 240 | + ((unsigned int)num_io_pages * PAGE_SIZE) / (1024 * 1024)); |
|---|
| 407 | 241 | DRM_INFO("qxl: %uM of Surface memory size\n", |
|---|
| 408 | | - (unsigned)qdev->surfaceram_size / (1024 * 1024)); |
|---|
| 242 | + (unsigned int)qdev->surfaceram_size / (1024 * 1024)); |
|---|
| 409 | 243 | return 0; |
|---|
| 410 | 244 | } |
|---|
| 411 | 245 | |
|---|
| 412 | 246 | void qxl_ttm_fini(struct qxl_device *qdev) |
|---|
| 413 | 247 | { |
|---|
| 414 | | - ttm_bo_clean_mm(&qdev->mman.bdev, TTM_PL_VRAM); |
|---|
| 415 | | - ttm_bo_clean_mm(&qdev->mman.bdev, TTM_PL_PRIV); |
|---|
| 248 | + ttm_range_man_fini(&qdev->mman.bdev, TTM_PL_VRAM); |
|---|
| 249 | + ttm_range_man_fini(&qdev->mman.bdev, TTM_PL_PRIV); |
|---|
| 416 | 250 | ttm_bo_device_release(&qdev->mman.bdev); |
|---|
| 417 | | - qxl_ttm_global_fini(qdev); |
|---|
| 418 | 251 | DRM_INFO("qxl: ttm finalized\n"); |
|---|
| 419 | 252 | } |
|---|
| 420 | | - |
|---|
| 421 | 253 | |
|---|
| 422 | 254 | #define QXL_DEBUGFS_MEM_TYPES 2 |
|---|
| 423 | 255 | |
|---|
| .. | .. |
|---|
| 425 | 257 | static int qxl_mm_dump_table(struct seq_file *m, void *data) |
|---|
| 426 | 258 | { |
|---|
| 427 | 259 | struct drm_info_node *node = (struct drm_info_node *)m->private; |
|---|
| 428 | | - struct drm_mm *mm = (struct drm_mm *)node->info_ent->data; |
|---|
| 429 | | - struct drm_device *dev = node->minor->dev; |
|---|
| 430 | | - struct qxl_device *rdev = dev->dev_private; |
|---|
| 431 | | - struct ttm_bo_global *glob = rdev->mman.bdev.glob; |
|---|
| 260 | + struct ttm_resource_manager *man = (struct ttm_resource_manager *)node->info_ent->data; |
|---|
| 432 | 261 | struct drm_printer p = drm_seq_file_printer(m); |
|---|
| 433 | 262 | |
|---|
| 434 | | - spin_lock(&glob->lru_lock); |
|---|
| 435 | | - drm_mm_print(mm, &p); |
|---|
| 436 | | - spin_unlock(&glob->lru_lock); |
|---|
| 263 | + ttm_resource_manager_debug(man, &p); |
|---|
| 437 | 264 | return 0; |
|---|
| 438 | 265 | } |
|---|
| 439 | 266 | #endif |
|---|
| 440 | 267 | |
|---|
| 441 | | -int qxl_ttm_debugfs_init(struct qxl_device *qdev) |
|---|
| 268 | +void qxl_ttm_debugfs_init(struct qxl_device *qdev) |
|---|
| 442 | 269 | { |
|---|
| 443 | 270 | #if defined(CONFIG_DEBUG_FS) |
|---|
| 444 | 271 | static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES]; |
|---|
| 445 | 272 | static char qxl_mem_types_names[QXL_DEBUGFS_MEM_TYPES][32]; |
|---|
| 446 | | - unsigned i; |
|---|
| 273 | + unsigned int i; |
|---|
| 447 | 274 | |
|---|
| 448 | 275 | for (i = 0; i < QXL_DEBUGFS_MEM_TYPES; i++) { |
|---|
| 449 | 276 | if (i == 0) |
|---|
| .. | .. |
|---|
| 454 | 281 | qxl_mem_types_list[i].show = &qxl_mm_dump_table; |
|---|
| 455 | 282 | qxl_mem_types_list[i].driver_features = 0; |
|---|
| 456 | 283 | if (i == 0) |
|---|
| 457 | | - qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv; |
|---|
| 284 | + qxl_mem_types_list[i].data = ttm_manager_type(&qdev->mman.bdev, TTM_PL_VRAM); |
|---|
| 458 | 285 | else |
|---|
| 459 | | - qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_PRIV].priv; |
|---|
| 286 | + qxl_mem_types_list[i].data = ttm_manager_type(&qdev->mman.bdev, TTM_PL_PRIV); |
|---|
| 460 | 287 | |
|---|
| 461 | 288 | } |
|---|
| 462 | | - return qxl_debugfs_add_files(qdev, qxl_mem_types_list, i); |
|---|
| 463 | | -#else |
|---|
| 464 | | - return 0; |
|---|
| 289 | + qxl_debugfs_add_files(qdev, qxl_mem_types_list, i); |
|---|
| 465 | 290 | #endif |
|---|
| 466 | 291 | } |
|---|