blob: a4751598c0b48cb243ff1b07732067ba06f17c3b [file] [log] [blame]
Chunming Zhouf556cb0c2015-08-02 11:18:04 +08001/*
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
Christian König5b232c22015-08-10 14:16:24 +020030struct amd_sched_fence *amd_sched_fence_create(struct amd_sched_entity *s_entity)
Chunming Zhouf556cb0c2015-08-02 11:18:04 +080031{
32 struct amd_sched_fence *fence = NULL;
33 fence = kzalloc(sizeof(struct amd_sched_fence), GFP_KERNEL);
34 if (fence == NULL)
35 return NULL;
36 fence->v_seq = atomic64_inc_return(&s_entity->last_queued_v_seq);
37 fence->entity = s_entity;
38 spin_lock_init(&fence->lock);
39 fence_init(&fence->base, &amd_sched_fence_ops,
40 &fence->lock,
41 s_entity->fence_context,
42 fence->v_seq);
Chunming Zhouf556cb0c2015-08-02 11:18:04 +080043 return fence;
44}
45
Chunming Zhouf556cb0c2015-08-02 11:18:04 +080046void amd_sched_fence_signal(struct amd_sched_fence *fence)
47{
Christian König2983e5c2015-08-10 14:20:55 +020048 int ret = fence_signal(&fence->base);
49 if (!ret)
50 FENCE_TRACE(&fence->base, "signaled from irq context\n");
51 else
52 FENCE_TRACE(&fence->base, "was already signaled\n");
Chunming Zhouf556cb0c2015-08-02 11:18:04 +080053}
54
55static const char *amd_sched_fence_get_driver_name(struct fence *fence)
56{
57 return "amd_sched";
58}
59
60static const char *amd_sched_fence_get_timeline_name(struct fence *f)
61{
62 struct amd_sched_fence *fence = to_amd_sched_fence(f);
63 return (const char *)fence->entity->name;
64}
65
66static bool amd_sched_fence_enable_signaling(struct fence *f)
67{
Christian König2983e5c2015-08-10 14:20:55 +020068 return true;
Chunming Zhouf556cb0c2015-08-02 11:18:04 +080069}
70
71const struct fence_ops amd_sched_fence_ops = {
72 .get_driver_name = amd_sched_fence_get_driver_name,
73 .get_timeline_name = amd_sched_fence_get_timeline_name,
74 .enable_signaling = amd_sched_fence_enable_signaling,
Christian König2983e5c2015-08-10 14:20:55 +020075 .signaled = NULL,
Chunming Zhouf556cb0c2015-08-02 11:18:04 +080076 .wait = fence_default_wait,
77 .release = NULL,
78};