Skip to content

Commit 278ff70

Browse files
Shyam Sundar S Kij-intel
authored andcommitted
platform/x86/amd/pmf: Refactor repetitive BIOS output handling
Replace repetitive switch-case statements for PMF_POLICY_BIOS_OUTPUT_* with a helper function and consolidated case handling. This reduces code duplication and improves maintainability. The 10 BIOS output policies (PMF_POLICY_BIOS_OUTPUT_1 through PMF_POLICY_BIOS_OUTPUT_10) previously each had individual case statements with identical logic. This patch introduces amd_pmf_get_bios_output_idx() to map policy values to array indices, consolidating the handling into a single case block with fallthrough. Also, add a new function amd_pmf_update_bios_output() to simplify the code handling. This approach handles non-sequential policy enum values gracefully and makes future additions easier to implement. No functional changes. Signed-off-by: Shyam Sundar S K <Shyam-sundar.S-k@amd.com> Link: https://patch.msgid.link/20251127091038.2088387-1-Shyam-sundar.S-k@amd.com Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com> Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
1 parent 5c14bff commit 278ff70

1 file changed

Lines changed: 42 additions & 30 deletions

File tree

drivers/platform/x86/amd/pmf/tee-if.c

Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,53 @@ static void amd_pmf_update_uevents(struct amd_pmf_dev *dev, u16 event)
7373
input_sync(dev->pmf_idev);
7474
}
7575

76+
static int amd_pmf_get_bios_output_idx(u32 action_idx)
77+
{
78+
switch (action_idx) {
79+
case PMF_POLICY_BIOS_OUTPUT_1:
80+
return 0;
81+
case PMF_POLICY_BIOS_OUTPUT_2:
82+
return 1;
83+
case PMF_POLICY_BIOS_OUTPUT_3:
84+
return 2;
85+
case PMF_POLICY_BIOS_OUTPUT_4:
86+
return 3;
87+
case PMF_POLICY_BIOS_OUTPUT_5:
88+
return 4;
89+
case PMF_POLICY_BIOS_OUTPUT_6:
90+
return 5;
91+
case PMF_POLICY_BIOS_OUTPUT_7:
92+
return 6;
93+
case PMF_POLICY_BIOS_OUTPUT_8:
94+
return 7;
95+
case PMF_POLICY_BIOS_OUTPUT_9:
96+
return 8;
97+
case PMF_POLICY_BIOS_OUTPUT_10:
98+
return 9;
99+
default:
100+
return -EINVAL;
101+
}
102+
}
103+
104+
static void amd_pmf_update_bios_output(struct amd_pmf_dev *pdev, struct ta_pmf_action *action)
105+
{
106+
u32 bios_idx;
107+
108+
bios_idx = amd_pmf_get_bios_output_idx(action->action_index);
109+
110+
amd_pmf_smartpc_apply_bios_output(pdev, action->value, BIT(bios_idx), bios_idx);
111+
}
112+
76113
static void amd_pmf_apply_policies(struct amd_pmf_dev *dev, struct ta_pmf_enact_result *out)
77114
{
115+
struct ta_pmf_action *action;
78116
u32 val;
79117
int idx;
80118

81119
for (idx = 0; idx < out->actions_count; idx++) {
82-
val = out->actions_list[idx].value;
83-
switch (out->actions_list[idx].action_index) {
120+
action = &out->actions_list[idx];
121+
val = action->value;
122+
switch (action->action_index) {
84123
case PMF_POLICY_SPL:
85124
if (dev->prev_data->spl != val) {
86125
amd_pmf_send_cmd(dev, SET_SPL, SET_CMD, val, NULL);
@@ -183,43 +222,16 @@ static void amd_pmf_apply_policies(struct amd_pmf_dev *dev, struct ta_pmf_enact_
183222
break;
184223

185224
case PMF_POLICY_BIOS_OUTPUT_1:
186-
amd_pmf_smartpc_apply_bios_output(dev, val, BIT(0), 0);
187-
break;
188-
189225
case PMF_POLICY_BIOS_OUTPUT_2:
190-
amd_pmf_smartpc_apply_bios_output(dev, val, BIT(1), 1);
191-
break;
192-
193226
case PMF_POLICY_BIOS_OUTPUT_3:
194-
amd_pmf_smartpc_apply_bios_output(dev, val, BIT(2), 2);
195-
break;
196-
197227
case PMF_POLICY_BIOS_OUTPUT_4:
198-
amd_pmf_smartpc_apply_bios_output(dev, val, BIT(3), 3);
199-
break;
200-
201228
case PMF_POLICY_BIOS_OUTPUT_5:
202-
amd_pmf_smartpc_apply_bios_output(dev, val, BIT(4), 4);
203-
break;
204-
205229
case PMF_POLICY_BIOS_OUTPUT_6:
206-
amd_pmf_smartpc_apply_bios_output(dev, val, BIT(5), 5);
207-
break;
208-
209230
case PMF_POLICY_BIOS_OUTPUT_7:
210-
amd_pmf_smartpc_apply_bios_output(dev, val, BIT(6), 6);
211-
break;
212-
213231
case PMF_POLICY_BIOS_OUTPUT_8:
214-
amd_pmf_smartpc_apply_bios_output(dev, val, BIT(7), 7);
215-
break;
216-
217232
case PMF_POLICY_BIOS_OUTPUT_9:
218-
amd_pmf_smartpc_apply_bios_output(dev, val, BIT(8), 8);
219-
break;
220-
221233
case PMF_POLICY_BIOS_OUTPUT_10:
222-
amd_pmf_smartpc_apply_bios_output(dev, val, BIT(9), 9);
234+
amd_pmf_update_bios_output(dev, action);
223235
break;
224236
}
225237
}

0 commit comments

Comments
 (0)