commonlib/region: Turn addrspace_32bit into a more official API

We had the addrspace_32bit rdev in prog_loaders.c for a while to help
represent memory ranges as an rdev, and we've found it useful for a
couple of things that have nothing to do with program loading. This
patch moves the concept straight into commonlib/region.c so it is no
longer anchored in such a weird place, and easier to use in unit tests.
Also expand the concept to the whole address space (there's no real need
to restrict it to 32 bits in 64-bit environments) and introduce an
rdev_chain_mem() helper function to make it a bit easier to use. Replace
some direct uses of struct mem_region_device with this new API where it
seems to make sense.

Signed-off-by: Julius Werner <jwerner@chromium.org>
Change-Id: Ie4c763b77f77d227768556a9528681d771a08dca
Reviewed-on: https://review.coreboot.org/c/coreboot/+/52533
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
This commit is contained in:
Julius Werner
2021-04-16 16:48:32 -07:00
parent b03e497ef1
commit c893197352
16 changed files with 117 additions and 147 deletions

View File

@ -287,6 +287,19 @@ const struct region_device_ops mem_rdev_rw_ops = {
.eraseat = mdev_eraseat,
};
static const struct mem_region_device mem_rdev = MEM_REGION_DEV_RO_INIT(0, ~(size_t)0);
static const struct mem_region_device mem_rdev_rw = MEM_REGION_DEV_RW_INIT(0, ~(size_t)0);
int rdev_chain_mem(struct region_device *child, const void *base, size_t size)
{
return rdev_chain(child, &mem_rdev.rdev, (uintptr_t)base, size);
}
int rdev_chain_mem_rw(struct region_device *child, void *base, size_t size)
{
return rdev_chain(child, &mem_rdev_rw.rdev, (uintptr_t)base, size);
}
void *mmap_helper_rdev_mmap(const struct region_device *rd, size_t offset,
size_t size)
{