aboutsummaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
authorJulius Werner <jwerner@chromium.org>2020-03-04 16:52:08 -0800
committerPatrick Georgi <pgeorgi@google.com>2020-12-02 22:13:17 +0000
commit834b3ecd7cbefbad8f09a9bda4f10cd7842cdbcd (patch)
tree13db079f261e5fd3854f85e7f03c2d177fa7dbbb /src/include
parent0d9072b1a196627755164288a9f334ef844628f5 (diff)
cbfs: Simplify load/map API names, remove type arguments
This patch renames cbfs_boot_map_with_leak() and cbfs_boot_load_file() to cbfs_map() and cbfs_load() respectively. This is supposed to be the start of a new, better organized CBFS API where the most common operations have the most simple and straight-forward names. Less commonly used variants of these operations (e.g. cbfs_ro_load() or cbfs_region_load()) can be introduced later. It seems unnecessary to keep carrying around "boot" in the names of most CBFS APIs if the vast majority of accesses go to the boot CBFS (instead, more unusual operations should have longer names that describe how they diverge from the common ones). cbfs_map() is paired with a new cbfs_unmap() to allow callers to cleanly reap mappings when desired. A few new cbfs_unmap() calls are added to generic code where it makes sense, but it seems unnecessary to introduce this everywhere in platform or architecture specific code where the boot medium is known to be memory-mapped anyway. In fact, even for non-memory-mapped platforms, sometimes leaking a mapping to the CBFS cache is a much cleaner solution than jumping through hoops to provide some other storage for some long-lived file object, and it shouldn't be outright forbidden when it makes sense. Additionally, remove the type arguments from these function signatures. The goal is to eventually remove type arguments for lookup from the whole CBFS API. Filenames already uniquely identify CBFS files. The type field is just informational, and there should be APIs to allow callers to check it when desired, but it's not clear what we gain from forcing this as a parameter into every single CBFS access when the vast majority of the time it provides no additional value and is just clutter. Signed-off-by: Julius Werner <jwerner@chromium.org> Change-Id: Ib24325400815a9c3d25f66c61829a24a239bb88e Reviewed-on: https://review.coreboot.org/c/coreboot/+/39304 Reviewed-by: Hung-Te Lin <hungte@chromium.org> Reviewed-by: Wim Vervoorn <wvervoorn@eltan.com> Reviewed-by: Mariusz SzafraƄski <mariuszx.szafranski@intel.com> Reviewed-by: Patrick Georgi <pgeorgi@google.com> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Diffstat (limited to 'src/include')
-rw-r--r--src/include/cbfs.h23
1 files changed, 13 insertions, 10 deletions
diff --git a/src/include/cbfs.h b/src/include/cbfs.h
index 1b446ac7a8..992b6583ca 100644
--- a/src/include/cbfs.h
+++ b/src/include/cbfs.h
@@ -18,19 +18,22 @@ void *cbfs_boot_map_optionrom(uint16_t vendor, uint16_t device);
void *cbfs_boot_map_optionrom_revision(uint16_t vendor, uint16_t device, uint8_t rev);
/* Locate file by name and optional type. Return 0 on success. < 0 on error. */
int cbfs_boot_locate(struct cbfsf *fh, const char *name, uint32_t *type);
-/* Map file into memory leaking the mapping. Only should be used when
- * leaking mappings are a no-op. Returns NULL on error, else returns
- * the mapping and sets the size of the file. */
-void *cbfs_boot_map_with_leak(const char *name, uint32_t type, size_t *size);
+/* Map file into memory, returning a pointer to the mapping or NULL on error.
+ If |size_out| is not NULL, it will pass out the size of the mapped file.
+ NOTE: Since this may return a direct pointer to memory-mapped hardware,
+ compressed files are NOT transparently decompressed (unlike cbfs_load()). */
+void *cbfs_map(const char *name, size_t *size_out);
+/* Removes a mapping previously allocated with cbfs_map(). 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);
/* Locate file in a specific region of fmap. Return 0 on success. < 0 on error*/
int cbfs_locate_file_in_region(struct cbfsf *fh, const char *region_name,
const char *name, uint32_t *type);
-/* Load an arbitrary type file from CBFS into a buffer. Returns amount of
- * loaded bytes on success or 0 on error. File will get decompressed as
- * necessary. Same decompression requirements as
- * cbfs_load_and_decompress(). */
-size_t cbfs_boot_load_file(const char *name, void *buf, size_t buf_size,
- uint32_t type);
+/* 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. Same
+ decompression requirements as cbfs_load_and_decompress(). */
+size_t cbfs_load(const char *name, void *buf, size_t buf_size);
/* Load |in_size| bytes from |rdev| at |offset| to the |buffer_size| bytes
* large |buffer|, decompressing it according to |compression| in the process.
* Returns the decompressed file size, or 0 on error.