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