152a65ff5SThomas Gleixner // SPDX-License-Identifier: GPL-2.0
2f3f59fbcSThomas Gleixner // Copyright 2017 Thomas Gleixner <tglx@linutronix.de>
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
12087cdfb6SThomas Gleixner struct irq_bit_descr {
13087cdfb6SThomas Gleixner unsigned int mask;
14087cdfb6SThomas Gleixner char *name;
15087cdfb6SThomas Gleixner };
16087cdfb6SThomas Gleixner #define BIT_MASK_DESCR(m) { .mask = m, .name = #m }
17087cdfb6SThomas Gleixner
irq_debug_show_bits(struct seq_file * m,int ind,unsigned int state,const struct irq_bit_descr * sd,int size)18087cdfb6SThomas Gleixner static void irq_debug_show_bits(struct seq_file *m, int ind, unsigned int state,
19087cdfb6SThomas Gleixner const struct irq_bit_descr *sd, int size)
20087cdfb6SThomas Gleixner {
21087cdfb6SThomas Gleixner int i;
22087cdfb6SThomas Gleixner
23087cdfb6SThomas Gleixner for (i = 0; i < size; i++, sd++) {
24087cdfb6SThomas Gleixner if (state & sd->mask)
25087cdfb6SThomas Gleixner seq_printf(m, "%*s%s\n", ind + 12, "", sd->name);
26087cdfb6SThomas Gleixner }
27087cdfb6SThomas Gleixner }
28087cdfb6SThomas Gleixner
29087cdfb6SThomas Gleixner #ifdef CONFIG_SMP
irq_debug_show_masks(struct seq_file * m,struct irq_desc * desc)30087cdfb6SThomas Gleixner static void irq_debug_show_masks(struct seq_file *m, struct irq_desc *desc)
31087cdfb6SThomas Gleixner {
32087cdfb6SThomas Gleixner struct irq_data *data = irq_desc_get_irq_data(desc);
334d0b8298SSamuel Holland const struct cpumask *msk;
34087cdfb6SThomas Gleixner
35087cdfb6SThomas Gleixner msk = irq_data_get_affinity_mask(data);
36087cdfb6SThomas Gleixner seq_printf(m, "affinity: %*pbl\n", cpumask_pr_args(msk));
370d3f5425SThomas Gleixner #ifdef CONFIG_GENERIC_IRQ_EFFECTIVE_AFF_MASK
380d3f5425SThomas Gleixner msk = irq_data_get_effective_affinity_mask(data);
390d3f5425SThomas Gleixner seq_printf(m, "effectiv: %*pbl\n", cpumask_pr_args(msk));
400d3f5425SThomas Gleixner #endif
41087cdfb6SThomas Gleixner #ifdef CONFIG_GENERIC_PENDING_IRQ
42087cdfb6SThomas Gleixner msk = desc->pending_mask;
43087cdfb6SThomas Gleixner seq_printf(m, "pending: %*pbl\n", cpumask_pr_args(msk));
44087cdfb6SThomas Gleixner #endif
45087cdfb6SThomas Gleixner }
46087cdfb6SThomas Gleixner #else
irq_debug_show_masks(struct seq_file * m,struct irq_desc * desc)47087cdfb6SThomas Gleixner static void irq_debug_show_masks(struct seq_file *m, struct irq_desc *desc) { }
48087cdfb6SThomas Gleixner #endif
49087cdfb6SThomas Gleixner
50087cdfb6SThomas Gleixner static const struct irq_bit_descr irqchip_flags[] = {
51087cdfb6SThomas Gleixner BIT_MASK_DESCR(IRQCHIP_SET_TYPE_MASKED),
52087cdfb6SThomas Gleixner BIT_MASK_DESCR(IRQCHIP_EOI_IF_HANDLED),
53087cdfb6SThomas Gleixner BIT_MASK_DESCR(IRQCHIP_MASK_ON_SUSPEND),
54087cdfb6SThomas Gleixner BIT_MASK_DESCR(IRQCHIP_ONOFFLINE_ENABLED),
55087cdfb6SThomas Gleixner BIT_MASK_DESCR(IRQCHIP_SKIP_SET_WAKE),
56087cdfb6SThomas Gleixner BIT_MASK_DESCR(IRQCHIP_ONESHOT_SAFE),
57087cdfb6SThomas Gleixner BIT_MASK_DESCR(IRQCHIP_EOI_THREADED),
5872a8edc2SMarc Zyngier BIT_MASK_DESCR(IRQCHIP_SUPPORTS_LEVEL_MSI),
59b525903cSJulien Thierry BIT_MASK_DESCR(IRQCHIP_SUPPORTS_NMI),
6090428a8eSMaulik Shah BIT_MASK_DESCR(IRQCHIP_ENABLE_WAKEUP_ON_SUSPEND),
616c846d02SMarc Zyngier BIT_MASK_DESCR(IRQCHIP_IMMUTABLE),
62087cdfb6SThomas Gleixner };
63087cdfb6SThomas Gleixner
64087cdfb6SThomas Gleixner static void
irq_debug_show_chip(struct seq_file * m,struct irq_data * data,int ind)65087cdfb6SThomas Gleixner irq_debug_show_chip(struct seq_file *m, struct irq_data *data, int ind)
66087cdfb6SThomas Gleixner {
67087cdfb6SThomas Gleixner struct irq_chip *chip = data->chip;
68087cdfb6SThomas Gleixner
69087cdfb6SThomas Gleixner if (!chip) {
70087cdfb6SThomas Gleixner seq_printf(m, "chip: None\n");
71087cdfb6SThomas Gleixner return;
72087cdfb6SThomas Gleixner }
730a25cb55SMarc Zyngier seq_printf(m, "%*schip: ", ind, "");
740a25cb55SMarc Zyngier if (chip->irq_print_chip)
750a25cb55SMarc Zyngier chip->irq_print_chip(data, m);
760a25cb55SMarc Zyngier else
770a25cb55SMarc Zyngier seq_printf(m, "%s", chip->name);
780a25cb55SMarc Zyngier seq_printf(m, "\n%*sflags: 0x%lx\n", ind + 1, "", chip->flags);
79087cdfb6SThomas Gleixner irq_debug_show_bits(m, ind, chip->flags, irqchip_flags,
80087cdfb6SThomas Gleixner ARRAY_SIZE(irqchip_flags));
81087cdfb6SThomas Gleixner }
82087cdfb6SThomas Gleixner
83087cdfb6SThomas Gleixner static void
irq_debug_show_data(struct seq_file * m,struct irq_data * data,int ind)84087cdfb6SThomas Gleixner irq_debug_show_data(struct seq_file *m, struct irq_data *data, int ind)
85087cdfb6SThomas Gleixner {
86087cdfb6SThomas Gleixner seq_printf(m, "%*sdomain: %s\n", ind, "",
87087cdfb6SThomas Gleixner data->domain ? data->domain->name : "");
88087cdfb6SThomas Gleixner seq_printf(m, "%*shwirq: 0x%lx\n", ind + 1, "", data->hwirq);
89087cdfb6SThomas Gleixner irq_debug_show_chip(m, data, ind + 1);
90c3e7239aSThomas Gleixner if (data->domain && data->domain->ops && data->domain->ops->debug_show)
91c3e7239aSThomas Gleixner data->domain->ops->debug_show(m, NULL, data, ind + 1);
92087cdfb6SThomas Gleixner #ifdef CONFIG_IRQ_DOMAIN_HIERARCHY
93087cdfb6SThomas Gleixner if (!data->parent_data)
94087cdfb6SThomas Gleixner return;
95087cdfb6SThomas Gleixner seq_printf(m, "%*sparent:\n", ind + 1, "");
96087cdfb6SThomas Gleixner irq_debug_show_data(m, data->parent_data, ind + 4);
97087cdfb6SThomas Gleixner #endif
98087cdfb6SThomas Gleixner }
99087cdfb6SThomas Gleixner
100087cdfb6SThomas Gleixner static const struct irq_bit_descr irqdata_states[] = {
101087cdfb6SThomas Gleixner BIT_MASK_DESCR(IRQ_TYPE_EDGE_RISING),
102087cdfb6SThomas Gleixner BIT_MASK_DESCR(IRQ_TYPE_EDGE_FALLING),
103087cdfb6SThomas Gleixner BIT_MASK_DESCR(IRQ_TYPE_LEVEL_HIGH),
104087cdfb6SThomas Gleixner BIT_MASK_DESCR(IRQ_TYPE_LEVEL_LOW),
105087cdfb6SThomas Gleixner BIT_MASK_DESCR(IRQD_LEVEL),
106087cdfb6SThomas Gleixner
107087cdfb6SThomas Gleixner BIT_MASK_DESCR(IRQD_ACTIVATED),
108087cdfb6SThomas Gleixner BIT_MASK_DESCR(IRQD_IRQ_STARTED),
109087cdfb6SThomas Gleixner BIT_MASK_DESCR(IRQD_IRQ_DISABLED),
110087cdfb6SThomas Gleixner BIT_MASK_DESCR(IRQD_IRQ_MASKED),
111087cdfb6SThomas Gleixner BIT_MASK_DESCR(IRQD_IRQ_INPROGRESS),
112087cdfb6SThomas Gleixner
113087cdfb6SThomas Gleixner BIT_MASK_DESCR(IRQD_PER_CPU),
114087cdfb6SThomas Gleixner BIT_MASK_DESCR(IRQD_NO_BALANCING),
115087cdfb6SThomas Gleixner
116d52dd441SThomas Gleixner BIT_MASK_DESCR(IRQD_SINGLE_TARGET),
117087cdfb6SThomas Gleixner BIT_MASK_DESCR(IRQD_MOVE_PCNTXT),
118087cdfb6SThomas Gleixner BIT_MASK_DESCR(IRQD_AFFINITY_SET),
119087cdfb6SThomas Gleixner BIT_MASK_DESCR(IRQD_SETAFFINITY_PENDING),
120087cdfb6SThomas Gleixner BIT_MASK_DESCR(IRQD_AFFINITY_MANAGED),
121aa251fc5SMarc Zyngier BIT_MASK_DESCR(IRQD_AFFINITY_ON_ACTIVATE),
122087cdfb6SThomas Gleixner BIT_MASK_DESCR(IRQD_MANAGED_SHUTDOWN),
12369790ba9SThomas Gleixner BIT_MASK_DESCR(IRQD_CAN_RESERVE),
124087cdfb6SThomas Gleixner
125087cdfb6SThomas Gleixner BIT_MASK_DESCR(IRQD_FORWARDED_TO_VCPU),
126087cdfb6SThomas Gleixner
127087cdfb6SThomas Gleixner BIT_MASK_DESCR(IRQD_WAKEUP_STATE),
128087cdfb6SThomas Gleixner BIT_MASK_DESCR(IRQD_WAKEUP_ARMED),
129aa251fc5SMarc Zyngier
130aa251fc5SMarc Zyngier BIT_MASK_DESCR(IRQD_DEFAULT_TRIGGER_SET),
131aa251fc5SMarc Zyngier
132aa251fc5SMarc Zyngier BIT_MASK_DESCR(IRQD_HANDLE_ENFORCE_IRQCTX),
13390428a8eSMaulik Shah
13490428a8eSMaulik Shah BIT_MASK_DESCR(IRQD_IRQ_ENABLED_ON_SUSPEND),
135*9c15eeb5SJames Gowans
136*9c15eeb5SJames Gowans BIT_MASK_DESCR(IRQD_RESEND_WHEN_IN_PROGRESS),
137087cdfb6SThomas Gleixner };
138087cdfb6SThomas Gleixner
139087cdfb6SThomas Gleixner static const struct irq_bit_descr irqdesc_states[] = {
140087cdfb6SThomas Gleixner BIT_MASK_DESCR(_IRQ_NOPROBE),
141087cdfb6SThomas Gleixner BIT_MASK_DESCR(_IRQ_NOREQUEST),
142087cdfb6SThomas Gleixner BIT_MASK_DESCR(_IRQ_NOTHREAD),
143087cdfb6SThomas Gleixner BIT_MASK_DESCR(_IRQ_NOAUTOEN),
144087cdfb6SThomas Gleixner BIT_MASK_DESCR(_IRQ_NESTED_THREAD),
145087cdfb6SThomas Gleixner BIT_MASK_DESCR(_IRQ_PER_CPU_DEVID),
146087cdfb6SThomas Gleixner BIT_MASK_DESCR(_IRQ_IS_POLLED),
147087cdfb6SThomas Gleixner BIT_MASK_DESCR(_IRQ_DISABLE_UNLAZY),
14883cfac95SMarc Zyngier BIT_MASK_DESCR(_IRQ_HIDDEN),
149087cdfb6SThomas Gleixner };
150087cdfb6SThomas Gleixner
151087cdfb6SThomas Gleixner static const struct irq_bit_descr irqdesc_istates[] = {
152087cdfb6SThomas Gleixner BIT_MASK_DESCR(IRQS_AUTODETECT),
153087cdfb6SThomas Gleixner BIT_MASK_DESCR(IRQS_SPURIOUS_DISABLED),
154087cdfb6SThomas Gleixner BIT_MASK_DESCR(IRQS_POLL_INPROGRESS),
155087cdfb6SThomas Gleixner BIT_MASK_DESCR(IRQS_ONESHOT),
156087cdfb6SThomas Gleixner BIT_MASK_DESCR(IRQS_REPLAY),
157087cdfb6SThomas Gleixner BIT_MASK_DESCR(IRQS_WAITING),
158087cdfb6SThomas Gleixner BIT_MASK_DESCR(IRQS_PENDING),
159087cdfb6SThomas Gleixner BIT_MASK_DESCR(IRQS_SUSPENDED),
160b525903cSJulien Thierry BIT_MASK_DESCR(IRQS_NMI),
161087cdfb6SThomas Gleixner };
162087cdfb6SThomas Gleixner
163087cdfb6SThomas Gleixner
irq_debug_show(struct seq_file * m,void * p)164087cdfb6SThomas Gleixner static int irq_debug_show(struct seq_file *m, void *p)
165087cdfb6SThomas Gleixner {
166087cdfb6SThomas Gleixner struct irq_desc *desc = m->private;
167087cdfb6SThomas Gleixner struct irq_data *data;
168087cdfb6SThomas Gleixner
169087cdfb6SThomas Gleixner raw_spin_lock_irq(&desc->lock);
170087cdfb6SThomas Gleixner data = irq_desc_get_irq_data(desc);
171d75f773cSSakari Ailus seq_printf(m, "handler: %ps\n", desc->handle_irq);
17207557ccbSThomas Gleixner seq_printf(m, "device: %s\n", desc->dev_name);
173087cdfb6SThomas Gleixner seq_printf(m, "status: 0x%08x\n", desc->status_use_accessors);
174087cdfb6SThomas Gleixner irq_debug_show_bits(m, 0, desc->status_use_accessors, irqdesc_states,
175087cdfb6SThomas Gleixner ARRAY_SIZE(irqdesc_states));
176087cdfb6SThomas Gleixner seq_printf(m, "istate: 0x%08x\n", desc->istate);
177087cdfb6SThomas Gleixner irq_debug_show_bits(m, 0, desc->istate, irqdesc_istates,
178087cdfb6SThomas Gleixner ARRAY_SIZE(irqdesc_istates));
179087cdfb6SThomas Gleixner seq_printf(m, "ddepth: %u\n", desc->depth);
180087cdfb6SThomas Gleixner seq_printf(m, "wdepth: %u\n", desc->wake_depth);
181087cdfb6SThomas Gleixner seq_printf(m, "dstate: 0x%08x\n", irqd_get(data));
182087cdfb6SThomas Gleixner irq_debug_show_bits(m, 0, irqd_get(data), irqdata_states,
183087cdfb6SThomas Gleixner ARRAY_SIZE(irqdata_states));
184087cdfb6SThomas Gleixner seq_printf(m, "node: %d\n", irq_data_get_node(data));
185087cdfb6SThomas Gleixner irq_debug_show_masks(m, desc);
186087cdfb6SThomas Gleixner irq_debug_show_data(m, data, 0);
187087cdfb6SThomas Gleixner raw_spin_unlock_irq(&desc->lock);
188087cdfb6SThomas Gleixner return 0;
189087cdfb6SThomas Gleixner }
190087cdfb6SThomas Gleixner
irq_debug_open(struct inode * inode,struct file * file)191087cdfb6SThomas Gleixner static int irq_debug_open(struct inode *inode, struct file *file)
192087cdfb6SThomas Gleixner {
193087cdfb6SThomas Gleixner return single_open(file, irq_debug_show, inode->i_private);
194087cdfb6SThomas Gleixner }
195087cdfb6SThomas Gleixner
irq_debug_write(struct file * file,const char __user * user_buf,size_t count,loff_t * ppos)196536e2e34SMarc Zyngier static ssize_t irq_debug_write(struct file *file, const char __user *user_buf,
197536e2e34SMarc Zyngier size_t count, loff_t *ppos)
198536e2e34SMarc Zyngier {
199536e2e34SMarc Zyngier struct irq_desc *desc = file_inode(file)->i_private;
200536e2e34SMarc Zyngier char buf[8] = { 0, };
201536e2e34SMarc Zyngier size_t size;
202536e2e34SMarc Zyngier
203536e2e34SMarc Zyngier size = min(sizeof(buf) - 1, count);
204536e2e34SMarc Zyngier if (copy_from_user(buf, user_buf, size))
205536e2e34SMarc Zyngier return -EFAULT;
206536e2e34SMarc Zyngier
207536e2e34SMarc Zyngier if (!strncmp(buf, "trigger", size)) {
208acd26bcfSThomas Gleixner int err = irq_inject_interrupt(irq_desc_get_irq(desc));
209536e2e34SMarc Zyngier
210536e2e34SMarc Zyngier return err ? err : count;
211536e2e34SMarc Zyngier }
212536e2e34SMarc Zyngier
213536e2e34SMarc Zyngier return count;
214536e2e34SMarc Zyngier }
215536e2e34SMarc Zyngier
216087cdfb6SThomas Gleixner static const struct file_operations dfs_irq_ops = {
217087cdfb6SThomas Gleixner .open = irq_debug_open,
218536e2e34SMarc Zyngier .write = irq_debug_write,
219087cdfb6SThomas Gleixner .read = seq_read,
220087cdfb6SThomas Gleixner .llseek = seq_lseek,
221087cdfb6SThomas Gleixner .release = single_release,
222087cdfb6SThomas Gleixner };
223087cdfb6SThomas Gleixner
irq_debugfs_copy_devname(int irq,struct device * dev)22407557ccbSThomas Gleixner void irq_debugfs_copy_devname(int irq, struct device *dev)
22507557ccbSThomas Gleixner {
22607557ccbSThomas Gleixner struct irq_desc *desc = irq_to_desc(irq);
22707557ccbSThomas Gleixner const char *name = dev_name(dev);
22807557ccbSThomas Gleixner
22907557ccbSThomas Gleixner if (name)
23007557ccbSThomas Gleixner desc->dev_name = kstrdup(name, GFP_KERNEL);
23107557ccbSThomas Gleixner }
23207557ccbSThomas Gleixner
irq_add_debugfs_entry(unsigned int irq,struct irq_desc * desc)233087cdfb6SThomas Gleixner void irq_add_debugfs_entry(unsigned int irq, struct irq_desc *desc)
234087cdfb6SThomas Gleixner {
235087cdfb6SThomas Gleixner char name [10];
236087cdfb6SThomas Gleixner
237087cdfb6SThomas Gleixner if (!irq_dir || !desc || desc->debugfs_file)
238087cdfb6SThomas Gleixner return;
239087cdfb6SThomas Gleixner
240087cdfb6SThomas Gleixner sprintf(name, "%d", irq);
241536e2e34SMarc Zyngier desc->debugfs_file = debugfs_create_file(name, 0644, irq_dir, desc,
242087cdfb6SThomas Gleixner &dfs_irq_ops);
243087cdfb6SThomas Gleixner }
244087cdfb6SThomas Gleixner
irq_debugfs_init(void)245087cdfb6SThomas Gleixner static int __init irq_debugfs_init(void)
246087cdfb6SThomas Gleixner {
247087cdfb6SThomas Gleixner struct dentry *root_dir;
248087cdfb6SThomas Gleixner int irq;
249087cdfb6SThomas Gleixner
250087cdfb6SThomas Gleixner root_dir = debugfs_create_dir("irq", NULL);
251087cdfb6SThomas Gleixner
252087cdfb6SThomas Gleixner irq_domain_debugfs_init(root_dir);
253087cdfb6SThomas Gleixner
254087cdfb6SThomas Gleixner irq_dir = debugfs_create_dir("irqs", root_dir);
255087cdfb6SThomas Gleixner
256087cdfb6SThomas Gleixner irq_lock_sparse();
257087cdfb6SThomas Gleixner for_each_active_irq(irq)
258087cdfb6SThomas Gleixner irq_add_debugfs_entry(irq, irq_to_desc(irq));
259087cdfb6SThomas Gleixner irq_unlock_sparse();
260087cdfb6SThomas Gleixner
261087cdfb6SThomas Gleixner return 0;
262087cdfb6SThomas Gleixner }
263087cdfb6SThomas Gleixner __initcall(irq_debugfs_init);
264