xref: /linux/drivers/gpu/drm/amd/display/dc/dml2_0/dml2_wrapper.c (revision 92c4c9fdc838d3b41a996bb700ea64b9e78fc7ea)
1 // SPDX-License-Identifier: MIT
2 /*
3  * Copyright 2025 Advanced Micro Devices, Inc.
4  *
5  * Authors: AMD
6  */
7 
8 #include "dml2_internal_types.h"
9 #include "dml2_wrapper.h"
10 #include "dml2_wrapper_fpu.h"
11 #include "dml21_wrapper.h"
12 #include "dml21_wrapper_fpu.h"
13 
14 #include "dc_fpu.h"
15 
16 #if !defined(DC_RUN_WITH_PREEMPTION_ENABLED)
17 #define DC_RUN_WITH_PREEMPTION_ENABLED(code) code
18 #endif // !DC_RUN_WITH_PREEMPTION_ENABLED
19 
dml2_allocate_memory(void)20 struct dml2_context *dml2_allocate_memory(void)
21 {
22 	struct dml2_context *dml2;
23 
24 	DC_RUN_WITH_PREEMPTION_ENABLED(dml2 = vzalloc(sizeof(struct dml2_context)));
25 	return dml2;
26 }
dml2_validate(const struct dc * in_dc,struct dc_state * context,struct dml2_context * dml2,enum dc_validate_mode validate_mode)27 bool dml2_validate(const struct dc *in_dc, struct dc_state *context, struct dml2_context *dml2,
28 	enum dc_validate_mode validate_mode)
29 {
30 	bool out = false;
31 
32 	if (!dml2)
33 		return false;
34 	dml2_apply_debug_options(in_dc, dml2);
35 
36 	/* DML2.1 validation path */
37 	if (dml2->architecture == dml2_architecture_21) {
38 		out = dml21_validate(in_dc, context, dml2, validate_mode);
39 		return out;
40 	}
41 
42 	/* Use dml_validate_only for DC_VALIDATE_MODE_ONLY and DC_VALIDATE_MODE_AND_STATE_INDEX path */
43 	if (validate_mode != DC_VALIDATE_MODE_AND_PROGRAMMING)
44 		out = dml2_validate_only(context, validate_mode);
45 	else
46 		out = dml2_validate_and_build_resource(in_dc, context, validate_mode);
47 
48 	return out;
49 }
50 
dml2_init(const struct dc * in_dc,const struct dml2_configuration_options * config,struct dml2_context ** dml2)51 static void dml2_init(const struct dc *in_dc, const struct dml2_configuration_options *config, struct dml2_context **dml2)
52 {
53 	if ((in_dc->debug.using_dml21) && (in_dc->ctx->dce_version >= DCN_VERSION_4_01)) {
54 		dml21_reinit(in_dc, *dml2, config);
55 		return;
56 	}
57 
58 	// Store config options
59 	(*dml2)->config = *config;
60 
61 	switch (in_dc->ctx->dce_version) {
62 	case DCN_VERSION_3_5:
63 		(*dml2)->v20.dml_core_ctx.project = dml_project_dcn35;
64 		break;
65 	case DCN_VERSION_3_51:
66 		(*dml2)->v20.dml_core_ctx.project = dml_project_dcn351;
67 		break;
68 	case DCN_VERSION_3_6:
69 		(*dml2)->v20.dml_core_ctx.project = dml_project_dcn36;
70 		break;
71 	case DCN_VERSION_3_2:
72 		(*dml2)->v20.dml_core_ctx.project = dml_project_dcn32;
73 		break;
74 	case DCN_VERSION_3_21:
75 		(*dml2)->v20.dml_core_ctx.project = dml_project_dcn321;
76 		break;
77 	case DCN_VERSION_4_01:
78 		(*dml2)->v20.dml_core_ctx.project = dml_project_dcn401;
79 		break;
80 	default:
81 		(*dml2)->v20.dml_core_ctx.project = dml_project_default;
82 		break;
83 	}
84 
85 	initialize_dml2_ip_params(*dml2, in_dc, &(*dml2)->v20.dml_core_ctx.ip);
86 
87 	initialize_dml2_soc_bbox(*dml2, in_dc, &(*dml2)->v20.dml_core_ctx.soc);
88 
89 	initialize_dml2_soc_states(*dml2, in_dc, &(*dml2)->v20.dml_core_ctx.soc, &(*dml2)->v20.dml_core_ctx.states);
90 
91 }
92 
dml2_create(const struct dc * in_dc,const struct dml2_configuration_options * config,struct dml2_context ** dml2)93 bool dml2_create(const struct dc *in_dc, const struct dml2_configuration_options *config, struct dml2_context **dml2)
94 {
95 	// TODO : Temporarily add DCN_VERSION_3_2 for N-1 validation. Remove DCN_VERSION_3_2 after N-1 validation phase is complete.
96 	if ((in_dc->debug.using_dml21) && (in_dc->ctx->dce_version >= DCN_VERSION_4_01)) {
97 		return dml21_create(in_dc, dml2, config);
98 	}
99 
100 	// Allocate Mode Lib Ctx
101 	*dml2 = dml2_allocate_memory();
102 
103 	if (!(*dml2))
104 		return false;
105 
106 	dml2_init(in_dc, config, dml2);
107 
108 	return true;
109 }
110 
dml2_destroy(struct dml2_context * dml2)111 void dml2_destroy(struct dml2_context *dml2)
112 {
113 	if (!dml2)
114 		return;
115 
116 	if (dml2->architecture == dml2_architecture_21)
117 		dml21_destroy(dml2);
118 
119 	DC_RUN_WITH_PREEMPTION_ENABLED(vfree(dml2));
120 }
121 
dml2_reinit(const struct dc * in_dc,const struct dml2_configuration_options * config,struct dml2_context ** dml2)122 void dml2_reinit(const struct dc *in_dc,
123 				 const struct dml2_configuration_options *config,
124 				 struct dml2_context **dml2)
125 {
126 	if ((in_dc->debug.using_dml21) && (in_dc->ctx->dce_version >= DCN_VERSION_4_01)) {
127 		dml21_reinit(in_dc, *dml2, config);
128 		return;
129 	}
130 
131 	dml2_init(in_dc, config, dml2);
132 }
133