From 02103e34d76c12b46b57143cd11d96758219423d Mon Sep 17 00:00:00 2001 From: Aaron Durbin Date: Thu, 14 Dec 2017 15:22:04 -0700 Subject: 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 Reviewed-on: https://review.coreboot.org/22878 Tested-by: build bot (Jenkins) Reviewed-by: Furquan Shaikh --- src/commonlib/include/commonlib/region.h | 3 +++ src/commonlib/region.c | 14 +++++++------- 2 files changed, 10 insertions(+), 7 deletions(-) (limited to 'src') 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); -- cgit v1.2.3