diff options
author | Furquan Shaikh <furquan@google.com> | 2016-06-19 23:16:45 -0700 |
---|---|---|
committer | Furquan Shaikh <furquan@google.com> | 2016-06-21 20:23:40 +0200 |
commit | 2b57691ce0dcb06d6d8677393f76006c363d5856 (patch) | |
tree | 95c01e16e04fabdf09c624c8852fd525112888cd /src/commonlib | |
parent | f4dac8ac06512c8ed00a58cacae453c128a159de (diff) | |
download | coreboot-2b57691ce0dcb06d6d8677393f76006c363d5856.tar.xz |
commonlib/region: Add helpers for dynamic initialization of region dev
This allows initialization of runtime region devices and xlate region
devices where all parameters cannot be statically determined.
BUG=chrome-os-partner:54563
Change-Id: Ia6e1b695fed3bbfa08598d1593e650fc1465d41f
Signed-off-by: Furquan Shaikh <furquan@google.com>
Reviewed-on: https://review.coreboot.org/15267
Tested-by: build bot (Jenkins)
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
Diffstat (limited to 'src/commonlib')
-rw-r--r-- | src/commonlib/include/commonlib/region.h | 11 | ||||
-rw-r--r-- | src/commonlib/region.c | 23 |
2 files changed, 34 insertions, 0 deletions
diff --git a/src/commonlib/include/commonlib/region.h b/src/commonlib/include/commonlib/region.h index 4e32b09be0..634132a695 100644 --- a/src/commonlib/include/commonlib/region.h +++ b/src/commonlib/include/commonlib/region.h @@ -90,6 +90,11 @@ struct region_device { }, \ } +/* Helper to dynamically initialize region device. */ +void region_device_init(struct region_device *rdev, + const struct region_device_ops *ops, size_t offset, + size_t size); + static inline size_t region_offset(const struct region *r) { return r->offset; @@ -187,4 +192,10 @@ extern const struct region_device_ops xlate_rdev_ops; .rdev = REGION_DEV_INIT(&xlate_rdev_ops, 0, (parent_sz_)),\ } +/* Helper to dynamically initialize xlate region device. */ +void xlate_region_device_init(struct xlate_region_device *xdev, + const struct region_device *access_dev, + size_t sub_offset, size_t sub_size, + size_t parent_size); + #endif /* _REGION_H_ */ diff --git a/src/commonlib/region.c b/src/commonlib/region.c index bfc5fc8471..6f710746ca 100644 --- a/src/commonlib/region.c +++ b/src/commonlib/region.c @@ -133,6 +133,29 @@ void mem_region_device_init(struct mem_region_device *mdev, void *base, mdev->rdev.region.size = size; } +void region_device_init(struct region_device *rdev, + const struct region_device_ops *ops, size_t offset, + size_t size) +{ + memset(rdev, 0, sizeof(*rdev)); + rdev->root = NULL; + rdev->ops = ops; + rdev->region.offset = offset; + rdev->region.size = size; +} + +void xlate_region_device_init(struct xlate_region_device *xdev, + const struct region_device *access_dev, + size_t sub_offset, size_t sub_size, + size_t parent_size) +{ + memset(xdev, 0, sizeof(*xdev)); + xdev->access_dev = access_dev; + xdev->sub_region.offset = sub_offset; + xdev->sub_region.size = sub_size; + region_device_init(&xdev->rdev, &xlate_rdev_ops, 0, parent_size); +} + static void *mdev_mmap(const struct region_device *rd, size_t offset, size_t size __unused) { |