aboutsummaryrefslogtreecommitdiffstats
path: root/common/recipes-kernel/linux/linux-yocto-4.14.71/1735-drm-amdkfd-Support-registering-third-pary-device-mem.patch
blob: 1a15ca95860567a60053e1b070787a2e24f32cfb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
From 92c1fc52472f971df7011381e6dbcf5c6e2bdff1 Mon Sep 17 00:00:00 2001
From: Harish Kasiviswanathan <Harish.Kasiviswanathan@amd.com>
Date: Thu, 13 Jul 2017 12:00:20 -0400
Subject: [PATCH 1735/4131] drm/amdkfd: Support registering third pary device
 memory

Register userptr that corresponds to third party device memory for GPU
access. Instead of userptr BO a doorbell BO will be created using the
physical address of the third party device memory. User space will treat
the doorbell BO as a regular userptr BO

BUG: KFD-351
Change-Id: I7ff5ded4ab0a90e01f984c1e0dc8067f09a35baa
Signed-off-by: Harish Kasiviswanathan <Harish.Kasiviswanathan@amd.com>
---
 drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 26 +++++++++++++++++++++-----
 1 file changed, 21 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
index 814ad7f..c254b52 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
@@ -1194,7 +1194,9 @@ static int kfd_ioctl_alloc_memory_of_gpu(struct file *filep,
 	struct kfd_dev *dev;
 	int idr_handle;
 	long err;
-	uint64_t offset;
+	uint64_t offset = args->mmap_offset;
+	uint32_t flags = args->flags;
+	struct vm_area_struct *vma;
 
 	if (args->size == 0)
 		return -EINVAL;
@@ -1209,17 +1211,31 @@ static int kfd_ioctl_alloc_memory_of_gpu(struct file *filep,
 	if (IS_ERR(pdd))
 		return PTR_ERR(pdd);
 
-	if (args->flags & KFD_IOC_ALLOC_MEM_FLAGS_DOORBELL) {
+	if (flags & KFD_IOC_ALLOC_MEM_FLAGS_USERPTR) {
+		/* Check if the userptr corresponds to another (or third-party)
+		 * device local memory. If so treat is as a doorbell. User
+		 * space will be oblivious of this and will use this doorbell
+		 * BO as a regular userptr BO
+		 */
+		vma = find_vma(current->mm, args->mmap_offset);
+		if (vma && (vma->vm_flags & VM_IO)) {
+			unsigned long pfn;
+
+			follow_pfn(vma, args->mmap_offset, &pfn);
+			flags |= KFD_IOC_ALLOC_MEM_FLAGS_DOORBELL;
+			flags &= ~KFD_IOC_ALLOC_MEM_FLAGS_USERPTR;
+			offset = (pfn << PAGE_SHIFT);
+		}
+	} else if (flags & KFD_IOC_ALLOC_MEM_FLAGS_DOORBELL) {
 		if (args->size != kfd_doorbell_process_slice(dev))
 			return -EINVAL;
 		offset = kfd_get_process_doorbells(dev, p);
-	} else
-		offset = args->mmap_offset;
+	}
 
 	err = dev->kfd2kgd->alloc_memory_of_gpu(
 		dev->kgd, args->va_addr, args->size,
 		pdd->vm, (struct kgd_mem **) &mem, &offset,
-		NULL, args->flags);
+		NULL, flags);
 
 	if (err != 0)
 		return err;
-- 
2.7.4