Ben Skeggs | cc36205 | 2018-05-08 20:39:46 +1000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018 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 | #include <nvif/fifo.h> |
| 23 | |
| 24 | static int |
| 25 | nvif_fifo_runlists(struct nvif_device *device) |
| 26 | { |
| 27 | struct nvif_object *object = &device->object; |
| 28 | struct { |
| 29 | struct nv_device_info_v1 m; |
| 30 | struct { |
| 31 | struct nv_device_info_v1_data runlists; |
| 32 | struct nv_device_info_v1_data runlist[64]; |
| 33 | } v; |
| 34 | } *a; |
| 35 | int ret, i; |
| 36 | |
| 37 | if (device->runlist) |
| 38 | return 0; |
| 39 | |
| 40 | if (!(a = kmalloc(sizeof(*a), GFP_KERNEL))) |
| 41 | return -ENOMEM; |
| 42 | a->m.version = 1; |
| 43 | a->m.count = sizeof(a->v) / sizeof(a->v.runlists); |
| 44 | a->v.runlists.mthd = NV_DEVICE_FIFO_RUNLISTS; |
| 45 | for (i = 0; i < ARRAY_SIZE(a->v.runlist); i++) |
| 46 | a->v.runlist[i].mthd = NV_DEVICE_FIFO_RUNLIST_ENGINES(i); |
| 47 | |
| 48 | ret = nvif_object_mthd(object, NV_DEVICE_V0_INFO, a, sizeof(*a)); |
| 49 | if (ret) |
| 50 | goto done; |
| 51 | |
| 52 | device->runlists = fls64(a->v.runlists.data); |
| 53 | device->runlist = kzalloc(sizeof(*device->runlist) * |
| 54 | device->runlists, GFP_KERNEL); |
| 55 | if (!device->runlist) { |
| 56 | ret = -ENOMEM; |
| 57 | goto done; |
| 58 | } |
| 59 | |
| 60 | for (i = 0; i < device->runlists; i++) { |
| 61 | if (a->v.runlists.data & BIT_ULL(i)) |
| 62 | device->runlist[i].engines = a->v.runlist[i].data; |
| 63 | } |
| 64 | |
| 65 | done: |
| 66 | kfree(a); |
| 67 | return ret; |
| 68 | } |
| 69 | |
| 70 | u64 |
| 71 | nvif_fifo_runlist(struct nvif_device *device, u64 engine) |
| 72 | { |
| 73 | struct nvif_object *object = &device->object; |
| 74 | struct { |
| 75 | struct nv_device_info_v1 m; |
| 76 | struct { |
| 77 | struct nv_device_info_v1_data engine; |
| 78 | } v; |
| 79 | } a = { |
| 80 | .m.version = 1, |
| 81 | .m.count = sizeof(a.v) / sizeof(a.v.engine), |
| 82 | .v.engine.mthd = engine, |
| 83 | }; |
| 84 | u64 runm = 0; |
| 85 | int ret, i; |
| 86 | |
| 87 | if ((ret = nvif_fifo_runlists(device))) |
| 88 | return runm; |
| 89 | |
| 90 | ret = nvif_object_mthd(object, NV_DEVICE_V0_INFO, &a, sizeof(a)); |
| 91 | if (ret == 0) { |
| 92 | for (i = 0; i < device->runlists; i++) { |
| 93 | if (device->runlist[i].engines & a.v.engine.data) |
| 94 | runm |= BIT_ULL(i); |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | return runm; |
| 99 | } |