1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright 2017 Thomas Gleixner <tglx@linutronix.de>
4 #include <linux/irqdomain.h>
6 #include <linux/uaccess.h>
10 static struct dentry
*irq_dir
;
12 void irq_debug_show_bits(struct seq_file
*m
, int ind
, unsigned int state
,
13 const struct irq_bit_descr
*sd
, int size
)
17 for (i
= 0; i
< size
; i
++, sd
++) {
19 seq_printf(m
, "%*s%s\n", ind
+ 12, "", sd
->name
);
24 static void irq_debug_show_masks(struct seq_file
*m
, struct irq_desc
*desc
)
26 struct irq_data
*data
= irq_desc_get_irq_data(desc
);
27 const struct cpumask
*msk
;
29 msk
= irq_data_get_affinity_mask(data
);
30 seq_printf(m
, "affinity: %*pbl\n", cpumask_pr_args(msk
));
31 #ifdef CONFIG_GENERIC_IRQ_EFFECTIVE_AFF_MASK
32 msk
= irq_data_get_effective_affinity_mask(data
);
33 seq_printf(m
, "effectiv: %*pbl\n", cpumask_pr_args(msk
));
35 #ifdef CONFIG_GENERIC_PENDING_IRQ
36 msk
= desc
->pending_mask
;
37 seq_printf(m
, "pending: %*pbl\n", cpumask_pr_args(msk
));
41 static void irq_debug_show_masks(struct seq_file
*m
, struct irq_desc
*desc
) { }
44 static const struct irq_bit_descr irqchip_flags
[] = {
45 BIT_MASK_DESCR(IRQCHIP_SET_TYPE_MASKED
),
46 BIT_MASK_DESCR(IRQCHIP_EOI_IF_HANDLED
),
47 BIT_MASK_DESCR(IRQCHIP_MASK_ON_SUSPEND
),
48 BIT_MASK_DESCR(IRQCHIP_ONOFFLINE_ENABLED
),
49 BIT_MASK_DESCR(IRQCHIP_SKIP_SET_WAKE
),
50 BIT_MASK_DESCR(IRQCHIP_ONESHOT_SAFE
),
51 BIT_MASK_DESCR(IRQCHIP_EOI_THREADED
),
52 BIT_MASK_DESCR(IRQCHIP_SUPPORTS_LEVEL_MSI
),
53 BIT_MASK_DESCR(IRQCHIP_SUPPORTS_NMI
),
54 BIT_MASK_DESCR(IRQCHIP_ENABLE_WAKEUP_ON_SUSPEND
),
55 BIT_MASK_DESCR(IRQCHIP_IMMUTABLE
),
59 irq_debug_show_chip(struct seq_file
*m
, struct irq_data
*data
, int ind
)
61 struct irq_chip
*chip
= data
->chip
;
64 seq_printf(m
, "chip: None\n");
67 seq_printf(m
, "%*schip: ", ind
, "");
68 if (chip
->irq_print_chip
)
69 chip
->irq_print_chip(data
, m
);
71 seq_printf(m
, "%s", chip
->name
);
72 seq_printf(m
, "\n%*sflags: 0x%lx\n", ind
+ 1, "", chip
->flags
);
73 irq_debug_show_bits(m
, ind
, chip
->flags
, irqchip_flags
,
74 ARRAY_SIZE(irqchip_flags
));
78 irq_debug_show_data(struct seq_file
*m
, struct irq_data
*data
, int ind
)
80 seq_printf(m
, "%*sdomain: %s\n", ind
, "",
81 data
->domain
? data
->domain
->name
: "");
82 seq_printf(m
, "%*shwirq: 0x%lx\n", ind
+ 1, "", data
->hwirq
);
83 irq_debug_show_chip(m
, data
, ind
+ 1);
84 if (data
->domain
&& data
->domain
->ops
&& data
->domain
->ops
->debug_show
)
85 data
->domain
->ops
->debug_show(m
, NULL
, data
, ind
+ 1);
86 #ifdef CONFIG_IRQ_DOMAIN_HIERARCHY
87 if (!data
->parent_data
)
89 seq_printf(m
, "%*sparent:\n", ind
+ 1, "");
90 irq_debug_show_data(m
, data
->parent_data
, ind
+ 4);
94 static const struct irq_bit_descr irqdata_states
[] = {
95 BIT_MASK_DESCR(IRQ_TYPE_EDGE_RISING
),
96 BIT_MASK_DESCR(IRQ_TYPE_EDGE_FALLING
),
97 BIT_MASK_DESCR(IRQ_TYPE_LEVEL_HIGH
),
98 BIT_MASK_DESCR(IRQ_TYPE_LEVEL_LOW
),
99 BIT_MASK_DESCR(IRQD_LEVEL
),
101 BIT_MASK_DESCR(IRQD_ACTIVATED
),
102 BIT_MASK_DESCR(IRQD_IRQ_STARTED
),
103 BIT_MASK_DESCR(IRQD_IRQ_DISABLED
),
104 BIT_MASK_DESCR(IRQD_IRQ_MASKED
),
105 BIT_MASK_DESCR(IRQD_IRQ_INPROGRESS
),
107 BIT_MASK_DESCR(IRQD_PER_CPU
),
108 BIT_MASK_DESCR(IRQD_NO_BALANCING
),
110 BIT_MASK_DESCR(IRQD_SINGLE_TARGET
),
111 BIT_MASK_DESCR(IRQD_MOVE_PCNTXT
),
112 BIT_MASK_DESCR(IRQD_AFFINITY_SET
),
113 BIT_MASK_DESCR(IRQD_SETAFFINITY_PENDING
),
114 BIT_MASK_DESCR(IRQD_AFFINITY_MANAGED
),
115 BIT_MASK_DESCR(IRQD_AFFINITY_ON_ACTIVATE
),
116 BIT_MASK_DESCR(IRQD_MANAGED_SHUTDOWN
),
117 BIT_MASK_DESCR(IRQD_CAN_RESERVE
),
119 BIT_MASK_DESCR(IRQD_FORWARDED_TO_VCPU
),
121 BIT_MASK_DESCR(IRQD_WAKEUP_STATE
),
122 BIT_MASK_DESCR(IRQD_WAKEUP_ARMED
),
124 BIT_MASK_DESCR(IRQD_DEFAULT_TRIGGER_SET
),
126 BIT_MASK_DESCR(IRQD_HANDLE_ENFORCE_IRQCTX
),
128 BIT_MASK_DESCR(IRQD_IRQ_ENABLED_ON_SUSPEND
),
130 BIT_MASK_DESCR(IRQD_RESEND_WHEN_IN_PROGRESS
),
133 static const struct irq_bit_descr irqdesc_states
[] = {
134 BIT_MASK_DESCR(_IRQ_NOPROBE
),
135 BIT_MASK_DESCR(_IRQ_NOREQUEST
),
136 BIT_MASK_DESCR(_IRQ_NOTHREAD
),
137 BIT_MASK_DESCR(_IRQ_NOAUTOEN
),
138 BIT_MASK_DESCR(_IRQ_NESTED_THREAD
),
139 BIT_MASK_DESCR(_IRQ_PER_CPU_DEVID
),
140 BIT_MASK_DESCR(_IRQ_IS_POLLED
),
141 BIT_MASK_DESCR(_IRQ_DISABLE_UNLAZY
),
142 BIT_MASK_DESCR(_IRQ_HIDDEN
),
145 static const struct irq_bit_descr irqdesc_istates
[] = {
146 BIT_MASK_DESCR(IRQS_AUTODETECT
),
147 BIT_MASK_DESCR(IRQS_SPURIOUS_DISABLED
),
148 BIT_MASK_DESCR(IRQS_POLL_INPROGRESS
),
149 BIT_MASK_DESCR(IRQS_ONESHOT
),
150 BIT_MASK_DESCR(IRQS_REPLAY
),
151 BIT_MASK_DESCR(IRQS_WAITING
),
152 BIT_MASK_DESCR(IRQS_PENDING
),
153 BIT_MASK_DESCR(IRQS_SUSPENDED
),
154 BIT_MASK_DESCR(IRQS_NMI
),
158 static int irq_debug_show(struct seq_file
*m
, void *p
)
160 struct irq_desc
*desc
= m
->private;
161 struct irq_data
*data
;
163 raw_spin_lock_irq(&desc
->lock
);
164 data
= irq_desc_get_irq_data(desc
);
165 seq_printf(m
, "handler: %ps\n", desc
->handle_irq
);
166 seq_printf(m
, "device: %s\n", desc
->dev_name
);
167 seq_printf(m
, "status: 0x%08x\n", desc
->status_use_accessors
);
168 irq_debug_show_bits(m
, 0, desc
->status_use_accessors
, irqdesc_states
,
169 ARRAY_SIZE(irqdesc_states
));
170 seq_printf(m
, "istate: 0x%08x\n", desc
->istate
);
171 irq_debug_show_bits(m
, 0, desc
->istate
, irqdesc_istates
,
172 ARRAY_SIZE(irqdesc_istates
));
173 seq_printf(m
, "ddepth: %u\n", desc
->depth
);
174 seq_printf(m
, "wdepth: %u\n", desc
->wake_depth
);
175 seq_printf(m
, "dstate: 0x%08x\n", irqd_get(data
));
176 irq_debug_show_bits(m
, 0, irqd_get(data
), irqdata_states
,
177 ARRAY_SIZE(irqdata_states
));
178 seq_printf(m
, "node: %d\n", irq_data_get_node(data
));
179 irq_debug_show_masks(m
, desc
);
180 irq_debug_show_data(m
, data
, 0);
181 raw_spin_unlock_irq(&desc
->lock
);
185 static int irq_debug_open(struct inode
*inode
, struct file
*file
)
187 return single_open(file
, irq_debug_show
, inode
->i_private
);
190 static ssize_t
irq_debug_write(struct file
*file
, const char __user
*user_buf
,
191 size_t count
, loff_t
*ppos
)
193 struct irq_desc
*desc
= file_inode(file
)->i_private
;
194 char buf
[8] = { 0, };
197 size
= min(sizeof(buf
) - 1, count
);
198 if (copy_from_user(buf
, user_buf
, size
))
201 if (!strncmp(buf
, "trigger", size
)) {
202 int err
= irq_inject_interrupt(irq_desc_get_irq(desc
));
204 return err
? err
: count
;
210 static const struct file_operations dfs_irq_ops
= {
211 .open
= irq_debug_open
,
212 .write
= irq_debug_write
,
215 .release
= single_release
,
218 void irq_debugfs_copy_devname(int irq
, struct device
*dev
)
220 struct irq_desc
*desc
= irq_to_desc(irq
);
221 const char *name
= dev_name(dev
);
224 desc
->dev_name
= kstrdup(name
, GFP_KERNEL
);
227 void irq_add_debugfs_entry(unsigned int irq
, struct irq_desc
*desc
)
231 if (!irq_dir
|| !desc
|| desc
->debugfs_file
)
234 sprintf(name
, "%d", irq
);
235 desc
->debugfs_file
= debugfs_create_file(name
, 0644, irq_dir
, desc
,
239 static int __init
irq_debugfs_init(void)
241 struct dentry
*root_dir
;
244 root_dir
= debugfs_create_dir("irq", NULL
);
246 irq_domain_debugfs_init(root_dir
);
248 irq_dir
= debugfs_create_dir("irqs", root_dir
);
251 for_each_active_irq(irq
)
252 irq_add_debugfs_entry(irq
, irq_to_desc(irq
));
257 __initcall(irq_debugfs_init
);