From 73f746ecf6d384ea328632a31e7f2982e343ebc8 Mon Sep 17 00:00:00 2001 From: Leo Sartre Date: Thu, 19 Nov 2020 13:27:01 +0100 Subject: [PATCH] lib/system/linux: pass correct offset to metal_map() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit According to UIO documentation, the offset device tree property purpose is to be used "if the device’s memory is not page aligned". Quoting the same documentation: "To map the memory of mapping N, you have to use N times the page size as your offset" So wee need to pass i * getpagesize() to get the correct mapping, otherwise, we end up with all io_region pointing to the same area. Signed-off-by: Leo Sartre --- lib/system/linux/device.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/system/linux/device.c b/lib/system/linux/device.c index f62e953..fa1864a 100644 --- a/lib/system/linux/device.c +++ b/lib/system/linux/device.c @@ -238,7 +238,7 @@ static int metal_uio_dev_open(struct linux_bus *lbus, struct linux_device *ldev) result = (result ? result : metal_uio_read_map_attr(ldev, i, "size", &size)); result = (result ? result : - metal_map(ldev->fd, offset, size, 0, 0, &virt)); + metal_map(ldev->fd, i * getpagesize(), size, 0, 0, &virt)); if (!result) { io = &ldev->device.regions[ldev->device.num_regions]; metal_io_init(io, virt, phys, size, -1, 0, NULL);