18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * SPDX-License-Identifier: MIT
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * Copyright © 2017 Intel Corporation
58c2ecf20Sopenharmony_ci */
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci#include <linux/fs.h>
88c2ecf20Sopenharmony_ci#include <linux/mount.h>
98c2ecf20Sopenharmony_ci#include <linux/pagemap.h>
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#include "i915_drv.h"
128c2ecf20Sopenharmony_ci#include "i915_gemfs.h"
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ciint i915_gemfs_init(struct drm_i915_private *i915)
158c2ecf20Sopenharmony_ci{
168c2ecf20Sopenharmony_ci	struct file_system_type *type;
178c2ecf20Sopenharmony_ci	struct vfsmount *gemfs;
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci	type = get_fs_type("tmpfs");
208c2ecf20Sopenharmony_ci	if (!type)
218c2ecf20Sopenharmony_ci		return -ENODEV;
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci	/*
248c2ecf20Sopenharmony_ci	 * By creating our own shmemfs mountpoint, we can pass in
258c2ecf20Sopenharmony_ci	 * mount flags that better match our usecase.
268c2ecf20Sopenharmony_ci	 *
278c2ecf20Sopenharmony_ci	 * One example, although it is probably better with a per-file
288c2ecf20Sopenharmony_ci	 * control, is selecting huge page allocations ("huge=within_size").
298c2ecf20Sopenharmony_ci	 * Currently unused due to bandwidth issues (slow reads) on Broadwell+.
308c2ecf20Sopenharmony_ci	 */
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ci	gemfs = kern_mount(type);
338c2ecf20Sopenharmony_ci	if (IS_ERR(gemfs))
348c2ecf20Sopenharmony_ci		return PTR_ERR(gemfs);
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci	i915->mm.gemfs = gemfs;
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci	return 0;
398c2ecf20Sopenharmony_ci}
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_civoid i915_gemfs_fini(struct drm_i915_private *i915)
428c2ecf20Sopenharmony_ci{
438c2ecf20Sopenharmony_ci	kern_unmount(i915->mm.gemfs);
448c2ecf20Sopenharmony_ci}
45