Ben Skeggs | 5e120f6 | 2012-04-30 13:55:29 +1000 | [diff] [blame] | 1 | /* |
| 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 Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 25 | #include <core/object.h> |
| 26 | #include <core/client.h> |
| 27 | #include <core/class.h> |
| 28 | |
Ben Skeggs | 02a841d | 2012-07-04 23:44:54 +1000 | [diff] [blame] | 29 | #include <engine/fifo.h> |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 30 | |
| 31 | #include "nouveau_drm.h" |
| 32 | #include "nouveau_dma.h" |
Ben Skeggs | 5e120f6 | 2012-04-30 13:55:29 +1000 | [diff] [blame] | 33 | #include "nouveau_fence.h" |
| 34 | |
| 35 | struct nvc0_fence_priv { |
| 36 | struct nouveau_fence_priv base; |
| 37 | struct nouveau_bo *bo; |
Ben Skeggs | d6ba6d2 | 2012-09-28 11:50:29 +1000 | [diff] [blame] | 38 | u32 *suspend; |
Ben Skeggs | 5e120f6 | 2012-04-30 13:55:29 +1000 | [diff] [blame] | 39 | }; |
| 40 | |
| 41 | struct nvc0_fence_chan { |
| 42 | struct nouveau_fence_chan base; |
| 43 | struct nouveau_vma vma; |
Ben Skeggs | f589be8 | 2012-07-22 11:55:54 +1000 | [diff] [blame] | 44 | struct nouveau_vma dispc_vma[4]; |
Ben Skeggs | 5e120f6 | 2012-04-30 13:55:29 +1000 | [diff] [blame] | 45 | }; |
| 46 | |
Ben Skeggs | f589be8 | 2012-07-22 11:55:54 +1000 | [diff] [blame] | 47 | u64 |
| 48 | nvc0_fence_crtc(struct nouveau_channel *chan, int crtc) |
| 49 | { |
| 50 | struct nvc0_fence_chan *fctx = chan->fence; |
| 51 | return fctx->dispc_vma[crtc].offset; |
| 52 | } |
| 53 | |
Ben Skeggs | 5e120f6 | 2012-04-30 13:55:29 +1000 | [diff] [blame] | 54 | static int |
| 55 | nvc0_fence_emit(struct nouveau_fence *fence) |
| 56 | { |
| 57 | struct nouveau_channel *chan = fence->channel; |
Ben Skeggs | e193b1d | 2012-07-19 10:51:42 +1000 | [diff] [blame] | 58 | struct nvc0_fence_chan *fctx = chan->fence; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 59 | struct nouveau_fifo_chan *fifo = (void *)chan->object; |
| 60 | u64 addr = fctx->vma.offset + fifo->chid * 16; |
Ben Skeggs | 5e120f6 | 2012-04-30 13:55:29 +1000 | [diff] [blame] | 61 | int ret; |
| 62 | |
| 63 | ret = RING_SPACE(chan, 5); |
| 64 | if (ret == 0) { |
| 65 | BEGIN_NVC0(chan, 0, NV84_SUBCHAN_SEMAPHORE_ADDRESS_HIGH, 4); |
| 66 | OUT_RING (chan, upper_32_bits(addr)); |
| 67 | OUT_RING (chan, lower_32_bits(addr)); |
| 68 | OUT_RING (chan, fence->sequence); |
| 69 | OUT_RING (chan, NV84_SUBCHAN_SEMAPHORE_TRIGGER_WRITE_LONG); |
| 70 | FIRE_RING (chan); |
| 71 | } |
| 72 | |
| 73 | return ret; |
| 74 | } |
| 75 | |
| 76 | static int |
Ben Skeggs | 906c033 | 2012-05-04 16:25:47 +1000 | [diff] [blame] | 77 | nvc0_fence_sync(struct nouveau_fence *fence, |
| 78 | struct nouveau_channel *prev, struct nouveau_channel *chan) |
Ben Skeggs | 5e120f6 | 2012-04-30 13:55:29 +1000 | [diff] [blame] | 79 | { |
Ben Skeggs | e193b1d | 2012-07-19 10:51:42 +1000 | [diff] [blame] | 80 | struct nvc0_fence_chan *fctx = chan->fence; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 81 | struct nouveau_fifo_chan *fifo = (void *)prev->object; |
| 82 | u64 addr = fctx->vma.offset + fifo->chid * 16; |
Ben Skeggs | 5e120f6 | 2012-04-30 13:55:29 +1000 | [diff] [blame] | 83 | int ret; |
| 84 | |
| 85 | ret = RING_SPACE(chan, 5); |
| 86 | if (ret == 0) { |
| 87 | BEGIN_NVC0(chan, 0, NV84_SUBCHAN_SEMAPHORE_ADDRESS_HIGH, 4); |
| 88 | OUT_RING (chan, upper_32_bits(addr)); |
| 89 | OUT_RING (chan, lower_32_bits(addr)); |
| 90 | OUT_RING (chan, fence->sequence); |
| 91 | OUT_RING (chan, NV84_SUBCHAN_SEMAPHORE_TRIGGER_ACQUIRE_GEQUAL | |
| 92 | NVC0_SUBCHAN_SEMAPHORE_TRIGGER_YIELD); |
| 93 | FIRE_RING (chan); |
| 94 | } |
| 95 | |
| 96 | return ret; |
| 97 | } |
| 98 | |
| 99 | static u32 |
| 100 | nvc0_fence_read(struct nouveau_channel *chan) |
| 101 | { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 102 | struct nouveau_fifo_chan *fifo = (void *)chan->object; |
| 103 | struct nvc0_fence_priv *priv = chan->drm->fence; |
| 104 | return nouveau_bo_rd32(priv->bo, fifo->chid * 16/4); |
Ben Skeggs | 5e120f6 | 2012-04-30 13:55:29 +1000 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | static void |
Ben Skeggs | e193b1d | 2012-07-19 10:51:42 +1000 | [diff] [blame] | 108 | nvc0_fence_context_del(struct nouveau_channel *chan) |
Ben Skeggs | 5e120f6 | 2012-04-30 13:55:29 +1000 | [diff] [blame] | 109 | { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 110 | struct drm_device *dev = chan->drm->dev; |
| 111 | struct nvc0_fence_priv *priv = chan->drm->fence; |
Ben Skeggs | e193b1d | 2012-07-19 10:51:42 +1000 | [diff] [blame] | 112 | struct nvc0_fence_chan *fctx = chan->fence; |
Ben Skeggs | f589be8 | 2012-07-22 11:55:54 +1000 | [diff] [blame] | 113 | int i; |
| 114 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 115 | if (nv_device(chan->drm->device)->card_type >= NV_D0) { |
Ben Skeggs | f589be8 | 2012-07-22 11:55:54 +1000 | [diff] [blame] | 116 | for (i = 0; i < dev->mode_config.num_crtc; i++) { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 117 | struct nouveau_bo *bo = nvd0sema(dev, i); |
Ben Skeggs | f589be8 | 2012-07-22 11:55:54 +1000 | [diff] [blame] | 118 | nouveau_bo_vma_del(bo, &fctx->dispc_vma[i]); |
| 119 | } |
| 120 | } else |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 121 | if (nv_device(chan->drm->device)->card_type >= NV_50) { |
Ben Skeggs | f589be8 | 2012-07-22 11:55:54 +1000 | [diff] [blame] | 122 | for (i = 0; i < dev->mode_config.num_crtc; i++) { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 123 | struct nouveau_bo *bo = nv50sema(dev, i); |
| 124 | nouveau_bo_vma_del(bo, &fctx->dispc_vma[i]); |
Ben Skeggs | f589be8 | 2012-07-22 11:55:54 +1000 | [diff] [blame] | 125 | } |
| 126 | } |
Ben Skeggs | 5e120f6 | 2012-04-30 13:55:29 +1000 | [diff] [blame] | 127 | |
| 128 | nouveau_bo_vma_del(priv->bo, &fctx->vma); |
| 129 | nouveau_fence_context_del(&fctx->base); |
Ben Skeggs | e193b1d | 2012-07-19 10:51:42 +1000 | [diff] [blame] | 130 | chan->fence = NULL; |
Ben Skeggs | 5e120f6 | 2012-04-30 13:55:29 +1000 | [diff] [blame] | 131 | kfree(fctx); |
| 132 | } |
| 133 | |
| 134 | static int |
Ben Skeggs | e193b1d | 2012-07-19 10:51:42 +1000 | [diff] [blame] | 135 | nvc0_fence_context_new(struct nouveau_channel *chan) |
Ben Skeggs | 5e120f6 | 2012-04-30 13:55:29 +1000 | [diff] [blame] | 136 | { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 137 | struct nouveau_fifo_chan *fifo = (void *)chan->object; |
| 138 | struct nouveau_client *client = nouveau_client(fifo); |
| 139 | struct nvc0_fence_priv *priv = chan->drm->fence; |
Ben Skeggs | 5e120f6 | 2012-04-30 13:55:29 +1000 | [diff] [blame] | 140 | struct nvc0_fence_chan *fctx; |
Ben Skeggs | f589be8 | 2012-07-22 11:55:54 +1000 | [diff] [blame] | 141 | int ret, i; |
Ben Skeggs | 5e120f6 | 2012-04-30 13:55:29 +1000 | [diff] [blame] | 142 | |
Ben Skeggs | e193b1d | 2012-07-19 10:51:42 +1000 | [diff] [blame] | 143 | fctx = chan->fence = kzalloc(sizeof(*fctx), GFP_KERNEL); |
Ben Skeggs | 5e120f6 | 2012-04-30 13:55:29 +1000 | [diff] [blame] | 144 | if (!fctx) |
| 145 | return -ENOMEM; |
| 146 | |
| 147 | nouveau_fence_context_new(&fctx->base); |
| 148 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 149 | ret = nouveau_bo_vma_add(priv->bo, client->vm, &fctx->vma); |
Ben Skeggs | 5e120f6 | 2012-04-30 13:55:29 +1000 | [diff] [blame] | 150 | if (ret) |
Ben Skeggs | e193b1d | 2012-07-19 10:51:42 +1000 | [diff] [blame] | 151 | nvc0_fence_context_del(chan); |
Ben Skeggs | 5e120f6 | 2012-04-30 13:55:29 +1000 | [diff] [blame] | 152 | |
Ben Skeggs | f589be8 | 2012-07-22 11:55:54 +1000 | [diff] [blame] | 153 | /* map display semaphore buffers into channel's vm */ |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 154 | for (i = 0; !ret && i < chan->drm->dev->mode_config.num_crtc; i++) { |
Ben Skeggs | f589be8 | 2012-07-22 11:55:54 +1000 | [diff] [blame] | 155 | struct nouveau_bo *bo; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 156 | if (nv_device(chan->drm->device)->card_type >= NV_D0) |
| 157 | bo = nvd0sema(chan->drm->dev, i); |
Ben Skeggs | f589be8 | 2012-07-22 11:55:54 +1000 | [diff] [blame] | 158 | else |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 159 | bo = nv50sema(chan->drm->dev, i); |
Ben Skeggs | f589be8 | 2012-07-22 11:55:54 +1000 | [diff] [blame] | 160 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 161 | ret = nouveau_bo_vma_add(bo, client->vm, &fctx->dispc_vma[i]); |
Ben Skeggs | f589be8 | 2012-07-22 11:55:54 +1000 | [diff] [blame] | 162 | } |
| 163 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 164 | nouveau_bo_wr32(priv->bo, fifo->chid * 16/4, 0x00000000); |
Ben Skeggs | 5e120f6 | 2012-04-30 13:55:29 +1000 | [diff] [blame] | 165 | return ret; |
| 166 | } |
| 167 | |
Ben Skeggs | e193b1d | 2012-07-19 10:51:42 +1000 | [diff] [blame] | 168 | static bool |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 169 | nvc0_fence_suspend(struct nouveau_drm *drm) |
Ben Skeggs | 5e120f6 | 2012-04-30 13:55:29 +1000 | [diff] [blame] | 170 | { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 171 | struct nouveau_fifo *pfifo = nouveau_fifo(drm->device); |
| 172 | struct nvc0_fence_priv *priv = drm->fence; |
Ben Skeggs | d6ba6d2 | 2012-09-28 11:50:29 +1000 | [diff] [blame] | 173 | int i; |
| 174 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 175 | priv->suspend = vmalloc((pfifo->max + 1) * sizeof(u32)); |
Ben Skeggs | e193b1d | 2012-07-19 10:51:42 +1000 | [diff] [blame] | 176 | if (priv->suspend) { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 177 | for (i = 0; i <= pfifo->max; i++) |
Ben Skeggs | d6ba6d2 | 2012-09-28 11:50:29 +1000 | [diff] [blame] | 178 | priv->suspend[i] = nouveau_bo_rd32(priv->bo, i); |
| 179 | } |
| 180 | |
Ben Skeggs | e193b1d | 2012-07-19 10:51:42 +1000 | [diff] [blame] | 181 | return priv->suspend != NULL; |
Ben Skeggs | 5e120f6 | 2012-04-30 13:55:29 +1000 | [diff] [blame] | 182 | } |
| 183 | |
Ben Skeggs | e193b1d | 2012-07-19 10:51:42 +1000 | [diff] [blame] | 184 | static void |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 185 | nvc0_fence_resume(struct nouveau_drm *drm) |
Ben Skeggs | 5e120f6 | 2012-04-30 13:55:29 +1000 | [diff] [blame] | 186 | { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 187 | struct nouveau_fifo *pfifo = nouveau_fifo(drm->device); |
| 188 | struct nvc0_fence_priv *priv = drm->fence; |
Ben Skeggs | d6ba6d2 | 2012-09-28 11:50:29 +1000 | [diff] [blame] | 189 | int i; |
| 190 | |
| 191 | if (priv->suspend) { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 192 | for (i = 0; i <= pfifo->max; i++) |
Ben Skeggs | d6ba6d2 | 2012-09-28 11:50:29 +1000 | [diff] [blame] | 193 | nouveau_bo_wr32(priv->bo, i, priv->suspend[i]); |
| 194 | vfree(priv->suspend); |
| 195 | priv->suspend = NULL; |
| 196 | } |
Ben Skeggs | 5e120f6 | 2012-04-30 13:55:29 +1000 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | static void |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 200 | nvc0_fence_destroy(struct nouveau_drm *drm) |
Ben Skeggs | 5e120f6 | 2012-04-30 13:55:29 +1000 | [diff] [blame] | 201 | { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 202 | struct nvc0_fence_priv *priv = drm->fence; |
Ben Skeggs | 5e120f6 | 2012-04-30 13:55:29 +1000 | [diff] [blame] | 203 | nouveau_bo_unmap(priv->bo); |
| 204 | nouveau_bo_ref(NULL, &priv->bo); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 205 | drm->fence = NULL; |
Ben Skeggs | 5e120f6 | 2012-04-30 13:55:29 +1000 | [diff] [blame] | 206 | kfree(priv); |
| 207 | } |
| 208 | |
| 209 | int |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 210 | nvc0_fence_create(struct nouveau_drm *drm) |
Ben Skeggs | 5e120f6 | 2012-04-30 13:55:29 +1000 | [diff] [blame] | 211 | { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 212 | struct nouveau_fifo *pfifo = nouveau_fifo(drm->device); |
Ben Skeggs | 5e120f6 | 2012-04-30 13:55:29 +1000 | [diff] [blame] | 213 | struct nvc0_fence_priv *priv; |
| 214 | int ret; |
| 215 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 216 | priv = drm->fence = kzalloc(sizeof(*priv), GFP_KERNEL); |
Ben Skeggs | 5e120f6 | 2012-04-30 13:55:29 +1000 | [diff] [blame] | 217 | if (!priv) |
| 218 | return -ENOMEM; |
| 219 | |
Ben Skeggs | e193b1d | 2012-07-19 10:51:42 +1000 | [diff] [blame] | 220 | priv->base.dtor = nvc0_fence_destroy; |
| 221 | priv->base.suspend = nvc0_fence_suspend; |
| 222 | priv->base.resume = nvc0_fence_resume; |
| 223 | priv->base.context_new = nvc0_fence_context_new; |
| 224 | priv->base.context_del = nvc0_fence_context_del; |
Ben Skeggs | 5e120f6 | 2012-04-30 13:55:29 +1000 | [diff] [blame] | 225 | priv->base.emit = nvc0_fence_emit; |
| 226 | priv->base.sync = nvc0_fence_sync; |
| 227 | priv->base.read = nvc0_fence_read; |
Ben Skeggs | 5e120f6 | 2012-04-30 13:55:29 +1000 | [diff] [blame] | 228 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 229 | ret = nouveau_bo_new(drm->dev, 16 * (pfifo->max + 1), 0, |
| 230 | TTM_PL_FLAG_VRAM, 0, 0, NULL, &priv->bo); |
Ben Skeggs | 5e120f6 | 2012-04-30 13:55:29 +1000 | [diff] [blame] | 231 | if (ret == 0) { |
| 232 | ret = nouveau_bo_pin(priv->bo, TTM_PL_FLAG_VRAM); |
| 233 | if (ret == 0) |
| 234 | ret = nouveau_bo_map(priv->bo); |
| 235 | if (ret) |
| 236 | nouveau_bo_ref(NULL, &priv->bo); |
| 237 | } |
| 238 | |
| 239 | if (ret) |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 240 | nvc0_fence_destroy(drm); |
Ben Skeggs | 5e120f6 | 2012-04-30 13:55:29 +1000 | [diff] [blame] | 241 | return ret; |
| 242 | } |