Angel Pons | 32859fc | 2020-04-02 23:48:27 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Peter Stuge | 483b7bb | 2009-04-14 07:40:01 +0000 | [diff] [blame] | 2 | |
| 3 | #ifndef _CBFS_H_ |
| 4 | #define _CBFS_H_ |
| 5 | |
Julius Werner | 1e37c9c | 2019-12-11 17:09:39 -0800 | [diff] [blame] | 6 | #include <cbmem.h> |
Aaron Durbin | 295d58b | 2015-12-15 13:33:51 -0600 | [diff] [blame] | 7 | #include <commonlib/cbfs.h> |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 8 | #include <program_loading.h> |
Julius Werner | 1e37c9c | 2019-12-11 17:09:39 -0800 | [diff] [blame] | 9 | #include <types.h> |
Daisuke Nojiri | e1298df | 2014-12-01 15:30:01 -0800 | [diff] [blame] | 10 | |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 11 | /*********************************************** |
| 12 | * Perform CBFS operations on the boot device. * |
| 13 | ***********************************************/ |
| 14 | |
Elyes HAOUAS | 918535a | 2016-07-28 21:25:21 +0200 | [diff] [blame] | 15 | /* Return mapping of option ROM found in boot device. NULL on error. */ |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 16 | void *cbfs_boot_map_optionrom(uint16_t vendor, uint16_t device); |
Martin Roth | a616a4b | 2020-01-21 09:28:40 -0700 | [diff] [blame] | 17 | /* Return mapping of option ROM with revision number. Returns NULL on error. */ |
| 18 | void *cbfs_boot_map_optionrom_revision(uint16_t vendor, uint16_t device, uint8_t rev); |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 19 | /* Locate file by name and optional type. Return 0 on success. < 0 on error. */ |
Aaron Durbin | 37a5d15 | 2015-09-17 16:09:30 -0500 | [diff] [blame] | 20 | int cbfs_boot_locate(struct cbfsf *fh, const char *name, uint32_t *type); |
Julius Werner | 834b3ec | 2020-03-04 16:52:08 -0800 | [diff] [blame^] | 21 | /* Map file into memory, returning a pointer to the mapping or NULL on error. |
| 22 | If |size_out| is not NULL, it will pass out the size of the mapped file. |
| 23 | NOTE: Since this may return a direct pointer to memory-mapped hardware, |
| 24 | compressed files are NOT transparently decompressed (unlike cbfs_load()). */ |
| 25 | void *cbfs_map(const char *name, size_t *size_out); |
| 26 | /* Removes a mapping previously allocated with cbfs_map(). Should try to unmap |
| 27 | mappings in strict LIFO order where possible, since mapping backends often |
| 28 | don't support more complicated cases. */ |
| 29 | int cbfs_unmap(void *mapping); |
Pratik Prajapati | 2a7708a | 2016-11-30 17:29:10 -0800 | [diff] [blame] | 30 | /* Locate file in a specific region of fmap. Return 0 on success. < 0 on error*/ |
| 31 | int cbfs_locate_file_in_region(struct cbfsf *fh, const char *region_name, |
| 32 | const char *name, uint32_t *type); |
Julius Werner | 834b3ec | 2020-03-04 16:52:08 -0800 | [diff] [blame^] | 33 | /* Load a file from CBFS into a buffer. Returns amount of loaded bytes on |
| 34 | success or 0 on error. File will get decompressed as necessary. Same |
| 35 | decompression requirements as cbfs_load_and_decompress(). */ |
| 36 | size_t cbfs_load(const char *name, void *buf, size_t buf_size); |
Julius Werner | 09f2921 | 2015-09-29 13:51:35 -0700 | [diff] [blame] | 37 | /* Load |in_size| bytes from |rdev| at |offset| to the |buffer_size| bytes |
| 38 | * large |buffer|, decompressing it according to |compression| in the process. |
| 39 | * Returns the decompressed file size, or 0 on error. |
| 40 | * LZMA files will be mapped for decompression. LZ4 files will be decompressed |
| 41 | * in-place with the buffer size requirements outlined in compression.h. */ |
| 42 | size_t cbfs_load_and_decompress(const struct region_device *rdev, size_t offset, |
| 43 | size_t in_size, void *buffer, size_t buffer_size, uint32_t compression); |
| 44 | |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 45 | /* Load stage into memory filling in prog. Return 0 on success. < 0 on error. */ |
| 46 | int cbfs_prog_stage_load(struct prog *prog); |
| 47 | |
Julius Werner | 0d9072b | 2020-03-05 12:51:08 -0800 | [diff] [blame] | 48 | /* |
| 49 | * Data structure that represents "a" CBFS boot device, with optional metadata |
| 50 | * cache. Generally we only have one of these, or two (RO and RW) when |
| 51 | * CONFIG(VBOOT) is set. The region device stored here must always be a |
| 52 | * subregion of boot_device_ro(). |
| 53 | */ |
Julius Werner | 1e37c9c | 2019-12-11 17:09:39 -0800 | [diff] [blame] | 54 | struct cbfs_boot_device { |
| 55 | struct region_device rdev; |
| 56 | void *mcache; |
| 57 | size_t mcache_size; |
| 58 | }; |
| 59 | |
| 60 | /* Helper to fill out |mcache| and |mcache_size| in a cbfs_boot_device. */ |
| 61 | void cbfs_boot_device_find_mcache(struct cbfs_boot_device *cbd, uint32_t id); |
| 62 | |
| 63 | /* |
| 64 | * Retrieves the currently active CBFS boot device. If |force_ro| is set, will |
| 65 | * always return the read-only CBFS instead (this only makes a difference when |
| 66 | * CONFIG(VBOOT) is enabled). May perform certain CBFS initialization tasks. |
| 67 | * Returns NULL on error (e.g. boot device IO error). |
| 68 | */ |
| 69 | const struct cbfs_boot_device *cbfs_get_boot_device(bool force_ro); |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 70 | |
Peter Stuge | 483b7bb | 2009-04-14 07:40:01 +0000 | [diff] [blame] | 71 | #endif |