]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
uio: Allow handling of non page-aligned memory regions
authorMichal Sojka <sojkam1@fel.cvut.cz>
Thu, 16 Mar 2017 13:50:08 +0000 (14:50 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 8 Apr 2017 16:13:27 +0000 (18:13 +0200)
Since commit b65502879556 ("uio: we cannot mmap unaligned page
contents") addresses and sizes of UIO memory regions must be
page-aligned. If the address in the BAR register is not
page-aligned (which is the case of the mf264 card), the mentioned
commit forces the UIO driver to round the address down to the page
size. Then, there is no easy way for user-space to learn the offset of
the actual memory region within the page, because the offset seen in
/sys/class/uio/uio?/maps/map?/offset is calculated from the rounded
address and thus it is always zero.

Fix that problem by including the offset in struct uio_mem. UIO
drivers can set this field and userspace can read its value from
/sys/class/uio/uio?/maps/map?/offset.

The following commits update the uio_mf264 driver to set this new offs
field.

Drivers for hardware with page-aligned BARs need not to be modified
provided that they initialize struct uio_info (which contains uio_mem)
with zeros.

Signed-off-by: Michal Sojka <sojkam1@fel.cvut.cz>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/uio/uio.c
include/linux/uio_driver.h

index 60ce7fd54e890e445daf81e04bcdd70d0ae09599..1c196f87e9d967886c88b1ae7fe05cc5f01ed4ee 100644 (file)
@@ -66,7 +66,7 @@ static ssize_t map_size_show(struct uio_mem *mem, char *buf)
 
 static ssize_t map_offset_show(struct uio_mem *mem, char *buf)
 {
-       return sprintf(buf, "0x%llx\n", (unsigned long long)mem->addr & ~PAGE_MASK);
+       return sprintf(buf, "0x%llx\n", (unsigned long long)mem->offs);
 }
 
 struct map_sysfs_entry {
index 32c0e83d62397355e1b6bb804c1d0381f56daca1..3c85c81b00279708eb6f816c153e9e4e2f735c1e 100644 (file)
@@ -23,11 +23,13 @@ struct uio_map;
 /**
  * struct uio_mem - description of a UIO memory region
  * @name:              name of the memory region for identification
- * @addr:              address of the device's memory (phys_addr is used since
- *                     addr can be logical, virtual, or physical & phys_addr_t
- *                     should always be large enough to handle any of the
- *                     address types)
- * @size:              size of IO
+ * @addr:               address of the device's memory rounded to page
+ *                     size (phys_addr is used since addr can be
+ *                     logical, virtual, or physical & phys_addr_t
+ *                     should always be large enough to handle any of
+ *                     the address types)
+ * @offs:               offset of device memory within the page
+ * @size:              size of IO (multiple of page size)
  * @memtype:           type of memory addr points to
  * @internal_addr:     ioremap-ped version of addr, for driver internal use
  * @map:               for use by the UIO core only.
@@ -35,6 +37,7 @@ struct uio_map;
 struct uio_mem {
        const char              *name;
        phys_addr_t             addr;
+       unsigned long           offs;
        resource_size_t         size;
        int                     memtype;
        void __iomem            *internal_addr;