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"
2316307b5dSAlexandre Courbot 
2416307b5dSAlexandre Courbot #include <engine/falcon.h>
2516307b5dSAlexandre Courbot 
2616307b5dSAlexandre Courbot static int
2716307b5dSAlexandre Courbot nvkm_nvdec_oneinit(struct nvkm_engine *engine)
2816307b5dSAlexandre Courbot {
2916307b5dSAlexandre Courbot 	struct nvkm_nvdec *nvdec = nvkm_nvdec(engine);
3016307b5dSAlexandre Courbot 	return nvkm_falcon_v1_new(&nvdec->engine.subdev, "NVDEC", 0x84000,
3116307b5dSAlexandre Courbot 				  &nvdec->falcon);
3216307b5dSAlexandre Courbot }
3316307b5dSAlexandre Courbot 
3416307b5dSAlexandre Courbot static void *
3516307b5dSAlexandre Courbot nvkm_nvdec_dtor(struct nvkm_engine *engine)
3616307b5dSAlexandre Courbot {
3716307b5dSAlexandre Courbot 	struct nvkm_nvdec *nvdec = nvkm_nvdec(engine);
3816307b5dSAlexandre Courbot 	nvkm_falcon_del(&nvdec->falcon);
3916307b5dSAlexandre Courbot 	return nvdec;
4016307b5dSAlexandre Courbot }
4116307b5dSAlexandre Courbot 
4216307b5dSAlexandre Courbot static const struct nvkm_engine_func
4316307b5dSAlexandre Courbot nvkm_nvdec = {
4416307b5dSAlexandre Courbot 	.dtor = nvkm_nvdec_dtor,
4516307b5dSAlexandre Courbot 	.oneinit = nvkm_nvdec_oneinit,
4616307b5dSAlexandre Courbot };
4716307b5dSAlexandre Courbot 
4816307b5dSAlexandre Courbot int
4916307b5dSAlexandre Courbot nvkm_nvdec_new_(struct nvkm_device *device, int index,
5016307b5dSAlexandre Courbot 		struct nvkm_nvdec **pnvdec)
5116307b5dSAlexandre Courbot {
5216307b5dSAlexandre Courbot 	struct nvkm_nvdec *nvdec;
5316307b5dSAlexandre Courbot 
5416307b5dSAlexandre Courbot 	if (!(nvdec = *pnvdec = kzalloc(sizeof(*nvdec), GFP_KERNEL)))
5516307b5dSAlexandre Courbot 		return -ENOMEM;
5616307b5dSAlexandre Courbot 
5716307b5dSAlexandre Courbot 	return nvkm_engine_ctor(&nvkm_nvdec, device, index, true,
5816307b5dSAlexandre Courbot 				&nvdec->engine);
5916307b5dSAlexandre Courbot };
60