xref: /linux/drivers/gpu/drm/amd/display/dc/dml2_0/dml2_wrapper.c (revision c17ee635fd3a482b2ad2bf5e269755c2eae5f25e)
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_fpu.h"
10 
11 bool dml2_validate(const struct dc *in_dc, struct dc_state *context, struct dml2_context *dml2,
12 	enum dc_validate_mode validate_mode)
13 {
14 	bool out = false;
15 
16 	if (!dml2)
17 		return false;
18 	dml2_apply_debug_options(in_dc, dml2);
19 
20 	/* DML2.1 validation path */
21 	if (dml2->architecture == dml2_architecture_21) {
22 		out = dml21_validate(in_dc, context, dml2, validate_mode);
23 		return out;
24 	}
25 
26 	DC_FP_START();
27 
28 	/* Use dml_validate_only for DC_VALIDATE_MODE_ONLY and DC_VALIDATE_MODE_AND_STATE_INDEX path */
29 	if (validate_mode != DC_VALIDATE_MODE_AND_PROGRAMMING)
30 		out = dml2_validate_only(context, validate_mode);
31 	else
32 		out = dml2_validate_and_build_resource(in_dc, context, validate_mode);
33 
34 	DC_FP_END();
35 
36 	return out;
37 }
38 
39 static void dml2_init(const struct dc *in_dc, const struct dml2_configuration_options *config, struct dml2_context **dml2)
40 {
41 	if ((in_dc->debug.using_dml21) && (in_dc->ctx->dce_version >= DCN_VERSION_4_01)) {
42 		dml21_reinit(in_dc, *dml2, config);
43 		return;
44 	}
45 
46 	// Store config options
47 	(*dml2)->config = *config;
48 
49 	switch (in_dc->ctx->dce_version) {
50 	case DCN_VERSION_3_5:
51 		(*dml2)->v20.dml_core_ctx.project = dml_project_dcn35;
52 		break;
53 	case DCN_VERSION_3_51:
54 		(*dml2)->v20.dml_core_ctx.project = dml_project_dcn351;
55 		break;
56 	case DCN_VERSION_3_6:
57 		(*dml2)->v20.dml_core_ctx.project = dml_project_dcn36;
58 		break;
59 	case DCN_VERSION_3_2:
60 		(*dml2)->v20.dml_core_ctx.project = dml_project_dcn32;
61 		break;
62 	case DCN_VERSION_3_21:
63 		(*dml2)->v20.dml_core_ctx.project = dml_project_dcn321;
64 		break;
65 	case DCN_VERSION_4_01:
66 		(*dml2)->v20.dml_core_ctx.project = dml_project_dcn401;
67 		break;
68 	default:
69 		(*dml2)->v20.dml_core_ctx.project = dml_project_default;
70 		break;
71 	}
72 
73 	DC_FP_START();
74 
75 	initialize_dml2_ip_params(*dml2, in_dc, &(*dml2)->v20.dml_core_ctx.ip);
76 
77 	initialize_dml2_soc_bbox(*dml2, in_dc, &(*dml2)->v20.dml_core_ctx.soc);
78 
79 	initialize_dml2_soc_states(*dml2, in_dc, &(*dml2)->v20.dml_core_ctx.soc, &(*dml2)->v20.dml_core_ctx.states);
80 
81 	DC_FP_END();
82 }
83 
84 bool dml2_create(const struct dc *in_dc, const struct dml2_configuration_options *config, struct dml2_context **dml2)
85 {
86 	// TODO : Temporarily add DCN_VERSION_3_2 for N-1 validation. Remove DCN_VERSION_3_2 after N-1 validation phase is complete.
87 	if ((in_dc->debug.using_dml21) && (in_dc->ctx->dce_version >= DCN_VERSION_4_01))
88 		return dml21_create(in_dc, dml2, config);
89 
90 	// Allocate Mode Lib Ctx
91 	*dml2 = dml2_allocate_memory();
92 
93 	if (!(*dml2))
94 		return false;
95 
96 	dml2_init(in_dc, config, dml2);
97 
98 	return true;
99 }
100 
101 void dml2_reinit(const struct dc *in_dc,
102 				 const struct dml2_configuration_options *config,
103 				 struct dml2_context **dml2)
104 {
105 	if ((in_dc->debug.using_dml21) && (in_dc->ctx->dce_version >= DCN_VERSION_4_01)) {
106 		dml21_reinit(in_dc, *dml2, config);
107 		return;
108 	}
109 
110 	dml2_init(in_dc, config, dml2);
111 }
112