summaryrefslogtreecommitdiff
path: root/src/commonlib/include
diff options
context:
space:
mode:
authorJulius Werner <jwerner@chromium.org>2021-04-16 16:48:32 -0700
committerJulius Werner <jwerner@chromium.org>2021-04-21 02:06:26 +0000
commitc893197352acc9b53c1beef5082cbc0271f63688 (patch)
treeb975712387bd54bd0101a736adbb2a6fe5b824bb /src/commonlib/include
parentb03e497ef16e9e38ba9220d31131a6bfdef35390 (diff)
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>
Diffstat (limited to 'src/commonlib/include')
-rw-r--r--src/commonlib/include/commonlib/region.h13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/commonlib/include/commonlib/region.h b/src/commonlib/include/commonlib/region.h
index 0080c441a5..764870f46c 100644
--- a/src/commonlib/include/commonlib/region.h
+++ b/src/commonlib/include/commonlib/region.h
@@ -164,14 +164,18 @@ static inline int rdev_chain_full(struct region_device *child,
ssize_t rdev_relative_offset(const struct region_device *p,
const struct region_device *c);
+/* Helper functions to create an rdev that represents memory. */
+int rdev_chain_mem(struct region_device *child, const void *base, size_t size);
+int rdev_chain_mem_rw(struct region_device *child, void *base, size_t size);
+
struct mem_region_device {
char *base;
struct region_device rdev;
};
-/* Initialize at runtime a mem_region_device. This would be used when
- * the base and size are dynamic or can't be known during linking.
- * There are two variants: read-only and read-write. */
+/* Initialize at runtime a mem_region_device. Should only be used for mappings
+ that need to fit right up to the edge of the physical address space. Most use
+ cases will want to use rdev_chain_mem() instead. */
void mem_region_device_ro_init(struct mem_region_device *mdev, void *base,
size_t size);
@@ -182,7 +186,8 @@ extern const struct region_device_ops mem_rdev_ro_ops;
extern const struct region_device_ops mem_rdev_rw_ops;
-/* Statically initialize mem_region_device. */
+/* Statically initialize mem_region_device. Should normally only be used for
+ const globals. Most use cases will want to use rdev_chain_mem() instead. */
#define MEM_REGION_DEV_INIT(base_, size_, ops_) \
{ \
.base = (void *)(base_), \