1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright (C) 2020-2022 Loongson Technology Corporation Limited
4  */
5 
6 #include <linux/debugfs.h>
7 #include <linux/kvm_host.h>
8 #include <linux/seq_file.h>
9 #include "kvmcpu.h"
10 #include "ls3a_ext_irq.h"
11 #include "ls7a_irq.h"
12 
13 #ifdef CONFIG_DEBUG_FS
irqchip_state_show(struct seq_file *m, void *v)14 static int irqchip_state_show(struct seq_file *m, void *v)
15 {
16 	struct kvm *kvm = m->private;
17 
18 	kvm_get_kvm(kvm);
19 	kvm_dump_ls3a_extirq_state(m, kvm->arch.v_extirq);
20 	kvm_dump_ls7a_ioapic_state(m, kvm->arch.v_ioapic);
21 	kvm_put_kvm(kvm);
22 
23 	return 0;
24 }
25 
irqchip_debug_open(struct inode *inode, struct file *file)26 static int irqchip_debug_open(struct inode *inode, struct file *file)
27 {
28 	return single_open(file, irqchip_state_show, inode->i_private);
29 }
30 
31 static const struct file_operations irqchip_debug_fops = {
32 	.open       = irqchip_debug_open,
33 	.read       = seq_read,
34 	.llseek     = seq_lseek,
35 	.release    = single_release,
36 };
37 
irqchip_debug_init(struct kvm *kvm)38 void irqchip_debug_init(struct kvm *kvm)
39 {
40 	debugfs_create_file("irqchip-state", 0444, kvm->debugfs_dentry, kvm,
41 			    &irqchip_debug_fops);
42 }
43 #else
44 
irqchip_debug_init(struct kvm *kvm)45 void irqchip_debug_init(struct kvm *kvm) {}
46 #endif
irqchip_debug_destroy(struct kvm *kvm)47 void irqchip_debug_destroy(struct kvm *kvm)
48 {
49 }
50