70 lines · c
1/*2 * Copyright 2014 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 * Authors: Ben Skeggs <bskeggs@redhat.com>23 */24#include <nvif/device.h>25#include <nvif/client.h>26 27u6428nvif_device_time(struct nvif_device *device)29{30 if (!device->user.func) {31 struct nv_device_time_v0 args = {};32 int ret = nvif_object_mthd(&device->object, NV_DEVICE_V0_TIME,33 &args, sizeof(args));34 WARN_ON_ONCE(ret != 0);35 return args.time;36 }37 38 return device->user.func->time(&device->user);39}40 41int42nvif_device_map(struct nvif_device *device)43{44 return nvif_object_map(&device->object, NULL, 0);45}46 47void48nvif_device_dtor(struct nvif_device *device)49{50 nvif_user_dtor(device);51 kfree(device->runlist);52 device->runlist = NULL;53 nvif_object_dtor(&device->object);54}55 56int57nvif_device_ctor(struct nvif_client *client, const char *name, struct nvif_device *device)58{59 int ret = nvif_object_ctor(&client->object, name ? name : "nvifDevice", 0,60 0x0080, NULL, 0, &device->object);61 device->runlist = NULL;62 device->user.func = NULL;63 if (ret == 0) {64 device->info.version = 0;65 ret = nvif_object_mthd(&device->object, NV_DEVICE_V0_INFO,66 &device->info, sizeof(device->info));67 }68 return ret;69}70