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 | |
Aaron Durbin | 295d58b | 2015-12-15 13:33:51 -0600 | [diff] [blame] | 6 | #include <commonlib/cbfs.h> |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 7 | #include <program_loading.h> |
Daisuke Nojiri | e1298df | 2014-12-01 15:30:01 -0800 | [diff] [blame] | 8 | |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 9 | /*********************************************** |
| 10 | * Perform CBFS operations on the boot device. * |
| 11 | ***********************************************/ |
| 12 | |
Elyes HAOUAS | 918535a | 2016-07-28 21:25:21 +0200 | [diff] [blame] | 13 | /* Return mapping of option ROM found in boot device. NULL on error. */ |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 14 | void *cbfs_boot_map_optionrom(uint16_t vendor, uint16_t device); |
Martin Roth | a616a4b | 2020-01-21 09:28:40 -0700 | [diff] [blame] | 15 | /* Return mapping of option ROM with revision number. Returns NULL on error. */ |
| 16 | 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] | 17 | /* 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] | 18 | int cbfs_boot_locate(struct cbfsf *fh, const char *name, uint32_t *type); |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 19 | /* Map file into memory leaking the mapping. Only should be used when |
| 20 | * leaking mappings are a no-op. Returns NULL on error, else returns |
| 21 | * the mapping and sets the size of the file. */ |
| 22 | void *cbfs_boot_map_with_leak(const char *name, uint32_t type, size_t *size); |
Pratik Prajapati | 2a7708a | 2016-11-30 17:29:10 -0800 | [diff] [blame] | 23 | /* Locate file in a specific region of fmap. Return 0 on success. < 0 on error*/ |
| 24 | int cbfs_locate_file_in_region(struct cbfsf *fh, const char *region_name, |
| 25 | const char *name, uint32_t *type); |
T Michael Turney | 809fa7b | 2018-04-12 13:36:40 -0700 | [diff] [blame] | 26 | /* Load an arbitrary type file from CBFS into a buffer. Returns amount of |
| 27 | * loaded bytes on success or 0 on error. File will get decompressed as |
| 28 | * necessary. Same decompression requirements as |
| 29 | * cbfs_load_and_decompress(). */ |
| 30 | size_t cbfs_boot_load_file(const char *name, void *buf, size_t buf_size, |
| 31 | uint32_t type); |
Julius Werner | 09f2921 | 2015-09-29 13:51:35 -0700 | [diff] [blame] | 32 | /* Load |in_size| bytes from |rdev| at |offset| to the |buffer_size| bytes |
| 33 | * large |buffer|, decompressing it according to |compression| in the process. |
| 34 | * Returns the decompressed file size, or 0 on error. |
| 35 | * LZMA files will be mapped for decompression. LZ4 files will be decompressed |
| 36 | * in-place with the buffer size requirements outlined in compression.h. */ |
| 37 | size_t cbfs_load_and_decompress(const struct region_device *rdev, size_t offset, |
| 38 | size_t in_size, void *buffer, size_t buffer_size, uint32_t compression); |
| 39 | |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 40 | /* Load stage into memory filling in prog. Return 0 on success. < 0 on error. */ |
| 41 | int cbfs_prog_stage_load(struct prog *prog); |
| 42 | |
Julius Werner | 815611e | 2019-12-05 22:29:07 -0800 | [diff] [blame] | 43 | /* Returns the region device of the currently active CBFS. |
Aaron Durbin | fe338e2 | 2019-11-18 12:35:21 -0700 | [diff] [blame] | 44 | Return < 0 on error, 0 on success. */ |
| 45 | int cbfs_boot_region_device(struct region_device *rdev); |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 46 | |
Peter Stuge | 483b7bb | 2009-04-14 07:40:01 +0000 | [diff] [blame] | 47 | #endif |