Skip to content

Commit f49499e

Browse files
vsyrjalajnikula
authored andcommitted
drm/i915: Walk crtcs in pipe order
Currently our crtcs are registered in pipe order, and thus all the for_intel_crtc*() iterators walk the crtcs in pipe order. There are a bunch of places that more or less depend on that. Eg. during plane updates and such we want joined pipes to be processed back-to-back to give a better chance of an atomic update across the whole set. When we start to register crtcs in a different order we don't want to change the order in which the pipes get handled. Decouple the for_each_intel_crtc*() iterators from the crtc registration order by using a separate list which will be sorted by the pipe rather than the crtc index. We could probably use a simple array or something, but that would require some kind of extra iterator variable for the macros, and thus would require a lot more changes. Using a linked list keeps the fallout minimal. We can look at using a more optimal data structure later. I also added this extra junk to the atomic state iterators: "(__i) = drm_crtc_index(&(crtc)->base), (void)(__i)" even though the macro itself no longer needs the "__i" iterator. This in case the "__i" is used by the caller, and to avoid compiler warnings if it's completely unused now. v2: Flip the pipe comparison (Jani) Reviewed-by: Jani Nikula <[email protected]> Signed-off-by: Ville Syrjälä <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jani Nikula <[email protected]>
1 parent 482bcc7 commit f49499e

6 files changed

Lines changed: 64 additions & 52 deletions

File tree

drivers/gpu/drm/i915/display/intel_crtc.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,8 @@ static struct intel_crtc *intel_crtc_alloc(void)
209209
crtc->base.state = &crtc_state->uapi;
210210
crtc->config = crtc_state;
211211

212+
INIT_LIST_HEAD(&crtc->pipe_head);
213+
212214
return crtc;
213215
}
214216

@@ -222,6 +224,8 @@ static void intel_crtc_destroy(struct drm_crtc *_crtc)
222224
{
223225
struct intel_crtc *crtc = to_intel_crtc(_crtc);
224226

227+
list_del(&crtc->pipe_head);
228+
225229
cpu_latency_qos_remove_request(&crtc->vblank_pm_qos);
226230

227231
drm_crtc_cleanup(&crtc->base);
@@ -308,6 +312,20 @@ static const struct drm_crtc_funcs i8xx_crtc_funcs = {
308312
.get_vblank_timestamp = intel_crtc_get_vblank_timestamp,
309313
};
310314

315+
static void add_crtc_to_pipe_list(struct intel_display *display, struct intel_crtc *crtc)
316+
{
317+
struct intel_crtc *iter;
318+
319+
list_for_each_entry(iter, &display->pipe_list, pipe_head) {
320+
if (crtc->pipe < iter->pipe) {
321+
list_add_tail(&crtc->pipe_head, &iter->pipe_head);
322+
return;
323+
}
324+
}
325+
326+
list_add_tail(&crtc->pipe_head, &display->pipe_list);
327+
}
328+
311329
static int __intel_crtc_init(struct intel_display *display, enum pipe pipe)
312330
{
313331
struct intel_plane *primary, *cursor;
@@ -398,6 +416,8 @@ static int __intel_crtc_init(struct intel_display *display, enum pipe pipe)
398416
if (HAS_CASF(display) && crtc->num_scalers >= 2)
399417
drm_crtc_create_sharpness_strength_property(&crtc->base);
400418

419+
add_crtc_to_pipe_list(display, crtc);
420+
401421
return 0;
402422

403423
fail:

drivers/gpu/drm/i915/display/intel_display.h

Lines changed: 38 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -212,22 +212,23 @@ enum phy_fia {
212212
base.head) \
213213
for_each_if((intel_plane)->pipe == (intel_crtc)->pipe)
214214

215-
#define for_each_intel_crtc(dev, intel_crtc) \
216-
list_for_each_entry(intel_crtc, \
217-
&(dev)->mode_config.crtc_list, \
218-
base.head)
215+
#define for_each_intel_crtc(dev, crtc) \
216+
list_for_each_entry((crtc), \
217+
&to_intel_display(dev)->pipe_list, \
218+
pipe_head)
219219

220-
#define for_each_intel_crtc_in_pipe_mask(dev, intel_crtc, pipe_mask) \
221-
list_for_each_entry(intel_crtc, \
222-
&(dev)->mode_config.crtc_list, \
223-
base.head) \
224-
for_each_if((pipe_mask) & BIT(intel_crtc->pipe))
220+
#define for_each_intel_crtc_reverse(dev, crtc) \
221+
list_for_each_entry_reverse((crtc), \
222+
&to_intel_display(dev)->pipe_list, \
223+
pipe_head)
224+
225+
#define for_each_intel_crtc_in_pipe_mask(dev, crtc, pipe_mask) \
226+
for_each_intel_crtc((dev), (crtc)) \
227+
for_each_if((pipe_mask) & BIT((crtc)->pipe))
225228

226-
#define for_each_intel_crtc_in_pipe_mask_reverse(dev, intel_crtc, pipe_mask) \
227-
list_for_each_entry_reverse((intel_crtc), \
228-
&(dev)->mode_config.crtc_list, \
229-
base.head) \
230-
for_each_if((pipe_mask) & BIT((intel_crtc)->pipe))
229+
#define for_each_intel_crtc_in_pipe_mask_reverse(dev, crtc, pipe_mask) \
230+
for_each_intel_crtc_reverse((dev), (crtc)) \
231+
for_each_if((pipe_mask) & BIT((crtc)->pipe))
231232

232233
#define for_each_intel_encoder(dev, intel_encoder) \
233234
list_for_each_entry(intel_encoder, \
@@ -269,14 +270,6 @@ enum phy_fia {
269270
(__i)++) \
270271
for_each_if(plane)
271272

272-
#define for_each_old_intel_crtc_in_state(__state, crtc, old_crtc_state, __i) \
273-
for ((__i) = 0; \
274-
(__i) < (__state)->base.dev->mode_config.num_crtc && \
275-
((crtc) = to_intel_crtc((__state)->base.crtcs[__i].ptr), \
276-
(old_crtc_state) = to_intel_crtc_state((__state)->base.crtcs[__i].old_state), 1); \
277-
(__i)++) \
278-
for_each_if(crtc)
279-
280273
#define for_each_new_intel_plane_in_state(__state, plane, new_plane_state, __i) \
281274
for ((__i) = 0; \
282275
(__i) < (__state)->base.dev->mode_config.num_total_plane && \
@@ -285,22 +278,6 @@ enum phy_fia {
285278
(__i)++) \
286279
for_each_if(plane)
287280

288-
#define for_each_new_intel_crtc_in_state(__state, crtc, new_crtc_state, __i) \
289-
for ((__i) = 0; \
290-
(__i) < (__state)->base.dev->mode_config.num_crtc && \
291-
((crtc) = to_intel_crtc((__state)->base.crtcs[__i].ptr), \
292-
(new_crtc_state) = to_intel_crtc_state((__state)->base.crtcs[__i].new_state), 1); \
293-
(__i)++) \
294-
for_each_if(crtc)
295-
296-
#define for_each_new_intel_crtc_in_state_reverse(__state, crtc, new_crtc_state, __i) \
297-
for ((__i) = (__state)->base.dev->mode_config.num_crtc - 1; \
298-
(__i) >= 0 && \
299-
((crtc) = to_intel_crtc((__state)->base.crtcs[__i].ptr), \
300-
(new_crtc_state) = to_intel_crtc_state((__state)->base.crtcs[__i].new_state), 1); \
301-
(__i)--) \
302-
for_each_if(crtc)
303-
304281
#define for_each_oldnew_intel_plane_in_state(__state, plane, old_plane_state, new_plane_state, __i) \
305282
for ((__i) = 0; \
306283
(__i) < (__state)->base.dev->mode_config.num_total_plane && \
@@ -310,23 +287,32 @@ enum phy_fia {
310287
(__i)++) \
311288
for_each_if(plane)
312289

290+
#define for_each_old_intel_crtc_in_state(__state, crtc, old_crtc_state, __i) \
291+
for_each_intel_crtc((__state)->base.dev, (crtc)) \
292+
for_each_if(((__i) = drm_crtc_index(&(crtc)->base), (void)(__i), \
293+
(old_crtc_state) = intel_atomic_get_old_crtc_state((__state), (crtc))))
294+
295+
#define for_each_new_intel_crtc_in_state(__state, crtc, new_crtc_state, __i) \
296+
for_each_intel_crtc((__state)->base.dev, (crtc)) \
297+
for_each_if(((__i) = drm_crtc_index(&(crtc)->base), (void)(__i), \
298+
(new_crtc_state) = intel_atomic_get_new_crtc_state((__state), (crtc))))
299+
300+
#define for_each_new_intel_crtc_in_state_reverse(__state, crtc, new_crtc_state, __i) \
301+
for_each_intel_crtc_reverse((__state)->base.dev, (crtc)) \
302+
for_each_if(((__i) = drm_crtc_index(&(crtc)->base), (void)(__i), \
303+
(new_crtc_state) = intel_atomic_get_new_crtc_state((__state), (crtc))))
304+
313305
#define for_each_oldnew_intel_crtc_in_state(__state, crtc, old_crtc_state, new_crtc_state, __i) \
314-
for ((__i) = 0; \
315-
(__i) < (__state)->base.dev->mode_config.num_crtc && \
316-
((crtc) = to_intel_crtc((__state)->base.crtcs[__i].ptr), \
317-
(old_crtc_state) = to_intel_crtc_state((__state)->base.crtcs[__i].old_state), \
318-
(new_crtc_state) = to_intel_crtc_state((__state)->base.crtcs[__i].new_state), 1); \
319-
(__i)++) \
320-
for_each_if(crtc)
306+
for_each_intel_crtc((__state)->base.dev, (crtc)) \
307+
for_each_if(((__i) = drm_crtc_index(&(crtc)->base), (void)(__i), \
308+
(old_crtc_state) = intel_atomic_get_old_crtc_state((__state), (crtc)), \
309+
(new_crtc_state) = intel_atomic_get_new_crtc_state((__state), (crtc))))
321310

322311
#define for_each_oldnew_intel_crtc_in_state_reverse(__state, crtc, old_crtc_state, new_crtc_state, __i) \
323-
for ((__i) = (__state)->base.dev->mode_config.num_crtc - 1; \
324-
(__i) >= 0 && \
325-
((crtc) = to_intel_crtc((__state)->base.crtcs[__i].ptr), \
326-
(old_crtc_state) = to_intel_crtc_state((__state)->base.crtcs[__i].old_state), \
327-
(new_crtc_state) = to_intel_crtc_state((__state)->base.crtcs[__i].new_state), 1); \
328-
(__i)--) \
329-
for_each_if(crtc)
312+
for_each_intel_crtc_reverse((__state)->base.dev, (crtc)) \
313+
for_each_if(((__i) = drm_crtc_index(&(crtc)->base), (void)(__i), \
314+
(old_crtc_state) = intel_atomic_get_old_crtc_state((__state), (crtc)), \
315+
(new_crtc_state) = intel_atomic_get_new_crtc_state((__state), (crtc))))
330316

331317
#define intel_atomic_crtc_state_for_each_plane_state( \
332318
plane, plane_state, \

drivers/gpu/drm/i915/display/intel_display_core.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,9 @@ struct intel_display {
294294
/* Parent, or core, driver functions exposed to display */
295295
const struct intel_display_parent_interface *parent;
296296

297+
/* list of all intel_crtcs sorted by pipe */
298+
struct list_head pipe_list;
299+
297300
/* Display functions */
298301
struct {
299302
/* Top level crtc-ish functions */

drivers/gpu/drm/i915/display/intel_display_driver.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ static void intel_mode_config_init(struct intel_display *display)
117117

118118
drm_mode_config_init(display->drm);
119119
INIT_LIST_HEAD(&display->global.obj_list);
120+
INIT_LIST_HEAD(&display->pipe_list);
120121

121122
mode_config->min_width = 0;
122123
mode_config->min_height = 0;

drivers/gpu/drm/i915/display/intel_display_types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1484,6 +1484,7 @@ struct intel_flipq {
14841484

14851485
struct intel_crtc {
14861486
struct drm_crtc base;
1487+
struct list_head pipe_head;
14871488
enum pipe pipe;
14881489
/*
14891490
* Whether the crtc and the connected output pipeline is active. Implies

drivers/gpu/drm/xe/display/xe_display.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "intel_audio.h"
2222
#include "intel_bw.h"
2323
#include "intel_display.h"
24+
#include "intel_display_core.h"
2425
#include "intel_display_device.h"
2526
#include "intel_display_driver.h"
2627
#include "intel_display_irq.h"

0 commit comments

Comments
 (0)