aboutsummaryrefslogtreecommitdiffstats
path: root/meta-amd-bsp/recipes-kernel/linux/linux-yocto-4.14.71/1739-drm-amdgpu-Rework-ptrace-access-function.patch
blob: e83f6afe6396cedae3fa8458b638bb2d53a4b998 (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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
From af6b95fe5067eb4bdb97f02f74e21b9645b5a0c0 Mon Sep 17 00:00:00 2001
From: Felix Kuehling <Felix.Kuehling@amd.com>
Date: Wed, 12 Jul 2017 17:08:28 -0400
Subject: [PATCH 1739/4131] drm/amdgpu: Rework ptrace access function

This is based on code review feedback from the amd-gfx:

* Move common code and system memory handling into TTM
* Handle VRAM and optionally private pools in driver callback
* Kmap only system memory pages that are accessed, one page at a time
* Swap in system memory BOs if needed
* Add range check

Change-Id: Id01a6675b2af9bd3400416c18b66c1baefc1c4f1
Signed-off-by: Felix Kuehling <Felix.Kuehling@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 109 +-------------------------------
 1 file changed, 1 insertion(+), 108 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
index 7bc3ed8..0ef0472 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
@@ -1637,113 +1637,7 @@ void amdgpu_ttm_set_active_vram_size(struct amdgpu_device *adev, u64 size)
 }
 
 static struct vm_operations_struct amdgpu_ttm_vm_ops;
-static const struct vm_operations_struct *ttm_vm_ops /* = NULL;
-                                                      * (appease checkpatch) */;
-static int amdgpu_ttm_bo_access_vram(struct amdgpu_bo *abo,
-                                     unsigned long offset,
-                                     void *buf, int len, int write)
-{
-	struct amdgpu_device *adev = amdgpu_ttm_adev(abo->tbo.bdev);
-	struct drm_mm_node *nodes = abo->tbo.mem.mm_node;
-        uint32_t value = 0;
-        int result = 0;
-	uint64_t pos;
-	unsigned long flags;
-
-	while (offset >= (nodes->size << PAGE_SHIFT)) {
-		offset -= nodes->size << PAGE_SHIFT;
-		++nodes;
-	}
-	pos = (nodes->start << PAGE_SHIFT) + offset;
-
-        while (len && pos < adev->mc.mc_vram_size) {
-                uint64_t aligned_pos = pos & ~(uint64_t)3;
-                uint32_t bytes = 4 - (pos & 3);
-                uint32_t shift = (pos & 3) * 8;
-                uint32_t mask = 0xffffffff << shift;
-
-                if (len < bytes) {
-                        mask &= 0xffffffff >> (bytes - len) * 8;
-                        bytes = len;
-                }
-
-                spin_lock_irqsave(&adev->mmio_idx_lock, flags);
-                WREG32(mmMM_INDEX, ((uint32_t)aligned_pos) | 0x80000000);
-                WREG32(mmMM_INDEX_HI, aligned_pos >> 31);
-                if (!write || mask != 0xffffffff)
-                        value = RREG32(mmMM_DATA);
-                if (write) {
-                        value &= ~mask;
-                        value |= (*(uint32_t *)buf << shift) & mask;
-                        WREG32(mmMM_DATA, value);
-                }
-                spin_unlock_irqrestore(&adev->mmio_idx_lock, flags);
-                if (!write) {
-                        value = (value & mask) >> shift;
-                        memcpy(buf, &value, bytes);
-                }
-
-                result += bytes;
-                buf = (uint8_t *)buf + bytes;
-                pos += bytes;
-                len -= bytes;
-		if (pos >= (nodes->start + nodes->size) << PAGE_SHIFT) {
-			++nodes;
-			pos = (nodes->start << PAGE_SHIFT);
-		}
-        }
-
-        return result;
-}
-
-static int amdgpu_ttm_bo_access_kmap(struct amdgpu_bo *abo,
-                                     unsigned long offset,
-                                     void *buf, int len, int write)
-{
-        struct ttm_buffer_object *bo = &abo->tbo;
-        struct ttm_bo_kmap_obj map;
-        void *ptr;
-        bool is_iomem;
-        int r;
-
-        r = ttm_bo_kmap(bo, 0, bo->num_pages, &map);
-        if (r)
-                return r;
-        ptr = (uint8_t *)ttm_kmap_obj_virtual(&map, &is_iomem) + offset;
-        WARN_ON(is_iomem);
-        if (write)
-                memcpy(ptr, buf, len);
-        else
-                memcpy(buf, ptr, len);
-        ttm_bo_kunmap(&map);
-
-        return len;
-}
-
-static int amdgpu_ttm_vm_access(struct vm_area_struct *vma, unsigned long addr,
-                                void *buf, int len, int write)
-{
-        unsigned long offset = (addr) - vma->vm_start;
-        struct ttm_buffer_object *bo = vma->vm_private_data;
-        struct amdgpu_bo *abo = container_of(bo, struct amdgpu_bo, tbo);
-        unsigned domain;
-        int result;
-
-        result = amdgpu_bo_reserve(abo, false);
-        if (result != 0)
-                return result;
-
-        domain = amdgpu_mem_type_to_domain(bo->mem.mem_type);
-        if (domain == AMDGPU_GEM_DOMAIN_VRAM)
-                result = amdgpu_ttm_bo_access_vram(abo, offset,
-                                                   buf, len, write);
-        else
-                result = amdgpu_ttm_bo_access_kmap(abo, offset,
-                                                   buf, len, write);
-        amdgpu_bo_unreserve(abo);
-
-        return len;
-}
+static const struct vm_operations_struct *ttm_vm_ops;
 
 /* This function is a tweak variance of ttm_bo_vm_open() just to avoid the
  * warning message when fork() with KFD BOs on DGPU.
@@ -1776,7 +1670,6 @@ int amdgpu_bo_mmap(struct file *filp, struct vm_area_struct *vma,
 	if (unlikely(ttm_vm_ops == NULL)) {
 		ttm_vm_ops = vma->vm_ops;
 		amdgpu_ttm_vm_ops = *ttm_vm_ops;
-		amdgpu_ttm_vm_ops.access = &amdgpu_ttm_vm_access;
 		amdgpu_ttm_vm_ops.open = &amdgpu_ttm_vm_open;
 	}
 	vma->vm_ops = &amdgpu_ttm_vm_ops;
-- 
2.7.4