]>
git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/blob - drivers/gpu/drm/nouveau/nvkm/engine/disp/outp.c
2 * Copyright 2014 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.
27 #include <subdev/bios.h>
28 #include <subdev/bios/dcb.h>
29 #include <subdev/i2c.h>
32 nvkm_outp_route(struct nvkm_disp
*disp
)
34 struct nvkm_outp
*outp
;
37 list_for_each_entry(ior
, &disp
->ior
, head
) {
38 if ((outp
= ior
->arm
.outp
) && ior
->arm
.outp
!= ior
->asy
.outp
) {
39 OUTP_DBG(outp
, "release %s", ior
->name
);
40 if (ior
->func
->route
.set
)
41 ior
->func
->route
.set(outp
, NULL
);
46 list_for_each_entry(ior
, &disp
->ior
, head
) {
47 if ((outp
= ior
->asy
.outp
)) {
48 OUTP_DBG(outp
, "acquire %s", ior
->name
);
49 if (ior
->asy
.outp
!= ior
->arm
.outp
) {
50 if (ior
->func
->route
.set
)
51 ior
->func
->route
.set(outp
, ior
);
52 ior
->arm
.outp
= ior
->asy
.outp
;
58 static enum nvkm_ior_proto
59 nvkm_outp_xlat(struct nvkm_outp
*outp
, enum nvkm_ior_type
*type
)
61 switch (outp
->info
.location
) {
63 switch (outp
->info
.type
) {
64 case DCB_OUTPUT_ANALOG
: *type
= DAC
; return CRT
;
65 case DCB_OUTPUT_TMDS
: *type
= SOR
; return TMDS
;
66 case DCB_OUTPUT_LVDS
: *type
= SOR
; return LVDS
;
67 case DCB_OUTPUT_DP
: *type
= SOR
; return DP
;
73 switch (outp
->info
.type
) {
74 case DCB_OUTPUT_TMDS
: *type
= PIOR
; return TMDS
;
75 case DCB_OUTPUT_DP
: *type
= PIOR
; return TMDS
; /* not a bug */
88 nvkm_outp_release(struct nvkm_outp
*outp
, u8 user
)
90 struct nvkm_ior
*ior
= outp
->ior
;
91 OUTP_TRACE(outp
, "release %02x &= %02x %p", outp
->acquired
, ~user
, ior
);
93 outp
->acquired
&= ~user
;
94 if (!outp
->acquired
) {
95 outp
->ior
->asy
.outp
= NULL
;
102 nvkm_outp_acquire_ior(struct nvkm_outp
*outp
, u8 user
, struct nvkm_ior
*ior
)
105 outp
->ior
->asy
.outp
= outp
;
106 outp
->ior
->asy
.link
= outp
->info
.sorconf
.link
;
107 outp
->acquired
|= user
;
112 nvkm_outp_acquire(struct nvkm_outp
*outp
, u8 user
)
114 struct nvkm_ior
*ior
= outp
->ior
;
115 enum nvkm_ior_proto proto
;
116 enum nvkm_ior_type type
;
118 OUTP_TRACE(outp
, "acquire %02x |= %02x %p", outp
->acquired
, user
, ior
);
120 outp
->acquired
|= user
;
124 /* Lookup a compatible, and unused, OR to assign to the device. */
125 proto
= nvkm_outp_xlat(outp
, &type
);
126 if (proto
== UNKNOWN
)
129 /* First preference is to reuse the OR that is currently armed
130 * on HW, if any, in order to prevent unnecessary switching.
132 list_for_each_entry(ior
, &outp
->disp
->ior
, head
) {
133 if (!ior
->asy
.outp
&& ior
->arm
.outp
== outp
)
134 return nvkm_outp_acquire_ior(outp
, user
, ior
);
137 /* Failing that, a completely unused OR is the next best thing. */
138 list_for_each_entry(ior
, &outp
->disp
->ior
, head
) {
139 if (!ior
->asy
.outp
&& ior
->type
== type
&& !ior
->arm
.outp
&&
140 (ior
->func
->route
.set
|| ior
->id
== __ffs(outp
->info
.or)))
141 return nvkm_outp_acquire_ior(outp
, user
, ior
);
144 /* Last resort is to assign an OR that's already active on HW,
145 * but will be released during the next modeset.
147 list_for_each_entry(ior
, &outp
->disp
->ior
, head
) {
148 if (!ior
->asy
.outp
&& ior
->type
== type
&&
149 (ior
->func
->route
.set
|| ior
->id
== __ffs(outp
->info
.or)))
150 return nvkm_outp_acquire_ior(outp
, user
, ior
);
157 nvkm_outp_fini(struct nvkm_outp
*outp
)
159 if (outp
->func
->fini
)
160 outp
->func
->fini(outp
);
164 nvkm_outp_init_route(struct nvkm_outp
*outp
)
166 struct nvkm_disp
*disp
= outp
->disp
;
167 enum nvkm_ior_proto proto
;
168 enum nvkm_ior_type type
;
169 struct nvkm_ior
*ior
;
172 /* Find any OR from the class that is able to support this device. */
173 proto
= nvkm_outp_xlat(outp
, &type
);
174 if (proto
== UNKNOWN
)
177 ior
= nvkm_ior_find(disp
, type
, -1);
183 /* Determine the specific OR, if any, this device is attached to. */
184 if (ior
->func
->route
.get
) {
185 id
= ior
->func
->route
.get(outp
, &link
);
187 OUTP_DBG(outp
, "no route");
191 /* Prior to DCB 4.1, this is hardwired like so. */
192 id
= ffs(outp
->info
.or) - 1;
193 link
= (ior
->type
== SOR
) ? outp
->info
.sorconf
.link
: 0;
196 ior
= nvkm_ior_find(disp
, type
, id
);
202 /* Determine if the OR is already configured for this device. */
203 ior
->func
->state(ior
, &ior
->arm
);
204 if (!ior
->arm
.head
|| ior
->arm
.proto
!= proto
) {
205 OUTP_DBG(outp
, "no heads (%x %d %d)", ior
->arm
.head
,
206 ior
->arm
.proto
, proto
);
210 OUTP_DBG(outp
, "on %s link %x", ior
->name
, ior
->arm
.link
);
211 ior
->arm
.outp
= outp
;
215 nvkm_outp_init(struct nvkm_outp
*outp
)
217 nvkm_outp_init_route(outp
);
218 if (outp
->func
->init
)
219 outp
->func
->init(outp
);
223 nvkm_outp_del(struct nvkm_outp
**poutp
)
225 struct nvkm_outp
*outp
= *poutp
;
226 if (outp
&& !WARN_ON(!outp
->func
)) {
227 if (outp
->func
->dtor
)
228 *poutp
= outp
->func
->dtor(outp
);
235 nvkm_outp_ctor(const struct nvkm_outp_func
*func
, struct nvkm_disp
*disp
,
236 int index
, struct dcb_output
*dcbE
, struct nvkm_outp
*outp
)
238 struct nvkm_i2c
*i2c
= disp
->engine
.subdev
.device
->i2c
;
239 enum nvkm_ior_proto proto
;
240 enum nvkm_ior_type type
;
246 outp
->i2c
= nvkm_i2c_bus_find(i2c
, dcbE
->i2c_index
);
247 outp
->or = ffs(outp
->info
.or) - 1;
249 OUTP_DBG(outp
, "type %02x loc %d or %d link %d con %x "
250 "edid %x bus %d head %x",
251 outp
->info
.type
, outp
->info
.location
, outp
->info
.or,
252 outp
->info
.type
>= 2 ? outp
->info
.sorconf
.link
: 0,
253 outp
->info
.connector
, outp
->info
.i2c_index
,
254 outp
->info
.bus
, outp
->info
.heads
);
256 /* Cull output paths we can't map to an output resource. */
257 proto
= nvkm_outp_xlat(outp
, &type
);
258 if (proto
== UNKNOWN
)
264 static const struct nvkm_outp_func
269 nvkm_outp_new(struct nvkm_disp
*disp
, int index
, struct dcb_output
*dcbE
,
270 struct nvkm_outp
**poutp
)
272 if (!(*poutp
= kzalloc(sizeof(**poutp
), GFP_KERNEL
)))
274 return nvkm_outp_ctor(&nvkm_outp
, disp
, index
, dcbE
, *poutp
);