xref: /openbmc/linux/drivers/iommu/iommu-debugfs.c (revision bad614b2)
1bad614b2SGary R Hook // SPDX-License-Identifier: GPL-2.0
2bad614b2SGary R Hook /*
3bad614b2SGary R Hook  * IOMMU debugfs core infrastructure
4bad614b2SGary R Hook  *
5bad614b2SGary R Hook  * Copyright (C) 2018 Advanced Micro Devices, Inc.
6bad614b2SGary R Hook  *
7bad614b2SGary R Hook  * Author: Gary R Hook <gary.hook@amd.com>
8bad614b2SGary R Hook  */
9bad614b2SGary R Hook 
10bad614b2SGary R Hook #include <linux/pci.h>
11bad614b2SGary R Hook #include <linux/iommu.h>
12bad614b2SGary R Hook #include <linux/debugfs.h>
13bad614b2SGary R Hook 
14bad614b2SGary R Hook struct dentry *iommu_debugfs_dir;
15bad614b2SGary R Hook 
16bad614b2SGary R Hook /**
17bad614b2SGary R Hook  * iommu_debugfs_setup - create the top-level iommu directory in debugfs
18bad614b2SGary R Hook  *
19bad614b2SGary R Hook  * Provide base enablement for using debugfs to expose internal data of an
20bad614b2SGary R Hook  * IOMMU driver. When called, this function creates the
21bad614b2SGary R Hook  * /sys/kernel/debug/iommu directory.
22bad614b2SGary R Hook  *
23bad614b2SGary R Hook  * Emit a strong warning at boot time to indicate that this feature is
24bad614b2SGary R Hook  * enabled.
25bad614b2SGary R Hook  *
26bad614b2SGary R Hook  * This function is called from iommu_init; drivers may then call
27bad614b2SGary R Hook  * iommu_debugfs_new_driver_dir() to instantiate a vendor-specific
28bad614b2SGary R Hook  * directory to be used to expose internal data.
29bad614b2SGary R Hook  */
30bad614b2SGary R Hook void iommu_debugfs_setup(void)
31bad614b2SGary R Hook {
32bad614b2SGary R Hook 	if (!iommu_debugfs_dir) {
33bad614b2SGary R Hook 		iommu_debugfs_dir = debugfs_create_dir("iommu", NULL);
34bad614b2SGary R Hook 		pr_warn("\n");
35bad614b2SGary R Hook 		pr_warn("*************************************************************\n");
36bad614b2SGary R Hook 		pr_warn("**     NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE    **\n");
37bad614b2SGary R Hook 		pr_warn("**                                                         **\n");
38bad614b2SGary R Hook 		pr_warn("**  IOMMU DebugFS SUPPORT HAS BEEN ENABLED IN THIS KERNEL  **\n");
39bad614b2SGary R Hook 		pr_warn("**                                                         **\n");
40bad614b2SGary R Hook 		pr_warn("** This means that this kernel is built to expose internal **\n");
41bad614b2SGary R Hook 		pr_warn("** IOMMU data structures, which may compromise security on **\n");
42bad614b2SGary R Hook 		pr_warn("** your system.                                            **\n");
43bad614b2SGary R Hook 		pr_warn("**                                                         **\n");
44bad614b2SGary R Hook 		pr_warn("** If you see this message and you are not debugging the   **\n");
45bad614b2SGary R Hook 		pr_warn("** kernel, report this immediately to your vendor!         **\n");
46bad614b2SGary R Hook 		pr_warn("**                                                         **\n");
47bad614b2SGary R Hook 		pr_warn("**     NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE    **\n");
48bad614b2SGary R Hook 		pr_warn("*************************************************************\n");
49bad614b2SGary R Hook 	}
50bad614b2SGary R Hook }
51bad614b2SGary R Hook 
52bad614b2SGary R Hook /**
53bad614b2SGary R Hook  * iommu_debugfs_new_driver_dir - create a vendor directory under debugfs/iommu
54bad614b2SGary R Hook  * @vendor: name of the vendor-specific subdirectory to create
55bad614b2SGary R Hook  *
56bad614b2SGary R Hook  * This function is called by an IOMMU driver to create the top-level debugfs
57bad614b2SGary R Hook  * directory for that driver.
58bad614b2SGary R Hook  *
59bad614b2SGary R Hook  * Return: upon success, a pointer to the dentry for the new directory.
60bad614b2SGary R Hook  *         NULL in case of failure.
61bad614b2SGary R Hook  */
62bad614b2SGary R Hook struct dentry *iommu_debugfs_new_driver_dir(const char *vendor)
63bad614b2SGary R Hook {
64bad614b2SGary R Hook 	return debugfs_create_dir(vendor, iommu_debugfs_dir);
65bad614b2SGary R Hook }
66bad614b2SGary R Hook EXPORT_SYMBOL_GPL(iommu_debugfs_new_driver_dir);
67