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