diff options
author | Mihai Caraman <mihai.caraman@freescale.com> | 2013-04-10 20:03:07 -0400 |
---|---|---|
committer | Alexander Graf <agraf@suse.de> | 2013-04-26 14:27:05 -0400 |
commit | 35b299e279eb5bc4622ec883b5f388c3224cbd61 (patch) | |
tree | dc67ad97836eaf77819a982f7ddd3c5f47e4dfab /arch/powerpc | |
parent | 9b4f530807e4243d8c4bc02c5bbd5b9e3e2ed9e0 (diff) |
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: Mihai Caraman <mihai.caraman@freescale.com>
Signed-off-by: Alexander Graf <agraf@suse.de>
Diffstat (limited to 'arch/powerpc')
-rw-r--r-- | arch/powerpc/kvm/44x.c | 12 | ||||
-rw-r--r-- | arch/powerpc/kvm/booke.c | 102 | ||||
-rw-r--r-- | arch/powerpc/kvm/e500.c | 12 | ||||
-rw-r--r-- | arch/powerpc/kvm/e500mc.c | 12 |
4 files changed, 91 insertions, 47 deletions
diff --git a/arch/powerpc/kvm/44x.c b/arch/powerpc/kvm/44x.c index 3d7fd21c65f9..2f5c6b6d6877 100644 --- a/arch/powerpc/kvm/44x.c +++ b/arch/powerpc/kvm/44x.c | |||
@@ -124,6 +124,18 @@ int kvmppc_core_set_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs) | |||
124 | return kvmppc_set_sregs_ivor(vcpu, sregs); | 124 | return kvmppc_set_sregs_ivor(vcpu, sregs); |
125 | } | 125 | } |
126 | 126 | ||
127 | int kvmppc_get_one_reg(struct kvm_vcpu *vcpu, u64 id, | ||
128 | union kvmppc_one_reg *val) | ||
129 | { | ||
130 | return -EINVAL; | ||
131 | } | ||
132 | |||
133 | int kvmppc_set_one_reg(struct kvm_vcpu *vcpu, u64 id, | ||
134 | union kvmppc_one_reg *val) | ||
135 | { | ||
136 | return -EINVAL; | ||
137 | } | ||
138 | |||
127 | struct kvm_vcpu *kvmppc_core_vcpu_create(struct kvm *kvm, unsigned int id) | 139 | struct kvm_vcpu *kvmppc_core_vcpu_create(struct kvm *kvm, unsigned int id) |
128 | { | 140 | { |
129 | struct kvmppc_vcpu_44x *vcpu_44x; | 141 | struct kvmppc_vcpu_44x *vcpu_44x; |
diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c index 97ae158ca4c8..02756537cd90 100644 --- a/arch/powerpc/kvm/booke.c +++ b/arch/powerpc/kvm/booke.c | |||
@@ -1415,117 +1415,125 @@ int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu, | |||
1415 | 1415 | ||
1416 | int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg) | 1416 | int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg) |
1417 | { | 1417 | { |
1418 | int r = -EINVAL; | 1418 | int r = 0; |
1419 | union kvmppc_one_reg val; | ||
1420 | int size; | ||
1421 | long int i; | ||
1422 | |||
1423 | size = one_reg_size(reg->id); | ||
1424 | if (size > sizeof(val)) | ||
1425 | return -EINVAL; | ||
1419 | 1426 | ||
1420 | switch (reg->id) { | 1427 | switch (reg->id) { |
1421 | case KVM_REG_PPC_IAC1: | 1428 | case KVM_REG_PPC_IAC1: |
1422 | case KVM_REG_PPC_IAC2: | 1429 | case KVM_REG_PPC_IAC2: |
1423 | case KVM_REG_PPC_IAC3: | 1430 | case KVM_REG_PPC_IAC3: |
1424 | case KVM_REG_PPC_IAC4: { | 1431 | case KVM_REG_PPC_IAC4: |
1425 | int iac = reg->id - KVM_REG_PPC_IAC1; | 1432 | i = reg->id - KVM_REG_PPC_IAC1; |
1426 | r = copy_to_user((u64 __user *)(long)reg->addr, | 1433 | val = get_reg_val(reg->id, vcpu->arch.dbg_reg.iac[i]); |
1427 | &vcpu->arch.dbg_reg.iac[iac], sizeof(u64)); | ||
1428 | break; | 1434 | break; |
1429 | } | ||
1430 | case KVM_REG_PPC_DAC1: | 1435 | case KVM_REG_PPC_DAC1: |
1431 | case KVM_REG_PPC_DAC2: { | 1436 | case KVM_REG_PPC_DAC2: |
1432 | int dac = reg->id - KVM_REG_PPC_DAC1; | 1437 | i = reg->id - KVM_REG_PPC_DAC1; |
1433 | r = copy_to_user((u64 __user *)(long)reg->addr, | 1438 | val = get_reg_val(reg->id, vcpu->arch.dbg_reg.dac[i]); |
1434 | &vcpu->arch.dbg_reg.dac[dac], sizeof(u64)); | ||
1435 | break; | 1439 | break; |
1436 | } | ||
1437 | case KVM_REG_PPC_EPR: { | 1440 | case KVM_REG_PPC_EPR: { |
1438 | u32 epr = get_guest_epr(vcpu); | 1441 | u32 epr = get_guest_epr(vcpu); |
1439 | r = put_user(epr, (u32 __user *)(long)reg->addr); | 1442 | val = get_reg_val(reg->id, epr); |
1440 | break; | 1443 | break; |
1441 | } | 1444 | } |
1442 | #if defined(CONFIG_64BIT) | 1445 | #if defined(CONFIG_64BIT) |
1443 | case KVM_REG_PPC_EPCR: | 1446 | case KVM_REG_PPC_EPCR: |
1444 | r = put_user(vcpu->arch.epcr, (u32 __user *)(long)reg->addr); | 1447 | val = get_reg_val(reg->id, vcpu->arch.epcr); |
1445 | break; | 1448 | break; |
1446 | #endif | 1449 | #endif |
1447 | case KVM_REG_PPC_TCR: | 1450 | case KVM_REG_PPC_TCR: |
1448 | r = put_user(vcpu->arch.tcr, (u32 __user *)(long)reg->addr); | 1451 | val = get_reg_val(reg->id, vcpu->arch.tcr); |
1449 | break; | 1452 | break; |
1450 | case KVM_REG_PPC_TSR: | 1453 | case KVM_REG_PPC_TSR: |
1451 | r = put_user(vcpu->arch.tsr, (u32 __user *)(long)reg->addr); | 1454 | val = get_reg_val(reg->id, vcpu->arch.tsr); |
1452 | break; | 1455 | break; |
1453 | case KVM_REG_PPC_DEBUG_INST: { | 1456 | case KVM_REG_PPC_DEBUG_INST: |
1454 | u32 opcode = KVMPPC_INST_EHPRIV; | 1457 | val = get_reg_val(reg->id, KVMPPC_INST_EHPRIV); |
1455 | r = copy_to_user((u32 __user *)(long)reg->addr, | ||
1456 | &opcode, sizeof(u32)); | ||
1457 | break; | 1458 | break; |
1458 | } | ||
1459 | default: | 1459 | default: |
1460 | r = kvmppc_get_one_reg(vcpu, reg->id, &val); | ||
1460 | break; | 1461 | break; |
1461 | } | 1462 | } |
1463 | |||
1464 | if (r) | ||
1465 | return r; | ||
1466 | |||
1467 | if (copy_to_user((char __user *)(unsigned long)reg->addr, &val, size)) | ||
1468 | r = -EFAULT; | ||
1469 | |||
1462 | return r; | 1470 | return r; |
1463 | } | 1471 | } |
1464 | 1472 | ||
1465 | int kvm_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg) | 1473 | int kvm_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg) |
1466 | { | 1474 | { |
1467 | int r = -EINVAL; | 1475 | int r = 0; |
1476 | union kvmppc_one_reg val; | ||
1477 | int size; | ||
1478 | long int i; | ||
1479 | |||
1480 | size = one_reg_size(reg->id); | ||
1481 | if (size > sizeof(val)) | ||
1482 | return -EINVAL; | ||
1483 | |||
1484 | if (copy_from_user(&val, (char __user *)(unsigned long)reg->addr, size)) | ||
1485 | return -EFAULT; | ||
1468 | 1486 | ||
1469 | switch (reg->id) { | 1487 | switch (reg->id) { |
1470 | case KVM_REG_PPC_IAC1: | 1488 | case KVM_REG_PPC_IAC1: |
1471 | case KVM_REG_PPC_IAC2: | 1489 | case KVM_REG_PPC_IAC2: |
1472 | case KVM_REG_PPC_IAC3: | 1490 | case KVM_REG_PPC_IAC3: |
1473 | case KVM_REG_PPC_IAC4: { | 1491 | case KVM_REG_PPC_IAC4: |
1474 | int iac = reg->id - KVM_REG_PPC_IAC1; | 1492 | i = reg->id - KVM_REG_PPC_IAC1; |
1475 | r = copy_from_user(&vcpu->arch.dbg_reg.iac[iac], | 1493 | vcpu->arch.dbg_reg.iac[i] = set_reg_val(reg->id, val); |
1476 | (u64 __user *)(long)reg->addr, sizeof(u64)); | ||
1477 | break; | 1494 | break; |
1478 | } | ||
1479 | case KVM_REG_PPC_DAC1: | 1495 | case KVM_REG_PPC_DAC1: |
1480 | case KVM_REG_PPC_DAC2: { | 1496 | case KVM_REG_PPC_DAC2: |
1481 | int dac = reg->id - KVM_REG_PPC_DAC1; | 1497 | i = reg->id - KVM_REG_PPC_DAC1; |
1482 | r = copy_from_user(&vcpu->arch.dbg_reg.dac[dac], | 1498 | vcpu->arch.dbg_reg.dac[i] = set_reg_val(reg->id, val); |
1483 | (u64 __user *)(long)reg->addr, sizeof(u64)); | ||
1484 | break; | 1499 | break; |
1485 | } | ||
1486 | case KVM_REG_PPC_EPR: { | 1500 | case KVM_REG_PPC_EPR: { |
1487 | u32 new_epr; | 1501 | u32 new_epr = set_reg_val(reg->id, val); |
1488 | r = get_user(new_epr, (u32 __user *)(long)reg->addr); | 1502 | kvmppc_set_epr(vcpu, new_epr); |
1489 | if (!r) | ||
1490 | kvmppc_set_epr(vcpu, new_epr); | ||
1491 | break; | 1503 | break; |
1492 | } | 1504 | } |
1493 | #if defined(CONFIG_64BIT) | 1505 | #if defined(CONFIG_64BIT) |
1494 | case KVM_REG_PPC_EPCR: { | 1506 | case KVM_REG_PPC_EPCR: { |
1495 | u32 new_epcr; | 1507 | u32 new_epcr = set_reg_val(reg->id, val); |
1496 | r = get_user(new_epcr, (u32 __user *)(long)reg->addr); | 1508 | kvmppc_set_epcr(vcpu, new_epcr); |
1497 | if (r == 0) | ||
1498 | kvmppc_set_epcr(vcpu, new_epcr); | ||
1499 | break; | 1509 | break; |
1500 | } | 1510 | } |
1501 | #endif | 1511 | #endif |
1502 | case KVM_REG_PPC_OR_TSR: { | 1512 | case KVM_REG_PPC_OR_TSR: { |
1503 | u32 tsr_bits; | 1513 | u32 tsr_bits = set_reg_val(reg->id, val); |
1504 | r = get_user(tsr_bits, (u32 __user *)(long)reg->addr); | ||
1505 | kvmppc_set_tsr_bits(vcpu, tsr_bits); | 1514 | kvmppc_set_tsr_bits(vcpu, tsr_bits); |
1506 | break; | 1515 | break; |
1507 | } | 1516 | } |
1508 | case KVM_REG_PPC_CLEAR_TSR: { | 1517 | case KVM_REG_PPC_CLEAR_TSR: { |
1509 | u32 tsr_bits; | 1518 | u32 tsr_bits = set_reg_val(reg->id, val); |
1510 | r = get_user(tsr_bits, (u32 __user *)(long)reg->addr); | ||
1511 | kvmppc_clr_tsr_bits(vcpu, tsr_bits); | 1519 | kvmppc_clr_tsr_bits(vcpu, tsr_bits); |
1512 | break; | 1520 | break; |
1513 | } | 1521 | } |
1514 | case KVM_REG_PPC_TSR: { | 1522 | case KVM_REG_PPC_TSR: { |
1515 | u32 tsr; | 1523 | u32 tsr = set_reg_val(reg->id, val); |
1516 | r = get_user(tsr, (u32 __user *)(long)reg->addr); | ||
1517 | kvmppc_set_tsr(vcpu, tsr); | 1524 | kvmppc_set_tsr(vcpu, tsr); |
1518 | break; | 1525 | break; |
1519 | } | 1526 | } |
1520 | case KVM_REG_PPC_TCR: { | 1527 | case KVM_REG_PPC_TCR: { |
1521 | u32 tcr; | 1528 | u32 tcr = set_reg_val(reg->id, val); |
1522 | r = get_user(tcr, (u32 __user *)(long)reg->addr); | ||
1523 | kvmppc_set_tcr(vcpu, tcr); | 1529 | kvmppc_set_tcr(vcpu, tcr); |
1524 | break; | 1530 | break; |
1525 | } | 1531 | } |
1526 | default: | 1532 | default: |
1533 | r = kvmppc_set_one_reg(vcpu, reg->id, &val); | ||
1527 | break; | 1534 | break; |
1528 | } | 1535 | } |
1536 | |||
1529 | return r; | 1537 | return r; |
1530 | } | 1538 | } |
1531 | 1539 | ||
diff --git a/arch/powerpc/kvm/e500.c b/arch/powerpc/kvm/e500.c index 6dd4de7802bf..576010f6c27d 100644 --- a/arch/powerpc/kvm/e500.c +++ b/arch/powerpc/kvm/e500.c | |||
@@ -425,6 +425,18 @@ int kvmppc_core_set_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs) | |||
425 | return kvmppc_set_sregs_ivor(vcpu, sregs); | 425 | return kvmppc_set_sregs_ivor(vcpu, sregs); |
426 | } | 426 | } |
427 | 427 | ||
428 | int kvmppc_get_one_reg(struct kvm_vcpu *vcpu, u64 id, | ||
429 | union kvmppc_one_reg *val) | ||
430 | { | ||
431 | return -EINVAL; | ||
432 | } | ||
433 | |||
434 | int kvmppc_set_one_reg(struct kvm_vcpu *vcpu, u64 id, | ||
435 | union kvmppc_one_reg *val) | ||
436 | { | ||
437 | return -EINVAL; | ||
438 | } | ||
439 | |||
428 | struct kvm_vcpu *kvmppc_core_vcpu_create(struct kvm *kvm, unsigned int id) | 440 | struct kvm_vcpu *kvmppc_core_vcpu_create(struct kvm *kvm, unsigned int id) |
429 | { | 441 | { |
430 | struct kvmppc_vcpu_e500 *vcpu_e500; | 442 | struct kvmppc_vcpu_e500 *vcpu_e500; |
diff --git a/arch/powerpc/kvm/e500mc.c b/arch/powerpc/kvm/e500mc.c index 1f89d26e65fb..b071bdcbe37d 100644 --- a/arch/powerpc/kvm/e500mc.c +++ b/arch/powerpc/kvm/e500mc.c | |||
@@ -255,6 +255,18 @@ int kvmppc_core_set_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs) | |||
255 | return kvmppc_set_sregs_ivor(vcpu, sregs); | 255 | return kvmppc_set_sregs_ivor(vcpu, sregs); |
256 | } | 256 | } |
257 | 257 | ||
258 | int kvmppc_get_one_reg(struct kvm_vcpu *vcpu, u64 id, | ||
259 | union kvmppc_one_reg *val) | ||
260 | { | ||
261 | return -EINVAL; | ||
262 | } | ||
263 | |||
264 | int kvmppc_set_one_reg(struct kvm_vcpu *vcpu, u64 id, | ||
265 | union kvmppc_one_reg *val) | ||
266 | { | ||
267 | return -EINVAL; | ||
268 | } | ||
269 | |||
258 | struct kvm_vcpu *kvmppc_core_vcpu_create(struct kvm *kvm, unsigned int id) | 270 | struct kvm_vcpu *kvmppc_core_vcpu_create(struct kvm *kvm, unsigned int id) |
259 | { | 271 | { |
260 | struct kvmppc_vcpu_e500 *vcpu_e500; | 272 | struct kvmppc_vcpu_e500 *vcpu_e500; |