diff options
author | Nikunj A Dadhania <nikunj@linux.vnet.ibm.com> | 2016-02-01 11:18:06 +0530 |
---|---|---|
committer | Alexey Kardashevskiy <aik@ozlabs.ru> | 2016-02-08 16:40:39 +1100 |
commit | 66c156d0dec4234fe7f423dda719f728ac898896 (patch) | |
tree | a7ccda68d3eed1e975557d24a9db3948018a7400 /lib | |
parent | ff9b0bd159ddb843d32f24e66a43fe99c920a00b (diff) | |
download | SLOF-66c156d0dec4234fe7f423dda719f728ac898896.zip SLOF-66c156d0dec4234fe7f423dda719f728ac898896.tar.gz SLOF-66c156d0dec4234fe7f423dda719f728ac898896.tar.bz2 |
virtio: add 64-bit virtio helpers for 1.0
64-bit fields are to be treated as two 32-bit fields, with low 32 bit
part followed by the high 32 bit part.
Signed-off-by: Nikunj A Dadhania <nikunj@linux.vnet.ibm.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libvirtio/virtio.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/libvirtio/virtio.c b/lib/libvirtio/virtio.c index f30b69b..467c619 100644 --- a/lib/libvirtio/virtio.c +++ b/lib/libvirtio/virtio.c @@ -51,6 +51,31 @@ struct virtio_dev_common { le64 q_used; } __attribute__ ((packed)); +/* virtio 1.0 Spec: 4.1.3 PCI Device Layout + * + * Fields of different sizes are present in the device configuration regions. + * All 64-bit, 32-bit and 16-bit fields are little-endian. 64-bit fields are to + * be treated as two 32-bit fields, with low 32 bit part followed by the high 32 + * bit part. + */ +static void virtio_pci_write64(void *addr, uint64_t val) +{ + uint32_t hi = (val >> 32) & 0xFFFFFFFF; + uint32_t lo = val & 0xFFFFFFFF; + + ci_write_32(addr, cpu_to_le32(lo)); + ci_write_32(addr + 4, cpu_to_le32(hi)); +} + +static uint64_t virtio_pci_read64(void *addr) +{ + uint64_t hi, lo; + + lo = le32_to_cpu(ci_read_32(addr)); + hi = le32_to_cpu(ci_read_32(addr + 4)); + return (hi << 32) | lo; +} + /** * Calculate ring size according to queue size number */ |