Home | History | Annotate | Line # | Download | only in vmwgfx
      1  1.2  riastrad /*	$NetBSD: vmwgfx_ttm_glue.c,v 1.3 2021/12/18 23:45:45 riastradh Exp $	*/
      2  1.2  riastrad 
      3  1.3  riastrad // SPDX-License-Identifier: GPL-2.0 OR MIT
      4  1.1  riastrad /**************************************************************************
      5  1.1  riastrad  *
      6  1.3  riastrad  * Copyright 2009-2011 VMware, Inc., Palo Alto, CA., USA
      7  1.1  riastrad  *
      8  1.1  riastrad  * Permission is hereby granted, free of charge, to any person obtaining a
      9  1.1  riastrad  * copy of this software and associated documentation files (the
     10  1.1  riastrad  * "Software"), to deal in the Software without restriction, including
     11  1.1  riastrad  * without limitation the rights to use, copy, modify, merge, publish,
     12  1.1  riastrad  * distribute, sub license, and/or sell copies of the Software, and to
     13  1.1  riastrad  * permit persons to whom the Software is furnished to do so, subject to
     14  1.1  riastrad  * the following conditions:
     15  1.1  riastrad  *
     16  1.1  riastrad  * The above copyright notice and this permission notice (including the
     17  1.1  riastrad  * next paragraph) shall be included in all copies or substantial portions
     18  1.1  riastrad  * of the Software.
     19  1.1  riastrad  *
     20  1.1  riastrad  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     21  1.1  riastrad  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     22  1.1  riastrad  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
     23  1.1  riastrad  * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
     24  1.1  riastrad  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
     25  1.1  riastrad  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
     26  1.1  riastrad  * USE OR OTHER DEALINGS IN THE SOFTWARE.
     27  1.1  riastrad  *
     28  1.1  riastrad  **************************************************************************/
     29  1.1  riastrad 
     30  1.2  riastrad #include <sys/cdefs.h>
     31  1.2  riastrad __KERNEL_RCSID(0, "$NetBSD: vmwgfx_ttm_glue.c,v 1.3 2021/12/18 23:45:45 riastradh Exp $");
     32  1.2  riastrad 
     33  1.1  riastrad #include "vmwgfx_drv.h"
     34  1.1  riastrad 
     35  1.1  riastrad int vmw_mmap(struct file *filp, struct vm_area_struct *vma)
     36  1.1  riastrad {
     37  1.3  riastrad 	static const struct vm_operations_struct vmw_vm_ops = {
     38  1.3  riastrad 		.pfn_mkwrite = vmw_bo_vm_mkwrite,
     39  1.3  riastrad 		.page_mkwrite = vmw_bo_vm_mkwrite,
     40  1.3  riastrad 		.fault = vmw_bo_vm_fault,
     41  1.3  riastrad 		.open = ttm_bo_vm_open,
     42  1.3  riastrad 		.close = ttm_bo_vm_close
     43  1.3  riastrad 	};
     44  1.3  riastrad 	struct drm_file *file_priv = filp->private_data;
     45  1.3  riastrad 	struct vmw_private *dev_priv = vmw_priv(file_priv->minor->dev);
     46  1.3  riastrad 	int ret = ttm_bo_mmap(filp, vma, &dev_priv->bdev);
     47  1.1  riastrad 
     48  1.3  riastrad 	if (ret)
     49  1.3  riastrad 		return ret;
     50  1.3  riastrad 
     51  1.3  riastrad 	vma->vm_ops = &vmw_vm_ops;
     52  1.3  riastrad 
     53  1.3  riastrad 	/* Use VM_PFNMAP rather than VM_MIXEDMAP if not a COW mapping */
     54  1.3  riastrad 	if ((vma->vm_flags & (VM_SHARED | VM_MAYWRITE)) != VM_MAYWRITE)
     55  1.3  riastrad 		vma->vm_flags = (vma->vm_flags & ~VM_MIXEDMAP) | VM_PFNMAP;
     56  1.3  riastrad 
     57  1.3  riastrad 	return 0;
     58  1.1  riastrad }
     59  1.1  riastrad 
     60  1.3  riastrad /* struct vmw_validation_mem callback */
     61  1.3  riastrad static int vmw_vmt_reserve(struct vmw_validation_mem *m, size_t size)
     62  1.1  riastrad {
     63  1.3  riastrad 	static struct ttm_operation_ctx ctx = {.interruptible = false,
     64  1.3  riastrad 					       .no_wait_gpu = false};
     65  1.3  riastrad 	struct vmw_private *dev_priv = container_of(m, struct vmw_private, vvm);
     66  1.1  riastrad 
     67  1.3  riastrad 	return ttm_mem_global_alloc(vmw_mem_glob(dev_priv), size, &ctx);
     68  1.1  riastrad }
     69  1.1  riastrad 
     70  1.3  riastrad /* struct vmw_validation_mem callback */
     71  1.3  riastrad static void vmw_vmt_unreserve(struct vmw_validation_mem *m, size_t size)
     72  1.1  riastrad {
     73  1.3  riastrad 	struct vmw_private *dev_priv = container_of(m, struct vmw_private, vvm);
     74  1.1  riastrad 
     75  1.3  riastrad 	return ttm_mem_global_free(vmw_mem_glob(dev_priv), size);
     76  1.1  riastrad }
     77  1.1  riastrad 
     78  1.3  riastrad /**
     79  1.3  riastrad  * vmw_validation_mem_init_ttm - Interface the validation memory tracker
     80  1.3  riastrad  * to ttm.
     81  1.3  riastrad  * @dev_priv: Pointer to struct vmw_private. The reason we choose a vmw private
     82  1.3  riastrad  * rather than a struct vmw_validation_mem is to make sure assumption in the
     83  1.3  riastrad  * callbacks that struct vmw_private derives from struct vmw_validation_mem
     84  1.3  riastrad  * holds true.
     85  1.3  riastrad  * @gran: The recommended allocation granularity
     86  1.3  riastrad  */
     87  1.3  riastrad void vmw_validation_mem_init_ttm(struct vmw_private *dev_priv, size_t gran)
     88  1.1  riastrad {
     89  1.3  riastrad 	struct vmw_validation_mem *vvm = &dev_priv->vvm;
     90  1.3  riastrad 
     91  1.3  riastrad 	vvm->reserve_mem = vmw_vmt_reserve;
     92  1.3  riastrad 	vvm->unreserve_mem = vmw_vmt_unreserve;
     93  1.3  riastrad 	vvm->gran = gran;
     94  1.1  riastrad }
     95