2 * Copyright 2021 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 #define nvkm_uconn(p) container_of((p), struct nvkm_conn, object)
25 #include <nvif/if0011.h>
28 nvkm_uconn_dtor(struct nvkm_object *object)
30 struct nvkm_conn *conn = nvkm_uconn(object);
31 struct nvkm_disp *disp = conn->disp;
33 spin_lock(&disp->client.lock);
34 conn->object.func = NULL;
35 spin_unlock(&disp->client.lock);
39 static const struct nvkm_object_func
41 .dtor = nvkm_uconn_dtor,
45 nvkm_uconn_new(const struct nvkm_oclass *oclass, void *argv, u32 argc, struct nvkm_object **pobject)
47 struct nvkm_disp *disp = nvkm_udisp(oclass->parent);
48 struct nvkm_conn *cont, *conn = NULL;
49 union nvif_conn_args *args = argv;
52 if (argc != sizeof(args->v0) || args->v0.version != 0)
55 list_for_each_entry(cont, &disp->conns, head) {
56 if (cont->index == args->v0.id) {
66 spin_lock(&disp->client.lock);
67 if (!conn->object.func) {
68 nvkm_object_ctor(&nvkm_uconn, oclass, &conn->object);
69 *pobject = &conn->object;
72 spin_unlock(&disp->client.lock);