Skip to content

Commit 2f412eb

Browse files
bibo-maochenhuacai
authored andcommitted
LoongArch: KVM: Set version information at initial stage
Register PCH_PIC_INT_ID constains version and supported irq number information, and it is a read only register. The detailed value can be set at initial stage, rather than read callback. Signed-off-by: Bibo Mao <[email protected]> Signed-off-by: Huacai Chen <[email protected]>
1 parent 3da2b0d commit 2f412eb

2 files changed

Lines changed: 32 additions & 10 deletions

File tree

arch/loongarch/include/asm/kvm_pch_pic.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,26 @@
3434
#define PCH_PIC_INT_ISR_END 0x3af
3535
#define PCH_PIC_POLARITY_START 0x3e0
3636
#define PCH_PIC_POLARITY_END 0x3e7
37-
#define PCH_PIC_INT_ID_VAL 0x7000000UL
37+
#define PCH_PIC_INT_ID_VAL 0x7UL
3838
#define PCH_PIC_INT_ID_VER 0x1UL
3939

40+
union pch_pic_id {
41+
struct {
42+
uint8_t reserved_0[3];
43+
uint8_t id;
44+
uint8_t version;
45+
uint8_t reserved_1;
46+
uint8_t irq_num;
47+
uint8_t reserved_2;
48+
} desc;
49+
uint64_t data;
50+
};
51+
4052
struct loongarch_pch_pic {
4153
spinlock_t lock;
4254
struct kvm *kvm;
4355
struct kvm_io_device device;
56+
union pch_pic_id id;
4457
uint64_t mask; /* 1:disable irq, 0:enable irq */
4558
uint64_t htmsi_en; /* 1:msi */
4659
uint64_t edge; /* 1:edge triggered, 0:level triggered */

arch/loongarch/kvm/intc/pch_pic.c

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -120,20 +120,13 @@ static int loongarch_pch_pic_read(struct loongarch_pch_pic *s, gpa_t addr, int l
120120
{
121121
int offset, index, ret = 0;
122122
u32 data = 0;
123-
u64 int_id = 0;
124123

125124
offset = addr - s->pch_pic_base;
126125

127126
spin_lock(&s->lock);
128127
switch (offset) {
129128
case PCH_PIC_INT_ID_START ... PCH_PIC_INT_ID_END:
130-
/* int id version */
131-
int_id |= (u64)PCH_PIC_INT_ID_VER << 32;
132-
/* irq number */
133-
int_id |= (u64)31 << (32 + 16);
134-
/* int id value */
135-
int_id |= PCH_PIC_INT_ID_VAL;
136-
*(u64 *)val = int_id;
129+
*(u64 *)val = s->id.data;
137130
break;
138131
case PCH_PIC_MASK_START ... PCH_PIC_MASK_END:
139132
offset -= PCH_PIC_MASK_START;
@@ -484,7 +477,7 @@ static int kvm_setup_default_irq_routing(struct kvm *kvm)
484477

485478
static int kvm_pch_pic_create(struct kvm_device *dev, u32 type)
486479
{
487-
int ret;
480+
int i, ret, irq_num;
488481
struct kvm *kvm = dev->kvm;
489482
struct loongarch_pch_pic *s;
490483

@@ -500,6 +493,22 @@ static int kvm_pch_pic_create(struct kvm_device *dev, u32 type)
500493
if (!s)
501494
return -ENOMEM;
502495

496+
/*
497+
* Interrupt controller identification register 1
498+
* Bit 24-31 Interrupt Controller ID
499+
* Interrupt controller identification register 2
500+
* Bit 0-7 Interrupt Controller version number
501+
* Bit 16-23 The number of interrupt sources supported
502+
*/
503+
irq_num = 32;
504+
s->mask = -1UL;
505+
s->id.desc.id = PCH_PIC_INT_ID_VAL;
506+
s->id.desc.version = PCH_PIC_INT_ID_VER;
507+
s->id.desc.irq_num = irq_num - 1;
508+
for (i = 0; i < irq_num; i++) {
509+
s->route_entry[i] = 1;
510+
s->htmsi_vector[i] = i;
511+
}
503512
spin_lock_init(&s->lock);
504513
s->kvm = kvm;
505514
kvm->arch.pch_pic = s;

0 commit comments

Comments
 (0)