diff options
author | Christian König <christian.koenig@amd.com> | 2018-01-16 10:54:25 -0500 |
---|---|---|
committer | Alex Deucher <alexander.deucher@amd.com> | 2018-02-19 14:17:45 -0500 |
commit | 373ac645c9b83ffd93f9905458166b25191a8df6 (patch) | |
tree | fcfec6301257b0d62f52b1dfec9460fbd44feb88 | |
parent | 132f34e4b558488cc8d153a1d18833054a76e44c (diff) |
drm/amdgpu: move PD/PT address calculation into backend function
This way we can better handle the differences for CPU based updates.
Signed-off-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Felix Kuehling <Felix.Kuehling@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
-rw-r--r-- | drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 79 |
1 files changed, 29 insertions, 50 deletions
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c index da634ae6ca8f..21b3915bfec1 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | |||
@@ -75,7 +75,8 @@ struct amdgpu_pte_update_params { | |||
75 | /* indirect buffer to fill with commands */ | 75 | /* indirect buffer to fill with commands */ |
76 | struct amdgpu_ib *ib; | 76 | struct amdgpu_ib *ib; |
77 | /* Function which actually does the update */ | 77 | /* Function which actually does the update */ |
78 | void (*func)(struct amdgpu_pte_update_params *params, uint64_t pe, | 78 | void (*func)(struct amdgpu_pte_update_params *params, |
79 | struct amdgpu_bo *bo, uint64_t pe, | ||
79 | uint64_t addr, unsigned count, uint32_t incr, | 80 | uint64_t addr, unsigned count, uint32_t incr, |
80 | uint64_t flags); | 81 | uint64_t flags); |
81 | /* The next two are used during VM update by CPU | 82 | /* The next two are used during VM update by CPU |
@@ -578,6 +579,7 @@ struct amdgpu_bo_va *amdgpu_vm_bo_find(struct amdgpu_vm *vm, | |||
578 | * amdgpu_vm_do_set_ptes - helper to call the right asic function | 579 | * amdgpu_vm_do_set_ptes - helper to call the right asic function |
579 | * | 580 | * |
580 | * @params: see amdgpu_pte_update_params definition | 581 | * @params: see amdgpu_pte_update_params definition |
582 | * @bo: PD/PT to update | ||
581 | * @pe: addr of the page entry | 583 | * @pe: addr of the page entry |
582 | * @addr: dst addr to write into pe | 584 | * @addr: dst addr to write into pe |
583 | * @count: number of page entries to update | 585 | * @count: number of page entries to update |
@@ -588,10 +590,12 @@ struct amdgpu_bo_va *amdgpu_vm_bo_find(struct amdgpu_vm *vm, | |||
588 | * to setup the page table using the DMA. | 590 | * to setup the page table using the DMA. |
589 | */ | 591 | */ |
590 | static void amdgpu_vm_do_set_ptes(struct amdgpu_pte_update_params *params, | 592 | static void amdgpu_vm_do_set_ptes(struct amdgpu_pte_update_params *params, |
593 | struct amdgpu_bo *bo, | ||
591 | uint64_t pe, uint64_t addr, | 594 | uint64_t pe, uint64_t addr, |
592 | unsigned count, uint32_t incr, | 595 | unsigned count, uint32_t incr, |
593 | uint64_t flags) | 596 | uint64_t flags) |
594 | { | 597 | { |
598 | pe += amdgpu_bo_gpu_offset(bo); | ||
595 | trace_amdgpu_vm_set_ptes(pe, addr, count, incr, flags); | 599 | trace_amdgpu_vm_set_ptes(pe, addr, count, incr, flags); |
596 | 600 | ||
597 | if (count < 3) { | 601 | if (count < 3) { |
@@ -608,6 +612,7 @@ static void amdgpu_vm_do_set_ptes(struct amdgpu_pte_update_params *params, | |||
608 | * amdgpu_vm_do_copy_ptes - copy the PTEs from the GART | 612 | * amdgpu_vm_do_copy_ptes - copy the PTEs from the GART |
609 | * | 613 | * |
610 | * @params: see amdgpu_pte_update_params definition | 614 | * @params: see amdgpu_pte_update_params definition |
615 | * @bo: PD/PT to update | ||
611 | * @pe: addr of the page entry | 616 | * @pe: addr of the page entry |
612 | * @addr: dst addr to write into pe | 617 | * @addr: dst addr to write into pe |
613 | * @count: number of page entries to update | 618 | * @count: number of page entries to update |
@@ -617,13 +622,14 @@ static void amdgpu_vm_do_set_ptes(struct amdgpu_pte_update_params *params, | |||
617 | * Traces the parameters and calls the DMA function to copy the PTEs. | 622 | * Traces the parameters and calls the DMA function to copy the PTEs. |
618 | */ | 623 | */ |
619 | static void amdgpu_vm_do_copy_ptes(struct amdgpu_pte_update_params *params, | 624 | static void amdgpu_vm_do_copy_ptes(struct amdgpu_pte_update_params *params, |
625 | struct amdgpu_bo *bo, | ||
620 | uint64_t pe, uint64_t addr, | 626 | uint64_t pe, uint64_t addr, |
621 | unsigned count, uint32_t incr, | 627 | unsigned count, uint32_t incr, |
622 | uint64_t flags) | 628 | uint64_t flags) |
623 | { | 629 | { |
624 | uint64_t src = (params->src + (addr >> 12) * 8); | 630 | uint64_t src = (params->src + (addr >> 12) * 8); |
625 | 631 | ||
626 | 632 | pe += amdgpu_bo_gpu_offset(bo); | |
627 | trace_amdgpu_vm_copy_ptes(pe, src, count); | 633 | trace_amdgpu_vm_copy_ptes(pe, src, count); |
628 | 634 | ||
629 | amdgpu_vm_copy_pte(params->adev, params->ib, pe, src, count); | 635 | amdgpu_vm_copy_pte(params->adev, params->ib, pe, src, count); |
@@ -657,6 +663,7 @@ static uint64_t amdgpu_vm_map_gart(const dma_addr_t *pages_addr, uint64_t addr) | |||
657 | * amdgpu_vm_cpu_set_ptes - helper to update page tables via CPU | 663 | * amdgpu_vm_cpu_set_ptes - helper to update page tables via CPU |
658 | * | 664 | * |
659 | * @params: see amdgpu_pte_update_params definition | 665 | * @params: see amdgpu_pte_update_params definition |
666 | * @bo: PD/PT to update | ||
660 | * @pe: kmap addr of the page entry | 667 | * @pe: kmap addr of the page entry |
661 | * @addr: dst addr to write into pe | 668 | * @addr: dst addr to write into pe |
662 | * @count: number of page entries to update | 669 | * @count: number of page entries to update |
@@ -666,6 +673,7 @@ static uint64_t amdgpu_vm_map_gart(const dma_addr_t *pages_addr, uint64_t addr) | |||
666 | * Write count number of PT/PD entries directly. | 673 | * Write count number of PT/PD entries directly. |
667 | */ | 674 | */ |
668 | static void amdgpu_vm_cpu_set_ptes(struct amdgpu_pte_update_params *params, | 675 | static void amdgpu_vm_cpu_set_ptes(struct amdgpu_pte_update_params *params, |
676 | struct amdgpu_bo *bo, | ||
669 | uint64_t pe, uint64_t addr, | 677 | uint64_t pe, uint64_t addr, |
670 | unsigned count, uint32_t incr, | 678 | unsigned count, uint32_t incr, |
671 | uint64_t flags) | 679 | uint64_t flags) |
@@ -673,6 +681,8 @@ static void amdgpu_vm_cpu_set_ptes(struct amdgpu_pte_update_params *params, | |||
673 | unsigned int i; | 681 | unsigned int i; |
674 | uint64_t value; | 682 | uint64_t value; |
675 | 683 | ||
684 | pe += (unsigned long)amdgpu_bo_kptr(bo); | ||
685 | |||
676 | trace_amdgpu_vm_set_ptes(pe, addr, count, incr, flags); | 686 | trace_amdgpu_vm_set_ptes(pe, addr, count, incr, flags); |
677 | 687 | ||
678 | for (i = 0; i < count; i++) { | 688 | for (i = 0; i < count; i++) { |
@@ -714,8 +724,7 @@ static void amdgpu_vm_update_pde(struct amdgpu_pte_update_params *params, | |||
714 | struct amdgpu_vm_pt *parent, | 724 | struct amdgpu_vm_pt *parent, |
715 | struct amdgpu_vm_pt *entry) | 725 | struct amdgpu_vm_pt *entry) |
716 | { | 726 | { |
717 | struct amdgpu_bo *bo = entry->base.bo, *shadow = NULL, *pbo; | 727 | struct amdgpu_bo *bo = parent->base.bo, *pbo; |
718 | uint64_t pd_addr, shadow_addr = 0; | ||
719 | uint64_t pde, pt, flags; | 728 | uint64_t pde, pt, flags; |
720 | unsigned level; | 729 | unsigned level; |
721 | 730 | ||
@@ -723,29 +732,17 @@ static void amdgpu_vm_update_pde(struct amdgpu_pte_update_params *params, | |||
723 | if (entry->huge) | 732 | if (entry->huge) |
724 | return; | 733 | return; |
725 | 734 | ||
726 | if (vm->use_cpu_for_update) { | 735 | for (level = 0, pbo = bo->parent; pbo; ++level) |
727 | pd_addr = (unsigned long)amdgpu_bo_kptr(parent->base.bo); | ||
728 | } else { | ||
729 | pd_addr = amdgpu_bo_gpu_offset(parent->base.bo); | ||
730 | shadow = parent->base.bo->shadow; | ||
731 | if (shadow) | ||
732 | shadow_addr = amdgpu_bo_gpu_offset(shadow); | ||
733 | } | ||
734 | |||
735 | for (level = 0, pbo = parent->base.bo->parent; pbo; ++level) | ||
736 | pbo = pbo->parent; | 736 | pbo = pbo->parent; |
737 | 737 | ||
738 | level += params->adev->vm_manager.root_level; | 738 | level += params->adev->vm_manager.root_level; |
739 | pt = amdgpu_bo_gpu_offset(bo); | 739 | pt = amdgpu_bo_gpu_offset(entry->base.bo); |
740 | flags = AMDGPU_PTE_VALID; | 740 | flags = AMDGPU_PTE_VALID; |
741 | amdgpu_gmc_get_vm_pde(params->adev, level, &pt, &flags); | 741 | amdgpu_gmc_get_vm_pde(params->adev, level, &pt, &flags); |
742 | if (shadow) { | 742 | pde = (entry - parent->entries) * 8; |
743 | pde = shadow_addr + (entry - parent->entries) * 8; | 743 | if (bo->shadow) |
744 | params->func(params, pde, pt, 1, 0, flags); | 744 | params->func(params, bo->shadow, pde, pt, 1, 0, flags); |
745 | } | 745 | params->func(params, bo, pde, pt, 1, 0, flags); |
746 | |||
747 | pde = pd_addr + (entry - parent->entries) * 8; | ||
748 | params->func(params, pde, pt, 1, 0, flags); | ||
749 | } | 746 | } |
750 | 747 | ||
751 | /* | 748 | /* |
@@ -946,7 +943,7 @@ static void amdgpu_vm_handle_huge_pages(struct amdgpu_pte_update_params *p, | |||
946 | unsigned nptes, uint64_t dst, | 943 | unsigned nptes, uint64_t dst, |
947 | uint64_t flags) | 944 | uint64_t flags) |
948 | { | 945 | { |
949 | uint64_t pd_addr, pde; | 946 | uint64_t pde; |
950 | 947 | ||
951 | /* In the case of a mixed PT the PDE must point to it*/ | 948 | /* In the case of a mixed PT the PDE must point to it*/ |
952 | if (p->adev->asic_type >= CHIP_VEGA10 && !p->src && | 949 | if (p->adev->asic_type >= CHIP_VEGA10 && !p->src && |
@@ -969,18 +966,10 @@ static void amdgpu_vm_handle_huge_pages(struct amdgpu_pte_update_params *p, | |||
969 | entry->huge = true; | 966 | entry->huge = true; |
970 | amdgpu_gmc_get_vm_pde(p->adev, AMDGPU_VM_PDB0, &dst, &flags); | 967 | amdgpu_gmc_get_vm_pde(p->adev, AMDGPU_VM_PDB0, &dst, &flags); |
971 | 968 | ||
972 | if (p->func == amdgpu_vm_cpu_set_ptes) { | 969 | pde = (entry - parent->entries) * 8; |
973 | pd_addr = (unsigned long)amdgpu_bo_kptr(parent->base.bo); | 970 | if (parent->base.bo->shadow) |
974 | } else { | 971 | p->func(p, parent->base.bo->shadow, pde, dst, 1, 0, flags); |
975 | if (parent->base.bo->shadow) { | 972 | p->func(p, parent->base.bo, pde, dst, 1, 0, flags); |
976 | pd_addr = amdgpu_bo_gpu_offset(parent->base.bo->shadow); | ||
977 | pde = pd_addr + (entry - parent->entries) * 8; | ||
978 | p->func(p, pde, dst, 1, 0, flags); | ||
979 | } | ||
980 | pd_addr = amdgpu_bo_gpu_offset(parent->base.bo); | ||
981 | } | ||
982 | pde = pd_addr + (entry - parent->entries) * 8; | ||
983 | p->func(p, pde, dst, 1, 0, flags); | ||
984 | } | 973 | } |
985 | 974 | ||
986 | /** | 975 | /** |
@@ -1006,7 +995,6 @@ static int amdgpu_vm_update_ptes(struct amdgpu_pte_update_params *params, | |||
1006 | uint64_t addr, pe_start; | 995 | uint64_t addr, pe_start; |
1007 | struct amdgpu_bo *pt; | 996 | struct amdgpu_bo *pt; |
1008 | unsigned nptes; | 997 | unsigned nptes; |
1009 | bool use_cpu_update = (params->func == amdgpu_vm_cpu_set_ptes); | ||
1010 | 998 | ||
1011 | /* walk over the address space and update the page tables */ | 999 | /* walk over the address space and update the page tables */ |
1012 | for (addr = start; addr < end; addr += nptes, | 1000 | for (addr = start; addr < end; addr += nptes, |
@@ -1029,20 +1017,11 @@ static int amdgpu_vm_update_ptes(struct amdgpu_pte_update_params *params, | |||
1029 | continue; | 1017 | continue; |
1030 | 1018 | ||
1031 | pt = entry->base.bo; | 1019 | pt = entry->base.bo; |
1032 | if (use_cpu_update) { | 1020 | pe_start = (addr & mask) * 8; |
1033 | pe_start = (unsigned long)amdgpu_bo_kptr(pt); | 1021 | if (pt->shadow) |
1034 | } else { | 1022 | params->func(params, pt->shadow, pe_start, dst, nptes, |
1035 | if (pt->shadow) { | 1023 | AMDGPU_GPU_PAGE_SIZE, flags); |
1036 | pe_start = amdgpu_bo_gpu_offset(pt->shadow); | 1024 | params->func(params, pt, pe_start, dst, nptes, |
1037 | pe_start += (addr & mask) * 8; | ||
1038 | params->func(params, pe_start, dst, nptes, | ||
1039 | AMDGPU_GPU_PAGE_SIZE, flags); | ||
1040 | } | ||
1041 | pe_start = amdgpu_bo_gpu_offset(pt); | ||
1042 | } | ||
1043 | |||
1044 | pe_start += (addr & mask) * 8; | ||
1045 | params->func(params, pe_start, dst, nptes, | ||
1046 | AMDGPU_GPU_PAGE_SIZE, flags); | 1025 | AMDGPU_GPU_PAGE_SIZE, flags); |
1047 | } | 1026 | } |
1048 | 1027 | ||