diff options
author | Christian König <christian.koenig@amd.com> | 2015-12-14 07:18:01 -0500 |
---|---|---|
committer | Alex Deucher <alexander.deucher@amd.com> | 2016-08-08 11:32:15 -0400 |
commit | 7c204889dec5e745cdcc174388fa3aa824e75160 (patch) | |
tree | da3bd3470ed92ad83da9e349e1386f396a89220f /drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | |
parent | 81e04e1809057128abe1b996ca7bc0cbb38e56c9 (diff) |
drm/amdgpu: add new helper for in kernel allocations
We often allocate, pin and map things at the same time in the kernel.
Signed-off-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Chunming Zhou <david1.zhou@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Diffstat (limited to 'drivers/gpu/drm/amd/amdgpu/amdgpu_object.c')
-rw-r--r-- | drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c index 6f0873c75a25..93573586e2de 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | |||
@@ -211,6 +211,69 @@ static void amdgpu_fill_placement_to_bo(struct amdgpu_bo *bo, | |||
211 | bo->placement.busy_placement = bo->placements; | 211 | bo->placement.busy_placement = bo->placements; |
212 | } | 212 | } |
213 | 213 | ||
214 | /** | ||
215 | * amdgpu_bo_create_kernel - create BO for kernel use | ||
216 | * | ||
217 | * @adev: amdgpu device object | ||
218 | * @size: size for the new BO | ||
219 | * @align: alignment for the new BO | ||
220 | * @domain: where to place it | ||
221 | * @bo_ptr: resulting BO | ||
222 | * @gpu_addr: GPU addr of the pinned BO | ||
223 | * @cpu_addr: optional CPU address mapping | ||
224 | * | ||
225 | * Allocates and pins a BO for kernel internal use. | ||
226 | * | ||
227 | * Returns 0 on success, negative error code otherwise. | ||
228 | */ | ||
229 | int amdgpu_bo_create_kernel(struct amdgpu_device *adev, | ||
230 | unsigned long size, int align, | ||
231 | u32 domain, struct amdgpu_bo **bo_ptr, | ||
232 | u64 *gpu_addr, void **cpu_addr) | ||
233 | { | ||
234 | int r; | ||
235 | |||
236 | r = amdgpu_bo_create(adev, size, align, true, domain, | ||
237 | AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED, | ||
238 | NULL, NULL, bo_ptr); | ||
239 | if (r) { | ||
240 | dev_err(adev->dev, "(%d) failed to allocate kernel bo\n", r); | ||
241 | return r; | ||
242 | } | ||
243 | |||
244 | r = amdgpu_bo_reserve(*bo_ptr, false); | ||
245 | if (r) { | ||
246 | dev_err(adev->dev, "(%d) failed to reserve kernel bo\n", r); | ||
247 | goto error_free; | ||
248 | } | ||
249 | |||
250 | r = amdgpu_bo_pin(*bo_ptr, domain, gpu_addr); | ||
251 | if (r) { | ||
252 | dev_err(adev->dev, "(%d) kernel bo pin failed\n", r); | ||
253 | goto error_unreserve; | ||
254 | } | ||
255 | |||
256 | if (cpu_addr) { | ||
257 | r = amdgpu_bo_kmap(*bo_ptr, cpu_addr); | ||
258 | if (r) { | ||
259 | dev_err(adev->dev, "(%d) kernel bo map failed\n", r); | ||
260 | goto error_unreserve; | ||
261 | } | ||
262 | } | ||
263 | |||
264 | amdgpu_bo_unreserve(*bo_ptr); | ||
265 | |||
266 | return 0; | ||
267 | |||
268 | error_unreserve: | ||
269 | amdgpu_bo_unreserve(*bo_ptr); | ||
270 | |||
271 | error_free: | ||
272 | amdgpu_bo_unref(bo_ptr); | ||
273 | |||
274 | return r; | ||
275 | } | ||
276 | |||
214 | int amdgpu_bo_create_restricted(struct amdgpu_device *adev, | 277 | int amdgpu_bo_create_restricted(struct amdgpu_device *adev, |
215 | unsigned long size, int byte_align, | 278 | unsigned long size, int byte_align, |
216 | bool kernel, u32 domain, u64 flags, | 279 | bool kernel, u32 domain, u64 flags, |