2 * Copyright 2016 Red Hat Inc.
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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.
22 * Authors: Ben Skeggs <bskeggs@redhat.com>
26 struct nvkm_top_device *
27 nvkm_top_device_new(struct nvkm_top *top)
29 struct nvkm_top_device *info = kmalloc(sizeof(*info), GFP_KERNEL);
31 info->type = NVKM_SUBDEV_NR;
33 info->index = NVKM_SUBDEV_NR;
40 list_add_tail(&info->head, &top->device);
46 nvkm_top_addr(struct nvkm_device *device, enum nvkm_devidx index)
48 struct nvkm_top *top = device->top;
49 struct nvkm_top_device *info;
52 list_for_each_entry(info, &top->device, head) {
53 if (info->index == index)
62 nvkm_top_reset(struct nvkm_device *device, enum nvkm_subdev_type type, int inst)
64 struct nvkm_top *top = device->top;
65 struct nvkm_top_device *info;
68 list_for_each_entry(info, &top->device, head) {
69 if (info->type == type && info->inst == inst && info->reset >= 0)
70 return BIT(info->reset);
78 nvkm_top_intr_mask(struct nvkm_device *device, enum nvkm_subdev_type type, int inst)
80 struct nvkm_top *top = device->top;
81 struct nvkm_top_device *info;
84 list_for_each_entry(info, &top->device, head) {
85 if (info->type == type && info->inst == inst && info->intr >= 0)
86 return BIT(info->intr);
94 nvkm_top_fault_id(struct nvkm_device *device, enum nvkm_devidx devidx)
96 struct nvkm_top *top = device->top;
97 struct nvkm_top_device *info;
99 list_for_each_entry(info, &top->device, head) {
100 if (info->index == devidx && info->fault >= 0)
108 nvkm_top_fault(struct nvkm_device *device, int fault)
110 struct nvkm_top *top = device->top;
111 struct nvkm_top_device *info;
113 list_for_each_entry(info, &top->device, head) {
114 if (info->fault == fault)
118 return NVKM_SUBDEV_NR;
122 nvkm_top_engine(struct nvkm_device *device, int index, int *runl, int *engn)
124 struct nvkm_top *top = device->top;
125 struct nvkm_top_device *info;
128 list_for_each_entry(info, &top->device, head) {
129 if (info->engine >= 0 && info->runlist >= 0 && n++ == index) {
130 *runl = info->runlist;
131 *engn = info->engine;
140 nvkm_top_oneinit(struct nvkm_subdev *subdev)
142 struct nvkm_top *top = nvkm_top(subdev);
143 return top->func->oneinit(top);
147 nvkm_top_dtor(struct nvkm_subdev *subdev)
149 struct nvkm_top *top = nvkm_top(subdev);
150 struct nvkm_top_device *info, *temp;
152 list_for_each_entry_safe(info, temp, &top->device, head) {
153 list_del(&info->head);
160 static const struct nvkm_subdev_func
162 .dtor = nvkm_top_dtor,
163 .oneinit = nvkm_top_oneinit,
167 nvkm_top_new_(const struct nvkm_top_func *func, struct nvkm_device *device,
168 enum nvkm_subdev_type type, int inst, struct nvkm_top **ptop)
170 struct nvkm_top *top;
171 if (!(top = *ptop = kzalloc(sizeof(*top), GFP_KERNEL)))
173 nvkm_subdev_ctor(&nvkm_top, device, type, inst, &top->subdev);
175 INIT_LIST_HEAD(&top->device);