xref: /linux/drivers/gpu/drm/v3d/v3d_gemfs.c (revision 7f71507851fc7764b36a3221839607d3a45c2025)
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 	/* The user doesn't want to enable Super Pages */
24 	if (!super_pages)
25 		goto err;
26 
27 	type = get_fs_type("tmpfs");
28 	if (!type)
29 		goto err;
30 
31 	gemfs = vfs_kern_mount(type, SB_KERNMOUNT, type->name, huge_opt);
32 	if (IS_ERR(gemfs))
33 		goto err;
34 
35 	v3d->gemfs = gemfs;
36 	drm_info(&v3d->drm, "Using Transparent Hugepages\n");
37 
38 	return;
39 
40 err:
41 	v3d->gemfs = NULL;
42 	drm_notice(&v3d->drm,
43 		   "Transparent Hugepage support is recommended for optimal performance on this platform!\n");
44 }
45 
46 void v3d_gemfs_fini(struct v3d_dev *v3d)
47 {
48 	if (v3d->gemfs)
49 		kern_unmount(v3d->gemfs);
50 }
51