1/*	$NetBSD: nouveau_nvkm_engine_nvdec_base.c,v 1.2 2021/12/18 23:45:37 riastradh Exp $	*/
2
3/*
4 * Copyright (c) 2017, NVIDIA CORPORATION. All rights reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 */
24#include <sys/cdefs.h>
25__KERNEL_RCSID(0, "$NetBSD: nouveau_nvkm_engine_nvdec_base.c,v 1.2 2021/12/18 23:45:37 riastradh Exp $");
26
27#include "priv.h"
28#include <core/firmware.h>
29
30static void *
31nvkm_nvdec_dtor(struct nvkm_engine *engine)
32{
33	struct nvkm_nvdec *nvdec = nvkm_nvdec(engine);
34	nvkm_falcon_dtor(&nvdec->falcon);
35	return nvdec;
36}
37
38static const struct nvkm_engine_func
39nvkm_nvdec = {
40	.dtor = nvkm_nvdec_dtor,
41};
42
43int
44nvkm_nvdec_new_(const struct nvkm_nvdec_fwif *fwif, struct nvkm_device *device,
45		int index, struct nvkm_nvdec **pnvdec)
46{
47	struct nvkm_nvdec *nvdec;
48	int ret;
49
50	if (!(nvdec = *pnvdec = kzalloc(sizeof(*nvdec), GFP_KERNEL)))
51		return -ENOMEM;
52
53	ret = nvkm_engine_ctor(&nvkm_nvdec, device, index, true,
54			       &nvdec->engine);
55	if (ret)
56		return ret;
57
58	fwif = nvkm_firmware_load(&nvdec->engine.subdev, fwif, "Nvdec", nvdec);
59	if (IS_ERR(fwif))
60		return -ENODEV;
61
62	nvdec->func = fwif->func;
63
64	return nvkm_falcon_ctor(nvdec->func->flcn, &nvdec->engine.subdev,
65				nvkm_subdev_name[index], 0, &nvdec->falcon);
66};
67