Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Shyam Sundar S K and committed by
Ilpo Järvinen
278ff704 5c14bff5

+42 -30
+42 -30
drivers/platform/x86/amd/pmf/tee-if.c
··· 73 73 input_sync(dev->pmf_idev); 74 74 } 75 75 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 + 76 113 static void amd_pmf_apply_policies(struct amd_pmf_dev *dev, struct ta_pmf_enact_result *out) 77 114 { 115 + struct ta_pmf_action *action; 78 116 u32 val; 79 117 int idx; 80 118 81 119 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) { 84 123 case PMF_POLICY_SPL: 85 124 if (dev->prev_data->spl != val) { 86 125 amd_pmf_send_cmd(dev, SET_SPL, SET_CMD, val, NULL); ··· 222 183 break; 223 184 224 185 case PMF_POLICY_BIOS_OUTPUT_1: 225 - amd_pmf_smartpc_apply_bios_output(dev, val, BIT(0), 0); 226 - break; 227 - 228 186 case PMF_POLICY_BIOS_OUTPUT_2: 229 - amd_pmf_smartpc_apply_bios_output(dev, val, BIT(1), 1); 230 - break; 231 - 232 187 case PMF_POLICY_BIOS_OUTPUT_3: 233 - amd_pmf_smartpc_apply_bios_output(dev, val, BIT(2), 2); 234 - break; 235 - 236 188 case PMF_POLICY_BIOS_OUTPUT_4: 237 - amd_pmf_smartpc_apply_bios_output(dev, val, BIT(3), 3); 238 - break; 239 - 240 189 case PMF_POLICY_BIOS_OUTPUT_5: 241 - amd_pmf_smartpc_apply_bios_output(dev, val, BIT(4), 4); 242 - break; 243 - 244 190 case PMF_POLICY_BIOS_OUTPUT_6: 245 - amd_pmf_smartpc_apply_bios_output(dev, val, BIT(5), 5); 246 - break; 247 - 248 191 case PMF_POLICY_BIOS_OUTPUT_7: 249 - amd_pmf_smartpc_apply_bios_output(dev, val, BIT(6), 6); 250 - break; 251 - 252 192 case PMF_POLICY_BIOS_OUTPUT_8: 253 - amd_pmf_smartpc_apply_bios_output(dev, val, BIT(7), 7); 254 - break; 255 - 256 193 case PMF_POLICY_BIOS_OUTPUT_9: 257 - amd_pmf_smartpc_apply_bios_output(dev, val, BIT(8), 8); 258 - break; 259 - 260 194 case PMF_POLICY_BIOS_OUTPUT_10: 261 - amd_pmf_smartpc_apply_bios_output(dev, val, BIT(9), 9); 195 + amd_pmf_update_bios_output(dev, action); 262 196 break; 263 197 } 264 198 }