diff options
| author | Michael S. Tsirkin <mst@redhat.com> | 2015-03-31 23:03:20 -0400 |
|---|---|---|
| committer | Rusty Russell <rusty@rustcorp.com.au> | 2015-04-01 00:07:15 -0400 |
| commit | c5d4c2c9ce4f4b6980a71dec50f2db4c2e55778d (patch) | |
| tree | 237c8573d47db80749a3353eee128f7ec1d57c2c /drivers/virtio | |
| parent | 3eebd233fcb392286d385e764eb91e90d6218cdf (diff) | |
virtio_pci_modern: type-safe io accessors
The spec is very clear on this:
4.1.3.1 Driver Requirements: PCI Device Layout
The driver MUST access each field using the “natural” access method,
i.e. 32-bit accesses for 32-bit fields, 16-bit accesses for 16-bit
fields and 8-bit accesses for 8-bit fields.
Add type-safe wrappers to prevent access with incorrect width.
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Diffstat (limited to 'drivers/virtio')
| -rw-r--r-- | drivers/virtio/virtio_pci_modern.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/drivers/virtio/virtio_pci_modern.c b/drivers/virtio/virtio_pci_modern.c index 2aa38e59db2e..826e500d4819 100644 --- a/drivers/virtio/virtio_pci_modern.c +++ b/drivers/virtio/virtio_pci_modern.c | |||
| @@ -20,6 +20,43 @@ | |||
| 20 | #define VIRTIO_PCI_NO_LEGACY | 20 | #define VIRTIO_PCI_NO_LEGACY |
| 21 | #include "virtio_pci_common.h" | 21 | #include "virtio_pci_common.h" |
| 22 | 22 | ||
| 23 | /* | ||
| 24 | * Type-safe wrappers for io accesses. | ||
| 25 | * Use these to enforce at compile time the following spec requirement: | ||
| 26 | * | ||
| 27 | * The driver MUST access each field using the “natural” access | ||
| 28 | * method, i.e. 32-bit accesses for 32-bit fields, 16-bit accesses | ||
| 29 | * for 16-bit fields and 8-bit accesses for 8-bit fields. | ||
| 30 | */ | ||
| 31 | static inline u8 vp_ioread8(u8 __iomem *addr) | ||
| 32 | { | ||
| 33 | return ioread8(addr); | ||
| 34 | } | ||
| 35 | static inline u16 vp_ioread16 (u16 __iomem *addr) | ||
| 36 | { | ||
| 37 | return ioread16(addr); | ||
| 38 | } | ||
| 39 | |||
| 40 | static inline u32 vp_ioread32(u32 __iomem *addr) | ||
| 41 | { | ||
| 42 | return ioread32(addr); | ||
| 43 | } | ||
| 44 | |||
| 45 | static inline void vp_iowrite8(u8 value, u8 __iomem *addr) | ||
| 46 | { | ||
| 47 | iowrite8(value, addr); | ||
| 48 | } | ||
| 49 | |||
| 50 | static inline void vp_iowrite16(u16 value, u16 __iomem *addr) | ||
| 51 | { | ||
| 52 | iowrite16(value, addr); | ||
| 53 | } | ||
| 54 | |||
| 55 | static inline void vp_iowrite32(u32 value, u32 __iomem *addr) | ||
| 56 | { | ||
| 57 | iowrite32(value, addr); | ||
| 58 | } | ||
| 59 | |||
| 23 | static void __iomem *map_capability(struct pci_dev *dev, int off, | 60 | static void __iomem *map_capability(struct pci_dev *dev, int off, |
| 24 | size_t minlen, | 61 | size_t minlen, |
| 25 | u32 align, | 62 | u32 align, |
