History

drm/amdgpu: drop amdgpu_gtt_node

We have the BO pointer in the base structure now as well.

Christian König committed 5 years ago

Commit 77ef2711 parent fee2ede2 files · +26 −31Browse files

Unified · Split

2 files
  1. drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c +18 −31
  2. include/drm/ttm/ttm_resource.h +8 −0
drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c+18−31
@@ -26,23 +26,12 @@ · 25 unmodified lines
26 26
27#include "amdgpu.h"27#include "amdgpu.h"
28 28
29struct amdgpu_gtt_node {
30 struct ttm_buffer_object *tbo;
31 struct ttm_range_mgr_node base;
32};
33
34static inline struct amdgpu_gtt_mgr *29static inline struct amdgpu_gtt_mgr *
35to_gtt_mgr(struct ttm_resource_manager *man)30to_gtt_mgr(struct ttm_resource_manager *man)
36{31{
37 return container_of(man, struct amdgpu_gtt_mgr, manager);32 return container_of(man, struct amdgpu_gtt_mgr, manager);
38}33}
39 34
40static inline struct amdgpu_gtt_node *
41to_amdgpu_gtt_node(struct ttm_resource *res)
42{
43 return container_of(res, struct amdgpu_gtt_node, base.base);
44}
45
46/**35/**
47 * DOC: mem_info_gtt_total36 * DOC: mem_info_gtt_total
48 *37 *
@@ -106,9 +95,9 @@ const struct attribute_group amdgpu_gtt_mgr_attr_group = { · 57 unmodified lines
106 */95 */
107bool amdgpu_gtt_mgr_has_gart_addr(struct ttm_resource *res)96bool amdgpu_gtt_mgr_has_gart_addr(struct ttm_resource *res)
108{97{
109 struct amdgpu_gtt_node *node = to_amdgpu_gtt_node(res);98 struct ttm_range_mgr_node *node = to_ttm_range_mgr_node(res);
110 99
111 return drm_mm_node_allocated(&node->base.mm_nodes[0]);100 return drm_mm_node_allocated(&node->mm_nodes[0]);
112}101}
113 102
114/**103/**
@@ -128,15 +117,14 @@ static int amdgpu_gtt_mgr_new(struct ttm_resource_manager *man, · 13 unmodified lines
128{117{
129 struct amdgpu_gtt_mgr *mgr = to_gtt_mgr(man);118 struct amdgpu_gtt_mgr *mgr = to_gtt_mgr(man);
130 uint32_t num_pages = PFN_UP(tbo->base.size);119 uint32_t num_pages = PFN_UP(tbo->base.size);
131 struct amdgpu_gtt_node *node;120 struct ttm_range_mgr_node *node;
132 int r;121 int r;
133 122
134 node = kzalloc(struct_size(node, base.mm_nodes, 1), GFP_KERNEL);123 node = kzalloc(struct_size(node, mm_nodes, 1), GFP_KERNEL);
135 if (!node)124 if (!node)
136 return -ENOMEM;125 return -ENOMEM;
137 126
138 node->tbo = tbo;127 ttm_resource_init(tbo, place, &node->base);
139 ttm_resource_init(tbo, place, &node->base.base);
140 if (!(place->flags & TTM_PL_FLAG_TEMPORARY) &&128 if (!(place->flags & TTM_PL_FLAG_TEMPORARY) &&
141 ttm_resource_manager_usage(man) > man->size) {129 ttm_resource_manager_usage(man) > man->size) {
142 r = -ENOSPC;130 r = -ENOSPC;
@@ -145,8 +133,7 @@ static int amdgpu_gtt_mgr_new(struct ttm_resource_manager *man, · 2 unmodified lines
145 133
146 if (place->lpfn) {134 if (place->lpfn) {
147 spin_lock(&mgr->lock);135 spin_lock(&mgr->lock);
148 r = drm_mm_insert_node_in_range(&mgr->mm,136 r = drm_mm_insert_node_in_range(&mgr->mm, &node->mm_nodes[0],
149 &node->base.mm_nodes[0],
150 num_pages, tbo->page_alignment,137 num_pages, tbo->page_alignment,
151 0, place->fpfn, place->lpfn,138 0, place->fpfn, place->lpfn,
152 DRM_MM_INSERT_BEST);139 DRM_MM_INSERT_BEST);
@@ -154,18 +141,18 @@ static int amdgpu_gtt_mgr_new(struct ttm_resource_manager *man, · 1 unmodified line
154 if (unlikely(r))141 if (unlikely(r))
155 goto err_free;142 goto err_free;
156 143
157 node->base.base.start = node->base.mm_nodes[0].start;144 node->base.start = node->mm_nodes[0].start;
158 } else {145 } else {
159 node->base.mm_nodes[0].start = 0;146 node->mm_nodes[0].start = 0;
160 node->base.mm_nodes[0].size = node->base.base.num_pages;147 node->mm_nodes[0].size = node->base.num_pages;
161 node->base.base.start = AMDGPU_BO_INVALID_OFFSET;148 node->base.start = AMDGPU_BO_INVALID_OFFSET;
162 }149 }
163 150
164 *res = &node->base.base;151 *res = &node->base;
165 return 0;152 return 0;
166 153
167err_free:154err_free:
168 ttm_resource_fini(man, &node->base.base);155 ttm_resource_fini(man, &node->base);
169 kfree(node);156 kfree(node);
170 return r;157 return r;
171}158}
@@ -181,12 +168,12 @@ err_free: · 9 unmodified lines
181static void amdgpu_gtt_mgr_del(struct ttm_resource_manager *man,168static void amdgpu_gtt_mgr_del(struct ttm_resource_manager *man,
182 struct ttm_resource *res)169 struct ttm_resource *res)
183{170{
184 struct amdgpu_gtt_node *node = to_amdgpu_gtt_node(res);171 struct ttm_range_mgr_node *node = to_ttm_range_mgr_node(res);
185 struct amdgpu_gtt_mgr *mgr = to_gtt_mgr(man);172 struct amdgpu_gtt_mgr *mgr = to_gtt_mgr(man);
186 173
187 spin_lock(&mgr->lock);174 spin_lock(&mgr->lock);
188 if (drm_mm_node_allocated(&node->base.mm_nodes[0]))175 if (drm_mm_node_allocated(&node->mm_nodes[0]))
189 drm_mm_remove_node(&node->base.mm_nodes[0]);176 drm_mm_remove_node(&node->mm_nodes[0]);
190 spin_unlock(&mgr->lock);177 spin_unlock(&mgr->lock);
191 178
192 ttm_resource_fini(man, res);179 ttm_resource_fini(man, res);
@@ -202,7 +189,7 @@ static void amdgpu_gtt_mgr_del(struct ttm_resource_manager *man, · 9 unmodified lines
202 */189 */
203int amdgpu_gtt_mgr_recover(struct amdgpu_gtt_mgr *mgr)190int amdgpu_gtt_mgr_recover(struct amdgpu_gtt_mgr *mgr)
204{191{
205 struct amdgpu_gtt_node *node;192 struct ttm_range_mgr_node *node;
206 struct drm_mm_node *mm_node;193 struct drm_mm_node *mm_node;
207 struct amdgpu_device *adev;194 struct amdgpu_device *adev;
208 int r = 0;195 int r = 0;
@@ -210,8 +197,8 @@ int amdgpu_gtt_mgr_recover(struct amdgpu_gtt_mgr *mgr) · 1 unmodified line
210 adev = container_of(mgr, typeof(*adev), mman.gtt_mgr);197 adev = container_of(mgr, typeof(*adev), mman.gtt_mgr);
211 spin_lock(&mgr->lock);198 spin_lock(&mgr->lock);
212 drm_mm_for_each_node(mm_node, &mgr->mm) {199 drm_mm_for_each_node(mm_node, &mgr->mm) {
213 node = container_of(mm_node, typeof(*node), base.mm_nodes[0]);200 node = container_of(mm_node, typeof(*node), mm_nodes[0]);
214 r = amdgpu_ttm_recover_gart(node->tbo);201 r = amdgpu_ttm_recover_gart(node->base.bo);
215 if (r)202 if (r)
216 break;203 break;
217 }204 }
include/drm/ttm/ttm_resource.h+8−0
@@ -355,6 +355,14 @@ ttm_resource_manager_next(struct ttm_resource_manager *man, · 354 unmodified lines
355 struct ttm_resource_cursor *cursor,355 struct ttm_resource_cursor *cursor,
356 struct ttm_resource *res);356 struct ttm_resource *res);
357 357
358/**
359 * ttm_resource_manager_for_each_res - iterate over all resources
360 * @man: the resource manager
361 * @cursor: struct ttm_resource_cursor for the current position
362 * @res: the current resource
363 *
364 * Iterate over all the evictable resources in a resource manager.
365 */
358#define ttm_resource_manager_for_each_res(man, cursor, res) \366#define ttm_resource_manager_for_each_res(man, cursor, res) \
359 for (res = ttm_resource_manager_first(man, cursor); res; \367 for (res = ttm_resource_manager_first(man, cursor); res; \
360 res = ttm_resource_manager_next(man, cursor, res))368 res = ttm_resource_manager_next(man, cursor, res))