Pull drm fixes from Dave Airlie: "Regular week of fixes, seems to be about right for this time in the release cycle, amdgpu, and nouveau are the main one with some scattered fixes otherwise. ttm: - Stop pooling cached NUMA pages amdgpu: - Fix invalid resource->start check - USB-C DSC fix - Fix a potential UAF in VA IOCTL - Fix visible VRAM handling during faults amdkfd: - Fix memory leak in create_process failure radeon: - Silence UBSAN warnings from variable sized arrays nouveau: - dp: Don't probe DP ports twice - nv04: Fix OOB access - nv50: Disable AUX bus for disconnected DP ports - nvkm: Fix instmem race condition panel: - Don't unregister DSI devices in several drivers v3d: - Fix enabled_ns increment xe: - Fix bo leak on error path during fb init - Fix use-after-free due to order vm is put and destroyed" * tag 'drm-fixes-2024-04-19' of https://gitlab.freedesktop.org/drm/kernel: drm/radeon: silence UBSAN warning (v3) drm/radeon: make -fstrict-flex-arrays=3 happy drm/amdgpu: fix visible VRAM handling during faults drm/amdgpu: validate the parameters of bo mapping operations more clearly Revert "drm/amd/display: fix USB-C flag update after enc10 feature init" drm/amdkfd: Fix memory leak in create_process failure drm/amdgpu: remove invalid resource->start check v2 drm/xe/vm: prevent UAF with asid based lookup drm/xe: Fix bo leak in intel_fb_bo_framebuffer_init drm/panel: novatek-nt36682e: don't unregister DSI device drm/panel: visionox-rm69299: don't unregister DSI device drm/nouveau/dp: Don't probe eDP ports twice harder drm/nouveau/kms/nv50-: Disable AUX bus for disconnected DP ports drm/v3d: Don't increment `enabled_ns` twice drm/vmwgfx: Sort primary plane formats by order of preference drm/vmwgfx: Fix crtc's atomic check conditional drm/vmwgfx: Fix prime import/export drm/ttm: stop pooling cached NUMA pages v2 drm: nv04: Fix out of bounds access nouveau: fix instmem race condition around ptr stores
Unified · Split
| @@ -819,7 +819,7 @@ retry: · 818 unmodified lines | |||
| 819 | 819 | ||
| 820 | p->bytes_moved += ctx.bytes_moved; | 820 | p->bytes_moved += ctx.bytes_moved; |
| 821 | if (!amdgpu_gmc_vram_full_visible(&adev->gmc) && | 821 | if (!amdgpu_gmc_vram_full_visible(&adev->gmc) && |
| 822 | amdgpu_bo_in_cpu_visible_vram(bo)) | 822 | amdgpu_res_cpu_visible(adev, bo->tbo.resource)) |
| 823 | p->bytes_moved_vis += ctx.bytes_moved; | 823 | p->bytes_moved_vis += ctx.bytes_moved; |
| 824 | 824 | ||
| 825 | if (unlikely(r == -ENOMEM) && domain != bo->allowed_domains) { | 825 | if (unlikely(r == -ENOMEM) && domain != bo->allowed_domains) { |
| @@ -617,8 +617,7 @@ int amdgpu_bo_create(struct amdgpu_device *adev, · 616 unmodified lines | |||
| 617 | return r; | 617 | return r; |
| 618 | 618 | ||
| 619 | if (!amdgpu_gmc_vram_full_visible(&adev->gmc) && | 619 | if (!amdgpu_gmc_vram_full_visible(&adev->gmc) && |
| 620 | bo->tbo.resource->mem_type == TTM_PL_VRAM && | 620 | amdgpu_res_cpu_visible(adev, bo->tbo.resource)) |
| 621 | amdgpu_bo_in_cpu_visible_vram(bo)) | ||
| 622 | amdgpu_cs_report_moved_bytes(adev, ctx.bytes_moved, | 621 | amdgpu_cs_report_moved_bytes(adev, ctx.bytes_moved, |
| 623 | ctx.bytes_moved); | 622 | ctx.bytes_moved); |
| 624 | else | 623 | else |
| @@ -1272,23 +1271,25 @@ void amdgpu_bo_move_notify(struct ttm_buffer_object *bo, bool evict) · 647 unmodified lines | |||
| 1272 | void amdgpu_bo_get_memory(struct amdgpu_bo *bo, | 1271 | void amdgpu_bo_get_memory(struct amdgpu_bo *bo, |
| 1273 | struct amdgpu_mem_stats *stats) | 1272 | struct amdgpu_mem_stats *stats) |
| 1274 | { | 1273 | { |
| 1274 | struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev); | ||
| 1275 | struct ttm_resource *res = bo->tbo.resource; | ||
| 1275 | uint64_t size = amdgpu_bo_size(bo); | 1276 | uint64_t size = amdgpu_bo_size(bo); |
| 1276 | struct drm_gem_object *obj; | 1277 | struct drm_gem_object *obj; |
| 1277 | unsigned int domain; | 1278 | unsigned int domain; |
| 1278 | bool shared; | 1279 | bool shared; |
| 1279 | 1280 | ||
| 1280 | /* Abort if the BO doesn't currently have a backing store */ | 1281 | /* Abort if the BO doesn't currently have a backing store */ |
| 1281 | if (!bo->tbo.resource) | 1282 | if (!res) |
| 1282 | return; | 1283 | return; |
| 1283 | 1284 | ||
| 1284 | obj = &bo->tbo.base; | 1285 | obj = &bo->tbo.base; |
| 1285 | shared = drm_gem_object_is_shared_for_memory_stats(obj); | 1286 | shared = drm_gem_object_is_shared_for_memory_stats(obj); |
| 1286 | 1287 | ||
| 1287 | domain = amdgpu_mem_type_to_domain(bo->tbo.resource->mem_type); | 1288 | domain = amdgpu_mem_type_to_domain(res->mem_type); |
| 1288 | switch (domain) { | 1289 | switch (domain) { |
| 1289 | case AMDGPU_GEM_DOMAIN_VRAM: | 1290 | case AMDGPU_GEM_DOMAIN_VRAM: |
| 1290 | stats->vram += size; | 1291 | stats->vram += size; |
| 1291 | if (amdgpu_bo_in_cpu_visible_vram(bo)) | 1292 | if (amdgpu_res_cpu_visible(adev, bo->tbo.resource)) |
| 1292 | stats->visible_vram += size; | 1293 | stats->visible_vram += size; |
| 1293 | if (shared) | 1294 | if (shared) |
| 1294 | stats->vram_shared += size; | 1295 | stats->vram_shared += size; |
| @@ -1389,10 +1390,7 @@ vm_fault_t amdgpu_bo_fault_reserve_notify(struct ttm_buffer_object *bo) · 94 unmodified lines | |||
| 1389 | /* Remember that this BO was accessed by the CPU */ | 1390 | /* Remember that this BO was accessed by the CPU */ |
| 1390 | abo->flags |= AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED; | 1391 | abo->flags |= AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED; |
| 1391 | 1392 | ||
| 1392 | if (bo->resource->mem_type != TTM_PL_VRAM) | 1393 | if (amdgpu_res_cpu_visible(adev, bo->resource)) |
| 1393 | return 0; | ||
| 1394 | |||
| 1395 | if (amdgpu_bo_in_cpu_visible_vram(abo)) | ||
| 1396 | return 0; | 1394 | return 0; |
| 1397 | 1395 | ||
| 1398 | /* Can't move a pinned BO to visible VRAM */ | 1396 | /* Can't move a pinned BO to visible VRAM */ |
| @@ -1415,7 +1413,7 @@ vm_fault_t amdgpu_bo_fault_reserve_notify(struct ttm_buffer_object *bo) · 16 unmodified lines | |||
| 1415 | 1413 | ||
| 1416 | /* this should never happen */ | 1414 | /* this should never happen */ |
| 1417 | if (bo->resource->mem_type == TTM_PL_VRAM && | 1415 | if (bo->resource->mem_type == TTM_PL_VRAM && |
| 1418 | !amdgpu_bo_in_cpu_visible_vram(abo)) | 1416 | !amdgpu_res_cpu_visible(adev, bo->resource)) |
| 1419 | return VM_FAULT_SIGBUS; | 1417 | return VM_FAULT_SIGBUS; |
| 1420 | 1418 | ||
| 1421 | ttm_bo_move_to_lru_tail_unlocked(bo); | 1419 | ttm_bo_move_to_lru_tail_unlocked(bo); |
| @@ -1579,6 +1577,7 @@ uint32_t amdgpu_bo_get_preferred_domain(struct amdgpu_device *adev, · 157 unmodified lines | |||
| 1579 | */ | 1577 | */ |
| 1580 | u64 amdgpu_bo_print_info(int id, struct amdgpu_bo *bo, struct seq_file *m) | 1578 | u64 amdgpu_bo_print_info(int id, struct amdgpu_bo *bo, struct seq_file *m) |
| 1581 | { | 1579 | { |
| 1580 | struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev); | ||
| 1582 | struct dma_buf_attachment *attachment; | 1581 | struct dma_buf_attachment *attachment; |
| 1583 | struct dma_buf *dma_buf; | 1582 | struct dma_buf *dma_buf; |
| 1584 | const char *placement; | 1583 | const char *placement; |
| @@ -1587,10 +1586,11 @@ u64 amdgpu_bo_print_info(int id, struct amdgpu_bo *bo, struct seq_file *m) · 2 unmodified lines | |||
| 1587 | 1586 | ||
| 1588 | if (dma_resv_trylock(bo->tbo.base.resv)) { | 1587 | if (dma_resv_trylock(bo->tbo.base.resv)) { |
| 1589 | unsigned int domain; | 1588 | unsigned int domain; |
| 1589 | |||
| 1590 | domain = amdgpu_mem_type_to_domain(bo->tbo.resource->mem_type); | 1590 | domain = amdgpu_mem_type_to_domain(bo->tbo.resource->mem_type); |
| 1591 | switch (domain) { | 1591 | switch (domain) { |
| 1592 | case AMDGPU_GEM_DOMAIN_VRAM: | 1592 | case AMDGPU_GEM_DOMAIN_VRAM: |
| 1593 | if (amdgpu_bo_in_cpu_visible_vram(bo)) | 1593 | if (amdgpu_res_cpu_visible(adev, bo->tbo.resource)) |
| 1594 | placement = "VRAM VISIBLE"; | 1594 | placement = "VRAM VISIBLE"; |
| 1595 | else | 1595 | else |
| 1596 | placement = "VRAM"; | 1596 | placement = "VRAM"; |
| @@ -250,28 +250,6 @@ static inline u64 amdgpu_bo_mmap_offset(struct amdgpu_bo *bo) · 249 unmodified lines | |||
| 250 | return drm_vma_node_offset_addr(&bo->tbo.base.vma_node); | 250 | return drm_vma_node_offset_addr(&bo->tbo.base.vma_node); |
| 251 | } | 251 | } |
| 252 | 252 | ||
| 253 | /** | ||
| 254 | * amdgpu_bo_in_cpu_visible_vram - check if BO is (partly) in visible VRAM | ||
| 255 | */ | ||
| 256 | static inline bool amdgpu_bo_in_cpu_visible_vram(struct amdgpu_bo *bo) | ||
| 257 | { | ||
| 258 | struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev); | ||
| 259 | struct amdgpu_res_cursor cursor; | ||
| 260 | |||
| 261 | if (!bo->tbo.resource || bo->tbo.resource->mem_type != TTM_PL_VRAM) | ||
| 262 | return false; | ||
| 263 | |||
| 264 | amdgpu_res_first(bo->tbo.resource, 0, amdgpu_bo_size(bo), &cursor); | ||
| 265 | while (cursor.remaining) { | ||
| 266 | if (cursor.start < adev->gmc.visible_vram_size) | ||
| 267 | return true; | ||
| 268 | |||
| 269 | amdgpu_res_next(&cursor, cursor.size); | ||
| 270 | } | ||
| 271 | |||
| 272 | return false; | ||
| 273 | } | ||
| 274 | |||
| 275 | /** | 253 | /** |
| 276 | * amdgpu_bo_explicit_sync - return whether the bo is explicitly synced | 254 | * amdgpu_bo_explicit_sync - return whether the bo is explicitly synced |
| 277 | */ | 255 | */ |
| @@ -133,7 +133,7 @@ static void amdgpu_evict_flags(struct ttm_buffer_object *bo, · 132 unmodified lines | |||
| 133 | 133 | ||
| 134 | } else if (!amdgpu_gmc_vram_full_visible(&adev->gmc) && | 134 | } else if (!amdgpu_gmc_vram_full_visible(&adev->gmc) && |
| 135 | !(abo->flags & AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED) && | 135 | !(abo->flags & AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED) && |
| 136 | amdgpu_bo_in_cpu_visible_vram(abo)) { | 136 | amdgpu_res_cpu_visible(adev, bo->resource)) { |
| 137 | 137 | ||
| 138 | /* Try evicting to the CPU inaccessible part of VRAM | 138 | /* Try evicting to the CPU inaccessible part of VRAM |
| 139 | * first, but only set GTT as busy placement, so this | 139 | * first, but only set GTT as busy placement, so this |
| @@ -403,40 +403,55 @@ error: · 263 unmodified lines | |||
| 403 | return r; | 403 | return r; |
| 404 | } | 404 | } |
| 405 | 405 | ||
| 406 | /* | 406 | /** |
| 407 | * amdgpu_mem_visible - Check that memory can be accessed by ttm_bo_move_memcpy | 407 | * amdgpu_res_cpu_visible - Check that resource can be accessed by CPU |
| 408 | * @adev: amdgpu device | ||
| 409 | * @res: the resource to check | ||
| 408 | * | 410 | * |
| 409 | * Called by amdgpu_bo_move() | 411 | * Returns: true if the full resource is CPU visible, false otherwise. |
| 410 | */ | 412 | */ |
| 411 | static bool amdgpu_mem_visible(struct amdgpu_device *adev, | 413 | bool amdgpu_res_cpu_visible(struct amdgpu_device *adev, |
| 412 | struct ttm_resource *mem) | 414 | struct ttm_resource *res) |
| 413 | { | 415 | { |
| 414 | u64 mem_size = (u64)mem->size; | ||
| 415 | struct amdgpu_res_cursor cursor; | 416 | struct amdgpu_res_cursor cursor; |
| 416 | u64 end; | ||
| 417 | 417 | ||
| 418 | if (mem->mem_type == TTM_PL_SYSTEM || | 418 | if (!res) |
| 419 | mem->mem_type == TTM_PL_TT) | 419 | return false; |
| 420 | |||
| 421 | if (res->mem_type == TTM_PL_SYSTEM || res->mem_type == TTM_PL_TT || | ||
| 422 | res->mem_type == AMDGPU_PL_PREEMPT) | ||
| 420 | return true; | 423 | return true; |
| 421 | if (mem->mem_type != TTM_PL_VRAM) | 424 | |
| 425 | if (res->mem_type != TTM_PL_VRAM) | ||
| 422 | return false; | 426 | return false; |
| 423 | 427 | ||
| 424 | amdgpu_res_first(mem, 0, mem_size, &cursor); | 428 | amdgpu_res_first(res, 0, res->size, &cursor); |
| 425 | end = cursor.start + cursor.size; | ||
| 426 | while (cursor.remaining) { | 429 | while (cursor.remaining) { |
| 430 | if ((cursor.start + cursor.size) >= adev->gmc.visible_vram_size) | ||
| 431 | return false; | ||
| 427 | amdgpu_res_next(&cursor, cursor.size); | 432 | amdgpu_res_next(&cursor, cursor.size); |
| 433 | } | ||
| 428 | 434 | ||
| 429 | if (!cursor.remaining) | 435 | return true; |
| 430 | break; | 436 | } |
| 431 | 437 | ||
| 432 | /* ttm_resource_ioremap only supports contiguous memory */ | 438 | /* |
| 433 | if (end != cursor.start) | 439 | * amdgpu_res_copyable - Check that memory can be accessed by ttm_bo_move_memcpy |
| 434 | return false; | 440 | * |
| 441 | * Called by amdgpu_bo_move() | ||
| 442 | */ | ||
| 443 | static bool amdgpu_res_copyable(struct amdgpu_device *adev, | ||
| 444 | struct ttm_resource *mem) | ||
| 445 | { | ||
| 446 | if (!amdgpu_res_cpu_visible(adev, mem)) | ||
| 447 | return false; | ||
| 435 | 448 | ||
| 436 | end = cursor.start + cursor.size; | 449 | /* ttm_resource_ioremap only supports contiguous memory */ |
| 437 | } | 450 | if (mem->mem_type == TTM_PL_VRAM && |
| 451 | !(mem->placement & TTM_PL_FLAG_CONTIGUOUS)) | ||
| 452 | return false; | ||
| 438 | 453 | ||
| 439 | return end <= adev->gmc.visible_vram_size; | 454 | return true; |
| 440 | } | 455 | } |
| 441 | 456 | ||
| 442 | /* | 457 | /* |
| @@ -529,8 +544,8 @@ static int amdgpu_bo_move(struct ttm_buffer_object *bo, bool evict, · 86 unmodified lines | |||
| 529 | 544 | ||
| 530 | if (r) { | 545 | if (r) { |
| 531 | /* Check that all memory is CPU accessible */ | 546 | /* Check that all memory is CPU accessible */ |
| 532 | if (!amdgpu_mem_visible(adev, old_mem) || | 547 | if (!amdgpu_res_copyable(adev, old_mem) || |
| 533 | !amdgpu_mem_visible(adev, new_mem)) { | 548 | !amdgpu_res_copyable(adev, new_mem)) { |
| 534 | pr_err("Move buffer fallback to memcpy unavailable\n"); | 549 | pr_err("Move buffer fallback to memcpy unavailable\n"); |
| 535 | return r; | 550 | return r; |
| 536 | } | 551 | } |
| @@ -557,7 +572,6 @@ static int amdgpu_ttm_io_mem_reserve(struct ttm_device *bdev, · 20 unmodified lines | |||
| 557 | struct ttm_resource *mem) | 572 | struct ttm_resource *mem) |
| 558 | { | 573 | { |
| 559 | struct amdgpu_device *adev = amdgpu_ttm_adev(bdev); | 574 | struct amdgpu_device *adev = amdgpu_ttm_adev(bdev); |
| 560 | size_t bus_size = (size_t)mem->size; | ||
| 561 | 575 | ||
| 562 | switch (mem->mem_type) { | 576 | switch (mem->mem_type) { |
| 563 | case TTM_PL_SYSTEM: | 577 | case TTM_PL_SYSTEM: |
| @@ -568,9 +582,6 @@ static int amdgpu_ttm_io_mem_reserve(struct ttm_device *bdev, · 4 unmodified lines | |||
| 568 | break; | 582 | break; |
| 569 | case TTM_PL_VRAM: | 583 | case TTM_PL_VRAM: |
| 570 | mem->bus.offset = mem->start << PAGE_SHIFT; | 584 | mem->bus.offset = mem->start << PAGE_SHIFT; |
| 571 | /* check if it's visible */ | ||
| 572 | if ((mem->bus.offset + bus_size) > adev->gmc.visible_vram_size) | ||
| 573 | return -EINVAL; | ||
| 574 | 585 | ||
| 575 | if (adev->mman.aper_base_kaddr && | 586 | if (adev->mman.aper_base_kaddr && |
| 576 | mem->placement & TTM_PL_FLAG_CONTIGUOUS) | 587 | mem->placement & TTM_PL_FLAG_CONTIGUOUS) |
| @@ -139,6 +139,9 @@ int amdgpu_vram_mgr_reserve_range(struct amdgpu_vram_mgr *mgr, · 138 unmodified lines | |||
| 139 | int amdgpu_vram_mgr_query_page_status(struct amdgpu_vram_mgr *mgr, | 139 | int amdgpu_vram_mgr_query_page_status(struct amdgpu_vram_mgr *mgr, |
| 140 | uint64_t start); | 140 | uint64_t start); |
| 141 | 141 | ||
| 142 | bool amdgpu_res_cpu_visible(struct amdgpu_device *adev, | ||
| 143 | struct ttm_resource *res); | ||
| 144 | |||
| 142 | int amdgpu_ttm_init(struct amdgpu_device *adev); | 145 | int amdgpu_ttm_init(struct amdgpu_device *adev); |
| 143 | void amdgpu_ttm_fini(struct amdgpu_device *adev); | 146 | void amdgpu_ttm_fini(struct amdgpu_device *adev); |
| 144 | void amdgpu_ttm_set_buffer_funcs_status(struct amdgpu_device *adev, | 147 | void amdgpu_ttm_set_buffer_funcs_status(struct amdgpu_device *adev, |
| @@ -1613,6 +1613,37 @@ static void amdgpu_vm_bo_insert_map(struct amdgpu_device *adev, · 1612 unmodified lines | |||
| 1613 | trace_amdgpu_vm_bo_map(bo_va, mapping); | 1613 | trace_amdgpu_vm_bo_map(bo_va, mapping); |
| 1614 | } | 1614 | } |
| 1615 | 1615 | ||
| 1616 | /* Validate operation parameters to prevent potential abuse */ | ||
| 1617 | static int amdgpu_vm_verify_parameters(struct amdgpu_device *adev, | ||
| 1618 | struct amdgpu_bo *bo, | ||
| 1619 | uint64_t saddr, | ||
| 1620 | uint64_t offset, | ||
| 1621 | uint64_t size) | ||
| 1622 | { | ||
| 1623 | uint64_t tmp, lpfn; | ||
| 1624 | |||
| 1625 | if (saddr & AMDGPU_GPU_PAGE_MASK | ||
| 1626 | || offset & AMDGPU_GPU_PAGE_MASK | ||
| 1627 | || size & AMDGPU_GPU_PAGE_MASK) | ||
| 1628 | return -EINVAL; | ||
| 1629 | |||
| 1630 | if (check_add_overflow(saddr, size, &tmp) | ||
| 1631 | || check_add_overflow(offset, size, &tmp) | ||
| 1632 | || size == 0 /* which also leads to end < begin */) | ||
| 1633 | return -EINVAL; | ||
| 1634 | |||
| 1635 | /* make sure object fit at this offset */ | ||
| 1636 | if (bo && offset + size > amdgpu_bo_size(bo)) | ||
| 1637 | return -EINVAL; | ||
| 1638 | |||
| 1639 | /* Ensure last pfn not exceed max_pfn */ | ||
| 1640 | lpfn = (saddr + size - 1) >> AMDGPU_GPU_PAGE_SHIFT; | ||
| 1641 | if (lpfn >= adev->vm_manager.max_pfn) | ||
| 1642 | return -EINVAL; | ||
| 1643 | |||
| 1644 | return 0; | ||
| 1645 | } | ||
| 1646 | |||
| 1616 | /** | 1647 | /** |
| 1617 | * amdgpu_vm_bo_map - map bo inside a vm | 1648 | * amdgpu_vm_bo_map - map bo inside a vm |
| 1618 | * | 1649 | * |
| @@ -1639,21 +1670,14 @@ int amdgpu_vm_bo_map(struct amdgpu_device *adev, · 20 unmodified lines | |||
| 1639 | struct amdgpu_bo *bo = bo_va->base.bo; | 1670 | struct amdgpu_bo *bo = bo_va->base.bo; |
| 1640 | struct amdgpu_vm *vm = bo_va->base.vm; | 1671 | struct amdgpu_vm *vm = bo_va->base.vm; |
| 1641 | uint64_t eaddr; | 1672 | uint64_t eaddr; |
| 1673 | int r; | ||
| 1642 | 1674 | ||
| 1643 | /* validate the parameters */ | 1675 | r = amdgpu_vm_verify_parameters(adev, bo, saddr, offset, size); |
| 1644 | if (saddr & ~PAGE_MASK || offset & ~PAGE_MASK || size & ~PAGE_MASK) | 1676 | if (r) |
| 1645 | return -EINVAL; | 1677 | return r; |
| 1646 | if (saddr + size <= saddr || offset + size <= offset) | ||
| 1647 | return -EINVAL; | ||
| 1648 | |||
| 1649 | /* make sure object fit at this offset */ | ||
| 1650 | eaddr = saddr + size - 1; | ||
| 1651 | if ((bo && offset + size > amdgpu_bo_size(bo)) || | ||
| 1652 | (eaddr >= adev->vm_manager.max_pfn << AMDGPU_GPU_PAGE_SHIFT)) | ||
| 1653 | return -EINVAL; | ||
| 1654 | 1678 | ||
| 1655 | saddr /= AMDGPU_GPU_PAGE_SIZE; | 1679 | saddr /= AMDGPU_GPU_PAGE_SIZE; |
| 1656 | eaddr /= AMDGPU_GPU_PAGE_SIZE; | 1680 | eaddr = saddr + (size - 1) / AMDGPU_GPU_PAGE_SIZE; |
| 1657 | 1681 | ||
| 1658 | tmp = amdgpu_vm_it_iter_first(&vm->va, saddr, eaddr); | 1682 | tmp = amdgpu_vm_it_iter_first(&vm->va, saddr, eaddr); |
| 1659 | if (tmp) { | 1683 | if (tmp) { |
| @@ -1706,17 +1730,9 @@ int amdgpu_vm_bo_replace_map(struct amdgpu_device *adev, · 46 unmodified lines | |||
| 1706 | uint64_t eaddr; | 1730 | uint64_t eaddr; |
| 1707 | int r; | 1731 | int r; |
| 1708 | 1732 | ||
| 1709 | /* validate the parameters */ | 1733 | r = amdgpu_vm_verify_parameters(adev, bo, saddr, offset, size); |
| 1710 | if (saddr & ~PAGE_MASK || offset & ~PAGE_MASK || size & ~PAGE_MASK) | 1734 | if (r) |
| 1711 | return -EINVAL; | 1735 | return r; |
| 1712 | if (saddr + size <= saddr || offset + size <= offset) | ||
| 1713 | return -EINVAL; | ||
| 1714 | |||
| 1715 | /* make sure object fit at this offset */ | ||
| 1716 | eaddr = saddr + size - 1; | ||
| 1717 | if ((bo && offset + size > amdgpu_bo_size(bo)) || | ||
| 1718 | (eaddr >= adev->vm_manager.max_pfn << AMDGPU_GPU_PAGE_SHIFT)) | ||
| 1719 | return -EINVAL; | ||
| 1720 | 1736 | ||
| 1721 | /* Allocate all the needed memory */ | 1737 | /* Allocate all the needed memory */ |
| 1722 | mapping = kmalloc(sizeof(*mapping), GFP_KERNEL); | 1738 | mapping = kmalloc(sizeof(*mapping), GFP_KERNEL); |
| @@ -1730,7 +1746,7 @@ int amdgpu_vm_bo_replace_map(struct amdgpu_device *adev, · 7 unmodified lines | |||
| 1730 | } | 1746 | } |
| 1731 | 1747 | ||
| 1732 | saddr /= AMDGPU_GPU_PAGE_SIZE; | 1748 | saddr /= AMDGPU_GPU_PAGE_SIZE; |
| 1733 | eaddr /= AMDGPU_GPU_PAGE_SIZE; | 1749 | eaddr = saddr + (size - 1) / AMDGPU_GPU_PAGE_SIZE; |
| 1734 | 1750 | ||
| 1735 | mapping->start = saddr; | 1751 | mapping->start = saddr; |
| 1736 | mapping->last = eaddr; | 1752 | mapping->last = eaddr; |
| @@ -1817,10 +1833,14 @@ int amdgpu_vm_bo_clear_mappings(struct amdgpu_device *adev, · 80 unmodified lines | |||
| 1817 | struct amdgpu_bo_va_mapping *before, *after, *tmp, *next; | 1833 | struct amdgpu_bo_va_mapping *before, *after, *tmp, *next; |
| 1818 | LIST_HEAD(removed); | 1834 | LIST_HEAD(removed); |
| 1819 | uint64_t eaddr; | 1835 | uint64_t eaddr; |
| 1836 | int r; | ||
| 1837 | |||
| 1838 | r = amdgpu_vm_verify_parameters(adev, NULL, saddr, 0, size); | ||
| 1839 | if (r) | ||
| 1840 | return r; | ||
| 1820 | 1841 | ||
| 1821 | eaddr = saddr + size - 1; | ||
| 1822 | saddr /= AMDGPU_GPU_PAGE_SIZE; | 1842 | saddr /= AMDGPU_GPU_PAGE_SIZE; |
| 1823 | eaddr /= AMDGPU_GPU_PAGE_SIZE; | 1843 | eaddr = saddr + (size - 1) / AMDGPU_GPU_PAGE_SIZE; |
| 1824 | 1844 | ||
| 1825 | /* Allocate all the needed memory */ | 1845 | /* Allocate all the needed memory */ |
| 1826 | before = kzalloc(sizeof(*before), GFP_KERNEL); | 1846 | before = kzalloc(sizeof(*before), GFP_KERNEL); |
| @@ -819,9 +819,9 @@ struct kfd_process *kfd_create_process(struct task_struct *thread) · 818 unmodified lines | |||
| 819 | mutex_lock(&kfd_processes_mutex); | 819 | mutex_lock(&kfd_processes_mutex); |
| 820 | 820 | ||
| 821 | if (kfd_is_locked()) { | 821 | if (kfd_is_locked()) { |
| 822 | mutex_unlock(&kfd_processes_mutex); | ||
| 823 | pr_debug("KFD is locked! Cannot create process"); | 822 | pr_debug("KFD is locked! Cannot create process"); |
| 824 | return ERR_PTR(-EINVAL); | 823 | process = ERR_PTR(-EINVAL); |
| 824 | goto out; | ||
| 825 | } | 825 | } |
| 826 | 826 | ||
| 827 | /* A prior open of /dev/kfd could have already created the process. */ | 827 | /* A prior open of /dev/kfd could have already created the process. */ |
| @@ -248,14 +248,12 @@ void dcn32_link_encoder_construct( · 247 unmodified lines | |||
| 248 | enc10->base.hpd_source = init_data->hpd_source; | 248 | enc10->base.hpd_source = init_data->hpd_source; |
| 249 | enc10->base.connector = init_data->connector; | 249 | enc10->base.connector = init_data->connector; |
| 250 | 250 | ||
| 251 | enc10->base.preferred_engine = ENGINE_ID_UNKNOWN; | ||
| 252 | |||
| 253 | enc10->base.features = *enc_features; | ||
| 254 | if (enc10->base.connector.id == CONNECTOR_ID_USBC) | 251 | if (enc10->base.connector.id == CONNECTOR_ID_USBC) |
| 255 | enc10->base.features.flags.bits.DP_IS_USB_C = 1; | 252 | enc10->base.features.flags.bits.DP_IS_USB_C = 1; |
| 256 | 253 | ||
| 257 | if (enc10->base.connector.id == CONNECTOR_ID_USBC) | 254 | enc10->base.preferred_engine = ENGINE_ID_UNKNOWN; |
| 258 | enc10->base.features.flags.bits.DP_IS_USB_C = 1; | 255 | |
| 256 | enc10->base.features = *enc_features; | ||
| 259 | 257 | ||
| 260 | enc10->base.transmitter = init_data->transmitter; | 258 | enc10->base.transmitter = init_data->transmitter; |
| 261 | 259 | ||
| @@ -184,6 +184,8 @@ void dcn35_link_encoder_construct( · 183 unmodified lines | |||
| 184 | enc10->base.hpd_source = init_data->hpd_source; | 184 | enc10->base.hpd_source = init_data->hpd_source; |
| 185 | enc10->base.connector = init_data->connector; | 185 | enc10->base.connector = init_data->connector; |
| 186 | 186 | ||
| 187 | if (enc10->base.connector.id == CONNECTOR_ID_USBC) | ||
| 188 | enc10->base.features.flags.bits.DP_IS_USB_C = 1; | ||
| 187 | 189 | ||
| 188 | enc10->base.preferred_engine = ENGINE_ID_UNKNOWN; | 190 | enc10->base.preferred_engine = ENGINE_ID_UNKNOWN; |
| 189 | 191 | ||
| @@ -238,8 +240,6 @@ void dcn35_link_encoder_construct( · 48 unmodified lines | |||
| 238 | } | 240 | } |
| 239 | 241 | ||
| 240 | enc10->base.features.flags.bits.HDMI_6GB_EN = 1; | 242 | enc10->base.features.flags.bits.HDMI_6GB_EN = 1; |
| 241 | if (enc10->base.connector.id == CONNECTOR_ID_USBC) | ||
| 242 | enc10->base.features.flags.bits.DP_IS_USB_C = 1; | ||
| 243 | 243 | ||
| 244 | if (bp_funcs->get_connector_speed_cap_info) | 244 | if (bp_funcs->get_connector_speed_cap_info) |
| 245 | result = bp_funcs->get_connector_speed_cap_info(enc10->base.ctx->dc_bios, | 245 | result = bp_funcs->get_connector_speed_cap_info(enc10->base.ctx->dc_bios, |
| @@ -23,6 +23,7 @@ · 22 unmodified lines | |||
| 23 | */ | 23 | */ |
| 24 | 24 | ||
| 25 | #include "nouveau_drv.h" | 25 | #include "nouveau_drv.h" |
| 26 | #include "nouveau_bios.h" | ||
| 26 | #include "nouveau_reg.h" | 27 | #include "nouveau_reg.h" |
| 27 | #include "dispnv04/hw.h" | 28 | #include "dispnv04/hw.h" |
| 28 | #include "nouveau_encoder.h" | 29 | #include "nouveau_encoder.h" |
| @@ -1677,7 +1678,7 @@ apply_dcb_encoder_quirks(struct drm_device *dev, int idx, u32 *conn, u32 *conf) · 1648 unmodified lines | |||
| 1677 | */ | 1678 | */ |
| 1678 | if (nv_match_device(dev, 0x0201, 0x1462, 0x8851)) { | 1679 | if (nv_match_device(dev, 0x0201, 0x1462, 0x8851)) { |
| 1679 | if (*conn == 0xf2005014 && *conf == 0xffffffff) { | 1680 | if (*conn == 0xf2005014 && *conf == 0xffffffff) { |
| 1680 | fabricate_dcb_output(dcb, DCB_OUTPUT_TMDS, 1, 1, 1); | 1681 | fabricate_dcb_output(dcb, DCB_OUTPUT_TMDS, 1, 1, DCB_OUTPUT_B); |
| 1681 | return false; | 1682 | return false; |
| 1682 | } | 1683 | } |
| 1683 | } | 1684 | } |
| @@ -1763,26 +1764,26 @@ fabricate_dcb_encoder_table(struct drm_device *dev, struct nvbios *bios) · 79 unmodified lines | |||
| 1763 | #ifdef __powerpc__ | 1764 | #ifdef __powerpc__ |
| 1764 | /* Apple iMac G4 NV17 */ | 1765 | /* Apple iMac G4 NV17 */ |
| 1765 | if (of_machine_is_compatible("PowerMac4,5")) { | 1766 | if (of_machine_is_compatible("PowerMac4,5")) { |
| 1766 | fabricate_dcb_output(dcb, DCB_OUTPUT_TMDS, 0, all_heads, 1); | 1767 | fabricate_dcb_output(dcb, DCB_OUTPUT_TMDS, 0, all_heads, DCB_OUTPUT_B); |
| 1767 | fabricate_dcb_output(dcb, DCB_OUTPUT_ANALOG, 1, all_heads, 2); | 1768 | fabricate_dcb_output(dcb, DCB_OUTPUT_ANALOG, 1, all_heads, DCB_OUTPUT_C); |
| 1768 | return; | 1769 | return; |
| 1769 | } | 1770 | } |
| 1770 | #endif | 1771 | #endif |
| 1771 | 1772 | ||
| 1772 | /* Make up some sane defaults */ | 1773 | /* Make up some sane defaults */ |
| 1773 | fabricate_dcb_output(dcb, DCB_OUTPUT_ANALOG, | 1774 | fabricate_dcb_output(dcb, DCB_OUTPUT_ANALOG, |
| 1774 | bios->legacy.i2c_indices.crt, 1, 1); | 1775 | bios->legacy.i2c_indices.crt, 1, DCB_OUTPUT_B); |
| 1775 | 1776 | ||
| 1776 | if (nv04_tv_identify(dev, bios->legacy.i2c_indices.tv) >= 0) | 1777 | if (nv04_tv_identify(dev, bios->legacy.i2c_indices.tv) >= 0) |
| 1777 | fabricate_dcb_output(dcb, DCB_OUTPUT_TV, | 1778 | fabricate_dcb_output(dcb, DCB_OUTPUT_TV, |
| 1778 | bios->legacy.i2c_indices.tv, | 1779 | bios->legacy.i2c_indices.tv, |
| 1779 | all_heads, 0); | 1780 | all_heads, DCB_OUTPUT_A); |
| 1780 | 1781 | ||
| 1781 | else if (bios->tmds.output0_script_ptr || | 1782 | else if (bios->tmds.output0_script_ptr || |
| 1782 | bios->tmds.output1_script_ptr) | 1783 | bios->tmds.output1_script_ptr) |
| 1783 | fabricate_dcb_output(dcb, DCB_OUTPUT_TMDS, | 1784 | fabricate_dcb_output(dcb, DCB_OUTPUT_TMDS, |
| 1784 | bios->legacy.i2c_indices.panel, | 1785 | bios->legacy.i2c_indices.panel, |
| 1785 | all_heads, 1); | 1786 | all_heads, DCB_OUTPUT_B); |
| 1786 | } | 1787 | } |
| 1787 | 1788 | ||
| 1788 | static int | 1789 | static int |
| @@ -225,12 +225,18 @@ nouveau_dp_detect(struct nouveau_connector *nv_connector, · 224 unmodified lines | |||
| 225 | u8 *dpcd = nv_encoder->dp.dpcd; | 225 | u8 *dpcd = nv_encoder->dp.dpcd; |
| 226 | int ret = NOUVEAU_DP_NONE, hpd; | 226 | int ret = NOUVEAU_DP_NONE, hpd; |
| 227 | 227 | ||
| 228 | /* If we've already read the DPCD on an eDP device, we don't need to | 228 | /* eDP ports don't support hotplugging - so there's no point in probing eDP ports unless we |
| 229 | * reread it as it won't change | 229 | * haven't probed them once before. |
| 230 | */ | 230 | */ |
| 231 | if (connector->connector_type == DRM_MODE_CONNECTOR_eDP && | 231 | if (connector->connector_type == DRM_MODE_CONNECTOR_eDP) { |
| 232 | dpcd[DP_DPCD_REV] != 0) | 232 | if (connector->status == connector_status_connected) |
| 233 | return NOUVEAU_DP_SST; | 233 | return NOUVEAU_DP_SST; |
| 234 | else if (connector->status == connector_status_disconnected) | ||
| 235 | return NOUVEAU_DP_NONE; | ||
| 236 | } | ||
| 237 | |||
| 238 | // Ensure that the aux bus is enabled for probing | ||
| 239 | drm_dp_dpcd_set_powered(&nv_connector->aux, true); | ||
| 234 | 240 | ||
| 235 | mutex_lock(&nv_encoder->dp.hpd_irq_lock); | 241 | mutex_lock(&nv_encoder->dp.hpd_irq_lock); |
| 236 | if (mstm) { | 242 | if (mstm) { |
| @@ -293,6 +299,13 @@ out: · 56 unmodified lines | |||
| 293 | if (mstm && !mstm->suspended && ret != NOUVEAU_DP_MST) | 299 | if (mstm && !mstm->suspended && ret != NOUVEAU_DP_MST) |
| 294 | nv50_mstm_remove(mstm); | 300 | nv50_mstm_remove(mstm); |
| 295 | 301 | ||
| 302 | /* GSP doesn't like when we try to do aux transactions on a port it considers disconnected, | ||
| 303 | * and since we don't really have a usecase for that anyway - just disable the aux bus here | ||
| 304 | * if we've decided the connector is disconnected | ||
| 305 | */ | ||
| 306 | if (ret == NOUVEAU_DP_NONE) | ||
| 307 | drm_dp_dpcd_set_powered(&nv_connector->aux, false); | ||
| 308 | |||
| 296 | mutex_unlock(&nv_encoder->dp.hpd_irq_lock); | 309 | mutex_unlock(&nv_encoder->dp.hpd_irq_lock); |
| 297 | return ret; | 310 | return ret; |
| 298 | } | 311 | } |
| @@ -222,8 +222,11 @@ nv50_instobj_acquire(struct nvkm_memory *memory) · 221 unmodified lines | |||
| 222 | void __iomem *map = NULL; | 222 | void __iomem *map = NULL; |
| 223 | 223 | ||
| 224 | /* Already mapped? */ | 224 | /* Already mapped? */ |
| 225 | if (refcount_inc_not_zero(&iobj->maps)) | 225 | if (refcount_inc_not_zero(&iobj->maps)) { |
| 226 | /* read barrier match the wmb on refcount set */ | ||
| 227 | smp_rmb(); | ||
| 226 | return iobj->map; | 228 | return iobj->map; |
| 229 | } | ||
| 227 | 230 | ||
| 228 | /* Take the lock, and re-check that another thread hasn't | 231 | /* Take the lock, and re-check that another thread hasn't |
| 229 | * already mapped the object in the meantime. | 232 | * already mapped the object in the meantime. |
| @@ -250,6 +253,8 @@ nv50_instobj_acquire(struct nvkm_memory *memory) · 20 unmodified lines | |||
| 250 | iobj->base.memory.ptrs = &nv50_instobj_fast; | 253 | iobj->base.memory.ptrs = &nv50_instobj_fast; |
| 251 | else | 254 | else |
| 252 | iobj->base.memory.ptrs = &nv50_instobj_slow; | 255 | iobj->base.memory.ptrs = &nv50_instobj_slow; |
| 256 | /* barrier to ensure the ptrs are written before refcount is set */ | ||
| 257 | smp_wmb(); | ||
| 253 | refcount_set(&iobj->maps, 1); | 258 | refcount_set(&iobj->maps, 1); |
| 254 | } | 259 | } |
| 255 | 260 | ||
| @@ -614,8 +614,6 @@ static void nt36672e_panel_remove(struct mipi_dsi_device *dsi) · 613 unmodified lines | |||
| 614 | struct nt36672e_panel *ctx = mipi_dsi_get_drvdata(dsi); | 614 | struct nt36672e_panel *ctx = mipi_dsi_get_drvdata(dsi); |
| 615 | 615 | ||
| 616 | mipi_dsi_detach(ctx->dsi); | 616 | mipi_dsi_detach(ctx->dsi); |
| 617 | mipi_dsi_device_unregister(ctx->dsi); | ||
| 618 | |||
| 619 | drm_panel_remove(&ctx->panel); | 617 | drm_panel_remove(&ctx->panel); |
| 620 | } | 618 | } |
| 621 | 619 | ||
| @@ -253,8 +253,6 @@ static void visionox_rm69299_remove(struct mipi_dsi_device *dsi) · 252 unmodified lines | |||
| 253 | struct visionox_rm69299 *ctx = mipi_dsi_get_drvdata(dsi); | 253 | struct visionox_rm69299 *ctx = mipi_dsi_get_drvdata(dsi); |
| 254 | 254 | ||
| 255 | mipi_dsi_detach(ctx->dsi); | 255 | mipi_dsi_detach(ctx->dsi); |
| 256 | mipi_dsi_device_unregister(ctx->dsi); | ||
| 257 | |||
| 258 | drm_panel_remove(&ctx->panel); | 256 | drm_panel_remove(&ctx->panel); |
| 259 | } | 257 | } |
| 260 | 258 | ||
| @@ -424,7 +424,7 @@ typedef struct _ATOM_PPLIB_SUMO_CLOCK_INFO{ · 423 unmodified lines | |||
| 424 | typedef struct _ATOM_PPLIB_STATE_V2 | 424 | typedef struct _ATOM_PPLIB_STATE_V2 |
| 425 | { | 425 | { |
| 426 | //number of valid dpm levels in this state; Driver uses it to calculate the whole | 426 | //number of valid dpm levels in this state; Driver uses it to calculate the whole |
| 427 | //size of the state: sizeof(ATOM_PPLIB_STATE_V2) + (ucNumDPMLevels - 1) * sizeof(UCHAR) | 427 | //size of the state: struct_size(ATOM_PPLIB_STATE_V2, clockInfoIndex, ucNumDPMLevels) |
| 428 | UCHAR ucNumDPMLevels; | 428 | UCHAR ucNumDPMLevels; |
| 429 | 429 | ||
| 430 | //a index to the array of nonClockInfos | 430 | //a index to the array of nonClockInfos |
| @@ -432,14 +432,14 @@ typedef struct _ATOM_PPLIB_STATE_V2 · 1 unmodified line | |||
| 432 | /** | 432 | /** |
| 433 | * Driver will read the first ucNumDPMLevels in this array | 433 | * Driver will read the first ucNumDPMLevels in this array |
| 434 | */ | 434 | */ |
| 435 | UCHAR clockInfoIndex[1]; | 435 | UCHAR clockInfoIndex[] __counted_by(ucNumDPMLevels); |
| 436 | } ATOM_PPLIB_STATE_V2; | 436 | } ATOM_PPLIB_STATE_V2; |
| 437 | 437 | ||
| 438 | typedef struct _StateArray{ | 438 | typedef struct _StateArray{ |
| 439 | //how many states we have | 439 | //how many states we have |
| 440 | UCHAR ucNumEntries; | 440 | UCHAR ucNumEntries; |
| 441 | 441 | ||
| 442 | ATOM_PPLIB_STATE_V2 states[1]; | 442 | ATOM_PPLIB_STATE_V2 states[] __counted_by(ucNumEntries); |
| 443 | }StateArray; | 443 | }StateArray; |
| 444 | 444 | ||
| 445 | 445 | ||
| @@ -450,7 +450,7 @@ typedef struct _ClockInfoArray{ · 4 unmodified lines | |||
| 450 | //sizeof(ATOM_PPLIB_CLOCK_INFO) | 450 | //sizeof(ATOM_PPLIB_CLOCK_INFO) |
| 451 | UCHAR ucEntrySize; | 451 | UCHAR ucEntrySize; |
| 452 | 452 | ||
| 453 | UCHAR clockInfo[1]; | 453 | UCHAR clockInfo[] __counted_by(ucNumEntries); |
| 454 | }ClockInfoArray; | 454 | }ClockInfoArray; |
| 455 | 455 | ||
| 456 | typedef struct _NonClockInfoArray{ | 456 | typedef struct _NonClockInfoArray{ |
| @@ -460,7 +460,7 @@ typedef struct _NonClockInfoArray{ · 3 unmodified lines | |||
| 460 | //sizeof(ATOM_PPLIB_NONCLOCK_INFO) | 460 | //sizeof(ATOM_PPLIB_NONCLOCK_INFO) |
| 461 | UCHAR ucEntrySize; | 461 | UCHAR ucEntrySize; |
| 462 | 462 | ||
| 463 | ATOM_PPLIB_NONCLOCK_INFO nonClockInfo[1]; | 463 | ATOM_PPLIB_NONCLOCK_INFO nonClockInfo[] __counted_by(ucNumEntries); |
| 464 | }NonClockInfoArray; | 464 | }NonClockInfoArray; |
| 465 | 465 | ||
| 466 | typedef struct _ATOM_PPLIB_Clock_Voltage_Dependency_Record | 466 | typedef struct _ATOM_PPLIB_Clock_Voltage_Dependency_Record |
| @@ -923,8 +923,12 @@ bool radeon_get_atom_connector_info_from_supported_devices_table(struct · 922 unmodified lines | |||
| 923 | max_device = ATOM_MAX_SUPPORTED_DEVICE_INFO; | 923 | max_device = ATOM_MAX_SUPPORTED_DEVICE_INFO; |
| 924 | 924 | ||
| 925 | for (i = 0; i < max_device; i++) { | 925 | for (i = 0; i < max_device; i++) { |
| 926 | ATOM_CONNECTOR_INFO_I2C ci = | 926 | ATOM_CONNECTOR_INFO_I2C ci; |
| 927 | supported_devices->info.asConnInfo[i]; | 927 | |
| 928 | if (frev > 1) | ||
| 929 | ci = supported_devices->info_2d1.asConnInfo[i]; | ||
| 930 | else | ||
| 931 | ci = supported_devices->info.asConnInfo[i]; | ||
| 928 | 932 | ||
| 929 | bios_connectors[i].valid = false; | 933 | bios_connectors[i].valid = false; |
| 930 | 934 | ||
| @@ -288,17 +288,23 @@ static struct ttm_pool_type *ttm_pool_select_type(struct ttm_pool *pool, · 287 unmodified lines | |||
| 288 | enum ttm_caching caching, | 288 | enum ttm_caching caching, |
| 289 | unsigned int order) | 289 | unsigned int order) |
| 290 | { | 290 | { |
| 291 | if (pool->use_dma_alloc || pool->nid != NUMA_NO_NODE) | 291 | if (pool->use_dma_alloc) |
| 292 | return &pool->caching[caching].orders[order]; | 292 | return &pool->caching[caching].orders[order]; |
| 293 | 293 | ||
| 294 | #ifdef CONFIG_X86 | 294 | #ifdef CONFIG_X86 |
| 295 | switch (caching) { | 295 | switch (caching) { |
| 296 | case ttm_write_combined: | 296 | case ttm_write_combined: |
| 297 | if (pool->nid != NUMA_NO_NODE) | ||
| 298 | return &pool->caching[caching].orders[order]; | ||
| 299 | |||
| 297 | if (pool->use_dma32) | 300 | if (pool->use_dma32) |
| 298 | return &global_dma32_write_combined[order]; | 301 | return &global_dma32_write_combined[order]; |
| 299 | 302 | ||
| 300 | return &global_write_combined[order]; | 303 | return &global_write_combined[order]; |
| 301 | case ttm_uncached: | 304 | case ttm_uncached: |
| 305 | if (pool->nid != NUMA_NO_NODE) | ||
| 306 | return &pool->caching[caching].orders[order]; | ||
| 307 | |||
| 302 | if (pool->use_dma32) | 308 | if (pool->use_dma32) |
| 303 | return &global_dma32_uncached[order]; | 309 | return &global_dma32_uncached[order]; |
| 304 | 310 | ||
| @@ -566,11 +572,17 @@ void ttm_pool_init(struct ttm_pool *pool, struct device *dev, · 261 unmodified lines | |||
| 566 | pool->use_dma_alloc = use_dma_alloc; | 572 | pool->use_dma_alloc = use_dma_alloc; |
| 567 | pool->use_dma32 = use_dma32; | 573 | pool->use_dma32 = use_dma32; |
| 568 | 574 | ||
| 569 | if (use_dma_alloc || nid != NUMA_NO_NODE) { | 575 | for (i = 0; i < TTM_NUM_CACHING_TYPES; ++i) { |
| 570 | for (i = 0; i < TTM_NUM_CACHING_TYPES; ++i) | 576 | for (j = 0; j < NR_PAGE_ORDERS; ++j) { |
| 571 | for (j = 0; j < NR_PAGE_ORDERS; ++j) | 577 | struct ttm_pool_type *pt; |
| 572 | ttm_pool_type_init(&pool->caching[i].orders[j], | 578 | |
| 573 | pool, i, j); | 579 | /* Initialize only pool types which are actually used */ |
| 580 | pt = ttm_pool_select_type(pool, i, j); | ||
| 581 | if (pt != &pool->caching[i].orders[j]) | ||
| 582 | continue; | ||
| 583 | |||
| 584 | ttm_pool_type_init(pt, pool, i, j); | ||
| 585 | } | ||
| 574 | } | 586 | } |
| 575 | } | 587 | } |
| 576 | EXPORT_SYMBOL(ttm_pool_init); | 588 | EXPORT_SYMBOL(ttm_pool_init); |
| @@ -599,10 +611,16 @@ void ttm_pool_fini(struct ttm_pool *pool) · 22 unmodified lines | |||
| 599 | { | 611 | { |
| 600 | unsigned int i, j; | 612 | unsigned int i, j; |
| 601 | 613 | ||
| 602 | if (pool->use_dma_alloc || pool->nid != NUMA_NO_NODE) { | 614 | for (i = 0; i < TTM_NUM_CACHING_TYPES; ++i) { |
| 603 | for (i = 0; i < TTM_NUM_CACHING_TYPES; ++i) | 615 | for (j = 0; j < NR_PAGE_ORDERS; ++j) { |
| 604 | for (j = 0; j < NR_PAGE_ORDERS; ++j) | 616 | struct ttm_pool_type *pt; |
| 605 | ttm_pool_type_fini(&pool->caching[i].orders[j]); | 617 | |
| 618 | pt = ttm_pool_select_type(pool, i, j); | ||
| 619 | if (pt != &pool->caching[i].orders[j]) | ||
| 620 | continue; | ||
| 621 | |||
| 622 | ttm_pool_type_fini(pt); | ||
| 623 | } | ||
| 606 | } | 624 | } |
| 607 | 625 | ||
| 608 | /* We removed the pool types from the LRU, but we need to also make sure | 626 | /* We removed the pool types from the LRU, but we need to also make sure |
| @@ -105,7 +105,6 @@ v3d_irq(int irq, void *arg) · 104 unmodified lines | |||
| 105 | struct v3d_file_priv *file = v3d->bin_job->base.file->driver_priv; | 105 | struct v3d_file_priv *file = v3d->bin_job->base.file->driver_priv; |
| 106 | u64 runtime = local_clock() - file->start_ns[V3D_BIN]; | 106 | u64 runtime = local_clock() - file->start_ns[V3D_BIN]; |
| 107 | 107 | ||
| 108 | file->enabled_ns[V3D_BIN] += local_clock() - file->start_ns[V3D_BIN]; | ||
| 109 | file->jobs_sent[V3D_BIN]++; | 108 | file->jobs_sent[V3D_BIN]++; |
| 110 | v3d->queue[V3D_BIN].jobs_sent++; | 109 | v3d->queue[V3D_BIN].jobs_sent++; |
| 111 | 110 | ||
| @@ -126,7 +125,6 @@ v3d_irq(int irq, void *arg) · 14 unmodified lines | |||
| 126 | struct v3d_file_priv *file = v3d->render_job->base.file->driver_priv; | 125 | struct v3d_file_priv *file = v3d->render_job->base.file->driver_priv; |
| 127 | u64 runtime = local_clock() - file->start_ns[V3D_RENDER]; | 126 | u64 runtime = local_clock() - file->start_ns[V3D_RENDER]; |
| 128 | 127 | ||
| 129 | file->enabled_ns[V3D_RENDER] += local_clock() - file->start_ns[V3D_RENDER]; | ||
| 130 | file->jobs_sent[V3D_RENDER]++; | 128 | file->jobs_sent[V3D_RENDER]++; |
| 131 | v3d->queue[V3D_RENDER].jobs_sent++; | 129 | v3d->queue[V3D_RENDER].jobs_sent++; |
| 132 | 130 | ||
| @@ -147,7 +145,6 @@ v3d_irq(int irq, void *arg) · 14 unmodified lines | |||
| 147 | struct v3d_file_priv *file = v3d->csd_job->base.file->driver_priv; | 145 | struct v3d_file_priv *file = v3d->csd_job->base.file->driver_priv; |
| 148 | u64 runtime = local_clock() - file->start_ns[V3D_CSD]; | 146 | u64 runtime = local_clock() - file->start_ns[V3D_CSD]; |
| 149 | 147 | ||
| 150 | file->enabled_ns[V3D_CSD] += local_clock() - file->start_ns[V3D_CSD]; | ||
| 151 | file->jobs_sent[V3D_CSD]++; | 148 | file->jobs_sent[V3D_CSD]++; |
| 152 | v3d->queue[V3D_CSD].jobs_sent++; | 149 | v3d->queue[V3D_CSD].jobs_sent++; |
| 153 | 150 | ||
| @@ -195,7 +192,6 @@ v3d_hub_irq(int irq, void *arg) · 41 unmodified lines | |||
| 195 | struct v3d_file_priv *file = v3d->tfu_job->base.file->driver_priv; | 192 | struct v3d_file_priv *file = v3d->tfu_job->base.file->driver_priv; |
| 196 | u64 runtime = local_clock() - file->start_ns[V3D_TFU]; | 193 | u64 runtime = local_clock() - file->start_ns[V3D_TFU]; |
| 197 | 194 | ||
| 198 | file->enabled_ns[V3D_TFU] += local_clock() - file->start_ns[V3D_TFU]; | ||
| 199 | file->jobs_sent[V3D_TFU]++; | 195 | file->jobs_sent[V3D_TFU]++; |
| 200 | v3d->queue[V3D_TFU].jobs_sent++; | 196 | v3d->queue[V3D_TFU].jobs_sent++; |
| 201 | 197 | ||
| @@ -456,8 +456,10 @@ int vmw_bo_cpu_blit(struct ttm_buffer_object *dst, · 455 unmodified lines | |||
| 456 | .no_wait_gpu = false | 456 | .no_wait_gpu = false |
| 457 | }; | 457 | }; |
| 458 | u32 j, initial_line = dst_offset / dst_stride; | 458 | u32 j, initial_line = dst_offset / dst_stride; |
| 459 | struct vmw_bo_blit_line_data d; | 459 | struct vmw_bo_blit_line_data d = {0}; |
| 460 | int ret = 0; | 460 | int ret = 0; |
| 461 | struct page **dst_pages = NULL; | ||
| 462 | struct page **src_pages = NULL; | ||
| 461 | 463 | ||
| 462 | /* Buffer objects need to be either pinned or reserved: */ | 464 | /* Buffer objects need to be either pinned or reserved: */ |
| 463 | if (!(dst->pin_count)) | 465 | if (!(dst->pin_count)) |
| @@ -477,12 +479,35 @@ int vmw_bo_cpu_blit(struct ttm_buffer_object *dst, · 13 unmodified lines | |||
| 477 | return ret; | 479 | return ret; |
| 478 | } | 480 | } |
| 479 | 481 | ||
| 482 | if (!src->ttm->pages && src->ttm->sg) { | ||
| 483 | src_pages = kvmalloc_array(src->ttm->num_pages, | ||
| 484 | sizeof(struct page *), GFP_KERNEL); | ||
| 485 | if (!src_pages) | ||
| 486 | return -ENOMEM; | ||
| 487 | ret = drm_prime_sg_to_page_array(src->ttm->sg, src_pages, | ||
| 488 | src->ttm->num_pages); | ||
| 489 | if (ret) | ||
| 490 | goto out; | ||
| 491 | } | ||
| 492 | if (!dst->ttm->pages && dst->ttm->sg) { | ||
| 493 | dst_pages = kvmalloc_array(dst->ttm->num_pages, | ||
| 494 | sizeof(struct page *), GFP_KERNEL); | ||
| 495 | if (!dst_pages) { | ||
| 496 | ret = -ENOMEM; | ||
| 497 | goto out; | ||
| 498 | } | ||
| 499 | ret = drm_prime_sg_to_page_array(dst->ttm->sg, dst_pages, | ||
| 500 | dst->ttm->num_pages); | ||
| 501 | if (ret) | ||
| 502 | goto out; | ||
| 503 | } | ||
| 504 | |||
| 480 | d.mapped_dst = 0; | 505 | d.mapped_dst = 0; |
| 481 | d.mapped_src = 0; | 506 | d.mapped_src = 0; |
| 482 | d.dst_addr = NULL; | 507 | d.dst_addr = NULL; |
| 483 | d.src_addr = NULL; | 508 | d.src_addr = NULL; |
| 484 | d.dst_pages = dst->ttm->pages; | 509 | d.dst_pages = dst->ttm->pages ? dst->ttm->pages : dst_pages; |
| 485 | d.src_pages = src->ttm->pages; | 510 | d.src_pages = src->ttm->pages ? src->ttm->pages : src_pages; |
| 486 | d.dst_num_pages = PFN_UP(dst->resource->size); | 511 | d.dst_num_pages = PFN_UP(dst->resource->size); |
| 487 | d.src_num_pages = PFN_UP(src->resource->size); | 512 | d.src_num_pages = PFN_UP(src->resource->size); |
| 488 | d.dst_prot = ttm_io_prot(dst, dst->resource, PAGE_KERNEL); | 513 | d.dst_prot = ttm_io_prot(dst, dst->resource, PAGE_KERNEL); |
| @@ -504,6 +529,10 @@ out: · 15 unmodified lines | |||
| 504 | kunmap_atomic(d.src_addr); | 529 | kunmap_atomic(d.src_addr); |
| 505 | if (d.dst_addr) | 530 | if (d.dst_addr) |
| 506 | kunmap_atomic(d.dst_addr); | 531 | kunmap_atomic(d.dst_addr); |
| 532 | if (src_pages) | ||
| 533 | kvfree(src_pages); | ||
| 534 | if (dst_pages) | ||
| 535 | kvfree(dst_pages); | ||
| 507 | 536 | ||
| 508 | return ret; | 537 | return ret; |
| 509 | } | 538 | } |
| @@ -377,7 +377,8 @@ static int vmw_bo_init(struct vmw_private *dev_priv, · 376 unmodified lines | |||
| 377 | { | 377 | { |
| 378 | struct ttm_operation_ctx ctx = { | 378 | struct ttm_operation_ctx ctx = { |
| 379 | .interruptible = params->bo_type != ttm_bo_type_kernel, | 379 | .interruptible = params->bo_type != ttm_bo_type_kernel, |
| 380 | .no_wait_gpu = false | 380 | .no_wait_gpu = false, |
| 381 | .resv = params->resv, | ||
| 381 | }; | 382 | }; |
| 382 | struct ttm_device *bdev = &dev_priv->bdev; | 383 | struct ttm_device *bdev = &dev_priv->bdev; |
| 383 | struct drm_device *vdev = &dev_priv->drm; | 384 | struct drm_device *vdev = &dev_priv->drm; |
| @@ -394,8 +395,8 @@ static int vmw_bo_init(struct vmw_private *dev_priv, · 10 unmodified lines | |||
| 394 | 395 | ||
| 395 | vmw_bo_placement_set(vmw_bo, params->domain, params->busy_domain); | 396 | vmw_bo_placement_set(vmw_bo, params->domain, params->busy_domain); |
| 396 | ret = ttm_bo_init_reserved(bdev, &vmw_bo->tbo, params->bo_type, | 397 | ret = ttm_bo_init_reserved(bdev, &vmw_bo->tbo, params->bo_type, |
| 397 | &vmw_bo->placement, 0, &ctx, NULL, | 398 | &vmw_bo->placement, 0, &ctx, |
| 398 | NULL, destroy); | 399 | params->sg, params->resv, destroy); |
| 399 | if (unlikely(ret)) | 400 | if (unlikely(ret)) |
| 400 | return ret; | 401 | return ret; |
| 401 | 402 | ||
| @@ -55,6 +55,8 @@ struct vmw_bo_params { · 54 unmodified lines | |||
| 55 | enum ttm_bo_type bo_type; | 55 | enum ttm_bo_type bo_type; |
| 56 | size_t size; | 56 | size_t size; |
| 57 | bool pin; | 57 | bool pin; |
| 58 | struct dma_resv *resv; | ||
| 59 | struct sg_table *sg; | ||
| 58 | }; | 60 | }; |
| 59 | 61 | ||
| 60 | /** | 62 | /** |
| @@ -1628,6 +1628,7 @@ static const struct drm_driver driver = { · 1627 unmodified lines | |||
| 1628 | 1628 | ||
| 1629 | .prime_fd_to_handle = vmw_prime_fd_to_handle, | 1629 | .prime_fd_to_handle = vmw_prime_fd_to_handle, |
| 1630 | .prime_handle_to_fd = vmw_prime_handle_to_fd, | 1630 | .prime_handle_to_fd = vmw_prime_handle_to_fd, |
| 1631 | .gem_prime_import_sg_table = vmw_prime_import_sg_table, | ||
| 1631 | 1632 | ||
| 1632 | .fops = &vmwgfx_driver_fops, | 1633 | .fops = &vmwgfx_driver_fops, |
| 1633 | .name = VMWGFX_DRIVER_NAME, | 1634 | .name = VMWGFX_DRIVER_NAME, |
| @@ -1130,6 +1130,9 @@ extern int vmw_prime_handle_to_fd(struct drm_device *dev, · 1129 unmodified lines | |||
| 1130 | struct drm_file *file_priv, | 1130 | struct drm_file *file_priv, |
| 1131 | uint32_t handle, uint32_t flags, | 1131 | uint32_t handle, uint32_t flags, |
| 1132 | int *prime_fd); | 1132 | int *prime_fd); |
| 1133 | struct drm_gem_object *vmw_prime_import_sg_table(struct drm_device *dev, | ||
| 1134 | struct dma_buf_attachment *attach, | ||
| 1135 | struct sg_table *table); | ||
| 1133 | 1136 | ||
| 1134 | /* | 1137 | /* |
| 1135 | * MemoryOBject management - vmwgfx_mob.c | 1138 | * MemoryOBject management - vmwgfx_mob.c |
| @@ -149,6 +149,38 @@ out_no_bo: · 148 unmodified lines | |||
| 149 | return ret; | 149 | return ret; |
| 150 | } | 150 | } |
| 151 | 151 | ||
| 152 | struct drm_gem_object *vmw_prime_import_sg_table(struct drm_device *dev, | ||
| 153 | struct dma_buf_attachment *attach, | ||
| 154 | struct sg_table *table) | ||
| 155 | { | ||
| 156 | int ret; | ||
| 157 | struct vmw_private *dev_priv = vmw_priv(dev); | ||
| 158 | struct drm_gem_object *gem = NULL; | ||
| 159 | struct vmw_bo *vbo; | ||
| 160 | struct vmw_bo_params params = { | ||
| 161 | .domain = (dev_priv->has_mob) ? VMW_BO_DOMAIN_SYS : VMW_BO_DOMAIN_VRAM, | ||
| 162 | .busy_domain = VMW_BO_DOMAIN_SYS, | ||
| 163 | .bo_type = ttm_bo_type_sg, | ||
| 164 | .size = attach->dmabuf->size, | ||
| 165 | .pin = false, | ||
| 166 | .resv = attach->dmabuf->resv, | ||
| 167 | .sg = table, | ||
| 168 | |||
| 169 | }; | ||
| 170 | |||
| 171 | dma_resv_lock(params.resv, NULL); | ||
| 172 | |||
| 173 | ret = vmw_bo_create(dev_priv, ¶ms, &vbo); | ||
| 174 | if (ret != 0) | ||
| 175 | goto out_no_bo; | ||
| 176 | |||
| 177 | vbo->tbo.base.funcs = &vmw_gem_object_funcs; | ||
| 178 | |||
| 179 | gem = &vbo->tbo.base; | ||
| 180 | out_no_bo: | ||
| 181 | dma_resv_unlock(params.resv); | ||
| 182 | return gem; | ||
| 183 | } | ||
| 152 | 184 | ||
| 153 | int vmw_gem_object_create_ioctl(struct drm_device *dev, void *data, | 185 | int vmw_gem_object_create_ioctl(struct drm_device *dev, void *data, |
| 154 | struct drm_file *filp) | 186 | struct drm_file *filp) |
| @@ -933,6 +933,7 @@ int vmw_du_cursor_plane_atomic_check(struct drm_plane *plane, · 932 unmodified lines | |||
| 933 | int vmw_du_crtc_atomic_check(struct drm_crtc *crtc, | 933 | int vmw_du_crtc_atomic_check(struct drm_crtc *crtc, |
| 934 | struct drm_atomic_state *state) | 934 | struct drm_atomic_state *state) |
| 935 | { | 935 | { |
| 936 | struct vmw_private *vmw = vmw_priv(crtc->dev); | ||
| 936 | struct drm_crtc_state *new_state = drm_atomic_get_new_crtc_state(state, | 937 | struct drm_crtc_state *new_state = drm_atomic_get_new_crtc_state(state, |
| 937 | crtc); | 938 | crtc); |
| 938 | struct vmw_display_unit *du = vmw_crtc_to_du(new_state->crtc); | 939 | struct vmw_display_unit *du = vmw_crtc_to_du(new_state->crtc); |
| @@ -940,9 +941,13 @@ int vmw_du_crtc_atomic_check(struct drm_crtc *crtc, · 1 unmodified line | |||
| 940 | bool has_primary = new_state->plane_mask & | 941 | bool has_primary = new_state->plane_mask & |
| 941 | drm_plane_mask(crtc->primary); | 942 | drm_plane_mask(crtc->primary); |
| 942 | 943 | ||
| 943 | /* We always want to have an active plane with an active CRTC */ | 944 | /* |
| 944 | if (has_primary != new_state->enable) | 945 | * This is fine in general, but broken userspace might expect |
| 945 | return -EINVAL; | 946 | * some actual rendering so give a clue as why it's blank. |
| 947 | */ | ||
| 948 | if (new_state->enable && !has_primary) | ||
| 949 | drm_dbg_driver(&vmw->drm, | ||
| 950 | "CRTC without a primary plane will be blank.\n"); | ||
| 946 | 951 | ||
| 947 | 952 | ||
| 948 | if (new_state->connector_mask != connector_mask && | 953 | if (new_state->connector_mask != connector_mask && |
| @@ -243,10 +243,10 @@ struct vmw_framebuffer_bo { · 242 unmodified lines | |||
| 243 | 243 | ||
| 244 | 244 | ||
| 245 | static const uint32_t __maybe_unused vmw_primary_plane_formats[] = { | 245 | static const uint32_t __maybe_unused vmw_primary_plane_formats[] = { |
| 246 | DRM_FORMAT_XRGB1555, | ||
| 247 | DRM_FORMAT_RGB565, | ||
| 248 | DRM_FORMAT_XRGB8888, | 246 | DRM_FORMAT_XRGB8888, |
| 249 | DRM_FORMAT_ARGB8888, | 247 | DRM_FORMAT_ARGB8888, |
| 248 | DRM_FORMAT_RGB565, | ||
| 249 | DRM_FORMAT_XRGB1555, | ||
| 250 | }; | 250 | }; |
| 251 | 251 | ||
| 252 | static const uint32_t __maybe_unused vmw_cursor_plane_formats[] = { | 252 | static const uint32_t __maybe_unused vmw_cursor_plane_formats[] = { |
| @@ -75,8 +75,12 @@ int vmw_prime_fd_to_handle(struct drm_device *dev, · 74 unmodified lines | |||
| 75 | int fd, u32 *handle) | 75 | int fd, u32 *handle) |
| 76 | { | 76 | { |
| 77 | struct ttm_object_file *tfile = vmw_fpriv(file_priv)->tfile; | 77 | struct ttm_object_file *tfile = vmw_fpriv(file_priv)->tfile; |
| 78 | int ret = ttm_prime_fd_to_handle(tfile, fd, handle); | ||
| 78 | 79 | ||
| 79 | return ttm_prime_fd_to_handle(tfile, fd, handle); | 80 | if (ret) |
| 81 | ret = drm_gem_prime_fd_to_handle(dev, file_priv, fd, handle); | ||
| 82 | |||
| 83 | return ret; | ||
| 80 | } | 84 | } |
| 81 | 85 | ||
| 82 | int vmw_prime_handle_to_fd(struct drm_device *dev, | 86 | int vmw_prime_handle_to_fd(struct drm_device *dev, |
| @@ -85,5 +89,12 @@ int vmw_prime_handle_to_fd(struct drm_device *dev, · 2 unmodified lines | |||
| 85 | int *prime_fd) | 89 | int *prime_fd) |
| 86 | { | 90 | { |
| 87 | struct ttm_object_file *tfile = vmw_fpriv(file_priv)->tfile; | 91 | struct ttm_object_file *tfile = vmw_fpriv(file_priv)->tfile; |
| 88 | return ttm_prime_handle_to_fd(tfile, handle, flags, prime_fd); | 92 | int ret; |
| 93 | |||
| 94 | if (handle > VMWGFX_NUM_MOB) | ||
| 95 | ret = ttm_prime_handle_to_fd(tfile, handle, flags, prime_fd); | ||
| 96 | else | ||
| 97 | ret = drm_gem_prime_handle_to_fd(dev, file_priv, handle, flags, prime_fd); | ||
| 98 | |||
| 99 | return ret; | ||
| 89 | } | 100 | } |
| @@ -188,13 +188,18 @@ static int vmw_ttm_map_dma(struct vmw_ttm_tt *vmw_tt) · 187 unmodified lines | |||
| 188 | switch (dev_priv->map_mode) { | 188 | switch (dev_priv->map_mode) { |
| 189 | case vmw_dma_map_bind: | 189 | case vmw_dma_map_bind: |
| 190 | case vmw_dma_map_populate: | 190 | case vmw_dma_map_populate: |
| 191 | vsgt->sgt = &vmw_tt->sgt; | 191 | if (vmw_tt->dma_ttm.page_flags & TTM_TT_FLAG_EXTERNAL) { |
| 192 | ret = sg_alloc_table_from_pages_segment( | 192 | vsgt->sgt = vmw_tt->dma_ttm.sg; |
| 193 | &vmw_tt->sgt, vsgt->pages, vsgt->num_pages, 0, | 193 | } else { |
| 194 | (unsigned long)vsgt->num_pages << PAGE_SHIFT, | 194 | vsgt->sgt = &vmw_tt->sgt; |
| 195 | dma_get_max_seg_size(dev_priv->drm.dev), GFP_KERNEL); | 195 | ret = sg_alloc_table_from_pages_segment(&vmw_tt->sgt, |
| 196 | if (ret) | 196 | vsgt->pages, vsgt->num_pages, 0, |
| 197 | goto out_sg_alloc_fail; | 197 | (unsigned long)vsgt->num_pages << PAGE_SHIFT, |
| 198 | dma_get_max_seg_size(dev_priv->drm.dev), | ||
| 199 | GFP_KERNEL); | ||
| 200 | if (ret) | ||
| 201 | goto out_sg_alloc_fail; | ||
| 202 | } | ||
| 198 | 203 | ||
| 199 | ret = vmw_ttm_map_for_dma(vmw_tt); | 204 | ret = vmw_ttm_map_for_dma(vmw_tt); |
| 200 | if (unlikely(ret != 0)) | 205 | if (unlikely(ret != 0)) |
| @@ -209,8 +214,9 @@ static int vmw_ttm_map_dma(struct vmw_ttm_tt *vmw_tt) · 8 unmodified lines | |||
| 209 | return 0; | 214 | return 0; |
| 210 | 215 | ||
| 211 | out_map_fail: | 216 | out_map_fail: |
| 212 | sg_free_table(vmw_tt->vsgt.sgt); | 217 | drm_warn(&dev_priv->drm, "VSG table map failed!"); |
| 213 | vmw_tt->vsgt.sgt = NULL; | 218 | sg_free_table(vsgt->sgt); |
| 219 | vsgt->sgt = NULL; | ||
| 214 | out_sg_alloc_fail: | 220 | out_sg_alloc_fail: |
| 215 | return ret; | 221 | return ret; |
| 216 | } | 222 | } |
| @@ -356,15 +362,17 @@ static void vmw_ttm_destroy(struct ttm_device *bdev, struct ttm_tt *ttm) · 139 unmodified lines | |||
| 356 | static int vmw_ttm_populate(struct ttm_device *bdev, | 362 | static int vmw_ttm_populate(struct ttm_device *bdev, |
| 357 | struct ttm_tt *ttm, struct ttm_operation_ctx *ctx) | 363 | struct ttm_tt *ttm, struct ttm_operation_ctx *ctx) |
| 358 | { | 364 | { |
| 359 | int ret; | 365 | bool external = (ttm->page_flags & TTM_TT_FLAG_EXTERNAL) != 0; |
| 360 | 366 | ||
| 361 | /* TODO: maybe completely drop this ? */ | ||
| 362 | if (ttm_tt_is_populated(ttm)) | 367 | if (ttm_tt_is_populated(ttm)) |
| 363 | return 0; | 368 | return 0; |
| 364 | 369 | ||
| 365 | ret = ttm_pool_alloc(&bdev->pool, ttm, ctx); | 370 | if (external && ttm->sg) |
| 371 | return drm_prime_sg_to_dma_addr_array(ttm->sg, | ||
| 372 | ttm->dma_address, | ||
| 373 | ttm->num_pages); | ||
| 366 | 374 | ||
| 367 | return ret; | 375 | return ttm_pool_alloc(&bdev->pool, ttm, ctx); |
| 368 | } | 376 | } |
| 369 | 377 | ||
| 370 | static void vmw_ttm_unpopulate(struct ttm_device *bdev, | 378 | static void vmw_ttm_unpopulate(struct ttm_device *bdev, |
| @@ -372,6 +380,10 @@ static void vmw_ttm_unpopulate(struct ttm_device *bdev, · 1 unmodified line | |||
| 372 | { | 380 | { |
| 373 | struct vmw_ttm_tt *vmw_tt = container_of(ttm, struct vmw_ttm_tt, | 381 | struct vmw_ttm_tt *vmw_tt = container_of(ttm, struct vmw_ttm_tt, |
| 374 | dma_ttm); | 382 | dma_ttm); |
| 383 | bool external = (ttm->page_flags & TTM_TT_FLAG_EXTERNAL) != 0; | ||
| 384 | |||
| 385 | if (external) | ||
| 386 | return; | ||
| 375 | 387 | ||
| 376 | vmw_ttm_unbind(bdev, ttm); | 388 | vmw_ttm_unbind(bdev, ttm); |
| 377 | 389 | ||
| @@ -390,6 +402,7 @@ static struct ttm_tt *vmw_ttm_tt_create(struct ttm_buffer_object *bo, · 12 unmodified lines | |||
| 390 | { | 402 | { |
| 391 | struct vmw_ttm_tt *vmw_be; | 403 | struct vmw_ttm_tt *vmw_be; |
| 392 | int ret; | 404 | int ret; |
| 405 | bool external = bo->type == ttm_bo_type_sg; | ||
| 393 | 406 | ||
| 394 | vmw_be = kzalloc(sizeof(*vmw_be), GFP_KERNEL); | 407 | vmw_be = kzalloc(sizeof(*vmw_be), GFP_KERNEL); |
| 395 | if (!vmw_be) | 408 | if (!vmw_be) |
| @@ -398,7 +411,10 @@ static struct ttm_tt *vmw_ttm_tt_create(struct ttm_buffer_object *bo, · 2 unmodified lines | |||
| 398 | vmw_be->dev_priv = vmw_priv_from_ttm(bo->bdev); | 411 | vmw_be->dev_priv = vmw_priv_from_ttm(bo->bdev); |
| 399 | vmw_be->mob = NULL; | 412 | vmw_be->mob = NULL; |
| 400 | 413 | ||
| 401 | if (vmw_be->dev_priv->map_mode == vmw_dma_alloc_coherent) | 414 | if (external) |
| 415 | page_flags |= TTM_TT_FLAG_EXTERNAL | TTM_TT_FLAG_EXTERNAL_MAPPABLE; | ||
| 416 | |||
| 417 | if (vmw_be->dev_priv->map_mode == vmw_dma_alloc_coherent || external) | ||
| 402 | ret = ttm_sg_tt_init(&vmw_be->dma_ttm, bo, page_flags, | 418 | ret = ttm_sg_tt_init(&vmw_be->dma_ttm, bo, page_flags, |
| 403 | ttm_cached); | 419 | ttm_cached); |
| 404 | else | 420 | else |
| @@ -31,7 +31,7 @@ int intel_fb_bo_framebuffer_init(struct intel_framebuffer *intel_fb, · 30 unmodified lines | |||
| 31 | 31 | ||
| 32 | ret = ttm_bo_reserve(&bo->ttm, true, false, NULL); | 32 | ret = ttm_bo_reserve(&bo->ttm, true, false, NULL); |
| 33 | if (ret) | 33 | if (ret) |
| 34 | return ret; | 34 | goto err; |
| 35 | 35 | ||
| 36 | if (!(bo->flags & XE_BO_SCANOUT_BIT)) { | 36 | if (!(bo->flags & XE_BO_SCANOUT_BIT)) { |
| 37 | /* | 37 | /* |
| @@ -42,12 +42,16 @@ int intel_fb_bo_framebuffer_init(struct intel_framebuffer *intel_fb, · 4 unmodified lines | |||
| 42 | */ | 42 | */ |
| 43 | if (XE_IOCTL_DBG(i915, !list_empty(&bo->ttm.base.gpuva.list))) { | 43 | if (XE_IOCTL_DBG(i915, !list_empty(&bo->ttm.base.gpuva.list))) { |
| 44 | ttm_bo_unreserve(&bo->ttm); | 44 | ttm_bo_unreserve(&bo->ttm); |
| 45 | return -EINVAL; | 45 | ret = -EINVAL; |
| 46 | goto err; | ||
| 46 | } | 47 | } |
| 47 | bo->flags |= XE_BO_SCANOUT_BIT; | 48 | bo->flags |= XE_BO_SCANOUT_BIT; |
| 48 | } | 49 | } |
| 49 | ttm_bo_unreserve(&bo->ttm); | 50 | ttm_bo_unreserve(&bo->ttm); |
| 51 | return 0; | ||
| 50 | 52 | ||
| 53 | err: | ||
| 54 | xe_bo_put(bo); | ||
| 51 | return ret; | 55 | return ret; |
| 52 | } | 56 | } |
| 53 | 57 | ||
| @@ -1577,6 +1577,16 @@ void xe_vm_close_and_put(struct xe_vm *vm) · 1576 unmodified lines | |||
| 1577 | xe->usm.num_vm_in_fault_mode--; | 1577 | xe->usm.num_vm_in_fault_mode--; |
| 1578 | else if (!(vm->flags & XE_VM_FLAG_MIGRATION)) | 1578 | else if (!(vm->flags & XE_VM_FLAG_MIGRATION)) |
| 1579 | xe->usm.num_vm_in_non_fault_mode--; | 1579 | xe->usm.num_vm_in_non_fault_mode--; |
| 1580 | |||
| 1581 | if (vm->usm.asid) { | ||
| 1582 | void *lookup; | ||
| 1583 | |||
| 1584 | xe_assert(xe, xe->info.has_asid); | ||
| 1585 | xe_assert(xe, !(vm->flags & XE_VM_FLAG_MIGRATION)); | ||
| 1586 | |||
| 1587 | lookup = xa_erase(&xe->usm.asid_to_vm, vm->usm.asid); | ||
| 1588 | xe_assert(xe, lookup == vm); | ||
| 1589 | } | ||
| 1580 | mutex_unlock(&xe->usm.lock); | 1590 | mutex_unlock(&xe->usm.lock); |
| 1581 | 1591 | ||
| 1582 | for_each_tile(tile, xe, id) | 1592 | for_each_tile(tile, xe, id) |
| @@ -1592,24 +1602,15 @@ static void vm_destroy_work_func(struct work_struct *w) · 9 unmodified lines | |||
| 1592 | struct xe_device *xe = vm->xe; | 1602 | struct xe_device *xe = vm->xe; |
| 1593 | struct xe_tile *tile; | 1603 | struct xe_tile *tile; |
| 1594 | u8 id; | 1604 | u8 id; |
| 1595 | void *lookup; | ||
| 1596 | 1605 | ||
| 1597 | /* xe_vm_close_and_put was not called? */ | 1606 | /* xe_vm_close_and_put was not called? */ |
| 1598 | xe_assert(xe, !vm->size); | 1607 | xe_assert(xe, !vm->size); |
| 1599 | 1608 | ||
| 1600 | mutex_destroy(&vm->snap_mutex); | 1609 | mutex_destroy(&vm->snap_mutex); |
| 1601 | 1610 | ||
| 1602 | if (!(vm->flags & XE_VM_FLAG_MIGRATION)) { | 1611 | if (!(vm->flags & XE_VM_FLAG_MIGRATION)) |
| 1603 | xe_device_mem_access_put(xe); | 1612 | xe_device_mem_access_put(xe); |
| 1604 | 1613 | ||
| 1605 | if (xe->info.has_asid && vm->usm.asid) { | ||
| 1606 | mutex_lock(&xe->usm.lock); | ||
| 1607 | lookup = xa_erase(&xe->usm.asid_to_vm, vm->usm.asid); | ||
| 1608 | xe_assert(xe, lookup == vm); | ||
| 1609 | mutex_unlock(&xe->usm.lock); | ||
| 1610 | } | ||
| 1611 | } | ||
| 1612 | |||
| 1613 | for_each_tile(tile, xe, id) | 1614 | for_each_tile(tile, xe, id) |
| 1614 | XE_WARN_ON(vm->pt_root[id]); | 1615 | XE_WARN_ON(vm->pt_root[id]); |
| 1615 | 1616 | ||