3fbbb6e6a66b3e55a8feca2ea7cc2ca2dd8ff2a0
[linux-2.6-microblaze.git] / drivers / gpu / drm / nouveau / nvkm / engine / disp / uconn.c
1 /*
2  * Copyright 2021 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 #define nvkm_uconn(p) container_of((p), struct nvkm_conn, object)
23 #include "conn.h"
24
25 #include <nvif/if0011.h>
26
27 static void *
28 nvkm_uconn_dtor(struct nvkm_object *object)
29 {
30         struct nvkm_conn *conn = nvkm_uconn(object);
31         struct nvkm_disp *disp = conn->disp;
32
33         spin_lock(&disp->client.lock);
34         conn->object.func = NULL;
35         spin_unlock(&disp->client.lock);
36         return NULL;
37 }
38
39 static const struct nvkm_object_func
40 nvkm_uconn = {
41         .dtor = nvkm_uconn_dtor,
42 };
43
44 int
45 nvkm_uconn_new(const struct nvkm_oclass *oclass, void *argv, u32 argc, struct nvkm_object **pobject)
46 {
47         struct nvkm_disp *disp = nvkm_udisp(oclass->parent);
48         struct nvkm_conn *cont, *conn = NULL;
49         union nvif_conn_args *args = argv;
50         int ret;
51
52         if (argc != sizeof(args->v0) || args->v0.version != 0)
53                 return -ENOSYS;
54
55         list_for_each_entry(cont, &disp->conns, head) {
56                 if (cont->index == args->v0.id) {
57                         conn = cont;
58                         break;
59                 }
60         }
61
62         if (!conn)
63                 return -EINVAL;
64
65         ret = -EBUSY;
66         spin_lock(&disp->client.lock);
67         if (!conn->object.func) {
68                 nvkm_object_ctor(&nvkm_uconn, oclass, &conn->object);
69                 *pobject = &conn->object;
70                 ret = 0;
71         }
72         spin_unlock(&disp->client.lock);
73         return ret;
74 }