soc/intel/xeon_sp: Revise IIO domain ACPI name encoding
[coreboot2.git] / payloads / libpayload / include / cbfs.h
blob9420cb0039ec3f98a7006a2d87e12e22dd71dce6
1 /* SPDX-License-Identifier: BSD-3-Clause */
3 #ifndef _CBFS_H_
4 #define _CBFS_H_
6 #include <commonlib/bsd/cb_err.h>
7 #include <commonlib/bsd/cbfs_mdata.h>
8 #include <endian.h>
9 #include <stdbool.h>
12 /**********************************************************************************************
13 * CBFS FILE ACCESS APIs *
14 **********************************************************************************************/
16 /* For documentation look in src/include/cbfs.h file in the main coreboot source tree. */
18 static inline size_t cbfs_load(const char *name, void *buf, size_t size);
19 static inline size_t cbfs_ro_load(const char *name, void *buf, size_t size);
20 static inline size_t cbfs_unverified_area_load(const char *area, const char *name, void *buf,
21 size_t size);
23 static inline void *cbfs_map(const char *name, size_t *size_out);
24 static inline void *cbfs_ro_map(const char *name, size_t *size_out);
25 static inline void *cbfs_unverified_area_map(const char *area, const char *name,
26 size_t *size_out);
28 void cbfs_unmap(void *mapping);
30 static inline size_t cbfs_get_size(const char *name);
31 static inline size_t cbfs_ro_get_size(const char *name);
33 static inline enum cbfs_type cbfs_get_type(const char *name);
34 static inline enum cbfs_type cbfs_ro_get_type(const char *name);
36 static inline bool cbfs_file_exists(const char *name);
37 static inline bool cbfs_ro_file_exists(const char *name);
39 /**********************************************************************************************
40 * INTERNAL HELPERS FOR INLINES, DO NOT USE. *
41 **********************************************************************************************/
42 ssize_t _cbfs_boot_lookup(const char *name, bool force_ro, union cbfs_mdata *mdata);
44 void *_cbfs_load(const char *name, void *buf, size_t *size_inout, bool force_ro);
46 void *_cbfs_unverified_area_load(const char *area, const char *name, void *buf,
47 size_t *size_inout);
49 /**********************************************************************************************
50 * INLINE IMPLEMENTATIONS *
51 **********************************************************************************************/
53 static inline void *cbfs_map(const char *name, size_t *size_out)
55 return _cbfs_load(name, NULL, size_out, false);
58 static inline void *cbfs_ro_map(const char *name, size_t *size_out)
60 return _cbfs_load(name, NULL, size_out, true);
63 static inline void *cbfs_unverified_area_map(const char *area, const char *name,
64 size_t *size_out)
66 return _cbfs_unverified_area_load(area, name, NULL, size_out);
69 static inline size_t cbfs_load(const char *name, void *buf, size_t size)
71 if (_cbfs_load(name, buf, &size, false))
72 return size;
73 else
74 return 0;
77 static inline size_t cbfs_ro_load(const char *name, void *buf, size_t size)
79 if (_cbfs_load(name, buf, &size, true))
80 return size;
81 else
82 return 0;
85 static inline size_t cbfs_unverified_area_load(const char *area, const char *name, void *buf,
86 size_t size)
88 if (_cbfs_unverified_area_load(area, name, buf, &size))
89 return size;
90 else
91 return 0;
94 static inline size_t cbfs_get_size(const char *name)
96 union cbfs_mdata mdata;
97 if (_cbfs_boot_lookup(name, false, &mdata) < 0)
98 return 0;
99 else
100 return be32toh(mdata.h.len);
103 static inline size_t cbfs_ro_get_size(const char *name)
105 union cbfs_mdata mdata;
106 if (_cbfs_boot_lookup(name, true, &mdata) < 0)
107 return 0;
108 else
109 return be32toh(mdata.h.len);
112 static inline enum cbfs_type cbfs_get_type(const char *name)
114 union cbfs_mdata mdata;
115 if (_cbfs_boot_lookup(name, false, &mdata) < 0)
116 return CBFS_TYPE_NULL;
117 else
118 return be32toh(mdata.h.type);
121 static inline enum cbfs_type cbfs_ro_get_type(const char *name)
123 union cbfs_mdata mdata;
124 if (_cbfs_boot_lookup(name, true, &mdata) < 0)
125 return CBFS_TYPE_NULL;
126 else
127 return be32toh(mdata.h.type);
130 static inline bool cbfs_file_exists(const char *name)
132 union cbfs_mdata mdata;
133 return _cbfs_boot_lookup(name, false, &mdata) >= 0;
136 static inline bool cbfs_ro_file_exists(const char *name)
138 union cbfs_mdata mdata;
139 return _cbfs_boot_lookup(name, true, &mdata) >= 0;
142 #endif