xref: /openbsd/sys/dev/pci/drm/include/linux/firmware.h (revision 1bb76ff1)
1 /* Public domain. */
2 
3 #ifndef _LINUX_FIRMWARE_H
4 #define _LINUX_FIRMWARE_H
5 
6 #include <sys/types.h>
7 #include <sys/malloc.h>
8 #include <sys/device.h>
9 #include <linux/types.h>
10 #include <linux/gfp.h>
11 
12 #ifndef __DECONST
13 #define __DECONST(type, var)	((type)(__uintptr_t)(const void *)(var))
14 #endif
15 
16 struct firmware {
17 	size_t size;
18 	const u8 *data;
19 };
20 
21 static inline int
request_firmware(const struct firmware ** fw,const char * name,struct device * device)22 request_firmware(const struct firmware **fw, const char *name,
23     struct device *device)
24 {
25 	int r;
26 	struct firmware *f = malloc(sizeof(struct firmware), M_DRM,
27 	    M_WAITOK | M_ZERO);
28 	r = loadfirmware(name, __DECONST(u_char **, &f->data), &f->size);
29 	if (r != 0) {
30 		free(f, M_DRM, sizeof(struct firmware));
31 		*fw = NULL;
32 		return -r;
33 	} else  {
34 		*fw = f;
35 		return 0;
36 	}
37 }
38 
39 static inline int
firmware_request_nowarn(const struct firmware ** fw,const char * name,struct device * device)40 firmware_request_nowarn(const struct firmware **fw, const char *name,
41     struct device *device)
42 {
43 	return request_firmware(fw, name, device);
44 }
45 
46 static inline int
request_firmware_direct(const struct firmware ** fw,const char * name,struct device * device)47 request_firmware_direct(const struct firmware **fw, const char *name,
48     struct device *device)
49 {
50 	return request_firmware(fw, name, device);
51 }
52 
53 #define request_firmware_nowait(a, b, c, d, e, f, g) -EINVAL
54 
55 static inline void
release_firmware(const struct firmware * fw)56 release_firmware(const struct firmware *fw)
57 {
58 	if (fw)
59 		free(__DECONST(u_char *, fw->data), M_DEVBUF, fw->size);
60 	free(__DECONST(struct firmware *, fw), M_DRM, sizeof(*fw));
61 }
62 
63 #endif
64