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/class.h> |
| 27 | |
Ben Skeggs | 02a841d | 2012-07-04 23:44:54 +1000 | [diff] [blame] | 28 | #include <engine/fifo.h> |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 29 | |
| 30 | #include "nouveau_drm.h" |
| 31 | #include "nouveau_dma.h" |
Ben Skeggs | 5e120f6 | 2012-04-30 13:55:29 +1000 | [diff] [blame] | 32 | #include "nouveau_fence.h" |
| 33 | |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 34 | #include "nv50_display.h" |
| 35 | |
Ben Skeggs | 5e120f6 | 2012-04-30 13:55:29 +1000 | [diff] [blame] | 36 | struct nv84_fence_chan { |
| 37 | struct nouveau_fence_chan base; |
| 38 | }; |
| 39 | |
| 40 | struct nv84_fence_priv { |
| 41 | struct nouveau_fence_priv base; |
| 42 | struct nouveau_gpuobj *mem; |
| 43 | }; |
| 44 | |
| 45 | static int |
| 46 | nv84_fence_emit(struct nouveau_fence *fence) |
| 47 | { |
| 48 | struct nouveau_channel *chan = fence->channel; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 49 | struct nouveau_fifo_chan *fifo = (void *)chan->object; |
Ben Skeggs | 5e120f6 | 2012-04-30 13:55:29 +1000 | [diff] [blame] | 50 | 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 Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 55 | OUT_RING (chan, upper_32_bits(fifo->chid * 16)); |
| 56 | OUT_RING (chan, lower_32_bits(fifo->chid * 16)); |
Ben Skeggs | 5e120f6 | 2012-04-30 13:55:29 +1000 | [diff] [blame] | 57 | 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 Skeggs | 906c033 | 2012-05-04 16:25:47 +1000 | [diff] [blame] | 64 | |
Ben Skeggs | 5e120f6 | 2012-04-30 13:55:29 +1000 | [diff] [blame] | 65 | static int |
Ben Skeggs | 906c033 | 2012-05-04 16:25:47 +1000 | [diff] [blame] | 66 | nv84_fence_sync(struct nouveau_fence *fence, |
| 67 | struct nouveau_channel *prev, struct nouveau_channel *chan) |
Ben Skeggs | 5e120f6 | 2012-04-30 13:55:29 +1000 | [diff] [blame] | 68 | { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 69 | struct nouveau_fifo_chan *fifo = (void *)prev->object; |
Ben Skeggs | 5e120f6 | 2012-04-30 13:55:29 +1000 | [diff] [blame] | 70 | 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 Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 75 | OUT_RING (chan, upper_32_bits(fifo->chid * 16)); |
| 76 | OUT_RING (chan, lower_32_bits(fifo->chid * 16)); |
Ben Skeggs | 5e120f6 | 2012-04-30 13:55:29 +1000 | [diff] [blame] | 77 | 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 | |
| 84 | static u32 |
| 85 | nv84_fence_read(struct nouveau_channel *chan) |
| 86 | { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 87 | 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 Skeggs | 5e120f6 | 2012-04-30 13:55:29 +1000 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | static void |
Ben Skeggs | e193b1d | 2012-07-19 10:51:42 +1000 | [diff] [blame] | 93 | nv84_fence_context_del(struct nouveau_channel *chan) |
Ben Skeggs | 5e120f6 | 2012-04-30 13:55:29 +1000 | [diff] [blame] | 94 | { |
Ben Skeggs | e193b1d | 2012-07-19 10:51:42 +1000 | [diff] [blame] | 95 | struct nv84_fence_chan *fctx = chan->fence; |
Ben Skeggs | 5e120f6 | 2012-04-30 13:55:29 +1000 | [diff] [blame] | 96 | nouveau_fence_context_del(&fctx->base); |
Ben Skeggs | e193b1d | 2012-07-19 10:51:42 +1000 | [diff] [blame] | 97 | chan->fence = NULL; |
Ben Skeggs | 5e120f6 | 2012-04-30 13:55:29 +1000 | [diff] [blame] | 98 | kfree(fctx); |
| 99 | } |
| 100 | |
| 101 | static int |
Ben Skeggs | e193b1d | 2012-07-19 10:51:42 +1000 | [diff] [blame] | 102 | nv84_fence_context_new(struct nouveau_channel *chan) |
Ben Skeggs | 5e120f6 | 2012-04-30 13:55:29 +1000 | [diff] [blame] | 103 | { |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 104 | struct drm_device *dev = chan->drm->dev; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 105 | struct nouveau_fifo_chan *fifo = (void *)chan->object; |
| 106 | struct nv84_fence_priv *priv = chan->drm->fence; |
Ben Skeggs | 5e120f6 | 2012-04-30 13:55:29 +1000 | [diff] [blame] | 107 | struct nv84_fence_chan *fctx; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 108 | struct nouveau_object *object; |
Ben Skeggs | f589be8 | 2012-07-22 11:55:54 +1000 | [diff] [blame] | 109 | int ret, i; |
Ben Skeggs | 5e120f6 | 2012-04-30 13:55:29 +1000 | [diff] [blame] | 110 | |
Ben Skeggs | e193b1d | 2012-07-19 10:51:42 +1000 | [diff] [blame] | 111 | fctx = chan->fence = kzalloc(sizeof(*fctx), GFP_KERNEL); |
Ben Skeggs | 5e120f6 | 2012-04-30 13:55:29 +1000 | [diff] [blame] | 112 | if (!fctx) |
| 113 | return -ENOMEM; |
| 114 | |
| 115 | nouveau_fence_context_new(&fctx->base); |
| 116 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 117 | 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 Skeggs | 5e120f6 | 2012-04-30 13:55:29 +1000 | [diff] [blame] | 127 | |
Ben Skeggs | f589be8 | 2012-07-22 11:55:54 +1000 | [diff] [blame] | 128 | /* dma objects for display sync channel semaphore blocks */ |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 129 | for (i = 0; !ret && i < dev->mode_config.num_crtc; i++) { |
| 130 | struct nouveau_bo *bo = nv50_display_crtc_sema(dev, i); |
Ben Skeggs | f589be8 | 2012-07-22 11:55:54 +1000 | [diff] [blame] | 131 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 132 | 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 Skeggs | f589be8 | 2012-07-22 11:55:54 +1000 | [diff] [blame] | 141 | } |
| 142 | |
Ben Skeggs | 5e120f6 | 2012-04-30 13:55:29 +1000 | [diff] [blame] | 143 | if (ret) |
Ben Skeggs | e193b1d | 2012-07-19 10:51:42 +1000 | [diff] [blame] | 144 | nv84_fence_context_del(chan); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 145 | nv_wo32(priv->mem, fifo->chid * 16, 0x00000000); |
Ben Skeggs | 5e120f6 | 2012-04-30 13:55:29 +1000 | [diff] [blame] | 146 | return ret; |
| 147 | } |
| 148 | |
Ben Skeggs | 5e120f6 | 2012-04-30 13:55:29 +1000 | [diff] [blame] | 149 | static void |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 150 | nv84_fence_destroy(struct nouveau_drm *drm) |
Ben Skeggs | 5e120f6 | 2012-04-30 13:55:29 +1000 | [diff] [blame] | 151 | { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 152 | struct nv84_fence_priv *priv = drm->fence; |
Ben Skeggs | 5e120f6 | 2012-04-30 13:55:29 +1000 | [diff] [blame] | 153 | nouveau_gpuobj_ref(NULL, &priv->mem); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 154 | drm->fence = NULL; |
Ben Skeggs | 5e120f6 | 2012-04-30 13:55:29 +1000 | [diff] [blame] | 155 | kfree(priv); |
| 156 | } |
| 157 | |
| 158 | int |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 159 | nv84_fence_create(struct nouveau_drm *drm) |
Ben Skeggs | 5e120f6 | 2012-04-30 13:55:29 +1000 | [diff] [blame] | 160 | { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 161 | struct nouveau_fifo *pfifo = nouveau_fifo(drm->device); |
Ben Skeggs | 5e120f6 | 2012-04-30 13:55:29 +1000 | [diff] [blame] | 162 | struct nv84_fence_priv *priv; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 163 | u32 chan = pfifo->max + 1; |
Ben Skeggs | 5e120f6 | 2012-04-30 13:55:29 +1000 | [diff] [blame] | 164 | int ret; |
| 165 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 166 | priv = drm->fence = kzalloc(sizeof(*priv), GFP_KERNEL); |
Ben Skeggs | 5e120f6 | 2012-04-30 13:55:29 +1000 | [diff] [blame] | 167 | if (!priv) |
| 168 | return -ENOMEM; |
| 169 | |
Ben Skeggs | e193b1d | 2012-07-19 10:51:42 +1000 | [diff] [blame] | 170 | 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 Skeggs | 5e120f6 | 2012-04-30 13:55:29 +1000 | [diff] [blame] | 173 | priv->base.emit = nv84_fence_emit; |
| 174 | priv->base.sync = nv84_fence_sync; |
| 175 | priv->base.read = nv84_fence_read; |
Ben Skeggs | 5e120f6 | 2012-04-30 13:55:29 +1000 | [diff] [blame] | 176 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 177 | ret = nouveau_gpuobj_new(drm->device, NULL, chan * 16, 0x1000, 0, |
| 178 | &priv->mem); |
Ben Skeggs | 5e120f6 | 2012-04-30 13:55:29 +1000 | [diff] [blame] | 179 | if (ret) |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 180 | nv84_fence_destroy(drm); |
Ben Skeggs | 5e120f6 | 2012-04-30 13:55:29 +1000 | [diff] [blame] | 181 | return ret; |
| 182 | } |