Commit 35b299e2 authored by Mihai Caraman's avatar Mihai Caraman Committed by Alexander Graf

KVM: PPC: Book3E: Refactor ONE_REG ioctl implementation

Refactor Book3E ONE_REG ioctl implementation to use kvmppc_get_one_reg/
kvmppc_set_one_reg delegation interface introduced by Book3S. This is
necessary for MMU SPRs which are platform specifics.

Get rid of useless case braces in the process.
Signed-off-by: default avatarMihai Caraman <mihai.caraman@freescale.com>
Signed-off-by: default avatarAlexander Graf <agraf@suse.de>
parent 9b4f5308
...@@ -124,6 +124,18 @@ int kvmppc_core_set_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs) ...@@ -124,6 +124,18 @@ int kvmppc_core_set_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs)
return kvmppc_set_sregs_ivor(vcpu, sregs); return kvmppc_set_sregs_ivor(vcpu, sregs);
} }
int kvmppc_get_one_reg(struct kvm_vcpu *vcpu, u64 id,
union kvmppc_one_reg *val)
{
return -EINVAL;
}
int kvmppc_set_one_reg(struct kvm_vcpu *vcpu, u64 id,
union kvmppc_one_reg *val)
{
return -EINVAL;
}
struct kvm_vcpu *kvmppc_core_vcpu_create(struct kvm *kvm, unsigned int id) struct kvm_vcpu *kvmppc_core_vcpu_create(struct kvm *kvm, unsigned int id)
{ {
struct kvmppc_vcpu_44x *vcpu_44x; struct kvmppc_vcpu_44x *vcpu_44x;
......
...@@ -1415,117 +1415,125 @@ int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu, ...@@ -1415,117 +1415,125 @@ int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu,
int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg) int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg)
{ {
int r = -EINVAL; int r = 0;
union kvmppc_one_reg val;
int size;
long int i;
size = one_reg_size(reg->id);
if (size > sizeof(val))
return -EINVAL;
switch (reg->id) { switch (reg->id) {
case KVM_REG_PPC_IAC1: case KVM_REG_PPC_IAC1:
case KVM_REG_PPC_IAC2: case KVM_REG_PPC_IAC2:
case KVM_REG_PPC_IAC3: case KVM_REG_PPC_IAC3:
case KVM_REG_PPC_IAC4: { case KVM_REG_PPC_IAC4:
int iac = reg->id - KVM_REG_PPC_IAC1; i = reg->id - KVM_REG_PPC_IAC1;
r = copy_to_user((u64 __user *)(long)reg->addr, val = get_reg_val(reg->id, vcpu->arch.dbg_reg.iac[i]);
&vcpu->arch.dbg_reg.iac[iac], sizeof(u64));
break; break;
}
case KVM_REG_PPC_DAC1: case KVM_REG_PPC_DAC1:
case KVM_REG_PPC_DAC2: { case KVM_REG_PPC_DAC2:
int dac = reg->id - KVM_REG_PPC_DAC1; i = reg->id - KVM_REG_PPC_DAC1;
r = copy_to_user((u64 __user *)(long)reg->addr, val = get_reg_val(reg->id, vcpu->arch.dbg_reg.dac[i]);
&vcpu->arch.dbg_reg.dac[dac], sizeof(u64));
break; break;
}
case KVM_REG_PPC_EPR: { case KVM_REG_PPC_EPR: {
u32 epr = get_guest_epr(vcpu); u32 epr = get_guest_epr(vcpu);
r = put_user(epr, (u32 __user *)(long)reg->addr); val = get_reg_val(reg->id, epr);
break; break;
} }
#if defined(CONFIG_64BIT) #if defined(CONFIG_64BIT)
case KVM_REG_PPC_EPCR: case KVM_REG_PPC_EPCR:
r = put_user(vcpu->arch.epcr, (u32 __user *)(long)reg->addr); val = get_reg_val(reg->id, vcpu->arch.epcr);
break; break;
#endif #endif
case KVM_REG_PPC_TCR: case KVM_REG_PPC_TCR:
r = put_user(vcpu->arch.tcr, (u32 __user *)(long)reg->addr); val = get_reg_val(reg->id, vcpu->arch.tcr);
break; break;
case KVM_REG_PPC_TSR: case KVM_REG_PPC_TSR:
r = put_user(vcpu->arch.tsr, (u32 __user *)(long)reg->addr); val = get_reg_val(reg->id, vcpu->arch.tsr);
break; break;
case KVM_REG_PPC_DEBUG_INST: { case KVM_REG_PPC_DEBUG_INST:
u32 opcode = KVMPPC_INST_EHPRIV; val = get_reg_val(reg->id, KVMPPC_INST_EHPRIV);
r = copy_to_user((u32 __user *)(long)reg->addr,
&opcode, sizeof(u32));
break; break;
}
default: default:
r = kvmppc_get_one_reg(vcpu, reg->id, &val);
break; break;
} }
if (r)
return r;
if (copy_to_user((char __user *)(unsigned long)reg->addr, &val, size))
r = -EFAULT;
return r; return r;
} }
int kvm_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg) int kvm_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg)
{ {
int r = -EINVAL; int r = 0;
union kvmppc_one_reg val;
int size;
long int i;
size = one_reg_size(reg->id);
if (size > sizeof(val))
return -EINVAL;
if (copy_from_user(&val, (char __user *)(unsigned long)reg->addr, size))
return -EFAULT;
switch (reg->id) { switch (reg->id) {
case KVM_REG_PPC_IAC1: case KVM_REG_PPC_IAC1:
case KVM_REG_PPC_IAC2: case KVM_REG_PPC_IAC2:
case KVM_REG_PPC_IAC3: case KVM_REG_PPC_IAC3:
case KVM_REG_PPC_IAC4: { case KVM_REG_PPC_IAC4:
int iac = reg->id - KVM_REG_PPC_IAC1; i = reg->id - KVM_REG_PPC_IAC1;
r = copy_from_user(&vcpu->arch.dbg_reg.iac[iac], vcpu->arch.dbg_reg.iac[i] = set_reg_val(reg->id, val);
(u64 __user *)(long)reg->addr, sizeof(u64));
break; break;
}
case KVM_REG_PPC_DAC1: case KVM_REG_PPC_DAC1:
case KVM_REG_PPC_DAC2: { case KVM_REG_PPC_DAC2:
int dac = reg->id - KVM_REG_PPC_DAC1; i = reg->id - KVM_REG_PPC_DAC1;
r = copy_from_user(&vcpu->arch.dbg_reg.dac[dac], vcpu->arch.dbg_reg.dac[i] = set_reg_val(reg->id, val);
(u64 __user *)(long)reg->addr, sizeof(u64));
break; break;
}
case KVM_REG_PPC_EPR: { case KVM_REG_PPC_EPR: {
u32 new_epr; u32 new_epr = set_reg_val(reg->id, val);
r = get_user(new_epr, (u32 __user *)(long)reg->addr); kvmppc_set_epr(vcpu, new_epr);
if (!r)
kvmppc_set_epr(vcpu, new_epr);
break; break;
} }
#if defined(CONFIG_64BIT) #if defined(CONFIG_64BIT)
case KVM_REG_PPC_EPCR: { case KVM_REG_PPC_EPCR: {
u32 new_epcr; u32 new_epcr = set_reg_val(reg->id, val);
r = get_user(new_epcr, (u32 __user *)(long)reg->addr); kvmppc_set_epcr(vcpu, new_epcr);
if (r == 0)
kvmppc_set_epcr(vcpu, new_epcr);
break; break;
} }
#endif #endif
case KVM_REG_PPC_OR_TSR: { case KVM_REG_PPC_OR_TSR: {
u32 tsr_bits; u32 tsr_bits = set_reg_val(reg->id, val);
r = get_user(tsr_bits, (u32 __user *)(long)reg->addr);
kvmppc_set_tsr_bits(vcpu, tsr_bits); kvmppc_set_tsr_bits(vcpu, tsr_bits);
break; break;
} }
case KVM_REG_PPC_CLEAR_TSR: { case KVM_REG_PPC_CLEAR_TSR: {
u32 tsr_bits; u32 tsr_bits = set_reg_val(reg->id, val);
r = get_user(tsr_bits, (u32 __user *)(long)reg->addr);
kvmppc_clr_tsr_bits(vcpu, tsr_bits); kvmppc_clr_tsr_bits(vcpu, tsr_bits);
break; break;
} }
case KVM_REG_PPC_TSR: { case KVM_REG_PPC_TSR: {
u32 tsr; u32 tsr = set_reg_val(reg->id, val);
r = get_user(tsr, (u32 __user *)(long)reg->addr);
kvmppc_set_tsr(vcpu, tsr); kvmppc_set_tsr(vcpu, tsr);
break; break;
} }
case KVM_REG_PPC_TCR: { case KVM_REG_PPC_TCR: {
u32 tcr; u32 tcr = set_reg_val(reg->id, val);
r = get_user(tcr, (u32 __user *)(long)reg->addr);
kvmppc_set_tcr(vcpu, tcr); kvmppc_set_tcr(vcpu, tcr);
break; break;
} }
default: default:
r = kvmppc_set_one_reg(vcpu, reg->id, &val);
break; break;
} }
return r; return r;
} }
......
...@@ -425,6 +425,18 @@ int kvmppc_core_set_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs) ...@@ -425,6 +425,18 @@ int kvmppc_core_set_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs)
return kvmppc_set_sregs_ivor(vcpu, sregs); return kvmppc_set_sregs_ivor(vcpu, sregs);
} }
int kvmppc_get_one_reg(struct kvm_vcpu *vcpu, u64 id,
union kvmppc_one_reg *val)
{
return -EINVAL;
}
int kvmppc_set_one_reg(struct kvm_vcpu *vcpu, u64 id,
union kvmppc_one_reg *val)
{
return -EINVAL;
}
struct kvm_vcpu *kvmppc_core_vcpu_create(struct kvm *kvm, unsigned int id) struct kvm_vcpu *kvmppc_core_vcpu_create(struct kvm *kvm, unsigned int id)
{ {
struct kvmppc_vcpu_e500 *vcpu_e500; struct kvmppc_vcpu_e500 *vcpu_e500;
......
...@@ -255,6 +255,18 @@ int kvmppc_core_set_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs) ...@@ -255,6 +255,18 @@ int kvmppc_core_set_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs)
return kvmppc_set_sregs_ivor(vcpu, sregs); return kvmppc_set_sregs_ivor(vcpu, sregs);
} }
int kvmppc_get_one_reg(struct kvm_vcpu *vcpu, u64 id,
union kvmppc_one_reg *val)
{
return -EINVAL;
}
int kvmppc_set_one_reg(struct kvm_vcpu *vcpu, u64 id,
union kvmppc_one_reg *val)
{
return -EINVAL;
}
struct kvm_vcpu *kvmppc_core_vcpu_create(struct kvm *kvm, unsigned int id) struct kvm_vcpu *kvmppc_core_vcpu_create(struct kvm *kvm, unsigned int id)
{ {
struct kvmppc_vcpu_e500 *vcpu_e500; struct kvmppc_vcpu_e500 *vcpu_e500;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment