0001
0002 #ifndef __NVKM_FIRMWARE_H__
0003 #define __NVKM_FIRMWARE_H__
0004 #include <core/option.h>
0005 #include <core/subdev.h>
0006
0007 int nvkm_firmware_get(const struct nvkm_subdev *, const char *fwname, int ver,
0008 const struct firmware **);
0009 void nvkm_firmware_put(const struct firmware *);
0010
0011 int nvkm_firmware_load_blob(const struct nvkm_subdev *subdev, const char *path,
0012 const char *name, int ver, struct nvkm_blob *);
0013 int nvkm_firmware_load_name(const struct nvkm_subdev *subdev, const char *path,
0014 const char *name, int ver,
0015 const struct firmware **);
0016
0017 #define nvkm_firmware_load(s,l,o,p...) ({ \
0018 struct nvkm_subdev *_s = (s); \
0019 const char *_opts = (o); \
0020 char _option[32]; \
0021 typeof(l[0]) *_list = (l), *_next, *_fwif = NULL; \
0022 int _ver, _fwv, _ret = 0; \
0023 \
0024 snprintf(_option, sizeof(_option), "Nv%sFw", _opts); \
0025 _ver = nvkm_longopt(_s->device->cfgopt, _option, -2); \
0026 if (_ver >= -1) { \
0027 for (_next = _list; !_fwif && _next->load; _next++) { \
0028 if (_next->version == _ver) \
0029 _fwif = _next; \
0030 } \
0031 _ret = _fwif ? 0 : -EINVAL; \
0032 } \
0033 \
0034 if (_ret == 0) { \
0035 snprintf(_option, sizeof(_option), "Nv%sFwVer", _opts); \
0036 _fwv = _fwif ? _fwif->version : -1; \
0037 _ver = nvkm_longopt(_s->device->cfgopt, _option, _fwv); \
0038 for (_next = _fwif ? _fwif : _list; _next->load; _next++) { \
0039 _fwv = (_ver >= 0) ? _ver : _next->version; \
0040 _ret = _next->load(p, _fwv, _next); \
0041 if (_ret == 0 || _ver >= 0) { \
0042 _fwif = _next; \
0043 break; \
0044 } \
0045 } \
0046 } \
0047 \
0048 if (_ret) \
0049 _fwif = ERR_PTR(_ret); \
0050 _fwif; \
0051 })
0052 #endif