From: "Christian König" <ckoenig.leichtzumerken-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org
Subject: [PATCH 2/8] drm/amdgpu: use leaf iterator for allocating PD/PT
Date: Wed, 12 Sep 2018 10:54:39 +0200 [thread overview]
Message-ID: <20180912085445.3245-2-christian.koenig@amd.com> (raw)
In-Reply-To: <20180912085445.3245-1-christian.koenig-5C7GfCeVMHo@public.gmane.org>
Less code and allows for easier error handling.
Signed-off-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Felix Kuehling <Felix.Kuehling@amd.com>
Reviewed-by: Junwei Zhang <Jerry.Zhang@amd.com>
---
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 156 ++++++++++++---------------------
1 file changed, 55 insertions(+), 101 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index 787a200cf796..2cc34d1b87e0 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
@@ -844,103 +844,6 @@ static void amdgpu_vm_bo_param(struct amdgpu_device *adev, struct amdgpu_vm *vm,
bp->resv = vm->root.base.bo->tbo.resv;
}
-/**
- * amdgpu_vm_alloc_levels - allocate the PD/PT levels
- *
- * @adev: amdgpu_device pointer
- * @vm: requested vm
- * @parent: parent PT
- * @saddr: start of the address range
- * @eaddr: end of the address range
- * @level: VMPT level
- * @ats: indicate ATS support from PTE
- *
- * Make sure the page directories and page tables are allocated
- *
- * Returns:
- * 0 on success, errno otherwise.
- */
-static int amdgpu_vm_alloc_levels(struct amdgpu_device *adev,
- struct amdgpu_vm *vm,
- struct amdgpu_vm_pt *parent,
- uint64_t saddr, uint64_t eaddr,
- unsigned level, bool ats)
-{
- unsigned shift = amdgpu_vm_level_shift(adev, level);
- struct amdgpu_bo_param bp;
- unsigned pt_idx, from, to;
- int r;
-
- if (!parent->entries) {
- unsigned num_entries = amdgpu_vm_num_entries(adev, level);
-
- parent->entries = kvmalloc_array(num_entries,
- sizeof(struct amdgpu_vm_pt),
- GFP_KERNEL | __GFP_ZERO);
- if (!parent->entries)
- return -ENOMEM;
- }
-
- from = saddr >> shift;
- to = eaddr >> shift;
- if (from >= amdgpu_vm_num_entries(adev, level) ||
- to >= amdgpu_vm_num_entries(adev, level))
- return -EINVAL;
-
- ++level;
- saddr = saddr & ((1 << shift) - 1);
- eaddr = eaddr & ((1 << shift) - 1);
-
- amdgpu_vm_bo_param(adev, vm, level, &bp);
-
- /* walk over the address space and allocate the page tables */
- for (pt_idx = from; pt_idx <= to; ++pt_idx) {
- struct amdgpu_vm_pt *entry = &parent->entries[pt_idx];
- struct amdgpu_bo *pt;
-
- if (!entry->base.bo) {
- r = amdgpu_bo_create(adev, &bp, &pt);
- if (r)
- return r;
-
- r = amdgpu_vm_clear_bo(adev, vm, pt, level, ats);
- if (r) {
- amdgpu_bo_unref(&pt->shadow);
- amdgpu_bo_unref(&pt);
- return r;
- }
-
- if (vm->use_cpu_for_update) {
- r = amdgpu_bo_kmap(pt, NULL);
- if (r) {
- amdgpu_bo_unref(&pt->shadow);
- amdgpu_bo_unref(&pt);
- return r;
- }
- }
-
- /* Keep a reference to the root directory to avoid
- * freeing them up in the wrong order.
- */
- pt->parent = amdgpu_bo_ref(parent->base.bo);
-
- amdgpu_vm_bo_base_init(&entry->base, vm, pt);
- }
-
- if (level < AMDGPU_VM_PTB) {
- uint64_t sub_saddr = (pt_idx == from) ? saddr : 0;
- uint64_t sub_eaddr = (pt_idx == to) ? eaddr :
- ((1 << shift) - 1);
- r = amdgpu_vm_alloc_levels(adev, vm, entry, sub_saddr,
- sub_eaddr, level, ats);
- if (r)
- return r;
- }
- }
-
- return 0;
-}
-
/**
* amdgpu_vm_alloc_pts - Allocate page tables.
*
@@ -949,7 +852,7 @@ static int amdgpu_vm_alloc_levels(struct amdgpu_device *adev,
* @saddr: Start address which needs to be allocated
* @size: Size from start address we need.
*
- * Make sure the page tables are allocated.
+ * Make sure the page directories and page tables are allocated
*
* Returns:
* 0 on success, errno otherwise.
@@ -958,8 +861,11 @@ int amdgpu_vm_alloc_pts(struct amdgpu_device *adev,
struct amdgpu_vm *vm,
uint64_t saddr, uint64_t size)
{
- uint64_t eaddr;
+ struct amdgpu_vm_pt_cursor cursor;
+ struct amdgpu_bo *pt;
bool ats = false;
+ uint64_t eaddr;
+ int r;
/* validate the parameters */
if (saddr & AMDGPU_GPU_PAGE_MASK || size & AMDGPU_GPU_PAGE_MASK)
@@ -979,8 +885,56 @@ int amdgpu_vm_alloc_pts(struct amdgpu_device *adev,
return -EINVAL;
}
- return amdgpu_vm_alloc_levels(adev, vm, &vm->root, saddr, eaddr,
- adev->vm_manager.root_level, ats);
+ for_each_amdgpu_vm_pt_leaf(adev, vm, saddr, eaddr, cursor) {
+ struct amdgpu_vm_pt *entry = cursor.entry;
+ struct amdgpu_bo_param bp;
+
+ if (cursor.level < AMDGPU_VM_PTB) {
+ unsigned num_entries;
+
+ num_entries = amdgpu_vm_num_entries(adev, cursor.level);
+ entry->entries = kvmalloc_array(num_entries,
+ sizeof(*entry->entries),
+ GFP_KERNEL |
+ __GFP_ZERO);
+ if (!entry->entries)
+ return -ENOMEM;
+ }
+
+
+ if (entry->base.bo)
+ continue;
+
+ amdgpu_vm_bo_param(adev, vm, cursor.level, &bp);
+
+ r = amdgpu_bo_create(adev, &bp, &pt);
+ if (r)
+ return r;
+
+ r = amdgpu_vm_clear_bo(adev, vm, pt, cursor.level, ats);
+ if (r)
+ goto error_free_pt;
+
+ if (vm->use_cpu_for_update) {
+ r = amdgpu_bo_kmap(pt, NULL);
+ if (r)
+ goto error_free_pt;
+ }
+
+ /* Keep a reference to the root directory to avoid
+ * freeing them up in the wrong order.
+ */
+ pt->parent = amdgpu_bo_ref(cursor.parent->base.bo);
+
+ amdgpu_vm_bo_base_init(&entry->base, vm, pt);
+ }
+
+ return 0;
+
+error_free_pt:
+ amdgpu_bo_unref(&pt->shadow);
+ amdgpu_bo_unref(&pt);
+ return r;
}
/**
--
2.14.1
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
next prev parent reply other threads:[~2018-09-12 8:54 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-09-12 8:54 [PATCH 1/8] drm/amdgpu: add some VM PD/PT iterators v2 Christian König
[not found] ` <20180912085445.3245-1-christian.koenig-5C7GfCeVMHo@public.gmane.org>
2018-09-12 8:54 ` Christian König [this message]
2018-09-12 8:54 ` [PATCH 3/8] drm/amdgpu: use dfs iterator to free PDs/PTs Christian König
2018-09-12 8:54 ` [PATCH 4/8] drm/amdgpu: use the DFS iterator in amdgpu_vm_invalidate_pds v2 Christian König
[not found] ` <20180912085445.3245-4-christian.koenig-5C7GfCeVMHo@public.gmane.org>
2018-09-13 2:52 ` Zhang, Jerry(Junwei)
2018-09-12 8:54 ` [PATCH 5/8] drm/amdgpu: use leaf iterator for filling PTs Christian König
2018-09-12 8:54 ` [PATCH 6/8] drm/amdgpu: meld together VM fragment and huge page handling Christian König
[not found] ` <20180912085445.3245-6-christian.koenig-5C7GfCeVMHo@public.gmane.org>
2018-11-08 16:17 ` Samuel Pitoiset
[not found] ` <cd923303-6208-3593-74fe-0d9e7b83c12c-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2018-11-08 16:50 ` Christian König
[not found] ` <f2d67c06-063f-6441-0699-1ab283a99f6c-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2018-11-08 19:35 ` Samuel Pitoiset
[not found] ` <363ce01b-c6f1-21bc-329e-bbb4ec568ba8-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2018-11-09 12:13 ` Koenig, Christian
[not found] ` <c4ffbce4-5225-dfc1-8056-2575b6bbdd9c-5C7GfCeVMHo@public.gmane.org>
2018-11-12 15:16 ` Christian König
2018-09-12 8:54 ` [PATCH 7/8] drm/amdgpu: use the maximum possible fragment size on Vega/Raven Christian König
2018-09-12 8:54 ` [PATCH 8/8] drm/amdgpu: allow fragment processing for invalid PTEs Christian König
2018-09-12 23:12 ` [PATCH 1/8] drm/amdgpu: add some VM PD/PT iterators v2 Felix Kuehling
2018-09-13 2:51 ` Zhang, Jerry(Junwei)
2018-09-13 6:58 ` Huang Rui
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180912085445.3245-2-christian.koenig@amd.com \
--to=ckoenig.leichtzumerken-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
--cc=amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox