[coreboot-gerrit] Patch set updated for coreboot: commonlib: Add function to compute relative offsets from two region_devices.

Aaron Durbin (adurbin@chromium.org) gerrit at coreboot.org
Tue Jan 5 17:12:21 CET 2016


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

-gerrit

commit 0b2b61ca43d9f083107715433fd92f35e8882167
Author: Aaron Durbin <adurbin at chromium.org>
Date:   Tue Dec 15 13:29:41 2015 -0600

    commonlib: Add function to compute relative offsets from two region_devices.
    
    Provide a helper function which returns the relative offset
    between 2 region_devices that have a parent-child child relationship.
    
    BUG=chrome-os-partner:48412
    BUG=chromium:445938
    BRANCH=None
    TEST=Utilized and booted on glados.
    
    Change-Id: Ie0041b33e73a6601748f1289e98b6f1f8756eb11
    Signed-off-by: Aaron Durbin <adurbin at chromium.org>
---
 src/commonlib/include/commonlib/region.h |  7 +++++++
 src/commonlib/region.c                   | 12 ++++++++++++
 2 files changed, 19 insertions(+)

diff --git a/src/commonlib/include/commonlib/region.h b/src/commonlib/include/commonlib/region.h
index cc4ee28..35d48ad 100644
--- a/src/commonlib/include/commonlib/region.h
+++ b/src/commonlib/include/commonlib/region.h
@@ -121,6 +121,13 @@ static inline void *rdev_mmap_full(const struct region_device *rd)
 	return rdev_mmap(rd, 0, region_device_sz(rd));
 }
 
+/*
+ * Compute relative offset of the child (c) w.r.t. the parent (p). Returns < 0
+ * when child is not within the parent's region.
+ */
+ssize_t rdev_relative_offset(const struct region_device *p,
+				const struct region_device *c);
+
 struct mem_region_device {
 	char *base;
 	struct region_device rdev;
diff --git a/src/commonlib/region.c b/src/commonlib/region.c
index 8b0b0d9..2cd273a 100644
--- a/src/commonlib/region.c
+++ b/src/commonlib/region.c
@@ -48,6 +48,18 @@ static const struct region_device *rdev_root(const struct region_device *rdev)
 	return rdev->root;
 }
 
+ssize_t rdev_relative_offset(const struct region_device *p,
+				const struct region_device *c)
+{
+	if (rdev_root(p) != rdev_root(c))
+		return -1;
+
+	if (!is_subregion(&p->region, &c->region))
+		return -1;
+
+	return region_device_offset(c) - region_device_offset(p);
+}
+
 void *rdev_mmap(const struct region_device *rd, size_t offset, size_t size)
 {
 	const struct region_device *rdev;



More information about the coreboot-gerrit mailing list