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 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 40 request_firmware_direct(const struct firmware **fw, const char *name, 41 struct device *device) 42 { 43 return request_firmware(fw, name, device); 44 } 45 46 #define request_firmware_nowait(a, b, c, d, e, f, g) -EINVAL 47 48 static inline void 49 release_firmware(const struct firmware *fw) 50 { 51 if (fw) 52 free(__DECONST(u_char *, fw->data), M_DEVBUF, fw->size); 53 free(__DECONST(struct firmware *, fw), M_DRM, sizeof(*fw)); 54 } 55 56 #endif 57