[PATCH] drm/amdgpu: Fix missing parameter desc for 'xcc_id' in gfx_v7_0.c & amdgpu_rlc.c

2023-05-29 Thread Srinivasan Shanmugam
Fix these warnings by adding 'xcc_id' arguments.

gcc with W=1
drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c:1557: warning: Function parameter or 
member 'xcc_id' not described in 'gfx_v7_0_select_se_sh'
drivers/gpu/drm/amd/amdgpu/amdgpu_rlc.c:38: warning: Function parameter or 
member 'xcc_id' not described in 'amdgpu_gfx_rlc_enter_safe_mode'
drivers/gpu/drm/amd/amdgpu/amdgpu_rlc.c:62: warning: Function parameter or 
member 'xcc_id' not described in 'amdgpu_gfx_rlc_exit_safe_mode'

Cc: Christian König 
Cc: Alex Deucher 
Signed-off-by: Srinivasan Shanmugam 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_rlc.c | 2 ++
 drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c   | 2 +-
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_rlc.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_rlc.c
index d3bed9a3e61f..35e0ae9acadc 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_rlc.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_rlc.c
@@ -31,6 +31,7 @@
  * amdgpu_gfx_rlc_enter_safe_mode - Set RLC into safe mode
  *
  * @adev: amdgpu_device pointer
+ * @xcc_id: xcc accelerated compute core id
  *
  * Set RLC enter into safe mode if RLC is enabled and haven't in safe mode.
  */
@@ -55,6 +56,7 @@ void amdgpu_gfx_rlc_enter_safe_mode(struct amdgpu_device 
*adev, int xcc_id)
  * amdgpu_gfx_rlc_exit_safe_mode - Set RLC out of safe mode
  *
  * @adev: amdgpu_device pointer
+ * @xcc_id: xcc accelerated compute core id
  *
  * Set RLC exit safe mode if RLC is enabled and have entered into safe mode.
  */
diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c 
b/drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c
index 0f0c12bbe228..7b3f13221c0f 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c
@@ -1548,7 +1548,7 @@ static void gfx_v7_0_tiling_mode_table_init(struct 
amdgpu_device *adev)
  * @sh_num: sh block to address
  * @instance: Certain registers are instanced per SE or SH.
  *0x means broadcast to all SEs or SHs (CIK).
- *
+ * @xcc_id: xcc accelerated compute core id
  * Select which SE, SH combinations to address.
  */
 static void gfx_v7_0_select_se_sh(struct amdgpu_device *adev,
-- 
2.25.1



[PATCH] drm/amdgpu: Fix up missing parameters kdoc in svm_migrate_vma_to_ram

2023-05-29 Thread Srinivasan Shanmugam
Fix these warnings by adding & deleting the deviant arguments.

gcc with W=1
drivers/gpu/drm/amd/amdgpu/../amdkfd/kfd_migrate.c:671: warning: Function 
parameter or member 'node' not described in 'svm_migrate_vma_to_ram'
drivers/gpu/drm/amd/amdgpu/../amdkfd/kfd_migrate.c:671: warning: Function 
parameter or member 'trigger' not described in 'svm_migrate_vma_to_ram'
drivers/gpu/drm/amd/amdgpu/../amdkfd/kfd_migrate.c:671: warning: Function 
parameter or member 'fault_page' not described in 'svm_migrate_vma_to_ram'
drivers/gpu/drm/amd/amdgpu/../amdkfd/kfd_migrate.c:671: warning: Excess 
function parameter 'adev' description in 'svm_migrate_vma_to_ram'
drivers/gpu/drm/amd/amdgpu/../amdkfd/kfd_migrate.c:771: warning: Function 
parameter or member 'fault_page' not described in 'svm_migrate_vram_to_ram'

Cc: Christian König 
Cc: Alex Deucher 
Signed-off-by: Srinivasan Shanmugam 
---
 drivers/gpu/drm/amd/amdkfd/kfd_migrate.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c 
b/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c
index 35cf6558cf1b..58d95fb99595 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c
@@ -651,11 +651,13 @@ svm_migrate_copy_to_ram(struct amdgpu_device *adev, 
struct svm_range *prange,
 /**
  * svm_migrate_vma_to_ram - migrate range inside one vma from device to system
  *
- * @adev: amdgpu device to migrate from
  * @prange: svm range structure
  * @vma: vm_area_struct that range [start, end] belongs to
  * @start: range start virtual address in pages
  * @end: range end virtual address in pages
+ * @node: kfd node device to migrate from
+ * @trigger: reason of migration
+ * @fault_page: is from vmf->page, svm_migrate_to_ram(), this is CPU page 
fault callback
  *
  * Context: Process context, caller hold mmap read lock, prange->migrate_mutex
  *
@@ -760,6 +762,7 @@ svm_migrate_vma_to_ram(struct kfd_node *node, struct 
svm_range *prange,
  * @prange: range structure
  * @mm: process mm, use current->mm if NULL
  * @trigger: reason of migration
+ * @fault_page: is from vmf->page, svm_migrate_to_ram(), this is CPU page 
fault callback
  *
  * Context: Process context, caller hold mmap read lock, prange->migrate_mutex
  *
-- 
2.25.1



Re: [PATCH v4 13/13] drm/i915: Implement dedicated fbdev I/O helpers

2023-05-29 Thread Sui Jingfeng

Hi,

On 2023/5/30 03:36, Sam Ravnborg wrote:

Hi Thomas,

On Wed, May 24, 2023 at 11:21:50AM +0200, Thomas Zimmermann wrote:

Implement dedicated fbdev helpers for framebuffer I/O instead
of using DRM's helpers. Use an fbdev generator macro for
deferred I/O to create the fbdev callbacks. i915 was the only
caller of the DRM helpers, so remove them from the helper module.

i915's fbdev emulation is still incomplete as it doesn't implement
deferred I/O and damage handling for mmaped pages.

v4:
* generate deferred-I/O helpers
* use initializer macros for fb_ops
v2:
* use FB_IO_HELPERS options

Signed-off-by: Thomas Zimmermann 
Cc: Jani Nikula 
Cc: Joonas Lahtinen 
Cc: Rodrigo Vivi 
Cc: Tvrtko Ursulin 
Cc: "Ville Syrjälä" 
---
  drivers/gpu/drm/Kconfig|   3 -
  drivers/gpu/drm/drm_fb_helper.c| 107 -
  drivers/gpu/drm/i915/Kconfig   |   1 +
  drivers/gpu/drm/i915/display/intel_fbdev.c |  14 +--
  include/drm/drm_fb_helper.h|  39 
  5 files changed, 9 insertions(+), 155 deletions(-)

diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig
index 92a782827b7b..bb2e48cc6cd6 100644
--- a/drivers/gpu/drm/Kconfig
+++ b/drivers/gpu/drm/Kconfig
@@ -133,9 +133,6 @@ config DRM_FBDEV_EMULATION
bool "Enable legacy fbdev support for your modesetting driver"
depends on DRM_KMS_HELPER
depends on FB=y || FB=DRM_KMS_HELPER
-   select FB_CFB_FILLRECT
-   select FB_CFB_COPYAREA
-   select FB_CFB_IMAGEBLIT
select FRAMEBUFFER_CONSOLE if !EXPERT
select FRAMEBUFFER_CONSOLE_DETECT_PRIMARY if FRAMEBUFFER_CONSOLE
default y
diff --git a/drivers/gpu/drm/drm_fb_helper.c b/drivers/gpu/drm/drm_fb_helper.c
index bab6b252f02a..9978147bbc8a 100644
--- a/drivers/gpu/drm/drm_fb_helper.c
+++ b/drivers/gpu/drm/drm_fb_helper.c
@@ -736,113 +736,6 @@ void drm_fb_helper_deferred_io(struct fb_info *info, 
struct list_head *pagerefli
  }
  EXPORT_SYMBOL(drm_fb_helper_deferred_io);
  
-/**

- * drm_fb_helper_cfb_read - Implements struct _ops.fb_read for I/O memory
- * @info: fb_info struct pointer
- * @buf: userspace buffer to read from framebuffer memory
- * @count: number of bytes to read from framebuffer memory
- * @ppos: read offset within framebuffer memory
- *
- * Returns:
- * The number of bytes read on success, or an error code otherwise.
- */
-ssize_t drm_fb_helper_cfb_read(struct fb_info *info, char __user *buf,
-  size_t count, loff_t *ppos)
-{
-   return fb_io_read(info, buf, count, ppos);
-}
-EXPORT_SYMBOL(drm_fb_helper_cfb_read);
-
-/**
- * drm_fb_helper_cfb_write - Implements struct _ops.fb_write for I/O memory
- * @info: fb_info struct pointer
- * @buf: userspace buffer to write to framebuffer memory
- * @count: number of bytes to write to framebuffer memory
- * @ppos: write offset within framebuffer memory
- *
- * Returns:
- * The number of bytes written on success, or an error code otherwise.
- */
-ssize_t drm_fb_helper_cfb_write(struct fb_info *info, const char __user *buf,
-   size_t count, loff_t *ppos)
-{
-   struct drm_fb_helper *helper = info->par;
-   loff_t pos = *ppos;
-   ssize_t ret;
-   struct drm_rect damage_area;
-
-   ret = fb_io_write(info, buf, count, ppos);
-   if (ret <= 0)
-   return ret;
-
-   if (helper->funcs->fb_dirty) {
-   drm_fb_helper_memory_range_to_clip(info, pos, ret, 
_area);
-   drm_fb_helper_damage(helper, damage_area.x1, damage_area.y1,
-drm_rect_width(_area),
-drm_rect_height(_area));
-   }

The generated helpers do not have the if (helper->funcs->fb_dirty)
check.


Nice catch!

If I understand this correctly, fb_io_write() will write directly to the 
ultimate


destination. There no need to check if (helper->funcs->fb_dirty) anymore.

code inside the curly brace of  `if (helper->funcs->fb_dirty) { }`  can 
be delete safely .



This could turn out to be an optimization. This is a benefit of 
untangled implement.


previously this is a generic (tangled) implement, which intended to be 
used by both


the UMA device driver and non-UMA device(with dedicate VRAM) driver.


drm_fbdev_generic always has a shadow screen buffer allocated in system RAM,

 it always has the fb_dirty hooked, so this could be an optimization 
for fbdev_generic


by eliminate if (helper->funcs->fb_dirty) check.


while dma helper based driver could switch to drm_fbdev_dma, they writing

to gem buffer directly, no shadow buffer is needed.


With those patch, device driver with dedicated video memory can also 
choose FB_CFB_*


to update (iomem)framebuffer directly, despite slower.



Is this implemented somewhere else that I missed?

Sam


drm_fb_helper_fb_dirty() function has a check:

```

    if (drm_WARN_ON_ONCE(dev, !helper->funcs->fb_dirty))
    

[PATCH 9/9] drm/amd/pm: enable Wifi RFI mitigation feature support for SMU13.0.7

2023-05-29 Thread Evan Quan
Fulfill the SMU13.0.7 support for Wifi RFI mitigation feature.

Signed-off-by: Evan Quan 
--
v1->v2:
  - check wbrf support using pmfw version(Lijo)
v2->v3:
  - some minor fixes(Mario)
---
 .../drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c  | 61 +++
 1 file changed, 61 insertions(+)

diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c 
b/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c
index 98a33f8ee209..d885f20e33d7 100644
--- a/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c
+++ b/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c
@@ -125,6 +125,7 @@ static struct cmn2asic_msg_mapping 
smu_v13_0_7_message_map[SMU_MSG_MAX_COUNT] =
MSG_MAP(ArmD3,  PPSMC_MSG_ArmD3,
   0),
MSG_MAP(AllowGpo,   PPSMC_MSG_SetGpoAllow,  
 0),
MSG_MAP(GetPptLimit,PPSMC_MSG_GetPptLimit,  
   0),
+   MSG_MAP(EnableUCLKShadow,   PPSMC_MSG_EnableUCLKShadow, 
   0),
 };
 
 static struct cmn2asic_mapping smu_v13_0_7_clk_map[SMU_CLK_COUNT] = {
@@ -205,6 +206,7 @@ static struct cmn2asic_mapping 
smu_v13_0_7_table_map[SMU_TABLE_COUNT] = {
TAB_MAP(DRIVER_SMU_CONFIG),
TAB_MAP(ACTIVITY_MONITOR_COEFF),
[SMU_TABLE_COMBO_PPTABLE] = {1, TABLE_COMBO_PPTABLE},
+   TAB_MAP(WIFIBAND),
 };
 
 static struct cmn2asic_mapping smu_v13_0_7_pwr_src_map[SMU_POWER_SOURCE_COUNT] 
= {
@@ -487,6 +489,9 @@ static int smu_v13_0_7_tables_init(struct smu_context *smu)
   AMDGPU_GEM_DOMAIN_VRAM);
SMU_TABLE_INIT(tables, SMU_TABLE_COMBO_PPTABLE, 
MP0_MP1_DATA_REGION_SIZE_COMBOPPTABLE,
PAGE_SIZE, AMDGPU_GEM_DOMAIN_VRAM);
+   SMU_TABLE_INIT(tables, SMU_TABLE_WIFIBAND,
+  sizeof(WifiBandEntryTable_t), PAGE_SIZE,
+  AMDGPU_GEM_DOMAIN_VRAM);
 
smu_table->metrics_table = kzalloc(sizeof(SmuMetricsExternal_t), 
GFP_KERNEL);
if (!smu_table->metrics_table)
@@ -1721,6 +1726,59 @@ static int smu_v13_0_7_set_df_cstate(struct smu_context 
*smu,
   NULL);
 }
 
+static bool smu_v13_0_7_wbrf_support_check(struct smu_context *smu)
+{
+   return smu->smc_fw_version > 0x00524600;
+}
+
+static int smu_v13_0_7_set_wbrf_exclusion_ranges(struct smu_context *smu,
+struct exclusion_range 
*exclusion_ranges)
+{
+   WifiBandEntryTable_t wifi_bands;
+   uint64_t start_rounddown;
+   uint64_t end_roundup;
+   int valid_entries = 0;
+   int ret, i;
+
+   memset(_bands, 0, sizeof(wifi_bands));
+   for (i = 0; i < ARRAY_SIZE(wifi_bands.WifiBandEntry); i++) {
+   if (!exclusion_ranges[i].start &&
+   !exclusion_ranges[i].end)
+   break;
+
+   start_rounddown = rounddown(exclusion_ranges[i].start, 
HZ_IN_MHZ);
+   end_roundup = roundup(exclusion_ranges[i].end, HZ_IN_MHZ);
+   /* PMFW expects the inputs to be in Mhz unit */
+   wifi_bands.WifiBandEntry[valid_entries].LowFreq = 
HZ_TO_MHZ(start_rounddown);
+   wifi_bands.WifiBandEntry[valid_entries++].HighFreq = 
HZ_TO_MHZ(end_roundup);
+   }
+   wifi_bands.WifiBandEntryNum = valid_entries;
+
+   /*
+* Per confirm with PMFW team, WifiBandEntryNum = 0 is a valid setting.
+* Considering the scenarios below:
+* - At first the wifi device adds an exclusion range e.g. (2400,2500) 
to
+*   BIOS and our driver gets notified. We will set WifiBandEntryNum = 1
+*   and pass the WifiBandEntry (2400, 2500) to PMFW.
+*
+* - Later the wifi device removes the wifiband list added above and
+*   our driver gets notified again. At this time, driver will set
+*   WifiBandEntryNum = 0 and pass an empty WifiBandEntry list to PMFW.
+*   - PMFW may still need to do some uclk shadow update(e.g. switching
+* from shadow clock back to primary clock) on receiving this.
+*/
+
+   ret = smu_cmn_update_table(smu,
+  SMU_TABLE_WIFIBAND,
+  0,
+  (void *)(_bands),
+  true);
+   if (ret)
+   dev_err(smu->adev->dev, "Failed to set wifiband!");
+
+   return ret;
+}
+
 static const struct pptable_funcs smu_v13_0_7_ppt_funcs = {
.get_allowed_feature_mask = smu_v13_0_7_get_allowed_feature_mask,
.set_default_dpm_table = smu_v13_0_7_set_default_dpm_table,
@@ -1786,6 +1844,9 @@ static const struct pptable_funcs smu_v13_0_7_ppt_funcs = 
{
.set_mp1_state = smu_v13_0_7_set_mp1_state,
.set_df_cstate = smu_v13_0_7_set_df_cstate,
.gpo_control = smu_v13_0_gpo_control,
+   .is_asic_wbrf_supported = smu_v13_0_7_wbrf_support_check,
+   

[PATCH 8/9] drm/amd/pm: enable Wifi RFI mitigation feature support for SMU13.0.0

2023-05-29 Thread Evan Quan
Fulfill the SMU13.0.0 support for Wifi RFI mitigation feature.

Signed-off-by: Evan Quan 
--
v1->v2:
  - check the wbrf support using pmfw version(Lijo)
v2->v3:
  - some minor fixes(Mario)
---
 drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h |  4 ++
 drivers/gpu/drm/amd/pm/swsmu/inc/smu_types.h  |  3 +-
 drivers/gpu/drm/amd/pm/swsmu/inc/smu_v13_0.h  |  3 +
 .../gpu/drm/amd/pm/swsmu/smu13/smu_v13_0.c|  9 +++
 .../drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c  | 62 +++
 5 files changed, 80 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h 
b/drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h
index aa63cc43d41c..b71df196d047 100644
--- a/drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h
+++ b/drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h
@@ -323,6 +323,7 @@ enum smu_table_id
SMU_TABLE_PACE,
SMU_TABLE_ECCINFO,
SMU_TABLE_COMBO_PPTABLE,
+   SMU_TABLE_WIFIBAND,
SMU_TABLE_COUNT,
 };
 
@@ -1496,6 +1497,9 @@ enum smu_baco_seq {
 __dst_size);  \
 })
 
+#define HZ_IN_MHZ  100UL
+#define HZ_TO_MHZ(freq)((freq) / HZ_IN_MHZ)
+
 #if !defined(SWSMU_CODE_LAYER_L2) && !defined(SWSMU_CODE_LAYER_L3) && 
!defined(SWSMU_CODE_LAYER_L4)
 int smu_get_power_limit(void *handle,
uint32_t *limit,
diff --git a/drivers/gpu/drm/amd/pm/swsmu/inc/smu_types.h 
b/drivers/gpu/drm/amd/pm/swsmu/inc/smu_types.h
index 297b70b9388f..5bbb60289a79 100644
--- a/drivers/gpu/drm/amd/pm/swsmu/inc/smu_types.h
+++ b/drivers/gpu/drm/amd/pm/swsmu/inc/smu_types.h
@@ -245,7 +245,8 @@
__SMU_DUMMY_MAP(AllowGpo),  \
__SMU_DUMMY_MAP(Mode2Reset),\
__SMU_DUMMY_MAP(RequestI2cTransaction), \
-   __SMU_DUMMY_MAP(GetMetricsTable),
+   __SMU_DUMMY_MAP(GetMetricsTable), \
+   __SMU_DUMMY_MAP(EnableUCLKShadow),
 
 #undef __SMU_DUMMY_MAP
 #define __SMU_DUMMY_MAP(type)  SMU_MSG_##type
diff --git a/drivers/gpu/drm/amd/pm/swsmu/inc/smu_v13_0.h 
b/drivers/gpu/drm/amd/pm/swsmu/inc/smu_v13_0.h
index df3baaab0037..b6fae9b92303 100644
--- a/drivers/gpu/drm/amd/pm/swsmu/inc/smu_v13_0.h
+++ b/drivers/gpu/drm/amd/pm/swsmu/inc/smu_v13_0.h
@@ -303,5 +303,8 @@ int smu_v13_0_get_pptable_from_firmware(struct smu_context 
*smu,
uint32_t *size,
uint32_t pptable_id);
 
+int smu_v13_0_enable_uclk_shadow(struct smu_context *smu,
+bool enablement);
+
 #endif
 #endif
diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0.c 
b/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0.c
index 393c6a7b9609..8c2230d1d862 100644
--- a/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0.c
+++ b/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0.c
@@ -2453,3 +2453,12 @@ int smu_v13_0_mode1_reset(struct smu_context *smu)
 
return ret;
 }
+
+int smu_v13_0_enable_uclk_shadow(struct smu_context *smu,
+bool enablement)
+{
+   return smu_cmn_send_smc_msg_with_param(smu,
+  SMU_MSG_EnableUCLKShadow,
+  enablement,
+  NULL);
+}
diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c 
b/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c
index 09405ef1e3c8..c617046cb893 100644
--- a/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c
+++ b/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c
@@ -155,6 +155,7 @@ static struct cmn2asic_msg_mapping 
smu_v13_0_0_message_map[SMU_MSG_MAX_COUNT] =
MSG_MAP(AllowGpo,   PPSMC_MSG_SetGpoAllow,  
 0),
MSG_MAP(AllowIHHostInterrupt,   PPSMC_MSG_AllowIHHostInterrupt, 
  0),
MSG_MAP(ReenableAcDcInterrupt,  
PPSMC_MSG_ReenableAcDcInterrupt,   0),
+   MSG_MAP(EnableUCLKShadow,   PPSMC_MSG_EnableUCLKShadow, 
   0),
 };
 
 static struct cmn2asic_mapping smu_v13_0_0_clk_map[SMU_CLK_COUNT] = {
@@ -235,6 +236,7 @@ static struct cmn2asic_mapping 
smu_v13_0_0_table_map[SMU_TABLE_COUNT] = {
TAB_MAP(DRIVER_SMU_CONFIG),
TAB_MAP(ACTIVITY_MONITOR_COEFF),
[SMU_TABLE_COMBO_PPTABLE] = {1, TABLE_COMBO_PPTABLE},
+   TAB_MAP(WIFIBAND),
TAB_MAP(I2C_COMMANDS),
TAB_MAP(ECCINFO),
 };
@@ -472,6 +474,9 @@ static int smu_v13_0_0_tables_init(struct smu_context *smu)
PAGE_SIZE, AMDGPU_GEM_DOMAIN_VRAM);
SMU_TABLE_INIT(tables, SMU_TABLE_ECCINFO, sizeof(EccInfoTable_t),
PAGE_SIZE, AMDGPU_GEM_DOMAIN_VRAM);
+   SMU_TABLE_INIT(tables, SMU_TABLE_WIFIBAND,
+  sizeof(WifiBandEntryTable_t), PAGE_SIZE,
+  AMDGPU_GEM_DOMAIN_VRAM);
 
smu_table->metrics_table = kzalloc(sizeof(SmuMetricsExternal_t), 
GFP_KERNEL);
if (!smu_table->metrics_table)
@@ -2112,6 

[PATCH 7/9] drm/amd/pm: add flood detection for wbrf events

2023-05-29 Thread Evan Quan
To protect PMFW from being overloaded.

Signed-off-by: Evan Quan 
--
v1->v2:
  - utilize the delayed work(Lijo, Christian)
  - split the new module parameter changes out(Christian, Alex)
v2->v3:
  - simplify the flood detection further per latest design
v3->v4:
  - drop unneeded wbrf_mutex(Lijo, Christian)
  - use schedule_delayed_work() to avoid possible concurrent
access(Chrisitan)
---
 drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c | 28 ---
 drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h |  7 +
 2 files changed, 31 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c 
b/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c
index 89f876cc60e6..2619e310ef54 100644
--- a/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c
+++ b/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c
@@ -1272,6 +1272,22 @@ static void smu_wbrf_event_handler(struct amdgpu_device 
*adev)
 {
struct smu_context *smu = adev->powerplay.pp_handle;
 
+   schedule_delayed_work(>wbrf_delayed_work,
+ msecs_to_jiffies(SMU_WBRF_EVENT_HANDLING_PACE));
+}
+
+/**
+ * smu_wbrf_delayed_work_handler - callback on delayed work timer expired
+ *
+ * @work: struct work_struct pointer
+ *
+ * Flood is over and driver will consume the latest exclusion ranges.
+ */
+static void smu_wbrf_delayed_work_handler(struct work_struct *work)
+{
+   struct smu_context *smu =
+   container_of(work, struct smu_context, wbrf_delayed_work.work);
+
smu_wbrf_handle_exclusion_ranges(smu);
 }
 
@@ -1311,6 +1327,9 @@ static int smu_wbrf_init(struct smu_context *smu)
if (!smu->wbrf_supported)
return 0;
 
+   INIT_DELAYED_WORK(>wbrf_delayed_work,
+ smu_wbrf_delayed_work_handler);
+
ret = amdgpu_acpi_register_wbrf_notify_handler(adev,
   smu_wbrf_event_handler);
if (ret)
@@ -1321,11 +1340,10 @@ static int smu_wbrf_init(struct smu_context *smu)
 * before our driver loaded. To make sure our driver
 * is awared of those exclusion ranges.
 */
-   ret = smu_wbrf_handle_exclusion_ranges(smu);
-   if (ret)
-   dev_err(adev->dev, "Failed to handle wbrf exclusion ranges\n");
+   schedule_delayed_work(>wbrf_delayed_work,
+ msecs_to_jiffies(SMU_WBRF_EVENT_HANDLING_PACE));
 
-   return ret;
+   return 0;
 }
 
 /**
@@ -1343,6 +1361,8 @@ static void smu_wbrf_fini(struct smu_context *smu)
return;
 
amdgpu_acpi_unregister_wbrf_notify_handler(adev);
+
+   cancel_delayed_work_sync(>wbrf_delayed_work);
 }
 
 static int smu_smc_hw_setup(struct smu_context *smu)
diff --git a/drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h 
b/drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h
index ff0af3da0be2..aa63cc43d41c 100644
--- a/drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h
+++ b/drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h
@@ -478,6 +478,12 @@ struct stb_context {
 
 #define WORKLOAD_POLICY_MAX 7
 
+/*
+ * Configure wbrf event handling pace as there can be only one
+ * event processed every SMU_WBRF_EVENT_HANDLING_PACE ms.
+ */
+#define SMU_WBRF_EVENT_HANDLING_PACE   10
+
 struct smu_context
 {
struct amdgpu_device*adev;
@@ -576,6 +582,7 @@ struct smu_context
 
/* data structures for wbrf feature support */
boolwbrf_supported;
+   struct delayed_work wbrf_delayed_work;
 };
 
 struct i2c_adapter;
-- 
2.34.1



[PATCH 6/9] drm/amd/pm: setup the framework to support Wifi RFI mitigation feature

2023-05-29 Thread Evan Quan
With WBRF feature supported, as a driver responding to the frequencies,
amdgpu driver is able to do shadow pstate switching to mitigate possible
interference(between its (G-)DDR memory clocks and local radio module
frequency bands used by Wifi 6/6e/7).

To make WBRF feature functional, the kernel needs to be configured with
CONFIG_ACPI_WBRF and the platform is equipped with necessary ACPI based
mechanism to get amdgpu driver notified.

Signed-off-by: Evan Quan 
--
v1->v2:
  - move the implementations to swsmu(Lijo)
  - support runpm suspend/resume scenario(Lijo)
  - add missing mutex_destory(Mario)
v2->v3:
  - Per the latest designs, get those ACPI interfaces
needed by consumer(VGA) implemented in amdgpu_smu.c
v3->v4:
  - update the descriptions for parameter 'wbrf'(Alex)
v4->v5:
  - support CONFIG_ACPI_WBRF disabled scenario
  - correct the default setting for parameter `wbrf` as -1 (auto)(Alex)
v5->v6:
  - separate those ACPI related code into amdgpu_acpi.c
and acpi_wbrf.c
v6->v7:
  - wrap the document and modinfo for `wbrf` under
CONFIG_ACPI_WBRF(Mario)
v7->v8:
  - some minor fixes around error/information prompts(Mario)
---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h   |  26 +++
 drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c  |  63 ++
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c   |  19 ++
 drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c | 184 ++
 drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h |  20 ++
 drivers/gpu/drm/amd/pm/swsmu/smu_internal.h   |   3 +
 6 files changed, 315 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
index 02b827785e39..2f2ec64ed1b2 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
@@ -50,6 +50,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -241,6 +242,7 @@ extern int amdgpu_num_kcq;
 #define AMDGPU_VCNFW_LOG_SIZE (32 * 1024)
 extern int amdgpu_vcnfw_log;
 extern int amdgpu_sg_display;
+extern int amdgpu_wbrf;
 
 #define AMDGPU_VM_MAX_NUM_CTX  4096
 #define AMDGPU_SG_THRESHOLD(256*1024*1024)
@@ -741,6 +743,9 @@ struct amdgpu_reset_domain;
  */
 #define AMDGPU_HAS_VRAM(_adev) ((_adev)->gmc.real_vram_size)
 
+typedef
+void (*wbrf_notify_handler) (struct amdgpu_device *adev);
+
 struct amdgpu_device {
struct device   *dev;
struct pci_dev  *pdev;
@@ -1050,6 +1055,8 @@ struct amdgpu_device {
 
booljob_hang;
booldc_enabled;
+
+   wbrf_notify_handler wbrf_event_handler;
 };
 
 static inline struct amdgpu_device *drm_to_adev(struct drm_device *ddev)
@@ -1381,6 +1388,25 @@ static inline int amdgpu_acpi_smart_shift_update(struct 
drm_device *dev,
 enum amdgpu_ss ss_state) { 
return 0; }
 #endif
 
+#if defined(CONFIG_ACPI_WBRF)
+bool amdgpu_acpi_is_wbrf_supported(struct amdgpu_device *adev);
+int amdgpu_acpi_wbrf_retrieve_exclusions(struct amdgpu_device *adev,
+struct wbrf_ranges_out 
*exclusions_out);
+int amdgpu_acpi_register_wbrf_notify_handler(struct amdgpu_device *adev,
+wbrf_notify_handler handler);
+int amdgpu_acpi_unregister_wbrf_notify_handler(struct amdgpu_device *adev);
+#else
+static inline bool amdgpu_acpi_is_wbrf_supported(struct amdgpu_device *adev) { 
return false; }
+static inline
+int amdgpu_acpi_wbrf_retrieve_exclusions(struct amdgpu_device *adev,
+struct wbrf_ranges_out 
*exclusions_out) { return 0; }
+static inline
+int amdgpu_acpi_register_wbrf_notify_handler(struct amdgpu_device *adev,
+wbrf_notify_handler handler) { 
return 0; }
+static inline
+int amdgpu_acpi_unregister_wbrf_notify_handler(struct amdgpu_device *adev) { 
return 0; }
+#endif
+
 #if defined(CONFIG_ACPI) && defined(CONFIG_SUSPEND)
 bool amdgpu_acpi_is_s3_active(struct amdgpu_device *adev);
 bool amdgpu_acpi_is_s0ix_active(struct amdgpu_device *adev);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c
index aeeec211861c..efbe6dd91d1a 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c
@@ -1105,3 +1105,66 @@ bool amdgpu_acpi_is_s0ix_active(struct amdgpu_device 
*adev)
 }
 
 #endif /* CONFIG_SUSPEND */
+
+#ifdef CONFIG_ACPI_WBRF
+bool amdgpu_acpi_is_wbrf_supported(struct amdgpu_device *adev)
+{
+   struct acpi_device *acpi_dev = ACPI_COMPANION(adev->dev);
+
+   if (!acpi_dev)
+   return false;
+
+   return wbrf_supported_consumer(acpi_dev);
+}
+
+int amdgpu_acpi_wbrf_retrieve_exclusions(struct amdgpu_device *adev,
+struct wbrf_ranges_out *exclusions_out)
+{
+   struct acpi_device *acpi_dev = 

[PATCH 5/9] drm/amd/pm: update driver_if and ppsmc headers for coming wbrf feature

2023-05-29 Thread Evan Quan
Add those data structures to support Wifi RFI mitigation feature.

Signed-off-by: Evan Quan 
--
v1->v2:
  - update smu_v13_0_7_ppsmc.h to fit latest messages definitions
---
 .../pm/swsmu/inc/pmfw_if/smu13_driver_if_v13_0_0.h | 14 +-
 .../pm/swsmu/inc/pmfw_if/smu13_driver_if_v13_0_7.h | 14 +-
 .../amd/pm/swsmu/inc/pmfw_if/smu_v13_0_0_ppsmc.h   |  3 ++-
 .../amd/pm/swsmu/inc/pmfw_if/smu_v13_0_7_ppsmc.h   |  3 ++-
 4 files changed, 30 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/amd/pm/swsmu/inc/pmfw_if/smu13_driver_if_v13_0_0.h 
b/drivers/gpu/drm/amd/pm/swsmu/inc/pmfw_if/smu13_driver_if_v13_0_0.h
index b686fb68a6e7..d64188fb5839 100644
--- a/drivers/gpu/drm/amd/pm/swsmu/inc/pmfw_if/smu13_driver_if_v13_0_0.h
+++ b/drivers/gpu/drm/amd/pm/swsmu/inc/pmfw_if/smu13_driver_if_v13_0_0.h
@@ -388,6 +388,17 @@ typedef struct {
   EccInfo_t  EccInfo[24];
 } EccInfoTable_t;
 
+typedef struct {
+  uint16_t LowFreq;
+  uint16_t HighFreq;
+} WifiOneBand_t;
+
+typedef struct {
+  uint32_t WifiBandEntryNum;
+  WifiOneBand_tWifiBandEntry[11];
+  uint32_t MmHubPadding[8];
+} WifiBandEntryTable_t;
+
 //D3HOT sequences
 typedef enum {
   BACO_SEQUENCE,
@@ -1592,7 +1603,8 @@ typedef struct {
 #define TABLE_I2C_COMMANDS9
 #define TABLE_DRIVER_INFO 10
 #define TABLE_ECCINFO 11
-#define TABLE_COUNT   12
+#define TABLE_WIFIBAND12
+#define TABLE_COUNT   13
 
 //IH Interupt ID
 #define IH_INTERRUPT_ID_TO_DRIVER   0xFE
diff --git a/drivers/gpu/drm/amd/pm/swsmu/inc/pmfw_if/smu13_driver_if_v13_0_7.h 
b/drivers/gpu/drm/amd/pm/swsmu/inc/pmfw_if/smu13_driver_if_v13_0_7.h
index 4c46a0392451..77483e8485e7 100644
--- a/drivers/gpu/drm/amd/pm/swsmu/inc/pmfw_if/smu13_driver_if_v13_0_7.h
+++ b/drivers/gpu/drm/amd/pm/swsmu/inc/pmfw_if/smu13_driver_if_v13_0_7.h
@@ -392,6 +392,17 @@ typedef struct {
   EccInfo_t  EccInfo[24];
 } EccInfoTable_t;
 
+typedef struct {
+  uint16_t LowFreq;
+  uint16_t HighFreq;
+} WifiOneBand_t;
+
+typedef struct {
+  uint32_t WifiBandEntryNum;
+  WifiOneBand_tWifiBandEntry[11];
+  uint32_t MmHubPadding[8];
+} WifiBandEntryTable_t;
+
 //D3HOT sequences
 typedef enum {
   BACO_SEQUENCE,
@@ -1624,7 +1635,8 @@ typedef struct {
 #define TABLE_I2C_COMMANDS9
 #define TABLE_DRIVER_INFO 10
 #define TABLE_ECCINFO 11
-#define TABLE_COUNT   12
+#define TABLE_WIFIBAND12
+#define TABLE_COUNT   13
 
 //IH Interupt ID
 #define IH_INTERRUPT_ID_TO_DRIVER   0xFE
diff --git a/drivers/gpu/drm/amd/pm/swsmu/inc/pmfw_if/smu_v13_0_0_ppsmc.h 
b/drivers/gpu/drm/amd/pm/swsmu/inc/pmfw_if/smu_v13_0_0_ppsmc.h
index 10cff75b44d5..c98cc32d11bd 100644
--- a/drivers/gpu/drm/amd/pm/swsmu/inc/pmfw_if/smu_v13_0_0_ppsmc.h
+++ b/drivers/gpu/drm/amd/pm/swsmu/inc/pmfw_if/smu_v13_0_0_ppsmc.h
@@ -138,7 +138,8 @@
 #define PPSMC_MSG_SetBadMemoryPagesRetiredFlagsPerChannel 0x4A
 #define PPSMC_MSG_SetPriorityDeltaGain   0x4B
 #define PPSMC_MSG_AllowIHHostInterrupt   0x4C
-#define PPSMC_Message_Count  0x4D
+#define PPSMC_MSG_EnableUCLKShadow   0x51
+#define PPSMC_Message_Count  0x52
 
 //Debug Dump Message
 #define DEBUGSMC_MSG_TestMessage0x1
diff --git a/drivers/gpu/drm/amd/pm/swsmu/inc/pmfw_if/smu_v13_0_7_ppsmc.h 
b/drivers/gpu/drm/amd/pm/swsmu/inc/pmfw_if/smu_v13_0_7_ppsmc.h
index 6aaefca9b595..a6bf9cdd130e 100644
--- a/drivers/gpu/drm/amd/pm/swsmu/inc/pmfw_if/smu_v13_0_7_ppsmc.h
+++ b/drivers/gpu/drm/amd/pm/swsmu/inc/pmfw_if/smu_v13_0_7_ppsmc.h
@@ -134,6 +134,7 @@
 #define PPSMC_MSG_SetBadMemoryPagesRetiredFlagsPerChannel 0x4A
 #define PPSMC_MSG_SetPriorityDeltaGain   0x4B
 #define PPSMC_MSG_AllowIHHostInterrupt   0x4C
-#define PPSMC_Message_Count  0x4D
+#define PPSMC_MSG_EnableUCLKShadow   0x51
+#define PPSMC_Message_Count  0x52
 
 #endif
-- 
2.34.1



[PATCH 4/9] wifi: ath12k: Add support to the Qualcomm ath12k for ACPI WBRF

2023-05-29 Thread Evan Quan
Qualcomm wifi adapters are utilized in systems that support AMD's WBRF
interference mitigation mechanism. For this mechanism to work frequencies
utilized use must be notified to an ACPI device.

If the kernel is configured with CONFIG_ACPI_WBRF then notify this ACPI
device accordingly.

Change based on code review, not tested due to lack of hardware.

Signed-off-by: Evan Quan 
---
v1->v2:
  - drop unnecessary EXPORT_SYMBOL_GPL(Mario)
---
 drivers/net/wireless/ath/ath12k/core.c | 21 +
 drivers/net/wireless/ath/ath12k/core.h | 14 ++
 drivers/net/wireless/ath/ath12k/mac.c  |  4 
 drivers/net/wireless/ath/ath12k/pci.c  |  3 +++
 4 files changed, 42 insertions(+)

diff --git a/drivers/net/wireless/ath/ath12k/core.c 
b/drivers/net/wireless/ath/ath12k/core.c
index a89e66653f04..fde811524756 100644
--- a/drivers/net/wireless/ath/ath12k/core.c
+++ b/drivers/net/wireless/ath/ath12k/core.c
@@ -14,6 +14,7 @@
 #include "dp_rx.h"
 #include "debug.h"
 #include "hif.h"
+#include "../ath.h"
 
 unsigned int ath12k_debug_mask;
 module_param_named(debug_mask, ath12k_debug_mask, uint, 0644);
@@ -935,5 +936,25 @@ struct ath12k_base *ath12k_core_alloc(struct device *dev, 
size_t priv_size,
return NULL;
 }
 
+#if defined(CONFIG_ACPI_WBRF)
+int ath12k_add_wbrf(struct ath12k_base *ab,
+   struct cfg80211_chan_def *chandef)
+{
+   if (!ab->wbrf)
+   return 0;
+
+   return ath_add_wbrf(ab->dev, chandef);
+}
+
+int ath12k_remove_wbrf(struct ath12k_base *ab,
+  struct cfg80211_chan_def *chandef)
+{
+   if (!ab->wbrf)
+   return 0;
+
+   return ath_remove_wbrf(ab->dev, chandef);
+}
+#endif
+
 MODULE_DESCRIPTION("Core module for Qualcomm Atheros 802.11be wireless LAN 
cards.");
 MODULE_LICENSE("Dual BSD/GPL");
diff --git a/drivers/net/wireless/ath/ath12k/core.h 
b/drivers/net/wireless/ath/ath12k/core.h
index 9439052a652e..53ffb679b5c1 100644
--- a/drivers/net/wireless/ath/ath12k/core.h
+++ b/drivers/net/wireless/ath/ath12k/core.h
@@ -736,6 +736,8 @@ struct ath12k_base {
u64 fw_soc_drop_count;
bool static_window_map;
 
+   bool wbrf;
+
/* must be last */
u8 drv_priv[] __aligned(sizeof(void *));
 };
@@ -820,4 +822,16 @@ static inline const char *ath12k_bus_str(enum ath12k_bus 
bus)
return "unknown";
 }
 
+#ifdef CONFIG_ACPI_WBRF
+int ath12k_add_wbrf(struct ath12k_base *ab, struct cfg80211_chan_def *chandef);
+int ath12k_remove_wbrf(struct ath12k_base *ab, struct cfg80211_chan_def 
*chandef);
+#else
+static inline
+int ath12k_add_wbrf(struct ath12k_base *ab,
+   struct cfg80211_chan_def *chandef) { return 0; }
+static inline
+int ath12k_remove_wbrf(struct ath12k_base *ab0,
+  struct cfg80211_chan_def *chandef) { return 0; }
+#endif /* CONFIG_ACPI_WBRF */
+
 #endif /* _CORE_H_ */
diff --git a/drivers/net/wireless/ath/ath12k/mac.c 
b/drivers/net/wireless/ath/ath12k/mac.c
index ee792822b411..999354d60228 100644
--- a/drivers/net/wireless/ath/ath12k/mac.c
+++ b/drivers/net/wireless/ath/ath12k/mac.c
@@ -5396,6 +5396,8 @@ static int ath12k_mac_op_add_chanctx(struct ieee80211_hw 
*hw,
 
mutex_lock(>conf_mutex);
 
+   ath12k_add_wbrf(ab, >def);
+
spin_lock_bh(>data_lock);
/* TODO: In case of multiple channel context, populate rx_channel from
 * Rx PPDU desc information.
@@ -5420,6 +5422,8 @@ static void ath12k_mac_op_remove_chanctx(struct 
ieee80211_hw *hw,
 
mutex_lock(>conf_mutex);
 
+   ath12k_remove_wbrf(ab, >def);
+
spin_lock_bh(>data_lock);
/* TODO: In case of there is one more channel context left, populate
 * rx_channel with the channel of that remaining channel context.
diff --git a/drivers/net/wireless/ath/ath12k/pci.c 
b/drivers/net/wireless/ath/ath12k/pci.c
index 9f174daf324c..544d93d66d69 100644
--- a/drivers/net/wireless/ath/ath12k/pci.c
+++ b/drivers/net/wireless/ath/ath12k/pci.c
@@ -13,6 +13,7 @@
 #include "hif.h"
 #include "mhi.h"
 #include "debug.h"
+#include "../ath.h"
 
 #define ATH12K_PCI_BAR_NUM 0
 #define ATH12K_PCI_DMA_MASK32
@@ -1272,6 +1273,8 @@ static int ath12k_pci_probe(struct pci_dev *pdev,
goto err_ce_free;
}
 
+   ab->wbrf = ath_check_wbrf_support(ab->dev);
+
ret = ath12k_core_init(ab);
if (ret) {
ath12k_err(ab, "failed to init core: %d\n", ret);
-- 
2.34.1



[PATCH 3/9] wifi: ath11k: Add support to the Qualcomm ath11k for ACPI WBRF

2023-05-29 Thread Evan Quan
From: Anson Tsao 

Qualcomm wifi adapters are utilized in systems that support AMD's WBRF
interference mitigation mechanism. For this mechanism to work frequencies
utilized use must be notified to an ACPI device.

If the kernel is configured with CONFIG_ACPI_WBRF then notify this ACPI
device accordingly.

Tested-on: WCN6855 hw2.0 PCI 
WLAN.HSP.1.1-03125-QCAHSPSWPL_V1_V2_SILICONZ_LITE-3.6510.23

Signed-off-by: Anson Tsao 
Signed-off-by: Evan Quan 
Co-developed-by: Evan Quan 
--
v1->v2:
  - Fix possible NULL pointer dereference caused by ar->hw->conf.chandef.chan
v2->v3:
  - correct the timing for `ath11k_add_wbrf` and `ath11k_remove_wbrf`
calling
---
 drivers/net/wireless/ath/Makefile  |  1 +
 drivers/net/wireless/ath/acpi_wbrf.c   | 45 ++
 drivers/net/wireless/ath/ath.h | 15 +
 drivers/net/wireless/ath/ath11k/core.c | 23 +
 drivers/net/wireless/ath/ath11k/core.h | 14 
 drivers/net/wireless/ath/ath11k/mac.c  |  4 +++
 drivers/net/wireless/ath/ath11k/pci.c  |  3 ++
 7 files changed, 105 insertions(+)
 create mode 100644 drivers/net/wireless/ath/acpi_wbrf.c

diff --git a/drivers/net/wireless/ath/Makefile 
b/drivers/net/wireless/ath/Makefile
index 8d6e6e218d24..234e904bdfa9 100644
--- a/drivers/net/wireless/ath/Makefile
+++ b/drivers/net/wireless/ath/Makefile
@@ -21,5 +21,6 @@ ath-objs :=   main.o \
 
 ath-$(CONFIG_ATH_DEBUG) += debug.o
 ath-$(CONFIG_ATH_TRACEPOINTS) += trace.o
+ath-$(CONFIG_ACPI_WBRF) += acpi_wbrf.o
 
 CFLAGS_trace.o := -I$(src)
diff --git a/drivers/net/wireless/ath/acpi_wbrf.c 
b/drivers/net/wireless/ath/acpi_wbrf.c
new file mode 100644
index ..98b3416eca4d
--- /dev/null
+++ b/drivers/net/wireless/ath/acpi_wbrf.c
@@ -0,0 +1,45 @@
+// SPDX-License-Identifier: ISC
+/* Copyright (C) 2023 Advanced Micro Devices */
+
+#include 
+#include "ath.h"
+
+bool ath_check_wbrf_support(struct device *dev)
+{
+   struct acpi_device *acpi_dev = ACPI_COMPANION(dev);
+   bool wbrf_supported;
+
+   if (!acpi_dev) {
+   dev_dbg(dev, "ACPI companion not found\n");
+   return false;
+   }
+
+   wbrf_supported = wbrf_supported_producer(acpi_dev);
+   dev_dbg(dev, "WBRF is %s supported\n",
+   wbrf_supported ? "" : "not");
+
+   return wbrf_supported;
+}
+EXPORT_SYMBOL_GPL(ath_check_wbrf_support);
+
+int ath_add_wbrf(struct device *dev, struct cfg80211_chan_def *chandef)
+{
+   struct acpi_device *acpi_dev = ACPI_COMPANION(dev);
+
+   if (!acpi_dev)
+   return -ENODEV;
+
+   return wbrf_add_exclusion_wlan(acpi_dev, chandef);
+}
+EXPORT_SYMBOL_GPL(ath_add_wbrf);
+
+int ath_remove_wbrf(struct device *dev, struct cfg80211_chan_def *chandef)
+{
+   struct acpi_device *acpi_dev = ACPI_COMPANION(dev);
+
+   if (!acpi_dev)
+   return -ENODEV;
+
+   return wbrf_remove_exclusion_wlan(acpi_dev, chandef);
+}
+EXPORT_SYMBOL_GPL(ath_remove_wbrf);
diff --git a/drivers/net/wireless/ath/ath.h b/drivers/net/wireless/ath/ath.h
index f02a308a9ffc..c9f5c9a67c0a 100644
--- a/drivers/net/wireless/ath/ath.h
+++ b/drivers/net/wireless/ath/ath.h
@@ -334,4 +334,19 @@ static inline const char *ath_bus_type_to_string(enum 
ath_bus_type bustype)
return ath_bus_type_strings[bustype];
 }
 
+#ifdef CONFIG_ACPI_WBRF
+bool ath_check_wbrf_support(struct device *dev);
+int ath_add_wbrf(struct device *dev, struct cfg80211_chan_def *chandef);
+int ath_remove_wbrf(struct device *dev, struct cfg80211_chan_def *chandef);
+#else
+static inline
+bool ath_check_wbrf_support(struct device *dev) { return false; }
+static inline
+int ath_add_wbrf(struct device *dev,
+struct cfg80211_chan_def *chandef) { return 0; }
+static inline
+int ath_remove_wbrf(struct device *dev,
+   struct cfg80211_chan_def *chandef) { return 0; }
+#endif
+
 #endif /* ATH_H */
diff --git a/drivers/net/wireless/ath/ath11k/core.c 
b/drivers/net/wireless/ath/ath11k/core.c
index b1b90bd34d67..1f1eed9c8ae7 100644
--- a/drivers/net/wireless/ath/ath11k/core.c
+++ b/drivers/net/wireless/ath/ath11k/core.c
@@ -16,6 +16,7 @@
 #include "debug.h"
 #include "hif.h"
 #include "wow.h"
+#include "../ath.h"
 
 unsigned int ath11k_debug_mask;
 EXPORT_SYMBOL(ath11k_debug_mask);
@@ -2035,5 +2036,27 @@ struct ath11k_base *ath11k_core_alloc(struct device 
*dev, size_t priv_size,
 }
 EXPORT_SYMBOL(ath11k_core_alloc);
 
+#if defined(CONFIG_ACPI_WBRF)
+int ath11k_add_wbrf(struct ath11k_base *ab,
+   struct cfg80211_chan_def *chandef)
+{
+   if (!ab->wbrf)
+   return 0;
+
+   return ath_add_wbrf(ab->dev, chandef);
+}
+EXPORT_SYMBOL_GPL(ath11k_add_wbrf);
+
+int ath11k_remove_wbrf(struct ath11k_base *ab,
+  struct cfg80211_chan_def *chandef)
+{
+   if (!ab->wbrf)
+   return 0;
+
+   return ath_remove_wbrf(ab->dev, chandef);
+}
+EXPORT_SYMBOL_GPL(ath11k_remove_wbrf);
+#endif
+
 MODULE_DESCRIPTION("Core module for 

[PATCH 2/9] mt76: Add support to the Mediatek MT7921 for ACPI WBRF

2023-05-29 Thread Evan Quan
From: Mario Limonciello 

Mediatek wifi adapters are utilized in systems that support AMD's WBRF
interference mitigation mechanism. For this mechanism to work frequencies
utilized use must be notified to an ACPI device.

If the kernel is configured with CONFIG_ACPI_WBRF then notify this ACPI
device accordingly.

Signed-off-by: Mario Limonciello 
Signed-off-by: Anson Taso 
Co-developed-by: Anson Taso 
--
v1->v2:
  - Fix build errors below for mt76 w/ WBRF enabled
ERROR: modpost: "mt76_add_wbrf" 
[drivers/net/wireless/mediatek/mt76/mt76x2/mt76x2e.ko] undefined!
ERROR: modpost: "mt76_remove_wbrf" 
[drivers/net/wireless/mediatek/mt76/mt76x2/mt76x2e.ko] undefined!
ERROR: modpost: "mt76_init_acpi_wbrf" 
[drivers/net/wireless/mediatek/mt76/mt7921/mt7921-common.ko] undefined!
v2->v3:
  - add support to the real driver(mt7921/main.c) which supports
Mediatek MT7921
---
 drivers/net/wireless/mediatek/mt76/Makefile   |  1 +
 .../net/wireless/mediatek/mt76/acpi_wbrf.c| 36 +++
 drivers/net/wireless/mediatek/mt76/mt76.h | 19 ++
 .../net/wireless/mediatek/mt76/mt7921/init.c  |  2 ++
 .../net/wireless/mediatek/mt76/mt7921/main.c  |  3 ++
 5 files changed, 61 insertions(+)
 create mode 100644 drivers/net/wireless/mediatek/mt76/acpi_wbrf.c

diff --git a/drivers/net/wireless/mediatek/mt76/Makefile 
b/drivers/net/wireless/mediatek/mt76/Makefile
index 84c99b7e57f9..c016c71f23bd 100644
--- a/drivers/net/wireless/mediatek/mt76/Makefile
+++ b/drivers/net/wireless/mediatek/mt76/Makefile
@@ -12,6 +12,7 @@ mt76-y := \
 
 mt76-$(CONFIG_PCI) += pci.o
 mt76-$(CONFIG_NL80211_TESTMODE) += testmode.o
+mt76-$(CONFIG_ACPI_WBRF) += acpi_wbrf.o
 
 mt76-usb-y := usb.o usb_trace.o
 mt76-sdio-y := sdio.o sdio_txrx.o
diff --git a/drivers/net/wireless/mediatek/mt76/acpi_wbrf.c 
b/drivers/net/wireless/mediatek/mt76/acpi_wbrf.c
new file mode 100644
index ..ceef57bddc6f
--- /dev/null
+++ b/drivers/net/wireless/mediatek/mt76/acpi_wbrf.c
@@ -0,0 +1,36 @@
+// SPDX-License-Identifier: ISC
+/* Copyright (C) 2023 Advanced Micro Devices */
+
+#include 
+#include "mt76.h"
+
+#if defined(CONFIG_ACPI_WBRF)
+void mt76_init_acpi_wbrf(struct mt76_dev *dev)
+{
+   struct acpi_device *acpi_dev = ACPI_COMPANION(dev->dev);
+
+   if (!acpi_dev) {
+   dev_dbg(dev->dev, "ACPI companion not found\n");
+   return;
+   }
+
+   dev->phy.wbrf = wbrf_supported_producer(acpi_dev);
+   dev_dbg(dev->dev, "WBRF is %s supported\n",
+   dev->phy.wbrf ? "" : "not");
+}
+EXPORT_SYMBOL_GPL(mt76_init_acpi_wbrf);
+int mt76_add_wbrf(struct mt76_dev *dev, struct cfg80211_chan_def *chandef)
+{
+   if (!dev->phy.wbrf)
+   return 0;
+   return wbrf_add_exclusion_wlan(ACPI_COMPANION(dev->dev), chandef);
+}
+EXPORT_SYMBOL_GPL(mt76_add_wbrf);
+int mt76_remove_wbrf(struct mt76_dev *dev, struct cfg80211_chan_def *chandef)
+{
+   if (!dev->phy.wbrf)
+   return 0;
+   return wbrf_remove_exclusion_wlan(ACPI_COMPANION(dev->dev), chandef);
+}
+EXPORT_SYMBOL_GPL(mt76_remove_wbrf);
+#endif
diff --git a/drivers/net/wireless/mediatek/mt76/mt76.h 
b/drivers/net/wireless/mediatek/mt76/mt76.h
index 6b07b8fafec2..fd33a553ba2e 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76.h
+++ b/drivers/net/wireless/mediatek/mt76/mt76.h
@@ -733,6 +733,7 @@ struct mt76_phy {
int txpower_cur;
u8 antenna_mask;
u16 chainmask;
+   bool wbrf;
 
 #ifdef CONFIG_NL80211_TESTMODE
struct mt76_testmode_data test;
@@ -1511,4 +1512,22 @@ mt76_packet_id_flush(struct mt76_dev *dev, struct 
mt76_wcid *wcid)
idr_destroy(>pktid);
 }
 
+#ifdef CONFIG_ACPI_WBRF
+void mt76_init_acpi_wbrf(struct mt76_dev *dev);
+int mt76_add_wbrf(struct mt76_dev *dev, struct cfg80211_chan_def *chandef);
+int mt76_remove_wbrf(struct mt76_dev *dev, struct cfg80211_chan_def *chandef);
+#else
+static inline void mt76_init_acpi_wbrf(struct mt76_dev *dev) { };
+static inline int
+mt76_add_wbrf(struct mt76_dev *dev, struct cfg80211_chan_def *chandef)
+{
+   return 0;
+}
+static inline int
+mt76_remove_wbrf(struct mt76_dev *dev, struct cfg80211_chan_def *chandef)
+{
+   return 0;
+}
+#endif /* CONFIG_ACPI_WBRF */
+
 #endif
diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/init.c 
b/drivers/net/wireless/mediatek/mt76/mt7921/init.c
index bf1da9fddfab..91396139a177 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7921/init.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7921/init.c
@@ -420,6 +420,8 @@ int mt7921_register_device(struct mt7921_dev *dev)
 
mt7921_init_acpi_sar(dev);
 
+   mt76_init_acpi_wbrf(>mt76);
+
ret = mt7921_init_wcid(dev);
if (ret)
return ret;
diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/main.c 
b/drivers/net/wireless/mediatek/mt76/mt7921/main.c
index 3b6adb29cbef..241d5b1729dd 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7921/main.c
+++ 

[PATCH 1/9] drivers/acpi: Add support for Wifi band RF mitigations

2023-05-29 Thread Evan Quan
From: Mario Limonciello 

Due to electrical and mechanical constraints in certain platform designs
there may be likely interference of relatively high-powered harmonics of
the (G-)DDR memory clocks with local radio module frequency bands used
by Wifi 6/6e/7.

To mitigate this, AMD has introduced an ACPI based mechanism that
devices can use to notify active use of particular frequencies so
that devices can make relative internal adjustments as necessary
to avoid this resonance.

In order for a device to support this, the expected flow for device
driver or subsystems:

Drivers/subsystems contributing frequencies:

1) During probe, check `wbrf_supported_producer` to see if WBRF supported
   for the device.
2) If adding frequencies, then call `wbrf_add_exclusion` with the
   start and end ranges of the frequencies. For net/wireless subsystem
   specifically, `wbrf_add_exclusion_wlan` can be used instead.
3) If removing frequencies, then call `wbrf_remove_exclusion` with
   start and end ranges of the frequencies. For net/wireless subsystem
   specifically, `wbrf_remove_exclusion_wlan` can be used instead.

Drivers/subsystems responding to frequencies:

1) During probe, check `wbrf_supported_consumer` to see if WBRF is supported
   for the device.
2) Call the `wbrf_retrieve_exclusions` to retrieve the current
   exclusions on receiving an ACPI notification for a new frequency
   change.

Signed-off-by: Mario Limonciello 
Co-developed-by: Evan Quan 
Signed-off-by: Evan Quan 
--
v1->v2:
  - update wifi_acpi_dsm_guid and wbrf_record to fit latest designs
  - the frequency range fed to BIOS is expected to be in HZ unit
v2->v3:
  - correct the algorithm for frequency range start and end point
calculation
  - drop unneeded notifier register/unregister APIs
v3->v4:
  - concentrate all wbrf ACPI related code in acpi_wbrf.c
v4->v5:
  - typo and some other minor fixes(Mario)
v5->v6:
  - correct the calculations around start/end frequency points
v6->v7:
  - correct the data type for arg3 to fit ACPI spce
---
 drivers/acpi/Kconfig |   7 +
 drivers/acpi/Makefile|   2 +
 drivers/acpi/acpi_wbrf.c | 343 +++
 include/linux/wbrf.h |  70 
 4 files changed, 422 insertions(+)
 create mode 100644 drivers/acpi/acpi_wbrf.c
 create mode 100644 include/linux/wbrf.h

diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig
index ccbeab9500ec..9ee7c7dcc3e6 100644
--- a/drivers/acpi/Kconfig
+++ b/drivers/acpi/Kconfig
@@ -611,3 +611,10 @@ config X86_PM_TIMER
 
  You should nearly always say Y here because many modern
  systems require this timer.
+
+config ACPI_WBRF
+   bool "ACPI Wifi band RF mitigation mechanism"
+   help
+ Wifi band RF mitigation mechanism allows multiple drivers from
+ different domains to notify the frequencies in use so that hardware
+ can be reconfigured to avoid harmonic conflicts.
\ No newline at end of file
diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile
index feb36c0b9446..be173e76aa62 100644
--- a/drivers/acpi/Makefile
+++ b/drivers/acpi/Makefile
@@ -131,3 +131,5 @@ obj-y   += dptf/
 obj-$(CONFIG_ARM64)+= arm64/
 
 obj-$(CONFIG_ACPI_VIOT)+= viot.o
+
+obj-$(CONFIG_ACPI_WBRF)+= acpi_wbrf.o
\ No newline at end of file
diff --git a/drivers/acpi/acpi_wbrf.c b/drivers/acpi/acpi_wbrf.c
new file mode 100644
index ..bf8e0ed73072
--- /dev/null
+++ b/drivers/acpi/acpi_wbrf.c
@@ -0,0 +1,343 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * AMD Wifi Band Exclusion Interface
+ * Copyright (C) 2023 Advanced Micro Devices
+ *
+ */
+
+#include 
+
+/* functions */
+#define WBRF_RECORD0x1
+#define WBRF_RETRIEVE  0x2
+
+/* record actions */
+#define WBRF_RECORD_ADD0x0
+#define WBRF_RECORD_REMOVE 0x1
+
+#define WBRF_REVISION  0x1
+
+#define KHZ_TO_HZ(freq)((freq) * 1000ULL)
+
+static const guid_t wifi_acpi_dsm_guid =
+   GUID_INIT(0x7b7656cf, 0xdc3d, 0x4c1c,
+ 0x83, 0xe9, 0x66, 0xe7, 0x21, 0xde, 0x30, 0x70);
+
+static int wbrf_dsm(struct acpi_device *adev, u8 fn,
+   union acpi_object *argv4,
+   union acpi_object **out)
+{
+   union acpi_object *obj;
+   int rc;
+
+   obj = acpi_evaluate_dsm(adev->handle, _acpi_dsm_guid,
+   WBRF_REVISION, fn, argv4);
+   if (!obj)
+   return -ENXIO;
+
+   switch (obj->type) {
+   case ACPI_TYPE_BUFFER:
+   if (!*out) {
+   rc = -EINVAL;
+   break;
+   }
+   *out = obj;
+   return 0;
+
+   case ACPI_TYPE_INTEGER:
+   rc =  obj->integer.value ? -EINVAL : 0;
+   break;
+   default:
+   rc = -EOPNOTSUPP;
+   }
+   ACPI_FREE(obj);
+
+   return rc;
+}
+
+static int wbrf_record(struct 

[PATCH 0/9] Support Wifi RFI interference mitigation feature

2023-05-29 Thread Evan Quan
Due to electrical and mechanical constraints in certain platform designs there 
may
be likely interference of relatively high-powered harmonics of the (G-)DDR 
memory
clocks with local radio module frequency bands used by Wifi 6/6e/7. To mitigate
possible RFI interference producers can advertise the frequencies in use and
consumers can use this information to avoid using these frequencies for
sensitive features.

The whole patch set is based on 6.4-rc3. With some brief introductions as below:
Patch1: Core ACPI interfaces needed to support WBRF feature.
Patch2 - 4: Enable WBRF support for some Mediatek and Qualcomm wifi drivers.
Patch5 - 9: Enable WBRF support for AMD graphics driver.

Anson Tsao (1):
  wifi: ath11k: Add support to the Qualcomm ath11k for ACPI WBRF

Evan Quan (6):
  wifi: ath12k: Add support to the Qualcomm ath12k for ACPI WBRF
  drm/amd/pm: update driver_if and ppsmc headers for coming wbrf feature
  drm/amd/pm: setup the framework to support Wifi RFI mitigation feature
  drm/amd/pm: add flood detection for wbrf events
  drm/amd/pm: enable Wifi RFI mitigation feature support for SMU13.0.0
  drm/amd/pm: enable Wifi RFI mitigation feature support for SMU13.0.7

Mario Limonciello (2):
  drivers/acpi: Add support for Wifi band RF mitigations
  mt76: Add support to the Mediatek MT7921 for ACPI WBRF

 drivers/acpi/Kconfig  |   7 +
 drivers/acpi/Makefile |   2 +
 drivers/acpi/acpi_wbrf.c  | 343 ++
 drivers/gpu/drm/amd/amdgpu/amdgpu.h   |  26 ++
 drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c  |  63 
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c   |  19 +
 drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c | 204 +++
 drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h |  31 ++
 .../inc/pmfw_if/smu13_driver_if_v13_0_0.h |  14 +-
 .../inc/pmfw_if/smu13_driver_if_v13_0_7.h |  14 +-
 .../pm/swsmu/inc/pmfw_if/smu_v13_0_0_ppsmc.h  |   3 +-
 .../pm/swsmu/inc/pmfw_if/smu_v13_0_7_ppsmc.h  |   3 +-
 drivers/gpu/drm/amd/pm/swsmu/inc/smu_types.h  |   3 +-
 drivers/gpu/drm/amd/pm/swsmu/inc/smu_v13_0.h  |   3 +
 .../gpu/drm/amd/pm/swsmu/smu13/smu_v13_0.c|   9 +
 .../drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c  |  62 
 .../drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c  |  61 
 drivers/gpu/drm/amd/pm/swsmu/smu_internal.h   |   3 +
 drivers/net/wireless/ath/Makefile |   1 +
 drivers/net/wireless/ath/acpi_wbrf.c  |  45 +++
 drivers/net/wireless/ath/ath.h|  15 +
 drivers/net/wireless/ath/ath11k/core.c|  23 ++
 drivers/net/wireless/ath/ath11k/core.h|  14 +
 drivers/net/wireless/ath/ath11k/mac.c |   4 +
 drivers/net/wireless/ath/ath11k/pci.c |   3 +
 drivers/net/wireless/ath/ath12k/core.c|  21 ++
 drivers/net/wireless/ath/ath12k/core.h|  14 +
 drivers/net/wireless/ath/ath12k/mac.c |   4 +
 drivers/net/wireless/ath/ath12k/pci.c |   3 +
 drivers/net/wireless/mediatek/mt76/Makefile   |   1 +
 .../net/wireless/mediatek/mt76/acpi_wbrf.c|  36 ++
 drivers/net/wireless/mediatek/mt76/mt76.h |  19 +
 .../net/wireless/mediatek/mt76/mt7921/init.c  |   2 +
 .../net/wireless/mediatek/mt76/mt7921/main.c  |   3 +
 include/linux/wbrf.h  |  70 
 35 files changed, 1143 insertions(+), 5 deletions(-)
 create mode 100644 drivers/acpi/acpi_wbrf.c
 create mode 100644 drivers/net/wireless/ath/acpi_wbrf.c
 create mode 100644 drivers/net/wireless/mediatek/mt76/acpi_wbrf.c
 create mode 100644 include/linux/wbrf.h

-- 
2.34.1



RE: [PATCH] drm/amdkfd: Fix MEC pipe interrupt enablement

2023-05-29 Thread Zhang, Hawking
[AMD Official Use Only - General]

Reviewed-by: Hawking Zhang 

Regards,
Hawking
-Original Message-
From: amd-gfx  On Behalf Of Lijo Lazar
Sent: Monday, May 29, 2023 21:58
To: amd-gfx@lists.freedesktop.org
Cc: Deucher, Alexander ; Joshi, Mukul 
; Zhang, Hawking 
Subject: [PATCH] drm/amdkfd: Fix MEC pipe interrupt enablement

for_each_inst modifies xcc_mask and therefore the loop doesn't initialize 
properly interrupts on all pipes. Keep looping through xcc as the outer loop to 
fix this issue.

Fixes: 7b04c90a48b1 ("drm/amdkfd: Use xcc mask for identifying xcc")

Signed-off-by: Lijo Lazar 
---
 drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c 
b/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
index 493b4b66f180..80cddb46657f 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
@@ -1274,11 +1274,12 @@ static void init_interrupts(struct device_queue_manager 
*dqm)
uint32_t xcc_mask = dqm->dev->xcc_mask;
unsigned int i, xcc_id;

-   for (i = 0 ; i < get_pipes_per_mec(dqm) ; i++) {
-   if (is_pipe_enabled(dqm, 0, i)) {
-   for_each_inst(xcc_id, xcc_mask)
+   for_each_inst(xcc_id, xcc_mask) {
+   for (i = 0 ; i < get_pipes_per_mec(dqm) ; i++) {
+   if (is_pipe_enabled(dqm, 0, i)) {
dqm->dev->kfd2kgd->init_interrupts(
dqm->dev->adev, i, xcc_id);
+   }
}
}
 }
--
2.25.1



Re: [PATCH] drm/amdkfd: flag added to handle errors from svm validate and map

2023-05-29 Thread Felix Kuehling

On 2023-05-29 17:11, Alex Sierra wrote:

If a return error is raised during validation and mapping of a
prange, this flag is set. It is a rare occurrence, but it could happen
when `amdgpu_hmm_range_get_pages_done` returns true. In such cases,
the caller should retry. However, it is important to ensure that the
prange is updated correctly during the retry.

Signed-off-by: Alex Sierra 


Reviewed-by: Felix Kuehling 



---
  drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 3 ++-
  drivers/gpu/drm/amd/amdkfd/kfd_svm.h | 1 +
  2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_svm.c 
b/drivers/gpu/drm/amd/amdkfd/kfd_svm.c
index fcfde9140bce..910c0269598a 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_svm.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_svm.c
@@ -823,7 +823,7 @@ svm_range_is_same_attrs(struct kfd_process *p, struct 
svm_range *prange,
}
}
  
-	return true;

+   return !prange->is_error_flag;
  }
  
  /**

@@ -1657,6 +1657,7 @@ static int svm_range_validate_and_map(struct mm_struct 
*mm,
  unreserve_out:
svm_range_unreserve_bos();
  
+	prange->is_error_flag = !!r;

if (!r)
prange->validate_timestamp = ktime_get_boottime();
  
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_svm.h b/drivers/gpu/drm/amd/amdkfd/kfd_svm.h

index 7a33b93f9df6..b716d4bf7ee0 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_svm.h
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_svm.h
@@ -133,6 +133,7 @@ struct svm_range {
DECLARE_BITMAP(bitmap_aip, MAX_GPU_INSTANCE);
boolvalidated_once;
boolmapped_to_gpu;
+   boolis_error_flag;
  };
  
  static inline void svm_range_lock(struct svm_range *prange)


[PATCH] drm/amdkfd: flag added to handle errors from svm validate and map

2023-05-29 Thread Alex Sierra
If a return error is raised during validation and mapping of a
prange, this flag is set. It is a rare occurrence, but it could happen
when `amdgpu_hmm_range_get_pages_done` returns true. In such cases,
the caller should retry. However, it is important to ensure that the
prange is updated correctly during the retry.

Signed-off-by: Alex Sierra 
---
 drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 3 ++-
 drivers/gpu/drm/amd/amdkfd/kfd_svm.h | 1 +
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_svm.c 
b/drivers/gpu/drm/amd/amdkfd/kfd_svm.c
index fcfde9140bce..910c0269598a 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_svm.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_svm.c
@@ -823,7 +823,7 @@ svm_range_is_same_attrs(struct kfd_process *p, struct 
svm_range *prange,
}
}
 
-   return true;
+   return !prange->is_error_flag;
 }
 
 /**
@@ -1657,6 +1657,7 @@ static int svm_range_validate_and_map(struct mm_struct 
*mm,
 unreserve_out:
svm_range_unreserve_bos();
 
+   prange->is_error_flag = !!r;
if (!r)
prange->validate_timestamp = ktime_get_boottime();
 
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_svm.h 
b/drivers/gpu/drm/amd/amdkfd/kfd_svm.h
index 7a33b93f9df6..b716d4bf7ee0 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_svm.h
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_svm.h
@@ -133,6 +133,7 @@ struct svm_range {
DECLARE_BITMAP(bitmap_aip, MAX_GPU_INSTANCE);
boolvalidated_once;
boolmapped_to_gpu;
+   boolis_error_flag;
 };
 
 static inline void svm_range_lock(struct svm_range *prange)
-- 
2.32.0



[PATCH] drm/amd: SVM flag error added at svm_range flags

2023-05-29 Thread Alex Sierra
If a return error is raised during validation and mapping of a
prange, this flag is set. It is a rare occurrence, but it could happen
when `amdgpu_hmm_range_get_pages_done` returns true. In such cases,
the caller should retry. However, it is important to ensure that the
prange is updated correctly during the retry.

Signed-off-by: Alex Sierra 
---
 drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 12 +++-
 include/uapi/linux/kfd_ioctl.h   |  2 ++
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_svm.c 
b/drivers/gpu/drm/amd/amdkfd/kfd_svm.c
index fcfde9140bce..96abae515bcf 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_svm.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_svm.c
@@ -756,10 +756,12 @@ svm_range_apply_attrs(struct kfd_process *p, struct 
svm_range *prange,
break;
case KFD_IOCTL_SVM_ATTR_SET_FLAGS:
*update_mapping = true;
+   attrs[i].value &= ~KFD_IOCTL_SVM_FLAG_ERROR;
prange->flags |= attrs[i].value;
break;
case KFD_IOCTL_SVM_ATTR_CLR_FLAGS:
*update_mapping = true;
+   attrs[i].value &= ~KFD_IOCTL_SVM_FLAG_ERROR;
prange->flags &= ~attrs[i].value;
break;
case KFD_IOCTL_SVM_ATTR_GRANULARITY:
@@ -778,6 +780,9 @@ svm_range_is_same_attrs(struct kfd_process *p, struct 
svm_range *prange,
uint32_t i;
int gpuidx;
 
+   if (prange->flags & KFD_IOCTL_SVM_FLAG_ERROR)
+   return false;
+
for (i = 0; i < nattr; i++) {
switch (attrs[i].type) {
case KFD_IOCTL_SVM_ATTR_PREFERRED_LOC:
@@ -1657,8 +1662,11 @@ static int svm_range_validate_and_map(struct mm_struct 
*mm,
 unreserve_out:
svm_range_unreserve_bos();
 
-   if (!r)
+   prange->flags |= KFD_IOCTL_SVM_FLAG_ERROR;
+   if (!r) {
+   prange->flags &= ~KFD_IOCTL_SVM_FLAG_ERROR;
prange->validate_timestamp = ktime_get_boottime();
+   }
 
return r;
 }
@@ -3674,9 +3682,11 @@ svm_range_get_attr(struct kfd_process *p, struct 
mm_struct *mm,
break;
case KFD_IOCTL_SVM_ATTR_SET_FLAGS:
attrs[i].value = flags_and;
+   attrs[i].value &= ~KFD_IOCTL_SVM_FLAG_ERROR;
break;
case KFD_IOCTL_SVM_ATTR_CLR_FLAGS:
attrs[i].value = ~flags_or;
+   attrs[i].value &= ~KFD_IOCTL_SVM_FLAG_ERROR;
break;
case KFD_IOCTL_SVM_ATTR_GRANULARITY:
attrs[i].value = (uint32_t)granularity;
diff --git a/include/uapi/linux/kfd_ioctl.h b/include/uapi/linux/kfd_ioctl.h
index 7e19a2d1e907..2b6f68bd06da 100644
--- a/include/uapi/linux/kfd_ioctl.h
+++ b/include/uapi/linux/kfd_ioctl.h
@@ -1125,6 +1125,8 @@ struct kfd_ioctl_cross_memory_copy_deprecated_args {
 #define KFD_IOCTL_SVM_FLAG_GPU_READ_MOSTLY 0x0020
 /* Keep GPU memory mapping always valid as if XNACK is disable */
 #define KFD_IOCTL_SVM_FLAG_GPU_ALWAYS_MAPPED   0x0040
+/* Set during svm validation and map error */
+#define KFD_IOCTL_SVM_FLAG_ERROR   0x8000
 
 /**
  * kfd_ioctl_svm_op - SVM ioctl operations
-- 
2.32.0



Re: [PATCH] drm/amd/display: Add missing kdoc entries in update_planes_and_stream_adapter

2023-05-29 Thread Aurabindo Pillai
This patch is:

Reviewed-by: Aurabindo Pillai 

On 5/27/23 10:25, Srinivasan Shanmugam wrote:
> Fixes the following gcc with W=1:
> 
> drivers/gpu/drm/amd/amdgpu/../display/amdgpu_dm/amdgpu_dm.c:374: warning: 
> Function parameter or member 'dc' not described in 
> 'update_planes_and_stream_adapter'
> drivers/gpu/drm/amd/amdgpu/../display/amdgpu_dm/amdgpu_dm.c:374: warning: 
> Function parameter or member 'update_type' not described in 
> 'update_planes_and_stream_adapter'
> drivers/gpu/drm/amd/amdgpu/../display/amdgpu_dm/amdgpu_dm.c:374: warning: 
> Function parameter or member 'planes_count' not described in 
> 'update_planes_and_stream_adapter'
> drivers/gpu/drm/amd/amdgpu/../display/amdgpu_dm/amdgpu_dm.c:374: warning: 
> Function parameter or member 'stream' not described in 
> 'update_planes_and_stream_adapter'
> drivers/gpu/drm/amd/amdgpu/../display/amdgpu_dm/amdgpu_dm.c:374: warning: 
> Function parameter or member 'stream_update' not described in 
> 'update_planes_and_stream_adapter'
> drivers/gpu/drm/amd/amdgpu/../display/amdgpu_dm/amdgpu_dm.c:374: warning: 
> Function parameter or member 'array_of_surface_update' not described in 
> 'update_planes_and_stream_adapter'
> 
> Cc: Rodrigo Siqueira 
> Signed-off-by: Srinivasan Shanmugam 
> ---
>  drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 8 
>  1 file changed, 8 insertions(+)
> 
> diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c 
> b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
> index a69f4a39d92a..90de0d37f1d2 100644
> --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
> +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
> @@ -364,6 +364,14 @@ static inline void reverse_planes_order(struct 
> dc_surface_update *array_of_surfa
>   * adjustments and preparation before calling it. This function is a wrapper
>   * for the dc_update_planes_and_stream that does any required configuration
>   * before passing control to DC.
> + *
> + * @dc: Display Core control structure
> + * @update_type: specify whether it is FULL/MEDIUM/FAST update
> + * @planes_count: planes count to update
> + * @stream: stream state
> + * @stream_update: stream update
> + * @array_of_surface_update: dc surface update pointer
> + *
>   */
>  static inline bool update_planes_and_stream_adapter(struct dc *dc,
>   int update_type,


Re: [PATCH] drm/amd/display: Fix up kdoc formats in dcn32_fpu.c

2023-05-29 Thread Aurabindo Pillai
Hi Srinivasan,

Please see my inline comments:

On 5/27/23 12:42, Srinivasan Shanmugam wrote:
> Fixes the following gcc with W=1:
> 
> drivers/gpu/drm/amd/amdgpu/../display/dc/dml/dcn32/dcn32_fpu.c:2806: warning: 
> Cannot understand  * 
> *
> drivers/gpu/drm/amd/amdgpu/../display/dc/dml/dcn32/dcn32_fpu.c:2855: warning: 
> Cannot understand  * 
> *
> drivers/gpu/drm/amd/amdgpu/../display/dc/dml/dcn32/dcn32_fpu.c:2900: warning: 
> Function parameter or member 'dc' not described in 
> 'dcn32_assign_fpo_vactive_candidate'
> drivers/gpu/drm/amd/amdgpu/../display/dc/dml/dcn32/dcn32_fpu.c:2900: warning: 
> Function parameter or member 'context' not described in 
> 'dcn32_assign_fpo_vactive_candidate'
> drivers/gpu/drm/amd/amdgpu/../display/dc/dml/dcn32/dcn32_fpu.c:2900: warning: 
> Function parameter or member 'fpo_candidate_stream' not described in 
> 'dcn32_assign_fpo_vactive_candidate'
> drivers/gpu/drm/amd/amdgpu/../display/dc/dml/dcn32/dcn32_fpu.c:2929: warning: 
> Function parameter or member 'dc' not described in 'dcn32_find_vactive_pipe'
> drivers/gpu/drm/amd/amdgpu/../display/dc/dml/dcn32/dcn32_fpu.c:2929: warning: 
> Function parameter or member 'context' not described in 
> 'dcn32_find_vactive_pipe'
> drivers/gpu/drm/amd/amdgpu/../display/dc/dml/dcn32/dcn32_fpu.c:2929: warning: 
> Function parameter or member 'vactive_margin_req_us' not described in 
> 'dcn32_find_vactive_pipe'
> 
> Cc: Rodrigo Siqueira 
> Cc: Harry Wentland 
> Cc: Aurabindo Pillai 
> Signed-off-by: Srinivasan Shanmugam 
> ---
>  .../drm/amd/display/dc/dml/dcn32/dcn32_fpu.c  | 46 +--
>  1 file changed, 22 insertions(+), 24 deletions(-)
> 
> diff --git a/drivers/gpu/drm/amd/display/dc/dml/dcn32/dcn32_fpu.c 
> b/drivers/gpu/drm/amd/display/dc/dml/dcn32/dcn32_fpu.c
> index 137ff970c9aa..6d8dda4cb065 100644
> --- a/drivers/gpu/drm/amd/display/dc/dml/dcn32/dcn32_fpu.c
> +++ b/drivers/gpu/drm/amd/display/dc/dml/dcn32/dcn32_fpu.c
> @@ -2802,13 +2802,12 @@ bool dcn32_allow_subvp_with_active_margin(struct 
> pipe_ctx *pipe)
>   return allow;
>  }
>  
> -/**
> - * 
> 
> +/*
>   * dcn32_allow_subvp_high_refresh_rate: Determine if the high refresh rate 
> config will allow subvp
>   *
> - * @param [in]: dc: Current DC state
> - * @param [in]: context: New DC state to be programmed
> - * @param [in]: pipe: Pipe to be considered for use in subvp
> + * @dc: Current DC state
> + * @context: New DC state to be programmed
> + * @pipe: Pipe to be considered for use in subvp
>   *
>   * On high refresh rate display configs, we will allow subvp under the 
> following conditions:
>   * 1. Resolution is 3840x2160, 3440x1440, or 2560x1440
> @@ -2817,9 +2816,8 @@ bool dcn32_allow_subvp_with_active_margin(struct 
> pipe_ctx *pipe)
>   * 4. Freesync is inactive
>   * 5. For single display cases, freesync must be disabled
>   *
> - * @return: True if pipe can be used for subvp, false otherwise
> - *
> - * 
> 
> + * Returns:
> + *   True if pipe can be used for subvp, false otherwise
>   */
>  bool dcn32_allow_subvp_high_refresh_rate(struct dc *dc, struct dc_state 
> *context, struct pipe_ctx *pipe)
>  {
> @@ -2851,16 +2849,15 @@ bool dcn32_allow_subvp_high_refresh_rate(struct dc 
> *dc, struct dc_state *context
>   return allow;
>  }
>  
> -/**
> - * 
> ***
> +/*
>   * dcn32_determine_max_vratio_prefetch: Determine max Vratio for prefetch by 
> driver policy
>   *
> - * @param [in]: dc: Current DC state
> - * @param [in]: context: New DC state to be programmed
> + * @dc: Current DC state
> + * @context: New DC state to be programmed
>   *
> - * @return: Max vratio for prefetch
> + * Returns:
> + *   Max vratio for prefetch
>   *
> - * 
> ***
>   */
>  double dcn32_determine_max_vratio_prefetch(struct dc *dc, struct dc_state 
> *context)
>  {
> @@ -2881,7 +2878,7 @@ double dcn32_determine_max_vratio_prefetch(struct dc 
> *dc, struct dc_state *conte
>   return max_vratio_pre;
>  }
>  
> -/**
> +/*
>   * dcn32_assign_fpo_vactive_candidate - Assign the FPO stream candidate for 
> FPO + VActive case
>   *
>   * This function chooses the FPO candidate stream for FPO + VActive cases (2 
> stream config).
> @@ -2890,11 +2887,12 @@ double dcn32_determine_max_vratio_prefetch(struct dc 
> *dc, struct dc_state *conte
>   * ActiveMargin <= 0 to be the FPO stream candidate if found.
>   *
>   *
> - * @param [in]: dc - current dc state
> - * @param [in]: context - new dc state
> - * @param [out]: fpo_candidate_stream - pointer to FPO stream 

Re: [PATCH v4 13/13] drm/i915: Implement dedicated fbdev I/O helpers

2023-05-29 Thread Sam Ravnborg
Hi Thomas,

On Wed, May 24, 2023 at 11:21:50AM +0200, Thomas Zimmermann wrote:
> Implement dedicated fbdev helpers for framebuffer I/O instead
> of using DRM's helpers. Use an fbdev generator macro for
> deferred I/O to create the fbdev callbacks. i915 was the only
> caller of the DRM helpers, so remove them from the helper module.
> 
> i915's fbdev emulation is still incomplete as it doesn't implement
> deferred I/O and damage handling for mmaped pages.
> 
> v4:
>   * generate deferred-I/O helpers
>   * use initializer macros for fb_ops
> v2:
>   * use FB_IO_HELPERS options
> 
> Signed-off-by: Thomas Zimmermann 
> Cc: Jani Nikula 
> Cc: Joonas Lahtinen 
> Cc: Rodrigo Vivi 
> Cc: Tvrtko Ursulin 
> Cc: "Ville Syrjälä" 
> ---
>  drivers/gpu/drm/Kconfig|   3 -
>  drivers/gpu/drm/drm_fb_helper.c| 107 -
>  drivers/gpu/drm/i915/Kconfig   |   1 +
>  drivers/gpu/drm/i915/display/intel_fbdev.c |  14 +--
>  include/drm/drm_fb_helper.h|  39 
>  5 files changed, 9 insertions(+), 155 deletions(-)

Nice diffstat!
Assuming there is a good explanation on the dirty check:
Reviewed-by: Sam Ravnborg 


Re: [PATCH v4 11/13] drm/fb-helper: Export helpers for marking damage areas

2023-05-29 Thread Sam Ravnborg
On Wed, May 24, 2023 at 11:21:48AM +0200, Thomas Zimmermann wrote:
> Export drm_fb_helper_damage() and drm_fb_helper_damage_range(), which
> handle damage areas for fbdev emulation. This is a temporary export
> that allows to move the DRM I/O helpers for fbdev into drivers. Only
> fbdev-generic and i915 need them. Both will be updated to implement
> damage handling by themselves and the exported functions will be removed.
> 
> v4:
>   * update interfaces
> 
> Signed-off-by: Thomas Zimmermann 

Assuming there is a good answer why there is no dirty check:
Reviewed-by: Sam Ravnborg 

> ---
>  drivers/gpu/drm/drm_fb_helper.c | 22 ++
>  include/drm/drm_fb_helper.h |  3 +++
>  2 files changed, 25 insertions(+)
> 
> diff --git a/drivers/gpu/drm/drm_fb_helper.c b/drivers/gpu/drm/drm_fb_helper.c
> index f0e9549b6bd7..cb03099fd2e3 100644
> --- a/drivers/gpu/drm/drm_fb_helper.c
> +++ b/drivers/gpu/drm/drm_fb_helper.c
> @@ -670,6 +670,28 @@ static void drm_fb_helper_memory_range_to_clip(struct 
> fb_info *info, off_t off,
>   drm_rect_init(clip, x1, y1, x2 - x1, y2 - y1);
>  }
>  
> +/* Don't use in new code. */
> +void drm_fb_helper_damage_range(struct fb_info *info, off_t off, size_t len)
> +{
> + struct drm_fb_helper *fb_helper = info->par;
> + struct drm_rect damage_area;
> +
> + drm_fb_helper_memory_range_to_clip(info, off, len, _area);
> + drm_fb_helper_damage(fb_helper, damage_area.x1, damage_area.y1,
> +  drm_rect_width(_area),
> +  drm_rect_height(_area));
> +}
> +EXPORT_SYMBOL(drm_fb_helper_damage_range);
> +
> +/* Don't use in new code. */
> +void drm_fb_helper_damage_area(struct fb_info *info, u32 x, u32 y, u32 
> width, u32 height)
> +{
> + struct drm_fb_helper *fb_helper = info->par;
> +
> + drm_fb_helper_damage(fb_helper, x, y, width, height);
> +}
> +EXPORT_SYMBOL(drm_fb_helper_damage_area);
> +
>  /**
>   * drm_fb_helper_deferred_io() - fbdev deferred_io callback function
>   * @info: fb_info struct pointer
> diff --git a/include/drm/drm_fb_helper.h b/include/drm/drm_fb_helper.h
> index 72032c354a30..7d5804882be7 100644
> --- a/include/drm/drm_fb_helper.h
> +++ b/include/drm/drm_fb_helper.h
> @@ -253,6 +253,9 @@ void drm_fb_helper_fill_info(struct fb_info *info,
>struct drm_fb_helper *fb_helper,
>struct drm_fb_helper_surface_size *sizes);
>  
> +void drm_fb_helper_damage_range(struct fb_info *info, off_t off, size_t len);
> +void drm_fb_helper_damage_area(struct fb_info *info, u32 x, u32 y, u32 
> width, u32 height);
> +
>  void drm_fb_helper_deferred_io(struct fb_info *info, struct list_head 
> *pagereflist);
>  
>  ssize_t drm_fb_helper_sys_read(struct fb_info *info, char __user *buf,
> -- 
> 2.40.1


Re: [PATCH v4 00/13] drm/fbdev: Remove DRM's helpers for fbdev I/O

2023-05-29 Thread Sam Ravnborg
Hi Thomas.

> v4:
>   * use initializer and generator macros for struct fb_ops
>   * partially support damage handling in msm (Dmitri)

I like the macros. They make it simpler and we do not spread the _cfb_
misname to more files.


> v3:
>   * fix Kconfig options (Jingfeng)
>   * minimize changes to exynos (Sam)
> v2:
>   * simplify Kconfig handling (Sam)
> 
> Thomas Zimmermann (13):
>   fbdev: Add Kconfig options to select different fb_ops helpers
>   fbdev: Add initializer macros for struct fb_ops


>   drm/armada: Use regular fbdev I/O helpers
>   drm/exynos: Use regular fbdev I/O helpers
>   drm/gma500: Use regular fbdev I/O helpers
>   drm/radeon: Use regular fbdev I/O helpers
>   drm/fbdev-dma: Use regular fbdev I/O helpers
>   drm/msm: Use regular fbdev I/O helpers
>   drm/omapdrm: Use regular fbdev I/O helpers
>   drm/tegra: Use regular fbdev I/O helpers
These are all:
Acked-by: Sam Ravnborg 


Re: [PATCH v4 13/13] drm/i915: Implement dedicated fbdev I/O helpers

2023-05-29 Thread Sam Ravnborg
Hi Thomas,

On Wed, May 24, 2023 at 11:21:50AM +0200, Thomas Zimmermann wrote:
> Implement dedicated fbdev helpers for framebuffer I/O instead
> of using DRM's helpers. Use an fbdev generator macro for
> deferred I/O to create the fbdev callbacks. i915 was the only
> caller of the DRM helpers, so remove them from the helper module.
> 
> i915's fbdev emulation is still incomplete as it doesn't implement
> deferred I/O and damage handling for mmaped pages.
> 
> v4:
>   * generate deferred-I/O helpers
>   * use initializer macros for fb_ops
> v2:
>   * use FB_IO_HELPERS options
> 
> Signed-off-by: Thomas Zimmermann 
> Cc: Jani Nikula 
> Cc: Joonas Lahtinen 
> Cc: Rodrigo Vivi 
> Cc: Tvrtko Ursulin 
> Cc: "Ville Syrjälä" 
> ---
>  drivers/gpu/drm/Kconfig|   3 -
>  drivers/gpu/drm/drm_fb_helper.c| 107 -
>  drivers/gpu/drm/i915/Kconfig   |   1 +
>  drivers/gpu/drm/i915/display/intel_fbdev.c |  14 +--
>  include/drm/drm_fb_helper.h|  39 
>  5 files changed, 9 insertions(+), 155 deletions(-)
> 
> diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig
> index 92a782827b7b..bb2e48cc6cd6 100644
> --- a/drivers/gpu/drm/Kconfig
> +++ b/drivers/gpu/drm/Kconfig
> @@ -133,9 +133,6 @@ config DRM_FBDEV_EMULATION
>   bool "Enable legacy fbdev support for your modesetting driver"
>   depends on DRM_KMS_HELPER
>   depends on FB=y || FB=DRM_KMS_HELPER
> - select FB_CFB_FILLRECT
> - select FB_CFB_COPYAREA
> - select FB_CFB_IMAGEBLIT
>   select FRAMEBUFFER_CONSOLE if !EXPERT
>   select FRAMEBUFFER_CONSOLE_DETECT_PRIMARY if FRAMEBUFFER_CONSOLE
>   default y
> diff --git a/drivers/gpu/drm/drm_fb_helper.c b/drivers/gpu/drm/drm_fb_helper.c
> index bab6b252f02a..9978147bbc8a 100644
> --- a/drivers/gpu/drm/drm_fb_helper.c
> +++ b/drivers/gpu/drm/drm_fb_helper.c
> @@ -736,113 +736,6 @@ void drm_fb_helper_deferred_io(struct fb_info *info, 
> struct list_head *pagerefli
>  }
>  EXPORT_SYMBOL(drm_fb_helper_deferred_io);
>  
> -/**
> - * drm_fb_helper_cfb_read - Implements struct _ops.fb_read for I/O memory
> - * @info: fb_info struct pointer
> - * @buf: userspace buffer to read from framebuffer memory
> - * @count: number of bytes to read from framebuffer memory
> - * @ppos: read offset within framebuffer memory
> - *
> - * Returns:
> - * The number of bytes read on success, or an error code otherwise.
> - */
> -ssize_t drm_fb_helper_cfb_read(struct fb_info *info, char __user *buf,
> -size_t count, loff_t *ppos)
> -{
> - return fb_io_read(info, buf, count, ppos);
> -}
> -EXPORT_SYMBOL(drm_fb_helper_cfb_read);
> -
> -/**
> - * drm_fb_helper_cfb_write - Implements struct _ops.fb_write for I/O 
> memory
> - * @info: fb_info struct pointer
> - * @buf: userspace buffer to write to framebuffer memory
> - * @count: number of bytes to write to framebuffer memory
> - * @ppos: write offset within framebuffer memory
> - *
> - * Returns:
> - * The number of bytes written on success, or an error code otherwise.
> - */
> -ssize_t drm_fb_helper_cfb_write(struct fb_info *info, const char __user *buf,
> - size_t count, loff_t *ppos)
> -{
> - struct drm_fb_helper *helper = info->par;
> - loff_t pos = *ppos;
> - ssize_t ret;
> - struct drm_rect damage_area;
> -
> - ret = fb_io_write(info, buf, count, ppos);
> - if (ret <= 0)
> - return ret;
> -
> - if (helper->funcs->fb_dirty) {
> - drm_fb_helper_memory_range_to_clip(info, pos, ret, 
> _area);
> - drm_fb_helper_damage(helper, damage_area.x1, damage_area.y1,
> -  drm_rect_width(_area),
> -  drm_rect_height(_area));
> - }

The generated helpers do not have the if (helper->funcs->fb_dirty)
check.
Is this implemented somewhere else that I missed?

Sam


> -
> - return ret;
> -}
> -EXPORT_SYMBOL(drm_fb_helper_cfb_write);
> -
> -/**
> - * drm_fb_helper_cfb_fillrect - wrapper around cfb_fillrect
> - * @info: fbdev registered by the helper
> - * @rect: info about rectangle to fill
> - *
> - * A wrapper around cfb_fillrect implemented by fbdev core
> - */
> -void drm_fb_helper_cfb_fillrect(struct fb_info *info,
> - const struct fb_fillrect *rect)
> -{
> - struct drm_fb_helper *helper = info->par;
> -
> - cfb_fillrect(info, rect);
> -
> - if (helper->funcs->fb_dirty)
> - drm_fb_helper_damage(helper, rect->dx, rect->dy, rect->width, 
> rect->height);
> -}
> -EXPORT_SYMBOL(drm_fb_helper_cfb_fillrect);
> -
> -/**
> - * drm_fb_helper_cfb_copyarea - wrapper around cfb_copyarea
> - * @info: fbdev registered by the helper
> - * @area: info about area to copy
> - *
> - * A wrapper around cfb_copyarea implemented by fbdev core
> - */
> -void drm_fb_helper_cfb_copyarea(struct fb_info *info,
> - const struct 

Re: [PATCH v2] drm/amdgpu: Fix create_dmamap_sg_bo kdoc warnings

2023-05-29 Thread Felix Kuehling

On 2023-05-29 15:22, Srinivasan Shanmugam wrote:

Fix the following gcc with W=1:

drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c:292: warning: Cannot 
understand  * @create_dmamap_sg_bo: Creates a amdgpu_bo object to reflect 
information

Cc: Felix Kuehling 
Cc: Christian König 
Cc: Alex Deucher 
Signed-off-by: Srinivasan Shanmugam 


Reviewed-by: Felix Kuehling 



---

v2:
  - Fix "@create_dmamap_sg_bo:" format (Felix)

  drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
index cd5d7a39ad0c..e73cbe126286 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
@@ -292,8 +292,9 @@ void amdgpu_amdkfd_release_notify(struct amdgpu_bo *bo)
  }
  
  /**

- * @create_dmamap_sg_bo: Creates a amdgpu_bo object to reflect information
+ * create_dmamap_sg_bo() - Creates a amdgpu_bo object to reflect information
   * about USERPTR or DOOREBELL or MMIO BO.
+ *
   * @adev: Device for which dmamap BO is being created
   * @mem: BO of peer device that is being DMA mapped. Provides parameters
   * in building the dmamap BO


Re: [PATCH v4 03/13] drm/armada: Use regular fbdev I/O helpers

2023-05-29 Thread Sam Ravnborg
On Wed, May 24, 2023 at 11:21:40AM +0200, Thomas Zimmermann wrote:
> Use the regular fbdev helpers for framebuffer I/O instead of DRM's
> helpers. Armada does not use damage handling, so DRM's fbdev helpers
> are mere wrappers around the fbdev code.
> 
> By using fbdev helpers directly within each DRM fbdev emulation,
> we can eventually remove DRM's wrapper functions entirely.
> 
> v4:
>   * use initializer macros for struct fb_ops
> v2:
>   * use FB_IO_HELPERS option
> 
> Signed-off-by: Thomas Zimmermann 
> Cc: Russell King 
Acked-by: Sam Ravnborg 


Re: [PATCH v4 02/13] fbdev: Add initializer macros for struct fb_ops

2023-05-29 Thread Sam Ravnborg
On Wed, May 24, 2023 at 11:21:39AM +0200, Thomas Zimmermann wrote:
> For framebuffers in I/O and system memory, add macros that set
> struct fb_ops to the respective callback functions.
> 
> For deferred I/O, add macros that generate callback functions with
> damage handling. Add initializer macros that set struct fb_ops to
> the generated callbacks.
> 
> These macros can remove a lot boilerplate code from fbdev drivers.
> The drivers are supposed to use the macro that is required for its
> framebuffer. Each macro is split into smaller helpers, so that
> drivers with non-standard callbacks can pick and customize callbacks
> as needed. There are individual helper macros for read/write, mmap
> and drawing.
> 
> Signed-off-by: Thomas Zimmermann 
I am not a fan of public functions/macros names __something.
But I see it used in so many places, so maybe it is just me.
And everything looks consistent, so OK.

With the white space issues fixed:
Reviewed-by: Sam Ravnborg 


[PATCH v2] drm/amdgpu: Fix create_dmamap_sg_bo kdoc warnings

2023-05-29 Thread Srinivasan Shanmugam
Fix the following gcc with W=1:

drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c:292: warning: Cannot 
understand  * @create_dmamap_sg_bo: Creates a amdgpu_bo object to reflect 
information

Cc: Felix Kuehling 
Cc: Christian König 
Cc: Alex Deucher 
Signed-off-by: Srinivasan Shanmugam 
---

v2:
 - Fix "@create_dmamap_sg_bo:" format (Felix)

 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
index cd5d7a39ad0c..e73cbe126286 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
@@ -292,8 +292,9 @@ void amdgpu_amdkfd_release_notify(struct amdgpu_bo *bo)
 }
 
 /**
- * @create_dmamap_sg_bo: Creates a amdgpu_bo object to reflect information
+ * create_dmamap_sg_bo() - Creates a amdgpu_bo object to reflect information
  * about USERPTR or DOOREBELL or MMIO BO.
+ *
  * @adev: Device for which dmamap BO is being created
  * @mem: BO of peer device that is being DMA mapped. Provides parameters
  *  in building the dmamap BO
-- 
2.25.1



Re: [PATCH v4 01/13] fbdev: Add Kconfig options to select different fb_ops helpers

2023-05-29 Thread Sam Ravnborg
Hi Thomas,

On Wed, May 24, 2023 at 11:21:38AM +0200, Thomas Zimmermann wrote:
> Many fbdev drivers use the same set of fb_ops helpers. Add Kconfig
> options to select them at once. This will help with making DRM's
> fbdev emulation code more modular, but can also be used to simplify
> fbdev's driver configs.
> 
> v3:
>   * fix select statement (Jingfeng)
> 
> Signed-off-by: Thomas Zimmermann 
I like these, thanks.
Reviewed-by: Sam Ravnborg 


Re: [PATCH] drm/amdgpu: Fix create_dmamap_sg_bo kdoc warnings

2023-05-29 Thread Felix Kuehling

On 2023-05-27 12:59, Srinivasan Shanmugam wrote:

Fix the following gcc with W=1:

drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c:292: warning: Cannot 
understand  * @create_dmamap_sg_bo: Creates a amdgpu_bo object to reflect 
information

Cc: Christian König 
Cc: Alex Deucher 
Signed-off-by: Srinivasan Shanmugam 
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
index fa4057da0d7f..4540d0964801 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
@@ -288,7 +288,7 @@ void amdgpu_amdkfd_release_notify(struct amdgpu_bo *bo)
kfree(bo->kfd_bo);
  }
  
-/**

+/*
   * @create_dmamap_sg_bo: Creates a amdgpu_bo object to reflect information


This was obviously meant to be a kdoc comment that is just badly 
formatted. Can you fix the format instead to make it valid?


Thanks,
  Felix



   * about USERPTR or DOOREBELL or MMIO BO.
   * @adev: Device for which dmamap BO is being created


[PATCH] drm/amdgpu: fix Null pointer dereference error in amdgpu_device_recover_vram

2023-05-29 Thread Horatio Zhang
Use the function of amdgpu_bo_vm_destroy to handle the resource release
of shadow bo. During the amdgpu_mes_self_test, shadow bo released, but
vmbo->shadow_list was not, which caused a null pointer reference error
in amdgpu_device_recover_vram when GPU reset.

Fixes: cd7050908070 ("drm/amdgpu: Fix vram recover doesn't work after whole GPU 
reset (v2)")
Signed-off-by: xinhui pan 
Signed-off-by: Horatio Zhang 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 10 --
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c  |  1 -
 2 files changed, 4 insertions(+), 7 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
index 46f249912b67..4e46f8f1b3de 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
@@ -79,9 +79,10 @@ static void amdgpu_bo_user_destroy(struct ttm_buffer_object 
*tbo)
 static void amdgpu_bo_vm_destroy(struct ttm_buffer_object *tbo)
 {
struct amdgpu_device *adev = amdgpu_ttm_adev(tbo->bdev);
-   struct amdgpu_bo *bo = ttm_to_amdgpu_bo(tbo);
+   struct amdgpu_bo *shadow_bo = ttm_to_amdgpu_bo(tbo), *bo;
struct amdgpu_bo_vm *vmbo;
 
+   bo = shadow_bo->parent;
vmbo = to_amdgpu_bo_vm(bo);
/* in case amdgpu_device_recover_vram got NULL of bo->parent */
if (!list_empty(>shadow_list)) {
@@ -711,11 +712,6 @@ int amdgpu_bo_create_vm(struct amdgpu_device *adev,
return r;
 
*vmbo_ptr = to_amdgpu_bo_vm(bo_ptr);
-   INIT_LIST_HEAD(&(*vmbo_ptr)->shadow_list);
-   /* Set destroy callback to amdgpu_bo_vm_destroy after vmbo->shadow_list
-* is initialized.
-*/
-   bo_ptr->tbo.destroy = _bo_vm_destroy;
return r;
 }
 
@@ -732,6 +728,8 @@ void amdgpu_bo_add_to_shadow_list(struct amdgpu_bo_vm *vmbo)
 
mutex_lock(>shadow_list_lock);
list_add_tail(>shadow_list, >shadow_list);
+   vmbo->shadow->parent = amdgpu_bo_ref(>bo);
+   vmbo->shadow->tbo.destroy = _bo_vm_destroy;
mutex_unlock(>shadow_list_lock);
 }
 
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c
index cc3b1b596e56..dea1a64be44d 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c
@@ -573,7 +573,6 @@ int amdgpu_vm_pt_create(struct amdgpu_device *adev, struct 
amdgpu_vm *vm,
return r;
}
 
-   (*vmbo)->shadow->parent = amdgpu_bo_ref(bo);
amdgpu_bo_add_to_shadow_list(*vmbo);
 
return 0;
-- 
2.34.1



[PATCH] drm/amdgpu: Fix missing parameter desc for 'xcp_id' in amdgpu_amdkfd_reserve_mem_limit

2023-05-29 Thread Srinivasan Shanmugam
Fix these warnings by adding 'xcp_id' argument.

gcc with W=1
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c:160: warning: Function 
parameter or member 'xcp_id' not described in 'amdgpu_amdkfd_reserve_mem_limit'

Cc: Christian König 
Cc: Alex Deucher 
Signed-off-by: Srinivasan Shanmugam 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
index fa4057da0d7f..cd5d7a39ad0c 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
@@ -152,8 +152,11 @@ void amdgpu_amdkfd_reserve_system_mem(uint64_t size)
  * @size: Size of buffer, in bytes, encapsulated by B0. This should be
  * equivalent to amdgpu_bo_size(BO)
  * @alloc_flag: Flag used in allocating a BO as noted above
+ * @xcp_id: xcp_id is used to get xcp from xcp manager, one xcp is
+ * managed as one compute node in driver for app
  *
- * Return: returns -ENOMEM in case of error, ZERO otherwise
+ * Return:
+ * returns -ENOMEM in case of error, ZERO otherwise
  */
 int amdgpu_amdkfd_reserve_mem_limit(struct amdgpu_device *adev,
uint64_t size, u32 alloc_flag, int8_t xcp_id)
-- 
2.25.1



[PATCH] drm/amdgpu: Fix missing parameter desc for 'xcc_id' in gfx_v7_0.c & amdgpu_rlc.c

2023-05-29 Thread Srinivasan Shanmugam
Fix these warnings by adding 'xcc_id' arguments.

gcc with W=1
drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c:1557: warning: Function parameter or 
member 'xcc_id' not described in 'gfx_v7_0_select_se_sh'
drivers/gpu/drm/amd/amdgpu/amdgpu_rlc.c:38: warning: Function parameter or 
member 'xcc_id' not described in 'amdgpu_gfx_rlc_enter_safe_mode'
drivers/gpu/drm/amd/amdgpu/amdgpu_rlc.c:62: warning: Function parameter or 
member 'xcc_id' not described in 'amdgpu_gfx_rlc_exit_safe_mode'

Cc: Christian König 
Cc: Alex Deucher 
Signed-off-by: Srinivasan Shanmugam 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_rlc.c | 2 ++
 drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c   | 2 +-
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_rlc.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_rlc.c
index d3bed9a3e61f..35e0ae9acadc 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_rlc.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_rlc.c
@@ -31,6 +31,7 @@
  * amdgpu_gfx_rlc_enter_safe_mode - Set RLC into safe mode
  *
  * @adev: amdgpu_device pointer
+ * @xcc_id: xcc accelerated compute core id
  *
  * Set RLC enter into safe mode if RLC is enabled and haven't in safe mode.
  */
@@ -55,6 +56,7 @@ void amdgpu_gfx_rlc_enter_safe_mode(struct amdgpu_device 
*adev, int xcc_id)
  * amdgpu_gfx_rlc_exit_safe_mode - Set RLC out of safe mode
  *
  * @adev: amdgpu_device pointer
+ * @xcc_id: xcc accelerated compute core id
  *
  * Set RLC exit safe mode if RLC is enabled and have entered into safe mode.
  */
diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c 
b/drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c
index 0f0c12bbe228..7b3f13221c0f 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c
@@ -1548,7 +1548,7 @@ static void gfx_v7_0_tiling_mode_table_init(struct 
amdgpu_device *adev)
  * @sh_num: sh block to address
  * @instance: Certain registers are instanced per SE or SH.
  *0x means broadcast to all SEs or SHs (CIK).
- *
+ * @xcc_id: xcc accelerated compute core id
  * Select which SE, SH combinations to address.
  */
 static void gfx_v7_0_select_se_sh(struct amdgpu_device *adev,
-- 
2.25.1



[PATCH] drm/amdkfd: Fix MEC pipe interrupt enablement

2023-05-29 Thread Lijo Lazar
for_each_inst modifies xcc_mask and therefore the loop doesn't
initialize properly interrupts on all pipes. Keep looping through xcc as
the outer loop to fix this issue.

Fixes: 7b04c90a48b1 ("drm/amdkfd: Use xcc mask for identifying xcc")

Signed-off-by: Lijo Lazar 
---
 drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c 
b/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
index 493b4b66f180..80cddb46657f 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
@@ -1274,11 +1274,12 @@ static void init_interrupts(struct device_queue_manager 
*dqm)
uint32_t xcc_mask = dqm->dev->xcc_mask;
unsigned int i, xcc_id;
 
-   for (i = 0 ; i < get_pipes_per_mec(dqm) ; i++) {
-   if (is_pipe_enabled(dqm, 0, i)) {
-   for_each_inst(xcc_id, xcc_mask)
+   for_each_inst(xcc_id, xcc_mask) {
+   for (i = 0 ; i < get_pipes_per_mec(dqm) ; i++) {
+   if (is_pipe_enabled(dqm, 0, i)) {
dqm->dev->kfd2kgd->init_interrupts(
dqm->dev->adev, i, xcc_id);
+   }
}
}
 }
-- 
2.25.1



Re: [PATCH] drm/amdgpu/gfx9: switch to golden tsc registers for raven/raven2

2023-05-29 Thread Michel Dänzer
On 4/12/23 03:23, Zhang, Jesse(Jie) wrote:
> 
>   Due to raven/raven2 maybe enable  sclk slow down,
> they cannot get clock count by the RLC at the auto level of dpm 
> performance.
> So switch to golden tsc register.

At least on this ThinkPad E595 with Picasso, the issue with this change (and 
the corresponding fbc24293ca16 "drm/amdgpu: change the reference clock for 
raven/raven2" & 9d2d1827af29 "drm/amdgpu: Differentiate between Raven2 and 
Raven/Picasso according to revision id") is that the GPU timestamps reported 
via the AMDGPU_INFO ioctl are no longer consistent with those reported via 
asynchronous GPU queries (e.g. via glQuery with GL_TIMESTAMP). The latter are 
still affected by clock changes, and even when the clock doesn't stop 
altogether, they still tick at 25 MHz, so the two kinds of GPU timestamps keep 
diverging further.

This makes it impossible to determine the wall clock time at which a certain 
GPU job finished. GNOME's mutter uses this for adaptive frame scheduling.

You can see the issue with the piglit test arb_timer_query-timestamp-get or 
with the Vulkan CTS tests dEQP-VK.pipeline.monolithic.timestamp.calibrated.*. 
(Note that some of these tests could already fail before with GFXOFF enabled, 
the symptoms are slightly different though)


An ideal long-term solution for this might be to modify the GPU microcode to 
use the golden registers for asynchronous timestamp queries as well.

In the meantime though, these changes need to be reverted for 6.4, at least for 
Picasso.


-- 
Earthling Michel Dänzer|  https://redhat.com
Libre software enthusiast  | Mesa and Xwayland developer



[PATCH] drm/ttm: Remove redundant code in ttm_tt_init_fields

2023-05-29 Thread Ma Jun
Remove redundant assignment code for ttm->caching

Signed-off-by: Ma Jun 
---
 drivers/gpu/drm/ttm/ttm_tt.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/gpu/drm/ttm/ttm_tt.c b/drivers/gpu/drm/ttm/ttm_tt.c
index 02b812dacc5d..45a44544b656 100644
--- a/drivers/gpu/drm/ttm/ttm_tt.c
+++ b/drivers/gpu/drm/ttm/ttm_tt.c
@@ -143,7 +143,6 @@ static void ttm_tt_init_fields(struct ttm_tt *ttm,
   unsigned long extra_pages)
 {
ttm->num_pages = (PAGE_ALIGN(bo->base.size) >> PAGE_SHIFT) + 
extra_pages;
-   ttm->caching = ttm_cached;
ttm->page_flags = page_flags;
ttm->dma_address = NULL;
ttm->swap_storage = NULL;
-- 
2.34.1



Re: [PATCH] Revert "drm/amdgpu: remove TOPDOWN flags when allocating VRAM in large bar system"

2023-05-29 Thread Arunpravin Paneer Selvam




On 5/29/2023 8:05 AM, Xiao, Shane wrote:

[AMD Official Use Only - General]


-Original Message-
From: Paneer Selvam, Arunpravin 
Sent: Saturday, May 27, 2023 2:12 AM
To: Xiao, Shane ; Kuehling, Felix
; amd-gfx@lists.freedesktop.org
Cc: Deucher, Alexander ; Koenig, Christian

Subject: Re: [PATCH] Revert "drm/amdgpu: remove TOPDOWN flags when
allocating VRAM in large bar system"



On 5/22/2023 8:52 AM, Xiao, Shane wrote:

[AMD Official Use Only - General]


-Original Message-
From: Kuehling, Felix 
Sent: Sunday, May 21, 2023 2:39 AM
To: Paneer Selvam, Arunpravin ;

amd-

g...@lists.freedesktop.org
Cc: Deucher, Alexander ; Koenig, Christian
; Xiao, Shane 
Subject: Re: [PATCH] Revert "drm/amdgpu: remove TOPDOWN flags when
allocating VRAM in large bar system"

Am 2023-05-20 um 05:25 schrieb Arunpravin Paneer Selvam:

This reverts commit c105518679b6e87232874ffc989ec403bee59664.

This patch disables the TOPDOWN flag for APU and few dGPU cards
which has the VRAM size equal to the BAR size.

With resizable BARs it's not that rare.



When we enable the TOPDOWN flag, we get the free blocks at the
highest available memory region and we don't split the lower order blocks.
This change is required to keep off the fragmentation related issues
particularly in ASIC which has VRAM space <= 500MiB

As far as I can understand that, both ways may cause fragmentation issues.

As I can understand that remove TOPDOWN flags may get two pros:
1) It can reduce the research time to O(1);
2) Reduce the risk of splitting higher order into lower orders when allocating

blocks.

But as for the second point, Removing TOPDOWN flags still carries the
risk of causing fragmentation issue on some scenarios.
For example, the apps need allocate (1M + 4K) VRAM size, which is not a

power of two.

Case 1: If not using TOPDOWN flag, we will allocate 1M order size and 4K

order size from different order.

--And then if this 4K buddy and 1M buddy are freed, it may prevent the system

from merging 4K(or 1M) to 8K(2M) order.

--If the app has many such allocation requirements, it may cause

fragmentation issue under memory stress.

Case 2: If using TOPDOWN flag, we will find the highest order which is

suitable for 4K and 1M needs.

--Assuming the highest order size is 8M, then we will split this 8M to lower

order to meet the needs of 1M and 4K sizes, respectively.

--In such case the 8M size will split into different lower orders.
--If any other thread or process need allocate 4K or 1M VRAM, and there is

also a chance to prevent the system from merging 4K(or 1M) to 8K(or 2M)
order.

If there are so many needs to allocate not power of two pages from apps,

one of the choose is to use suballocator from UMD such as what ROCr does.

That means suballocator can allocate power of two pages(for example 2M

bytes) from driver, and the app can allocate memory from suballocator.

In such way, it may reduce the risk of causing fragmentation issues.  But I am

not sure that such an option is feasible.

Maybe case 2 occurs less frequently than case one, then we should use

TOPDOWN flags whether the system is lar-bar or not.
Yes, It is better to set TOPDOWN flag mainly to avoid splitting down the lower
order blocks which resolves the fragmentation issues and it doesn't try to
allocate from visible memory (provided that we have the enough requested
memory space in the top down region) which improves the graphics
performances as well.

Hi Arun,
Think it more, the gfx needs get continuous VRAM for display something.
In such case, the TOPDOWN flag can meet this need better than not use TOPDOWN 
flag because the drm buddy TOPDOWN flag
is prone to meet the condition in amdgpu_is_vram_mgr_blocks_contiguous, which 
means that the blocks are contiguous.

As you mentioned that issue 
https://gitlab.freedesktop.org/drm/amd/-/issues/2270 , one of the reasons may 
be that TOPDOWN
flag in drm buddy can make it easier to get contiguous VRAM with the size of 
not power of two.
This means that we do not need allocate contiguous VRAM again and then do copy 
for display something.
In such way, we can get good performance and reduce the risk of allocation 
failures.
If so, it's necessary to use TOPDOWN flag for gfx.
The reason behind setting TOPDOWN flag is that we don't hold the small 
blocks randomly preventing the merge back into larger sized blocks.
Enabling TOPDOWN flag allocates the smaller sized blocks from the higher 
orders which are split already for the previous requests, thus we
don't disturb the lower order or middle order blocks. Hence we don't hit 
fragmentation issues.



Hi Felix & Christian,
However, for compute, there is suballocator on ROCr to allocate power of two 
sizes from drm buddy.
If we use the TOPDOWN flag,  there is a potential problem that split higher 
order into lower order.

Exactly, this is what we want to solve the fragmentation problems.

It may increase the risk of allocating higher order blocks under memory 
pressure if