diff options
author | Dave Airlie <airlied@redhat.com> | 2019-04-04 21:21:47 -0400 |
---|---|---|
committer | Dave Airlie <airlied@redhat.com> | 2019-04-04 21:38:02 -0400 |
commit | 14d2bd53a47a7e1cb3e03d00a6b952734cf90f3f (patch) | |
tree | 616e11aacdf96d495bf6ef9c8163fb83cd5b712b /drivers/gpu/drm/lima/lima_ctx.c | |
parent | 5ebffda257731a11cf1db6c6142c82d5b30aec35 (diff) | |
parent | f15a3ea80391e83f32d4a23f83b1f02415cd5889 (diff) |
Merge tag 'drm-misc-next-2019-04-04' of git://anongit.freedesktop.org/drm/drm-misc into drm-next
drm-misc-next for 5.2:
UAPI Changes:
-syncobj: Add TIMELINE_WAIT|QUERY|TRANSFER|TIMELINE_SIGNAL ioctls (Chunming)
-Clarify that 1.0 can be represented by drm_color_lut (Daniel)
Cross-subsystem Changes:
-dt-bindings: Add binding for rk3066 hdmi (Johan)
-dt-bindings: Add binding for Feiyang FY07024DI26A30-D panel (Jagan)
-dt-bindings: Add Rocktech vendor prefix and jh057n00900 panel bindings (Guido)
-MAINTAINERS: Add lima and ASPEED entries (Joel & Qiang)
Core Changes:
-memory: use dma_alloc_coherent when mem encryption is active (Christian)
-dma_buf: add support for a dma_fence chain (Christian)
-shmem_gem: fix off-by-one bug in new shmem gem helpers (Dan)
Driver Changes:
-rockchip: Add support for rk3066 hdmi (Johan)
-ASPEED: Add driver supporting ASPEED BMC display controller to drm (Joel)
-lima: Add driver supporting Arm Mali4xx gpus to drm (Qiang)
-vc4/v3d: Various cleanups and improved error handling (Eric)
-panel: Add support for Feiyang FY07024DI26A30-D MIPI-DSI panel (Jagan)
-panel: Add support for Rocktech jh057n00900 MIPI-DSI panel (Guido)
Cc: Johan Jonker <jbx6244@gmail.com>
Cc: Christian König <christian.koenig@amd.com>
Cc: Chunming Zhou <david1.zhou@amd.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Cc: Eric Anholt <eric@anholt.net>
Cc: Qiang Yu <yuq825@gmail.com>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: Jagan Teki <jagan@amarulasolutions.com>
Cc: Guido Günther <agx@sigxcpu.org>
Cc: Joel Stanley <joel@jms.id.au>
[airlied: fixed XA limit build breakage, Rodrigo also submitted the same patch, but
I squashed it in the merge.]
Signed-off-by: Dave Airlie <airlied@redhat.com>
From: Sean Paul <sean@poorly.run>
Link: https://patchwork.freedesktop.org/patch/msgid/20190404201016.GA139524@art_vandelay
Diffstat (limited to 'drivers/gpu/drm/lima/lima_ctx.c')
-rw-r--r-- | drivers/gpu/drm/lima/lima_ctx.c | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/drivers/gpu/drm/lima/lima_ctx.c b/drivers/gpu/drm/lima/lima_ctx.c new file mode 100644 index 000000000000..22fff6caa961 --- /dev/null +++ b/drivers/gpu/drm/lima/lima_ctx.c | |||
@@ -0,0 +1,98 @@ | |||
1 | // SPDX-License-Identifier: GPL-2.0 OR MIT | ||
2 | /* Copyright 2018-2019 Qiang Yu <yuq825@gmail.com> */ | ||
3 | |||
4 | #include <linux/slab.h> | ||
5 | |||
6 | #include "lima_device.h" | ||
7 | #include "lima_ctx.h" | ||
8 | |||
9 | int lima_ctx_create(struct lima_device *dev, struct lima_ctx_mgr *mgr, u32 *id) | ||
10 | { | ||
11 | struct lima_ctx *ctx; | ||
12 | int i, err; | ||
13 | |||
14 | ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); | ||
15 | if (!ctx) | ||
16 | return -ENOMEM; | ||
17 | ctx->dev = dev; | ||
18 | kref_init(&ctx->refcnt); | ||
19 | |||
20 | for (i = 0; i < lima_pipe_num; i++) { | ||
21 | err = lima_sched_context_init(dev->pipe + i, ctx->context + i, &ctx->guilty); | ||
22 | if (err) | ||
23 | goto err_out0; | ||
24 | } | ||
25 | |||
26 | err = xa_alloc(&mgr->handles, id, ctx, xa_limit_32b, GFP_KERNEL); | ||
27 | if (err < 0) | ||
28 | goto err_out0; | ||
29 | |||
30 | return 0; | ||
31 | |||
32 | err_out0: | ||
33 | for (i--; i >= 0; i--) | ||
34 | lima_sched_context_fini(dev->pipe + i, ctx->context + i); | ||
35 | kfree(ctx); | ||
36 | return err; | ||
37 | } | ||
38 | |||
39 | static void lima_ctx_do_release(struct kref *ref) | ||
40 | { | ||
41 | struct lima_ctx *ctx = container_of(ref, struct lima_ctx, refcnt); | ||
42 | int i; | ||
43 | |||
44 | for (i = 0; i < lima_pipe_num; i++) | ||
45 | lima_sched_context_fini(ctx->dev->pipe + i, ctx->context + i); | ||
46 | kfree(ctx); | ||
47 | } | ||
48 | |||
49 | int lima_ctx_free(struct lima_ctx_mgr *mgr, u32 id) | ||
50 | { | ||
51 | struct lima_ctx *ctx; | ||
52 | int ret = 0; | ||
53 | |||
54 | mutex_lock(&mgr->lock); | ||
55 | ctx = xa_erase(&mgr->handles, id); | ||
56 | if (ctx) | ||
57 | kref_put(&ctx->refcnt, lima_ctx_do_release); | ||
58 | else | ||
59 | ret = -EINVAL; | ||
60 | mutex_unlock(&mgr->lock); | ||
61 | return ret; | ||
62 | } | ||
63 | |||
64 | struct lima_ctx *lima_ctx_get(struct lima_ctx_mgr *mgr, u32 id) | ||
65 | { | ||
66 | struct lima_ctx *ctx; | ||
67 | |||
68 | mutex_lock(&mgr->lock); | ||
69 | ctx = xa_load(&mgr->handles, id); | ||
70 | if (ctx) | ||
71 | kref_get(&ctx->refcnt); | ||
72 | mutex_unlock(&mgr->lock); | ||
73 | return ctx; | ||
74 | } | ||
75 | |||
76 | void lima_ctx_put(struct lima_ctx *ctx) | ||
77 | { | ||
78 | kref_put(&ctx->refcnt, lima_ctx_do_release); | ||
79 | } | ||
80 | |||
81 | void lima_ctx_mgr_init(struct lima_ctx_mgr *mgr) | ||
82 | { | ||
83 | mutex_init(&mgr->lock); | ||
84 | xa_init_flags(&mgr->handles, XA_FLAGS_ALLOC); | ||
85 | } | ||
86 | |||
87 | void lima_ctx_mgr_fini(struct lima_ctx_mgr *mgr) | ||
88 | { | ||
89 | struct lima_ctx *ctx; | ||
90 | unsigned long id; | ||
91 | |||
92 | xa_for_each(&mgr->handles, id, ctx) { | ||
93 | kref_put(&ctx->refcnt, lima_ctx_do_release); | ||
94 | } | ||
95 | |||
96 | xa_destroy(&mgr->handles); | ||
97 | mutex_destroy(&mgr->lock); | ||
98 | } | ||