1 /* SPDX-License-Identifier: MIT */
2 #ifndef __NVKM_FIRMWARE_H__
3 #define __NVKM_FIRMWARE_H__
4 #include <core/option.h>
5 #include <core/subdev.h>
7 int nvkm_firmware_get(const struct nvkm_subdev *, const char *fwname, int ver,
8 const struct firmware **);
9 void nvkm_firmware_put(const struct firmware *);
11 int nvkm_firmware_load_blob(const struct nvkm_subdev *subdev, const char *path,
12 const char *name, int ver, struct nvkm_blob *);
13 int nvkm_firmware_load_name(const struct nvkm_subdev *subdev, const char *path,
14 const char *name, int ver,
15 const struct firmware **);
17 #define nvkm_firmware_load(s,l,o,p...) ({ \
18 struct nvkm_subdev *_s = (s); \
19 const char *_opts = (o); \
21 typeof(l[0]) *_list = (l), *_next, *_fwif = NULL; \
22 int _ver, _fwv, _ret = 0; \
24 snprintf(_option, sizeof(_option), "Nv%sFw", _opts); \
25 _ver = nvkm_longopt(_s->device->cfgopt, _option, -2); \
27 for (_next = _list; !_fwif && _next->load; _next++) { \
28 if (_next->version == _ver) \
31 _ret = _fwif ? 0 : -EINVAL; \
35 snprintf(_option, sizeof(_option), "Nv%sFwVer", _opts); \
36 _fwv = _fwif ? _fwif->version : -1; \
37 _ver = nvkm_longopt(_s->device->cfgopt, _option, _fwv); \
38 for (_next = _fwif ? _fwif : _list; _next->load; _next++) { \
39 _fwv = (_ver >= 0) ? _ver : _next->version; \
40 _ret = _next->load(p, _fwv, _next); \
41 if (_ret == 0 || _ver >= 0) { \
49 _fwif = ERR_PTR(_ret); \