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