summaryrefslogtreecommitdiff
path: root/src/commonlib
diff options
context:
space:
mode:
authorJulius Werner <jwerner@chromium.org>2020-12-30 17:30:12 -0800
committerJulius Werner <jwerner@chromium.org>2021-03-08 22:31:29 +0000
commit9b1f3cc6fb129789f1dd28160a83a1ea59dd123a (patch)
tree98347b2285d361fbcaa74892fa75a40a629d4b7f /src/commonlib
parent11075fc80e00186cb5b488e8e0fd280cd4e97823 (diff)
downloadcoreboot-9b1f3cc6fb129789f1dd28160a83a1ea59dd123a.tar.xz
cbfs: Pull handling of the CBFS_CACHE mem_pool into CBFS core
This patch pulls control of the memory pool serving allocations from the CBFS_CACHE memlayout area into cbfs.c and makes it a core part of the CBFS API. Previously, platforms would independently instantiate this as part of boot_device_ro() (mostly through cbfs_spi.c). The new cbfs_cache pool is exported as a global so these platforms can still use it to directly back rdev_mmap() on their boot device, but the cbfs_cache can now also use it to directly make allocations itself. This is used to allow transparent decompression support in cbfs_map(). Signed-off-by: Julius Werner <jwerner@chromium.org> Change-Id: I0d52b6a8f582a81a19fd0fd663bb89eab55a49d9 Reviewed-on: https://review.coreboot.org/c/coreboot/+/49333 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Aaron Durbin <adurbin@chromium.org>
Diffstat (limited to 'src/commonlib')
-rw-r--r--src/commonlib/Makefile.inc1
-rw-r--r--src/commonlib/include/commonlib/region.h8
-rw-r--r--src/commonlib/region.c12
3 files changed, 7 insertions, 14 deletions
diff --git a/src/commonlib/Makefile.inc b/src/commonlib/Makefile.inc
index 1a38e4a89f..c5fa8ed85e 100644
--- a/src/commonlib/Makefile.inc
+++ b/src/commonlib/Makefile.inc
@@ -5,6 +5,7 @@ verstage-y += mem_pool.c
romstage-y += mem_pool.c
ramstage-y += mem_pool.c
postcar-y += mem_pool.c
+smm-y += mem_pool.c
bootblock-y += iobuf.c
verstage-y += iobuf.c
diff --git a/src/commonlib/include/commonlib/region.h b/src/commonlib/include/commonlib/region.h
index 4d095b731d..0080c441a5 100644
--- a/src/commonlib/include/commonlib/region.h
+++ b/src/commonlib/include/commonlib/region.h
@@ -196,18 +196,16 @@ extern const struct region_device_ops mem_rdev_rw_ops;
MEM_REGION_DEV_INIT(base_, size_, &mem_rdev_rw_ops) \
struct mmap_helper_region_device {
- struct mem_pool pool;
+ struct mem_pool *pool;
struct region_device rdev;
};
-#define MMAP_HELPER_REGION_INIT(ops_, offset_, size_) \
+#define MMAP_HELPER_DEV_INIT(ops_, offset_, size_, mpool_) \
{ \
.rdev = REGION_DEV_INIT((ops_), (offset_), (size_)), \
+ .pool = (mpool_), \
}
-void mmap_helper_device_init(struct mmap_helper_region_device *mdev,
- void *cache, size_t cache_size);
-
void *mmap_helper_rdev_mmap(const struct region_device *, size_t, size_t);
int mmap_helper_rdev_munmap(const struct region_device *, void *);
diff --git a/src/commonlib/region.c b/src/commonlib/region.c
index a10702a6c5..55c0679033 100644
--- a/src/commonlib/region.c
+++ b/src/commonlib/region.c
@@ -287,12 +287,6 @@ const struct region_device_ops mem_rdev_rw_ops = {
.eraseat = mdev_eraseat,
};
-void mmap_helper_device_init(struct mmap_helper_region_device *mdev,
- void *cache, size_t cache_size)
-{
- mem_pool_init(&mdev->pool, cache, cache_size);
-}
-
void *mmap_helper_rdev_mmap(const struct region_device *rd, size_t offset,
size_t size)
{
@@ -301,13 +295,13 @@ void *mmap_helper_rdev_mmap(const struct region_device *rd, size_t offset,
mdev = container_of((void *)rd, __typeof__(*mdev), rdev);
- mapping = mem_pool_alloc(&mdev->pool, size);
+ mapping = mem_pool_alloc(mdev->pool, size);
if (mapping == NULL)
return NULL;
if (rd->ops->readat(rd, mapping, offset, size) != size) {
- mem_pool_free(&mdev->pool, mapping);
+ mem_pool_free(mdev->pool, mapping);
return NULL;
}
@@ -320,7 +314,7 @@ int mmap_helper_rdev_munmap(const struct region_device *rd, void *mapping)
mdev = container_of((void *)rd, __typeof__(*mdev), rdev);
- mem_pool_free(&mdev->pool, mapping);
+ mem_pool_free(mdev->pool, mapping);
return 0;
}