[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[qemu-s390x] [PULL 22/46] s390x/pci: factor out endianess conversion
From: |
Cornelia Huck |
Subject: |
[qemu-s390x] [PULL 22/46] s390x/pci: factor out endianess conversion |
Date: |
Thu, 14 Dec 2017 18:09:40 +0100 |
From: Pierre Morel <address@hidden>
There are two places where the same endianness conversion
is done.
Let's factor this out into a static function.
Note that the conversion must always be done for data in a register:
The S390 BE guest converted date to le before issuing the instruction.
After interception in a BE host:
ZPCI VFIO using pwrite must make the conversion back for the BE kernel.
Kernel will do BE to le translation when loading the register for the
real instruction.
After interception in a le host:
TCG stores a BE register in le, swapping bytes.
But since the data in the register was already le it is now BE
ZPCI VFIO must convert it to le before writing to the PCI memory.
In both cases ZPCI VFIO must swap the bytes from the register.
Signed-off-by: Pierre Morel <address@hidden>
Reviewed-by: Yi Min Zhao <address@hidden>
Message-Id: <address@hidden>
Signed-off-by: Cornelia Huck <address@hidden>
---
hw/s390x/s390-pci-inst.c | 58 ++++++++++++++++++++++++++----------------------
1 file changed, 32 insertions(+), 26 deletions(-)
diff --git a/hw/s390x/s390-pci-inst.c b/hw/s390x/s390-pci-inst.c
index 6f41083244..cb84d209e0 100644
--- a/hw/s390x/s390-pci-inst.c
+++ b/hw/s390x/s390-pci-inst.c
@@ -318,6 +318,36 @@ out:
return 0;
}
+/**
+ * Swap data contained in s390x big endian registers to little endian
+ * PCI bars.
+ *
+ * @ptr: a pointer to a uint64_t data field
+ * @len: the length of the valid data, must be 1,2,4 or 8
+ */
+static int zpci_endian_swap(uint64_t *ptr, uint8_t len)
+{
+ uint64_t data = *ptr;
+
+ switch (len) {
+ case 1:
+ break;
+ case 2:
+ data = bswap16(data);
+ break;
+ case 4:
+ data = bswap32(data);
+ break;
+ case 8:
+ data = bswap64(data);
+ break;
+ default:
+ return -EINVAL;
+ }
+ *ptr = data;
+ return 0;
+}
+
int pcilg_service_call(S390CPU *cpu, uint8_t r1, uint8_t r2, uintptr_t ra)
{
CPUS390XState *env = &cpu->env;
@@ -389,19 +419,7 @@ int pcilg_service_call(S390CPU *cpu, uint8_t r1, uint8_t
r2, uintptr_t ra)
data = pci_host_config_read_common(
pbdev->pdev, offset, pci_config_size(pbdev->pdev), len);
- switch (len) {
- case 1:
- break;
- case 2:
- data = bswap16(data);
- break;
- case 4:
- data = bswap32(data);
- break;
- case 8:
- data = bswap64(data);
- break;
- default:
+ if (zpci_endian_swap(&data, len)) {
s390_program_interrupt(env, PGM_OPERAND, 4, ra);
return 0;
}
@@ -504,19 +522,7 @@ int pcistg_service_call(S390CPU *cpu, uint8_t r1, uint8_t
r2, uintptr_t ra)
s390_program_interrupt(env, PGM_OPERAND, 4, ra);
return 0;
}
- switch (len) {
- case 1:
- break;
- case 2:
- data = bswap16(data);
- break;
- case 4:
- data = bswap32(data);
- break;
- case 8:
- data = bswap64(data);
- break;
- default:
+ if (zpci_endian_swap(&data, len)) {
s390_program_interrupt(env, PGM_OPERAND, 4, ra);
return 0;
}
--
2.13.6
- [qemu-s390x] [PULL 12/46] s390x: handle exceptions during s390_cpu_virt_mem_rw() correctly (TCG), (continued)
- [qemu-s390x] [PULL 12/46] s390x: handle exceptions during s390_cpu_virt_mem_rw() correctly (TCG), Cornelia Huck, 2017/12/14
- [qemu-s390x] [PULL 13/46] s390x/tcg: don't exit the cpu loop in s390_cpu_virt_mem_rw(), Cornelia Huck, 2017/12/14
- [qemu-s390x] [PULL 14/46] s390x/tcg: io instructions don't need potential_page_fault(), Cornelia Huck, 2017/12/14
- [qemu-s390x] [PULL 15/46] s390x/tcg: use s390_program_interrupt() in SCLP Service Call, Cornelia Huck, 2017/12/14
- [qemu-s390x] [PULL 16/46] s390x/tcg: use s390_program_interrupt() in DIAG, Cornelia Huck, 2017/12/14
- [qemu-s390x] [PULL 17/46] s390x/tcg: use s390_program_interrupt() in per_check_exception(), Cornelia Huck, 2017/12/14
- [qemu-s390x] [PULL 18/46] s390x/tcg: use s390_program_interrupt() in SACF, Cornelia Huck, 2017/12/14
- [qemu-s390x] [PULL 19/46] s390x/tcg: use s390_program_interrupt() in STSI, Cornelia Huck, 2017/12/14
- [qemu-s390x] [PULL 20/46] s390x/tcg: drop program_interrupt(), Cornelia Huck, 2017/12/14
- [qemu-s390x] [PULL 21/46] s390x/tcg: drop potential_page_fault(), Cornelia Huck, 2017/12/14
- [qemu-s390x] [PULL 22/46] s390x/pci: factor out endianess conversion,
Cornelia Huck <=
- [qemu-s390x] [PULL 23/46] s390x/pci: rework PCI STORE, Cornelia Huck, 2017/12/14
- [qemu-s390x] [PULL 24/46] s390x/pci: rework PCI LOAD, Cornelia Huck, 2017/12/14
- [qemu-s390x] [PULL 25/46] s390x/pci: rework PCI STORE BLOCK, Cornelia Huck, 2017/12/14
- [qemu-s390x] [PULL 26/46] s390x/pci: move the memory region read from pcilg, Cornelia Huck, 2017/12/14
- [qemu-s390x] [PULL 27/46] s390x/pci: move the memory region write from pcistg, Cornelia Huck, 2017/12/14
- [qemu-s390x] [PULL 28/46] s390x/pci: search for subregion inside the BARs, Cornelia Huck, 2017/12/14
- [qemu-s390x] [PULL 29/46] s390x/css: unrestrict cssids, Cornelia Huck, 2017/12/14
- [qemu-s390x] [PULL 30/46] s390x: deprecate s390-squash-mcss machine prop, Cornelia Huck, 2017/12/14
- [qemu-s390x] [PULL 31/46] s390x/css: attach css bridge, Cornelia Huck, 2017/12/14
- [qemu-s390x] [PULL 32/46] s390x/kvm: factor out build_channel_report_mcic() into cpu.h, Cornelia Huck, 2017/12/14