1f83d1c31SBen Skeggs /*
2f83d1c31SBen Skeggs * Copyright 2021 Red Hat Inc.
3f83d1c31SBen Skeggs *
4f83d1c31SBen Skeggs * Permission is hereby granted, free of charge, to any person obtaining a
5f83d1c31SBen Skeggs * copy of this software and associated documentation files (the "Software"),
6f83d1c31SBen Skeggs * to deal in the Software without restriction, including without limitation
7f83d1c31SBen Skeggs * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8f83d1c31SBen Skeggs * and/or sell copies of the Software, and to permit persons to whom the
9f83d1c31SBen Skeggs * Software is furnished to do so, subject to the following conditions:
10f83d1c31SBen Skeggs *
11f83d1c31SBen Skeggs * The above copyright notice and this permission notice shall be included in
12f83d1c31SBen Skeggs * all copies or substantial portions of the Software.
13f83d1c31SBen Skeggs *
14f83d1c31SBen Skeggs * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15f83d1c31SBen Skeggs * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16f83d1c31SBen Skeggs * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17f83d1c31SBen Skeggs * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18f83d1c31SBen Skeggs * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19f83d1c31SBen Skeggs * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20f83d1c31SBen Skeggs * OTHER DEALINGS IN THE SOFTWARE.
21f83d1c31SBen Skeggs */
22f83d1c31SBen Skeggs #include "priv.h"
23f83d1c31SBen Skeggs
24f83d1c31SBen Skeggs static void *
nvkm_vfn_dtor(struct nvkm_subdev * subdev)25f83d1c31SBen Skeggs nvkm_vfn_dtor(struct nvkm_subdev *subdev)
26f83d1c31SBen Skeggs {
27f83d1c31SBen Skeggs return nvkm_vfn(subdev);
28f83d1c31SBen Skeggs }
29f83d1c31SBen Skeggs
30f83d1c31SBen Skeggs static const struct nvkm_subdev_func
31f83d1c31SBen Skeggs nvkm_vfn = {
32f83d1c31SBen Skeggs .dtor = nvkm_vfn_dtor,
33f83d1c31SBen Skeggs };
34f83d1c31SBen Skeggs
35f83d1c31SBen Skeggs int
nvkm_vfn_new_(const struct nvkm_vfn_func * func,struct nvkm_device * device,enum nvkm_subdev_type type,int inst,u32 addr,struct nvkm_vfn ** pvfn)36f83d1c31SBen Skeggs nvkm_vfn_new_(const struct nvkm_vfn_func *func, struct nvkm_device *device,
37f83d1c31SBen Skeggs enum nvkm_subdev_type type, int inst, u32 addr, struct nvkm_vfn **pvfn)
38f83d1c31SBen Skeggs {
39f83d1c31SBen Skeggs struct nvkm_vfn *vfn;
40*e6507380SBen Skeggs int ret;
41f83d1c31SBen Skeggs
42f83d1c31SBen Skeggs if (!(vfn = *pvfn = kzalloc(sizeof(*vfn), GFP_KERNEL)))
43f83d1c31SBen Skeggs return -ENOMEM;
44f83d1c31SBen Skeggs
45f83d1c31SBen Skeggs nvkm_subdev_ctor(&nvkm_vfn, device, type, inst, &vfn->subdev);
46f83d1c31SBen Skeggs vfn->func = func;
47f83d1c31SBen Skeggs vfn->addr.priv = addr;
4858c3d3c8SBen Skeggs vfn->addr.user = vfn->addr.priv + func->user.addr;
4958c3d3c8SBen Skeggs
50*e6507380SBen Skeggs if (vfn->func->intr) {
51*e6507380SBen Skeggs ret = nvkm_intr_add(vfn->func->intr, vfn->func->intrs,
52*e6507380SBen Skeggs &vfn->subdev, 8, &vfn->intr);
53*e6507380SBen Skeggs if (ret)
54*e6507380SBen Skeggs return ret;
55*e6507380SBen Skeggs }
56*e6507380SBen Skeggs
5758c3d3c8SBen Skeggs vfn->user.ctor = nvkm_uvfn_new;
5858c3d3c8SBen Skeggs vfn->user.base = func->user.base;
59f83d1c31SBen Skeggs return 0;
60f83d1c31SBen Skeggs }
61