Chunming Zhou | f556cb0c | 2015-08-02 11:18:04 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Advanced Micro Devices, Inc. |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 5 | * copy of this software and associated documentation files (the "Software"), |
| 6 | * to deal in the Software without restriction, including without limitation |
| 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 | * and/or sell copies of the Software, and to permit persons to whom the |
| 9 | * Software is furnished to do so, subject to the following conditions: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice shall be included in |
| 12 | * all copies or substantial portions of the Software. |
| 13 | * |
| 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 17 | * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 18 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 20 | * OTHER DEALINGS IN THE SOFTWARE. |
| 21 | * |
| 22 | * |
| 23 | */ |
| 24 | #include <linux/kthread.h> |
| 25 | #include <linux/wait.h> |
| 26 | #include <linux/sched.h> |
| 27 | #include <drm/drmP.h> |
| 28 | #include "gpu_scheduler.h" |
| 29 | |
Chunming Zhou | 84f76ea | 2015-08-24 12:47:36 +0800 | [diff] [blame] | 30 | struct amd_sched_fence *amd_sched_fence_create(struct amd_sched_entity *s_entity, void *owner) |
Chunming Zhou | f556cb0c | 2015-08-02 11:18:04 +0800 | [diff] [blame] | 31 | { |
| 32 | struct amd_sched_fence *fence = NULL; |
Christian König | ce882e6 | 2015-08-19 15:00:55 +0200 | [diff] [blame] | 33 | unsigned seq; |
| 34 | |
Chunming Zhou | f5617f9 | 2015-11-05 11:41:50 +0800 | [diff] [blame] | 35 | fence = kmem_cache_zalloc(sched_fence_slab, GFP_KERNEL); |
Chunming Zhou | f556cb0c | 2015-08-02 11:18:04 +0800 | [diff] [blame] | 36 | if (fence == NULL) |
| 37 | return NULL; |
Chunming Zhou | 84f76ea | 2015-08-24 12:47:36 +0800 | [diff] [blame] | 38 | fence->owner = owner; |
Christian König | 9b398fa | 2015-09-07 18:16:49 +0200 | [diff] [blame] | 39 | fence->sched = s_entity->sched; |
Chunming Zhou | f556cb0c | 2015-08-02 11:18:04 +0800 | [diff] [blame] | 40 | spin_lock_init(&fence->lock); |
Christian König | ce882e6 | 2015-08-19 15:00:55 +0200 | [diff] [blame] | 41 | |
| 42 | seq = atomic_inc_return(&s_entity->fence_seq); |
| 43 | fence_init(&fence->base, &amd_sched_fence_ops, &fence->lock, |
| 44 | s_entity->fence_context, seq); |
| 45 | |
Chunming Zhou | f556cb0c | 2015-08-02 11:18:04 +0800 | [diff] [blame] | 46 | return fence; |
| 47 | } |
| 48 | |
Chunming Zhou | f556cb0c | 2015-08-02 11:18:04 +0800 | [diff] [blame] | 49 | void amd_sched_fence_signal(struct amd_sched_fence *fence) |
| 50 | { |
Christian König | 2983e5c | 2015-08-10 14:20:55 +0200 | [diff] [blame] | 51 | int ret = fence_signal(&fence->base); |
| 52 | if (!ret) |
| 53 | FENCE_TRACE(&fence->base, "signaled from irq context\n"); |
| 54 | else |
| 55 | FENCE_TRACE(&fence->base, "was already signaled\n"); |
Chunming Zhou | f556cb0c | 2015-08-02 11:18:04 +0800 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | static const char *amd_sched_fence_get_driver_name(struct fence *fence) |
| 59 | { |
| 60 | return "amd_sched"; |
| 61 | } |
| 62 | |
| 63 | static const char *amd_sched_fence_get_timeline_name(struct fence *f) |
| 64 | { |
| 65 | struct amd_sched_fence *fence = to_amd_sched_fence(f); |
Christian König | 9b398fa | 2015-09-07 18:16:49 +0200 | [diff] [blame] | 66 | return (const char *)fence->sched->name; |
Chunming Zhou | f556cb0c | 2015-08-02 11:18:04 +0800 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | static bool amd_sched_fence_enable_signaling(struct fence *f) |
| 70 | { |
Christian König | 2983e5c | 2015-08-10 14:20:55 +0200 | [diff] [blame] | 71 | return true; |
Chunming Zhou | f556cb0c | 2015-08-02 11:18:04 +0800 | [diff] [blame] | 72 | } |
| 73 | |
Chunming Zhou | f5617f9 | 2015-11-05 11:41:50 +0800 | [diff] [blame] | 74 | static void amd_sched_fence_release(struct fence *f) |
| 75 | { |
| 76 | struct amd_sched_fence *fence = to_amd_sched_fence(f); |
| 77 | kmem_cache_free(sched_fence_slab, fence); |
| 78 | } |
| 79 | |
Chunming Zhou | f556cb0c | 2015-08-02 11:18:04 +0800 | [diff] [blame] | 80 | const struct fence_ops amd_sched_fence_ops = { |
| 81 | .get_driver_name = amd_sched_fence_get_driver_name, |
| 82 | .get_timeline_name = amd_sched_fence_get_timeline_name, |
| 83 | .enable_signaling = amd_sched_fence_enable_signaling, |
Christian König | 2983e5c | 2015-08-10 14:20:55 +0200 | [diff] [blame] | 84 | .signaled = NULL, |
Chunming Zhou | f556cb0c | 2015-08-02 11:18:04 +0800 | [diff] [blame] | 85 | .wait = fence_default_wait, |
Chunming Zhou | f5617f9 | 2015-11-05 11:41:50 +0800 | [diff] [blame] | 86 | .release = amd_sched_fence_release, |
Chunming Zhou | f556cb0c | 2015-08-02 11:18:04 +0800 | [diff] [blame] | 87 | }; |