Home | History | Annotate | Line # | Download | only in nouveau
      1  1.1  riastrad /*	$NetBSD: nouveau_nv50_fence.c,v 1.3 2021/12/18 23:45:32 riastradh Exp $	*/
      2  1.1  riastrad 
      3  1.1  riastrad /*
      4  1.1  riastrad  * Copyright 2012 Red Hat Inc.
      5  1.1  riastrad  *
      6  1.1  riastrad  * Permission is hereby granted, free of charge, to any person obtaining a
      7  1.1  riastrad  * copy of this software and associated documentation files (the "Software"),
      8  1.1  riastrad  * to deal in the Software without restriction, including without limitation
      9  1.1  riastrad  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
     10  1.1  riastrad  * and/or sell copies of the Software, and to permit persons to whom the
     11  1.1  riastrad  * Software is furnished to do so, subject to the following conditions:
     12  1.1  riastrad  *
     13  1.1  riastrad  * The above copyright notice and this permission notice shall be included in
     14  1.1  riastrad  * all copies or substantial portions of the Software.
     15  1.1  riastrad  *
     16  1.1  riastrad  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     17  1.1  riastrad  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     18  1.1  riastrad  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
     19  1.1  riastrad  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
     20  1.1  riastrad  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
     21  1.1  riastrad  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
     22  1.1  riastrad  * OTHER DEALINGS IN THE SOFTWARE.
     23  1.1  riastrad  *
     24  1.1  riastrad  * Authors: Ben Skeggs <bskeggs (at) redhat.com>
     25  1.1  riastrad  */
     26  1.1  riastrad 
     27  1.1  riastrad #include <sys/cdefs.h>
     28  1.1  riastrad __KERNEL_RCSID(0, "$NetBSD: nouveau_nv50_fence.c,v 1.3 2021/12/18 23:45:32 riastradh Exp $");
     29  1.1  riastrad 
     30  1.2  riastrad #include <nvif/os.h>
     31  1.2  riastrad #include <nvif/class.h>
     32  1.3  riastrad #include <nvif/cl0002.h>
     33  1.1  riastrad 
     34  1.3  riastrad #include "nouveau_drv.h"
     35  1.1  riastrad #include "nouveau_dma.h"
     36  1.1  riastrad #include "nv10_fence.h"
     37  1.1  riastrad 
     38  1.1  riastrad #include "nv50_display.h"
     39  1.1  riastrad 
     40  1.1  riastrad static int
     41  1.1  riastrad nv50_fence_context_new(struct nouveau_channel *chan)
     42  1.1  riastrad {
     43  1.1  riastrad 	struct nv10_fence_priv *priv = chan->drm->fence;
     44  1.1  riastrad 	struct nv10_fence_chan *fctx;
     45  1.3  riastrad 	struct ttm_mem_reg *reg = &priv->bo->bo.mem;
     46  1.3  riastrad 	u32 start = reg->start * PAGE_SIZE;
     47  1.3  riastrad 	u32 limit = start + reg->size - 1;
     48  1.3  riastrad 	int ret;
     49  1.1  riastrad 
     50  1.1  riastrad 	fctx = chan->fence = kzalloc(sizeof(*fctx), GFP_KERNEL);
     51  1.1  riastrad 	if (!fctx)
     52  1.1  riastrad 		return -ENOMEM;
     53  1.1  riastrad 
     54  1.2  riastrad 	nouveau_fence_context_new(chan, &fctx->base);
     55  1.1  riastrad 	fctx->base.emit = nv10_fence_emit;
     56  1.1  riastrad 	fctx->base.read = nv10_fence_read;
     57  1.1  riastrad 	fctx->base.sync = nv17_fence_sync;
     58  1.1  riastrad 
     59  1.2  riastrad 	ret = nvif_object_init(&chan->user, NvSema, NV_DMA_IN_MEMORY,
     60  1.2  riastrad 			       &(struct nv_dma_v0) {
     61  1.2  riastrad 					.target = NV_DMA_V0_TARGET_VRAM,
     62  1.2  riastrad 					.access = NV_DMA_V0_ACCESS_RDWR,
     63  1.1  riastrad 					.start = start,
     64  1.1  riastrad 					.limit = limit,
     65  1.2  riastrad 			       }, sizeof(struct nv_dma_v0),
     66  1.2  riastrad 			       &fctx->sema);
     67  1.1  riastrad 	if (ret)
     68  1.1  riastrad 		nv10_fence_context_del(chan);
     69  1.1  riastrad 	return ret;
     70  1.1  riastrad }
     71  1.1  riastrad 
     72  1.1  riastrad int
     73  1.1  riastrad nv50_fence_create(struct nouveau_drm *drm)
     74  1.1  riastrad {
     75  1.1  riastrad 	struct nv10_fence_priv *priv;
     76  1.1  riastrad 	int ret = 0;
     77  1.1  riastrad 
     78  1.1  riastrad 	priv = drm->fence = kzalloc(sizeof(*priv), GFP_KERNEL);
     79  1.1  riastrad 	if (!priv)
     80  1.1  riastrad 		return -ENOMEM;
     81  1.1  riastrad 
     82  1.1  riastrad 	priv->base.dtor = nv10_fence_destroy;
     83  1.1  riastrad 	priv->base.resume = nv17_fence_resume;
     84  1.1  riastrad 	priv->base.context_new = nv50_fence_context_new;
     85  1.1  riastrad 	priv->base.context_del = nv10_fence_context_del;
     86  1.1  riastrad 	spin_lock_init(&priv->lock);
     87  1.1  riastrad 
     88  1.3  riastrad 	ret = nouveau_bo_new(&drm->client, 4096, 0x1000, TTM_PL_FLAG_VRAM,
     89  1.2  riastrad 			     0, 0x0000, NULL, NULL, &priv->bo);
     90  1.1  riastrad 	if (!ret) {
     91  1.2  riastrad 		ret = nouveau_bo_pin(priv->bo, TTM_PL_FLAG_VRAM, false);
     92  1.1  riastrad 		if (!ret) {
     93  1.1  riastrad 			ret = nouveau_bo_map(priv->bo);
     94  1.1  riastrad 			if (ret)
     95  1.1  riastrad 				nouveau_bo_unpin(priv->bo);
     96  1.1  riastrad 		}
     97  1.1  riastrad 		if (ret)
     98  1.1  riastrad 			nouveau_bo_ref(NULL, &priv->bo);
     99  1.1  riastrad 	}
    100  1.1  riastrad 
    101  1.1  riastrad 	if (ret) {
    102  1.1  riastrad 		nv10_fence_destroy(drm);
    103  1.1  riastrad 		return ret;
    104  1.1  riastrad 	}
    105  1.1  riastrad 
    106  1.1  riastrad 	nouveau_bo_wr32(priv->bo, 0x000, 0x00000000);
    107  1.1  riastrad 	return ret;
    108  1.1  riastrad }
    109