Skip to content

Commit 7d0f5fd

Browse files
garyrhookjoergroedel
authored andcommitted
iommu/amd: Add basic debugfs infrastructure for AMD IOMMU
Implement a skeleton framework for debugfs support in the AMD IOMMU. Add an AMD-specific Kconfig boolean that depends upon general enablement of DebugFS in the IOMMU. Signed-off-by: Gary R Hook <[email protected]> Signed-off-by: Joerg Roedel <[email protected]>
1 parent bad614b commit 7d0f5fd

File tree

6 files changed

+61
-2
lines changed

6 files changed

+61
-2
lines changed

drivers/iommu/Kconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,18 @@ config AMD_IOMMU_V2
145145
hardware. Select this option if you want to use devices that support
146146
the PCI PRI and PASID interface.
147147

148+
config AMD_IOMMU_DEBUGFS
149+
bool "Enable AMD IOMMU internals in DebugFS"
150+
depends on AMD_IOMMU && IOMMU_DEBUGFS
151+
---help---
152+
!!!WARNING!!! !!!WARNING!!! !!!WARNING!!! !!!WARNING!!!
153+
154+
DO NOT ENABLE THIS OPTION UNLESS YOU REALLY, -REALLY- KNOW WHAT YOU ARE DOING!!!
155+
Exposes AMD IOMMU device internals in DebugFS.
156+
157+
This option is -NOT- intended for production environments, and should
158+
not generally be enabled.
159+
148160
# Intel IOMMU support
149161
config DMAR_TABLE
150162
bool

drivers/iommu/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ obj-$(CONFIG_IOMMU_IOVA) += iova.o
1111
obj-$(CONFIG_OF_IOMMU) += of_iommu.o
1212
obj-$(CONFIG_MSM_IOMMU) += msm_iommu.o
1313
obj-$(CONFIG_AMD_IOMMU) += amd_iommu.o amd_iommu_init.o
14+
obj-$(CONFIG_AMD_IOMMU_DEBUGFS) += amd_iommu_debugfs.o
1415
obj-$(CONFIG_AMD_IOMMU_V2) += amd_iommu_v2.o
1516
obj-$(CONFIG_ARM_SMMU) += arm-smmu.o
1617
obj-$(CONFIG_ARM_SMMU_V3) += arm-smmu-v3.o

drivers/iommu/amd_iommu_debugfs.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/*
3+
* AMD IOMMU driver
4+
*
5+
* Copyright (C) 2018 Advanced Micro Devices, Inc.
6+
*
7+
* Author: Gary R Hook <[email protected]>
8+
*/
9+
10+
#include <linux/debugfs.h>
11+
#include <linux/iommu.h>
12+
#include <linux/pci.h>
13+
#include "amd_iommu_proto.h"
14+
#include "amd_iommu_types.h"
15+
16+
static struct dentry *amd_iommu_debugfs;
17+
static DEFINE_MUTEX(amd_iommu_debugfs_lock);
18+
19+
#define MAX_NAME_LEN 20
20+
21+
void amd_iommu_debugfs_setup(struct amd_iommu *iommu)
22+
{
23+
char name[MAX_NAME_LEN + 1];
24+
25+
mutex_lock(&amd_iommu_debugfs_lock);
26+
if (!amd_iommu_debugfs)
27+
amd_iommu_debugfs = debugfs_create_dir("amd",
28+
iommu_debugfs_dir);
29+
mutex_unlock(&amd_iommu_debugfs_lock);
30+
31+
snprintf(name, MAX_NAME_LEN, "iommu%02d", iommu->index);
32+
iommu->debugfs = debugfs_create_dir(name, amd_iommu_debugfs);
33+
}

drivers/iommu/amd_iommu_init.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2721,6 +2721,7 @@ int __init amd_iommu_enable_faulting(void)
27212721
*/
27222722
static int __init amd_iommu_init(void)
27232723
{
2724+
struct amd_iommu *iommu;
27242725
int ret;
27252726

27262727
ret = iommu_go_to_state(IOMMU_INITIALIZED);
@@ -2730,14 +2731,15 @@ static int __init amd_iommu_init(void)
27302731
disable_iommus();
27312732
free_iommu_resources();
27322733
} else {
2733-
struct amd_iommu *iommu;
2734-
27352734
uninit_device_table_dma();
27362735
for_each_iommu(iommu)
27372736
iommu_flush_all_caches(iommu);
27382737
}
27392738
}
27402739

2740+
for_each_iommu(iommu)
2741+
amd_iommu_debugfs_setup(iommu);
2742+
27412743
return ret;
27422744
}
27432745

drivers/iommu/amd_iommu_proto.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ extern void amd_iommu_uninit_devices(void);
3333
extern void amd_iommu_init_notifier(void);
3434
extern int amd_iommu_init_api(void);
3535

36+
#ifdef CONFIG_AMD_IOMMU_DEBUGFS
37+
void amd_iommu_debugfs_setup(struct amd_iommu *iommu);
38+
#else
39+
static inline void amd_iommu_debugfs_setup(struct amd_iommu *iommu) {}
40+
#endif
41+
3642
/* Needed for interrupt remapping */
3743
extern int amd_iommu_prepare(void);
3844
extern int amd_iommu_enable(void);

drivers/iommu/amd_iommu_types.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,11 @@ struct amd_iommu {
594594

595595
u32 flags;
596596
volatile u64 __aligned(8) cmd_sem;
597+
598+
#ifdef CONFIG_AMD_IOMMU_DEBUGFS
599+
/* DebugFS Info */
600+
struct dentry *debugfs;
601+
#endif
597602
};
598603

599604
static inline struct amd_iommu *dev_to_amd_iommu(struct device *dev)

0 commit comments

Comments
 (0)