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 11 #ifndef __DECONST 12 #define __DECONST(type, var) ((type)(__uintptr_t)(const void *)(var)) 13 #endif 14 15 struct firmware { 16 size_t size; 17 const u8 *data; 18 }; 19 20 static inline int 21 request_firmware(const struct firmware **fw, const char *name, 22 struct device *device) 23 { 24 int r; 25 struct firmware *f = malloc(sizeof(struct firmware), M_DRM, 26 M_WAITOK | M_ZERO); 27 r = loadfirmware(name, __DECONST(u_char **, &f->data), &f->size); 28 if (r != 0) { 29 free(f, M_DRM, sizeof(struct firmware)); 30 *fw = NULL; 31 return -r; 32 } else { 33 *fw = f; 34 return 0; 35 } 36 } 37 38 static inline int 39 request_firmware_direct(const struct firmware **fw, const char *name, 40 struct device *device) 41 { 42 return request_firmware(fw, name, device); 43 } 44 45 #define request_firmware_nowait(a, b, c, d, e, f, g) -EINVAL 46 47 static inline void 48 release_firmware(const struct firmware *fw) 49 { 50 if (fw) 51 free(__DECONST(u_char *, fw->data), M_DEVBUF, fw->size); 52 free(__DECONST(struct firmware *, fw), M_DRM, sizeof(*fw)); 53 } 54 55 #endif 56