1 /*
2  * SPDX-License-Identifier: MIT
3  *
4  * Copyright © 2019 Intel Corporation
5  */
6 
7 #include <drm/drm_file.h>
8 
9 #include "i915_drv.h"
10 #include "igt_mmap.h"
11 
12 unsigned long igt_mmap_node(struct drm_i915_private *i915,
13 			    struct drm_vma_offset_node *node,
14 			    unsigned long addr,
15 			    unsigned long prot,
16 			    unsigned long flags)
17 {
18 	struct file *file;
19 	int err;
20 
21 	/* Pretend to open("/dev/dri/card0") */
22 	file = mock_drm_getfile(i915->drm.primary, O_RDWR);
23 	if (IS_ERR(file))
24 		return PTR_ERR(file);
25 
26 	err = drm_vma_node_allow(node, file->private_data);
27 	if (err) {
28 		addr = err;
29 		goto out_file;
30 	}
31 
32 	addr = vm_mmap(file, addr, drm_vma_node_size(node) << PAGE_SHIFT,
33 		       prot, flags, drm_vma_node_offset_addr(node));
34 
35 	drm_vma_node_revoke(node, file->private_data);
36 out_file:
37 	fput(file);
38 	return addr;
39 }
40