1*58c3d3c8SBen Skeggs /*
2*58c3d3c8SBen Skeggs * Copyright 2021 Red Hat Inc.
3*58c3d3c8SBen Skeggs *
4*58c3d3c8SBen Skeggs * Permission is hereby granted, free of charge, to any person obtaining a
5*58c3d3c8SBen Skeggs * copy of this software and associated documentation files (the "Software"),
6*58c3d3c8SBen Skeggs * to deal in the Software without restriction, including without limitation
7*58c3d3c8SBen Skeggs * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8*58c3d3c8SBen Skeggs * and/or sell copies of the Software, and to permit persons to whom the
9*58c3d3c8SBen Skeggs * Software is furnished to do so, subject to the following conditions:
10*58c3d3c8SBen Skeggs *
11*58c3d3c8SBen Skeggs * The above copyright notice and this permission notice shall be included in
12*58c3d3c8SBen Skeggs * all copies or substantial portions of the Software.
13*58c3d3c8SBen Skeggs *
14*58c3d3c8SBen Skeggs * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15*58c3d3c8SBen Skeggs * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16*58c3d3c8SBen Skeggs * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17*58c3d3c8SBen Skeggs * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18*58c3d3c8SBen Skeggs * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19*58c3d3c8SBen Skeggs * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20*58c3d3c8SBen Skeggs * OTHER DEALINGS IN THE SOFTWARE.
21*58c3d3c8SBen Skeggs */
22*58c3d3c8SBen Skeggs #define nvkm_uvfn(p) container_of((p), struct nvkm_uvfn, object)
23*58c3d3c8SBen Skeggs #include "priv.h"
24*58c3d3c8SBen Skeggs
25*58c3d3c8SBen Skeggs #include <core/object.h>
26*58c3d3c8SBen Skeggs
27*58c3d3c8SBen Skeggs struct nvkm_uvfn {
28*58c3d3c8SBen Skeggs struct nvkm_object object;
29*58c3d3c8SBen Skeggs struct nvkm_vfn *vfn;
30*58c3d3c8SBen Skeggs };
31*58c3d3c8SBen Skeggs
32*58c3d3c8SBen Skeggs static int
nvkm_uvfn_map(struct nvkm_object * object,void * argv,u32 argc,enum nvkm_object_map * type,u64 * addr,u64 * size)33*58c3d3c8SBen Skeggs nvkm_uvfn_map(struct nvkm_object *object, void *argv, u32 argc,
34*58c3d3c8SBen Skeggs enum nvkm_object_map *type, u64 *addr, u64 *size)
35*58c3d3c8SBen Skeggs {
36*58c3d3c8SBen Skeggs struct nvkm_vfn *vfn = nvkm_uvfn(object)->vfn;
37*58c3d3c8SBen Skeggs struct nvkm_device *device = vfn->subdev.device;
38*58c3d3c8SBen Skeggs
39*58c3d3c8SBen Skeggs *addr = device->func->resource_addr(device, 0) + vfn->addr.user;
40*58c3d3c8SBen Skeggs *size = vfn->func->user.size;
41*58c3d3c8SBen Skeggs *type = NVKM_OBJECT_MAP_IO;
42*58c3d3c8SBen Skeggs return 0;
43*58c3d3c8SBen Skeggs }
44*58c3d3c8SBen Skeggs
45*58c3d3c8SBen Skeggs static const struct nvkm_object_func
46*58c3d3c8SBen Skeggs nvkm_uvfn = {
47*58c3d3c8SBen Skeggs .map = nvkm_uvfn_map,
48*58c3d3c8SBen Skeggs };
49*58c3d3c8SBen Skeggs
50*58c3d3c8SBen Skeggs int
nvkm_uvfn_new(struct nvkm_device * device,const struct nvkm_oclass * oclass,void * argv,u32 argc,struct nvkm_object ** pobject)51*58c3d3c8SBen Skeggs nvkm_uvfn_new(struct nvkm_device *device, const struct nvkm_oclass *oclass,
52*58c3d3c8SBen Skeggs void *argv, u32 argc, struct nvkm_object **pobject)
53*58c3d3c8SBen Skeggs {
54*58c3d3c8SBen Skeggs struct nvkm_uvfn *uvfn;
55*58c3d3c8SBen Skeggs
56*58c3d3c8SBen Skeggs if (argc != 0)
57*58c3d3c8SBen Skeggs return -ENOSYS;
58*58c3d3c8SBen Skeggs
59*58c3d3c8SBen Skeggs if (!(uvfn = kzalloc(sizeof(*uvfn), GFP_KERNEL)))
60*58c3d3c8SBen Skeggs return -ENOMEM;
61*58c3d3c8SBen Skeggs
62*58c3d3c8SBen Skeggs nvkm_object_ctor(&nvkm_uvfn, oclass, &uvfn->object);
63*58c3d3c8SBen Skeggs uvfn->vfn = device->vfn;
64*58c3d3c8SBen Skeggs
65*58c3d3c8SBen Skeggs *pobject = &uvfn->object;
66*58c3d3c8SBen Skeggs return 0;
67*58c3d3c8SBen Skeggs }
68