mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/chenhuacai/linux-loongson
synced 2025-08-26 05:15:50 +00:00
Compare commits
5 Commits
ef59259df6
...
955853cf83
Author | SHA1 | Date | |
---|---|---|---|
![]() |
955853cf83 | ||
![]() |
cc8d5b209e | ||
![]() |
45515c643d | ||
![]() |
c34bbc2c99 | ||
![]() |
9159c5e733 |
@ -9,7 +9,8 @@
|
||||
|
||||
static void eiointc_set_sw_coreisr(struct loongarch_eiointc *s)
|
||||
{
|
||||
int ipnum, cpu, irq_index, irq_mask, irq;
|
||||
int ipnum, cpu, cpuid, irq_index, irq_mask, irq;
|
||||
struct kvm_vcpu *vcpu;
|
||||
|
||||
for (irq = 0; irq < EIOINTC_IRQS; irq++) {
|
||||
ipnum = s->ipmap.reg_u8[irq / 32];
|
||||
@ -20,7 +21,12 @@ static void eiointc_set_sw_coreisr(struct loongarch_eiointc *s)
|
||||
irq_index = irq / 32;
|
||||
irq_mask = BIT(irq & 0x1f);
|
||||
|
||||
cpu = s->coremap.reg_u8[irq];
|
||||
cpuid = s->coremap.reg_u8[irq];
|
||||
vcpu = kvm_get_vcpu_by_cpuid(s->kvm, cpuid);
|
||||
if (!vcpu)
|
||||
continue;
|
||||
|
||||
cpu = vcpu->vcpu_id;
|
||||
if (!!(s->coreisr.reg_u32[cpu][irq_index] & irq_mask))
|
||||
set_bit(irq, s->sw_coreisr[cpu][ipnum]);
|
||||
else
|
||||
@ -66,20 +72,25 @@ static void eiointc_update_irq(struct loongarch_eiointc *s, int irq, int level)
|
||||
}
|
||||
|
||||
static inline void eiointc_update_sw_coremap(struct loongarch_eiointc *s,
|
||||
int irq, void *pvalue, u32 len, bool notify)
|
||||
int irq, u64 val, u32 len, bool notify)
|
||||
{
|
||||
int i, cpu;
|
||||
u64 val = *(u64 *)pvalue;
|
||||
int i, cpu, cpuid;
|
||||
struct kvm_vcpu *vcpu;
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
cpu = val & 0xff;
|
||||
cpuid = val & 0xff;
|
||||
val = val >> 8;
|
||||
|
||||
if (!(s->status & BIT(EIOINTC_ENABLE_CPU_ENCODE))) {
|
||||
cpu = ffs(cpu) - 1;
|
||||
cpu = (cpu >= 4) ? 0 : cpu;
|
||||
cpuid = ffs(cpuid) - 1;
|
||||
cpuid = (cpuid >= 4) ? 0 : cpuid;
|
||||
}
|
||||
|
||||
vcpu = kvm_get_vcpu_by_cpuid(s->kvm, cpuid);
|
||||
if (!vcpu)
|
||||
continue;
|
||||
|
||||
cpu = vcpu->vcpu_id;
|
||||
if (s->sw_coremap[irq + i] == cpu)
|
||||
continue;
|
||||
|
||||
@ -305,6 +316,11 @@ static int kvm_eiointc_read(struct kvm_vcpu *vcpu,
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (addr & (len - 1)) {
|
||||
kvm_err("%s: eiointc not aligned addr %llx len %d\n", __func__, addr, len);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
vcpu->kvm->stat.eiointc_read_exits++;
|
||||
spin_lock_irqsave(&eiointc->lock, flags);
|
||||
switch (len) {
|
||||
@ -398,7 +414,7 @@ static int loongarch_eiointc_writeb(struct kvm_vcpu *vcpu,
|
||||
irq = offset - EIOINTC_COREMAP_START;
|
||||
index = irq;
|
||||
s->coremap.reg_u8[index] = data;
|
||||
eiointc_update_sw_coremap(s, irq, (void *)&data, sizeof(data), true);
|
||||
eiointc_update_sw_coremap(s, irq, data, sizeof(data), true);
|
||||
break;
|
||||
default:
|
||||
ret = -EINVAL;
|
||||
@ -483,7 +499,7 @@ static int loongarch_eiointc_writew(struct kvm_vcpu *vcpu,
|
||||
irq = offset - EIOINTC_COREMAP_START;
|
||||
index = irq >> 1;
|
||||
s->coremap.reg_u16[index] = data;
|
||||
eiointc_update_sw_coremap(s, irq, (void *)&data, sizeof(data), true);
|
||||
eiointc_update_sw_coremap(s, irq, data, sizeof(data), true);
|
||||
break;
|
||||
default:
|
||||
ret = -EINVAL;
|
||||
@ -568,7 +584,7 @@ static int loongarch_eiointc_writel(struct kvm_vcpu *vcpu,
|
||||
irq = offset - EIOINTC_COREMAP_START;
|
||||
index = irq >> 2;
|
||||
s->coremap.reg_u32[index] = data;
|
||||
eiointc_update_sw_coremap(s, irq, (void *)&data, sizeof(data), true);
|
||||
eiointc_update_sw_coremap(s, irq, data, sizeof(data), true);
|
||||
break;
|
||||
default:
|
||||
ret = -EINVAL;
|
||||
@ -653,7 +669,7 @@ static int loongarch_eiointc_writeq(struct kvm_vcpu *vcpu,
|
||||
irq = offset - EIOINTC_COREMAP_START;
|
||||
index = irq >> 3;
|
||||
s->coremap.reg_u64[index] = data;
|
||||
eiointc_update_sw_coremap(s, irq, (void *)&data, sizeof(data), true);
|
||||
eiointc_update_sw_coremap(s, irq, data, sizeof(data), true);
|
||||
break;
|
||||
default:
|
||||
ret = -EINVAL;
|
||||
@ -676,6 +692,11 @@ static int kvm_eiointc_write(struct kvm_vcpu *vcpu,
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (addr & (len - 1)) {
|
||||
kvm_err("%s: eiointc not aligned addr %llx len %d\n", __func__, addr, len);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
vcpu->kvm->stat.eiointc_write_exits++;
|
||||
spin_lock_irqsave(&eiointc->lock, flags);
|
||||
switch (len) {
|
||||
@ -784,7 +805,7 @@ static int kvm_eiointc_ctrl_access(struct kvm_device *dev,
|
||||
int ret = 0;
|
||||
unsigned long flags;
|
||||
unsigned long type = (unsigned long)attr->attr;
|
||||
u32 i, start_irq;
|
||||
u32 i, start_irq, val;
|
||||
void __user *data;
|
||||
struct loongarch_eiointc *s = dev->kvm->arch.eiointc;
|
||||
|
||||
@ -792,8 +813,14 @@ static int kvm_eiointc_ctrl_access(struct kvm_device *dev,
|
||||
spin_lock_irqsave(&s->lock, flags);
|
||||
switch (type) {
|
||||
case KVM_DEV_LOONGARCH_EXTIOI_CTRL_INIT_NUM_CPU:
|
||||
if (copy_from_user(&s->num_cpu, data, 4))
|
||||
if (copy_from_user(&val, data, 4))
|
||||
ret = -EFAULT;
|
||||
else {
|
||||
if (val >= EIOINTC_ROUTE_MAX_VCPUS)
|
||||
ret = -EINVAL;
|
||||
else
|
||||
s->num_cpu = val;
|
||||
}
|
||||
break;
|
||||
case KVM_DEV_LOONGARCH_EXTIOI_CTRL_INIT_FEATURE:
|
||||
if (copy_from_user(&s->features, data, 4))
|
||||
@ -806,7 +833,7 @@ static int kvm_eiointc_ctrl_access(struct kvm_device *dev,
|
||||
for (i = 0; i < (EIOINTC_IRQS / 4); i++) {
|
||||
start_irq = i * 4;
|
||||
eiointc_update_sw_coremap(s, start_irq,
|
||||
(void *)&s->coremap.reg_u32[i], sizeof(u32), false);
|
||||
s->coremap.reg_u32[i], sizeof(u32), false);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@ -821,7 +848,7 @@ static int kvm_eiointc_regs_access(struct kvm_device *dev,
|
||||
struct kvm_device_attr *attr,
|
||||
bool is_write)
|
||||
{
|
||||
int addr, cpuid, offset, ret = 0;
|
||||
int addr, cpu, offset, ret = 0;
|
||||
unsigned long flags;
|
||||
void *p = NULL;
|
||||
void __user *data;
|
||||
@ -829,7 +856,7 @@ static int kvm_eiointc_regs_access(struct kvm_device *dev,
|
||||
|
||||
s = dev->kvm->arch.eiointc;
|
||||
addr = attr->attr;
|
||||
cpuid = addr >> 16;
|
||||
cpu = addr >> 16;
|
||||
addr &= 0xffff;
|
||||
data = (void __user *)attr->addr;
|
||||
switch (addr) {
|
||||
@ -854,8 +881,11 @@ static int kvm_eiointc_regs_access(struct kvm_device *dev,
|
||||
p = &s->isr.reg_u32[offset];
|
||||
break;
|
||||
case EIOINTC_COREISR_START ... EIOINTC_COREISR_END:
|
||||
if (cpu >= s->num_cpu)
|
||||
return -EINVAL;
|
||||
|
||||
offset = (addr - EIOINTC_COREISR_START) / 4;
|
||||
p = &s->coreisr.reg_u32[cpuid][offset];
|
||||
p = &s->coreisr.reg_u32[cpu][offset];
|
||||
break;
|
||||
case EIOINTC_COREMAP_START ... EIOINTC_COREMAP_END:
|
||||
offset = (addr - EIOINTC_COREMAP_START) / 4;
|
||||
@ -896,9 +926,15 @@ static int kvm_eiointc_sw_status_access(struct kvm_device *dev,
|
||||
data = (void __user *)attr->addr;
|
||||
switch (addr) {
|
||||
case KVM_DEV_LOONGARCH_EXTIOI_SW_STATUS_NUM_CPU:
|
||||
if (is_write)
|
||||
return ret;
|
||||
|
||||
p = &s->num_cpu;
|
||||
break;
|
||||
case KVM_DEV_LOONGARCH_EXTIOI_SW_STATUS_FEATURE:
|
||||
if (is_write)
|
||||
return ret;
|
||||
|
||||
p = &s->features;
|
||||
break;
|
||||
case KVM_DEV_LOONGARCH_EXTIOI_SW_STATUS_STATE:
|
||||
|
Loading…
Reference in New Issue
Block a user