at v4.3-rc2 102 lines 3.1 kB view raw
1/* 2 * Copyright 2011 Christian König. 3 * All Rights Reserved. 4 * 5 * Permission is hereby granted, free of charge, to any person obtaining a 6 * copy of this software and associated documentation files (the 7 * "Software"), to deal in the Software without restriction, including 8 * without limitation the rights to use, copy, modify, merge, publish, 9 * distribute, sub license, and/or sell copies of the Software, and to 10 * permit persons to whom the Software is furnished to do so, subject to 11 * the following conditions: 12 * 13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 16 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, 17 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 18 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 19 * USE OR OTHER DEALINGS IN THE SOFTWARE. 20 * 21 * The above copyright notice and this permission notice (including the 22 * next paragraph) shall be included in all copies or substantial portions 23 * of the Software. 24 * 25 */ 26/* 27 * Authors: 28 * Christian König <deathsimple@vodafone.de> 29 */ 30#include <drm/drmP.h> 31#include "amdgpu.h" 32#include "amdgpu_trace.h" 33 34int amdgpu_semaphore_create(struct amdgpu_device *adev, 35 struct amdgpu_semaphore **semaphore) 36{ 37 int r; 38 39 *semaphore = kmalloc(sizeof(struct amdgpu_semaphore), GFP_KERNEL); 40 if (*semaphore == NULL) { 41 return -ENOMEM; 42 } 43 r = amdgpu_sa_bo_new(adev, &adev->ring_tmp_bo, 44 &(*semaphore)->sa_bo, 8, 8); 45 if (r) { 46 kfree(*semaphore); 47 *semaphore = NULL; 48 return r; 49 } 50 (*semaphore)->waiters = 0; 51 (*semaphore)->gpu_addr = amdgpu_sa_bo_gpu_addr((*semaphore)->sa_bo); 52 53 *((uint64_t *)amdgpu_sa_bo_cpu_addr((*semaphore)->sa_bo)) = 0; 54 55 return 0; 56} 57 58bool amdgpu_semaphore_emit_signal(struct amdgpu_ring *ring, 59 struct amdgpu_semaphore *semaphore) 60{ 61 trace_amdgpu_semaphore_signale(ring->idx, semaphore); 62 63 if (amdgpu_ring_emit_semaphore(ring, semaphore, false)) { 64 --semaphore->waiters; 65 66 /* for debugging lockup only, used by sysfs debug files */ 67 ring->last_semaphore_signal_addr = semaphore->gpu_addr; 68 return true; 69 } 70 return false; 71} 72 73bool amdgpu_semaphore_emit_wait(struct amdgpu_ring *ring, 74 struct amdgpu_semaphore *semaphore) 75{ 76 trace_amdgpu_semaphore_wait(ring->idx, semaphore); 77 78 if (amdgpu_ring_emit_semaphore(ring, semaphore, true)) { 79 ++semaphore->waiters; 80 81 /* for debugging lockup only, used by sysfs debug files */ 82 ring->last_semaphore_wait_addr = semaphore->gpu_addr; 83 return true; 84 } 85 return false; 86} 87 88void amdgpu_semaphore_free(struct amdgpu_device *adev, 89 struct amdgpu_semaphore **semaphore, 90 struct fence *fence) 91{ 92 if (semaphore == NULL || *semaphore == NULL) { 93 return; 94 } 95 if ((*semaphore)->waiters > 0) { 96 dev_err(adev->dev, "semaphore %p has more waiters than signalers," 97 " hardware lockup imminent!\n", *semaphore); 98 } 99 amdgpu_sa_bo_free(adev, &(*semaphore)->sa_bo, fence); 100 kfree(*semaphore); 101 *semaphore = NULL; 102}