1 // SPDX-License-Identifier: GPL-2.0+
2 /* Copyright (C) 2024 Raspberry Pi */
3
4 #include <linux/fs.h>
5 #include <linux/mount.h>
6 #include <linux/fs_context.h>
7
8 #include "v3d_drv.h"
9
add_param(struct fs_context * fc,const char * key,const char * val)10 static int add_param(struct fs_context *fc, const char *key, const char *val)
11 {
12 return vfs_parse_fs_string(fc, key, val, strlen(val));
13 }
14
v3d_gemfs_init(struct v3d_dev * v3d)15 void v3d_gemfs_init(struct v3d_dev *v3d)
16 {
17 struct file_system_type *type;
18 struct fs_context *fc;
19 struct vfsmount *gemfs;
20 int ret;
21
22 /*
23 * By creating our own shmemfs mountpoint, we can pass in
24 * mount flags that better match our usecase. However, we
25 * only do so on platforms which benefit from it.
26 */
27 if (!IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE))
28 goto err;
29
30 /* The user doesn't want to enable Super Pages */
31 if (!super_pages)
32 goto err;
33
34 type = get_fs_type("tmpfs");
35 if (!type)
36 goto err;
37
38 fc = fs_context_for_mount(type, SB_KERNMOUNT);
39 if (IS_ERR(fc))
40 goto err;
41 ret = add_param(fc, "source", "tmpfs");
42 if (!ret)
43 ret = add_param(fc, "huge", "within_size");
44 if (!ret)
45 gemfs = fc_mount_longterm(fc);
46 put_fs_context(fc);
47 if (ret)
48 goto err;
49
50 v3d->gemfs = gemfs;
51 drm_info(&v3d->drm, "Using Transparent Hugepages\n");
52
53 return;
54
55 err:
56 v3d->gemfs = NULL;
57 drm_notice(&v3d->drm,
58 "Transparent Hugepage support is recommended for optimal performance on this platform!\n");
59 }
60
v3d_gemfs_fini(struct v3d_dev * v3d)61 void v3d_gemfs_fini(struct v3d_dev *v3d)
62 {
63 if (v3d->gemfs)
64 kern_unmount(v3d->gemfs);
65 }
66