src/include: Open brace on same line as enum or struct
[coreboot.git] / src / include / cbfs.h
blob1350671af21a84b69bea462c203f744fdffeb1cd
1 /*
2 * This file is part of the coreboot project.
4 * Copyright 2015 Google Inc.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
16 #ifndef _CBFS_H_
17 #define _CBFS_H_
19 #include <commonlib/cbfs.h>
20 #include <program_loading.h>
22 /***********************************************
23 * Perform CBFS operations on the boot device. *
24 ***********************************************/
26 /* Return mapping of option ROM found in boot device. NULL on error. */
27 void *cbfs_boot_map_optionrom(uint16_t vendor, uint16_t device);
28 /* Load stage by name into memory. Returns entry address on success. NULL on
29 * failure. */
30 void *cbfs_boot_load_stage_by_name(const char *name);
31 /* Locate file by name and optional type. Return 0 on success. < 0 on error. */
32 int cbfs_boot_locate(struct cbfsf *fh, const char *name, uint32_t *type);
33 /* Map file into memory leaking the mapping. Only should be used when
34 * leaking mappings are a no-op. Returns NULL on error, else returns
35 * the mapping and sets the size of the file. */
36 void *cbfs_boot_map_with_leak(const char *name, uint32_t type, size_t *size);
37 /* Locate file in a specific region of fmap. Return 0 on success. < 0 on error*/
38 int cbfs_locate_file_in_region(struct cbfsf *fh, const char *region_name,
39 const char *name, uint32_t *type);
40 /* Load a struct file from CBFS into a buffer. Returns amount of loaded
41 * bytes on success or 0 on error. File will get decompressed as necessary.
42 * Same decompression requirements as cbfs_load_and_decompress(). */
43 size_t cbfs_boot_load_struct(const char *name, void *buf, size_t buf_size);
45 /* Load |in_size| bytes from |rdev| at |offset| to the |buffer_size| bytes
46 * large |buffer|, decompressing it according to |compression| in the process.
47 * Returns the decompressed file size, or 0 on error.
48 * LZMA files will be mapped for decompression. LZ4 files will be decompressed
49 * in-place with the buffer size requirements outlined in compression.h. */
50 size_t cbfs_load_and_decompress(const struct region_device *rdev, size_t offset,
51 size_t in_size, void *buffer, size_t buffer_size, uint32_t compression);
53 /* Return the size and fill base of the memory pstage will occupy after loaded. */
54 size_t cbfs_prog_stage_section(struct prog *pstage, uintptr_t *base);
56 /* Load stage into memory filling in prog. Return 0 on success. < 0 on error. */
57 int cbfs_prog_stage_load(struct prog *prog);
59 /*****************************************************************
60 * Support structures and functions. Direct field access should *
61 * only be done by implementers of cbfs regions -- Not the above *
62 * API. *
63 *****************************************************************/
65 /* The cbfs_props struct describes the properties associated with a CBFS. */
66 struct cbfs_props {
67 /* CBFS starts at the following offset within the boot region. */
68 size_t offset;
69 /* CBFS size. */
70 size_t size;
73 /* Return < 0 on error otherwise props are filled out accordingly. */
74 int cbfs_boot_region_properties(struct cbfs_props *props);
76 /* Allow external logic to take action prior to locating a program
77 * (stage or payload). */
78 void cbfs_prepare_program_locate(void);
80 /* Object used to identify location of current cbfs to use for cbfs_boot_*
81 * operations. It's used by cbfs_boot_region_properties() and
82 * cbfs_prepare_program_locate(). */
83 struct cbfs_locator {
84 const char *name;
85 void (*prepare)(void);
86 /* Returns 0 on successful fill of cbfs properties. */
87 int (*locate)(struct cbfs_props *props);
90 #endif