Skip to contentSkip to conversation

drm/amd/powerplay: using fixed vram address for table transferring

PATCH In review Evan Quan 2 participants 5 messages Dec 30, 2019 – Dec 31, 2019

Subsystems (2)
lore
Share & tools
lore

Evan Quan

author
#0 lore raw

PATCH 1/2 drm/amd/powerplay: using fixed vram address for table transferring

By this, we can avoid to pass in the vram address on every table transferring.

Change-Id Ia8a3dbe923bc562286ab102a5830392a95dcf28c
---
 drivers/gpu/drm/amd/powerplay/amdgpu_smu.c    | 42 ++++++++++++-------
 drivers/gpu/drm/amd/powerplay/arcturus_ppt.c  |  1 +
 .../gpu/drm/amd/powerplay/inc/amdgpu_smu.h    |  2 +
 drivers/gpu/drm/amd/powerplay/inc/smu_v11_0.h |  2 +
 drivers/gpu/drm/amd/powerplay/inc/smu_v12_0.h |  2 +
 drivers/gpu/drm/amd/powerplay/navi10_ppt.c    |  1 +
 drivers/gpu/drm/amd/powerplay/renoir_ppt.c    |  1 +
 drivers/gpu/drm/amd/powerplay/smu_internal.h  |  2 +
 drivers/gpu/drm/amd/powerplay/smu_v11_0.c     | 18 ++++++++
 drivers/gpu/drm/amd/powerplay/smu_v12_0.c     | 18 ++++++++
 drivers/gpu/drm/amd/powerplay/vega20_ppt.c    |  1 +
 11 files changed, 76 insertions(+), 14 deletions(-)
drivers/gpu/drm/amd/powerplay/amdgpu_smu.c +28 -14
index 4a7fb6b15635..c3cb1b8f43b5 100644
@@ -490,26 +490,19 @@ int smu_update_table(struct smu_context *smu, enum smu_table_id table_index, int
 {
 	struct smu_table_context *smu_table = &smu->smu_table;
 	struct amdgpu_device *adev = smu->adev;
-	struct smu_table *table = NULL;
-	int ret = 0;
+	struct smu_table *table = smu_table->driver_table;
 	int table_id = smu_table_get_index(smu, table_index);
+	uint32_t table_size;
+	int ret = 0;
 
 	if (!table_data || table_id >= SMU_TABLE_COUNT || table_id < 0)
 		return -EINVAL;
 
-	table = &smu_table->tables[table_index];
+	table_size = smu_table->tables[table_index].size;
 
 	if (drv2smu)
-		memcpy(table->cpu_addr, table_data, table->size);
+		memcpy(table->cpu_addr, table_data, table_size);
 
-	ret = smu_send_smc_msg_with_param(smu, SMU_MSG_SetDriverDramAddrHigh,
-					  upper_32_bits(table->mc_address));
-	if (ret)
-		return ret;
-	ret = smu_send_smc_msg_with_param(smu, SMU_MSG_SetDriverDramAddrLow,
-					  lower_32_bits(table->mc_address));
-	if (ret)
-		return ret;
 	ret = smu_send_smc_msg_with_param(smu, drv2smu ?
 					  SMU_MSG_TransferTableDram2Smu :
 					  SMU_MSG_TransferTableSmu2Dram,
@@ -521,7 +514,7 @@ int smu_update_table(struct smu_context *smu, enum smu_table_id table_index, int
 	adev->nbio.funcs->hdp_flush(adev, NULL);
 
 	if (!drv2smu)
-		memcpy(table_data, table->cpu_addr, table->size);
+		memcpy(table_data, table->cpu_addr, table_size);
 
 	return ret;
 }
@@ -948,7 +941,9 @@ static int smu_init_fb_allocations(struct smu_context *smu)
 	struct amdgpu_device *adev = smu->adev;
 	struct smu_table_context *smu_table = &smu->smu_table;
 	struct smu_table *tables = smu_table->tables;
-	int ret, i;
+	struct smu_table **driver_table = &(smu_table->driver_table);
+	uint32_t max_table_size = 0;
+	int ret, i, index = 0;
 
 	for (i = 0; i < SMU_TABLE_COUNT; i++) {
 		if (tables[i].size == 0)
@@ -964,6 +959,21 @@ static int smu_init_fb_allocations(struct smu_context *smu)
 			goto failed;
 	}
 
+	for (i = 0; i < SMU_TABLE_COUNT; i++) {
+		if (tables[i].size == 0)
+			continue;
+
+		if (i == SMU_TABLE_PMSTATUSLOG)
+			continue;
+
+		if (max_table_size < tables[i].size) {
+			max_table_size = tables[i].size;
+			index = i;
+		}
+	}
+
+	*driver_table = &tables[index];
+
 	return 0;
 failed:
 	while (--i >= 0) {
@@ -1063,6 +1073,10 @@ static int smu_smc_table_hw_init(struct smu_context *smu,
 
 	/* smu_dump_pptable(smu); */
 
+	ret = smu_set_driver_table_location(smu);
+	if (ret)
+		return ret;
+
 	/*
 	 * Copy pptable bo in the vram to smc with SMU MSGs such as
 	 * SetDriverDramAddr and TransferTableDram2Smu.
drivers/gpu/drm/amd/powerplay/arcturus_ppt.c +1 -0
index 50b317f4b1e6..e89965e5fdcb 100644
@@ -2261,6 +2261,7 @@ static const struct pptable_funcs arcturus_ppt_funcs = {
 	.check_fw_version = smu_v11_0_check_fw_version,
 	.write_pptable = smu_v11_0_write_pptable,
 	.set_min_dcef_deep_sleep = smu_v11_0_set_min_dcef_deep_sleep,
+	.set_driver_table_location = smu_v11_0_set_driver_table_location,
 	.set_tool_table_location = smu_v11_0_set_tool_table_location,
 	.notify_memory_pool_location = smu_v11_0_notify_memory_pool_location,
 	.system_features_control = smu_v11_0_system_features_control,
drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h +2 -0
index 541cfde289ea..ed193adc881c 100644
@@ -259,6 +259,7 @@ struct smu_table_context
 	struct smu_bios_boot_up_values	boot_values;
 	void                            *driver_pptable;
 	struct smu_table		*tables;
+	struct smu_table		*driver_table;
 	struct smu_table		memory_pool;
 	uint8_t                         thermal_controller_type;
 
@@ -497,6 +498,7 @@ struct pptable_funcs {
 	int (*set_gfx_cgpg)(struct smu_context *smu, bool enable);
 	int (*write_pptable)(struct smu_context *smu);
 	int (*set_min_dcef_deep_sleep)(struct smu_context *smu);
+	int (*set_driver_table_location)(struct smu_context *smu);
 	int (*set_tool_table_location)(struct smu_context *smu);
 	int (*notify_memory_pool_location)(struct smu_context *smu);
 	int (*set_last_dcef_min_deep_sleep_clk)(struct smu_context *smu);
drivers/gpu/drm/amd/powerplay/inc/smu_v11_0.h +2 -0
index db3f78676aeb..662989296174 100644
@@ -170,6 +170,8 @@ int smu_v11_0_write_pptable(struct smu_context *smu);
 
 int smu_v11_0_set_min_dcef_deep_sleep(struct smu_context *smu);
 
+int smu_v11_0_set_driver_table_location(struct smu_context *smu);
+
 int smu_v11_0_set_tool_table_location(struct smu_context *smu);
 
 int smu_v11_0_notify_memory_pool_location(struct smu_context *smu);
drivers/gpu/drm/amd/powerplay/inc/smu_v12_0.h +2 -0
index 3f1cd06e273c..d79e54b5ebf6 100644
@@ -90,4 +90,6 @@ int smu_v12_0_mode2_reset(struct smu_context *smu);
 int smu_v12_0_set_soft_freq_limited_range(struct smu_context *smu, enum smu_clk_type clk_type,
 			    uint32_t min, uint32_t max);
 
+int smu_v12_0_set_driver_table_location(struct smu_context *smu);
+
 #endif
drivers/gpu/drm/amd/powerplay/navi10_ppt.c +1 -0
index e7ab8caee222..ed147dd51325 100644
@@ -2116,6 +2116,7 @@ static const struct pptable_funcs navi10_ppt_funcs = {
 	.check_fw_version = smu_v11_0_check_fw_version,
 	.write_pptable = smu_v11_0_write_pptable,
 	.set_min_dcef_deep_sleep = smu_v11_0_set_min_dcef_deep_sleep,
+	.set_driver_table_location = smu_v11_0_set_driver_table_location,
 	.set_tool_table_location = smu_v11_0_set_tool_table_location,
 	.notify_memory_pool_location = smu_v11_0_notify_memory_pool_location,
 	.system_features_control = smu_v11_0_system_features_control,
drivers/gpu/drm/amd/powerplay/renoir_ppt.c +1 -0
index e73644beffd9..c4b5984c86d9 100644
@@ -916,6 +916,7 @@ static const struct pptable_funcs renoir_ppt_funcs = {
 	.get_dpm_ultimate_freq = smu_v12_0_get_dpm_ultimate_freq,
 	.mode2_reset = smu_v12_0_mode2_reset,
 	.set_soft_freq_limited_range = smu_v12_0_set_soft_freq_limited_range,
+	.set_driver_table_location = smu_v12_0_set_driver_table_location,
 };
 
 void renoir_set_ppt_funcs(struct smu_context *smu)
drivers/gpu/drm/amd/powerplay/smu_internal.h +2 -0
index 77864e4236c4..783319ec8bf9 100644
@@ -61,6 +61,8 @@
 	((smu)->ppt_funcs->write_pptable ? (smu)->ppt_funcs->write_pptable((smu)) : 0)
 #define smu_set_min_dcef_deep_sleep(smu) \
 	((smu)->ppt_funcs->set_min_dcef_deep_sleep ? (smu)->ppt_funcs->set_min_dcef_deep_sleep((smu)) : 0)
+#define smu_set_driver_table_location(smu) \
+	((smu)->ppt_funcs->set_driver_table_location ? (smu)->ppt_funcs->set_driver_table_location((smu)) : 0)
 #define smu_set_tool_table_location(smu) \
 	((smu)->ppt_funcs->set_tool_table_location ? (smu)->ppt_funcs->set_tool_table_location((smu)) : 0)
 #define smu_notify_memory_pool_location(smu) \
drivers/gpu/drm/amd/powerplay/smu_v11_0.c +18 -0
index 73935cf7ff39..79a63edcd7ba 100644
@@ -774,6 +774,24 @@ int smu_v11_0_set_min_dcef_deep_sleep(struct smu_context *smu)
 	return smu_v11_0_set_deep_sleep_dcefclk(smu, table_context->boot_values.dcefclk / 100);
 }
 
+int smu_v11_0_set_driver_table_location(struct smu_context *smu)
+{
+	struct smu_table *driver_table = smu->smu_table.driver_table;
+	int ret = 0;
+
+	if (driver_table->mc_address) {
+		ret = smu_send_smc_msg_with_param(smu,
+				SMU_MSG_SetDriverDramAddrHigh,
+				upper_32_bits(driver_table->mc_address));
+		if (!ret)
+			ret = smu_send_smc_msg_with_param(smu,
+				SMU_MSG_SetDriverDramAddrLow,
+				lower_32_bits(driver_table->mc_address));
+	}
+
+	return ret;
+}
+
 int smu_v11_0_set_tool_table_location(struct smu_context *smu)
 {
 	int ret = 0;
drivers/gpu/drm/amd/powerplay/smu_v12_0.c +18 -0
index 2ac7f2f231b6..cd2be9fb2513 100644
@@ -514,3 +514,21 @@ int smu_v12_0_set_soft_freq_limited_range(struct smu_context *smu, enum smu_clk_
 
 	return ret;
 }
+
+int smu_v12_0_set_driver_table_location(struct smu_context *smu)
+{
+	struct smu_table *driver_table = smu->smu_table.driver_table;
+	int ret = 0;
+
+	if (driver_table->mc_address) {
+		ret = smu_send_smc_msg_with_param(smu,
+				SMU_MSG_SetDriverDramAddrHigh,
+				upper_32_bits(driver_table->mc_address));
+		if (!ret)
+			ret = smu_send_smc_msg_with_param(smu,
+				SMU_MSG_SetDriverDramAddrLow,
+				lower_32_bits(driver_table->mc_address));
+	}
+
+	return ret;
+}
drivers/gpu/drm/amd/powerplay/vega20_ppt.c +1 -0
index 534c46bc0146..12f97956058b 100644
@@ -3232,6 +3232,7 @@ static const struct pptable_funcs vega20_ppt_funcs = {
 	.check_fw_version = smu_v11_0_check_fw_version,
 	.write_pptable = smu_v11_0_write_pptable,
 	.set_min_dcef_deep_sleep = smu_v11_0_set_min_dcef_deep_sleep,
+	.set_driver_table_location = smu_v11_0_set_driver_table_location,
 	.set_tool_table_location = smu_v11_0_set_tool_table_location,
 	.notify_memory_pool_location = smu_v11_0_notify_memory_pool_location,
 	.system_features_control = smu_v11_0_system_features_control,
Signature · 6 lines
2.24.0

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
author
#1 lore raw

PATCH 2/2 drm/amd/powerplay: allocate one piece of VRAM for all tables transferring

Simplify the table transferring between driver and SMU and use less VRAM.

Change-Id I3f9b54fd9b8c0bcaeb533fc1a07bb06050fefbd8
---
 drivers/gpu/drm/amd/powerplay/amdgpu_smu.c    | 101 ++++++++++--------
 drivers/gpu/drm/amd/powerplay/arcturus_ppt.c  |   2 +-
 .../gpu/drm/amd/powerplay/inc/amdgpu_smu.h    |   3 +-
 drivers/gpu/drm/amd/powerplay/navi10_ppt.c    |   4 +
 drivers/gpu/drm/amd/powerplay/renoir_ppt.c    |   4 +
 drivers/gpu/drm/amd/powerplay/smu_v11_0.c     |   4 +-
 drivers/gpu/drm/amd/powerplay/smu_v12_0.c     |  10 +-
 drivers/gpu/drm/amd/powerplay/vega20_ppt.c    |   4 +
 8 files changed, 73 insertions(+), 59 deletions(-)
drivers/gpu/drm/amd/powerplay/amdgpu_smu.c +54 -47
index c3cb1b8f43b5..bd3dbd1a0ad3 100644
@@ -490,7 +490,7 @@ int smu_update_table(struct smu_context *smu, enum smu_table_id table_index, int
 {
 	struct smu_table_context *smu_table = &smu->smu_table;
 	struct amdgpu_device *adev = smu->adev;
-	struct smu_table *table = smu_table->driver_table;
+	struct smu_table *table = &smu_table->driver_table;
 	int table_id = smu_table_get_index(smu, table_index);
 	uint32_t table_size;
 	int ret = 0;
@@ -941,24 +941,26 @@ static int smu_init_fb_allocations(struct smu_context *smu)
 	struct amdgpu_device *adev = smu->adev;
 	struct smu_table_context *smu_table = &smu->smu_table;
 	struct smu_table *tables = smu_table->tables;
-	struct smu_table **driver_table = &(smu_table->driver_table);
+	struct smu_table *driver_table = &(smu_table->driver_table);
 	uint32_t max_table_size = 0;
-	int ret, i, index = 0;
+	int ret, i;
 
-	for (i = 0; i < SMU_TABLE_COUNT; i++) {
-		if (tables[i].size == 0)
-			continue;
+	/* VRAM allocation for tool table */
+	if (tables[SMU_TABLE_PMSTATUSLOG].size) {
 		ret = amdgpu_bo_create_kernel(adev,
-					      tables[i].size,
-					      tables[i].align,
-					      tables[i].domain,
-					      &tables[i].bo,
-					      &tables[i].mc_address,
-					      &tables[i].cpu_addr);
-		if (ret)
-			goto failed;
+					      tables[SMU_TABLE_PMSTATUSLOG].size,
+					      tables[SMU_TABLE_PMSTATUSLOG].align,
+					      tables[SMU_TABLE_PMSTATUSLOG].domain,
+					      &tables[SMU_TABLE_PMSTATUSLOG].bo,
+					      &tables[SMU_TABLE_PMSTATUSLOG].mc_address,
+					      &tables[SMU_TABLE_PMSTATUSLOG].cpu_addr);
+		if (ret) {
+			pr_err("VRAM allocation for tool table failed!\n");
+			return ret;
+		}
 	}
 
+	/* VRAM allocation for driver table */
 	for (i = 0; i < SMU_TABLE_COUNT; i++) {
 		if (tables[i].size == 0)
 			continue;
@@ -966,24 +968,29 @@ static int smu_init_fb_allocations(struct smu_context *smu)
 		if (i == SMU_TABLE_PMSTATUSLOG)
 			continue;
 
-		if (max_table_size < tables[i].size) {
+		if (max_table_size < tables[i].size)
 			max_table_size = tables[i].size;
-			index = i;
-		}
 	}
 
-	*driver_table = &tables[index];
-
-	return 0;
-failed:
-	while (--i >= 0) {
-		if (tables[i].size == 0)
-			continue;
-		amdgpu_bo_free_kernel(&tables[i].bo,
-				      &tables[i].mc_address,
-				      &tables[i].cpu_addr);
-
+	driver_table->size = max_table_size;
+	driver_table->align = PAGE_SIZE;
+	driver_table->domain = AMDGPU_GEM_DOMAIN_VRAM;
+
+	ret = amdgpu_bo_create_kernel(adev,
+				      driver_table->size,
+				      driver_table->align,
+				      driver_table->domain,
+				      &driver_table->bo,
+				      &driver_table->mc_address,
+				      &driver_table->cpu_addr);
+	if (ret) {
+		pr_err("VRAM allocation for driver table failed!\n");
+		if (tables[SMU_TABLE_PMSTATUSLOG].mc_address)
+			amdgpu_bo_free_kernel(&tables[SMU_TABLE_PMSTATUSLOG].bo,
+					      &tables[SMU_TABLE_PMSTATUSLOG].mc_address,
+					      &tables[SMU_TABLE_PMSTATUSLOG].cpu_addr);
 	}
+
 	return ret;
 }
 
@@ -991,18 +998,19 @@ static int smu_fini_fb_allocations(struct smu_context *smu)
 {
 	struct smu_table_context *smu_table = &smu->smu_table;
 	struct smu_table *tables = smu_table->tables;
-	uint32_t i = 0;
+	struct smu_table *driver_table = &(smu_table->driver_table);
 
 	if (!tables)
 		return 0;
 
-	for (i = 0; i < SMU_TABLE_COUNT; i++) {
-		if (tables[i].size == 0)
-			continue;
-		amdgpu_bo_free_kernel(&tables[i].bo,
-				      &tables[i].mc_address,
-				      &tables[i].cpu_addr);
-	}
+	if (tables[SMU_TABLE_PMSTATUSLOG].mc_address)
+		amdgpu_bo_free_kernel(&tables[SMU_TABLE_PMSTATUSLOG].bo,
+				      &tables[SMU_TABLE_PMSTATUSLOG].mc_address,
+				      &tables[SMU_TABLE_PMSTATUSLOG].cpu_addr);
+
+	amdgpu_bo_free_kernel(&driver_table->bo,
+			      &driver_table->mc_address,
+			      &driver_table->cpu_addr);
 
 	return 0;
 }
@@ -1913,26 +1921,25 @@ int smu_set_df_cstate(struct smu_context *smu,
 
 int smu_write_watermarks_table(struct smu_context *smu)
 {
-	int ret = 0;
-	struct smu_table_context *smu_table = &smu->smu_table;
-	struct smu_table *table = NULL;
+	void *watermarks_table = smu->smu_table.watermarks_table;
 
-	table = &smu_table->tables[SMU_TABLE_WATERMARKS];
-
-	if (!table->cpu_addr)
+	if (!watermarks_table)
 		return -EINVAL;
 
-	ret = smu_update_table(smu, SMU_TABLE_WATERMARKS, 0, table->cpu_addr,
+	return smu_update_table(smu,
+				SMU_TABLE_WATERMARKS,
+				0,
+				watermarks_table,
 				true);
-
-	return ret;
 }
 
 int smu_set_watermarks_for_clock_ranges(struct smu_context *smu,
 		struct dm_pp_wm_sets_with_clock_ranges_soc15 *clock_ranges)
 {
-	struct smu_table *watermarks = &smu->smu_table.tables[SMU_TABLE_WATERMARKS];
-	void *table = watermarks->cpu_addr;
+	void *table = smu->smu_table.watermarks_table;
+
+	if (!table)
+		return -EINVAL;
 
 	mutex_lock(&smu->mutex);
 
drivers/gpu/drm/amd/powerplay/arcturus_ppt.c +1 -1
index e89965e5fdcb..064b5201a8a7 100644
@@ -2022,7 +2022,7 @@ static int arcturus_i2c_eeprom_read_data(struct i2c_adapter *control,
 	SwI2cRequest_t req;
 	struct amdgpu_device *adev = to_amdgpu_device(control);
 	struct smu_table_context *smu_table = &adev->smu.smu_table;
-	struct smu_table *table = &smu_table->tables[SMU_TABLE_I2C_COMMANDS];
+	struct smu_table *table = &smu_table->driver_table;
 
 	memset(&req, 0, sizeof(req));
 	arcturus_fill_eeprom_i2c_req(&req, false, address, numbytes, data);
drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h +2 -1
index ed193adc881c..121bf81eced5 100644
@@ -254,12 +254,13 @@ struct smu_table_context
 	unsigned long			metrics_time;
 	void				*metrics_table;
 	void				*clocks_table;
+	void				*watermarks_table;
 
 	void				*max_sustainable_clocks;
 	struct smu_bios_boot_up_values	boot_values;
 	void                            *driver_pptable;
 	struct smu_table		*tables;
-	struct smu_table		*driver_table;
+	struct smu_table		driver_table;
 	struct smu_table		memory_pool;
 	uint8_t                         thermal_controller_type;
 
drivers/gpu/drm/amd/powerplay/navi10_ppt.c +4 -0
index ed147dd51325..aa206bde619b 100644
@@ -555,6 +555,10 @@ static int navi10_tables_init(struct smu_context *smu, struct smu_table *tables)
 		return -ENOMEM;
 	smu_table->metrics_time = 0;
 
+	smu_table->watermarks_table = kzalloc(sizeof(Watermarks_t), GFP_KERNEL);
+	if (!smu_table->watermarks_table)
+		return -ENOMEM;
+
 	return 0;
 }
 
drivers/gpu/drm/amd/powerplay/renoir_ppt.c +4 -0
index c4b5984c86d9..861e6410363b 100644
@@ -209,6 +209,10 @@ static int renoir_tables_init(struct smu_context *smu, struct smu_table *tables)
 		return -ENOMEM;
 	smu_table->metrics_time = 0;
 
+	smu_table->watermarks_table = kzalloc(sizeof(Watermarks_t), GFP_KERNEL);
+	if (!smu_table->watermarks_table)
+		return -ENOMEM;
+
 	return 0;
 }
 
drivers/gpu/drm/amd/powerplay/smu_v11_0.c +3 -1
index 79a63edcd7ba..962e97860fe8 100644
@@ -450,8 +450,10 @@ int smu_v11_0_fini_smc_tables(struct smu_context *smu)
 
 	kfree(smu_table->tables);
 	kfree(smu_table->metrics_table);
+	kfree(smu_table->watermarks_table);
 	smu_table->tables = NULL;
 	smu_table->metrics_table = NULL;
+	smu_table->watermarks_table = NULL;
 	smu_table->metrics_time = 0;
 
 	ret = smu_v11_0_fini_dpm_context(smu);
@@ -776,7 +778,7 @@ int smu_v11_0_set_min_dcef_deep_sleep(struct smu_context *smu)
 
 int smu_v11_0_set_driver_table_location(struct smu_context *smu)
 {
-	struct smu_table *driver_table = smu->smu_table.driver_table;
+	struct smu_table *driver_table = &smu->smu_table.driver_table;
 	int ret = 0;
 
 	if (driver_table->mc_address) {
drivers/gpu/drm/amd/powerplay/smu_v12_0.c +1 -9
index cd2be9fb2513..2b1ef9eb0db6 100644
@@ -318,14 +318,6 @@ int smu_v12_0_fini_smc_tables(struct smu_context *smu)
 int smu_v12_0_populate_smc_tables(struct smu_context *smu)
 {
 	struct smu_table_context *smu_table = &smu->smu_table;
-	struct smu_table *table = NULL;
-
-	table = &smu_table->tables[SMU_TABLE_DPMCLOCKS];
-	if (!table)
-		return -EINVAL;
-
-	if (!table->cpu_addr)
-		return -EINVAL;
 
 	return smu_update_table(smu, SMU_TABLE_DPMCLOCKS, 0, smu_table->clocks_table, false);
 }
@@ -517,7 +509,7 @@ int smu_v12_0_set_soft_freq_limited_range(struct smu_context *smu, enum smu_clk_
 
 int smu_v12_0_set_driver_table_location(struct smu_context *smu)
 {
-	struct smu_table *driver_table = smu->smu_table.driver_table;
+	struct smu_table *driver_table = &smu->smu_table.driver_table;
 	int ret = 0;
 
 	if (driver_table->mc_address) {
drivers/gpu/drm/amd/powerplay/vega20_ppt.c +4 -0
index 12f97956058b..38febd5ca4da 100644
@@ -338,6 +338,10 @@ static int vega20_tables_init(struct smu_context *smu, struct smu_table *tables)
 		return -ENOMEM;
 	smu_table->metrics_time = 0;
 
+	smu_table->watermarks_table = kzalloc(sizeof(Watermarks_t), GFP_KERNEL);
+	if (!smu_table->watermarks_table)
+		return -ENOMEM;
+
 	return 0;
 }
 
Signature · 6 lines
2.24.0

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
#2 lore raw

Re: [PATCH 2/2] drm/amd/powerplay: allocate one piece of VRAM for all tables transferring

Quoted 102 lines · Evan Quan

Simplify the table transferring between driver and SMU and use less VRAM.

Change-Id I3f9b54fd9b8c0bcaeb533fc1a07bb06050fefbd8
---
 drivers/gpu/drm/amd/powerplay/amdgpu_smu.c    | 101 ++++++++++--------
 drivers/gpu/drm/amd/powerplay/arcturus_ppt.c  |   2 +-
 .../gpu/drm/amd/powerplay/inc/amdgpu_smu.h    |   3 +-
 drivers/gpu/drm/amd/powerplay/navi10_ppt.c    |   4 +
 drivers/gpu/drm/amd/powerplay/renoir_ppt.c    |   4 +
 drivers/gpu/drm/amd/powerplay/smu_v11_0.c     |   4 +-
 drivers/gpu/drm/amd/powerplay/smu_v12_0.c     |  10 +-
 drivers/gpu/drm/amd/powerplay/vega20_ppt.c    |   4 +
 8 files changed, 73 insertions(+), 59 deletions(-)
drivers/gpu/drm/amd/powerplay/amdgpu_smu.c +27 -28
index c3cb1b8f43b5..bd3dbd1a0ad3 100644
@@ -490,7 +490,7 @@ int smu_update_table(struct smu_context *smu, enum smu_table_id table_index, int
 {
        struct smu_table_context *smu_table = &smu->smu_table;
        struct amdgpu_device *adev = smu->adev;
-       struct smu_table *table = smu_table->driver_table;
+       struct smu_table *table = &smu_table->driver_table;
        int table_id = smu_table_get_index(smu, table_index);
        uint32_t table_size;
        int ret = 0;
@@ -941,24 +941,26 @@ static int smu_init_fb_allocations(struct smu_context *smu)
        struct amdgpu_device *adev = smu->adev;
        struct smu_table_context *smu_table = &smu->smu_table;
        struct smu_table *tables = smu_table->tables;
-       struct smu_table **driver_table = &(smu_table->driver_table);
+       struct smu_table *driver_table = &(smu_table->driver_table);
        uint32_t max_table_size = 0;
-       int ret, i, index = 0;
+       int ret, i;
 
-       for (i = 0; i < SMU_TABLE_COUNT; i++) {
-               if (tables[i].size == 0)
-                       continue;
+       /* VRAM allocation for tool table */
+       if (tables[SMU_TABLE_PMSTATUSLOG].size) {
                ret = amdgpu_bo_create_kernel(adev,
-                                             tables[i].size,
-                                             tables[i].align,
-                                             tables[i].domain,
-                                             &tables[i].bo,
-                                             &tables[i].mc_address,
-                                             &tables[i].cpu_addr);
-               if (ret)
-                       goto failed;
+                                             tables[SMU_TABLE_PMSTATUSLOG].size,
+                                             tables[SMU_TABLE_PMSTATUSLOG].align,
+                                             tables[SMU_TABLE_PMSTATUSLOG].domain,
+                                             &tables[SMU_TABLE_PMSTATUSLOG].bo,
+                                             &tables[SMU_TABLE_PMSTATUSLOG].mc_address,
+                                             &tables[SMU_TABLE_PMSTATUSLOG].cpu_addr);
+               if (ret) {
+                       pr_err("VRAM allocation for tool table failed!\n");
+                       return ret;
+               }
        }
 
+       /* VRAM allocation for driver table */
        for (i = 0; i < SMU_TABLE_COUNT; i++) {
                if (tables[i].size == 0)
                        continue;
@@ -966,24 +968,29 @@ static int smu_init_fb_allocations(struct smu_context *smu)
                if (i == SMU_TABLE_PMSTATUSLOG)
                        continue;
 
-               if (max_table_size < tables[i].size) {
+               if (max_table_size < tables[i].size)
                        max_table_size = tables[i].size;
-                       index = i;
-               }
        }
 
-       *driver_table = &tables[index];
-
-       return 0;
-failed:
-       while (--i >= 0) {
-               if (tables[i].size == 0)
-                       continue;
-               amdgpu_bo_free_kernel(&tables[i].bo,
-                                     &tables[i].mc_address,
-                                     &tables[i].cpu_addr);
-
+       driver_table->size = max_table_size;
+       driver_table->align = PAGE_SIZE;
+       driver_table->domain = AMDGPU_GEM_DOMAIN_VRAM;
+
+       ret = amdgpu_bo_create_kernel(adev,
+                                     driver_table->size,
+                                     driver_table->align,
+                                     driver_table->domain,
+                                     &driver_table->bo,
+                                     &driver_table->mc_address,

drivers/gpu/drm/amd/powerplay/amdgpu_smu.c static int smu_init_fb_allocations(struct smu_context *smu) · line 994

Quoted 10 lines
drivers/gpu/drm/amd/powerplay/amdgpu_smu.c +8 -0
+                                     &driver_table->cpu_addr);
+       if (ret) {
+               pr_err("VRAM allocation for driver table failed!\n");
+               if (tables[SMU_TABLE_PMSTATUSLOG].mc_address)
+                       amdgpu_bo_free_kernel(&tables[SMU_TABLE_PMSTATUSLOG].bo,
+                                             &tables[SMU_TABLE_PMSTATUSLOG].mc_address,
+                                             &tables[SMU_TABLE_PMSTATUSLOG].cpu_addr);
        }
+
        return ret;

Shouldn't this change be merged into the previous patch? Otherwise, we'll break I think.

Quoted 85 lines
drivers/gpu/drm/amd/powerplay/amdgpu_smu.c +19 -19
 }
 
@@ -991,18 +998,19 @@ static int smu_fini_fb_allocations(struct smu_context *smu)
 {
        struct smu_table_context *smu_table = &smu->smu_table;
        struct smu_table *tables = smu_table->tables;
-       uint32_t i = 0;
+       struct smu_table *driver_table = &(smu_table->driver_table);
 
        if (!tables)
                return 0;
 
-       for (i = 0; i < SMU_TABLE_COUNT; i++) {
-               if (tables[i].size == 0)
-                       continue;
-               amdgpu_bo_free_kernel(&tables[i].bo,
-                                     &tables[i].mc_address,
-                                     &tables[i].cpu_addr);
-       }
+       if (tables[SMU_TABLE_PMSTATUSLOG].mc_address)
+               amdgpu_bo_free_kernel(&tables[SMU_TABLE_PMSTATUSLOG].bo,
+                                     &tables[SMU_TABLE_PMSTATUSLOG].mc_address,
+                                     &tables[SMU_TABLE_PMSTATUSLOG].cpu_addr);
+
+       amdgpu_bo_free_kernel(&driver_table->bo,
+                             &driver_table->mc_address,
+                             &driver_table->cpu_addr);
 
        return 0;
 }
@@ -1913,26 +1921,25 @@ int smu_set_df_cstate(struct smu_context *smu,
 
 int smu_write_watermarks_table(struct smu_context *smu)
 {
-       int ret = 0;
-       struct smu_table_context *smu_table = &smu->smu_table;
-       struct smu_table *table = NULL;
+       void *watermarks_table = smu->smu_table.watermarks_table;
 
-       table = &smu_table->tables[SMU_TABLE_WATERMARKS];
-
-       if (!table->cpu_addr)
+       if (!watermarks_table)
                return -EINVAL;
 
-       ret = smu_update_table(smu, SMU_TABLE_WATERMARKS, 0, table->cpu_addr,
+       return smu_update_table(smu,
+                               SMU_TABLE_WATERMARKS,
+                               0,
+                               watermarks_table,
                                true);
-
-       return ret;
 }
 
 int smu_set_watermarks_for_clock_ranges(struct smu_context *smu,
                struct dm_pp_wm_sets_with_clock_ranges_soc15 *clock_ranges)
 {
-       struct smu_table *watermarks = &smu->smu_table.tables[SMU_TABLE_WATERMARKS];
-       void *table = watermarks->cpu_addr;
+       void *table = smu->smu_table.watermarks_table;
+
+       if (!table)
+               return -EINVAL;
 
        mutex_lock(&smu->mutex);
 
drivers/gpu/drm/amd/powerplay/arcturus_ppt.c +1 -1
index e89965e5fdcb..064b5201a8a7 100644
@@ -2022,7 +2022,7 @@ static int arcturus_i2c_eeprom_read_data(struct i2c_adapter *control,
        SwI2cRequest_t req;
        struct amdgpu_device *adev = to_amdgpu_device(control);
        struct smu_table_context *smu_table = &adev->smu.smu_table;
-       struct smu_table *table = &smu_table->tables[SMU_TABLE_I2C_COMMANDS];
+       struct smu_table *table = &smu_table->driver_table;
 
        memset(&req, 0, sizeof(req));
        arcturus_fill_eeprom_i2c_req(&req, false, address, numbytes, data);
drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h +0 -0
index ed193adc881c..121bf81eced5 100644

drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h struct smu_table_context · line 257

Quoted 4 lines
drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h +1 -0
@@ -254,12 +254,13 @@ struct smu_table_context
        unsigned long                   metrics_time;
        void                            *metrics_table;
        void                            *clocks_table;
+       void                            *watermarks_table;

Can you split out the watermarks change as a separate patch or at least explain why you are changing how it's handled?

Alex

Quoted 110 lines
drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h +1 -1
        void                            *max_sustainable_clocks;
        struct smu_bios_boot_up_values  boot_values;
        void                            *driver_pptable;
        struct smu_table                *tables;
-       struct smu_table                *driver_table;
+       struct smu_table                driver_table;
        struct smu_table                memory_pool;
        uint8_t                         thermal_controller_type;
 
drivers/gpu/drm/amd/powerplay/navi10_ppt.c +4 -0
index ed147dd51325..aa206bde619b 100644
@@ -555,6 +555,10 @@ static int navi10_tables_init(struct smu_context *smu, struct smu_table *tables)
                return -ENOMEM;
        smu_table->metrics_time = 0;
 
+       smu_table->watermarks_table = kzalloc(sizeof(Watermarks_t), GFP_KERNEL);
+       if (!smu_table->watermarks_table)
+               return -ENOMEM;
+
        return 0;
 }
 
drivers/gpu/drm/amd/powerplay/renoir_ppt.c +4 -0
index c4b5984c86d9..861e6410363b 100644
@@ -209,6 +209,10 @@ static int renoir_tables_init(struct smu_context *smu, struct smu_table *tables)
                return -ENOMEM;
        smu_table->metrics_time = 0;
 
+       smu_table->watermarks_table = kzalloc(sizeof(Watermarks_t), GFP_KERNEL);
+       if (!smu_table->watermarks_table)
+               return -ENOMEM;
+
        return 0;
 }
 
drivers/gpu/drm/amd/powerplay/smu_v11_0.c +3 -1
index 79a63edcd7ba..962e97860fe8 100644
@@ -450,8 +450,10 @@ int smu_v11_0_fini_smc_tables(struct smu_context *smu)
 
        kfree(smu_table->tables);
        kfree(smu_table->metrics_table);
+       kfree(smu_table->watermarks_table);
        smu_table->tables = NULL;
        smu_table->metrics_table = NULL;
+       smu_table->watermarks_table = NULL;
        smu_table->metrics_time = 0;
 
        ret = smu_v11_0_fini_dpm_context(smu);
@@ -776,7 +778,7 @@ int smu_v11_0_set_min_dcef_deep_sleep(struct smu_context *smu)
 
 int smu_v11_0_set_driver_table_location(struct smu_context *smu)
 {
-       struct smu_table *driver_table = smu->smu_table.driver_table;
+       struct smu_table *driver_table = &smu->smu_table.driver_table;
        int ret = 0;
 
        if (driver_table->mc_address) {
drivers/gpu/drm/amd/powerplay/smu_v12_0.c +1 -9
index cd2be9fb2513..2b1ef9eb0db6 100644
@@ -318,14 +318,6 @@ int smu_v12_0_fini_smc_tables(struct smu_context *smu)
 int smu_v12_0_populate_smc_tables(struct smu_context *smu)
 {
        struct smu_table_context *smu_table = &smu->smu_table;
-       struct smu_table *table = NULL;
-
-       table = &smu_table->tables[SMU_TABLE_DPMCLOCKS];
-       if (!table)
-               return -EINVAL;
-
-       if (!table->cpu_addr)
-               return -EINVAL;
 
        return smu_update_table(smu, SMU_TABLE_DPMCLOCKS, 0, smu_table->clocks_table, false);
 }
@@ -517,7 +509,7 @@ int smu_v12_0_set_soft_freq_limited_range(struct smu_context *smu, enum smu_clk_
 
 int smu_v12_0_set_driver_table_location(struct smu_context *smu)
 {
-       struct smu_table *driver_table = smu->smu_table.driver_table;
+       struct smu_table *driver_table = &smu->smu_table.driver_table;
        int ret = 0;
 
        if (driver_table->mc_address) {
drivers/gpu/drm/amd/powerplay/vega20_ppt.c +4 -1
index 12f97956058b..38febd5ca4da 100644
@@ -338,6 +338,10 @@ static int vega20_tables_init(struct smu_context *smu, struct smu_table *tables)
                return -ENOMEM;
        smu_table->metrics_time = 0;
 
+       smu_table->watermarks_table = kzalloc(sizeof(Watermarks_t), GFP_KERNEL);
+       if (!smu_table->watermarks_table)
+               return -ENOMEM;
+
        return 0;
 }
 
--

2.24.0

Quoted 4 lines

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

author
#3 lore raw

RE: [PATCH 2/2] drm/amd/powerplay: allocate one piece of VRAM for all tables transferring

Hi Alex,

Please check the new patch sets.
https://lists.freedesktop.org/archives/amd-gfx/2019-December/044352.html
https://lists.freedesktop.org/archives/amd-gfx/2019-December/044353.html

Regards,
Evan

Quoted 364 lines

-----Original Message-----
From: Alex Deucher <[email protected]>
Sent: Monday, December 30, 2019 11:22 PM
To: Quan, Evan <[email protected]>
Cc: amd-gfx list <[email protected]>
Subject: Re: [PATCH 2/2] drm/amd/powerplay: allocate one piece of VRAM for all tables transferring

drivers/gpu/drm/amd/powerplay/amdgpu_smu.c int smu_update_table(struct smu_context *smu,

Quoted 23 lines · Evan Quan

Simplify the table transferring between driver and SMU and use less VRAM.

Change-Id I3f9b54fd9b8c0bcaeb533fc1a07bb06050fefbd8
---
 drivers/gpu/drm/amd/powerplay/amdgpu_smu.c    | 101 ++++++++++--------
 drivers/gpu/drm/amd/powerplay/arcturus_ppt.c  |   2 +-
 .../gpu/drm/amd/powerplay/inc/amdgpu_smu.h    |   3 +-
 drivers/gpu/drm/amd/powerplay/navi10_ppt.c    |   4 +
 drivers/gpu/drm/amd/powerplay/renoir_ppt.c    |   4 +
 drivers/gpu/drm/amd/powerplay/smu_v11_0.c     |   4 +-
 drivers/gpu/drm/amd/powerplay/smu_v12_0.c     |  10 +-
 drivers/gpu/drm/amd/powerplay/vega20_ppt.c    |   4 +
 8 files changed, 73 insertions(+), 59 deletions(-)
drivers/gpu/drm/amd/powerplay/amdgpu_smu.c +0 -0
index c3cb1b8f43b5..bd3dbd1a0ad3 100644
@@ -490,7 +490,7 @@ int smu_update_table(struct smu_context *smu,

enum

drivers/gpu/drm/amd/powerplay/amdgpu_smu.c static int smu_init_fb_allocations(struct

Quoted 9 lines
drivers/gpu/drm/amd/powerplay/amdgpu_smu.c +1 -1
 smu_table_id table_index, int  {
        struct smu_table_context *smu_table = &smu->smu_table;
        struct amdgpu_device *adev = smu->adev;
-       struct smu_table *table = smu_table->driver_table;
+       struct smu_table *table = &smu_table->driver_table;
        int table_id = smu_table_get_index(smu, table_index);
        uint32_t table_size;
        int ret = 0;
@@ -941,24 +941,26 @@ static int smu_init_fb_allocations(struct

smu_context *smu)

Quoted 18 lines
drivers/gpu/drm/amd/powerplay/amdgpu_smu.c +4 -8
        struct amdgpu_device *adev = smu->adev;
        struct smu_table_context *smu_table = &smu->smu_table;
        struct smu_table *tables = smu_table->tables;
-       struct smu_table **driver_table = &(smu_table->driver_table);
+       struct smu_table *driver_table = &(smu_table->driver_table);
        uint32_t max_table_size = 0;
-       int ret, i, index = 0;
+       int ret, i;
 
-       for (i = 0; i < SMU_TABLE_COUNT; i++) {
-               if (tables[i].size == 0)
-                       continue;
+       /* VRAM allocation for tool table */
+       if (tables[SMU_TABLE_PMSTATUSLOG].size) {
                ret = amdgpu_bo_create_kernel(adev,
-                                             tables[i].size,
-                                             tables[i].align,
-                                             tables[i].domain,

drivers/gpu/drm/amd/powerplay/amdgpu_smu.c static int smu_init_fb_allocations(struct smu_context *smu)

Quoted 10 lines
drivers/gpu/drm/amd/powerplay/amdgpu_smu.c +5 -5
-                                             &tables[i].bo,
-                                             &tables[i].mc_address,
-                                             &tables[i].cpu_addr);
-               if (ret)
-                       goto failed;
+                                             tables[SMU_TABLE_PMSTATUSLOG].size,
+                                             tables[SMU_TABLE_PMSTATUSLOG].align,
+                                             tables[SMU_TABLE_PMSTATUSLOG].domain,
+                                             &tables[SMU_TABLE_PMSTATUSLOG].bo,
+

&tables[SMU_TABLE_PMSTATUSLOG].mc_address,

drivers/gpu/drm/amd/powerplay/amdgpu_smu.c static int smu_init_fb_allocations(struct

Quoted 12 lines
drivers/gpu/drm/amd/powerplay/amdgpu_smu.c +6 -0
+                                             &tables[SMU_TABLE_PMSTATUSLOG].cpu_addr);
+               if (ret) {
+                       pr_err("VRAM allocation for tool table failed!\n");
+                       return ret;
+               }
        }
 
+       /* VRAM allocation for driver table */
        for (i = 0; i < SMU_TABLE_COUNT; i++) {
                if (tables[i].size == 0)
                        continue;
@@ -966,24 +968,29 @@ static int smu_init_fb_allocations(struct

smu_context *smu)

Quoted 26 lines
drivers/gpu/drm/amd/powerplay/amdgpu_smu.c +6 -14
                if (i == SMU_TABLE_PMSTATUSLOG)
                        continue;
 
-               if (max_table_size < tables[i].size) {
+               if (max_table_size < tables[i].size)
                        max_table_size = tables[i].size;
-                       index = i;
-               }
        }
 
-       *driver_table = &tables[index];
-
-       return 0;
-failed:
-       while (--i >= 0) {
-               if (tables[i].size == 0)
-                       continue;
-               amdgpu_bo_free_kernel(&tables[i].bo,
-                                     &tables[i].mc_address,
-                                     &tables[i].cpu_addr);
-
+       driver_table->size = max_table_size;
+       driver_table->align = PAGE_SIZE;
+       driver_table->domain = AMDGPU_GEM_DOMAIN_VRAM;
+
+       ret = amdgpu_bo_create_kernel(adev,

drivers/gpu/drm/amd/powerplay/amdgpu_smu.c static int smu_init_fb_allocations(struct smu_context *smu) · line 993

Quoted 10 lines
drivers/gpu/drm/amd/powerplay/amdgpu_smu.c +10 -0
+                                     driver_table->size,
+                                     driver_table->align,
+                                     driver_table->domain,
+                                     &driver_table->bo,
+                                     &driver_table->mc_address,
+                                     &driver_table->cpu_addr);
+       if (ret) {
+               pr_err("VRAM allocation for driver table failed!\n");
+               if (tables[SMU_TABLE_PMSTATUSLOG].mc_address)
+

amdgpu_bo_free_kernel(&tables[SMU_TABLE_PMSTATUSLOG].bo,

drivers/gpu/drm/amd/powerplay/amdgpu_smu.c static int smu_init_fb_allocations(struct · line 990

Quoted 1 line
drivers/gpu/drm/amd/powerplay/amdgpu_smu.c +1 -0
+

&tables[SMU_TABLE_PMSTATUSLOG].mc_address,

drivers/gpu/drm/amd/powerplay/amdgpu_smu.c static int smu_init_fb_allocations(struct smu_context *smu) · line 994

Quoted 5 lines
drivers/gpu/drm/amd/powerplay/amdgpu_smu.c +3 -0
+
+ &tables[SMU_TABLE_PMSTATUSLOG].cpu_addr);
        }
+
        return ret;

Shouldn't this change be merged into the previous patch? Otherwise, we'll break I think.

Review

Quoted 70 lines
drivers/gpu/drm/amd/powerplay/amdgpu_smu.c +20 -19
 }
@@ -991,18 +998,19 @@ static int smu_fini_fb_allocations(struct
 smu_context *smu)  {
        struct smu_table_context *smu_table = &smu->smu_table;
        struct smu_table *tables = smu_table->tables;
-       uint32_t i = 0;
+       struct smu_table *driver_table = &(smu_table->driver_table);
 
        if (!tables)
                return 0;
 
-       for (i = 0; i < SMU_TABLE_COUNT; i++) {
-               if (tables[i].size == 0)
-                       continue;
-               amdgpu_bo_free_kernel(&tables[i].bo,
-                                     &tables[i].mc_address,
-                                     &tables[i].cpu_addr);
-       }
+       if (tables[SMU_TABLE_PMSTATUSLOG].mc_address)
+               amdgpu_bo_free_kernel(&tables[SMU_TABLE_PMSTATUSLOG].bo,
+                                     &tables[SMU_TABLE_PMSTATUSLOG].mc_address,
+
+ &tables[SMU_TABLE_PMSTATUSLOG].cpu_addr);
+
+       amdgpu_bo_free_kernel(&driver_table->bo,
+                             &driver_table->mc_address,
+                             &driver_table->cpu_addr);
 
        return 0;
 }
@@ -1913,26 +1921,25 @@ int smu_set_df_cstate(struct smu_context *smu,
 
 int smu_write_watermarks_table(struct smu_context *smu)  {
-       int ret = 0;
-       struct smu_table_context *smu_table = &smu->smu_table;
-       struct smu_table *table = NULL;
+       void *watermarks_table = smu->smu_table.watermarks_table;
 
-       table = &smu_table->tables[SMU_TABLE_WATERMARKS];
-
-       if (!table->cpu_addr)
+       if (!watermarks_table)
                return -EINVAL;
 
-       ret = smu_update_table(smu, SMU_TABLE_WATERMARKS, 0, table-
 cpu_addr,
+       return smu_update_table(smu,
+                               SMU_TABLE_WATERMARKS,
+                               0,
+                               watermarks_table,
                                true);
-
-       return ret;
 }
 
 int smu_set_watermarks_for_clock_ranges(struct smu_context *smu,
                struct dm_pp_wm_sets_with_clock_ranges_soc15 *clock_ranges)
 {
-       struct smu_table *watermarks = &smu-
 smu_table.tables[SMU_TABLE_WATERMARKS];
-       void *table = watermarks->cpu_addr;
+       void *table = smu->smu_table.watermarks_table;
+
+       if (!table)
+               return -EINVAL;
 
        mutex_lock(&smu->mutex);
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/powerplay/arcturus_ppt.c

drivers/gpu/drm/amd/powerplay/arcturus_ppt.c static int arcturus_i2c_eeprom_read_data(struct

Quoted 4 lines

index e89965e5fdcb..064b5201a8a7 100644

drivers/gpu/drm/amd/powerplay/arcturus_ppt.c +0 -0
@@ -2022,7 +2022,7 @@ static int arcturus_i2c_eeprom_read_data(struct

i2c_adapter *control,

Review

Quoted 10 lines
drivers/gpu/drm/amd/powerplay/arcturus_ppt.c +1 -1
        SwI2cRequest_t req;
        struct amdgpu_device *adev = to_amdgpu_device(control);
        struct smu_table_context *smu_table = &adev->smu.smu_table;
-       struct smu_table *table = &smu_table-
 tables[SMU_TABLE_I2C_COMMANDS];
+       struct smu_table *table = &smu_table->driver_table;
 
        memset(&req, 0, sizeof(req));
        arcturus_fill_eeprom_i2c_req(&req, false, address, numbytes, data);
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h

drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h struct smu_table_context · line 257

Quoted 8 lines

index ed193adc881c..121bf81eced5 100644

drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h +1 -0
@@ -254,12 +254,13 @@ struct smu_table_context
        unsigned long                   metrics_time;
        void                            *metrics_table;
        void                            *clocks_table;
+       void                            *watermarks_table;

Can you split out the watermarks change as a separate patch or at least explain why you are changing how it's handled?

Alex

Review

Quoted 11 lines
drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h +1 -1
        void                            *max_sustainable_clocks;
        struct smu_bios_boot_up_values  boot_values;
        void                            *driver_pptable;
        struct smu_table                *tables;
-       struct smu_table                *driver_table;
+       struct smu_table                driver_table;
        struct smu_table                memory_pool;
        uint8_t                         thermal_controller_type;
 
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/powerplay/navi10_ppt.c

drivers/gpu/drm/amd/powerplay/navi10_ppt.c static int navi10_tables_init(struct smu_context

Quoted 4 lines

index ed147dd51325..aa206bde619b 100644

drivers/gpu/drm/amd/powerplay/navi10_ppt.c +0 -0
@@ -555,6 +555,10 @@ static int navi10_tables_init(struct smu_context

*smu, struct smu_table *tables)

drivers/gpu/drm/amd/powerplay/navi10_ppt.c static int navi10_tables_init(struct smu_context *smu, struct smu_table *tables)

Quoted 4 lines
drivers/gpu/drm/amd/powerplay/navi10_ppt.c +1 -0
                return -ENOMEM;
        smu_table->metrics_time = 0;
 
+       smu_table->watermarks_table = kzalloc(sizeof(Watermarks_t),

GFP_KERNEL);

Review

Quoted 7 lines
drivers/gpu/drm/amd/powerplay/navi10_ppt.c +3 -0
+       if (!smu_table->watermarks_table)
+               return -ENOMEM;
+
        return 0;
 }
 
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/powerplay/renoir_ppt.c

drivers/gpu/drm/amd/powerplay/renoir_ppt.c static int renoir_tables_init(struct smu_context

Quoted 4 lines

index c4b5984c86d9..861e6410363b 100644

drivers/gpu/drm/amd/powerplay/renoir_ppt.c +0 -0
@@ -209,6 +209,10 @@ static int renoir_tables_init(struct smu_context

*smu, struct smu_table *tables)

drivers/gpu/drm/amd/powerplay/renoir_ppt.c static int renoir_tables_init(struct smu_context · line 212

Quoted 4 lines
drivers/gpu/drm/amd/powerplay/renoir_ppt.c +1 -0
                return -ENOMEM;
        smu_table->metrics_time = 0;
 
+       smu_table->watermarks_table = kzalloc(sizeof(Watermarks_t),

GFP_KERNEL);

Review

Quoted 7 lines
drivers/gpu/drm/amd/powerplay/renoir_ppt.c +3 -0
+       if (!smu_table->watermarks_table)
+               return -ENOMEM;
+
        return 0;
 }
 
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/powerplay/smu_v11_0.c

drivers/gpu/drm/amd/powerplay/smu_v11_0.c int smu_v11_0_fini_smc_tables(struct smu_context

Quoted 4 lines

index 79a63edcd7ba..962e97860fe8 100644

drivers/gpu/drm/amd/powerplay/smu_v11_0.c +0 -0
@@ -450,8 +450,10 @@ int smu_v11_0_fini_smc_tables(struct smu_context

*smu)

drivers/gpu/drm/amd/powerplay/smu_v11_0.c int smu_v11_0_set_min_dcef_deep_sleep(struct

Quoted 11 lines
drivers/gpu/drm/amd/powerplay/smu_v11_0.c +2 -0
        kfree(smu_table->tables);
        kfree(smu_table->metrics_table);
+       kfree(smu_table->watermarks_table);
        smu_table->tables = NULL;
        smu_table->metrics_table = NULL;
+       smu_table->watermarks_table = NULL;
        smu_table->metrics_time = 0;
 
        ret = smu_v11_0_fini_dpm_context(smu);
@@ -776,7 +778,7 @@ int smu_v11_0_set_min_dcef_deep_sleep(struct

smu_context *smu)

Review

Quoted 9 lines
drivers/gpu/drm/amd/powerplay/smu_v11_0.c +1 -1
 int smu_v11_0_set_driver_table_location(struct smu_context *smu)
 {
-       struct smu_table *driver_table = smu->smu_table.driver_table;
+       struct smu_table *driver_table = &smu->smu_table.driver_table;
        int ret = 0;
 
        if (driver_table->mc_address) {
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/powerplay/smu_v12_0.c

drivers/gpu/drm/amd/powerplay/smu_v12_0.c int smu_v12_0_fini_smc_tables(struct smu_context

Quoted 4 lines

index cd2be9fb2513..2b1ef9eb0db6 100644

drivers/gpu/drm/amd/powerplay/smu_v12_0.c +0 -0
@@ -318,14 +318,6 @@ int smu_v12_0_fini_smc_tables(struct smu_context

*smu)

drivers/gpu/drm/amd/powerplay/smu_v12_0.c int smu_v12_0_set_soft_freq_limited_range(struct

Quoted 16 lines
drivers/gpu/drm/amd/powerplay/smu_v12_0.c +0 -8
 int smu_v12_0_populate_smc_tables(struct smu_context *smu)
 {
        struct smu_table_context *smu_table = &smu->smu_table;
-       struct smu_table *table = NULL;
-
-       table = &smu_table->tables[SMU_TABLE_DPMCLOCKS];
-       if (!table)
-               return -EINVAL;
-
-       if (!table->cpu_addr)
-               return -EINVAL;
 
        return smu_update_table(smu, SMU_TABLE_DPMCLOCKS, 0, smu_table-
 clocks_table, false);

}

drivers/gpu/drm/amd/powerplay/smu_v12_0.c +0 -0
@@ -517,7 +509,7 @@ int smu_v12_0_set_soft_freq_limited_range(struct

smu_context *smu, enum smu_clk_

Review

Quoted 9 lines
drivers/gpu/drm/amd/powerplay/smu_v12_0.c +1 -1
 int smu_v12_0_set_driver_table_location(struct smu_context *smu)
 {
-       struct smu_table *driver_table = smu->smu_table.driver_table;
+       struct smu_table *driver_table = &smu->smu_table.driver_table;
        int ret = 0;
 
        if (driver_table->mc_address) {
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/powerplay/vega20_ppt.c

drivers/gpu/drm/amd/powerplay/vega20_ppt.c static int vega20_tables_init(struct smu_context

Quoted 4 lines

index 12f97956058b..38febd5ca4da 100644

drivers/gpu/drm/amd/powerplay/vega20_ppt.c +0 -0
@@ -338,6 +338,10 @@ static int vega20_tables_init(struct smu_context

*smu, struct smu_table *tables)

drivers/gpu/drm/amd/powerplay/vega20_ppt.c static int vega20_tables_init(struct smu_context · line 341

Quoted 4 lines
drivers/gpu/drm/amd/powerplay/vega20_ppt.c +1 -0
                return -ENOMEM;
        smu_table->metrics_time = 0;
 
+       smu_table->watermarks_table = kzalloc(sizeof(Watermarks_t),

GFP_KERNEL);

Quoted 9 lines
drivers/gpu/drm/amd/powerplay/vega20_ppt.c +3 -1
+       if (!smu_table->watermarks_table)
+               return -ENOMEM;
+
        return 0;
 }
 
--

2.24.0

Quoted 4 lines

_______________________________________________
amd-gfx mailing list
[email protected]

Quoted 6 lines

https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.free
desktop.org%2Fmailman%2Flistinfo%2Famd- gfx&amp;data=02%7C01%7Cevan.quan%40amd.com%7Cdd3a4f9d66ba4e7085 ba08d78d3c0c38%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637 133161355995859&amp;sdata=KYYcYqB%2Bd3vWoIHVYVSed8bXtqrfg1dWrlFT0 QMFhRs%3D&amp;reserved=0

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#4 lore raw
In reply to Evan Quan
Quoted 85 lines · Evan Quan

By this, we can avoid to pass in the vram address on every table transferring.

Change-Id Ia8a3dbe923bc562286ab102a5830392a95dcf28c
---
 drivers/gpu/drm/amd/powerplay/amdgpu_smu.c    | 42 ++++++++++++-------
 drivers/gpu/drm/amd/powerplay/arcturus_ppt.c  |  1 +
 .../gpu/drm/amd/powerplay/inc/amdgpu_smu.h    |  2 +
 drivers/gpu/drm/amd/powerplay/inc/smu_v11_0.h |  2 +
 drivers/gpu/drm/amd/powerplay/inc/smu_v12_0.h |  2 +
 drivers/gpu/drm/amd/powerplay/navi10_ppt.c    |  1 +
 drivers/gpu/drm/amd/powerplay/renoir_ppt.c    |  1 +
 drivers/gpu/drm/amd/powerplay/smu_internal.h  |  2 +
 drivers/gpu/drm/amd/powerplay/smu_v11_0.c     | 18 ++++++++
 drivers/gpu/drm/amd/powerplay/smu_v12_0.c     | 18 ++++++++
 drivers/gpu/drm/amd/powerplay/vega20_ppt.c    |  1 +
 11 files changed, 76 insertions(+), 14 deletions(-)
drivers/gpu/drm/amd/powerplay/amdgpu_smu.c +14 -14
index 4a7fb6b15635..c3cb1b8f43b5 100644
@@ -490,26 +490,19 @@ int smu_update_table(struct smu_context *smu, enum smu_table_id table_index, int
 {
        struct smu_table_context *smu_table = &smu->smu_table;
        struct amdgpu_device *adev = smu->adev;
-       struct smu_table *table = NULL;
-       int ret = 0;
+       struct smu_table *table = smu_table->driver_table;
        int table_id = smu_table_get_index(smu, table_index);
+       uint32_t table_size;
+       int ret = 0;
 
        if (!table_data || table_id >= SMU_TABLE_COUNT || table_id < 0)
                return -EINVAL;
 
-       table = &smu_table->tables[table_index];
+       table_size = smu_table->tables[table_index].size;
 
        if (drv2smu)
-               memcpy(table->cpu_addr, table_data, table->size);
+               memcpy(table->cpu_addr, table_data, table_size);
 
-       ret = smu_send_smc_msg_with_param(smu, SMU_MSG_SetDriverDramAddrHigh,
-                                         upper_32_bits(table->mc_address));
-       if (ret)
-               return ret;
-       ret = smu_send_smc_msg_with_param(smu, SMU_MSG_SetDriverDramAddrLow,
-                                         lower_32_bits(table->mc_address));
-       if (ret)
-               return ret;
        ret = smu_send_smc_msg_with_param(smu, drv2smu ?
                                          SMU_MSG_TransferTableDram2Smu :
                                          SMU_MSG_TransferTableSmu2Dram,
@@ -521,7 +514,7 @@ int smu_update_table(struct smu_context *smu, enum smu_table_id table_index, int
        adev->nbio.funcs->hdp_flush(adev, NULL);
 
        if (!drv2smu)
-               memcpy(table_data, table->cpu_addr, table->size);
+               memcpy(table_data, table->cpu_addr, table_size);
 
        return ret;
 }
@@ -948,7 +941,9 @@ static int smu_init_fb_allocations(struct smu_context *smu)
        struct amdgpu_device *adev = smu->adev;
        struct smu_table_context *smu_table = &smu->smu_table;
        struct smu_table *tables = smu_table->tables;
-       int ret, i;
+       struct smu_table **driver_table = &(smu_table->driver_table);
+       uint32_t max_table_size = 0;
+       int ret, i, index = 0;
 
        for (i = 0; i < SMU_TABLE_COUNT; i++) {
                if (tables[i].size == 0)
@@ -964,6 +959,21 @@ static int smu_init_fb_allocations(struct smu_context *smu)
                        goto failed;
        }
 
+       for (i = 0; i < SMU_TABLE_COUNT; i++) {
+               if (tables[i].size == 0)
+                       continue;
+
+               if (i == SMU_TABLE_PMSTATUSLOG)

drivers/gpu/drm/amd/powerplay/amdgpu_smu.c static int smu_init_fb_allocations(struct smu_context *smu) · line 976

Quoted 10 lines
drivers/gpu/drm/amd/powerplay/amdgpu_smu.c +10 -0
+                       continue;
+
+               if (max_table_size < tables[i].size) {
+                       max_table_size = tables[i].size;
+                       index = i;
+               }
+       }
+
+       *driver_table = &tables[index];
+

Will this work? I don't think we have any guarantee that the memory for each table is contiguous.

Quoted 4 lines
drivers/gpu/drm/amd/powerplay/amdgpu_smu.c +0 -0
        return 0;
 failed:
        while (--i >= 0) {

drivers/gpu/drm/amd/powerplay/amdgpu_smu.c static int smu_smc_table_hw_init(struct smu_context *smu, · line 1082

Quoted 10 lines
drivers/gpu/drm/amd/powerplay/amdgpu_smu.c +4 -0
@@ -1063,6 +1073,10 @@ static int smu_smc_table_hw_init(struct smu_context *smu,
 
        /* smu_dump_pptable(smu); */
 
+       ret = smu_set_driver_table_location(smu);
+       if (ret)
+               return ret;
+
        /*
         * Copy pptable bo in the vram to smc with SMU MSGs such as
         * SetDriverDramAddr and TransferTableDram2Smu.

Fix this comment to match the code changes.

Quoted 163 lines
drivers/gpu/drm/amd/powerplay/arcturus_ppt.c +1 -0
index 50b317f4b1e6..e89965e5fdcb 100644
@@ -2261,6 +2261,7 @@ static const struct pptable_funcs arcturus_ppt_funcs = {
        .check_fw_version = smu_v11_0_check_fw_version,
        .write_pptable = smu_v11_0_write_pptable,
        .set_min_dcef_deep_sleep = smu_v11_0_set_min_dcef_deep_sleep,
+       .set_driver_table_location = smu_v11_0_set_driver_table_location,
        .set_tool_table_location = smu_v11_0_set_tool_table_location,
        .notify_memory_pool_location = smu_v11_0_notify_memory_pool_location,
        .system_features_control = smu_v11_0_system_features_control,
drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h +2 -0
index 541cfde289ea..ed193adc881c 100644
@@ -259,6 +259,7 @@ struct smu_table_context
        struct smu_bios_boot_up_values  boot_values;
        void                            *driver_pptable;
        struct smu_table                *tables;
+       struct smu_table                *driver_table;
        struct smu_table                memory_pool;
        uint8_t                         thermal_controller_type;
 
@@ -497,6 +498,7 @@ struct pptable_funcs {
        int (*set_gfx_cgpg)(struct smu_context *smu, bool enable);
        int (*write_pptable)(struct smu_context *smu);
        int (*set_min_dcef_deep_sleep)(struct smu_context *smu);
+       int (*set_driver_table_location)(struct smu_context *smu);
        int (*set_tool_table_location)(struct smu_context *smu);
        int (*notify_memory_pool_location)(struct smu_context *smu);
        int (*set_last_dcef_min_deep_sleep_clk)(struct smu_context *smu);
drivers/gpu/drm/amd/powerplay/inc/smu_v11_0.h +2 -0
index db3f78676aeb..662989296174 100644
@@ -170,6 +170,8 @@ int smu_v11_0_write_pptable(struct smu_context *smu);
 
 int smu_v11_0_set_min_dcef_deep_sleep(struct smu_context *smu);
 
+int smu_v11_0_set_driver_table_location(struct smu_context *smu);
+
 int smu_v11_0_set_tool_table_location(struct smu_context *smu);
 
 int smu_v11_0_notify_memory_pool_location(struct smu_context *smu);
drivers/gpu/drm/amd/powerplay/inc/smu_v12_0.h +2 -0
index 3f1cd06e273c..d79e54b5ebf6 100644
@@ -90,4 +90,6 @@ int smu_v12_0_mode2_reset(struct smu_context *smu);
 int smu_v12_0_set_soft_freq_limited_range(struct smu_context *smu, enum smu_clk_type clk_type,
                            uint32_t min, uint32_t max);
 
+int smu_v12_0_set_driver_table_location(struct smu_context *smu);
+
 #endif
drivers/gpu/drm/amd/powerplay/navi10_ppt.c +1 -0
index e7ab8caee222..ed147dd51325 100644
@@ -2116,6 +2116,7 @@ static const struct pptable_funcs navi10_ppt_funcs = {
        .check_fw_version = smu_v11_0_check_fw_version,
        .write_pptable = smu_v11_0_write_pptable,
        .set_min_dcef_deep_sleep = smu_v11_0_set_min_dcef_deep_sleep,
+       .set_driver_table_location = smu_v11_0_set_driver_table_location,
        .set_tool_table_location = smu_v11_0_set_tool_table_location,
        .notify_memory_pool_location = smu_v11_0_notify_memory_pool_location,
        .system_features_control = smu_v11_0_system_features_control,
drivers/gpu/drm/amd/powerplay/renoir_ppt.c +1 -0
index e73644beffd9..c4b5984c86d9 100644
@@ -916,6 +916,7 @@ static const struct pptable_funcs renoir_ppt_funcs = {
        .get_dpm_ultimate_freq = smu_v12_0_get_dpm_ultimate_freq,
        .mode2_reset = smu_v12_0_mode2_reset,
        .set_soft_freq_limited_range = smu_v12_0_set_soft_freq_limited_range,
+       .set_driver_table_location = smu_v12_0_set_driver_table_location,
 };
 
 void renoir_set_ppt_funcs(struct smu_context *smu)
drivers/gpu/drm/amd/powerplay/smu_internal.h +2 -0
index 77864e4236c4..783319ec8bf9 100644
@@ -61,6 +61,8 @@
        ((smu)->ppt_funcs->write_pptable ? (smu)->ppt_funcs->write_pptable((smu)) : 0)
 #define smu_set_min_dcef_deep_sleep(smu) \
        ((smu)->ppt_funcs->set_min_dcef_deep_sleep ? (smu)->ppt_funcs->set_min_dcef_deep_sleep((smu)) : 0)
+#define smu_set_driver_table_location(smu) \
+       ((smu)->ppt_funcs->set_driver_table_location ? (smu)->ppt_funcs->set_driver_table_location((smu)) : 0)
 #define smu_set_tool_table_location(smu) \
        ((smu)->ppt_funcs->set_tool_table_location ? (smu)->ppt_funcs->set_tool_table_location((smu)) : 0)
 #define smu_notify_memory_pool_location(smu) \
drivers/gpu/drm/amd/powerplay/smu_v11_0.c +18 -0
index 73935cf7ff39..79a63edcd7ba 100644
@@ -774,6 +774,24 @@ int smu_v11_0_set_min_dcef_deep_sleep(struct smu_context *smu)
        return smu_v11_0_set_deep_sleep_dcefclk(smu, table_context->boot_values.dcefclk / 100);
 }
 
+int smu_v11_0_set_driver_table_location(struct smu_context *smu)
+{
+       struct smu_table *driver_table = smu->smu_table.driver_table;
+       int ret = 0;
+
+       if (driver_table->mc_address) {
+               ret = smu_send_smc_msg_with_param(smu,
+                               SMU_MSG_SetDriverDramAddrHigh,
+                               upper_32_bits(driver_table->mc_address));
+               if (!ret)
+                       ret = smu_send_smc_msg_with_param(smu,
+                               SMU_MSG_SetDriverDramAddrLow,
+                               lower_32_bits(driver_table->mc_address));
+       }
+
+       return ret;
+}
+
 int smu_v11_0_set_tool_table_location(struct smu_context *smu)
 {
        int ret = 0;
drivers/gpu/drm/amd/powerplay/smu_v12_0.c +18 -0
index 2ac7f2f231b6..cd2be9fb2513 100644
@@ -514,3 +514,21 @@ int smu_v12_0_set_soft_freq_limited_range(struct smu_context *smu, enum smu_clk_
 
        return ret;
 }
+
+int smu_v12_0_set_driver_table_location(struct smu_context *smu)
+{
+       struct smu_table *driver_table = smu->smu_table.driver_table;
+       int ret = 0;
+
+       if (driver_table->mc_address) {
+               ret = smu_send_smc_msg_with_param(smu,
+                               SMU_MSG_SetDriverDramAddrHigh,
+                               upper_32_bits(driver_table->mc_address));
+               if (!ret)
+                       ret = smu_send_smc_msg_with_param(smu,
+                               SMU_MSG_SetDriverDramAddrLow,
+                               lower_32_bits(driver_table->mc_address));
+       }
+
+       return ret;
+}
drivers/gpu/drm/amd/powerplay/vega20_ppt.c +1 -1
index 534c46bc0146..12f97956058b 100644
@@ -3232,6 +3232,7 @@ static const struct pptable_funcs vega20_ppt_funcs = {
        .check_fw_version = smu_v11_0_check_fw_version,
        .write_pptable = smu_v11_0_write_pptable,
        .set_min_dcef_deep_sleep = smu_v11_0_set_min_dcef_deep_sleep,
+       .set_driver_table_location = smu_v11_0_set_driver_table_location,
        .set_tool_table_location = smu_v11_0_set_tool_table_location,
        .notify_memory_pool_location = smu_v11_0_notify_memory_pool_location,
        .system_features_control = smu_v11_0_system_features_control,
--

2.24.0

Quoted 4 lines

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx