1 /* SPDX-License-Identifier: MIT */
2 #ifndef __NVKM_FIRMWARE_H__
3 #define __NVKM_FIRMWARE_H__
4 #include <core/memory.h>
5 #include <core/option.h>
6 #include <core/subdev.h>
9 const struct nvkm_firmware_func {
10 enum nvkm_firmware_type {
11 NVKM_FIRMWARE_IMG_RAM,
12 NVKM_FIRMWARE_IMG_DMA,
13 NVKM_FIRMWARE_IMG_SGT,
17 struct nvkm_device *device;
23 struct nvkm_firmware_mem {
24 struct nvkm_memory memory;
26 struct scatterlist sgl; /* DMA */
27 struct sg_table sgt; /* SGT */
32 int nvkm_firmware_ctor(const struct nvkm_firmware_func *, const char *name, struct nvkm_device *,
33 const void *ptr, int len, struct nvkm_firmware *);
34 void nvkm_firmware_dtor(struct nvkm_firmware *);
36 int nvkm_firmware_get(const struct nvkm_subdev *, const char *fwname, int ver,
37 const struct firmware **);
38 void nvkm_firmware_put(const struct firmware *);
40 int nvkm_firmware_load_blob(const struct nvkm_subdev *subdev, const char *path,
41 const char *name, int ver, struct nvkm_blob *);
42 int nvkm_firmware_load_name(const struct nvkm_subdev *subdev, const char *path,
43 const char *name, int ver,
44 const struct firmware **);
46 #define nvkm_firmware_load(s,l,o,p...) ({ \
47 struct nvkm_subdev *_s = (s); \
48 const char *_opts = (o); \
50 typeof(l[0]) *_list = (l), *_next, *_fwif = NULL; \
51 int _ver, _fwv, _ret = 0; \
53 snprintf(_option, sizeof(_option), "Nv%sFw", _opts); \
54 _ver = nvkm_longopt(_s->device->cfgopt, _option, -2); \
56 for (_next = _list; !_fwif && _next->load; _next++) { \
57 if (_next->version == _ver) \
60 _ret = _fwif ? 0 : -EINVAL; \
64 snprintf(_option, sizeof(_option), "Nv%sFwVer", _opts); \
65 _fwv = _fwif ? _fwif->version : -1; \
66 _ver = nvkm_longopt(_s->device->cfgopt, _option, _fwv); \
67 for (_next = _fwif ? _fwif : _list; _next->load; _next++) { \
68 _fwv = (_ver >= 0) ? _ver : _next->version; \
69 _ret = _next->load(p, _fwv, _next); \
70 if (_ret == 0 || _ver >= 0) { \
78 _fwif = ERR_PTR(_ret); \