xref: /dragonfly/sys/dev/drm/include/linux/firmware.h (revision e57b1815)
104e8519dSMichael Neumann /*
204e8519dSMichael Neumann  * Copyright (c) 2015 Michael Neumann
3*e57b1815SFrançois Tigeot  * Copyright (c) 2016 François Tigeot
404e8519dSMichael Neumann  * All rights reserved.
504e8519dSMichael Neumann  *
604e8519dSMichael Neumann  * Redistribution and use in source and binary forms, with or without
704e8519dSMichael Neumann  * modification, are permitted provided that the following conditions
804e8519dSMichael Neumann  * are met:
904e8519dSMichael Neumann  * 1. Redistributions of source code must retain the above copyright
1004e8519dSMichael Neumann  *    notice unmodified, this list of conditions, and the following
1104e8519dSMichael Neumann  *    disclaimer.
1204e8519dSMichael Neumann  * 2. Redistributions in binary form must reproduce the above copyright
1304e8519dSMichael Neumann  *    notice, this list of conditions and the following disclaimer in the
1404e8519dSMichael Neumann  *    documentation and/or other materials provided with the distribution.
1504e8519dSMichael Neumann  *
1604e8519dSMichael Neumann  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1704e8519dSMichael Neumann  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1804e8519dSMichael Neumann  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1904e8519dSMichael Neumann  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
2004e8519dSMichael Neumann  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2104e8519dSMichael Neumann  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2204e8519dSMichael Neumann  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2304e8519dSMichael Neumann  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2404e8519dSMichael Neumann  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2504e8519dSMichael Neumann  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2604e8519dSMichael Neumann  */
2704e8519dSMichael Neumann 
2804e8519dSMichael Neumann #ifndef _LINUX_FIRMWARE_H_
2904e8519dSMichael Neumann #define _LINUX_FIRMWARE_H_
3004e8519dSMichael Neumann 
3104e8519dSMichael Neumann #include <sys/bus.h>
3204e8519dSMichael Neumann #include <sys/firmware.h>
3371187b16SFrançois Tigeot #include <linux/types.h>
3471187b16SFrançois Tigeot #include <linux/compiler.h>
3571187b16SFrançois Tigeot #include <linux/gfp.h>
3671187b16SFrançois Tigeot #include <linux/device.h>
3704e8519dSMichael Neumann 
3804e8519dSMichael Neumann static inline int
request_firmware(const struct firmware ** fw,const char * name,__unused struct device * dev)3971187b16SFrançois Tigeot request_firmware(const struct firmware **fw, const char *name, __unused struct device *dev) {
4004e8519dSMichael Neumann 	*fw = firmware_get(name);
4104e8519dSMichael Neumann 	if (*fw) {
4204e8519dSMichael Neumann 		return 0;
4304e8519dSMichael Neumann 	}
44fcd4983fSzrj 	return -ENOENT;
4504e8519dSMichael Neumann }
4604e8519dSMichael Neumann 
47*e57b1815SFrançois Tigeot static inline int
request_firmware_nowait(struct module * module,bool uevent,const char * name,struct device * device,gfp_t gfp,void * context,void (* cont)(const struct firmware * fw,void * context))48*e57b1815SFrançois Tigeot request_firmware_nowait(struct module *module, bool uevent,
49*e57b1815SFrançois Tigeot     const char *name, struct device *device, gfp_t gfp, void *context,
50*e57b1815SFrançois Tigeot     void (*cont)(const struct firmware *fw, void *context))
51*e57b1815SFrançois Tigeot {
52*e57b1815SFrançois Tigeot 	const struct firmware *fw;
53*e57b1815SFrançois Tigeot 
54*e57b1815SFrançois Tigeot 	fw = firmware_get(name);
55*e57b1815SFrançois Tigeot 	if (fw == NULL) {
56*e57b1815SFrançois Tigeot 		return -ENOENT;
57*e57b1815SFrançois Tigeot 	}
58*e57b1815SFrançois Tigeot 
59*e57b1815SFrançois Tigeot 	cont(fw, context);
60*e57b1815SFrançois Tigeot 
61*e57b1815SFrançois Tigeot 	return 0;
62*e57b1815SFrançois Tigeot }
63*e57b1815SFrançois Tigeot 
6404e8519dSMichael Neumann static inline void
release_firmware(const struct firmware * fw)6504e8519dSMichael Neumann release_firmware(const struct firmware *fw) {
66fcd4983fSzrj 	if (fw != NULL) {
6704e8519dSMichael Neumann 		firmware_put(fw, FIRMWARE_UNLOAD);
6804e8519dSMichael Neumann 	}
69fcd4983fSzrj }
7004e8519dSMichael Neumann 
7104e8519dSMichael Neumann #endif	/* _LINUX_FIRMWARE_H_ */
72