116307b5dSAlexandre Courbot /*
216307b5dSAlexandre Courbot  * Copyright (c) 2017, NVIDIA CORPORATION. All rights reserved.
316307b5dSAlexandre Courbot  *
416307b5dSAlexandre Courbot  * Permission is hereby granted, free of charge, to any person obtaining a
516307b5dSAlexandre Courbot  * copy of this software and associated documentation files (the "Software"),
616307b5dSAlexandre Courbot  * to deal in the Software without restriction, including without limitation
716307b5dSAlexandre Courbot  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
816307b5dSAlexandre Courbot  * and/or sell copies of the Software, and to permit persons to whom the
916307b5dSAlexandre Courbot  * Software is furnished to do so, subject to the following conditions:
1016307b5dSAlexandre Courbot  *
1116307b5dSAlexandre Courbot  * The above copyright notice and this permission notice shall be included in
1216307b5dSAlexandre Courbot  * all copies or substantial portions of the Software.
1316307b5dSAlexandre Courbot  *
1416307b5dSAlexandre Courbot  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1516307b5dSAlexandre Courbot  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1616307b5dSAlexandre Courbot  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
1716307b5dSAlexandre Courbot  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1816307b5dSAlexandre Courbot  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
1916307b5dSAlexandre Courbot  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
2016307b5dSAlexandre Courbot  * DEALINGS IN THE SOFTWARE.
2116307b5dSAlexandre Courbot  */
2216307b5dSAlexandre Courbot #include "priv.h"
2398a34d99SBen Skeggs #include <core/firmware.h>
2416307b5dSAlexandre Courbot 
2516307b5dSAlexandre Courbot static void *
nvkm_nvdec_dtor(struct nvkm_engine * engine)2616307b5dSAlexandre Courbot nvkm_nvdec_dtor(struct nvkm_engine *engine)
2716307b5dSAlexandre Courbot {
2816307b5dSAlexandre Courbot 	struct nvkm_nvdec *nvdec = nvkm_nvdec(engine);
293a900a5dSBen Skeggs 	nvkm_falcon_dtor(&nvdec->falcon);
3016307b5dSAlexandre Courbot 	return nvdec;
3116307b5dSAlexandre Courbot }
3216307b5dSAlexandre Courbot 
3316307b5dSAlexandre Courbot static const struct nvkm_engine_func
3416307b5dSAlexandre Courbot nvkm_nvdec = {
3516307b5dSAlexandre Courbot 	.dtor = nvkm_nvdec_dtor,
3616307b5dSAlexandre Courbot };
3716307b5dSAlexandre Courbot 
3816307b5dSAlexandre Courbot int
nvkm_nvdec_new_(const struct nvkm_nvdec_fwif * fwif,struct nvkm_device * device,enum nvkm_subdev_type type,int inst,u32 addr,struct nvkm_nvdec ** pnvdec)3998a34d99SBen Skeggs nvkm_nvdec_new_(const struct nvkm_nvdec_fwif *fwif, struct nvkm_device *device,
40*a51c69eeSBen Skeggs 		enum nvkm_subdev_type type, int inst, u32 addr, struct nvkm_nvdec **pnvdec)
4116307b5dSAlexandre Courbot {
4216307b5dSAlexandre Courbot 	struct nvkm_nvdec *nvdec;
4398a34d99SBen Skeggs 	int ret;
4416307b5dSAlexandre Courbot 
4516307b5dSAlexandre Courbot 	if (!(nvdec = *pnvdec = kzalloc(sizeof(*nvdec), GFP_KERNEL)))
4616307b5dSAlexandre Courbot 		return -ENOMEM;
4716307b5dSAlexandre Courbot 
48f8aeb133SBen Skeggs 	ret = nvkm_engine_ctor(&nvkm_nvdec, device, type, inst, true,
4916307b5dSAlexandre Courbot 			       &nvdec->engine);
5098a34d99SBen Skeggs 	if (ret)
5198a34d99SBen Skeggs 		return ret;
5298a34d99SBen Skeggs 
5398a34d99SBen Skeggs 	fwif = nvkm_firmware_load(&nvdec->engine.subdev, fwif, "Nvdec", nvdec);
5498a34d99SBen Skeggs 	if (IS_ERR(fwif))
5598a34d99SBen Skeggs 		return -ENODEV;
5698a34d99SBen Skeggs 
5798a34d99SBen Skeggs 	nvdec->func = fwif->func;
583a900a5dSBen Skeggs 
593a900a5dSBen Skeggs 	return nvkm_falcon_ctor(nvdec->func->flcn, &nvdec->engine.subdev,
60*a51c69eeSBen Skeggs 				nvdec->engine.subdev.name, addr, &nvdec->falcon);
6116307b5dSAlexandre Courbot };
62