blob: 2998bde292112649cd1747110a68270d7a3a7899 [file] [log] [blame]
Ben Skeggs5e120f62012-04-30 13:55:29 +10001/*
2 * Copyright 2012 Red Hat 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 * Authors: Ben Skeggs <bskeggs@redhat.com>
23 */
24
Ben Skeggs4dc28132016-05-20 09:22:55 +100025#include "nouveau_drv.h"
Ben Skeggs5e120f62012-04-30 13:55:29 +100026#include "nouveau_dma.h"
Marcin Slusarza4cea272012-12-25 17:50:43 +010027#include "nv10_fence.h"
Ben Skeggs5e120f62012-04-30 13:55:29 +100028
Ben Skeggsf589be82012-07-22 11:55:54 +100029int
Ben Skeggs5e120f62012-04-30 13:55:29 +100030nv10_fence_emit(struct nouveau_fence *fence)
31{
32 struct nouveau_channel *chan = fence->channel;
33 int ret = RING_SPACE(chan, 2);
34 if (ret == 0) {
35 BEGIN_NV04(chan, 0, NV10_SUBCHAN_REF_CNT, 1);
Maarten Lankhorst29ba89b2014-01-09 11:03:11 +010036 OUT_RING (chan, fence->base.seqno);
Ben Skeggs5e120f62012-04-30 13:55:29 +100037 FIRE_RING (chan);
38 }
39 return ret;
40}
41
Ben Skeggs906c0332012-05-04 16:25:47 +100042
Ben Skeggs5e120f62012-04-30 13:55:29 +100043static int
Ben Skeggs906c0332012-05-04 16:25:47 +100044nv10_fence_sync(struct nouveau_fence *fence,
45 struct nouveau_channel *prev, struct nouveau_channel *chan)
Ben Skeggs5e120f62012-04-30 13:55:29 +100046{
47 return -ENODEV;
48}
49
Ben Skeggsf589be82012-07-22 11:55:54 +100050u32
Ben Skeggs5e120f62012-04-30 13:55:29 +100051nv10_fence_read(struct nouveau_channel *chan)
52{
Ben Skeggsa01ca782015-08-20 14:54:15 +100053 return nvif_rd32(&chan->user, 0x0048);
Ben Skeggs5e120f62012-04-30 13:55:29 +100054}
55
Ben Skeggsf589be82012-07-22 11:55:54 +100056void
Ben Skeggse193b1d2012-07-19 10:51:42 +100057nv10_fence_context_del(struct nouveau_channel *chan)
Ben Skeggs5e120f62012-04-30 13:55:29 +100058{
Ben Skeggse193b1d2012-07-19 10:51:42 +100059 struct nv10_fence_chan *fctx = chan->fence;
Ben Skeggs5e120f62012-04-30 13:55:29 +100060 nouveau_fence_context_del(&fctx->base);
Ben Skeggs0ad72862014-08-10 04:10:22 +100061 nvif_object_fini(&fctx->sema);
Ben Skeggse193b1d2012-07-19 10:51:42 +100062 chan->fence = NULL;
Maarten Lankhorst15a996b2014-09-29 10:06:18 +020063 nouveau_fence_context_free(&fctx->base);
Ben Skeggs5e120f62012-04-30 13:55:29 +100064}
65
Baoyou Xiee08a1d92016-10-24 11:09:03 +080066static int
Ben Skeggse193b1d2012-07-19 10:51:42 +100067nv10_fence_context_new(struct nouveau_channel *chan)
Ben Skeggs5e120f62012-04-30 13:55:29 +100068{
Ben Skeggs5e120f62012-04-30 13:55:29 +100069 struct nv10_fence_chan *fctx;
Ben Skeggs5e120f62012-04-30 13:55:29 +100070
Ben Skeggse193b1d2012-07-19 10:51:42 +100071 fctx = chan->fence = kzalloc(sizeof(*fctx), GFP_KERNEL);
Ben Skeggs5e120f62012-04-30 13:55:29 +100072 if (!fctx)
73 return -ENOMEM;
74
Maarten Lankhorst29ba89b2014-01-09 11:03:11 +010075 nouveau_fence_context_new(chan, &fctx->base);
Ben Skeggs827520c2013-02-14 13:20:17 +100076 fctx->base.emit = nv10_fence_emit;
77 fctx->base.read = nv10_fence_read;
78 fctx->base.sync = nv10_fence_sync;
Ben Skeggs60e5cb72013-02-14 12:59:36 +100079 return 0;
Ben Skeggs5e120f62012-04-30 13:55:29 +100080}
81
Ben Skeggsf589be82012-07-22 11:55:54 +100082void
Ben Skeggsebb945a2012-07-20 08:17:34 +100083nv10_fence_destroy(struct nouveau_drm *drm)
Ben Skeggs5e120f62012-04-30 13:55:29 +100084{
Ben Skeggsebb945a2012-07-20 08:17:34 +100085 struct nv10_fence_priv *priv = drm->fence;
86 nouveau_bo_unmap(priv->bo);
Marcin Slusarz04c8c212012-11-25 23:04:23 +010087 if (priv->bo)
88 nouveau_bo_unpin(priv->bo);
Ben Skeggs5e120f62012-04-30 13:55:29 +100089 nouveau_bo_ref(NULL, &priv->bo);
Ben Skeggsebb945a2012-07-20 08:17:34 +100090 drm->fence = NULL;
Ben Skeggs5e120f62012-04-30 13:55:29 +100091 kfree(priv);
92}
93
94int
Ben Skeggsebb945a2012-07-20 08:17:34 +100095nv10_fence_create(struct nouveau_drm *drm)
Ben Skeggs5e120f62012-04-30 13:55:29 +100096{
Ben Skeggs5e120f62012-04-30 13:55:29 +100097 struct nv10_fence_priv *priv;
Ben Skeggs5e120f62012-04-30 13:55:29 +100098
Ben Skeggsebb945a2012-07-20 08:17:34 +100099 priv = drm->fence = kzalloc(sizeof(*priv), GFP_KERNEL);
Ben Skeggs5e120f62012-04-30 13:55:29 +1000100 if (!priv)
101 return -ENOMEM;
102
Ben Skeggse193b1d2012-07-19 10:51:42 +1000103 priv->base.dtor = nv10_fence_destroy;
104 priv->base.context_new = nv10_fence_context_new;
105 priv->base.context_del = nv10_fence_context_del;
Maarten Lankhorst29ba89b2014-01-09 11:03:11 +0100106 priv->base.contexts = 31;
Chris Wilsonf54d1862016-10-25 13:00:45 +0100107 priv->base.context_base = dma_fence_context_alloc(priv->base.contexts);
Ben Skeggs5e120f62012-04-30 13:55:29 +1000108 spin_lock_init(&priv->lock);
Ben Skeggs60e5cb72013-02-14 12:59:36 +1000109 return 0;
Ben Skeggs5e120f62012-04-30 13:55:29 +1000110}