Skip to content

Commit 40bae1a

Browse files
Karthi Kandasamyalexdeucher
authored andcommitted
drm/amd/display: Move mcache allocation programming from DML to resource
[Why] mcache allocation programming is not part of DML's core responsibilities. Keeping this logic in DML leads to poor separation of concerns and complicates maintenance. [How] Refactored code to move mcache parameter preparation and mcache ID assignment into the resource file. Reviewed-by: Alvin Lee <[email protected]> Signed-off-by: Karthi Kandasamy <[email protected]> Signed-off-by: Tom Chung <[email protected]> Tested-by: Daniel Wheeler <[email protected]> Signed-off-by: Alex Deucher <[email protected]>
1 parent 17accf4 commit 40bae1a

File tree

8 files changed

+129
-1
lines changed

8 files changed

+129
-1
lines changed

drivers/gpu/drm/amd/display/dc/core/dc_resource.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5525,6 +5525,14 @@ struct dscl_prog_data *resource_get_dscl_prog_data(struct pipe_ctx *pipe_ctx)
55255525
return &pipe_ctx->plane_res.scl_data.dscl_prog_data;
55265526
}
55275527

5528+
static bool resource_allocate_mcache(struct dc_state *context, const struct dc_mcache_params *mcache_params)
5529+
{
5530+
if (context->clk_mgr->ctx->dc->res_pool->funcs->program_mcache_pipe_config)
5531+
context->clk_mgr->ctx->dc->res_pool->funcs->program_mcache_pipe_config(context, mcache_params);
5532+
5533+
return true;
5534+
}
5535+
55285536
void resource_init_common_dml2_callbacks(struct dc *dc, struct dml2_configuration_options *dml2_options)
55295537
{
55305538
dml2_options->callbacks.dc = dc;
@@ -5544,6 +5552,7 @@ void resource_init_common_dml2_callbacks(struct dc *dc, struct dml2_configuratio
55445552
dml2_options->callbacks.get_stream_status = &dc_state_get_stream_status;
55455553
dml2_options->callbacks.get_stream_from_id = &dc_state_get_stream_from_id;
55465554
dml2_options->callbacks.get_max_flickerless_instant_vtotal_increase = &dc_stream_get_max_flickerless_instant_vtotal_increase;
5555+
dml2_options->callbacks.allocate_mcache = &resource_allocate_mcache;
55475556

55485557
dml2_options->svp_pstate.callbacks.dc = dc;
55495558
dml2_options->svp_pstate.callbacks.add_phantom_plane = &dc_state_add_phantom_plane;

drivers/gpu/drm/amd/display/dc/dml2/dml21/dml21_translation_helper.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -952,7 +952,7 @@ static unsigned int map_stream_to_dml21_display_cfg(const struct dml2_context *d
952952
return location;
953953
}
954954

955-
static unsigned int map_plane_to_dml21_display_cfg(const struct dml2_context *dml_ctx, unsigned int stream_id,
955+
unsigned int map_plane_to_dml21_display_cfg(const struct dml2_context *dml_ctx, unsigned int stream_id,
956956
const struct dc_plane_state *plane, const struct dc_state *context)
957957
{
958958
unsigned int plane_id;

drivers/gpu/drm/amd/display/dc/dml2/dml21/dml21_translation_helper.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ struct dc_state;
1111
struct dcn_watermarks;
1212
union dcn_watermark_set;
1313
struct pipe_ctx;
14+
struct dc_plane_state;
1415

1516
struct dml2_context;
1617
struct dml2_configuration_options;
@@ -25,4 +26,5 @@ void dml21_extract_watermark_sets(const struct dc *in_dc, union dcn_watermark_se
2526
void dml21_map_hw_resources(struct dml2_context *dml_ctx);
2627
void dml21_get_pipe_mcache_config(struct dc_state *context, struct pipe_ctx *pipe_ctx, struct dml2_per_plane_programming *pln_prog, struct dml2_pipe_configuration_descriptor *mcache_pipe_config);
2728
void dml21_set_dc_p_state_type(struct pipe_ctx *pipe_ctx, struct dml2_per_stream_programming *stream_programming, bool sub_vp_enabled);
29+
unsigned int map_plane_to_dml21_display_cfg(const struct dml2_context *dml_ctx, unsigned int stream_id, const struct dc_plane_state *plane, const struct dc_state *context);
2830
#endif

drivers/gpu/drm/amd/display/dc/dml2/dml21/dml21_wrapper.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#include "dml21_translation_helper.h"
1313
#include "dml2_dc_resource_mgmt.h"
1414

15+
#define INVALID -1
16+
1517
static bool dml21_allocate_memory(struct dml2_context **dml_ctx)
1618
{
1719
*dml_ctx = vzalloc(sizeof(struct dml2_context));
@@ -208,10 +210,40 @@ static void dml21_calculate_rq_and_dlg_params(const struct dc *dc, struct dc_sta
208210
}
209211
}
210212

213+
static void dml21_prepare_mcache_params(struct dml2_context *dml_ctx, struct dc_state *context, struct dc_mcache_params *mcache_params)
214+
{
215+
int dc_plane_idx = 0;
216+
int dml_prog_idx, stream_idx, plane_idx;
217+
struct dml2_per_plane_programming *pln_prog = NULL;
218+
219+
for (stream_idx = 0; stream_idx < context->stream_count; stream_idx++) {
220+
for (plane_idx = 0; plane_idx < context->stream_status[stream_idx].plane_count; plane_idx++) {
221+
dml_prog_idx = map_plane_to_dml21_display_cfg(dml_ctx, context->streams[stream_idx]->stream_id, context->stream_status[stream_idx].plane_states[plane_idx], context);
222+
if (dml_prog_idx == INVALID) {
223+
continue;
224+
}
225+
pln_prog = &dml_ctx->v21.mode_programming.programming->plane_programming[dml_prog_idx];
226+
mcache_params[dc_plane_idx].valid = pln_prog->mcache_allocation.valid;
227+
mcache_params[dc_plane_idx].num_mcaches_plane0 = pln_prog->mcache_allocation.num_mcaches_plane0;
228+
mcache_params[dc_plane_idx].num_mcaches_plane1 = pln_prog->mcache_allocation.num_mcaches_plane1;
229+
mcache_params[dc_plane_idx].requires_dedicated_mall_mcache = pln_prog->mcache_allocation.requires_dedicated_mall_mcache;
230+
mcache_params[dc_plane_idx].last_slice_sharing.plane0_plane1 = pln_prog->mcache_allocation.last_slice_sharing.plane0_plane1;
231+
memcpy(mcache_params[dc_plane_idx].mcache_x_offsets_plane0,
232+
pln_prog->mcache_allocation.mcache_x_offsets_plane0,
233+
sizeof(int) * (DML2_MAX_MCACHES + 1));
234+
memcpy(mcache_params[dc_plane_idx].mcache_x_offsets_plane1,
235+
pln_prog->mcache_allocation.mcache_x_offsets_plane1,
236+
sizeof(int) * (DML2_MAX_MCACHES + 1));
237+
dc_plane_idx++;
238+
}
239+
}
240+
}
241+
211242
static bool dml21_mode_check_and_programming(const struct dc *in_dc, struct dc_state *context, struct dml2_context *dml_ctx)
212243
{
213244
bool result = false;
214245
struct dml2_build_mode_programming_in_out *mode_programming = &dml_ctx->v21.mode_programming;
246+
struct dc_mcache_params mcache_params[MAX_PLANES] = {0};
215247

216248
memset(&dml_ctx->v21.display_config, 0, sizeof(struct dml2_display_cfg));
217249
memset(&dml_ctx->v21.dml_to_dc_pipe_mapping, 0, sizeof(struct dml2_dml_to_dc_pipe_mapping));
@@ -246,6 +278,14 @@ static bool dml21_mode_check_and_programming(const struct dc *in_dc, struct dc_s
246278
dml2_map_dc_pipes(dml_ctx, context, NULL, &dml_ctx->v21.dml_to_dc_pipe_mapping, in_dc->current_state);
247279
/* if subvp phantoms are present, expand them into dc context */
248280
dml21_handle_phantom_streams_planes(in_dc, context, dml_ctx);
281+
282+
if (in_dc->res_pool->funcs->program_mcache_pipe_config) {
283+
//Prepare mcache params for each plane based on mcache output from DML
284+
dml21_prepare_mcache_params(dml_ctx, context, mcache_params);
285+
286+
//populate mcache regs to each pipe
287+
dml_ctx->config.callbacks.allocate_mcache(context, mcache_params);
288+
}
249289
}
250290

251291
/* Copy DML CLK, WM and REG outputs to bandwidth context */

drivers/gpu/drm/amd/display/dc/dml2/dml21/dml21_wrapper.h

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include "os_types.h"
1010
#include "dml_top_soc_parameter_types.h"
11+
#include "dml_top_display_cfg_types.h"
1112

1213
struct dc;
1314
struct dc_state;
@@ -65,4 +66,67 @@ struct socbb_ip_params_external {
6566
struct dml2_ip_capabilities ip_params;
6667
struct dml2_soc_bb soc_bb;
6768
};
69+
70+
/*mcache parameters decided by dml*/
71+
struct dc_mcache_params {
72+
bool valid;
73+
/*
74+
* For iMALL, dedicated mall mcaches are required (sharing of last
75+
* slice possible), for legacy phantom or phantom without return
76+
* the only mall mcaches need to be valid.
77+
*/
78+
bool requires_dedicated_mall_mcache;
79+
unsigned int num_mcaches_plane0;
80+
unsigned int num_mcaches_plane1;
81+
/*
82+
* Generally, plane0/1 slices must use a disjoint set of caches
83+
* but in some cases the final segement of the two planes can
84+
* use the same cache. If plane0_plane1 is set, then this is
85+
* allowed.
86+
*
87+
* Similarly, the caches allocated to MALL prefetcher are generally
88+
* disjoint, but if mall_prefetch is set, then the final segment
89+
* between the main and the mall pixel requestor can use the same
90+
* cache.
91+
*
92+
* Note that both bits may be set at the same time.
93+
*/
94+
struct {
95+
bool mall_comb_mcache_p0;
96+
bool mall_comb_mcache_p1;
97+
bool plane0_plane1;
98+
} last_slice_sharing;
99+
/*
100+
* A plane is divided into vertical slices of mcaches,
101+
* which wrap on the surface width.
102+
*
103+
* For example, if the surface width is 7680, and split into
104+
* three slices of equal width, the boundary array would contain
105+
* [2560, 5120, 7680]
106+
*
107+
* The assignments are
108+
* 0 = [0 .. 2559]
109+
* 1 = [2560 .. 5119]
110+
* 2 = [5120 .. 7679]
111+
* 0 = [7680 .. INF]
112+
* The final element implicitly is the same as the first, and
113+
* at first seems invalid since it is never referenced (since)
114+
* it is outside the surface. However, its useful when shifting
115+
* (see below).
116+
*
117+
* For any given valid mcache assignment, a shifted version, wrapped
118+
* on the surface width boundary is also assumed to be valid.
119+
*
120+
* For example, shifting [2560, 5120, 7680] by -50 results in
121+
* [2510, 5170, 7630].
122+
*
123+
* The assignments are now:
124+
* 0 = [0 .. 2509]
125+
* 1 = [2510 .. 5169]
126+
* 2 = [5170 .. 7629]
127+
* 0 = [7630 .. INF]
128+
*/
129+
int mcache_x_offsets_plane0[DML2_MAX_MCACHES + 1];
130+
int mcache_x_offsets_plane1[DML2_MAX_MCACHES + 1];
131+
};
68132
#endif

drivers/gpu/drm/amd/display/dc/dml2/dml2_wrapper.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ struct dc_sink;
4040
struct dc_stream_state;
4141
struct resource_context;
4242
struct display_stream_compressor;
43+
struct dc_mcache_params;
4344

4445
// Configuration of the MALL on the SoC
4546
struct dml2_soc_mall_info {
@@ -107,6 +108,7 @@ struct dml2_dc_callbacks {
107108
unsigned int (*get_max_flickerless_instant_vtotal_increase)(
108109
struct dc_stream_state *stream,
109110
bool is_gaming);
111+
bool (*allocate_mcache)(struct dc_state *context, const struct dc_mcache_params *mcache_params);
110112
};
111113

112114
struct dml2_dc_svp_callbacks {

drivers/gpu/drm/amd/display/dc/inc/core_types.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ struct resource_pool;
6565
struct dc_state;
6666
struct resource_context;
6767
struct clk_bw_params;
68+
struct dc_mcache_params;
6869

6970
struct resource_funcs {
7071
enum engine_id (*get_preferred_eng_id_dpia)(unsigned int dpia_index);
@@ -220,6 +221,8 @@ struct resource_funcs {
220221
unsigned int (*get_max_hw_cursor_size)(const struct dc *dc,
221222
struct dc_state *state,
222223
const struct dc_stream_state *stream);
224+
bool (*program_mcache_pipe_config)(struct dc_state *context,
225+
const struct dc_mcache_params *mcache_params);
223226
};
224227

225228
struct audio_support{

drivers/gpu/drm/amd/display/dc/inc/resource.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
#define MEMORY_TYPE_MULTIPLIER_CZ 4
3434
#define MEMORY_TYPE_HBM 2
35+
#define MAX_MCACHES 8
3536

3637

3738
#define IS_PIPE_SYNCD_VALID(pipe) ((((pipe)->pipe_idx_syncd) & 0x80)?1:0)
@@ -65,6 +66,13 @@ struct resource_straps {
6566
uint32_t audio_stream_number;
6667
};
6768

69+
struct dc_mcache_allocations {
70+
int global_mcache_ids_plane0[MAX_MCACHES + 1];
71+
int global_mcache_ids_plane1[MAX_MCACHES + 1];
72+
int global_mcache_ids_mall_plane0[MAX_MCACHES + 1];
73+
int global_mcache_ids_mall_plane1[MAX_MCACHES + 1];
74+
};
75+
6876
struct resource_create_funcs {
6977
void (*read_dce_straps)(
7078
struct dc_context *ctx, struct resource_straps *straps);

0 commit comments

Comments
 (0)