blob: c686650584b6d33ad203ed3b4ed4cd62dd38bb73 [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
23 */
24
Ben Skeggsebb945a2012-07-20 08:17:34 +100025#include <core/object.h>
26#include <core/class.h>
27
Ben Skeggs02a841d2012-07-04 23:44:54 +100028#include <engine/fifo.h>
Ben Skeggsebb945a2012-07-20 08:17:34 +100029
30#include "nouveau_drm.h"
31#include "nouveau_dma.h"
Ben Skeggs5e120f62012-04-30 13:55:29 +100032#include "nouveau_fence.h"
33
Ben Skeggs77145f12012-07-31 16:16:21 +100034#include "nv50_display.h"
35
Ben Skeggs5e120f62012-04-30 13:55:29 +100036struct nv84_fence_chan {
37 struct nouveau_fence_chan base;
38};
39
40struct nv84_fence_priv {
41 struct nouveau_fence_priv base;
42 struct nouveau_gpuobj *mem;
43};
44
45static int
46nv84_fence_emit(struct nouveau_fence *fence)
47{
48 struct nouveau_channel *chan = fence->channel;
Ben Skeggsebb945a2012-07-20 08:17:34 +100049 struct nouveau_fifo_chan *fifo = (void *)chan->object;
Ben Skeggs5e120f62012-04-30 13:55:29 +100050 int ret = RING_SPACE(chan, 7);
51 if (ret == 0) {
52 BEGIN_NV04(chan, 0, NV11_SUBCHAN_DMA_SEMAPHORE, 1);
53 OUT_RING (chan, NvSema);
54 BEGIN_NV04(chan, 0, NV84_SUBCHAN_SEMAPHORE_ADDRESS_HIGH, 4);
Ben Skeggsebb945a2012-07-20 08:17:34 +100055 OUT_RING (chan, upper_32_bits(fifo->chid * 16));
56 OUT_RING (chan, lower_32_bits(fifo->chid * 16));
Ben Skeggs5e120f62012-04-30 13:55:29 +100057 OUT_RING (chan, fence->sequence);
58 OUT_RING (chan, NV84_SUBCHAN_SEMAPHORE_TRIGGER_WRITE_LONG);
59 FIRE_RING (chan);
60 }
61 return ret;
62}
63
Ben Skeggs906c0332012-05-04 16:25:47 +100064
Ben Skeggs5e120f62012-04-30 13:55:29 +100065static int
Ben Skeggs906c0332012-05-04 16:25:47 +100066nv84_fence_sync(struct nouveau_fence *fence,
67 struct nouveau_channel *prev, struct nouveau_channel *chan)
Ben Skeggs5e120f62012-04-30 13:55:29 +100068{
Ben Skeggsebb945a2012-07-20 08:17:34 +100069 struct nouveau_fifo_chan *fifo = (void *)prev->object;
Ben Skeggs5e120f62012-04-30 13:55:29 +100070 int ret = RING_SPACE(chan, 7);
71 if (ret == 0) {
72 BEGIN_NV04(chan, 0, NV11_SUBCHAN_DMA_SEMAPHORE, 1);
73 OUT_RING (chan, NvSema);
74 BEGIN_NV04(chan, 0, NV84_SUBCHAN_SEMAPHORE_ADDRESS_HIGH, 4);
Ben Skeggsebb945a2012-07-20 08:17:34 +100075 OUT_RING (chan, upper_32_bits(fifo->chid * 16));
76 OUT_RING (chan, lower_32_bits(fifo->chid * 16));
Ben Skeggs5e120f62012-04-30 13:55:29 +100077 OUT_RING (chan, fence->sequence);
78 OUT_RING (chan, NV84_SUBCHAN_SEMAPHORE_TRIGGER_ACQUIRE_GEQUAL);
79 FIRE_RING (chan);
80 }
81 return ret;
82}
83
84static u32
85nv84_fence_read(struct nouveau_channel *chan)
86{
Ben Skeggsebb945a2012-07-20 08:17:34 +100087 struct nouveau_fifo_chan *fifo = (void *)chan->object;
88 struct nv84_fence_priv *priv = chan->drm->fence;
89 return nv_ro32(priv->mem, fifo->chid * 16);
Ben Skeggs5e120f62012-04-30 13:55:29 +100090}
91
92static void
Ben Skeggse193b1d2012-07-19 10:51:42 +100093nv84_fence_context_del(struct nouveau_channel *chan)
Ben Skeggs5e120f62012-04-30 13:55:29 +100094{
Ben Skeggse193b1d2012-07-19 10:51:42 +100095 struct nv84_fence_chan *fctx = chan->fence;
Ben Skeggs5e120f62012-04-30 13:55:29 +100096 nouveau_fence_context_del(&fctx->base);
Ben Skeggse193b1d2012-07-19 10:51:42 +100097 chan->fence = NULL;
Ben Skeggs5e120f62012-04-30 13:55:29 +100098 kfree(fctx);
99}
100
101static int
Ben Skeggse193b1d2012-07-19 10:51:42 +1000102nv84_fence_context_new(struct nouveau_channel *chan)
Ben Skeggs5e120f62012-04-30 13:55:29 +1000103{
Ben Skeggs77145f12012-07-31 16:16:21 +1000104 struct drm_device *dev = chan->drm->dev;
Ben Skeggsebb945a2012-07-20 08:17:34 +1000105 struct nouveau_fifo_chan *fifo = (void *)chan->object;
106 struct nv84_fence_priv *priv = chan->drm->fence;
Ben Skeggs5e120f62012-04-30 13:55:29 +1000107 struct nv84_fence_chan *fctx;
Ben Skeggsebb945a2012-07-20 08:17:34 +1000108 struct nouveau_object *object;
Ben Skeggsf589be82012-07-22 11:55:54 +1000109 int ret, i;
Ben Skeggs5e120f62012-04-30 13:55:29 +1000110
Ben Skeggse193b1d2012-07-19 10:51:42 +1000111 fctx = chan->fence = kzalloc(sizeof(*fctx), GFP_KERNEL);
Ben Skeggs5e120f62012-04-30 13:55:29 +1000112 if (!fctx)
113 return -ENOMEM;
114
115 nouveau_fence_context_new(&fctx->base);
116
Ben Skeggsebb945a2012-07-20 08:17:34 +1000117 ret = nouveau_object_new(nv_object(chan->cli), chan->handle,
118 NvSema, 0x0002,
119 &(struct nv_dma_class) {
120 .flags = NV_DMA_TARGET_VRAM |
121 NV_DMA_ACCESS_RDWR,
122 .start = priv->mem->addr,
123 .limit = priv->mem->addr +
124 priv->mem->size - 1,
125 }, sizeof(struct nv_dma_class),
126 &object);
Ben Skeggs5e120f62012-04-30 13:55:29 +1000127
Ben Skeggsf589be82012-07-22 11:55:54 +1000128 /* dma objects for display sync channel semaphore blocks */
Ben Skeggs77145f12012-07-31 16:16:21 +1000129 for (i = 0; !ret && i < dev->mode_config.num_crtc; i++) {
130 struct nouveau_bo *bo = nv50_display_crtc_sema(dev, i);
Ben Skeggsf589be82012-07-22 11:55:54 +1000131
Ben Skeggsebb945a2012-07-20 08:17:34 +1000132 ret = nouveau_object_new(nv_object(chan->cli), chan->handle,
133 NvEvoSema0 + i, 0x003d,
134 &(struct nv_dma_class) {
135 .flags = NV_DMA_TARGET_VRAM |
136 NV_DMA_ACCESS_RDWR,
137 .start = bo->bo.offset,
138 .limit = bo->bo.offset + 0xfff,
139 }, sizeof(struct nv_dma_class),
140 &object);
Ben Skeggsf589be82012-07-22 11:55:54 +1000141 }
142
Ben Skeggs5e120f62012-04-30 13:55:29 +1000143 if (ret)
Ben Skeggse193b1d2012-07-19 10:51:42 +1000144 nv84_fence_context_del(chan);
Ben Skeggsebb945a2012-07-20 08:17:34 +1000145 nv_wo32(priv->mem, fifo->chid * 16, 0x00000000);
Ben Skeggs5e120f62012-04-30 13:55:29 +1000146 return ret;
147}
148
Ben Skeggs5e120f62012-04-30 13:55:29 +1000149static void
Ben Skeggsebb945a2012-07-20 08:17:34 +1000150nv84_fence_destroy(struct nouveau_drm *drm)
Ben Skeggs5e120f62012-04-30 13:55:29 +1000151{
Ben Skeggsebb945a2012-07-20 08:17:34 +1000152 struct nv84_fence_priv *priv = drm->fence;
Ben Skeggs5e120f62012-04-30 13:55:29 +1000153 nouveau_gpuobj_ref(NULL, &priv->mem);
Ben Skeggsebb945a2012-07-20 08:17:34 +1000154 drm->fence = NULL;
Ben Skeggs5e120f62012-04-30 13:55:29 +1000155 kfree(priv);
156}
157
158int
Ben Skeggsebb945a2012-07-20 08:17:34 +1000159nv84_fence_create(struct nouveau_drm *drm)
Ben Skeggs5e120f62012-04-30 13:55:29 +1000160{
Ben Skeggsebb945a2012-07-20 08:17:34 +1000161 struct nouveau_fifo *pfifo = nouveau_fifo(drm->device);
Ben Skeggs5e120f62012-04-30 13:55:29 +1000162 struct nv84_fence_priv *priv;
Ben Skeggsebb945a2012-07-20 08:17:34 +1000163 u32 chan = pfifo->max + 1;
Ben Skeggs5e120f62012-04-30 13:55:29 +1000164 int ret;
165
Ben Skeggsebb945a2012-07-20 08:17:34 +1000166 priv = drm->fence = kzalloc(sizeof(*priv), GFP_KERNEL);
Ben Skeggs5e120f62012-04-30 13:55:29 +1000167 if (!priv)
168 return -ENOMEM;
169
Ben Skeggse193b1d2012-07-19 10:51:42 +1000170 priv->base.dtor = nv84_fence_destroy;
171 priv->base.context_new = nv84_fence_context_new;
172 priv->base.context_del = nv84_fence_context_del;
Ben Skeggs5e120f62012-04-30 13:55:29 +1000173 priv->base.emit = nv84_fence_emit;
174 priv->base.sync = nv84_fence_sync;
175 priv->base.read = nv84_fence_read;
Ben Skeggs5e120f62012-04-30 13:55:29 +1000176
Ben Skeggsebb945a2012-07-20 08:17:34 +1000177 ret = nouveau_gpuobj_new(drm->device, NULL, chan * 16, 0x1000, 0,
178 &priv->mem);
Ben Skeggs5e120f62012-04-30 13:55:29 +1000179 if (ret)
Ben Skeggsebb945a2012-07-20 08:17:34 +1000180 nv84_fence_destroy(drm);
Ben Skeggs5e120f62012-04-30 13:55:29 +1000181 return ret;
182}