Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1594387 > unrolled thread
| Started by | Michal Sojka <sojkam1@fel.cvut.cz> |
|---|---|
| First post | 2017-03-07 17:10 +0100 |
| Last post | 2017-03-07 17:10 +0100 |
| Articles | 3 — 1 participant |
Back to article view | Back to linux.kernel
[PATCH 1/3] uio: Allow handling of non page-aligned memory regions Michal Sojka <sojkam1@fel.cvut.cz> - 2017-03-07 17:10 +0100
[PATCH 2/3] uio_mf624: Refactor memory info initialization Michal Sojka <sojkam1@fel.cvut.cz> - 2017-03-07 17:10 +0100
[PATCH 3/3] uio_mf624: Align memory regions to page size Michal Sojka <sojkam1@fel.cvut.cz> - 2017-03-07 17:10 +0100
| From | Michal Sojka <sojkam1@fel.cvut.cz> |
|---|---|
| Date | 2017-03-07 17:10 +0100 |
| Subject | [PATCH 1/3] uio: Allow handling of non page-aligned memory regions |
| Message-ID | <tipQu-1uF-21@gated-at.bofh.it> |
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,
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 the sysfs 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 its value is reported via sysfs.
Drivers for hardware with page-aligned BARs need not to be modified
provided that they initialize struct uio_info with zeros.
Signed-off-by: Michal Sojka <sojkam1@fel.cvut.cz>
---
drivers/uio/uio.c | 2 +-
include/linux/uio_driver.h | 13 ++++++++-----
2 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
index fba021f5736a..27c329131350 100644
--- a/drivers/uio/uio.c
+++ b/drivers/uio/uio.c
@@ -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 {
diff --git a/include/linux/uio_driver.h b/include/linux/uio_driver.h
index 32c0e83d6239..89b53094f127 100644
--- a/include/linux/uio_driver.h
+++ b/include/linux/uio_driver.h
@@ -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;
--
2.11.0
[toc] | [next] | [standalone]
| From | Michal Sojka <sojkam1@fel.cvut.cz> |
|---|---|
| Date | 2017-03-07 17:10 +0100 |
| Subject | [PATCH 2/3] uio_mf624: Refactor memory info initialization |
| Message-ID | <tipQu-1uF-39@gated-at.bofh.it> |
| In reply to | #1594387 |
No functional changes.
Signed-off-by: Michal Sojka <sojkam1@fel.cvut.cz>
---
drivers/uio/uio_mf624.c | 44 ++++++++++++++++++--------------------------
1 file changed, 18 insertions(+), 26 deletions(-)
diff --git a/drivers/uio/uio_mf624.c b/drivers/uio/uio_mf624.c
index d1f95a1567bb..8f30fa1af2ab 100644
--- a/drivers/uio/uio_mf624.c
+++ b/drivers/uio/uio_mf624.c
@@ -127,6 +127,20 @@ static int mf624_irqcontrol(struct uio_info *info, s32 irq_on)
return 0;
}
+static int mf624_setup_mem(struct pci_dev *dev, int bar, struct uio_mem *mem, const char *name)
+{
+ mem->name = name;
+ mem->addr = pci_resource_start(dev, bar);
+ if (!mem->addr)
+ return -ENODEV;
+ mem->size = pci_resource_len(dev, bar);
+ mem->memtype = UIO_MEM_PHYS;
+ mem->internal_addr = pci_ioremap_bar(dev, bar);
+ if (!mem->internal_addr)
+ return -ENODEV;
+ return 0;
+}
+
static int mf624_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
{
struct uio_info *info;
@@ -147,37 +161,15 @@ static int mf624_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
/* Note: Datasheet says device uses BAR0, BAR1, BAR2 -- do not trust it */
/* BAR0 */
- info->mem[0].name = "PCI chipset, interrupts, status "
- "bits, special functions";
- info->mem[0].addr = pci_resource_start(dev, 0);
- if (!info->mem[0].addr)
+ if (mf624_setup_mem(dev, 0, &info->mem[0], "PCI chipset, interrupts, status "
+ "bits, special functions"))
goto out_release;
- info->mem[0].size = pci_resource_len(dev, 0);
- info->mem[0].memtype = UIO_MEM_PHYS;
- info->mem[0].internal_addr = pci_ioremap_bar(dev, 0);
- if (!info->mem[0].internal_addr)
- goto out_release;
-
/* BAR2 */
- info->mem[1].name = "ADC, DAC, DIO";
- info->mem[1].addr = pci_resource_start(dev, 2);
- if (!info->mem[1].addr)
- goto out_unmap0;
- info->mem[1].size = pci_resource_len(dev, 2);
- info->mem[1].memtype = UIO_MEM_PHYS;
- info->mem[1].internal_addr = pci_ioremap_bar(dev, 2);
- if (!info->mem[1].internal_addr)
+ if (mf624_setup_mem(dev, 2, &info->mem[1], "ADC, DAC, DIO"))
goto out_unmap0;
/* BAR4 */
- info->mem[2].name = "Counter/timer chip";
- info->mem[2].addr = pci_resource_start(dev, 4);
- if (!info->mem[2].addr)
- goto out_unmap1;
- info->mem[2].size = pci_resource_len(dev, 4);
- info->mem[2].memtype = UIO_MEM_PHYS;
- info->mem[2].internal_addr = pci_ioremap_bar(dev, 4);
- if (!info->mem[2].internal_addr)
+ if (mf624_setup_mem(dev, 4, &info->mem[2], "Counter/timer chip"))
goto out_unmap1;
info->irq = dev->irq;
--
2.11.0
[toc] | [prev] | [next] | [standalone]
| From | Michal Sojka <sojkam1@fel.cvut.cz> |
|---|---|
| Date | 2017-03-07 17:10 +0100 |
| Subject | [PATCH 3/3] uio_mf624: Align memory regions to page size |
| Message-ID | <tipQu-1uF-41@gated-at.bofh.it> |
| In reply to | #1594387 |
Without that, one cannot mmap() the registers to user-space, at least since
commit b65502879556 ("uio: we cannot mmap unaligned page contents").
Tested with real mf624 card.
Signed-off-by: Michal Sojka <sojkam1@fel.cvut.cz>
---
drivers/uio/uio_mf624.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/drivers/uio/uio_mf624.c b/drivers/uio/uio_mf624.c
index 8f30fa1af2ab..35187c052e8c 100644
--- a/drivers/uio/uio_mf624.c
+++ b/drivers/uio/uio_mf624.c
@@ -129,11 +129,15 @@ static int mf624_irqcontrol(struct uio_info *info, s32 irq_on)
static int mf624_setup_mem(struct pci_dev *dev, int bar, struct uio_mem *mem, const char *name)
{
+ resource_size_t start = pci_resource_start(dev, bar);
+ resource_size_t len = pci_resource_len(dev, bar);
+
mem->name = name;
- mem->addr = pci_resource_start(dev, bar);
+ mem->addr = start & PAGE_MASK;
+ mem->offs = start & ~PAGE_MASK;
if (!mem->addr)
return -ENODEV;
- mem->size = pci_resource_len(dev, bar);
+ mem->size = ((start & ~PAGE_MASK) + len + PAGE_SIZE - 1) & PAGE_MASK;
mem->memtype = UIO_MEM_PHYS;
mem->internal_addr = pci_ioremap_bar(dev, bar);
if (!mem->internal_addr)
--
2.11.0
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web