aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Williamson <alex.williamson@redhat.com>2018-03-21 14:46:21 -0400
committerAlex Williamson <alex.williamson@redhat.com>2018-03-26 15:22:58 -0400
commit07fd7ef3a1c25a11015bb5821c9c5982f722d4a2 (patch)
tree4059277e92a709d14c2befaeff83007103f33ca1
parent0d77ed3589ac054d197ccde7231e36f9e032426c (diff)
vfio/pci: Use endian neutral helpers
The iowriteXX/ioreadXX functions assume little endian hardware and convert to little endian on a write and from little endian on a read. We currently do our own explicit conversion to negate this. Instead, add some endian dependent defines to avoid all byte swaps. There should be no functional change other than big endian systems aren't penalized with wasted swaps. Reviewed-by: Alexey Kardashevskiy <aik@ozlabs.ru> Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
-rw-r--r--drivers/vfio/pci/vfio_pci_rdwr.c34
1 files changed, 26 insertions, 8 deletions
diff --git a/drivers/vfio/pci/vfio_pci_rdwr.c b/drivers/vfio/pci/vfio_pci_rdwr.c
index 5f2b376dcebd..925419e0f459 100644
--- a/drivers/vfio/pci/vfio_pci_rdwr.c
+++ b/drivers/vfio/pci/vfio_pci_rdwr.c
@@ -21,6 +21,24 @@
21 21
22#include "vfio_pci_private.h" 22#include "vfio_pci_private.h"
23 23
24#ifdef __LITTLE_ENDIAN
25#define vfio_ioread64 ioread64
26#define vfio_iowrite64 iowrite64
27#define vfio_ioread32 ioread32
28#define vfio_iowrite32 iowrite32
29#define vfio_ioread16 ioread16
30#define vfio_iowrite16 iowrite16
31#else
32#define vfio_ioread64 ioread64be
33#define vfio_iowrite64 iowrite64be
34#define vfio_ioread32 ioread32be
35#define vfio_iowrite32 iowrite32be
36#define vfio_ioread16 ioread16be
37#define vfio_iowrite16 iowrite16be
38#endif
39#define vfio_ioread8 ioread8
40#define vfio_iowrite8 iowrite8
41
24/* 42/*
25 * Read or write from an __iomem region (MMIO or I/O port) with an excluded 43 * Read or write from an __iomem region (MMIO or I/O port) with an excluded
26 * range which is inaccessible. The excluded range drops writes and fills 44 * range which is inaccessible. The excluded range drops writes and fills
@@ -44,15 +62,15 @@ static ssize_t do_io_rw(void __iomem *io, char __user *buf,
44 fillable = 0; 62 fillable = 0;
45 63
46 if (fillable >= 4 && !(off % 4)) { 64 if (fillable >= 4 && !(off % 4)) {
47 __le32 val; 65 u32 val;
48 66
49 if (iswrite) { 67 if (iswrite) {
50 if (copy_from_user(&val, buf, 4)) 68 if (copy_from_user(&val, buf, 4))
51 return -EFAULT; 69 return -EFAULT;
52 70
53 iowrite32(le32_to_cpu(val), io + off); 71 vfio_iowrite32(val, io + off);
54 } else { 72 } else {
55 val = cpu_to_le32(ioread32(io + off)); 73 val = vfio_ioread32(io + off);
56 74
57 if (copy_to_user(buf, &val, 4)) 75 if (copy_to_user(buf, &val, 4))
58 return -EFAULT; 76 return -EFAULT;
@@ -60,15 +78,15 @@ static ssize_t do_io_rw(void __iomem *io, char __user *buf,
60 78
61 filled = 4; 79 filled = 4;
62 } else if (fillable >= 2 && !(off % 2)) { 80 } else if (fillable >= 2 && !(off % 2)) {
63 __le16 val; 81 u16 val;
64 82
65 if (iswrite) { 83 if (iswrite) {
66 if (copy_from_user(&val, buf, 2)) 84 if (copy_from_user(&val, buf, 2))
67 return -EFAULT; 85 return -EFAULT;
68 86
69 iowrite16(le16_to_cpu(val), io + off); 87 vfio_iowrite16(val, io + off);
70 } else { 88 } else {
71 val = cpu_to_le16(ioread16(io + off)); 89 val = vfio_ioread16(io + off);
72 90
73 if (copy_to_user(buf, &val, 2)) 91 if (copy_to_user(buf, &val, 2))
74 return -EFAULT; 92 return -EFAULT;
@@ -82,9 +100,9 @@ static ssize_t do_io_rw(void __iomem *io, char __user *buf,
82 if (copy_from_user(&val, buf, 1)) 100 if (copy_from_user(&val, buf, 1))
83 return -EFAULT; 101 return -EFAULT;
84 102
85 iowrite8(val, io + off); 103 vfio_iowrite8(val, io + off);
86 } else { 104 } else {
87 val = ioread8(io + off); 105 val = vfio_ioread8(io + off);
88 106
89 if (copy_to_user(buf, &val, 1)) 107 if (copy_to_user(buf, &val, 1))
90 return -EFAULT; 108 return -EFAULT;