Skip to content

Commit 20f505f

Browse files
StanFox1984vsyrjala
authored andcommitted
drm/i915: Restrict qgv points which don't have enough bandwidth.
According to BSpec 53998, we should try to restrict qgv points, which can't provide enough bandwidth for desired display configuration. Currently we are just comparing against all of those and take minimum(worst case). v2: Fixed wrong PCode reply mask, removed hardcoded values. v3: Forbid simultaneous legacy SAGV PCode requests and restricting qgv points. Put the actual restriction to commit function, added serialization(thanks to Ville) to prevent commit being applied out of order in case of nonblocking and/or nomodeset commits. v4: - Minor code refactoring, fixed few typos(thanks to James Ausmus) - Change the naming of qgv point masking/unmasking functions(James Ausmus). - Simplify the masking/unmasking operation itself, as we don't need to mask only single point per request(James Ausmus) - Reject and stick to highest bandwidth point if SAGV can't be enabled(BSpec) v5: - Add new mailbox reply codes, which seems to happen during boot time for TGL and indicate that QGV setting is not yet available. v6: - Increase number of supported QGV points to be in sync with BSpec. v7: - Rebased and resolved conflict to fix build failure. - Fix NUM_QGV_POINTS to 8 and moved that to header file(James Ausmus) v8: - Don't report an error if we can't restrict qgv points, as SAGV can be disabled by BIOS, which is completely legal. So don't make CI panic. Instead if we detect that there is only 1 QGV point accessible just analyze if we can fit the required bandwidth requirements, but no need in restricting. v9: - Fix wrong QGV transition if we have 0 planes and no SAGV simultaneously. v10: - Fix CDCLK corruption, because of global state getting serialized without modeset, which caused copying of non-calculated cdclk to be copied to dev_priv(thanks to Ville for the hint). v11: - Remove unneeded headers and spaces(Matthew Roper) - Remove unneeded intel_qgv_info qi struct from bw check and zero out the needed one(Matthew Roper) - Changed QGV error message to have more clear meaning(Matthew Roper) - Use state->modeset_set instead of any_ms(Matthew Roper) - Moved NUM_SAGV_POINTS from i915_reg.h to i915_drv.h where it's used - Keep using crtc_state->hw.active instead of .enable(Matthew Roper) - Moved unrelated changes to other patch(using latency as parameter for plane wm calculation, moved to SAGV refactoring patch) v12: - Fix rebase conflict with own temporary SAGV/QGV fix. - Remove unnecessary mask being zero check when unmasking qgv points as this is completely legal(Matt Roper) - Check if we are setting the same mask as already being set in hardware to prevent error from PCode. - Fix error message when restricting/unrestricting qgv points to "mask/unmask" which sounds more accurate(Matt Roper) - Move sagv status setting to icl_get_bw_info from atomic check as this should be calculated only once.(Matt Roper) - Edited comments for the case when we can't enable SAGV and use only 1 QGV point with highest bandwidth to be more understandable.(Matt Roper) v13: - Moved max_data_rate in bw check to closer scope(Ville Syrjälä) - Changed comment for zero new_mask in qgv points masking function to better reflect reality(Ville Syrjälä) - Simplified bit mask operation in qgv points masking function (Ville Syrjälä) - Moved intel_qgv_points_mask closer to gen11 SAGV disabling, however this still can't be under modeset condition(Ville Syrjälä) - Packed qgv_points_mask as u8 and moved closer to pipe_sagv_mask (Ville Syrjälä) - Extracted PCode changes to separate patch.(Ville Syrjälä) - Now treat num_planes 0 same as 1 to avoid confusion and returning max_bw as 0, which would prevent choosing QGV point having max bandwidth in case if SAGV is not allowed, as per BSpec(Ville Syrjälä) - Do the actual qgv_points_mask swap in the same place as all other global state parts like cdclk are swapped. In the next patch, this all will be moved to bw state as global state, once new global state patch series from Ville lands v14: - Now using global state to serialize access to qgv points - Added global state locking back, otherwise we seem to read bw state in a wrong way. v15: - Added TODO comment for near atomic global state locking in bw code. v16: - Fixed intel_atomic_bw_* functions to be intel_bw_* as discussed with Jani Nikula. - Take bw_state_changed flag into use. v17: - Moved qgv point related manipulations next to SAGV code, as those are semantically related(Ville Syrjälä) - Renamed those into intel_sagv_(pre)|(post)_plane_update (Ville Syrjälä) v18: - Move sagv related calls from commit tail into intel_sagv_(pre)|(post)_plane_update(Ville Syrjälä) v19: - Use intel_atomic_get_bw_(old)|(new)_state which is intended for commit tail stage. v20: - Return max bandwidth for 0 planes(Ville) - Constify old_bw_state in bw_atomic_check(Ville) - Removed some debugs(Ville) - Added data rate to debug print when no QGV points(Ville) - Removed some comments(Ville) v21, v22, v23: - Fixed rebase conflict v24: - Changed PCode mask to use ICL_ prefix v25: - Resolved rebase conflict v26: - Removed redundant NULL checks(Ville) - Removed redundant error prints(Ville) v27: - Use device specific drm_err(Ville) - Fixed parenthesis ident reported by checkpatch Line over 100 warns to be fixed together with existing code style. Signed-off-by: Stanislav Lisovskiy <[email protected]> Cc: Ville Syrjälä <[email protected]> Cc: James Ausmus <[email protected]> [vsyrjala: Drop duplicate intel_sagv_{pre,post}_plane_update() prototypes and drop unused NUM_SAGV_POINTS define] Signed-off-by: Ville Syrjälä <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent 7241c57 commit 20f505f

File tree

3 files changed

+162
-37
lines changed

3 files changed

+162
-37
lines changed

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

Lines changed: 102 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
#include "intel_bw.h"
99
#include "intel_display_types.h"
1010
#include "intel_sideband.h"
11+
#include "intel_atomic.h"
12+
#include "intel_pm.h"
13+
1114

1215
/* Parameters for Qclk Geyserville (QGV) */
1316
struct intel_qgv_point {
@@ -113,6 +116,26 @@ static int icl_pcode_read_qgv_point_info(struct drm_i915_private *dev_priv,
113116
return 0;
114117
}
115118

119+
int icl_pcode_restrict_qgv_points(struct drm_i915_private *dev_priv,
120+
u32 points_mask)
121+
{
122+
int ret;
123+
124+
/* bspec says to keep retrying for at least 1 ms */
125+
ret = skl_pcode_request(dev_priv, ICL_PCODE_SAGV_DE_MEM_SS_CONFIG,
126+
points_mask,
127+
ICL_PCODE_POINTS_RESTRICTED_MASK,
128+
ICL_PCODE_POINTS_RESTRICTED,
129+
1);
130+
131+
if (ret < 0) {
132+
drm_err(&dev_priv->drm, "Failed to disable qgv points (%d)\n", ret);
133+
return ret;
134+
}
135+
136+
return 0;
137+
}
138+
116139
static int icl_get_qgv_points(struct drm_i915_private *dev_priv,
117140
struct intel_qgv_info *qi)
118141
{
@@ -240,6 +263,16 @@ static int icl_get_bw_info(struct drm_i915_private *dev_priv, const struct intel
240263
break;
241264
}
242265

266+
/*
267+
* In case if SAGV is disabled in BIOS, we always get 1
268+
* SAGV point, but we can't send PCode commands to restrict it
269+
* as it will fail and pointless anyway.
270+
*/
271+
if (qi.num_points == 1)
272+
dev_priv->sagv_status = I915_SAGV_NOT_CONTROLLED;
273+
else
274+
dev_priv->sagv_status = I915_SAGV_ENABLED;
275+
243276
return 0;
244277
}
245278

@@ -248,6 +281,11 @@ static unsigned int icl_max_bw(struct drm_i915_private *dev_priv,
248281
{
249282
int i;
250283

284+
/*
285+
* Let's return max bw for 0 planes
286+
*/
287+
num_planes = max(1, num_planes);
288+
251289
for (i = 0; i < ARRAY_SIZE(dev_priv->max_bw); i++) {
252290
const struct intel_bw_info *bi =
253291
&dev_priv->max_bw[i];
@@ -277,34 +315,6 @@ void intel_bw_init_hw(struct drm_i915_private *dev_priv)
277315
icl_get_bw_info(dev_priv, &icl_sa_info);
278316
}
279317

280-
static unsigned int intel_max_data_rate(struct drm_i915_private *dev_priv,
281-
int num_planes)
282-
{
283-
if (INTEL_GEN(dev_priv) >= 11) {
284-
/*
285-
* Any bw group has same amount of QGV points
286-
*/
287-
const struct intel_bw_info *bi =
288-
&dev_priv->max_bw[0];
289-
unsigned int min_bw = UINT_MAX;
290-
int i;
291-
292-
/*
293-
* FIXME with SAGV disabled maybe we can assume
294-
* point 1 will always be used? Seems to match
295-
* the behaviour observed in the wild.
296-
*/
297-
for (i = 0; i < bi->num_qgv_points; i++) {
298-
unsigned int bw = icl_max_bw(dev_priv, num_planes, i);
299-
300-
min_bw = min(bw, min_bw);
301-
}
302-
return min_bw;
303-
} else {
304-
return UINT_MAX;
305-
}
306-
}
307-
308318
static unsigned int intel_bw_crtc_num_active_planes(const struct intel_crtc_state *crtc_state)
309319
{
310320
/*
@@ -415,10 +425,15 @@ int intel_bw_atomic_check(struct intel_atomic_state *state)
415425
struct drm_i915_private *dev_priv = to_i915(state->base.dev);
416426
struct intel_crtc_state *new_crtc_state, *old_crtc_state;
417427
struct intel_bw_state *new_bw_state = NULL;
418-
unsigned int data_rate, max_data_rate;
428+
const struct intel_bw_state *old_bw_state = NULL;
429+
unsigned int data_rate;
419430
unsigned int num_active_planes;
420431
struct intel_crtc *crtc;
421432
int i, ret;
433+
u32 allowed_points = 0;
434+
unsigned int max_bw_point = 0, max_bw = 0;
435+
unsigned int num_qgv_points = dev_priv->max_bw[0].num_qgv_points;
436+
u32 mask = (1 << num_qgv_points) - 1;
422437

423438
/* FIXME earlier gens need some checks too */
424439
if (INTEL_GEN(dev_priv) < 11)
@@ -465,19 +480,71 @@ int intel_bw_atomic_check(struct intel_atomic_state *state)
465480
return ret;
466481

467482
data_rate = intel_bw_data_rate(dev_priv, new_bw_state);
483+
data_rate = DIV_ROUND_UP(data_rate, 1000);
484+
468485
num_active_planes = intel_bw_num_active_planes(dev_priv, new_bw_state);
469486

470-
max_data_rate = intel_max_data_rate(dev_priv, num_active_planes);
487+
for (i = 0; i < num_qgv_points; i++) {
488+
unsigned int max_data_rate;
471489

472-
data_rate = DIV_ROUND_UP(data_rate, 1000);
490+
max_data_rate = icl_max_bw(dev_priv, num_active_planes, i);
491+
/*
492+
* We need to know which qgv point gives us
493+
* maximum bandwidth in order to disable SAGV
494+
* if we find that we exceed SAGV block time
495+
* with watermarks. By that moment we already
496+
* have those, as it is calculated earlier in
497+
* intel_atomic_check,
498+
*/
499+
if (max_data_rate > max_bw) {
500+
max_bw_point = i;
501+
max_bw = max_data_rate;
502+
}
503+
if (max_data_rate >= data_rate)
504+
allowed_points |= BIT(i);
505+
drm_dbg_kms(&dev_priv->drm, "QGV point %d: max bw %d required %d\n",
506+
i, max_data_rate, data_rate);
507+
}
473508

474-
if (data_rate > max_data_rate) {
475-
drm_dbg_kms(&dev_priv->drm,
476-
"Bandwidth %u MB/s exceeds max available %d MB/s (%d active planes)\n",
477-
data_rate, max_data_rate, num_active_planes);
509+
/*
510+
* BSpec states that we always should have at least one allowed point
511+
* left, so if we couldn't - simply reject the configuration for obvious
512+
* reasons.
513+
*/
514+
if (allowed_points == 0) {
515+
drm_dbg_kms(&dev_priv->drm, "No QGV points provide sufficient memory"
516+
" bandwidth %d for display configuration(%d active planes).\n",
517+
data_rate, num_active_planes);
478518
return -EINVAL;
479519
}
480520

521+
/*
522+
* Leave only single point with highest bandwidth, if
523+
* we can't enable SAGV due to the increased memory latency it may
524+
* cause.
525+
*/
526+
if (!intel_can_enable_sagv(dev_priv, new_bw_state)) {
527+
allowed_points = BIT(max_bw_point);
528+
drm_dbg_kms(&dev_priv->drm, "No SAGV, using single QGV point %d\n",
529+
max_bw_point);
530+
}
531+
/*
532+
* We store the ones which need to be masked as that is what PCode
533+
* actually accepts as a parameter.
534+
*/
535+
new_bw_state->qgv_points_mask = ~allowed_points & mask;
536+
537+
old_bw_state = intel_atomic_get_old_bw_state(state);
538+
/*
539+
* If the actual mask had changed we need to make sure that
540+
* the commits are serialized(in case this is a nomodeset, nonblocking)
541+
*/
542+
if (new_bw_state->qgv_points_mask != old_bw_state->qgv_points_mask) {
543+
ret = intel_atomic_serialize_global_state(&new_bw_state->base);
544+
if (ret)
545+
return ret;
546+
}
547+
481548
return 0;
482549
}
483550

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ struct intel_bw_state {
2424
*/
2525
u8 pipe_sagv_reject;
2626

27+
/*
28+
* Current QGV points mask, which restricts
29+
* some particular SAGV states, not to confuse
30+
* with pipe_sagv_mask.
31+
*/
32+
u8 qgv_points_mask;
33+
2734
unsigned int data_rate[I915_MAX_PIPES];
2835
u8 num_active_planes[I915_MAX_PIPES];
2936

@@ -47,5 +54,7 @@ int intel_bw_init(struct drm_i915_private *dev_priv);
4754
int intel_bw_atomic_check(struct intel_atomic_state *state);
4855
void intel_bw_crtc_update(struct intel_bw_state *bw_state,
4956
const struct intel_crtc_state *crtc_state);
57+
int icl_pcode_restrict_qgv_points(struct drm_i915_private *dev_priv,
58+
u32 points_mask);
5059

5160
#endif /* __INTEL_BW_H__ */

drivers/gpu/drm/i915/intel_pm.c

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3762,6 +3762,8 @@ void intel_sagv_pre_plane_update(struct intel_atomic_state *state)
37623762
{
37633763
struct drm_i915_private *dev_priv = to_i915(state->base.dev);
37643764
const struct intel_bw_state *new_bw_state;
3765+
const struct intel_bw_state *old_bw_state;
3766+
u32 new_mask = 0;
37653767

37663768
/*
37673769
* Just return if we can't control SAGV or don't have it.
@@ -3777,14 +3779,42 @@ void intel_sagv_pre_plane_update(struct intel_atomic_state *state)
37773779
if (!new_bw_state)
37783780
return;
37793781

3780-
if (!intel_can_enable_sagv(dev_priv, new_bw_state))
3782+
if (INTEL_GEN(dev_priv) < 11 && !intel_can_enable_sagv(dev_priv, new_bw_state)) {
37813783
intel_disable_sagv(dev_priv);
3784+
return;
3785+
}
3786+
3787+
old_bw_state = intel_atomic_get_old_bw_state(state);
3788+
/*
3789+
* Nothing to mask
3790+
*/
3791+
if (new_bw_state->qgv_points_mask == old_bw_state->qgv_points_mask)
3792+
return;
3793+
3794+
new_mask = old_bw_state->qgv_points_mask | new_bw_state->qgv_points_mask;
3795+
3796+
/*
3797+
* If new mask is zero - means there is nothing to mask,
3798+
* we can only unmask, which should be done in unmask.
3799+
*/
3800+
if (!new_mask)
3801+
return;
3802+
3803+
/*
3804+
* Restrict required qgv points before updating the configuration.
3805+
* According to BSpec we can't mask and unmask qgv points at the same
3806+
* time. Also masking should be done before updating the configuration
3807+
* and unmasking afterwards.
3808+
*/
3809+
icl_pcode_restrict_qgv_points(dev_priv, new_mask);
37823810
}
37833811

37843812
void intel_sagv_post_plane_update(struct intel_atomic_state *state)
37853813
{
37863814
struct drm_i915_private *dev_priv = to_i915(state->base.dev);
37873815
const struct intel_bw_state *new_bw_state;
3816+
const struct intel_bw_state *old_bw_state;
3817+
u32 new_mask = 0;
37883818

37893819
/*
37903820
* Just return if we can't control SAGV or don't have it.
@@ -3800,8 +3830,27 @@ void intel_sagv_post_plane_update(struct intel_atomic_state *state)
38003830
if (!new_bw_state)
38013831
return;
38023832

3803-
if (intel_can_enable_sagv(dev_priv, new_bw_state))
3833+
if (INTEL_GEN(dev_priv) < 11 && intel_can_enable_sagv(dev_priv, new_bw_state)) {
38043834
intel_enable_sagv(dev_priv);
3835+
return;
3836+
}
3837+
3838+
old_bw_state = intel_atomic_get_old_bw_state(state);
3839+
/*
3840+
* Nothing to unmask
3841+
*/
3842+
if (new_bw_state->qgv_points_mask == old_bw_state->qgv_points_mask)
3843+
return;
3844+
3845+
new_mask = new_bw_state->qgv_points_mask;
3846+
3847+
/*
3848+
* Allow required qgv points after updating the configuration.
3849+
* According to BSpec we can't mask and unmask qgv points at the same
3850+
* time. Also masking should be done before updating the configuration
3851+
* and unmasking afterwards.
3852+
*/
3853+
icl_pcode_restrict_qgv_points(dev_priv, new_mask);
38053854
}
38063855

38073856
static bool skl_crtc_can_enable_sagv(const struct intel_crtc_state *crtc_state)

0 commit comments

Comments
 (0)