152a65ff5SThomas Gleixner // SPDX-License-Identifier: GPL-2.0
2f3f59fbcSThomas Gleixner // Copyright 2017 Thomas Gleixner <[email protected]>
3f3f59fbcSThomas Gleixner
4087cdfb6SThomas Gleixner #include <linux/irqdomain.h>
5087cdfb6SThomas Gleixner #include <linux/irq.h>
6536e2e34SMarc Zyngier #include <linux/uaccess.h>
7087cdfb6SThomas Gleixner
8087cdfb6SThomas Gleixner #include "internals.h"
9087cdfb6SThomas Gleixner
10087cdfb6SThomas Gleixner static struct dentry *irq_dir;
11087cdfb6SThomas Gleixner
irq_debug_show_bits(struct seq_file * m,int ind,unsigned int state,const struct irq_bit_descr * sd,int size)12cb06c982SJinjie Ruan void irq_debug_show_bits(struct seq_file *m, int ind, unsigned int state,
13087cdfb6SThomas Gleixner const struct irq_bit_descr *sd, int size)
14087cdfb6SThomas Gleixner {
15087cdfb6SThomas Gleixner int i;
16087cdfb6SThomas Gleixner
17087cdfb6SThomas Gleixner for (i = 0; i < size; i++, sd++) {
18087cdfb6SThomas Gleixner if (state & sd->mask)
19087cdfb6SThomas Gleixner seq_printf(m, "%*s%s\n", ind + 12, "", sd->name);
20087cdfb6SThomas Gleixner }
21087cdfb6SThomas Gleixner }
22087cdfb6SThomas Gleixner
23087cdfb6SThomas Gleixner #ifdef CONFIG_SMP
irq_debug_show_masks(struct seq_file * m,struct irq_desc * desc)24087cdfb6SThomas Gleixner static void irq_debug_show_masks(struct seq_file *m, struct irq_desc *desc)
25087cdfb6SThomas Gleixner {
26087cdfb6SThomas Gleixner struct irq_data *data = irq_desc_get_irq_data(desc);
274d0b8298SSamuel Holland const struct cpumask *msk;
28087cdfb6SThomas Gleixner
29087cdfb6SThomas Gleixner msk = irq_data_get_affinity_mask(data);
30087cdfb6SThomas Gleixner seq_printf(m, "affinity: %*pbl\n", cpumask_pr_args(msk));
310d3f5425SThomas Gleixner #ifdef CONFIG_GENERIC_IRQ_EFFECTIVE_AFF_MASK
320d3f5425SThomas Gleixner msk = irq_data_get_effective_affinity_mask(data);
330d3f5425SThomas Gleixner seq_printf(m, "effectiv: %*pbl\n", cpumask_pr_args(msk));
340d3f5425SThomas Gleixner #endif
35087cdfb6SThomas Gleixner #ifdef CONFIG_GENERIC_PENDING_IRQ
36087cdfb6SThomas Gleixner msk = desc->pending_mask;
37087cdfb6SThomas Gleixner seq_printf(m, "pending: %*pbl\n", cpumask_pr_args(msk));
38087cdfb6SThomas Gleixner #endif
39087cdfb6SThomas Gleixner }
40087cdfb6SThomas Gleixner #else
irq_debug_show_masks(struct seq_file * m,struct irq_desc * desc)41087cdfb6SThomas Gleixner static void irq_debug_show_masks(struct seq_file *m, struct irq_desc *desc) { }
42087cdfb6SThomas Gleixner #endif
43087cdfb6SThomas Gleixner
44087cdfb6SThomas Gleixner static const struct irq_bit_descr irqchip_flags[] = {
45087cdfb6SThomas Gleixner BIT_MASK_DESCR(IRQCHIP_SET_TYPE_MASKED),
46087cdfb6SThomas Gleixner BIT_MASK_DESCR(IRQCHIP_EOI_IF_HANDLED),
47087cdfb6SThomas Gleixner BIT_MASK_DESCR(IRQCHIP_MASK_ON_SUSPEND),
48087cdfb6SThomas Gleixner BIT_MASK_DESCR(IRQCHIP_ONOFFLINE_ENABLED),
49087cdfb6SThomas Gleixner BIT_MASK_DESCR(IRQCHIP_SKIP_SET_WAKE),
50087cdfb6SThomas Gleixner BIT_MASK_DESCR(IRQCHIP_ONESHOT_SAFE),
51087cdfb6SThomas Gleixner BIT_MASK_DESCR(IRQCHIP_EOI_THREADED),
5272a8edc2SMarc Zyngier BIT_MASK_DESCR(IRQCHIP_SUPPORTS_LEVEL_MSI),
53b525903cSJulien Thierry BIT_MASK_DESCR(IRQCHIP_SUPPORTS_NMI),
5490428a8eSMaulik Shah BIT_MASK_DESCR(IRQCHIP_ENABLE_WAKEUP_ON_SUSPEND),
556c846d02SMarc Zyngier BIT_MASK_DESCR(IRQCHIP_IMMUTABLE),
56*a648eb3aSThomas Gleixner BIT_MASK_DESCR(IRQCHIP_MOVE_DEFERRED),
57087cdfb6SThomas Gleixner };
58087cdfb6SThomas Gleixner
59087cdfb6SThomas Gleixner static void
irq_debug_show_chip(struct seq_file * m,struct irq_data * data,int ind)60087cdfb6SThomas Gleixner irq_debug_show_chip(struct seq_file *m, struct irq_data *data, int ind)
61087cdfb6SThomas Gleixner {
62087cdfb6SThomas Gleixner struct irq_chip *chip = data->chip;
63087cdfb6SThomas Gleixner
64087cdfb6SThomas Gleixner if (!chip) {
65087cdfb6SThomas Gleixner seq_printf(m, "chip: None\n");
66087cdfb6SThomas Gleixner return;
67087cdfb6SThomas Gleixner }
680a25cb55SMarc Zyngier seq_printf(m, "%*schip: ", ind, "");
690a25cb55SMarc Zyngier if (chip->irq_print_chip)
700a25cb55SMarc Zyngier chip->irq_print_chip(data, m);
710a25cb55SMarc Zyngier else
720a25cb55SMarc Zyngier seq_printf(m, "%s", chip->name);
730a25cb55SMarc Zyngier seq_printf(m, "\n%*sflags: 0x%lx\n", ind + 1, "", chip->flags);
74087cdfb6SThomas Gleixner irq_debug_show_bits(m, ind, chip->flags, irqchip_flags,
75087cdfb6SThomas Gleixner ARRAY_SIZE(irqchip_flags));
76087cdfb6SThomas Gleixner }
77087cdfb6SThomas Gleixner
78087cdfb6SThomas Gleixner static void
irq_debug_show_data(struct seq_file * m,struct irq_data * data,int ind)79087cdfb6SThomas Gleixner irq_debug_show_data(struct seq_file *m, struct irq_data *data, int ind)
80087cdfb6SThomas Gleixner {
81087cdfb6SThomas Gleixner seq_printf(m, "%*sdomain: %s\n", ind, "",
82087cdfb6SThomas Gleixner data->domain ? data->domain->name : "");
83087cdfb6SThomas Gleixner seq_printf(m, "%*shwirq: 0x%lx\n", ind + 1, "", data->hwirq);
84087cdfb6SThomas Gleixner irq_debug_show_chip(m, data, ind + 1);
85c3e7239aSThomas Gleixner if (data->domain && data->domain->ops && data->domain->ops->debug_show)
86c3e7239aSThomas Gleixner data->domain->ops->debug_show(m, NULL, data, ind + 1);
87087cdfb6SThomas Gleixner #ifdef CONFIG_IRQ_DOMAIN_HIERARCHY
88087cdfb6SThomas Gleixner if (!data->parent_data)
89087cdfb6SThomas Gleixner return;
90087cdfb6SThomas Gleixner seq_printf(m, "%*sparent:\n", ind + 1, "");
91087cdfb6SThomas Gleixner irq_debug_show_data(m, data->parent_data, ind + 4);
92087cdfb6SThomas Gleixner #endif
93087cdfb6SThomas Gleixner }
94087cdfb6SThomas Gleixner
95087cdfb6SThomas Gleixner static const struct irq_bit_descr irqdata_states[] = {
96087cdfb6SThomas Gleixner BIT_MASK_DESCR(IRQ_TYPE_EDGE_RISING),
97087cdfb6SThomas Gleixner BIT_MASK_DESCR(IRQ_TYPE_EDGE_FALLING),
98087cdfb6SThomas Gleixner BIT_MASK_DESCR(IRQ_TYPE_LEVEL_HIGH),
99087cdfb6SThomas Gleixner BIT_MASK_DESCR(IRQ_TYPE_LEVEL_LOW),
100087cdfb6SThomas Gleixner BIT_MASK_DESCR(IRQD_LEVEL),
101087cdfb6SThomas Gleixner
102087cdfb6SThomas Gleixner BIT_MASK_DESCR(IRQD_ACTIVATED),
103087cdfb6SThomas Gleixner BIT_MASK_DESCR(IRQD_IRQ_STARTED),
104087cdfb6SThomas Gleixner BIT_MASK_DESCR(IRQD_IRQ_DISABLED),
105087cdfb6SThomas Gleixner BIT_MASK_DESCR(IRQD_IRQ_MASKED),
106087cdfb6SThomas Gleixner BIT_MASK_DESCR(IRQD_IRQ_INPROGRESS),
107087cdfb6SThomas Gleixner
108087cdfb6SThomas Gleixner BIT_MASK_DESCR(IRQD_PER_CPU),
109087cdfb6SThomas Gleixner BIT_MASK_DESCR(IRQD_NO_BALANCING),
110087cdfb6SThomas Gleixner
111d52dd441SThomas Gleixner BIT_MASK_DESCR(IRQD_SINGLE_TARGET),
112087cdfb6SThomas Gleixner BIT_MASK_DESCR(IRQD_AFFINITY_SET),
113087cdfb6SThomas Gleixner BIT_MASK_DESCR(IRQD_SETAFFINITY_PENDING),
114087cdfb6SThomas Gleixner BIT_MASK_DESCR(IRQD_AFFINITY_MANAGED),
115aa251fc5SMarc Zyngier BIT_MASK_DESCR(IRQD_AFFINITY_ON_ACTIVATE),
116087cdfb6SThomas Gleixner BIT_MASK_DESCR(IRQD_MANAGED_SHUTDOWN),
11769790ba9SThomas Gleixner BIT_MASK_DESCR(IRQD_CAN_RESERVE),
118087cdfb6SThomas Gleixner
119087cdfb6SThomas Gleixner BIT_MASK_DESCR(IRQD_FORWARDED_TO_VCPU),
120087cdfb6SThomas Gleixner
121087cdfb6SThomas Gleixner BIT_MASK_DESCR(IRQD_WAKEUP_STATE),
122087cdfb6SThomas Gleixner BIT_MASK_DESCR(IRQD_WAKEUP_ARMED),
123aa251fc5SMarc Zyngier
124aa251fc5SMarc Zyngier BIT_MASK_DESCR(IRQD_DEFAULT_TRIGGER_SET),
125aa251fc5SMarc Zyngier
126aa251fc5SMarc Zyngier BIT_MASK_DESCR(IRQD_HANDLE_ENFORCE_IRQCTX),
12790428a8eSMaulik Shah
12890428a8eSMaulik Shah BIT_MASK_DESCR(IRQD_IRQ_ENABLED_ON_SUSPEND),
1299c15eeb5SJames Gowans
1309c15eeb5SJames Gowans BIT_MASK_DESCR(IRQD_RESEND_WHEN_IN_PROGRESS),
131087cdfb6SThomas Gleixner };
132087cdfb6SThomas Gleixner
133087cdfb6SThomas Gleixner static const struct irq_bit_descr irqdesc_states[] = {
134087cdfb6SThomas Gleixner BIT_MASK_DESCR(_IRQ_NOPROBE),
135087cdfb6SThomas Gleixner BIT_MASK_DESCR(_IRQ_NOREQUEST),
136087cdfb6SThomas Gleixner BIT_MASK_DESCR(_IRQ_NOTHREAD),
137087cdfb6SThomas Gleixner BIT_MASK_DESCR(_IRQ_NOAUTOEN),
138087cdfb6SThomas Gleixner BIT_MASK_DESCR(_IRQ_NESTED_THREAD),
139087cdfb6SThomas Gleixner BIT_MASK_DESCR(_IRQ_PER_CPU_DEVID),
140087cdfb6SThomas Gleixner BIT_MASK_DESCR(_IRQ_IS_POLLED),
141087cdfb6SThomas Gleixner BIT_MASK_DESCR(_IRQ_DISABLE_UNLAZY),
14283cfac95SMarc Zyngier BIT_MASK_DESCR(_IRQ_HIDDEN),
143087cdfb6SThomas Gleixner };
144087cdfb6SThomas Gleixner
145087cdfb6SThomas Gleixner static const struct irq_bit_descr irqdesc_istates[] = {
146087cdfb6SThomas Gleixner BIT_MASK_DESCR(IRQS_AUTODETECT),
147087cdfb6SThomas Gleixner BIT_MASK_DESCR(IRQS_SPURIOUS_DISABLED),
148087cdfb6SThomas Gleixner BIT_MASK_DESCR(IRQS_POLL_INPROGRESS),
149087cdfb6SThomas Gleixner BIT_MASK_DESCR(IRQS_ONESHOT),
150087cdfb6SThomas Gleixner BIT_MASK_DESCR(IRQS_REPLAY),
151087cdfb6SThomas Gleixner BIT_MASK_DESCR(IRQS_WAITING),
152087cdfb6SThomas Gleixner BIT_MASK_DESCR(IRQS_PENDING),
153087cdfb6SThomas Gleixner BIT_MASK_DESCR(IRQS_SUSPENDED),
154b525903cSJulien Thierry BIT_MASK_DESCR(IRQS_NMI),
155087cdfb6SThomas Gleixner };
156087cdfb6SThomas Gleixner
157087cdfb6SThomas Gleixner
irq_debug_show(struct seq_file * m,void * p)158087cdfb6SThomas Gleixner static int irq_debug_show(struct seq_file *m, void *p)
159087cdfb6SThomas Gleixner {
160087cdfb6SThomas Gleixner struct irq_desc *desc = m->private;
161087cdfb6SThomas Gleixner struct irq_data *data;
162087cdfb6SThomas Gleixner
163087cdfb6SThomas Gleixner raw_spin_lock_irq(&desc->lock);
164087cdfb6SThomas Gleixner data = irq_desc_get_irq_data(desc);
165d75f773cSSakari Ailus seq_printf(m, "handler: %ps\n", desc->handle_irq);
16607557ccbSThomas Gleixner seq_printf(m, "device: %s\n", desc->dev_name);
167087cdfb6SThomas Gleixner seq_printf(m, "status: 0x%08x\n", desc->status_use_accessors);
168087cdfb6SThomas Gleixner irq_debug_show_bits(m, 0, desc->status_use_accessors, irqdesc_states,
169087cdfb6SThomas Gleixner ARRAY_SIZE(irqdesc_states));
170087cdfb6SThomas Gleixner seq_printf(m, "istate: 0x%08x\n", desc->istate);
171087cdfb6SThomas Gleixner irq_debug_show_bits(m, 0, desc->istate, irqdesc_istates,
172087cdfb6SThomas Gleixner ARRAY_SIZE(irqdesc_istates));
173087cdfb6SThomas Gleixner seq_printf(m, "ddepth: %u\n", desc->depth);
174087cdfb6SThomas Gleixner seq_printf(m, "wdepth: %u\n", desc->wake_depth);
175087cdfb6SThomas Gleixner seq_printf(m, "dstate: 0x%08x\n", irqd_get(data));
176087cdfb6SThomas Gleixner irq_debug_show_bits(m, 0, irqd_get(data), irqdata_states,
177087cdfb6SThomas Gleixner ARRAY_SIZE(irqdata_states));
178087cdfb6SThomas Gleixner seq_printf(m, "node: %d\n", irq_data_get_node(data));
179087cdfb6SThomas Gleixner irq_debug_show_masks(m, desc);
180087cdfb6SThomas Gleixner irq_debug_show_data(m, data, 0);
181087cdfb6SThomas Gleixner raw_spin_unlock_irq(&desc->lock);
182087cdfb6SThomas Gleixner return 0;
183087cdfb6SThomas Gleixner }
184087cdfb6SThomas Gleixner
irq_debug_open(struct inode * inode,struct file * file)185087cdfb6SThomas Gleixner static int irq_debug_open(struct inode *inode, struct file *file)
186087cdfb6SThomas Gleixner {
187087cdfb6SThomas Gleixner return single_open(file, irq_debug_show, inode->i_private);
188087cdfb6SThomas Gleixner }
189087cdfb6SThomas Gleixner
irq_debug_write(struct file * file,const char __user * user_buf,size_t count,loff_t * ppos)190536e2e34SMarc Zyngier static ssize_t irq_debug_write(struct file *file, const char __user *user_buf,
191536e2e34SMarc Zyngier size_t count, loff_t *ppos)
192536e2e34SMarc Zyngier {
193536e2e34SMarc Zyngier struct irq_desc *desc = file_inode(file)->i_private;
194536e2e34SMarc Zyngier char buf[8] = { 0, };
195536e2e34SMarc Zyngier size_t size;
196536e2e34SMarc Zyngier
197536e2e34SMarc Zyngier size = min(sizeof(buf) - 1, count);
198536e2e34SMarc Zyngier if (copy_from_user(buf, user_buf, size))
199536e2e34SMarc Zyngier return -EFAULT;
200536e2e34SMarc Zyngier
201536e2e34SMarc Zyngier if (!strncmp(buf, "trigger", size)) {
202acd26bcfSThomas Gleixner int err = irq_inject_interrupt(irq_desc_get_irq(desc));
203536e2e34SMarc Zyngier
204536e2e34SMarc Zyngier return err ? err : count;
205536e2e34SMarc Zyngier }
206536e2e34SMarc Zyngier
207536e2e34SMarc Zyngier return count;
208536e2e34SMarc Zyngier }
209536e2e34SMarc Zyngier
210087cdfb6SThomas Gleixner static const struct file_operations dfs_irq_ops = {
211087cdfb6SThomas Gleixner .open = irq_debug_open,
212536e2e34SMarc Zyngier .write = irq_debug_write,
213087cdfb6SThomas Gleixner .read = seq_read,
214087cdfb6SThomas Gleixner .llseek = seq_lseek,
215087cdfb6SThomas Gleixner .release = single_release,
216087cdfb6SThomas Gleixner };
217087cdfb6SThomas Gleixner
irq_debugfs_copy_devname(int irq,struct device * dev)21807557ccbSThomas Gleixner void irq_debugfs_copy_devname(int irq, struct device *dev)
21907557ccbSThomas Gleixner {
22007557ccbSThomas Gleixner struct irq_desc *desc = irq_to_desc(irq);
22107557ccbSThomas Gleixner const char *name = dev_name(dev);
22207557ccbSThomas Gleixner
22307557ccbSThomas Gleixner if (name)
22407557ccbSThomas Gleixner desc->dev_name = kstrdup(name, GFP_KERNEL);
22507557ccbSThomas Gleixner }
22607557ccbSThomas Gleixner
irq_add_debugfs_entry(unsigned int irq,struct irq_desc * desc)227087cdfb6SThomas Gleixner void irq_add_debugfs_entry(unsigned int irq, struct irq_desc *desc)
228087cdfb6SThomas Gleixner {
229087cdfb6SThomas Gleixner char name [10];
230087cdfb6SThomas Gleixner
231087cdfb6SThomas Gleixner if (!irq_dir || !desc || desc->debugfs_file)
232087cdfb6SThomas Gleixner return;
233087cdfb6SThomas Gleixner
234087cdfb6SThomas Gleixner sprintf(name, "%d", irq);
235536e2e34SMarc Zyngier desc->debugfs_file = debugfs_create_file(name, 0644, irq_dir, desc,
236087cdfb6SThomas Gleixner &dfs_irq_ops);
237087cdfb6SThomas Gleixner }
238087cdfb6SThomas Gleixner
irq_debugfs_init(void)239087cdfb6SThomas Gleixner static int __init irq_debugfs_init(void)
240087cdfb6SThomas Gleixner {
241087cdfb6SThomas Gleixner struct dentry *root_dir;
242087cdfb6SThomas Gleixner int irq;
243087cdfb6SThomas Gleixner
244087cdfb6SThomas Gleixner root_dir = debugfs_create_dir("irq", NULL);
245087cdfb6SThomas Gleixner
246087cdfb6SThomas Gleixner irq_domain_debugfs_init(root_dir);
247087cdfb6SThomas Gleixner
248087cdfb6SThomas Gleixner irq_dir = debugfs_create_dir("irqs", root_dir);
249087cdfb6SThomas Gleixner
250087cdfb6SThomas Gleixner irq_lock_sparse();
251087cdfb6SThomas Gleixner for_each_active_irq(irq)
252087cdfb6SThomas Gleixner irq_add_debugfs_entry(irq, irq_to_desc(irq));
253087cdfb6SThomas Gleixner irq_unlock_sparse();
254087cdfb6SThomas Gleixner
255087cdfb6SThomas Gleixner return 0;
256087cdfb6SThomas Gleixner }
257087cdfb6SThomas Gleixner __initcall(irq_debugfs_init);
258