18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci#ifndef _LINUX_FIRMWARE_H 38c2ecf20Sopenharmony_ci#define _LINUX_FIRMWARE_H 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ci#include <linux/types.h> 68c2ecf20Sopenharmony_ci#include <linux/compiler.h> 78c2ecf20Sopenharmony_ci#include <linux/gfp.h> 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#define FW_ACTION_NOHOTPLUG 0 108c2ecf20Sopenharmony_ci#define FW_ACTION_HOTPLUG 1 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_cistruct firmware { 138c2ecf20Sopenharmony_ci size_t size; 148c2ecf20Sopenharmony_ci const u8 *data; 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_ci /* firmware loader private fields */ 178c2ecf20Sopenharmony_ci void *priv; 188c2ecf20Sopenharmony_ci}; 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_cistruct module; 218c2ecf20Sopenharmony_cistruct device; 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_cistruct builtin_fw { 248c2ecf20Sopenharmony_ci char *name; 258c2ecf20Sopenharmony_ci void *data; 268c2ecf20Sopenharmony_ci unsigned long size; 278c2ecf20Sopenharmony_ci}; 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_ci/* We have to play tricks here much like stringify() to get the 308c2ecf20Sopenharmony_ci __COUNTER__ macro to be expanded as we want it */ 318c2ecf20Sopenharmony_ci#define __fw_concat1(x, y) x##y 328c2ecf20Sopenharmony_ci#define __fw_concat(x, y) __fw_concat1(x, y) 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_ci#define DECLARE_BUILTIN_FIRMWARE(name, blob) \ 358c2ecf20Sopenharmony_ci DECLARE_BUILTIN_FIRMWARE_SIZE(name, &(blob), sizeof(blob)) 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ci#define DECLARE_BUILTIN_FIRMWARE_SIZE(name, blob, size) \ 388c2ecf20Sopenharmony_ci static const struct builtin_fw __fw_concat(__builtin_fw,__COUNTER__) \ 398c2ecf20Sopenharmony_ci __used __section(".builtin_fw") = { name, blob, size } 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ci#if defined(CONFIG_FW_LOADER) || (defined(CONFIG_FW_LOADER_MODULE) && defined(MODULE)) 428c2ecf20Sopenharmony_ciint request_firmware(const struct firmware **fw, const char *name, 438c2ecf20Sopenharmony_ci struct device *device); 448c2ecf20Sopenharmony_ciint firmware_request_nowarn(const struct firmware **fw, const char *name, 458c2ecf20Sopenharmony_ci struct device *device); 468c2ecf20Sopenharmony_ciint firmware_request_platform(const struct firmware **fw, const char *name, 478c2ecf20Sopenharmony_ci struct device *device); 488c2ecf20Sopenharmony_ciint request_firmware_nowait( 498c2ecf20Sopenharmony_ci struct module *module, bool uevent, 508c2ecf20Sopenharmony_ci const char *name, struct device *device, gfp_t gfp, void *context, 518c2ecf20Sopenharmony_ci void (*cont)(const struct firmware *fw, void *context)); 528c2ecf20Sopenharmony_ciint request_firmware_direct(const struct firmware **fw, const char *name, 538c2ecf20Sopenharmony_ci struct device *device); 548c2ecf20Sopenharmony_ciint request_firmware_into_buf(const struct firmware **firmware_p, 558c2ecf20Sopenharmony_ci const char *name, struct device *device, void *buf, size_t size); 568c2ecf20Sopenharmony_ciint request_partial_firmware_into_buf(const struct firmware **firmware_p, 578c2ecf20Sopenharmony_ci const char *name, struct device *device, 588c2ecf20Sopenharmony_ci void *buf, size_t size, size_t offset); 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_civoid release_firmware(const struct firmware *fw); 618c2ecf20Sopenharmony_ci#else 628c2ecf20Sopenharmony_cistatic inline int request_firmware(const struct firmware **fw, 638c2ecf20Sopenharmony_ci const char *name, 648c2ecf20Sopenharmony_ci struct device *device) 658c2ecf20Sopenharmony_ci{ 668c2ecf20Sopenharmony_ci return -EINVAL; 678c2ecf20Sopenharmony_ci} 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_cistatic inline int firmware_request_nowarn(const struct firmware **fw, 708c2ecf20Sopenharmony_ci const char *name, 718c2ecf20Sopenharmony_ci struct device *device) 728c2ecf20Sopenharmony_ci{ 738c2ecf20Sopenharmony_ci return -EINVAL; 748c2ecf20Sopenharmony_ci} 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_cistatic inline int firmware_request_platform(const struct firmware **fw, 778c2ecf20Sopenharmony_ci const char *name, 788c2ecf20Sopenharmony_ci struct device *device) 798c2ecf20Sopenharmony_ci{ 808c2ecf20Sopenharmony_ci return -EINVAL; 818c2ecf20Sopenharmony_ci} 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_cistatic inline int request_firmware_nowait( 848c2ecf20Sopenharmony_ci struct module *module, bool uevent, 858c2ecf20Sopenharmony_ci const char *name, struct device *device, gfp_t gfp, void *context, 868c2ecf20Sopenharmony_ci void (*cont)(const struct firmware *fw, void *context)) 878c2ecf20Sopenharmony_ci{ 888c2ecf20Sopenharmony_ci return -EINVAL; 898c2ecf20Sopenharmony_ci} 908c2ecf20Sopenharmony_ci 918c2ecf20Sopenharmony_cistatic inline void release_firmware(const struct firmware *fw) 928c2ecf20Sopenharmony_ci{ 938c2ecf20Sopenharmony_ci} 948c2ecf20Sopenharmony_ci 958c2ecf20Sopenharmony_cistatic inline int request_firmware_direct(const struct firmware **fw, 968c2ecf20Sopenharmony_ci const char *name, 978c2ecf20Sopenharmony_ci struct device *device) 988c2ecf20Sopenharmony_ci{ 998c2ecf20Sopenharmony_ci return -EINVAL; 1008c2ecf20Sopenharmony_ci} 1018c2ecf20Sopenharmony_ci 1028c2ecf20Sopenharmony_cistatic inline int request_firmware_into_buf(const struct firmware **firmware_p, 1038c2ecf20Sopenharmony_ci const char *name, struct device *device, void *buf, size_t size) 1048c2ecf20Sopenharmony_ci{ 1058c2ecf20Sopenharmony_ci return -EINVAL; 1068c2ecf20Sopenharmony_ci} 1078c2ecf20Sopenharmony_ci 1088c2ecf20Sopenharmony_cistatic inline int request_partial_firmware_into_buf 1098c2ecf20Sopenharmony_ci (const struct firmware **firmware_p, 1108c2ecf20Sopenharmony_ci const char *name, 1118c2ecf20Sopenharmony_ci struct device *device, 1128c2ecf20Sopenharmony_ci void *buf, size_t size, size_t offset) 1138c2ecf20Sopenharmony_ci{ 1148c2ecf20Sopenharmony_ci return -EINVAL; 1158c2ecf20Sopenharmony_ci} 1168c2ecf20Sopenharmony_ci 1178c2ecf20Sopenharmony_ci#endif 1188c2ecf20Sopenharmony_ci 1198c2ecf20Sopenharmony_ciint firmware_request_cache(struct device *device, const char *name); 1208c2ecf20Sopenharmony_ci 1218c2ecf20Sopenharmony_ci#endif 122