]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blob - drivers/gpu/drm/nouveau/core/engine/disp/base.c
drm/nouveau/disp: implement nvif event sources for vblank/connector notifiers
[mirror_ubuntu-jammy-kernel.git] / drivers / gpu / drm / nouveau / core / engine / disp / base.c
1 /*
2 * Copyright 2013 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
23 */
24
25 #include <core/os.h>
26 #include <nvif/unpack.h>
27 #include <nvif/class.h>
28 #include <nvif/event.h>
29
30 #include "priv.h"
31 #include "outp.h"
32 #include "conn.h"
33
34 int
35 nouveau_disp_vblank_ctor(void *data, u32 size, struct nvkm_notify *notify)
36 {
37 struct nouveau_disp *disp =
38 container_of(notify->event, typeof(*disp), vblank);
39 union {
40 struct nvif_notify_head_req_v0 v0;
41 } *req = data;
42 int ret;
43
44 if (nvif_unpack(req->v0, 0, 0, false)) {
45 notify->size = sizeof(struct nvif_notify_head_rep_v0);
46 if (ret = -ENXIO, req->v0.head <= disp->vblank.index_nr) {
47 notify->types = 1;
48 notify->index = req->v0.head;
49 return 0;
50 }
51 }
52
53 return ret;
54 }
55
56 void
57 nouveau_disp_vblank(struct nouveau_disp *disp, int head)
58 {
59 struct nvif_notify_head_rep_v0 rep = {};
60 nvkm_event_send(&disp->vblank, 1, head, &rep, sizeof(rep));
61 }
62
63 static int
64 nouveau_disp_hpd_ctor(void *data, u32 size, struct nvkm_notify *notify)
65 {
66 struct nouveau_disp *disp =
67 container_of(notify->event, typeof(*disp), hpd);
68 union {
69 struct nvif_notify_conn_req_v0 v0;
70 } *req = data;
71 struct nvkm_output *outp;
72 int ret;
73
74 if (nvif_unpack(req->v0, 0, 0, false)) {
75 notify->size = sizeof(struct nvif_notify_conn_rep_v0);
76 list_for_each_entry(outp, &disp->outp, head) {
77 if (ret = -ENXIO, outp->conn->index == req->v0.conn) {
78 if (ret = -ENODEV, outp->conn->hpd.event) {
79 notify->types = req->v0.mask;
80 notify->index = req->v0.conn;
81 ret = 0;
82 }
83 break;
84 }
85 }
86 }
87
88 return ret;
89 }
90
91 static const struct nvkm_event_func
92 nouveau_disp_hpd_func = {
93 .ctor = nouveau_disp_hpd_ctor
94 };
95
96 int
97 nouveau_disp_ntfy(struct nouveau_object *object, u32 type,
98 struct nvkm_event **event)
99 {
100 struct nouveau_disp *disp = (void *)object->engine;
101 switch (type) {
102 case NV04_DISP_NTFY_VBLANK:
103 *event = &disp->vblank;
104 return 0;
105 case NV04_DISP_NTFY_CONN:
106 *event = &disp->hpd;
107 return 0;
108 default:
109 break;
110 }
111 return -EINVAL;
112 }
113
114 int
115 _nouveau_disp_fini(struct nouveau_object *object, bool suspend)
116 {
117 struct nouveau_disp *disp = (void *)object;
118 struct nvkm_output *outp;
119 int ret;
120
121 list_for_each_entry(outp, &disp->outp, head) {
122 ret = nv_ofuncs(outp)->fini(nv_object(outp), suspend);
123 if (ret && suspend)
124 goto fail_outp;
125 }
126
127 return nouveau_engine_fini(&disp->base, suspend);
128
129 fail_outp:
130 list_for_each_entry_continue_reverse(outp, &disp->outp, head) {
131 nv_ofuncs(outp)->init(nv_object(outp));
132 }
133
134 return ret;
135 }
136
137 int
138 _nouveau_disp_init(struct nouveau_object *object)
139 {
140 struct nouveau_disp *disp = (void *)object;
141 struct nvkm_output *outp;
142 int ret;
143
144 ret = nouveau_engine_init(&disp->base);
145 if (ret)
146 return ret;
147
148 list_for_each_entry(outp, &disp->outp, head) {
149 ret = nv_ofuncs(outp)->init(nv_object(outp));
150 if (ret)
151 goto fail_outp;
152 }
153
154 return ret;
155
156 fail_outp:
157 list_for_each_entry_continue_reverse(outp, &disp->outp, head) {
158 nv_ofuncs(outp)->fini(nv_object(outp), false);
159 }
160
161 return ret;
162 }
163
164 void
165 _nouveau_disp_dtor(struct nouveau_object *object)
166 {
167 struct nouveau_disp *disp = (void *)object;
168 struct nvkm_output *outp, *outt;
169
170 nvkm_event_fini(&disp->vblank);
171 nvkm_event_fini(&disp->hpd);
172
173 if (disp->outp.next) {
174 list_for_each_entry_safe(outp, outt, &disp->outp, head) {
175 nouveau_object_ref(NULL, (struct nouveau_object **)&outp);
176 }
177 }
178
179 nouveau_engine_destroy(&disp->base);
180 }
181
182 int
183 nouveau_disp_create_(struct nouveau_object *parent,
184 struct nouveau_object *engine,
185 struct nouveau_oclass *oclass, int heads,
186 const char *intname, const char *extname,
187 int length, void **pobject)
188 {
189 struct nouveau_disp_impl *impl = (void *)oclass;
190 struct nouveau_bios *bios = nouveau_bios(parent);
191 struct nouveau_disp *disp;
192 struct nouveau_oclass **sclass;
193 struct nouveau_object *object;
194 struct dcb_output dcbE;
195 u8 hpd = 0, ver, hdr;
196 u32 data;
197 int ret, i;
198
199 ret = nouveau_engine_create_(parent, engine, oclass, true,
200 intname, extname, length, pobject);
201 disp = *pobject;
202 if (ret)
203 return ret;
204
205 INIT_LIST_HEAD(&disp->outp);
206
207 /* create output objects for each display path in the vbios */
208 i = -1;
209 while ((data = dcb_outp_parse(bios, ++i, &ver, &hdr, &dcbE))) {
210 if (dcbE.type == DCB_OUTPUT_UNUSED)
211 continue;
212 if (dcbE.type == DCB_OUTPUT_EOL)
213 break;
214 data = dcbE.location << 4 | dcbE.type;
215
216 oclass = nvkm_output_oclass;
217 sclass = impl->outp;
218 while (sclass && sclass[0]) {
219 if (sclass[0]->handle == data) {
220 oclass = sclass[0];
221 break;
222 }
223 sclass++;
224 }
225
226 nouveau_object_ctor(*pobject, *pobject, oclass,
227 &dcbE, i, &object);
228 hpd = max(hpd, (u8)(dcbE.connector + 1));
229 }
230
231 ret = nvkm_event_init(&nouveau_disp_hpd_func, 3, hpd, &disp->hpd);
232 if (ret)
233 return ret;
234
235 ret = nvkm_event_init(impl->vblank, 1, heads, &disp->vblank);
236 if (ret)
237 return ret;
238
239 return 0;
240 }