1 /* $NetBSD: nouveau_nvc0_fence.c,v 1.1.1.1 2014/08/06 12:36:23 riastradh Exp $ */ 2 3 /* 4 * Copyright 2012 Red Hat Inc. 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a 7 * copy of this software and associated documentation files (the "Software"), 8 * to deal in the Software without restriction, including without limitation 9 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 * and/or sell copies of the Software, and to permit persons to whom the 11 * Software is furnished to do so, subject to the following conditions: 12 * 13 * The above copyright notice and this permission notice shall be included in 14 * all copies or substantial portions of the Software. 15 * 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 * OTHER DEALINGS IN THE SOFTWARE. 23 * 24 * Authors: Ben Skeggs 25 */ 26 27 #include <sys/cdefs.h> 28 __KERNEL_RCSID(0, "$NetBSD: nouveau_nvc0_fence.c,v 1.1.1.1 2014/08/06 12:36:23 riastradh Exp $"); 29 30 #include <core/object.h> 31 #include <core/client.h> 32 #include <core/class.h> 33 34 #include <engine/fifo.h> 35 36 #include "nouveau_drm.h" 37 #include "nouveau_dma.h" 38 #include "nouveau_fence.h" 39 40 #include "nv50_display.h" 41 42 static int 43 nvc0_fence_emit32(struct nouveau_channel *chan, u64 virtual, u32 sequence) 44 { 45 int ret = RING_SPACE(chan, 6); 46 if (ret == 0) { 47 BEGIN_NVC0(chan, 0, NV84_SUBCHAN_SEMAPHORE_ADDRESS_HIGH, 5); 48 OUT_RING (chan, upper_32_bits(virtual)); 49 OUT_RING (chan, lower_32_bits(virtual)); 50 OUT_RING (chan, sequence); 51 OUT_RING (chan, NV84_SUBCHAN_SEMAPHORE_TRIGGER_WRITE_LONG); 52 OUT_RING (chan, 0x00000000); 53 FIRE_RING (chan); 54 } 55 return ret; 56 } 57 58 static int 59 nvc0_fence_sync32(struct nouveau_channel *chan, u64 virtual, u32 sequence) 60 { 61 int ret = RING_SPACE(chan, 5); 62 if (ret == 0) { 63 BEGIN_NVC0(chan, 0, NV84_SUBCHAN_SEMAPHORE_ADDRESS_HIGH, 4); 64 OUT_RING (chan, upper_32_bits(virtual)); 65 OUT_RING (chan, lower_32_bits(virtual)); 66 OUT_RING (chan, sequence); 67 OUT_RING (chan, NV84_SUBCHAN_SEMAPHORE_TRIGGER_ACQUIRE_GEQUAL | 68 NVC0_SUBCHAN_SEMAPHORE_TRIGGER_YIELD); 69 FIRE_RING (chan); 70 } 71 return ret; 72 } 73 74 static int 75 nvc0_fence_context_new(struct nouveau_channel *chan) 76 { 77 int ret = nv84_fence_context_new(chan); 78 if (ret == 0) { 79 struct nv84_fence_chan *fctx = chan->fence; 80 fctx->base.emit32 = nvc0_fence_emit32; 81 fctx->base.sync32 = nvc0_fence_sync32; 82 } 83 return ret; 84 } 85 86 int 87 nvc0_fence_create(struct nouveau_drm *drm) 88 { 89 int ret = nv84_fence_create(drm); 90 if (ret == 0) { 91 struct nv84_fence_priv *priv = drm->fence; 92 priv->base.context_new = nvc0_fence_context_new; 93 } 94 return ret; 95 } 96