blob: 32ed7f899eb1b32421741531fe4090766de1c945 [file] [log] [blame]
Angel Pons32859fc2020-04-02 23:48:27 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Peter Stuge483b7bb2009-04-14 07:40:01 +00002
3#ifndef _CBFS_H_
4#define _CBFS_H_
5
Julius Werner1e37c9c2019-12-11 17:09:39 -08006#include <cbmem.h>
Aaron Durbin295d58b2015-12-15 13:33:51 -06007#include <commonlib/cbfs.h>
Aaron Durbin899d13d2015-05-15 23:39:23 -05008#include <program_loading.h>
Julius Werner1e37c9c2019-12-11 17:09:39 -08009#include <types.h>
Daisuke Nojirie1298df2014-12-01 15:30:01 -080010
Aaron Durbin899d13d2015-05-15 23:39:23 -050011/***********************************************
12 * Perform CBFS operations on the boot device. *
13 ***********************************************/
14
Elyes HAOUAS918535a2016-07-28 21:25:21 +020015/* Return mapping of option ROM found in boot device. NULL on error. */
Aaron Durbin899d13d2015-05-15 23:39:23 -050016void *cbfs_boot_map_optionrom(uint16_t vendor, uint16_t device);
Martin Rotha616a4b2020-01-21 09:28:40 -070017/* Return mapping of option ROM with revision number. Returns NULL on error. */
18void *cbfs_boot_map_optionrom_revision(uint16_t vendor, uint16_t device, uint8_t rev);
Aaron Durbin899d13d2015-05-15 23:39:23 -050019/* Locate file by name and optional type. Return 0 on success. < 0 on error. */
Aaron Durbin37a5d152015-09-17 16:09:30 -050020int cbfs_boot_locate(struct cbfsf *fh, const char *name, uint32_t *type);
Aaron Durbin899d13d2015-05-15 23:39:23 -050021/* Map file into memory leaking the mapping. Only should be used when
22 * leaking mappings are a no-op. Returns NULL on error, else returns
23 * the mapping and sets the size of the file. */
24void *cbfs_boot_map_with_leak(const char *name, uint32_t type, size_t *size);
Pratik Prajapati2a7708a2016-11-30 17:29:10 -080025/* Locate file in a specific region of fmap. Return 0 on success. < 0 on error*/
26int cbfs_locate_file_in_region(struct cbfsf *fh, const char *region_name,
27 const char *name, uint32_t *type);
T Michael Turney809fa7b2018-04-12 13:36:40 -070028/* Load an arbitrary type file from CBFS into a buffer. Returns amount of
29 * loaded bytes on success or 0 on error. File will get decompressed as
30 * necessary. Same decompression requirements as
31 * cbfs_load_and_decompress(). */
32size_t cbfs_boot_load_file(const char *name, void *buf, size_t buf_size,
33 uint32_t type);
Julius Werner09f29212015-09-29 13:51:35 -070034/* Load |in_size| bytes from |rdev| at |offset| to the |buffer_size| bytes
35 * large |buffer|, decompressing it according to |compression| in the process.
36 * Returns the decompressed file size, or 0 on error.
37 * LZMA files will be mapped for decompression. LZ4 files will be decompressed
38 * in-place with the buffer size requirements outlined in compression.h. */
39size_t cbfs_load_and_decompress(const struct region_device *rdev, size_t offset,
40 size_t in_size, void *buffer, size_t buffer_size, uint32_t compression);
41
Aaron Durbin899d13d2015-05-15 23:39:23 -050042/* Load stage into memory filling in prog. Return 0 on success. < 0 on error. */
43int cbfs_prog_stage_load(struct prog *prog);
44
Julius Werner1e37c9c2019-12-11 17:09:39 -080045struct cbfs_boot_device {
46 struct region_device rdev;
47 void *mcache;
48 size_t mcache_size;
49};
50
51/* Helper to fill out |mcache| and |mcache_size| in a cbfs_boot_device. */
52void cbfs_boot_device_find_mcache(struct cbfs_boot_device *cbd, uint32_t id);
53
54/*
55 * Retrieves the currently active CBFS boot device. If |force_ro| is set, will
56 * always return the read-only CBFS instead (this only makes a difference when
57 * CONFIG(VBOOT) is enabled). May perform certain CBFS initialization tasks.
58 * Returns NULL on error (e.g. boot device IO error).
59 */
60const struct cbfs_boot_device *cbfs_get_boot_device(bool force_ro);
Aaron Durbin899d13d2015-05-15 23:39:23 -050061
Peter Stuge483b7bb2009-04-14 07:40:01 +000062#endif