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