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