xref: /openbmc/linux/drivers/gpu/drm/i915/gem/i915_gemfs.c (revision 6523d3b2)
1 /*
2  * SPDX-License-Identifier: MIT
3  *
4  * Copyright © 2017 Intel Corporation
5  */
6 
7 #include <linux/fs.h>
8 #include <linux/mount.h>
9 
10 #include "i915_drv.h"
11 #include "i915_gemfs.h"
12 
13 int i915_gemfs_init(struct drm_i915_private *i915)
14 {
15 	char huge_opt[] = "huge=within_size"; /* r/w */
16 	struct file_system_type *type;
17 	struct vfsmount *gemfs;
18 	char *opts;
19 
20 	type = get_fs_type("tmpfs");
21 	if (!type)
22 		return -ENODEV;
23 
24 	/*
25 	 * By creating our own shmemfs mountpoint, we can pass in
26 	 * mount flags that better match our usecase.
27 	 *
28 	 * One example, although it is probably better with a per-file
29 	 * control, is selecting huge page allocations ("huge=within_size").
30 	 * However, we only do so to offset the overhead of iommu lookups
31 	 * due to bandwidth issues (slow reads) on Broadwell+.
32 	 */
33 
34 	opts = NULL;
35 	if (intel_vtd_active(i915)) {
36 		if (IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE)) {
37 			opts = huge_opt;
38 			drm_info(&i915->drm,
39 				 "Transparent Hugepage mode '%s'\n",
40 				 opts);
41 		} else {
42 			drm_notice(&i915->drm,
43 				   "Transparent Hugepage support is recommended for optimal performance when IOMMU is enabled!\n");
44 		}
45 	}
46 
47 	gemfs = vfs_kern_mount(type, SB_KERNMOUNT, type->name, opts);
48 	if (IS_ERR(gemfs))
49 		return PTR_ERR(gemfs);
50 
51 	i915->mm.gemfs = gemfs;
52 
53 	return 0;
54 }
55 
56 void i915_gemfs_fini(struct drm_i915_private *i915)
57 {
58 	kern_unmount(i915->mm.gemfs);
59 }
60