1 /* $NetBSD: firmware.h,v 1.2 2021/12/18 23:45:33 riastradh Exp $ */ 2 3 /* SPDX-License-Identifier: MIT */ 4 #ifndef __NVKM_FIRMWARE_H__ 5 #define __NVKM_FIRMWARE_H__ 6 #include <core/option.h> 7 #include <core/subdev.h> 8 9 int nvkm_firmware_get(const struct nvkm_subdev *, const char *fwname, int ver, 10 const struct firmware **); 11 void nvkm_firmware_put(const struct firmware *); 12 13 int nvkm_firmware_load_blob(const struct nvkm_subdev *subdev, const char *path, 14 const char *name, int ver, struct nvkm_blob *); 15 int nvkm_firmware_load_name(const struct nvkm_subdev *subdev, const char *path, 16 const char *name, int ver, 17 const struct firmware **); 18 19 #define nvkm_firmware_load(s,l,o,p...) ({ \ 20 struct nvkm_subdev *_s = (s); \ 21 const char *_opts = (o); \ 22 char _option[32]; \ 23 typeof(l[0]) *_list = (l), *_next, *_fwif = NULL; \ 24 int _ver, _fwv, _ret = 0; \ 25 \ 26 snprintf(_option, sizeof(_option), "Nv%sFw", _opts); \ 27 _ver = nvkm_longopt(_s->device->cfgopt, _option, -2); \ 28 if (_ver >= -1) { \ 29 for (_next = _list; !_fwif && _next->load; _next++) { \ 30 if (_next->version == _ver) \ 31 _fwif = _next; \ 32 } \ 33 _ret = _fwif ? 0 : -EINVAL; \ 34 } \ 35 \ 36 if (_ret == 0) { \ 37 snprintf(_option, sizeof(_option), "Nv%sFwVer", _opts); \ 38 _fwv = _fwif ? _fwif->version : -1; \ 39 _ver = nvkm_longopt(_s->device->cfgopt, _option, _fwv); \ 40 for (_next = _fwif ? _fwif : _list; _next->load; _next++) { \ 41 _fwv = (_ver >= 0) ? _ver : _next->version; \ 42 _ret = _next->load(p, _fwv, _next); \ 43 if (_ret == 0 || _ver >= 0) { \ 44 _fwif = _next; \ 45 break; \ 46 } \ 47 } \ 48 } \ 49 \ 50 if (_ret) { \ 51 nvkm_error(_s, "failed to load firmware\n"); \ 52 _fwif = ERR_PTR(_ret); \ 53 } \ 54 \ 55 _fwif; \ 56 }) 57 #endif 58