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>
This commit is contained in:
Julius Werner
2020-12-30 17:30:12 -08:00
parent 11075fc80e
commit 9b1f3cc6fb
10 changed files with 89 additions and 49 deletions

View File

@@ -5,6 +5,7 @@
#include <cbmem.h>
#include <commonlib/cbfs.h>
#include <commonlib/mem_pool.h>
#include <program_loading.h>
#include <types.h>
#include <vb2_sha.h>
@@ -26,7 +27,7 @@ static inline void *cbfs_ro_map(const char *name, size_t *size_out);
/* Removes a previously allocated CBFS mapping. Should try to unmap mappings in strict LIFO
order where possible, since mapping backends often don't support more complicated cases. */
int cbfs_unmap(void *mapping);
void cbfs_unmap(void *mapping);
/* Load a file from CBFS into a buffer. Returns amount of loaded bytes on success or 0 on error.
File will get decompressed as necessary. */
@@ -38,10 +39,21 @@ static inline size_t cbfs_ro_load(const char *name, void *buf, size_t buf_size);
/* Load stage into memory filling in prog. Return 0 on success. < 0 on error. */
int cbfs_prog_stage_load(struct prog *prog);
/**********************************************************************************************
* BOOT DEVICE HELPER APIs *
**********************************************************************************************/
/*
* The shared memory pool for backing mapped CBFS files, and other CBFS allocation needs.
* On x86 platforms, this would only be needed to transparently map compressed files, but it
* would require a permanent CBMEM carveout to be safe to use during S3 resume. Since it's not
* clear whether this feature is necessary or worth the wasted memory, it is currently disabled
* but could be added behind a Kconfig later if desired.
*/
#define CBFS_CACHE_AVAILABLE (!CONFIG(ARCH_X86))
extern struct mem_pool cbfs_cache;
/*
* Data structure that represents "a" CBFS boot device, with optional metadata cache. Generally
* we only have one of these, or two (RO and RW) when CONFIG(VBOOT) is set. The region device
@@ -95,6 +107,7 @@ void *cbfs_boot_map_optionrom_revision(uint16_t vendor, uint16_t device, uint8_t
size_t cbfs_load_and_decompress(const struct region_device *rdev, size_t offset,
size_t in_size, void *buffer, size_t buffer_size, uint32_t compression);
/**********************************************************************************************
* INTERNAL HELPERS FOR INLINES, DO NOT USE. *
**********************************************************************************************/