xref: /freebsd/sys/compat/linuxkpi/common/include/linux/firmware.h (revision 02e9120893770924227138ba49df1edb3896112a)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 2020-2021 The FreeBSD Foundation
5  * Copyright (c) 2022 Bjoern A. Zeeb
6  *
7  * This software was developed by Björn Zeeb under sponsorship from
8  * the FreeBSD Foundation.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29  * SUCH DAMAGE.
30  */
31 
32 #ifndef	_LINUXKPI_LINUX_FIRMWARE_H
33 #define	_LINUXKPI_LINUX_FIRMWARE_H
34 
35 #include <sys/types.h>
36 #include <linux/types.h>
37 #include <linux/device.h>
38 
39 struct firmware;
40 
41 struct linuxkpi_firmware {
42 	size_t			size;
43 	const uint8_t		*data;
44 	/* XXX Does Linux expose anything else? */
45 
46 	/* This is LinuxKPI implementation private. */
47 	const struct firmware	*fbdfw;
48 };
49 
50 int linuxkpi_request_firmware_nowait(struct module *, bool, const char *,
51     struct device *, gfp_t, void *,
52     void(*cont)(const struct linuxkpi_firmware *, void *));
53 int linuxkpi_request_firmware(const struct linuxkpi_firmware **,
54     const char *, struct device *);
55 int linuxkpi_firmware_request_nowarn(const struct linuxkpi_firmware **,
56     const char *, struct device *);
57 void linuxkpi_release_firmware(const struct linuxkpi_firmware *);
58 int linuxkpi_request_partial_firmware_into_buf(const struct linuxkpi_firmware **,
59     const char *, struct device *, uint8_t *, size_t, size_t);
60 
61 
62 static __inline int
63 request_firmware_nowait(struct module *mod, bool _t,
64     const char *fw_name, struct device *dev, gfp_t gfp, void *drv,
65     void(*cont)(const struct linuxkpi_firmware *, void *))
66 {
67 
68 
69 	return (linuxkpi_request_firmware_nowait(mod, _t, fw_name, dev, gfp,
70 	    drv, cont));
71 }
72 
73 static __inline int
74 request_firmware(const struct linuxkpi_firmware **fw,
75     const char *fw_name, struct device *dev)
76 {
77 
78 	return (linuxkpi_request_firmware(fw, fw_name, dev));
79 }
80 
81 static __inline int
82 request_firmware_direct(const struct linuxkpi_firmware **fw,
83     const char *fw_name, struct device *dev)
84 {
85 
86 	return (linuxkpi_request_firmware(fw, fw_name, dev));
87 }
88 
89 static __inline int
90 firmware_request_nowarn(const struct linuxkpi_firmware **fw,
91     const char *fw_name, struct device *dev)
92 {
93 
94 	return (linuxkpi_firmware_request_nowarn(fw, fw_name, dev));
95 }
96 
97 static __inline void
98 release_firmware(const struct linuxkpi_firmware *fw)
99 {
100 
101 	linuxkpi_release_firmware(fw);
102 }
103 
104 static inline int
105 request_partial_firmware_into_buf(const struct linuxkpi_firmware **fw,
106     const char *fw_name, struct device *dev, void *buf, size_t buflen,
107     size_t offset)
108 {
109 
110 	return (linuxkpi_request_partial_firmware_into_buf(fw, fw_name,
111 	    dev, buf, buflen, offset));
112 }
113 
114 #define	firmware	linuxkpi_firmware
115 
116 #endif	/* _LINUXKPI_LINUX_FIRMWARE_H */
117