summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Durbin <adurbin@chromium.org>2017-12-14 15:22:04 -0700
committerAaron Durbin <adurbin@chromium.org>2017-12-15 23:35:05 +0000
commit02103e34d76c12b46b57143cd11d96758219423d (patch)
treedb253313a59f1d81ad1691f9eca1340682944abd
parent9ab8ae6a55681874ec194bc144077ded5363a317 (diff)
commonlib/region: expose subregion helper function
Export region_is_subregion() for determinig if a region is a child of a parent region. BUG=b:69614064 Change-Id: I6363fe4fdb33342f9d025a726ec7e17e87adf7e0 Signed-off-by: Aaron Durbn <adurbin@chromium.org> Reviewed-on: https://review.coreboot.org/22878 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Furquan Shaikh <furquan@google.com>
-rw-r--r--src/commonlib/include/commonlib/region.h3
-rw-r--r--src/commonlib/region.c14
2 files changed, 10 insertions, 7 deletions
diff --git a/src/commonlib/include/commonlib/region.h b/src/commonlib/include/commonlib/region.h
index 3f7d3bd52f..45484dddd6 100644
--- a/src/commonlib/include/commonlib/region.h
+++ b/src/commonlib/include/commonlib/region.h
@@ -112,6 +112,9 @@ void region_device_init(struct region_device *rdev,
const struct region_device_ops *ops, size_t offset,
size_t size);
+/* Return 1 if child is subregion of parent, else 0. */
+int region_is_subregion(const struct region *p, const struct region *c);
+
static inline size_t region_offset(const struct region *r)
{
return r->offset;
diff --git a/src/commonlib/region.c b/src/commonlib/region.c
index 051fe3479b..541a125ad4 100644
--- a/src/commonlib/region.c
+++ b/src/commonlib/region.c
@@ -22,7 +22,7 @@ static inline size_t region_end(const struct region *r)
return region_sz(r) + region_offset(r);
}
-static int is_subregion(const struct region *p, const struct region *c)
+int region_is_subregion(const struct region *p, const struct region *c)
{
if (region_offset(c) < region_offset(p))
return 0;
@@ -39,7 +39,7 @@ static int is_subregion(const struct region *p, const struct region *c)
static int normalize_and_ok(const struct region *outer, struct region *inner)
{
inner->offset += region_offset(outer);
- return is_subregion(outer, inner);
+ return region_is_subregion(outer, inner);
}
static const struct region_device *rdev_root(const struct region_device *rdev)
@@ -55,7 +55,7 @@ ssize_t rdev_relative_offset(const struct region_device *p,
if (rdev_root(p) != rdev_root(c))
return -1;
- if (!is_subregion(&p->region, &c->region))
+ if (!region_is_subregion(&p->region, &c->region))
return -1;
return region_device_offset(c) - region_device_offset(p);
@@ -350,7 +350,7 @@ static void *xlate_mmap(const struct region_device *rd, size_t offset,
xldev = container_of(rd, __typeof__(*xldev), rdev);
- if (!is_subregion(&xldev->sub_region, &req))
+ if (!region_is_subregion(&xldev->sub_region, &req))
return NULL;
offset -= region_offset(&xldev->sub_region);
@@ -378,7 +378,7 @@ static ssize_t xlate_readat(const struct region_device *rd, void *b,
xldev = container_of(rd, __typeof__(*xldev), rdev);
- if (!is_subregion(&xldev->sub_region, &req))
+ if (!region_is_subregion(&xldev->sub_region, &req))
return -1;
offset -= region_offset(&xldev->sub_region);
@@ -397,7 +397,7 @@ static ssize_t xlate_writeat(const struct region_device *rd, const void *b,
xldev = container_of(rd, __typeof__(*xldev), rdev);
- if (!is_subregion(&xldev->sub_region, &req))
+ if (!region_is_subregion(&xldev->sub_region, &req))
return -1;
offset -= region_offset(&xldev->sub_region);
@@ -416,7 +416,7 @@ static ssize_t xlate_eraseat(const struct region_device *rd,
xldev = container_of(rd, __typeof__(*xldev), rdev);
- if (!is_subregion(&xldev->sub_region, &req))
+ if (!region_is_subregion(&xldev->sub_region, &req))
return -1;
offset -= region_offset(&xldev->sub_region);