Ben Skeggs | a04d042 | 2014-08-10 04:10:21 +1000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 Red Hat Inc. |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 5 | * copy of this software and associated documentation files (the "Software"), |
| 6 | * to deal in the Software without restriction, including without limitation |
| 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 | * and/or sell copies of the Software, and to permit persons to whom the |
| 9 | * Software is furnished to do so, subject to the following conditions: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice shall be included in |
| 12 | * all copies or substantial portions of the Software. |
| 13 | * |
| 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 17 | * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 18 | * 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 OR |
| 20 | * OTHER DEALINGS IN THE SOFTWARE. |
| 21 | * |
| 22 | * Authors: Ben Skeggs <bskeggs@redhat.com> |
| 23 | */ |
| 24 | |
Ben Skeggs | c39f472 | 2015-01-13 22:13:14 +1000 | [diff] [blame] | 25 | #include <nvif/device.h> |
Ben Skeggs | a04d042 | 2014-08-10 04:10:21 +1000 | [diff] [blame] | 26 | |
Ben Skeggs | 56f67dc | 2015-08-20 14:54:10 +1000 | [diff] [blame^] | 27 | u64 |
| 28 | nvif_device_time(struct nvif_device *device) |
| 29 | { |
| 30 | return nvxx_timer(device)->read(nvxx_timer(device)); |
| 31 | } |
| 32 | |
Ben Skeggs | a04d042 | 2014-08-10 04:10:21 +1000 | [diff] [blame] | 33 | void |
| 34 | nvif_device_fini(struct nvif_device *device) |
| 35 | { |
| 36 | nvif_object_fini(&device->base); |
| 37 | } |
| 38 | |
| 39 | int |
| 40 | nvif_device_init(struct nvif_object *parent, void (*dtor)(struct nvif_device *), |
| 41 | u32 handle, u32 oclass, void *data, u32 size, |
| 42 | struct nvif_device *device) |
| 43 | { |
| 44 | int ret = nvif_object_init(parent, (void *)dtor, handle, oclass, |
| 45 | data, size, &device->base); |
| 46 | if (ret == 0) { |
| 47 | device->object = &device->base; |
| 48 | device->info.version = 0; |
| 49 | ret = nvif_object_mthd(&device->base, NV_DEVICE_V0_INFO, |
| 50 | &device->info, sizeof(device->info)); |
| 51 | } |
| 52 | return ret; |
| 53 | } |
| 54 | |
| 55 | static void |
| 56 | nvif_device_del(struct nvif_device *device) |
| 57 | { |
| 58 | nvif_device_fini(device); |
| 59 | kfree(device); |
| 60 | } |
| 61 | |
| 62 | int |
| 63 | nvif_device_new(struct nvif_object *parent, u32 handle, u32 oclass, |
| 64 | void *data, u32 size, struct nvif_device **pdevice) |
| 65 | { |
| 66 | struct nvif_device *device = kzalloc(sizeof(*device), GFP_KERNEL); |
| 67 | if (device) { |
| 68 | int ret = nvif_device_init(parent, nvif_device_del, handle, |
| 69 | oclass, data, size, device); |
| 70 | if (ret) { |
| 71 | kfree(device); |
| 72 | device = NULL; |
| 73 | } |
| 74 | *pdevice = device; |
| 75 | return ret; |
| 76 | } |
| 77 | return -ENOMEM; |
| 78 | } |
| 79 | |
| 80 | void |
| 81 | nvif_device_ref(struct nvif_device *device, struct nvif_device **pdevice) |
| 82 | { |
| 83 | nvif_object_ref(&device->base, (struct nvif_object **)pdevice); |
| 84 | } |