summaryrefslogtreecommitdiffstats
path: root/sys/dev/pci/drm/include/linux/firmware.h
blob: 4f06d4de2a4e1f47761a4ca63ba44821235d7e83 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/* Public domain. */

#ifndef _LINUX_FIRMWARE_H
#define _LINUX_FIRMWARE_H

#include <sys/types.h>
#include <sys/malloc.h>
#include <sys/device.h>
#include <linux/types.h>

#ifndef __DECONST
#define __DECONST(type, var)	((type)(__uintptr_t)(const void *)(var))
#endif

struct firmware {
	size_t size;
	const u8 *data;
};

static inline int
request_firmware(const struct firmware **fw, const char *name,
    struct device *device)
{
	int r;
	struct firmware *f = malloc(sizeof(struct firmware), M_DRM,
	    M_WAITOK | M_ZERO);
	r = loadfirmware(name, __DECONST(u_char **, &f->data), &f->size);
	if (r != 0) {
		free(f, M_DRM, sizeof(struct firmware));
		*fw = NULL;
		return -r;
	} else  {
		*fw = f;
		return 0;
	}
}

#define request_firmware_nowait(a, b, c, d, e, f, g) -EINVAL

static inline void
release_firmware(const struct firmware *fw)
{
	if (fw)
		free(__DECONST(u_char *, fw->data), M_DEVBUF, fw->size);
	free(__DECONST(struct firmware *, fw), M_DRM, sizeof(*fw));
}

#endif