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