Home | History | Annotate | Line # | Download | only in selftests
      1  1.1  riastrad /*	$NetBSD: igt_mmap.c,v 1.2 2021/12/18 23:45:31 riastradh Exp $	*/
      2  1.1  riastrad 
      3  1.1  riastrad /*
      4  1.1  riastrad  * SPDX-License-Identifier: MIT
      5  1.1  riastrad  *
      6  1.1  riastrad  * Copyright  2019 Intel Corporation
      7  1.1  riastrad  */
      8  1.1  riastrad 
      9  1.1  riastrad #include <sys/cdefs.h>
     10  1.1  riastrad __KERNEL_RCSID(0, "$NetBSD: igt_mmap.c,v 1.2 2021/12/18 23:45:31 riastradh Exp $");
     11  1.1  riastrad 
     12  1.1  riastrad #include <drm/drm_file.h>
     13  1.1  riastrad 
     14  1.1  riastrad #include "i915_drv.h"
     15  1.1  riastrad #include "igt_mmap.h"
     16  1.1  riastrad 
     17  1.1  riastrad unsigned long igt_mmap_node(struct drm_i915_private *i915,
     18  1.1  riastrad 			    struct drm_vma_offset_node *node,
     19  1.1  riastrad 			    unsigned long addr,
     20  1.1  riastrad 			    unsigned long prot,
     21  1.1  riastrad 			    unsigned long flags)
     22  1.1  riastrad {
     23  1.1  riastrad 	struct file *file;
     24  1.1  riastrad 	int err;
     25  1.1  riastrad 
     26  1.1  riastrad 	/* Pretend to open("/dev/dri/card0") */
     27  1.1  riastrad 	file = mock_drm_getfile(i915->drm.primary, O_RDWR);
     28  1.1  riastrad 	if (IS_ERR(file))
     29  1.1  riastrad 		return PTR_ERR(file);
     30  1.1  riastrad 
     31  1.1  riastrad 	err = drm_vma_node_allow(node, file->private_data);
     32  1.1  riastrad 	if (err) {
     33  1.1  riastrad 		addr = err;
     34  1.1  riastrad 		goto out_file;
     35  1.1  riastrad 	}
     36  1.1  riastrad 
     37  1.1  riastrad 	addr = vm_mmap(file, addr, drm_vma_node_size(node) << PAGE_SHIFT,
     38  1.1  riastrad 		       prot, flags, drm_vma_node_offset_addr(node));
     39  1.1  riastrad 
     40  1.1  riastrad 	drm_vma_node_revoke(node, file->private_data);
     41  1.1  riastrad out_file:
     42  1.1  riastrad 	fput(file);
     43  1.1  riastrad 	return addr;
     44  1.1  riastrad }
     45