Skip to content

Commit 1327d8f

Browse files
Lijo Lazaralexdeucher
authored andcommitted
drm/amd/pm: Use macro to initialize metrics table
Helps to keep a build time check about usage of right datatype and avoids maintenance as new versions get added. Signed-off-by: Lijo Lazar <[email protected]> Reviewed-by: Hawking Zhang <[email protected]> Reviewed-by: Yang Wang <[email protected]> Reviewed-by: Asad Kamal <[email protected]> Signed-off-by: Alex Deucher <[email protected]>
1 parent 2ed4fd9 commit 1327d8f

File tree

2 files changed

+12
-69
lines changed

2 files changed

+12
-69
lines changed

drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,73 +1051,6 @@ int smu_cmn_get_combo_pptable(struct smu_context *smu)
10511051
false);
10521052
}
10531053

1054-
void smu_cmn_init_soft_gpu_metrics(void *table, uint8_t frev, uint8_t crev)
1055-
{
1056-
struct metrics_table_header *header = (struct metrics_table_header *)table;
1057-
uint16_t structure_size;
1058-
1059-
#define METRICS_VERSION(a, b) ((a << 16) | b)
1060-
1061-
switch (METRICS_VERSION(frev, crev)) {
1062-
case METRICS_VERSION(1, 0):
1063-
structure_size = sizeof(struct gpu_metrics_v1_0);
1064-
break;
1065-
case METRICS_VERSION(1, 1):
1066-
structure_size = sizeof(struct gpu_metrics_v1_1);
1067-
break;
1068-
case METRICS_VERSION(1, 2):
1069-
structure_size = sizeof(struct gpu_metrics_v1_2);
1070-
break;
1071-
case METRICS_VERSION(1, 3):
1072-
structure_size = sizeof(struct gpu_metrics_v1_3);
1073-
break;
1074-
case METRICS_VERSION(1, 4):
1075-
structure_size = sizeof(struct gpu_metrics_v1_4);
1076-
break;
1077-
case METRICS_VERSION(1, 5):
1078-
structure_size = sizeof(struct gpu_metrics_v1_5);
1079-
break;
1080-
case METRICS_VERSION(1, 6):
1081-
structure_size = sizeof(struct gpu_metrics_v1_6);
1082-
break;
1083-
case METRICS_VERSION(1, 7):
1084-
structure_size = sizeof(struct gpu_metrics_v1_7);
1085-
break;
1086-
case METRICS_VERSION(1, 8):
1087-
structure_size = sizeof(struct gpu_metrics_v1_8);
1088-
break;
1089-
case METRICS_VERSION(2, 0):
1090-
structure_size = sizeof(struct gpu_metrics_v2_0);
1091-
break;
1092-
case METRICS_VERSION(2, 1):
1093-
structure_size = sizeof(struct gpu_metrics_v2_1);
1094-
break;
1095-
case METRICS_VERSION(2, 2):
1096-
structure_size = sizeof(struct gpu_metrics_v2_2);
1097-
break;
1098-
case METRICS_VERSION(2, 3):
1099-
structure_size = sizeof(struct gpu_metrics_v2_3);
1100-
break;
1101-
case METRICS_VERSION(2, 4):
1102-
structure_size = sizeof(struct gpu_metrics_v2_4);
1103-
break;
1104-
case METRICS_VERSION(3, 0):
1105-
structure_size = sizeof(struct gpu_metrics_v3_0);
1106-
break;
1107-
default:
1108-
return;
1109-
}
1110-
1111-
#undef METRICS_VERSION
1112-
1113-
memset(header, 0xFF, structure_size);
1114-
1115-
header->format_revision = frev;
1116-
header->content_revision = crev;
1117-
header->structure_size = structure_size;
1118-
1119-
}
1120-
11211054
int smu_cmn_set_mp1_state(struct smu_context *smu,
11221055
enum pp_mp1_state mp1_state)
11231056
{

drivers/gpu/drm/amd/pm/swsmu/smu_cmn.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,18 @@
4040
#define SMU_IH_INTERRUPT_CONTEXT_ID_FAN_ABNORMAL 0x8
4141
#define SMU_IH_INTERRUPT_CONTEXT_ID_FAN_RECOVERY 0x9
4242

43+
#define smu_cmn_init_soft_gpu_metrics(ptr, frev, crev) \
44+
do { \
45+
typecheck(struct gpu_metrics_v##frev##_##crev, \
46+
typeof(*(ptr))); \
47+
struct metrics_table_header *header = \
48+
(struct metrics_table_header *)(ptr); \
49+
memset(header, 0xFF, sizeof(*(ptr))); \
50+
header->format_revision = frev; \
51+
header->content_revision = crev; \
52+
header->structure_size = sizeof(*(ptr)); \
53+
} while (0)
54+
4355
extern const int link_speed[];
4456

4557
/* Helper to Convert from PCIE Gen 1/2/3/4/5/6 to 0.1 GT/s speed units */
@@ -125,8 +137,6 @@ int smu_cmn_get_metrics_table(struct smu_context *smu,
125137

126138
int smu_cmn_get_combo_pptable(struct smu_context *smu);
127139

128-
void smu_cmn_init_soft_gpu_metrics(void *table, uint8_t frev, uint8_t crev);
129-
130140
int smu_cmn_set_mp1_state(struct smu_context *smu,
131141
enum pp_mp1_state mp1_state);
132142

0 commit comments

Comments
 (0)