Home | History | Annotate | Line # | Download | only in nouveau
nouveau_nv17_fence.c revision 1.1.1.1.2.2
      1 /*	$NetBSD: nouveau_nv17_fence.c,v 1.1.1.1.2.2 2014/08/10 06:55:30 tls 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 <bskeggs (at) redhat.com>
     25  */
     26 
     27 #include <sys/cdefs.h>
     28 __KERNEL_RCSID(0, "$NetBSD: nouveau_nv17_fence.c,v 1.1.1.1.2.2 2014/08/10 06:55:30 tls Exp $");
     29 
     30 #include <core/object.h>
     31 #include <core/class.h>
     32 
     33 #include "nouveau_drm.h"
     34 #include "nouveau_dma.h"
     35 #include "nv10_fence.h"
     36 
     37 int
     38 nv17_fence_sync(struct nouveau_fence *fence,
     39 		struct nouveau_channel *prev, struct nouveau_channel *chan)
     40 {
     41 	struct nv10_fence_priv *priv = chan->drm->fence;
     42 	u32 value;
     43 	int ret;
     44 
     45 	if (!mutex_trylock(&prev->cli->mutex))
     46 		return -EBUSY;
     47 
     48 	spin_lock(&priv->lock);
     49 	value = priv->sequence;
     50 	priv->sequence += 2;
     51 	spin_unlock(&priv->lock);
     52 
     53 	ret = RING_SPACE(prev, 5);
     54 	if (!ret) {
     55 		BEGIN_NV04(prev, 0, NV11_SUBCHAN_DMA_SEMAPHORE, 4);
     56 		OUT_RING  (prev, NvSema);
     57 		OUT_RING  (prev, 0);
     58 		OUT_RING  (prev, value + 0);
     59 		OUT_RING  (prev, value + 1);
     60 		FIRE_RING (prev);
     61 	}
     62 
     63 	if (!ret && !(ret = RING_SPACE(chan, 5))) {
     64 		BEGIN_NV04(chan, 0, NV11_SUBCHAN_DMA_SEMAPHORE, 4);
     65 		OUT_RING  (chan, NvSema);
     66 		OUT_RING  (chan, 0);
     67 		OUT_RING  (chan, value + 1);
     68 		OUT_RING  (chan, value + 2);
     69 		FIRE_RING (chan);
     70 	}
     71 
     72 	mutex_unlock(&prev->cli->mutex);
     73 	return 0;
     74 }
     75 
     76 static int
     77 nv17_fence_context_new(struct nouveau_channel *chan)
     78 {
     79 	struct nv10_fence_priv *priv = chan->drm->fence;
     80 	struct nv10_fence_chan *fctx;
     81 	struct ttm_mem_reg *mem = &priv->bo->bo.mem;
     82 	struct nouveau_object *object;
     83 	u32 start = mem->start * PAGE_SIZE;
     84 	u32 limit = start + mem->size - 1;
     85 	int ret = 0;
     86 
     87 	fctx = chan->fence = kzalloc(sizeof(*fctx), GFP_KERNEL);
     88 	if (!fctx)
     89 		return -ENOMEM;
     90 
     91 	nouveau_fence_context_new(&fctx->base);
     92 	fctx->base.emit = nv10_fence_emit;
     93 	fctx->base.read = nv10_fence_read;
     94 	fctx->base.sync = nv17_fence_sync;
     95 
     96 	ret = nouveau_object_new(nv_object(chan->cli), chan->handle,
     97 				 NvSema, 0x0002,
     98 				 &(struct nv_dma_class) {
     99 					.flags = NV_DMA_TARGET_VRAM |
    100 						 NV_DMA_ACCESS_RDWR,
    101 					.start = start,
    102 					.limit = limit,
    103 				 }, sizeof(struct nv_dma_class),
    104 				 &object);
    105 	if (ret)
    106 		nv10_fence_context_del(chan);
    107 	return ret;
    108 }
    109 
    110 void
    111 nv17_fence_resume(struct nouveau_drm *drm)
    112 {
    113 	struct nv10_fence_priv *priv = drm->fence;
    114 
    115 	nouveau_bo_wr32(priv->bo, 0, priv->sequence);
    116 }
    117 
    118 int
    119 nv17_fence_create(struct nouveau_drm *drm)
    120 {
    121 	struct nv10_fence_priv *priv;
    122 	int ret = 0;
    123 
    124 	priv = drm->fence = kzalloc(sizeof(*priv), GFP_KERNEL);
    125 	if (!priv)
    126 		return -ENOMEM;
    127 
    128 	priv->base.dtor = nv10_fence_destroy;
    129 	priv->base.resume = nv17_fence_resume;
    130 	priv->base.context_new = nv17_fence_context_new;
    131 	priv->base.context_del = nv10_fence_context_del;
    132 	spin_lock_init(&priv->lock);
    133 
    134 	ret = nouveau_bo_new(drm->dev, 4096, 0x1000, TTM_PL_FLAG_VRAM,
    135 			     0, 0x0000, NULL, &priv->bo);
    136 	if (!ret) {
    137 		ret = nouveau_bo_pin(priv->bo, TTM_PL_FLAG_VRAM);
    138 		if (!ret) {
    139 			ret = nouveau_bo_map(priv->bo);
    140 			if (ret)
    141 				nouveau_bo_unpin(priv->bo);
    142 		}
    143 		if (ret)
    144 			nouveau_bo_ref(NULL, &priv->bo);
    145 	}
    146 
    147 	if (ret) {
    148 		nv10_fence_destroy(drm);
    149 		return ret;
    150 	}
    151 
    152 	nouveau_bo_wr32(priv->bo, 0x000, 0x00000000);
    153 	return ret;
    154 }
    155