[coreboot-gerrit] Patch set updated for coreboot: region: add xlate_region_device

Aaron Durbin (adurbin@chromium.org) gerrit at coreboot.org
Wed Oct 28 22:22:42 CET 2015


Aaron Durbin (adurbin at chromium.org) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/12227

-gerrit

commit 4e724aeb5d04bfe59f6624259247eae4eed096db
Author: Aaron Durbin <adurbin at chromium.org>
Date:   Wed Oct 28 16:09:42 2015 -0500

    region: add xlate_region_device
    
    There are cases where one region_device needs to be
    accessed using offset/sizes from one address space
    that need the offset translated into a different
    address space for operations to take place. The
    xlate_region_device provides an offset that is
    subtracted from the incoming transaction before
    deferring to the backing access region.
    
    Change-Id: I41d43924bb6fbc7b4d3681877543209e1085e15c
    Signed-off-by: Aaron Durbin <adurbin at chromium.org>
---
 src/commonlib/include/commonlib/region.h | 22 ++++++++++++++++++++
 src/commonlib/region.c                   | 35 ++++++++++++++++++++++++++++++++
 2 files changed, 57 insertions(+)

diff --git a/src/commonlib/include/commonlib/region.h b/src/commonlib/include/commonlib/region.h
index d3e7ebd..e52fb93 100644
--- a/src/commonlib/include/commonlib/region.h
+++ b/src/commonlib/include/commonlib/region.h
@@ -154,4 +154,26 @@ void mmap_helper_device_init(struct mmap_helper_region_device *mdev,
 void *mmap_helper_rdev_mmap(const struct region_device *, size_t, size_t);
 int mmap_helper_rdev_munmap(const struct region_device *, void *);
 
+/* A translated region device provides the ability to publish a region device
+ * in on address space and use an access mechansim within another address
+ * space. The offset is peeled from the incoming transaction before
+ * utilizing the backing access_dev. */
+struct xlate_region_device {
+	const struct region_device *access_dev;
+	size_t offset;
+	struct region_device rdev;
+};
+
+extern const struct region_device_ops xlate_rdev_ops;
+
+#define XLATE_REGION_INIT_OFF(access_dev_, xlate_offset_, offset_, size_) \
+	{								\
+		.access_dev = access_dev_,				\
+		.offset = xlate_offset_,				\
+		.rdev = REGION_DEV_INIT(&xlate_rdev_ops, (offset_),  (size_)),\
+	}
+
+#define XLATE_REGION_INIT(access_dev_, offset_, size_) \
+	XLATE_REGION_INIT_OFF((access_dev_, (offset_), (offset_), (size_)
+
 #endif /* _REGION_H_ */
diff --git a/src/commonlib/region.c b/src/commonlib/region.c
index 352f92e..fc87880 100644
--- a/src/commonlib/region.c
+++ b/src/commonlib/region.c
@@ -194,3 +194,38 @@ int mmap_helper_rdev_munmap(const struct region_device *rd, void *mapping)
 
 	return 0;
 }
+
+static void *xlate_mmap(const struct region_device *rd, size_t offset,
+			size_t size)
+{
+	const struct xlate_region_device *xldev;
+
+	xldev = container_of(rd, typeof(*xldev), rdev);
+
+	return rdev_mmap(xldev->access_dev, offset - xldev->offset, size);
+}
+
+static int xlate_munmap(const struct region_device *rd, void *mapping)
+{
+	const struct xlate_region_device *xldev;
+
+	xldev = container_of(rd, typeof(*xldev), rdev);
+
+	return rdev_munmap(xldev->access_dev, mapping);
+}
+
+static ssize_t xlate_readat(const struct region_device *rd, void *b,
+				size_t offset, size_t size)
+{
+	const struct xlate_region_device *xldev;
+
+	xldev = container_of(rd, typeof(*xldev), rdev);
+
+	return rdev_readat(xldev->access_dev, b, offset - xldev->offset, size);
+}
+
+const struct region_device_ops xlate_rdev_ops = {
+	.mmap = xlate_mmap,
+	.munmap = xlate_munmap,
+	.readat = xlate_readat,
+};



More information about the coreboot-gerrit mailing list