xref: /linux/drivers/gpu/drm/v3d/v3d_gemfs.c (revision 25768de50b1f2dbb6ea44bd5148a87fe2c9c3688)
1eb8d395fSMaíra Canal // SPDX-License-Identifier: GPL-2.0+
2eb8d395fSMaíra Canal /* Copyright (C) 2024 Raspberry Pi */
3eb8d395fSMaíra Canal 
4eb8d395fSMaíra Canal #include <linux/fs.h>
5eb8d395fSMaíra Canal #include <linux/mount.h>
6eb8d395fSMaíra Canal 
7eb8d395fSMaíra Canal #include "v3d_drv.h"
8eb8d395fSMaíra Canal 
9eb8d395fSMaíra Canal void v3d_gemfs_init(struct v3d_dev *v3d)
10eb8d395fSMaíra Canal {
11eb8d395fSMaíra Canal 	char huge_opt[] = "huge=within_size";
12eb8d395fSMaíra Canal 	struct file_system_type *type;
13eb8d395fSMaíra Canal 	struct vfsmount *gemfs;
14eb8d395fSMaíra Canal 
15eb8d395fSMaíra Canal 	/*
16eb8d395fSMaíra Canal 	 * By creating our own shmemfs mountpoint, we can pass in
17eb8d395fSMaíra Canal 	 * mount flags that better match our usecase. However, we
18eb8d395fSMaíra Canal 	 * only do so on platforms which benefit from it.
19eb8d395fSMaíra Canal 	 */
20eb8d395fSMaíra Canal 	if (!IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE))
21eb8d395fSMaíra Canal 		goto err;
22eb8d395fSMaíra Canal 
23*0df4a13cSMaíra Canal 	/* The user doesn't want to enable Super Pages */
24*0df4a13cSMaíra Canal 	if (!super_pages)
25*0df4a13cSMaíra Canal 		goto err;
26*0df4a13cSMaíra Canal 
27eb8d395fSMaíra Canal 	type = get_fs_type("tmpfs");
28eb8d395fSMaíra Canal 	if (!type)
29eb8d395fSMaíra Canal 		goto err;
30eb8d395fSMaíra Canal 
31eb8d395fSMaíra Canal 	gemfs = vfs_kern_mount(type, SB_KERNMOUNT, type->name, huge_opt);
32eb8d395fSMaíra Canal 	if (IS_ERR(gemfs))
33eb8d395fSMaíra Canal 		goto err;
34eb8d395fSMaíra Canal 
35eb8d395fSMaíra Canal 	v3d->gemfs = gemfs;
36eb8d395fSMaíra Canal 	drm_info(&v3d->drm, "Using Transparent Hugepages\n");
37eb8d395fSMaíra Canal 
38eb8d395fSMaíra Canal 	return;
39eb8d395fSMaíra Canal 
40eb8d395fSMaíra Canal err:
41eb8d395fSMaíra Canal 	v3d->gemfs = NULL;
42eb8d395fSMaíra Canal 	drm_notice(&v3d->drm,
43eb8d395fSMaíra Canal 		   "Transparent Hugepage support is recommended for optimal performance on this platform!\n");
44eb8d395fSMaíra Canal }
45eb8d395fSMaíra Canal 
46eb8d395fSMaíra Canal void v3d_gemfs_fini(struct v3d_dev *v3d)
47eb8d395fSMaíra Canal {
48eb8d395fSMaíra Canal 	if (v3d->gemfs)
49eb8d395fSMaíra Canal 		kern_unmount(v3d->gemfs);
50eb8d395fSMaíra Canal }
51