xref: /linux/drivers/gpu/drm/v3d/v3d_gemfs.c (revision eb8d395f68421449c6201d3019f51011d034f00e)
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 
7 #include "v3d_drv.h"
8 
9 void v3d_gemfs_init(struct v3d_dev *v3d)
10 {
11 	char huge_opt[] = "huge=within_size";
12 	struct file_system_type *type;
13 	struct vfsmount *gemfs;
14 
15 	/*
16 	 * By creating our own shmemfs mountpoint, we can pass in
17 	 * mount flags that better match our usecase. However, we
18 	 * only do so on platforms which benefit from it.
19 	 */
20 	if (!IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE))
21 		goto err;
22 
23 	type = get_fs_type("tmpfs");
24 	if (!type)
25 		goto err;
26 
27 	gemfs = vfs_kern_mount(type, SB_KERNMOUNT, type->name, huge_opt);
28 	if (IS_ERR(gemfs))
29 		goto err;
30 
31 	v3d->gemfs = gemfs;
32 	drm_info(&v3d->drm, "Using Transparent Hugepages\n");
33 
34 	return;
35 
36 err:
37 	v3d->gemfs = NULL;
38 	drm_notice(&v3d->drm,
39 		   "Transparent Hugepage support is recommended for optimal performance on this platform!\n");
40 }
41 
42 void v3d_gemfs_fini(struct v3d_dev *v3d)
43 {
44 	if (v3d->gemfs)
45 		kern_unmount(v3d->gemfs);
46 }
47