RE: [PATCH v3] drm/amdgpu: load sdma ucode in the guest machine

2023-07-20 Thread Chen, Horace
[AMD Official Use Only - General]

Reviewed-By: Horace Chen 


-Original Message-
From: YuanShang Mao (River) 
Sent: Tuesday, July 18, 2023 4:31 PM
To: amd-gfx@lists.freedesktop.org
Cc: YuanShang Mao (River) ; Chen, Horace 
; YuanShang Mao (River) 
Subject: [PATCH v3] drm/amdgpu: load sdma ucode in the guest machine

[why]
User mode driver need to check the sdma ucode version to
see whether the sdma engine supports a new type of PM4 packet.
In SRIOV, sdma is loaded by the host. And, there is no way
to check the sdma ucode version of CHIP_NAVI12 and
CHIP_SIENNA_CICHLID of the host in the guest machine.

[how]
Load the sdma ucode for CHIP_NAVI12 and CHIP_SIENNA_CICHLID
in the guest machine.

Signed-off-by: YuanShang 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c |  3 ---
 drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c | 11 +++
 drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c   |  8 +++-
 3 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c
index dacf281d2b21..e2b9392d7f0d 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c
@@ -239,9 +239,6 @@ int amdgpu_sdma_init_microcode(struct amdgpu_device *adev,
   sizeof(struct amdgpu_sdma_instance));
}

-   if (amdgpu_sriov_vf(adev))
-   return 0;
-
DRM_DEBUG("psp_load == '%s'\n",
  adev->firmware.load_type == AMDGPU_FW_LOAD_PSP ? "true" : 
"false");

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
index 41aa853a07d2..3365fe04275a 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
@@ -845,6 +845,17 @@ bool amdgpu_virt_fw_load_skip_check(struct amdgpu_device 
*adev, uint32_t ucode_i
return false;
else
return true;
+   case IP_VERSION(11, 0, 9):
+   case IP_VERSION(11, 0, 7):
+   /* black list for CHIP_NAVI12 and CHIP_SIENNA_CICHLID */
+   if (ucode_id == AMDGPU_UCODE_ID_RLC_G
+   || ucode_id == AMDGPU_UCODE_ID_RLC_RESTORE_LIST_CNTL
+   || ucode_id == AMDGPU_UCODE_ID_RLC_RESTORE_LIST_GPM_MEM
+   || ucode_id == AMDGPU_UCODE_ID_RLC_RESTORE_LIST_SRM_MEM
+   || ucode_id == AMDGPU_UCODE_ID_SMC)
+   return true;
+   else
+   return false;
case IP_VERSION(13, 0, 10):
/* white list */
if (ucode_id == AMDGPU_UCODE_ID_CAP
diff --git a/drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c 
b/drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c
index 5c4d4df9cf94..1cc34efb455b 100644
--- a/drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c
@@ -237,17 +237,15 @@ static void sdma_v5_0_init_golden_registers(struct 
amdgpu_device *adev)
 // emulation only, won't work on real chip
 // navi10 real chip need to use PSP to load firmware
 static int sdma_v5_0_init_microcode(struct amdgpu_device *adev)
-{  int ret, i;
-
-   if (amdgpu_sriov_vf(adev) && (adev->ip_versions[SDMA0_HWIP][0] == 
IP_VERSION(5, 0, 5)))
-   return 0;
+{
+   int ret, i;

for (i = 0; i < adev->sdma.num_instances; i++) {
ret = amdgpu_sdma_init_microcode(adev, i, false);
if (ret)
return ret;
}
-
+
return ret;
 }

--
2.25.1



AMDGPU crash - request for assistance triaging / reporting

2023-07-20 Thread Matthew Hall
Hello,

I see you are listed in the MAINTAINERS for Radeon / AMDGPU.

I would greatly appreciate your advice in the best route to a triage and fix 
for the following:

https://bugzilla.kernel.org/show_bug.cgi?id=217690

It makes it difficult to have a consistently stable Lenovo ThinkPad Z16 which I 
think is one of the best available AMD & Radeon laptops out today, and listed 
as supporting Linux officially.

I have about 30 years of programming experience, though none of it was on GPUs, 
so please let me know what I might be able to do in order to help figure this 
out.

Sincerely,
Matthew Hall


RE: [PATCH] drm/amdgpu: set sw state to gfxoff after SR-IOV reset

2023-07-20 Thread Chang, HaiJun
[AMD Official Use Only - General]

Reviewed-by: HaiJun Chang 

-Original Message-
From: Horace Chen 
Sent: Wednesday, July 19, 2023 5:07 PM
To: amd-gfx@lists.freedesktop.org
Cc: Andrey Grodzovsky ; Quan, Evan 
; Chen, Horace ; Koenig, Christian 
; Deucher, Alexander ; 
Xiao, Jack ; Zhang, Hawking ; Liu, 
Monk ; Xu, Feifei ; Chang, HaiJun 
; Leo Liu 
Subject: [PATCH] drm/amdgpu: set sw state to gfxoff after SR-IOV reset

[Why]
Current SR-IOV will not set GC to off state, while it is a real GC hard reset. 
Whthout GFX off flag, driver may do gfxhub invalidation before firmware load 
and gfxhub gart enable. This operation may cause CP to become busy because GC 
is not in the right state for invalidation.

[How]
Add a function for SR-IOV to clean up some sw state before recover. Set
adev->gfx.is_poweron to false to prevent gfxhub invalidation before gfx
firmware autoload complete.

Signed-off-by: Horace Chen 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c |  3 +++
 drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c   | 10 ++
 drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h   |  1 +
 3 files changed, 14 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index 28e6419023b7..1c786190a84e 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
@@ -4575,6 +4575,9 @@ static int amdgpu_device_reset_sriov(struct amdgpu_device 
*adev,
if (r)
return r;

+   /* some sw clean up VF needs to do before recover */
+   amdgpu_virt_post_reset(adev);
+
/* Resume IP prior to SMC */
r = amdgpu_device_ip_reinit_early_sriov(adev);
if (r)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
index 770eb9725ec1..c712d027d62d 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
@@ -835,6 +835,16 @@ enum amdgpu_sriov_vf_mode 
amdgpu_virt_get_sriov_vf_mode(struct amdgpu_device *ad
return mode;
 }

+void amdgpu_virt_post_reset(struct amdgpu_device *adev) {
+   if (adev->ip_versions[GC_HWIP][0] == IP_VERSION(11, 0, 3)) {
+   /* force set to GFXOFF state after reset,
+* to avoid some invalid operation before GC enable
+*/
+   adev->gfx.is_poweron = false;
+   }
+}
+
 bool amdgpu_virt_fw_load_skip_check(struct amdgpu_device *adev, uint32_t 
ucode_id)  {
switch (adev->ip_versions[MP0_HWIP][0]) { diff --git 
a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h
index d1f7509a44cb..fabb83e9d9ae 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h
@@ -360,4 +360,5 @@ u32 amdgpu_sriov_rreg(struct amdgpu_device *adev,
  u32 offset, u32 acc_flags, u32 hwip, u32 xcc_id);  bool 
amdgpu_virt_fw_load_skip_check(struct amdgpu_device *adev,
uint32_t ucode_id);
+void amdgpu_virt_post_reset(struct amdgpu_device *adev);
 #endif
--
2.34.1



Re: [PATCH v5 05/11] drm/amdgpu: Use RMW accessors for changing LNKCTL

2023-07-20 Thread Bjorn Helgaas
On Mon, Jul 17, 2023 at 03:04:57PM +0300, Ilpo Järvinen wrote:
> Don't assume that only the driver would be accessing LNKCTL. ASPM
> policy changes can trigger write to LNKCTL outside of driver's control.
> And in the case of upstream bridge, the driver does not even own the
> device it's changing the registers for.
> 
> Use RMW capability accessors which do proper locking to avoid losing
> concurrent updates to the register value.
> 
> Fixes: a2e73f56fa62 ("drm/amdgpu: Add support for CIK parts")
> Fixes: 62a37553414a ("drm/amdgpu: add si implementation v10")
> Suggested-by: Lukas Wunner 
> Signed-off-by: Ilpo Järvinen 
> Cc: sta...@vger.kernel.org

Do we have any reports of problems that are fixed by this patch (or by
others in the series)?  If not, I'm not sure it really fits the usual
stable kernel criteria:

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/stable-kernel-rules.rst?id=v6.4

> ---
>  drivers/gpu/drm/amd/amdgpu/cik.c | 36 +---
>  drivers/gpu/drm/amd/amdgpu/si.c  | 36 +---
>  2 files changed, 20 insertions(+), 52 deletions(-)
> 
> diff --git a/drivers/gpu/drm/amd/amdgpu/cik.c 
> b/drivers/gpu/drm/amd/amdgpu/cik.c
> index 5641cf05d856..e63abdf52b6c 100644
> --- a/drivers/gpu/drm/amd/amdgpu/cik.c
> +++ b/drivers/gpu/drm/amd/amdgpu/cik.c
> @@ -1574,17 +1574,8 @@ static void cik_pcie_gen3_enable(struct amdgpu_device 
> *adev)
>   u16 bridge_cfg2, gpu_cfg2;
>   u32 max_lw, current_lw, tmp;
>  
> - pcie_capability_read_word(root, PCI_EXP_LNKCTL,
> -   _cfg);
> - pcie_capability_read_word(adev->pdev, PCI_EXP_LNKCTL,
> -   _cfg);
> -
> - tmp16 = bridge_cfg | PCI_EXP_LNKCTL_HAWD;
> - pcie_capability_write_word(root, PCI_EXP_LNKCTL, tmp16);
> -
> - tmp16 = gpu_cfg | PCI_EXP_LNKCTL_HAWD;
> - pcie_capability_write_word(adev->pdev, PCI_EXP_LNKCTL,
> -tmp16);
> + pcie_capability_set_word(root, PCI_EXP_LNKCTL, 
> PCI_EXP_LNKCTL_HAWD);
> + pcie_capability_set_word(adev->pdev, PCI_EXP_LNKCTL, 
> PCI_EXP_LNKCTL_HAWD);
>  
>   tmp = RREG32_PCIE(ixPCIE_LC_STATUS1);
>   max_lw = (tmp & 
> PCIE_LC_STATUS1__LC_DETECTED_LINK_WIDTH_MASK) >>
> @@ -1637,21 +1628,14 @@ static void cik_pcie_gen3_enable(struct amdgpu_device 
> *adev)
>   msleep(100);
>  
>   /* linkctl */
> - pcie_capability_read_word(root, PCI_EXP_LNKCTL,
> -   );
> - tmp16 &= ~PCI_EXP_LNKCTL_HAWD;
> - tmp16 |= (bridge_cfg & PCI_EXP_LNKCTL_HAWD);
> - pcie_capability_write_word(root, PCI_EXP_LNKCTL,
> -tmp16);
> -
> - pcie_capability_read_word(adev->pdev,
> -   PCI_EXP_LNKCTL,
> -   );
> - tmp16 &= ~PCI_EXP_LNKCTL_HAWD;
> - tmp16 |= (gpu_cfg & PCI_EXP_LNKCTL_HAWD);
> - pcie_capability_write_word(adev->pdev,
> -PCI_EXP_LNKCTL,
> -tmp16);
> + pcie_capability_clear_and_set_word(root, 
> PCI_EXP_LNKCTL,
> +
> PCI_EXP_LNKCTL_HAWD,
> +bridge_cfg &
> +
> PCI_EXP_LNKCTL_HAWD);
> + pcie_capability_clear_and_set_word(adev->pdev, 
> PCI_EXP_LNKCTL,
> +
> PCI_EXP_LNKCTL_HAWD,
> +gpu_cfg &
> +
> PCI_EXP_LNKCTL_HAWD);

Wow, there's a lot of pointless-looking work going on here:

  set root PCI_EXP_LNKCTL_HAWD
  set GPU  PCI_EXP_LNKCTL_HAWD

  for (i = 0; i < 10; i++) {
read root PCI_EXP_LNKCTL
read GPU  PCI_EXP_LNKCTL

clear root PCI_EXP_LNKCTL_HAWD
if (root PCI_EXP_LNKCTL_HAWD was set)
  set root PCI_EXP_LNKCTL_HAWD

clear GPU  PCI_EXP_LNKCTL_HAWD
if (GPU  PCI_EXP_LNKCTL_HAWD was set)
  set GPU  PCI_EXP_LNKCTL_HAWD
  }

If it really *is* pointless, it would be nice to clean it up, but that
wouldn't be material for this patch, so what you 

Re: [PATCH] drm/amdgpu: Always emit GDS switch when GDS/GWS/OA is used

2023-07-20 Thread Friedrich Vock

Hi,

On 07.07.23 10:21, Christian König wrote:

Am 07.07.23 um 09:28 schrieb Friedrich Vock:

Hi Christian,

On 07.07.23 08:56, Christian König wrote:



Am 07.07.23 um 08:28 schrieb Friedrich Vock:

During gfxoff, the per-VMID GDS registers are reset and not restored
afterwards.


Hui? Since when? Those registers should be part of the saved ones.

Have you found that by observation?


yes. I tested this on my RX 6700 XT and the Steam Deck (Vangogh). In the
bug report I linked, a test program using GWS I developed hangs because
of this.

The hang occurs as soon as the kernel re-uses a VMID on which GWS was
already used once. In the hung state, inspecting the per-VMID GWS
registers shows that the values have been reset to 0.
The hang does not occur when gfxoff is disabled.

Even without causing hangs, you can confirm the behaviour by doing the
following:
1. Disable gfxoff.
2. Set some GWS registers.
3. Enable gfxoff and wait a bit.
4. Disable gfxoff and read the registers again. The GWS registers have
been reset.

I performed this test for the GDS_BASE/SIZE registers and it seems these
aren't affected, so it's only GWS that is buggy here.


That's most like a bug in the FW then. I'm going to ask around
internally.


Did the talks with the FW team result in anything yet? It's not that
high-priority, but it'd be nice to know if this is going to be fixed in
the firmware or if I should make a v2 (or if this isn't going to be
fixed at all).

Thanks,
Friedrich




I should probably make a v2 that combines the behaviour before this
patch for GDS and OA, and the patched behaviour for GWS.


Yeah, that sounds like a good idea to me. But let me ping the fw teams
first.



I'm not aware of userspace using GWS (yet, I had some ideas for using it
in RADV which is what I've been writing these tests for),
so perhaps the Cc to stable can also be omitted.


Depends on what the fw teams says. As far as I know GWS has never been
used widely on Linux.

Could be that they say there is a hw bug and we deprecated it for this
generation, or it's simply not handled by the fw and the driver needs
to take care of this (like this patch does) or whatever.

Thanks for the notice,
Christian.



Thanks,
Friedrich



Thanks,
Christian.



  The kernel needs to emit a GDS switch to manually update the
GWS registers in this case. Since gfxoff can happen between any two
submissions and the kernel has no way of knowing, emit the GDS switch
before every submission.

Fixes: 56b0989e29 ("drm/amdgpu: fix GDS/GWS/OA switch handling")
Cc: sta...@vger.kernel.org
Link: https://gitlab.freedesktop.org/drm/amd/-/issues/2530
Signed-off-by: Friedrich Vock 
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c | 22 +++---
  drivers/gpu/drm/amd/amdgpu/amdgpu_job.h |  1 -
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c  | 10 --
  3 files changed, 15 insertions(+), 18 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c
b/drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c
index ff1ea99292fb..de73797e9279 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c
@@ -165,24 +165,17 @@ bool amdgpu_vmid_had_gpu_reset(struct
amdgpu_device *adev,
  atomic_read(>gpu_reset_counter);
  }

-/* Check if we need to switch to another set of resources */
-static bool amdgpu_vmid_gds_switch_needed(struct amdgpu_vmid *id,
-  struct amdgpu_job *job)
-{
-    return id->gds_base != job->gds_base ||
-    id->gds_size != job->gds_size ||
-    id->gws_base != job->gws_base ||
-    id->gws_size != job->gws_size ||
-    id->oa_base != job->oa_base ||
-    id->oa_size != job->oa_size;
-}
-
  /* Check if the id is compatible with the job */
  static bool amdgpu_vmid_compatible(struct amdgpu_vmid *id,
 struct amdgpu_job *job)
  {
  return  id->pd_gpu_addr == job->vm_pd_addr &&
-    !amdgpu_vmid_gds_switch_needed(id, job);
+    id->gds_base == job->gds_base &&
+    id->gds_size == job->gds_size &&
+    id->gws_base == job->gws_base &&
+    id->gws_size == job->gws_size &&
+    id->oa_base == job->oa_base &&
+    id->oa_size == job->oa_size;
  }

  /**
@@ -434,7 +427,6 @@ int amdgpu_vmid_grab(struct amdgpu_vm *vm, struct
amdgpu_ring *ring,
  list_move_tail(>list, _mgr->ids_lru);
  }

-    job->gds_switch_needed = amdgpu_vmid_gds_switch_needed(id, job);
  if (job->vm_needs_flush) {
  id->flushed_updates = amdgpu_vm_tlb_seq(vm);
  dma_fence_put(id->last_flush);
@@ -503,7 +495,7 @@ void amdgpu_vmid_free_reserved(struct
amdgpu_device *adev,
   * @vmhub: vmhub type
   * @vmid: vmid number to use
   *
- * Reset saved GDW, GWS and OA to force switch on next flush.
+ * Reset saved GDS, GWS and OA data.
   */
  void amdgpu_vmid_reset(struct amdgpu_device *adev, unsigned vmhub,
 unsigned vmid)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_job.h
b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.h
index 

Re: [PATCH v2 3/4] selinux: use vma_is_initial_stack() and vma_is_initial_heap()

2023-07-20 Thread Paul Moore
On Thu, Jul 20, 2023 at 4:28 AM Kefeng Wang  wrote:
> On 2023/7/19 23:25, Paul Moore wrote:
> > On Wed, Jul 19, 2023 at 6:23 AM Kefeng Wang  
> > wrote:
> >> On 2023/7/19 17:02, Christian Göttsche wrote:
> >>> On Wed, 19 Jul 2023 at 09:40, Kefeng Wang  
> >>> wrote:
> 
>  Use the helpers to simplify code.
> 
>  Cc: Paul Moore 
>  Cc: Stephen Smalley 
>  Cc: Eric Paris 
>  Acked-by: Paul Moore 
>  Signed-off-by: Kefeng Wang 
>  ---
> security/selinux/hooks.c | 7 ++-
> 1 file changed, 2 insertions(+), 5 deletions(-)
> 
>  diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
>  index d06e350fedee..ee8575540a8e 100644
>  --- a/security/selinux/hooks.c
>  +++ b/security/selinux/hooks.c
>  @@ -3762,13 +3762,10 @@ static int selinux_file_mprotect(struct 
>  vm_area_struct *vma,
>    if (default_noexec &&
>    (prot & PROT_EXEC) && !(vma->vm_flags & VM_EXEC)) {
>    int rc = 0;
>  -   if (vma->vm_start >= vma->vm_mm->start_brk &&
>  -   vma->vm_end <= vma->vm_mm->brk) {
>  +   if (vma_is_initial_heap(vma)) {
> >>>
> >>> This seems to change the condition from
> >>>
> >>>   vma->vm_start >= vma->vm_mm->start_brk && vma->vm_end <= 
> >>> vma->vm_mm->brk
> >>>
> >>> to
> >>>
> >>>   vma->vm_start <= vma->vm_mm->brk && vma->vm_end >= 
> >>> vma->vm_mm->start_brk
> >>>
> >>> (or AND arguments swapped)
> >>>
> >>>   vma->vm_end >= vma->vm_mm->start_brk && vma->vm_start <= 
> >>> vma->vm_mm->brk
> >>>
> >>> Is this intended?
> >>
> >> The new condition is to check whether there is intersection between
> >> [startbrk,brk] and [vm_start,vm_end], it contains orignal check, so
> >> I think it is ok, but for selinux check, I am not sure if there is
> >> some other problem.
> >
> > This particular SELinux vma check is see if the vma falls within the
> > heap; can you confirm that this change preserves this?
>
> Yes, within is one case of new vma scope check.

Thanks for the confirmation.

-- 
paul-moore.com


[PATCH 7/7] drm/amdgpu/vcn: change end doorbell index for vcn_v4_0_3

2023-07-20 Thread Samir Dhume
For sriov, doorbell index for vcn0 for AID needs to be on
32 byte boundary so we need to move the vcn end doorbell

Signed-off-by: Samir Dhume 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_doorbell.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_doorbell.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_doorbell.h
index f637574644c0..4a279960cd21 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_doorbell.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_doorbell.h
@@ -330,14 +330,14 @@ typedef enum _AMDGPU_DOORBELL_ASSIGNMENT_LAYOUT1 {
AMDGPU_DOORBELL_LAYOUT1_sDMA_ENGINE_END = 0x19F,
/* IH: 0x1A0 ~ 0x1AF */
AMDGPU_DOORBELL_LAYOUT1_IH  = 0x1A0,
-   /* VCN: 0x1B0 ~ 0x1D4 */
+   /* VCN: 0x1B0 ~ 0x1E8 */
AMDGPU_DOORBELL_LAYOUT1_VCN_START   = 0x1B0,
-   AMDGPU_DOORBELL_LAYOUT1_VCN_END = 0x1D4,
+   AMDGPU_DOORBELL_LAYOUT1_VCN_END = 0x1E8,
 
AMDGPU_DOORBELL_LAYOUT1_FIRST_NON_CP= 
AMDGPU_DOORBELL_LAYOUT1_sDMA_ENGINE_START,
AMDGPU_DOORBELL_LAYOUT1_LAST_NON_CP = 
AMDGPU_DOORBELL_LAYOUT1_VCN_END,
 
-   AMDGPU_DOORBELL_LAYOUT1_MAX_ASSIGNMENT  = 0x1D4,
+   AMDGPU_DOORBELL_LAYOUT1_MAX_ASSIGNMENT  = 0x1E8,
AMDGPU_DOORBELL_LAYOUT1_INVALID = 0x
 } AMDGPU_DOORBELL_ASSIGNMENT_LAYOUT1;
 
-- 
2.34.1



[PATCH 2/7] drm/amdgpu/vcn : Skip vcn power-gating change for sriov

2023-07-20 Thread Samir Dhume
Signed-off-by: Samir Dhume 
---
 drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c | 9 +
 1 file changed, 9 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c 
b/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c
index 550ac040b4be..411c1d802823 100644
--- a/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c
+++ b/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c
@@ -1317,6 +1317,15 @@ static int vcn_v4_0_3_set_powergating_state(void *handle,
struct amdgpu_device *adev = (struct amdgpu_device *)handle;
int ret;
 
+   /* for SRIOV, guest should not control VCN Power-gating
+* MMSCH FW should control Power-gating and clock-gating
+* guest should avoid touching CGC and PG
+*/
+   if (amdgpu_sriov_vf(adev)) {
+   adev->vcn.cur_state = AMD_PG_STATE_UNGATE;
+   return 0;
+   }
+
if (state == adev->vcn.cur_state)
return 0;
 
-- 
2.34.1



[PATCH 6/7] drm/amdgpu/jpeg: mmsch_v3_0_4 requires doorbell on 32 byte boundary

2023-07-20 Thread Samir Dhume
Signed-off-by: Samir Dhume 
---
 drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_3.c | 17 ++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_3.c 
b/drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_3.c
index 85ee74fdb7e3..896e2f895884 100644
--- a/drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_3.c
+++ b/drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_3.c
@@ -111,9 +111,20 @@ static int jpeg_v4_0_3_sw_init(void *handle)
ring = >jpeg.inst[i].ring_dec[j];
ring->use_doorbell = true;
ring->vm_hub = AMDGPU_MMHUB0(adev->jpeg.inst[i].aid_id);
-   ring->doorbell_index =
-   (adev->doorbell_index.vcn.vcn_ring0_1 << 1) +
-   1 + j + 9 * jpeg_inst;
+   if (!amdgpu_sriov_vf(adev)) {
+   ring->doorbell_index =
+   (adev->doorbell_index.vcn.vcn_ring0_1 
<< 1) +
+   1 + j + 9 * jpeg_inst;
+   } else {
+   if (j < 4)
+   ring->doorbell_index =
+   
(adev->doorbell_index.vcn.vcn_ring0_1 << 1) +
+   4 + j + 32 * jpeg_inst;
+   else
+   ring->doorbell_index =
+   
(adev->doorbell_index.vcn.vcn_ring0_1 << 1) +
+   8 + j + 32 * jpeg_inst;
+   }
sprintf(ring->name, "jpeg_dec_%d.%d", 
adev->jpeg.inst[i].aid_id, j);
r = amdgpu_ring_init(adev, ring, 512, 
>jpeg.inst->irq, 0,
AMDGPU_RING_PRIO_DEFAULT, NULL);
-- 
2.34.1



[PATCH 5/7] drm/amdgpu/jpeg: sriov support for jpeg_v4_0_3

2023-07-20 Thread Samir Dhume
initialization table handshake with mmsch

Signed-off-by: Samir Dhume 
---
 drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_3.c | 171 ---
 1 file changed, 150 insertions(+), 21 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_3.c 
b/drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_3.c
index ce2b22f7e4e4..85ee74fdb7e3 100644
--- a/drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_3.c
+++ b/drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_3.c
@@ -26,6 +26,7 @@
 #include "soc15.h"
 #include "soc15d.h"
 #include "jpeg_v4_0_3.h"
+#include "mmsch_v4_0_3.h"
 
 #include "vcn/vcn_4_0_3_offset.h"
 #include "vcn/vcn_4_0_3_sh_mask.h"
@@ -41,6 +42,7 @@ static void jpeg_v4_0_3_set_irq_funcs(struct amdgpu_device 
*adev);
 static int jpeg_v4_0_3_set_powergating_state(void *handle,
enum amd_powergating_state state);
 static void jpeg_v4_0_3_set_ras_funcs(struct amdgpu_device *adev);
+static void jpeg_v4_0_3_dec_ring_set_wptr(struct amdgpu_ring *ring);
 
 static int amdgpu_ih_srcid_jpeg[] = {
VCN_4_0__SRCID__JPEG_DECODE,
@@ -160,6 +162,117 @@ static int jpeg_v4_0_3_sw_fini(void *handle)
return r;
 }
 
+static int jpeg_v4_0_3_start_sriov(struct amdgpu_device *adev)
+{
+   struct amdgpu_ring *ring;
+   uint64_t ctx_addr;
+   uint32_t param, resp, expected;
+   uint32_t tmp, timeout;
+
+   struct amdgpu_mm_table *table = >virt.mm_table;
+   uint32_t *table_loc;
+   uint32_t table_size;
+   uint32_t size, size_dw, item_offset;
+   uint32_t init_status;
+   int i, j;
+
+   struct mmsch_v4_0_cmd_direct_write
+   direct_wt = { {0} };
+   struct mmsch_v4_0_cmd_end end = { {0} };
+   struct mmsch_v4_0_3_init_header header;
+
+   direct_wt.cmd_header.command_type =
+   MMSCH_COMMAND__DIRECT_REG_WRITE;
+   end.cmd_header.command_type =
+   MMSCH_COMMAND__END;
+
+   for (i = 0; i < adev->jpeg.num_jpeg_inst; i++) {
+   memset(, 0, sizeof(struct mmsch_v4_0_3_init_header));
+   header.version = MMSCH_VERSION;
+   header.total_size = sizeof(struct mmsch_v4_0_3_init_header) >> 
2;
+
+   table_loc = (uint32_t *)table->cpu_addr;
+   table_loc += header.total_size;
+
+   item_offset = header.total_size;
+
+   for (j = 0; j < adev->jpeg.num_jpeg_rings; j++) {
+   ring = >jpeg.inst[i].ring_dec[j];
+   table_size = 0;
+
+   tmp = SOC15_REG_OFFSET(JPEG, 0, 
regUVD_JMI0_UVD_LMI_JRBC_RB_64BIT_BAR_LOW);
+   MMSCH_V4_0_INSERT_DIRECT_WT(tmp, 
lower_32_bits(ring->gpu_addr));
+   tmp = SOC15_REG_OFFSET(JPEG, 0, 
regUVD_JMI0_UVD_LMI_JRBC_RB_64BIT_BAR_HIGH);
+   MMSCH_V4_0_INSERT_DIRECT_WT(tmp, 
upper_32_bits(ring->gpu_addr));
+   tmp = SOC15_REG_OFFSET(JPEG, 0, 
regUVD_JRBC0_UVD_JRBC_RB_SIZE);
+   MMSCH_V4_0_INSERT_DIRECT_WT(tmp, ring->ring_size / 4);
+
+   if (j <= 3) {
+   header.mjpegdec0[j].table_offset = item_offset;
+   header.mjpegdec0[j].init_status = 0;
+   header.mjpegdec0[j].table_size = table_size;
+   } else {
+   header.mjpegdec1[j-4].table_offset = 
item_offset;
+   header.mjpegdec1[j-4].init_status = 0;
+   header.mjpegdec1[j-4].table_size = table_size;
+   }
+   header.total_size += table_size;
+   item_offset+= table_size;
+   }
+
+   MMSCH_V4_0_INSERT_END();
+
+   /* send init table to MMSCH */
+   size = sizeof(struct mmsch_v4_0_3_init_header);
+   table_loc = (uint32_t *)table->cpu_addr;
+   memcpy((void *)table_loc, , size);
+
+   ctx_addr = table->gpu_addr;
+   WREG32_SOC15(VCN, i, regMMSCH_VF_CTX_ADDR_LO, 
lower_32_bits(ctx_addr));
+   WREG32_SOC15(VCN, i, regMMSCH_VF_CTX_ADDR_HI, 
upper_32_bits(ctx_addr));
+
+   tmp = RREG32_SOC15(VCN, i, regMMSCH_VF_VMID);
+   tmp &= ~MMSCH_VF_VMID__VF_CTX_VMID_MASK;
+   tmp |= (0 << MMSCH_VF_VMID__VF_CTX_VMID__SHIFT);
+   WREG32_SOC15(VCN, i, regMMSCH_VF_VMID, tmp);
+
+   size = header.total_size;
+   WREG32_SOC15(VCN, i, regMMSCH_VF_CTX_SIZE, size);
+
+   WREG32_SOC15(VCN, i, regMMSCH_VF_MAILBOX_RESP, 0);
+
+   param = 0x0001;
+   WREG32_SOC15(VCN, i, regMMSCH_VF_MAILBOX_HOST, param);
+   tmp = 0;
+   timeout = 1000;
+   resp = 0;
+   expected = MMSCH_VF_MAILBOX_RESP__OK;
+   init_status = ((struct mmsch_v4_0_3_init_header 
*)(table_loc))->mjpegdec0[i].init_status;
+   

[PATCH 3/7] drm/amdgpu/vcn: sriov support for vcn_v4_0_3

2023-07-20 Thread Samir Dhume
initialization table handshake with mmsch

Signed-off-by: Samir Dhume 
---
 drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c | 261 +---
 1 file changed, 237 insertions(+), 24 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c 
b/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c
index 411c1d802823..8650e3c6288d 100644
--- a/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c
+++ b/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c
@@ -31,6 +31,7 @@
 #include "soc15d.h"
 #include "soc15_hw_ip.h"
 #include "vcn_v2_0.h"
+#include "mmsch_v4_0_3.h"
 
 #include "vcn/vcn_4_0_3_offset.h"
 #include "vcn/vcn_4_0_3_sh_mask.h"
@@ -44,6 +45,7 @@
 #define VCN_VID_SOC_ADDRESS_2_00x1fb00
 #define VCN1_VID_SOC_ADDRESS_3_0   0x48300
 
+static int vcn_v4_0_3_start_sriov(struct amdgpu_device *adev);
 static void vcn_v4_0_3_set_unified_ring_funcs(struct amdgpu_device *adev);
 static void vcn_v4_0_3_set_irq_funcs(struct amdgpu_device *adev);
 static int vcn_v4_0_3_set_powergating_state(void *handle,
@@ -130,6 +132,10 @@ static int vcn_v4_0_3_sw_init(void *handle)
amdgpu_vcn_fwlog_init(>vcn.inst[i]);
}
 
+   r = amdgpu_virt_alloc_mm_table(adev);
+   if (r)
+   return r;
+
if (adev->pg_flags & AMD_PG_SUPPORT_VCN_DPG)
adev->vcn.pause_dpg_mode = vcn_v4_0_3_pause_dpg_mode;
 
@@ -167,6 +173,8 @@ static int vcn_v4_0_3_sw_fini(void *handle)
drm_dev_exit(idx);
}
 
+   amdgpu_virt_free_mm_table(adev);
+
r = amdgpu_vcn_suspend(adev);
if (r)
return r;
@@ -189,33 +197,50 @@ static int vcn_v4_0_3_hw_init(void *handle)
struct amdgpu_ring *ring;
int i, r, vcn_inst;
 
-   for (i = 0; i < adev->vcn.num_vcn_inst; ++i) {
-   vcn_inst = GET_INST(VCN, i);
-   ring = >vcn.inst[i].ring_enc[0];
+   if (amdgpu_sriov_vf(adev)) {
+   r = vcn_v4_0_3_start_sriov(adev);
+   if (r)
+   goto done;
+
+   for (i = 0; i < adev->vcn.num_vcn_inst; ++i) {
+   if (adev->vcn.harvest_config & (1 << i))
+   continue;
 
-   if (ring->use_doorbell) {
-   adev->nbio.funcs->vcn_doorbell_range(
-   adev, ring->use_doorbell,
-   (adev->doorbell_index.vcn.vcn_ring0_1 << 1) +
-   9 * vcn_inst,
-   adev->vcn.inst[i].aid_id);
-
-   WREG32_SOC15(
-   VCN, GET_INST(VCN, ring->me),
-   regVCN_RB1_DB_CTRL,
-   ring->doorbell_index
-   << 
VCN_RB1_DB_CTRL__OFFSET__SHIFT |
-   VCN_RB1_DB_CTRL__EN_MASK);
-
-   /* Read DB_CTRL to flush the write DB_CTRL command. */
-   RREG32_SOC15(
-   VCN, GET_INST(VCN, ring->me),
-   regVCN_RB1_DB_CTRL);
+   ring = >vcn.inst[i].ring_enc[0];
+   ring->wptr = 0;
+   ring->wptr_old = 0;
+   vcn_v4_0_3_unified_ring_set_wptr(ring);
+   ring->sched.ready = true;
}
+   } else {
+   for (i = 0; i < adev->vcn.num_vcn_inst; ++i) {
+   vcn_inst = GET_INST(VCN, i);
+   ring = >vcn.inst[i].ring_enc[0];
+
+   if (ring->use_doorbell) {
+   adev->nbio.funcs->vcn_doorbell_range(
+   adev, ring->use_doorbell,
+   (adev->doorbell_index.vcn.vcn_ring0_1 
<< 1) +
+   9 * vcn_inst,
+   adev->vcn.inst[i].aid_id);
+
+   WREG32_SOC15(
+   VCN, GET_INST(VCN, ring->me),
+   regVCN_RB1_DB_CTRL,
+   ring->doorbell_index
+   << 
VCN_RB1_DB_CTRL__OFFSET__SHIFT |
+   VCN_RB1_DB_CTRL__EN_MASK);
+
+   /* Read DB_CTRL to flush the write DB_CTRL 
command. */
+   RREG32_SOC15(
+   VCN, GET_INST(VCN, ring->me),
+   regVCN_RB1_DB_CTRL);
+   }
 
-   r = amdgpu_ring_test_helper(ring);
-   if (r)
-   goto done;
+   r = amdgpu_ring_test_helper(ring);
+   if (r)
+   goto done;
+   }
}
 
 done:
@@ -813,6 

[PATCH 4/7] drm/amdgpu/vcn: mmsch_v3_0_4 requires doorbell on 32 byte boundary

2023-07-20 Thread Samir Dhume
Signed-off-by: Samir Dhume 
---
 drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c | 13 ++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c 
b/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c
index 8650e3c6288d..09b3fa707af6 100644
--- a/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c
+++ b/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c
@@ -113,9 +113,16 @@ static int vcn_v4_0_3_sw_init(void *handle)
 
ring = >vcn.inst[i].ring_enc[0];
ring->use_doorbell = true;
-   ring->doorbell_index =
-   (adev->doorbell_index.vcn.vcn_ring0_1 << 1) +
-   9 * vcn_inst;
+
+   if (!amdgpu_sriov_vf(adev))
+   ring->doorbell_index =
+   (adev->doorbell_index.vcn.vcn_ring0_1 << 1) +
+   9 * vcn_inst;
+   else
+   ring->doorbell_index =
+   (adev->doorbell_index.vcn.vcn_ring0_1 << 1) +
+   32 * vcn_inst;
+
ring->vm_hub = AMDGPU_MMHUB0(adev->vcn.inst[i].aid_id);
sprintf(ring->name, "vcn_unified_%d", adev->vcn.inst[i].aid_id);
r = amdgpu_ring_init(adev, ring, 512, >vcn.inst->irq, 0,
-- 
2.34.1



[PATCH 1/7] drm/amdgpu/vcn: Add MMSCH v4_0_3 support for sriov

2023-07-20 Thread Samir Dhume
The structures are the same as v4_0 except for the
init header

Signed-off-by: Samir Dhume 
---
 drivers/gpu/drm/amd/amdgpu/mmsch_v4_0_3.h | 37 +++
 1 file changed, 37 insertions(+)
 create mode 100644 drivers/gpu/drm/amd/amdgpu/mmsch_v4_0_3.h

diff --git a/drivers/gpu/drm/amd/amdgpu/mmsch_v4_0_3.h 
b/drivers/gpu/drm/amd/amdgpu/mmsch_v4_0_3.h
new file mode 100644
index ..db7eb5260295
--- /dev/null
+++ b/drivers/gpu/drm/amd/amdgpu/mmsch_v4_0_3.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2023 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+
+#ifndef __MMSCH_V4_0_3_H__
+#define __MMSCH_V4_0_3_H__
+
+#include "amdgpu_vcn.h"
+#include "mmsch_v4_0.h"
+
+struct mmsch_v4_0_3_init_header {
+   uint32_t version;
+   uint32_t total_size;
+   struct mmsch_v4_0_table_info vcn0;
+   struct mmsch_v4_0_table_info mjpegdec0[4];
+   struct mmsch_v4_0_table_info mjpegdec1[4];
+};
+#endif
-- 
2.34.1



RE: [PATCH 3/7] drm/amdgpu/vcn: sriov support for vcn_v4_0_3

2023-07-20 Thread Dhume, Samir
[Public]

Fair point. I'll follow up with another patch.

Thanks,
Samir


-Original Message-
From: Chen, Guchun 
Sent: Tuesday, July 18, 2023 1:54 AM
To: Dhume, Samir ; amd-gfx@lists.freedesktop.org
Cc: Dhume, Samir 
Subject: RE: [PATCH 3/7] drm/amdgpu/vcn: sriov support for vcn_v4_0_3

[Public]

> -Original Message-
> From: amd-gfx  On Behalf Of
> Samir Dhume
> Sent: Monday, July 17, 2023 11:59 PM
> To: amd-gfx@lists.freedesktop.org
> Cc: Dhume, Samir 
> Subject: [PATCH 3/7] drm/amdgpu/vcn: sriov support for vcn_v4_0_3
>
> initialization table handshake with mmsch
>
> Signed-off-by: Samir Dhume 
> ---
>  drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c | 264
> +---
>  1 file changed, 240 insertions(+), 24 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c
> b/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c
> index 411c1d802823..ac405dfcfaf1 100644
> --- a/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c
> +++ b/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c
> @@ -31,6 +31,7 @@
>  #include "soc15d.h"
>  #include "soc15_hw_ip.h"
>  #include "vcn_v2_0.h"
> +#include "mmsch_v4_0_3.h"
>
>  #include "vcn/vcn_4_0_3_offset.h"
>  #include "vcn/vcn_4_0_3_sh_mask.h"
> @@ -44,6 +45,7 @@
>  #define VCN_VID_SOC_ADDRESS_2_0  0x1fb00
>  #define VCN1_VID_SOC_ADDRESS_3_0 0x48300
>
> +static int vcn_v4_0_3_start_sriov(struct amdgpu_device *adev);
>  static void vcn_v4_0_3_set_unified_ring_funcs(struct amdgpu_device
> *adev); static void vcn_v4_0_3_set_irq_funcs(struct amdgpu_device
> *adev);  static int vcn_v4_0_3_set_powergating_state(void *handle, @@
> -130,6 +132,12 @@ static int vcn_v4_0_3_sw_init(void *handle)
>   amdgpu_vcn_fwlog_init(>vcn.inst[i]);
>   }
>
> + if (amdgpu_sriov_vf(adev)) {
> + r = amdgpu_virt_alloc_mm_table(adev);

amdgpu_virt_alloc_mm_table has an early check of amdgpu_sriov_vf(adev), so from 
coding style's perspective, I think you can drop this superfluous check here 
and directly call amdgpu_virt_alloc_mm_table.

> + if (r)
> + return r;
> + }
> +
>   if (adev->pg_flags & AMD_PG_SUPPORT_VCN_DPG)
>   adev->vcn.pause_dpg_mode = vcn_v4_0_3_pause_dpg_mode;
>
> @@ -167,6 +175,9 @@ static int vcn_v4_0_3_sw_fini(void *handle)
>   drm_dev_exit(idx);
>   }
>
> + if (amdgpu_sriov_vf(adev))
> + amdgpu_virt_free_mm_table(adev);

Same as above.

Regards,
Guchun

>   r = amdgpu_vcn_suspend(adev);
>   if (r)
>   return r;
> @@ -189,33 +200,50 @@ static int vcn_v4_0_3_hw_init(void *handle)
>   struct amdgpu_ring *ring;
>   int i, r, vcn_inst;
>
> - for (i = 0; i < adev->vcn.num_vcn_inst; ++i) {
> - vcn_inst = GET_INST(VCN, i);
> - ring = >vcn.inst[i].ring_enc[0];
> + if (amdgpu_sriov_vf(adev)) {
> + r = vcn_v4_0_3_start_sriov(adev);
> + if (r)
> + goto done;
>
> - if (ring->use_doorbell) {
> - adev->nbio.funcs->vcn_doorbell_range(
> - adev, ring->use_doorbell,
> - (adev->doorbell_index.vcn.vcn_ring0_1 << 1)
> +
> - 9 * vcn_inst,
> - adev->vcn.inst[i].aid_id);
> -
> - WREG32_SOC15(
> - VCN, GET_INST(VCN, ring->me),
> - regVCN_RB1_DB_CTRL,
> - ring->doorbell_index
> - <<
> VCN_RB1_DB_CTRL__OFFSET__SHIFT |
> - VCN_RB1_DB_CTRL__EN_MASK);
> -
> - /* Read DB_CTRL to flush the write DB_CTRL
> command. */
> - RREG32_SOC15(
> - VCN, GET_INST(VCN, ring->me),
> - regVCN_RB1_DB_CTRL);
> + for (i = 0; i < adev->vcn.num_vcn_inst; ++i) {
> + if (adev->vcn.harvest_config & (1 << i))
> + continue;
> +
> + ring = >vcn.inst[i].ring_enc[0];
> + ring->wptr = 0;
> + ring->wptr_old = 0;
> + vcn_v4_0_3_unified_ring_set_wptr(ring);
> + ring->sched.ready = true;
>   }
> + } else {
> + for (i = 0; i < adev->vcn.num_vcn_inst; ++i) {
> + vcn_inst = GET_INST(VCN, i);
> + ring = >vcn.inst[i].ring_enc[0];
> +
> + if (ring->use_doorbell) {
> + adev->nbio.funcs->vcn_doorbell_range(
> + adev, ring->use_doorbell,
> + (adev-
> >doorbell_index.vcn.vcn_ring0_1 << 1) +
> + 9 * vcn_inst,
> + adev->vcn.inst[i].aid_id);
> +
> +

Patch "drm/client: Send hotplug event after registering a client" has been added to the 6.1-stable tree

2023-07-20 Thread gregkh


This is a note to let you know that I've just added the patch titled

drm/client: Send hotplug event after registering a client

to the 6.1-stable tree which can be found at:

http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
 drm-client-send-hotplug-event-after-registering-a-client.patch
and it can be found in the queue-6.1 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let  know about it.


>From 27655b9bb9f0d9c32b8de8bec649b676898c52d5 Mon Sep 17 00:00:00 2001
From: Thomas Zimmermann 
Date: Mon, 10 Jul 2023 11:10:17 +0200
Subject: drm/client: Send hotplug event after registering a client
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

From: Thomas Zimmermann 

commit 27655b9bb9f0d9c32b8de8bec649b676898c52d5 upstream.

Generate a hotplug event after registering a client to allow the
client to configure its display. Remove the hotplug calls from the
existing clients for fbdev emulation. This change fixes a concurrency
bug between registering a client and receiving events from the DRM
core. The bug is present in the fbdev emulation of all drivers.

The fbdev emulation currently generates a hotplug event before
registering the client to the device. For each new output, the DRM
core sends an additional hotplug event to each registered client.

If the DRM core detects first output between sending the artificial
hotplug and registering the device, the output's hotplug event gets
lost. If this is the first output, the fbdev console display remains
dark. This has been observed with amdgpu and fbdev-generic.

Fix this by adding hotplug generation directly to the client's
register helper drm_client_register(). Registering the client and
receiving events are serialized by struct drm_device.clientlist_mutex.
So an output is either configured by the initial hotplug event, or
the client has already been registered.

The bug was originally added in commit 6e3f17ee73f7 ("drm/fb-helper:
generic: Call drm_client_add() after setup is done"), in which adding
a client and receiving a hotplug event switched order. It was hidden,
as most hardware and drivers have at least on static output configured.
Other drivers didn't use the internal DRM client or still had struct
drm_mode_config_funcs.output_poll_changed set. That callback handled
hotplug events as well. After not setting the callback in amdgpu in
commit 0e3172bac3f4 ("drm/amdgpu: Don't set struct
drm_driver.output_poll_changed"), amdgpu did not show a framebuffer
console if output events got lost. The bug got copy-pasted from
fbdev-generic into the other fbdev emulation.

Reported-by: Moritz Duge 
Closes: https://gitlab.freedesktop.org/drm/amd/-/issues/2649
Fixes: 6e3f17ee73f7 ("drm/fb-helper: generic: Call drm_client_add() after setup 
is done")
Fixes: 8ab59da26bc0 ("drm/fb-helper: Move generic fbdev emulation into separate 
source file")
Fixes: b79fe9abd58b ("drm/fbdev-dma: Implement fbdev emulation for GEM DMA 
helpers")
Fixes: 63c381552f69 ("drm/armada: Implement fbdev emulation as in-kernel 
client")
Fixes: 49953b70e7d3 ("drm/exynos: Implement fbdev emulation as in-kernel 
client")
Fixes: 8f1aaccb04b7 ("drm/gma500: Implement client-based fbdev emulation")
Fixes: 940b869c2f2f ("drm/msm: Implement fbdev emulation as in-kernel client")
Fixes: 9e69bcd88e45 ("drm/omapdrm: Implement fbdev emulation as in-kernel 
client")
Fixes: e317a69fe891 ("drm/radeon: Implement client-based fbdev emulation")
Fixes: 71ec16f45ef8 ("drm/tegra: Implement fbdev emulation as in-kernel client")
Fixes: 0e3172bac3f4 ("drm/amdgpu: Don't set struct 
drm_driver.output_poll_changed")
Signed-off-by: Thomas Zimmermann 
Tested-by: Moritz Duge 
Tested-by: Torsten Krah 
Tested-by: Paul Schyska 
Cc: Daniel Vetter 
Cc: David Airlie 
Cc: Noralf Trønnes 
Cc: Maarten Lankhorst 
Cc: Maxime Ripard 
Cc: Javier Martinez Canillas 
Cc: Russell King 
Cc: Inki Dae 
Cc: Seung-Woo Kim 
Cc: Kyungmin Park 
Cc: Krzysztof Kozlowski 
Cc: Patrik Jakobsson 
Cc: Rob Clark 
Cc: Abhinav Kumar 
Cc: Dmitry Baryshkov 
Cc: Tomi Valkeinen 
Cc: Alex Deucher 
Cc: "Christian König" 
Cc: "Pan, Xinhui" 
Cc: Thierry Reding 
Cc: Mikko Perttunen 
Cc: dri-de...@lists.freedesktop.org
Cc: linux-ker...@vger.kernel.org
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-samsung-...@vger.kernel.org
Cc: linux-arm-...@vger.kernel.org
Cc: freedr...@lists.freedesktop.org
Cc: amd-gfx@lists.freedesktop.org
Cc: linux-te...@vger.kernel.org
Cc: dri-de...@lists.freedesktop.org
Cc:  # v5.2+
Reviewed-by: Javier Martinez Canillas 
Reviewed-by: Dmitry Baryshkov  # msm
Link: 
https://patchwork.freedesktop.org/patch/msgid/20230710091029.27503-1-tzimmerm...@suse.de
(cherry picked from commit 27655b9bb9f0d9c32b8de8bec649b676898c52d5)
[ Dropped changes to drivers/gpu/drm/armada/armada_fbdev.c as
  174c3c38e3a2 drm/armada: Initialize fbdev DRM client
  was introduced in 6.5-rc1.

  Dropped changes to 

Patch "drm/client: Send hotplug event after registering a client" has been added to the 6.4-stable tree

2023-07-20 Thread gregkh


This is a note to let you know that I've just added the patch titled

drm/client: Send hotplug event after registering a client

to the 6.4-stable tree which can be found at:

http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
 drm-client-send-hotplug-event-after-registering-a-client.patch
and it can be found in the queue-6.4 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let  know about it.


>From 27655b9bb9f0d9c32b8de8bec649b676898c52d5 Mon Sep 17 00:00:00 2001
From: Thomas Zimmermann 
Date: Mon, 10 Jul 2023 11:10:17 +0200
Subject: drm/client: Send hotplug event after registering a client
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

From: Thomas Zimmermann 

commit 27655b9bb9f0d9c32b8de8bec649b676898c52d5 upstream.

Generate a hotplug event after registering a client to allow the
client to configure its display. Remove the hotplug calls from the
existing clients for fbdev emulation. This change fixes a concurrency
bug between registering a client and receiving events from the DRM
core. The bug is present in the fbdev emulation of all drivers.

The fbdev emulation currently generates a hotplug event before
registering the client to the device. For each new output, the DRM
core sends an additional hotplug event to each registered client.

If the DRM core detects first output between sending the artificial
hotplug and registering the device, the output's hotplug event gets
lost. If this is the first output, the fbdev console display remains
dark. This has been observed with amdgpu and fbdev-generic.

Fix this by adding hotplug generation directly to the client's
register helper drm_client_register(). Registering the client and
receiving events are serialized by struct drm_device.clientlist_mutex.
So an output is either configured by the initial hotplug event, or
the client has already been registered.

The bug was originally added in commit 6e3f17ee73f7 ("drm/fb-helper:
generic: Call drm_client_add() after setup is done"), in which adding
a client and receiving a hotplug event switched order. It was hidden,
as most hardware and drivers have at least on static output configured.
Other drivers didn't use the internal DRM client or still had struct
drm_mode_config_funcs.output_poll_changed set. That callback handled
hotplug events as well. After not setting the callback in amdgpu in
commit 0e3172bac3f4 ("drm/amdgpu: Don't set struct
drm_driver.output_poll_changed"), amdgpu did not show a framebuffer
console if output events got lost. The bug got copy-pasted from
fbdev-generic into the other fbdev emulation.

Reported-by: Moritz Duge 
Closes: https://gitlab.freedesktop.org/drm/amd/-/issues/2649
Fixes: 6e3f17ee73f7 ("drm/fb-helper: generic: Call drm_client_add() after setup 
is done")
Fixes: 8ab59da26bc0 ("drm/fb-helper: Move generic fbdev emulation into separate 
source file")
Fixes: b79fe9abd58b ("drm/fbdev-dma: Implement fbdev emulation for GEM DMA 
helpers")
Fixes: 63c381552f69 ("drm/armada: Implement fbdev emulation as in-kernel 
client")
Fixes: 49953b70e7d3 ("drm/exynos: Implement fbdev emulation as in-kernel 
client")
Fixes: 8f1aaccb04b7 ("drm/gma500: Implement client-based fbdev emulation")
Fixes: 940b869c2f2f ("drm/msm: Implement fbdev emulation as in-kernel client")
Fixes: 9e69bcd88e45 ("drm/omapdrm: Implement fbdev emulation as in-kernel 
client")
Fixes: e317a69fe891 ("drm/radeon: Implement client-based fbdev emulation")
Fixes: 71ec16f45ef8 ("drm/tegra: Implement fbdev emulation as in-kernel client")
Fixes: 0e3172bac3f4 ("drm/amdgpu: Don't set struct 
drm_driver.output_poll_changed")
Signed-off-by: Thomas Zimmermann 
Tested-by: Moritz Duge 
Tested-by: Torsten Krah 
Tested-by: Paul Schyska 
Cc: Daniel Vetter 
Cc: David Airlie 
Cc: Noralf Trønnes 
Cc: Maarten Lankhorst 
Cc: Maxime Ripard 
Cc: Javier Martinez Canillas 
Cc: Russell King 
Cc: Inki Dae 
Cc: Seung-Woo Kim 
Cc: Kyungmin Park 
Cc: Krzysztof Kozlowski 
Cc: Patrik Jakobsson 
Cc: Rob Clark 
Cc: Abhinav Kumar 
Cc: Dmitry Baryshkov 
Cc: Tomi Valkeinen 
Cc: Alex Deucher 
Cc: "Christian König" 
Cc: "Pan, Xinhui" 
Cc: Thierry Reding 
Cc: Mikko Perttunen 
Cc: dri-de...@lists.freedesktop.org
Cc: linux-ker...@vger.kernel.org
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-samsung-...@vger.kernel.org
Cc: linux-arm-...@vger.kernel.org
Cc: freedr...@lists.freedesktop.org
Cc: amd-gfx@lists.freedesktop.org
Cc: linux-te...@vger.kernel.org
Cc: dri-de...@lists.freedesktop.org
Cc:  # v5.2+
Reviewed-by: Javier Martinez Canillas 
Reviewed-by: Dmitry Baryshkov  # msm
Link: 
https://patchwork.freedesktop.org/patch/msgid/20230710091029.27503-1-tzimmerm...@suse.de
[ Dropped changes to drivers/gpu/drm/armada/armada_fbdev.c as
  174c3c38e3a2 drm/armada: Initialize fbdev DRM client
  was introduced in 6.5-rc1 ]
Signed-off-by: Mario Limonciello 
Signed-off-by: Greg Kroah-Hartman 
---
 

Re: [PATCH -next] drm/amdgpu: Fix one kernel-doc comment

2023-07-20 Thread Alex Deucher
Applied.  Thanks!

On Wed, Jul 19, 2023 at 9:27 PM Randy Dunlap  wrote:
>
>
>
> On 7/19/23 18:05, Yang Li wrote:
> > Use colon to separate parameter name from their specific meaning.
> > silence the warning:
> >
> > drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c:793: warning: Function parameter 
> > or member 'adev' not described in 'amdgpu_vm_pte_update_noretry_flags'
> >
> > Signed-off-by: Yang Li 
>
> Reviewed-by: Randy Dunlap 
> Thanks.
>
> > ---
> >  drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c 
> > b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c
> > index 83e1923f6775..96d601e209b8 100644
> > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c
> > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c
> > @@ -783,7 +783,7 @@ int amdgpu_vm_pde_update(struct amdgpu_vm_update_params 
> > *params,
> >  /**
> >   * amdgpu_vm_pte_update_noretry_flags - Update PTE no-retry flags
> >   *
> > - * @adev - amdgpu_device pointer
> > + * @adev: amdgpu_device pointer
> >   * @flags: pointer to PTE flags
> >   *
> >   * Update PTE no-retry flags when TF is enabled.
>
> --
> ~Randy


Re: [PATCH v2] drm/amd/amdgpu: Fix warnings in amdgpu/amdgpu_display.c

2023-07-20 Thread Alex Deucher
On Wed, Jul 19, 2023 at 10:42 PM Srinivasan Shanmugam
 wrote:
>
> Fixes the below checkpatch.pl warnings:
>
> WARNING: Block comments use * on subsequent lines
> WARNING: Block comments use a trailing */ on a separate line
> WARNING: suspect code indent for conditional statements (8, 12)
> WARNING: braces {} are not necessary for single statement blocks
>
> Cc: Christian König 
> Cc: Alex Deucher 
> Signed-off-by: Srinivasan Shanmugam 
> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_display.c | 42 -
>  1 file changed, 25 insertions(+), 17 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c 
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c
> index b702f499f5fb..9a74eae50ad4 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c
> @@ -124,7 +124,7 @@ static void amdgpu_display_flip_work_func(struct 
> work_struct *__work)
>
> struct drm_crtc *crtc = _crtc->base;
> unsigned long flags;
> -   unsigned i;
> +   unsigned int i;
> int vpos, hpos;
>
> for (i = 0; i < work->shared_count; ++i)
> @@ -201,7 +201,7 @@ int amdgpu_display_crtc_page_flip_target(struct drm_crtc 
> *crtc,
> u64 tiling_flags;
> int i, r;
>
> -   work = kzalloc(sizeof *work, GFP_KERNEL);
> +   work = kzalloc(sizeof(*work), GFP_KERNEL);
> if (work == NULL)
> return -ENOMEM;
>
> @@ -332,13 +332,15 @@ int amdgpu_display_crtc_set_config(struct drm_mode_set 
> *set,
>
> adev = drm_to_adev(dev);
> /* if we have active crtcs and we don't have a power ref,
> -  take the current one */
> +* take the current one
> +*/
> if (active && !adev->have_disp_power_ref) {
> adev->have_disp_power_ref = true;
> return ret;
> }
> /* if we have no active crtcs, then drop the power ref
> -  we got before */
> +* we got before
> +*/
> if (!active && adev->have_disp_power_ref) {
> pm_runtime_put_autosuspend(dev->dev);
> adev->have_disp_power_ref = false;
> @@ -507,11 +509,10 @@ bool amdgpu_display_ddc_probe(struct amdgpu_connector 
> *amdgpu_connector,
> if (amdgpu_connector->router.ddc_valid)
> amdgpu_i2c_router_select_ddc_port(amdgpu_connector);
>
> -   if (use_aux) {
> +   if (use_aux)
> ret = i2c_transfer(_connector->ddc_bus->aux.ddc, msgs, 
> 2);
> -   } else {
> +   else
> ret = i2c_transfer(_connector->ddc_bus->adapter, msgs, 
> 2);
> -   }
>
> if (ret != 2)
> /* Couldn't find an accessible DDC on this connector */
> @@ -520,10 +521,12 @@ bool amdgpu_display_ddc_probe(struct amdgpu_connector 
> *amdgpu_connector,
>  * EDID header starts with:
>  * 0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00.
>  * Only the first 6 bytes must be valid as
> -* drm_edid_block_valid() can fix the last 2 bytes */
> +* drm_edid_block_valid() can fix the last 2 bytes
> +*/
> if (drm_edid_header_is_valid(buf) < 6) {
> /* Couldn't find an accessible EDID on this
> -* connector */
> +* connector
> +*/
> return false;
> }
> return true;
> @@ -1216,8 +1219,10 @@ amdgpu_display_user_framebuffer_create(struct 
> drm_device *dev,
>
> obj = drm_gem_object_lookup(file_priv, mode_cmd->handles[0]);
> if (obj ==  NULL) {
> -   drm_dbg_kms(dev, "No GEM object associated to handle 0x%08X, "
> -   "can't create framebuffer\n", 
> mode_cmd->handles[0]);
> +   drm_dbg_kms(dev, "No GEM object associated to handle 
> 0x%08X\n",
> +   mode_cmd->handles[0]);
> +   drm_dbg_kms(dev, "  - Can't create framebuffer\n");

Can you rework this to be a single debug statement?  Maybe
   drm_dbg_kms(dev,
   "No GEM object associated to handle 0x%08X,
can't create framebuffer\n"
   mode_cmd->handles[0]);

With that fixed,
Reviewed-by: Alex Deucher 


> +
> return ERR_PTR(-ENOENT);
> }
>
> @@ -1410,6 +1415,7 @@ bool amdgpu_display_crtc_scaling_mode_fixup(struct 
> drm_crtc *crtc,
> }
> if (amdgpu_crtc->rmx_type != RMX_OFF) {
> fixed20_12 a, b;
> +
> a.full = dfixed_const(src_v);
> b.full = dfixed_const(dst_v);
> amdgpu_crtc->vsc.full = dfixed_div(a, b);
> @@ -1429,7 +1435,7 @@ bool amdgpu_display_crtc_scaling_mode_fixup(struct 
> drm_crtc *crtc,
>   *
>   * \param dev Device to query.
>   * \param pipe Crtc to query.
> - * \param flags Flags from caller (DRM_CALLED_FROM_VBLIRQ or 0).
> + * \param flags from caller (DRM_CALLED_FROM_VBLIRQ or 0).
>   *  For driver internal 

[PATCH 6.4] drm/client: Send hotplug event after registering a client

2023-07-20 Thread Mario Limonciello
From: Thomas Zimmermann 

Generate a hotplug event after registering a client to allow the
client to configure its display. Remove the hotplug calls from the
existing clients for fbdev emulation. This change fixes a concurrency
bug between registering a client and receiving events from the DRM
core. The bug is present in the fbdev emulation of all drivers.

The fbdev emulation currently generates a hotplug event before
registering the client to the device. For each new output, the DRM
core sends an additional hotplug event to each registered client.

If the DRM core detects first output between sending the artificial
hotplug and registering the device, the output's hotplug event gets
lost. If this is the first output, the fbdev console display remains
dark. This has been observed with amdgpu and fbdev-generic.

Fix this by adding hotplug generation directly to the client's
register helper drm_client_register(). Registering the client and
receiving events are serialized by struct drm_device.clientlist_mutex.
So an output is either configured by the initial hotplug event, or
the client has already been registered.

The bug was originally added in commit 6e3f17ee73f7 ("drm/fb-helper:
generic: Call drm_client_add() after setup is done"), in which adding
a client and receiving a hotplug event switched order. It was hidden,
as most hardware and drivers have at least on static output configured.
Other drivers didn't use the internal DRM client or still had struct
drm_mode_config_funcs.output_poll_changed set. That callback handled
hotplug events as well. After not setting the callback in amdgpu in
commit 0e3172bac3f4 ("drm/amdgpu: Don't set struct
drm_driver.output_poll_changed"), amdgpu did not show a framebuffer
console if output events got lost. The bug got copy-pasted from
fbdev-generic into the other fbdev emulation.

Reported-by: Moritz Duge 
Closes: https://gitlab.freedesktop.org/drm/amd/-/issues/2649
Fixes: 6e3f17ee73f7 ("drm/fb-helper: generic: Call drm_client_add() after setup 
is done")
Fixes: 8ab59da26bc0 ("drm/fb-helper: Move generic fbdev emulation into separate 
source file")
Fixes: b79fe9abd58b ("drm/fbdev-dma: Implement fbdev emulation for GEM DMA 
helpers")
Fixes: 63c381552f69 ("drm/armada: Implement fbdev emulation as in-kernel 
client")
Fixes: 49953b70e7d3 ("drm/exynos: Implement fbdev emulation as in-kernel 
client")
Fixes: 8f1aaccb04b7 ("drm/gma500: Implement client-based fbdev emulation")
Fixes: 940b869c2f2f ("drm/msm: Implement fbdev emulation as in-kernel client")
Fixes: 9e69bcd88e45 ("drm/omapdrm: Implement fbdev emulation as in-kernel 
client")
Fixes: e317a69fe891 ("drm/radeon: Implement client-based fbdev emulation")
Fixes: 71ec16f45ef8 ("drm/tegra: Implement fbdev emulation as in-kernel client")
Fixes: 0e3172bac3f4 ("drm/amdgpu: Don't set struct 
drm_driver.output_poll_changed")
Signed-off-by: Thomas Zimmermann 
Tested-by: Moritz Duge 
Tested-by: Torsten Krah 
Tested-by: Paul Schyska 
Cc: Daniel Vetter 
Cc: David Airlie 
Cc: Noralf Trønnes 
Cc: Maarten Lankhorst 
Cc: Maxime Ripard 
Cc: Javier Martinez Canillas 
Cc: Russell King 
Cc: Inki Dae 
Cc: Seung-Woo Kim 
Cc: Kyungmin Park 
Cc: Krzysztof Kozlowski 
Cc: Patrik Jakobsson 
Cc: Rob Clark 
Cc: Abhinav Kumar 
Cc: Dmitry Baryshkov 
Cc: Tomi Valkeinen 
Cc: Alex Deucher 
Cc: "Christian König" 
Cc: "Pan, Xinhui" 
Cc: Thierry Reding 
Cc: Mikko Perttunen 
Cc: dri-de...@lists.freedesktop.org
Cc: linux-ker...@vger.kernel.org
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-samsung-...@vger.kernel.org
Cc: linux-arm-...@vger.kernel.org
Cc: freedr...@lists.freedesktop.org
Cc: amd-gfx@lists.freedesktop.org
Cc: linux-te...@vger.kernel.org
Cc: dri-de...@lists.freedesktop.org
Cc:  # v5.2+
Reviewed-by: Javier Martinez Canillas 
Reviewed-by: Dmitry Baryshkov  # msm
Link: 
https://patchwork.freedesktop.org/patch/msgid/20230710091029.27503-1-tzimmerm...@suse.de
(cherry picked from commit 27655b9bb9f0d9c32b8de8bec649b676898c52d5)
Dropped changes to drivers/gpu/drm/armada/armada_fbdev.c as
174c3c38e3a2 drm/armada: Initialize fbdev DRM client
was introduced in 6.5-rc1
Signed-off-by: Mario Limonciello 
---
 drivers/gpu/drm/drm_client.c  | 21 +
 drivers/gpu/drm/drm_fbdev_dma.c   |  4 
 drivers/gpu/drm/drm_fbdev_generic.c   |  4 
 drivers/gpu/drm/exynos/exynos_drm_fbdev.c |  4 
 drivers/gpu/drm/gma500/fbdev.c|  4 
 drivers/gpu/drm/msm/msm_fbdev.c   |  4 
 drivers/gpu/drm/omapdrm/omap_fbdev.c  |  4 
 drivers/gpu/drm/radeon/radeon_fbdev.c |  4 
 drivers/gpu/drm/tegra/fbdev.c |  4 
 9 files changed, 21 insertions(+), 32 deletions(-)

diff --git a/drivers/gpu/drm/drm_client.c b/drivers/gpu/drm/drm_client.c
index f6292ba0e6fc..037e36f2049c 100644
--- a/drivers/gpu/drm/drm_client.c
+++ b/drivers/gpu/drm/drm_client.c
@@ -122,13 +122,34 @@ EXPORT_SYMBOL(drm_client_init);
  * drm_client_register() it is no longer permissible to call 

[PATCH 6.1] drm/client: Send hotplug event after registering a client

2023-07-20 Thread Mario Limonciello
From: Thomas Zimmermann 

Generate a hotplug event after registering a client to allow the
client to configure its display. Remove the hotplug calls from the
existing clients for fbdev emulation. This change fixes a concurrency
bug between registering a client and receiving events from the DRM
core. The bug is present in the fbdev emulation of all drivers.

The fbdev emulation currently generates a hotplug event before
registering the client to the device. For each new output, the DRM
core sends an additional hotplug event to each registered client.

If the DRM core detects first output between sending the artificial
hotplug and registering the device, the output's hotplug event gets
lost. If this is the first output, the fbdev console display remains
dark. This has been observed with amdgpu and fbdev-generic.

Fix this by adding hotplug generation directly to the client's
register helper drm_client_register(). Registering the client and
receiving events are serialized by struct drm_device.clientlist_mutex.
So an output is either configured by the initial hotplug event, or
the client has already been registered.

The bug was originally added in commit 6e3f17ee73f7 ("drm/fb-helper:
generic: Call drm_client_add() after setup is done"), in which adding
a client and receiving a hotplug event switched order. It was hidden,
as most hardware and drivers have at least on static output configured.
Other drivers didn't use the internal DRM client or still had struct
drm_mode_config_funcs.output_poll_changed set. That callback handled
hotplug events as well. After not setting the callback in amdgpu in
commit 0e3172bac3f4 ("drm/amdgpu: Don't set struct
drm_driver.output_poll_changed"), amdgpu did not show a framebuffer
console if output events got lost. The bug got copy-pasted from
fbdev-generic into the other fbdev emulation.

Reported-by: Moritz Duge 
Closes: https://gitlab.freedesktop.org/drm/amd/-/issues/2649
Fixes: 6e3f17ee73f7 ("drm/fb-helper: generic: Call drm_client_add() after setup 
is done")
Fixes: 8ab59da26bc0 ("drm/fb-helper: Move generic fbdev emulation into separate 
source file")
Fixes: b79fe9abd58b ("drm/fbdev-dma: Implement fbdev emulation for GEM DMA 
helpers")
Fixes: 63c381552f69 ("drm/armada: Implement fbdev emulation as in-kernel 
client")
Fixes: 49953b70e7d3 ("drm/exynos: Implement fbdev emulation as in-kernel 
client")
Fixes: 8f1aaccb04b7 ("drm/gma500: Implement client-based fbdev emulation")
Fixes: 940b869c2f2f ("drm/msm: Implement fbdev emulation as in-kernel client")
Fixes: 9e69bcd88e45 ("drm/omapdrm: Implement fbdev emulation as in-kernel 
client")
Fixes: e317a69fe891 ("drm/radeon: Implement client-based fbdev emulation")
Fixes: 71ec16f45ef8 ("drm/tegra: Implement fbdev emulation as in-kernel client")
Fixes: 0e3172bac3f4 ("drm/amdgpu: Don't set struct 
drm_driver.output_poll_changed")
Signed-off-by: Thomas Zimmermann 
Tested-by: Moritz Duge 
Tested-by: Torsten Krah 
Tested-by: Paul Schyska 
Cc: Daniel Vetter 
Cc: David Airlie 
Cc: Noralf Trønnes 
Cc: Maarten Lankhorst 
Cc: Maxime Ripard 
Cc: Javier Martinez Canillas 
Cc: Russell King 
Cc: Inki Dae 
Cc: Seung-Woo Kim 
Cc: Kyungmin Park 
Cc: Krzysztof Kozlowski 
Cc: Patrik Jakobsson 
Cc: Rob Clark 
Cc: Abhinav Kumar 
Cc: Dmitry Baryshkov 
Cc: Tomi Valkeinen 
Cc: Alex Deucher 
Cc: "Christian König" 
Cc: "Pan, Xinhui" 
Cc: Thierry Reding 
Cc: Mikko Perttunen 
Cc: dri-de...@lists.freedesktop.org
Cc: linux-ker...@vger.kernel.org
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-samsung-...@vger.kernel.org
Cc: linux-arm-...@vger.kernel.org
Cc: freedr...@lists.freedesktop.org
Cc: amd-gfx@lists.freedesktop.org
Cc: linux-te...@vger.kernel.org
Cc: dri-de...@lists.freedesktop.org
Cc:  # v5.2+
Reviewed-by: Javier Martinez Canillas 
Reviewed-by: Dmitry Baryshkov  # msm
Link: 
https://patchwork.freedesktop.org/patch/msgid/20230710091029.27503-1-tzimmerm...@suse.de
(cherry picked from commit 27655b9bb9f0d9c32b8de8bec649b676898c52d5)
Dropped changes to drivers/gpu/drm/armada/armada_fbdev.c as
174c3c38e3a2 drm/armada: Initialize fbdev DRM client
was introduced in 6.5-rc1.

Dropped changes to exynos, msm, omapdrm, radeon, tegra drivers
as missing code these commits introduced:

99286486d674 drm/exynos: Initialize fbdev DRM client
841ef552b141 drm/msm: Initialize fbdev DRM client
9e69bcd88e45 drm/omapdrm: Implement fbdev emulation as in-kernel client
e317a69fe891 drm/radeon: Implement client-based fbdev emulation
9b926bcf2636 drm/radeon: Only build fbdev if DRM_FBDEV_EMULATION is set
25dda38e0b07 drm/tegra: Initialize fbdev DRM client
8f1aaccb04b7 drm/gma500: Implement client-based fbdev emulation
b79fe9abd58b drm/fbdev-dma: Implement fbdev emulation for GEM DMA helpers

Move code for drm-fbdev-generic.c to matching file in 6.1.y because
these commits haven't happened in 6.1.y.
8ab59da26bc0 drm/fb-helper: Move generic fbdev emulation into separate source 
file
b9c93f4ec737 drm/fbdev-generic: Rename symbols

Cc: alexandru.gagn...@hp.com
Link: 

[pull] amdgpu drm-fixes-6.5

2023-07-20 Thread Alex Deucher
Hi Dave, Daniel,

Fixes for 6.5.

The following changes since commit fdf0eaf11452d72945af31804e2a1048ee1b574c:

  Linux 6.5-rc2 (2023-07-16 15:10:37 -0700)

are available in the Git repository at:

  https://gitlab.freedesktop.org/agd5f/linux.git 
tags/amd-drm-fixes-6.5-2023-07-20

for you to fetch changes up to b13d3e9c6b62597a5c31fdc74febb3bc588893bf:

  drm/amdgpu: use a macro to define no xcp partition case (2023-07-18 14:42:54 
-0400)


amd-drm-fixes-6.5-2023-07-20:

amdgpu:
- More PCIe DPM fixes for Intel platforms
- DCN3.0.1 fixes
- Virtual display timer fix
- Async flip fix
- SMU13 clock reporting fixes
- Add missing PSP firmware declaration
- DP MST fix
- DCN3.1.x fixes
- Slab out of bounds fix


Alex Deucher (2):
  drm/amdgpu/pm: make gfxclock consistent for sienna cichlid
  drm/amdgpu/pm: make mclk consistent for smu 13.0.7

Aurabindo Pillai (2):
  drm/amd/display: export some optc function for reuse
  drm/amd/display: add DCN301 specific logic for OTG programming

Candice Li (1):
  drm/amdgpu: Allow the initramfs generator to include psp_13_0_6_ta

Daniel Miess (1):
  drm/amd/display: Prevent vtotal from being set to 0

Guchun Chen (5):
  drm/amdgpu/vkms: relax timer deactivation by hrtimer_try_to_cancel
  drm/amdgpu: Allocate root PD on correct partition
  drm/amdgpu: fix slab-out-of-bounds issue in amdgpu_vm_pt_create
  drm/amdgpu/vm: use the same xcp_id from root PD
  drm/amdgpu: use a macro to define no xcp partition case

Mario Limonciello (1):
  drm/amd: Use amdgpu_device_pcie_dynamic_switching_supported() for SMU7

Nicholas Kazlauskas (1):
  drm/amd/display: Keep PHY active for DP displays on DCN31

Simon Ser (1):
  drm/amd/display: only accept async flips for fast updates

Srinivasan Shanmugam (1):
  drm/amd/display: Clean up errors & warnings in amdgpu_dm.c

Taimur Hassan (1):
  drm/amd/display: check TG is non-null before checking if enabled

Wayne Lin (1):
  drm/amd/display: Add polling method to handle MST reply packet

Zhikai Zhai (1):
  drm/amd/display: Disable MPC split by default on special asic

 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c   |   3 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c|   6 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c|   2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c   |   5 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c |   5 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h |   5 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c  |  12 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c|   4 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.h|   2 +
 .../gpu/drm/amd/amdgpu/aqua_vanjaram_reg_init.c|   4 +-
 drivers/gpu/drm/amd/amdgpu/psp_v13_0.c |   1 +
 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c  | 256 +
 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h  |   7 +
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crtc.c |  12 +
 .../amd/display/amdgpu_dm/amdgpu_dm_mst_types.c| 110 +
 .../amd/display/amdgpu_dm/amdgpu_dm_mst_types.h|  11 +
 .../amd/display/dc/clk_mgr/dcn31/dcn31_clk_mgr.c   |   5 +
 .../drm/amd/display/dc/dcn10/dcn10_hw_sequencer.c  |   3 +-
 drivers/gpu/drm/amd/display/dc/dcn30/dcn30_optc.c  |   4 +-
 drivers/gpu/drm/amd/display/dc/dcn30/dcn30_optc.h  |   3 +
 drivers/gpu/drm/amd/display/dc/dcn301/Makefile |   3 +-
 .../gpu/drm/amd/display/dc/dcn301/dcn301_optc.c| 185 +++
 .../gpu/drm/amd/display/dc/dcn301/dcn301_optc.h|  36 +++
 .../drm/amd/display/dc/dcn301/dcn301_resource.c|   4 +-
 .../drm/amd/display/dc/dcn303/dcn303_resource.c|   2 +-
 .../gpu/drm/amd/display/dc/dml/dcn314/dcn314_fpu.c |   6 +-
 .../gpu/drm/amd/pm/powerplay/hwmgr/smu7_hwmgr.c|  14 +-
 .../drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c|   8 +-
 .../gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c   |   2 +-
 29 files changed, 524 insertions(+), 196 deletions(-)
 create mode 100644 drivers/gpu/drm/amd/display/dc/dcn301/dcn301_optc.c
 create mode 100644 drivers/gpu/drm/amd/display/dc/dcn301/dcn301_optc.h


Re: [PATCH 28/29] drm/amdkfd: Refactor migrate init to support partition switch

2023-07-20 Thread Michel Dänzer
On 7/17/23 15:09, Michel Dänzer wrote:
> On 5/10/23 23:23, Alex Deucher wrote:
>> From: Philip Yang 
>>
>> Rename smv_migrate_init to a better name kgd2kfd_init_zone_device
>> because it setup zone devive pgmap for page migration and keep it in
>> kfd_migrate.c to access static functions svm_migrate_pgmap_ops. Call it
>> only once in amdgpu_device_ip_init after adev ip blocks are initialized,
>> but before amdgpu_amdkfd_device_init initialize kfd nodes which enable
>> SVM support based on pgmap.
>>
>> svm_range_set_max_pages is called by kgd2kfd_device_init everytime after
>> switching compute partition mode.
>>
>> Signed-off-by: Philip Yang 
>> Reviewed-by: Felix Kuehling 
>> Signed-off-by: Alex Deucher 
> 
> I bisected a regression to this commit, which broke HW acceleration on this 
> ThinkPad E595 with Picasso APU.

Actually, it doesn't seem to break HW acceleration completely. GDM eventually 
comes up with HW acceleration, it takes a long time (~30s or so) to start up 
though.

Later, the same messages as described in 
https://gitlab.freedesktop.org/drm/amd/-/issues/2659 appear.

Reverting this commit fixes all of the above symptoms.


I reproduced all of the above symptoms with amd-staging-drm-next commit 
75515acf4b60 ("i2c: nvidia-gpu: Add ACPI property to align with device-tree") 
as well.


For full disclosure, I use these kernel command line arguments:

 fbcon=font:10x18 drm_kms_helper.drm_fbdev_overalloc=112 amdgpu.noretry=1 
amdgpu.mcbp=1


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



[PATCH v2] drm/radeon: Prefer dev_* variant over printk

2023-07-20 Thread Srinivasan Shanmugam
Changed from pr_err/info to dev_* variants so that
we get better debug info when there are multiple GPUs
in the system.

'Fixes: 8e2503972912c ("drm/radeon: Prefer pr_err/_info over printk")'
Suggested-by: Alex Deucher 
Cc: Christian König 
Cc: Alex Deucher 
Signed-off-by: Srinivasan Shanmugam 
---
 drivers/gpu/drm/radeon/radeon_atpx_handler.c | 12 
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/radeon/radeon_atpx_handler.c 
b/drivers/gpu/drm/radeon/radeon_atpx_handler.c
index 595354e3ce0b..fb4d931fdf18 100644
--- a/drivers/gpu/drm/radeon/radeon_atpx_handler.c
+++ b/drivers/gpu/drm/radeon/radeon_atpx_handler.c
@@ -94,6 +94,8 @@ static union acpi_object *radeon_atpx_call(acpi_handle 
handle, int function,
union acpi_object atpx_arg_elements[2];
struct acpi_object_list atpx_arg;
struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
+   struct acpi_device *adev = container_of(handle, struct acpi_device, 
handle);
+   struct device *dev = >dev;
 
atpx_arg.count = 2;
atpx_arg.pointer = _arg_elements[0];
@@ -115,8 +117,8 @@ static union acpi_object *radeon_atpx_call(acpi_handle 
handle, int function,
 
/* Fail only if calling the method fails and ATPX is supported */
if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
-   pr_err("failed to evaluate ATPX got %s\n",
-  acpi_format_exception(status));
+   dev_err(dev, "failed to evaluate ATPX got %s\n",
+   acpi_format_exception(status));
kfree(buffer.pointer);
return NULL;
}
@@ -157,6 +159,8 @@ static void radeon_atpx_parse_functions(struct 
radeon_atpx_functions *f, u32 mas
 static int radeon_atpx_validate(struct radeon_atpx *atpx)
 {
u32 valid_bits = 0;
+   struct acpi_device *adev = container_of(atpx->handle, struct 
acpi_device, handle);
+   struct device *dev = >dev;
 
if (atpx->functions.px_params) {
union acpi_object *info;
@@ -171,7 +175,7 @@ static int radeon_atpx_validate(struct radeon_atpx *atpx)
 
size = *(u16 *) info->buffer.pointer;
if (size < 10) {
-   pr_err("ATPX buffer is too small: %zu\n", size);
+   dev_err(dev, "ATPX buffer is too small: %zu\n", size);
kfree(info);
return -EINVAL;
}
@@ -202,7 +206,7 @@ static int radeon_atpx_validate(struct radeon_atpx *atpx)
 
atpx->is_hybrid = false;
if (valid_bits & ATPX_MS_HYBRID_GFX_SUPPORTED) {
-   pr_info("ATPX Hybrid Graphics\n");
+   dev_info(dev, "ATPX Hybrid Graphics\n");
/*
 * Disable legacy PM methods only when pcie port PM is usable,
 * otherwise the device might fail to power off or power on.
-- 
2.25.1



[PATCH] vt: remove spaces after '*'

2023-07-20 Thread sunran001

remove redundant spaces to clear checkpatch errors.

ERROR: "foo * bar" should be "foo *bar"

Signed-off-by: Ran Sun 
---
 include/linux/kbd_kern.h | 20 ++--
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/include/linux/kbd_kern.h b/include/linux/kbd_kern.h
index c40811d79769..6cb4ab685a84 100644
--- a/include/linux/kbd_kern.h
+++ b/include/linux/kbd_kern.h
@@ -69,52 +69,52 @@ extern void (*kbd_ledfunc)(unsigned int led);
 extern int set_console(int nr);
 extern void schedule_console_callback(void);

-static inline int vc_kbd_mode(struct kbd_struct * kbd, int flag)
+static inline int vc_kbd_mode(struct kbd_struct *kbd, int flag)
 {
return ((kbd->modeflags >> flag) & 1);
 }

-static inline int vc_kbd_led(struct kbd_struct * kbd, int flag)
+static inline int vc_kbd_led(struct kbd_struct *kbd, int flag)
 {
return ((kbd->ledflagstate >> flag) & 1);
 }

-static inline void set_vc_kbd_mode(struct kbd_struct * kbd, int flag)
+static inline void set_vc_kbd_mode(struct kbd_struct *kbd, int flag)
 {
kbd->modeflags |= 1 << flag;
 }

-static inline void set_vc_kbd_led(struct kbd_struct * kbd, int flag)
+static inline void set_vc_kbd_led(struct kbd_struct *kbd, int flag)
 {
kbd->ledflagstate |= 1 << flag;
 }

-static inline void clr_vc_kbd_mode(struct kbd_struct * kbd, int flag)
+static inline void clr_vc_kbd_mode(struct kbd_struct *kbd, int flag)
 {
kbd->modeflags &= ~(1 << flag);
 }

-static inline void clr_vc_kbd_led(struct kbd_struct * kbd, int flag)
+static inline void clr_vc_kbd_led(struct kbd_struct *kbd, int flag)
 {
kbd->ledflagstate &= ~(1 << flag);
 }

-static inline void chg_vc_kbd_lock(struct kbd_struct * kbd, int flag)
+static inline void chg_vc_kbd_lock(struct kbd_struct *kbd, int flag)
 {
kbd->lockstate ^= 1 << flag;
 }

-static inline void chg_vc_kbd_slock(struct kbd_struct * kbd, int flag)
+static inline void chg_vc_kbd_slock(struct kbd_struct *kbd, int flag)
 {
kbd->slockstate ^= 1 << flag;
 }

-static inline void chg_vc_kbd_mode(struct kbd_struct * kbd, int flag)
+static inline void chg_vc_kbd_mode(struct kbd_struct *kbd, int flag)
 {
kbd->modeflags ^= 1 << flag;
 }

-static inline void chg_vc_kbd_led(struct kbd_struct * kbd, int flag)
+static inline void chg_vc_kbd_led(struct kbd_struct *kbd, int flag)
 {
kbd->ledflagstate ^= 1 << flag;
 }


Re: [PATCH v2 3/4] selinux: use vma_is_initial_stack() and vma_is_initial_heap()

2023-07-20 Thread Kefeng Wang




On 2023/7/19 23:25, Paul Moore wrote:

On Wed, Jul 19, 2023 at 6:23 AM Kefeng Wang  wrote:

On 2023/7/19 17:02, Christian Göttsche wrote:

On Wed, 19 Jul 2023 at 09:40, Kefeng Wang  wrote:


Use the helpers to simplify code.

Cc: Paul Moore 
Cc: Stephen Smalley 
Cc: Eric Paris 
Acked-by: Paul Moore 
Signed-off-by: Kefeng Wang 
---
   security/selinux/hooks.c | 7 ++-
   1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index d06e350fedee..ee8575540a8e 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -3762,13 +3762,10 @@ static int selinux_file_mprotect(struct vm_area_struct 
*vma,
  if (default_noexec &&
  (prot & PROT_EXEC) && !(vma->vm_flags & VM_EXEC)) {
  int rc = 0;
-   if (vma->vm_start >= vma->vm_mm->start_brk &&
-   vma->vm_end <= vma->vm_mm->brk) {
+   if (vma_is_initial_heap(vma)) {


This seems to change the condition from

  vma->vm_start >= vma->vm_mm->start_brk && vma->vm_end <= vma->vm_mm->brk

to

  vma->vm_start <= vma->vm_mm->brk && vma->vm_end >= vma->vm_mm->start_brk

(or AND arguments swapped)

  vma->vm_end >= vma->vm_mm->start_brk && vma->vm_start <= vma->vm_mm->brk

Is this intended?


The new condition is to check whether there is intersection between
[startbrk,brk] and [vm_start,vm_end], it contains orignal check, so
I think it is ok, but for selinux check, I am not sure if there is
some other problem.


This particular SELinux vma check is see if the vma falls within the
heap; can you confirm that this change preserves this?


Yes, within is one case of new vma scope check.





Re: [PATCH v3 0/9] PCI/VGA: Improve the default VGA device selection

2023-07-20 Thread Sui Jingfeng

Hi,

On 2023/7/20 03:32, Bjorn Helgaas wrote:

   drm/amdgpu: Implement the is_primary_gpu callback of
 vga_client_register()
   drm/radeon: Add an implement for the is_primary_gpu function callback
   drm/i915: Add an implement for the is_primary_gpu hook
   drm/ast: Register as a vga client to vgaarb by calling
 vga_client_register()
   drm/loongson: Add an implement for the is_primary_gpu function
 callback

There's unnecessary variation in the subject lines (and the commit
logs) of these patches.  If they all do the same thing but in
different drivers, it's useful if the patches all*look*  the same.

You might be able to write these subjects as
"Implement .is_primary_gpu() callback" for brevity.



This is a very good suggestion, I will adopt this.

Thanks, really.



[bug report] drm/amd/display: Reduce stack size

2023-07-20 Thread Dan Carpenter
Hello Rodrigo Siqueira,

The patch 135fd1b35690: "drm/amd/display: Reduce stack size" from Jun
21, 2023 (linux-next), leads to the following Smatch static checker
warning:

drivers/gpu/drm/amd/amdgpu/../display/amdgpu_dm/amdgpu_dm.c:8785 
amdgpu_dm_atomic_commit_tail()
error: potential null dereference 'dummy_updates'.  (kzalloc returns 
null)

drivers/gpu/drm/amd/amdgpu/../display/amdgpu_dm/amdgpu_dm.c
8771 status = 
dc_stream_get_status(dm_new_crtc_state->stream);
8772 
8773 if (WARN_ON(!status))
8774 continue;
8775 
8776 WARN_ON(!status->plane_count);
8777 
8778 /*
8779  * TODO: DC refuses to perform stream updates without 
a dc_surface_update.
8780  * Here we create an empty update on each plane.
8781  * To fix this, DC should permit updating only stream 
properties.
8782  */
8783 dummy_updates = kzalloc(sizeof(struct 
dc_surface_update) * MAX_SURFACES, GFP_ATOMIC);

This needs a NULL check.

8784 for (j = 0; j < status->plane_count; j++)
--> 8785 dummy_updates[j].surface = 
status->plane_states[0];
 
Kaplooey!

8786 
8787 
8788 mutex_lock(>dc_lock);
8789 dc_update_planes_and_stream(dm->dc,
8790 dummy_updates,
8791 status->plane_count,
8792 dm_new_crtc_state->stream,
8793 _update);
8794 mutex_unlock(>dc_lock);
8795 kfree(dummy_updates);

regards,
dan carpenter


[PATCH -next] drm/amdgpu: Fix one kernel-doc comment

2023-07-20 Thread Yang Li
Use colon to separate parameter name from their specific meaning.
silence the warning:

drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c:793: warning: Function parameter or 
member 'adev' not described in 'amdgpu_vm_pte_update_noretry_flags'

Signed-off-by: Yang Li 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c
index 83e1923f6775..96d601e209b8 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c
@@ -783,7 +783,7 @@ int amdgpu_vm_pde_update(struct amdgpu_vm_update_params 
*params,
 /**
  * amdgpu_vm_pte_update_noretry_flags - Update PTE no-retry flags
  *
- * @adev - amdgpu_device pointer
+ * @adev: amdgpu_device pointer
  * @flags: pointer to PTE flags
  *
  * Update PTE no-retry flags when TF is enabled.
-- 
2.20.1.7.g153144c



Re: [PATCH -next] drm/amdgpu: Fix one kernel-doc comment

2023-07-20 Thread Randy Dunlap



On 7/19/23 18:05, Yang Li wrote:
> Use colon to separate parameter name from their specific meaning.
> silence the warning:
> 
> drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c:793: warning: Function parameter or 
> member 'adev' not described in 'amdgpu_vm_pte_update_noretry_flags'
> 
> Signed-off-by: Yang Li 

Reviewed-by: Randy Dunlap 
Thanks.

> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c 
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c
> index 83e1923f6775..96d601e209b8 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c
> @@ -783,7 +783,7 @@ int amdgpu_vm_pde_update(struct amdgpu_vm_update_params 
> *params,
>  /**
>   * amdgpu_vm_pte_update_noretry_flags - Update PTE no-retry flags
>   *
> - * @adev - amdgpu_device pointer
> + * @adev: amdgpu_device pointer
>   * @flags: pointer to PTE flags
>   *
>   * Update PTE no-retry flags when TF is enabled.

-- 
~Randy


Re: [PATCH v3 4/9] PCI/VGA: Improve the default VGA device selection

2023-07-20 Thread Sui Jingfeng



On 2023/7/20 06:32, suijingfeng wrote:

it will be works no matter CONFIG_DRM_AST=m or CONFIG_DRM_AST=y



It will be works regardless of CONFIG_DRM_AST=m or CONFIG_DRM_AST=y.

When vgaarb call to the device driver, device driver already loaded 
successfully.


and the PCI(e) device emulation already finished.


So the last change the vgaarb gave us to override is actually happen 
very late.


But it will be happen as long as the device driver get loaded successfully.




RE: [PATCH 2/2] drm/amdgpu: not update the same version ras ta

2023-07-20 Thread Zhou1, Tao
[AMD Official Use Only - General]

> -Original Message-
> From: Chai, Thomas 
> Sent: Wednesday, July 19, 2023 8:40 PM
> To: amd-gfx@lists.freedesktop.org
> Cc: Chai, Thomas ; Zhang, Hawking
> ; Zhou1, Tao ; Li, Candice
> ; Yang, Stanley ; Chai, Thomas
> 
> Subject: [PATCH 2/2] drm/amdgpu: not update the same version ras ta
>
> not update the same version ras ta.

[Tao] don't update ras ta with same version

>
> Signed-off-by: YiPeng Chai 
> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_psp_ta.c | 20 +++-
>  1 file changed, 19 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp_ta.c
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp_ta.c
> index 049d34fd5ba0..c27574239fde 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp_ta.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp_ta.c
> @@ -120,6 +120,7 @@ static const struct file_operations
> ta_invoke_debugfs_fops = {
>   *   Transmit buffer:
>   *- TA type (4bytes)
>   *- TA bin length (4bytes)
> + *- TA bin version (4bytes)

[Tao] the patch is fine for me, but since the bin structure is updated, do we 
need to consider backward compatibility?

>   *- TA bin
>   *   Receive buffer:
>   *- TA ID (4bytes)
> @@ -148,6 +149,7 @@ static ssize_t ta_if_load_debugfs_write(struct file *fp,
> const char *buf, size_t
>   uint8_t  *ta_bin= NULL;
>   uint32_t copy_pos   = 0;
>   int  ret= 0;
> + uint32_t ta_version = 0;
>
>   struct amdgpu_device *adev= (struct amdgpu_device *)file_inode(fp)-
> >i_private;
>   struct psp_context   *psp = >psp;
> @@ -168,6 +170,12 @@ static ssize_t ta_if_load_debugfs_write(struct file *fp,
> const char *buf, size_t
>
>   copy_pos += sizeof(uint32_t);
>
> + ret = copy_from_user((void *)_version, [copy_pos],
> sizeof(uint32_t));
> + if (ret)
> + return -EFAULT;
> +
> + copy_pos += sizeof(uint32_t);
> +
>   ta_bin = kzalloc(ta_bin_len, GFP_KERNEL);
>   if (!ta_bin)
>   return -ENOMEM;
> @@ -185,6 +193,16 @@ static ssize_t ta_if_load_debugfs_write(struct file *fp,
> const char *buf, size_t
>   goto err_free_bin;
>   }
>
> + if (ta_version == context->bin_desc.fw_version) {
> + dev_info(adev->dev,
> +"new ta is same as running ta, running ta will not be
> updated!\n");
> + if (copy_to_user((char *)buf, (void *)>session_id,
> sizeof(uint32_t)))
> + ret = -EFAULT;
> + else
> + ret = len;
> + goto err_free_bin;
> + }
> +
>   /*
>* Allocate TA shared buf in case shared buf was freed
>* due to loading TA failed before.
> @@ -209,7 +227,7 @@ static ssize_t ta_if_load_debugfs_write(struct file *fp,
> const char *buf, size_t
>
>   /* Prepare TA context for TA initialization */
>   context->ta_type = ta_type;
> - context->bin_desc.fw_version = get_bin_version(ta_bin);
> + context->bin_desc.fw_version = ta_version;
>   context->bin_desc.size_bytes = ta_bin_len;
>   context->bin_desc.start_addr = ta_bin;
>
> --
> 2.34.1



RE: [PATCH 1/2] drm/amdgpu: add ta initialization failure check condition

2023-07-20 Thread Zhou1, Tao
[AMD Official Use Only - General]

> -Original Message-
> From: Chai, Thomas 
> Sent: Wednesday, July 19, 2023 8:40 PM
> To: amd-gfx@lists.freedesktop.org
> Cc: Chai, Thomas ; Zhang, Hawking
> ; Zhou1, Tao ; Li, Candice
> ; Yang, Stanley ; Chai, Thomas
> 
> Subject: [PATCH 1/2] drm/amdgpu: add ta initialization failure check condition
>
> Add ta initialization failure check condition.

[Tao] better to say "Add condition check for ta initialization failure"

>
> Signed-off-by: YiPeng Chai 
> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_psp_ta.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp_ta.c
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp_ta.c
> index 468a67b302d4..049d34fd5ba0 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp_ta.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp_ta.c
> @@ -220,7 +220,7 @@ static ssize_t ta_if_load_debugfs_write(struct file *fp,
> const char *buf, size_t
>   }
>
>   ret = psp_fn_ta_initialize(psp);
> - if (ret || context->resp_status) {
> + if (ret || context->resp_status || !context->initialized) {
>   dev_err(adev->dev, "Failed to load TA via debugfs (%d) and 
> status
> (0x%X)\n",
>   ret, context->resp_status);
>   if (!ret)
> --
> 2.34.1



RE: [PATCH] drm/amdgpu: Program xcp_ctl registers as needed

2023-07-20 Thread Zhang, Hawking
[AMD Official Use Only - General]

Reviewed-by: Hawking Zhang 

Regards,
Hawking
-Original Message-
From: Lazar, Lijo 
Sent: Thursday, July 20, 2023 13:56
To: amd-gfx@lists.freedesktop.org
Cc: Zhang, Hawking ; Deucher, Alexander 
; Zhang, Morris 
Subject: [PATCH] drm/amdgpu: Program xcp_ctl registers as needed

XCP_CTL register is expected to be programmed by firmware. Under certain 
conditions FW may not have programmed it correctly. As a workaround, program it 
when FW has not programmed the right values.

Signed-off-by: Lijo Lazar 
---
 drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c | 23 ---
 1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c 
b/drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c
index 738226ed6e50..c567be88c47d 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c
@@ -621,7 +621,7 @@ static int gfx_v9_4_3_switch_compute_partition(struct 
amdgpu_device *adev,
int num_xccs_per_xcp)
 {
int ret, i, num_xcc;
-   u32 tmp = 0;
+   u32 tmp = 0, regval;

if (adev->psp.funcs) {
ret = psp_spatial_partition(>psp, @@ -629,23 +629,24 @@ 
static int gfx_v9_4_3_switch_compute_partition(struct amdgpu_device *adev,
num_xccs_per_xcp);
if (ret)
return ret;
-   } else {
-   num_xcc = NUM_XCC(adev->gfx.xcc_mask);
+   }
+
+   num_xcc = NUM_XCC(adev->gfx.xcc_mask);

-   for (i = 0; i < num_xcc; i++) {
-   tmp = REG_SET_FIELD(tmp, CP_HYP_XCP_CTL, NUM_XCC_IN_XCP,
-   num_xccs_per_xcp);
-   tmp = REG_SET_FIELD(tmp, CP_HYP_XCP_CTL, VIRTUAL_XCC_ID,
-   i % num_xccs_per_xcp);
+   for (i = 0; i < num_xcc; i++) {
+   tmp = REG_SET_FIELD(tmp, CP_HYP_XCP_CTL, NUM_XCC_IN_XCP,
+   num_xccs_per_xcp);
+   tmp = REG_SET_FIELD(tmp, CP_HYP_XCP_CTL, VIRTUAL_XCC_ID,
+   i % num_xccs_per_xcp);
+   regval = RREG32_SOC15(GC, GET_INST(GC, i), regCP_HYP_XCP_CTL);
+   if (regval != tmp)
WREG32_SOC15(GC, GET_INST(GC, i), regCP_HYP_XCP_CTL,
 tmp);
-   }
-   ret = 0;
}

adev->gfx.num_xcc_per_xcp = num_xccs_per_xcp;

-   return ret;
+   return 0;
 }

 static int gfx_v9_4_3_ih_to_xcc_inst(struct amdgpu_device *adev, int ih_node)
--
2.25.1