All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] drm/amdgpu: read FB through BAR0 when aperture is unavailable
@ 2026-07-01  5:53 chong li
  2026-07-01  5:53 ` [PATCH 2/2] drm/amdgpu: improve the amdgpu device init progress in sriov mode chong li
  2026-07-06 11:36 ` [PATCH 1/2] drm/amdgpu: read FB through BAR0 when aperture is unavailable Christian König
  0 siblings, 2 replies; 4+ messages in thread
From: chong li @ 2026-07-01  5:53 UTC (permalink / raw)
  To: amd-gfx; +Cc: HaiJun.Chang, Emily.Deng, chong li, Cursor

Allow early VRAM reads to fall back to a temporary BAR0 mapping
when the normal aperture mapping has not been established yet.

Signed-off-by: chong li <chongli2@amd.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 43 +++++++++++++++++++++-
 1 file changed, 42 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index 5442a1fc1c37..610d82b79de3 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
@@ -743,6 +743,44 @@ void amdgpu_device_mm_access(struct amdgpu_device *adev, loff_t pos,
 	drm_dev_exit(idx);
 }
 
+static int amdgpu_device_read_fb_via_bar0(struct amdgpu_device *adev,
+					  u64 offset, void *buf, size_t size)
+{
+	resource_size_t bar_start, bar_size, map_base;
+	void __iomem *vram;
+	size_t map_offset, map_size;
+	unsigned long flags;
+	u64 end;
+
+	if (!buf || !size)
+		return -EINVAL;
+
+	flags = pci_resource_flags(adev->pdev, 0);
+	if ((flags & IORESOURCE_UNSET) || !(flags & IORESOURCE_MEM))
+		return -EINVAL;
+
+	bar_size = pci_resource_len(adev->pdev, 0);
+	if (!bar_size)
+		return -ENODEV;
+
+	if (check_add_overflow(offset, size, &end) || end > bar_size)
+		return -EINVAL;
+
+	bar_start = pci_resource_start(adev->pdev, 0);
+	map_offset = offset_in_page(offset);
+	map_base = bar_start + (offset & PAGE_MASK);
+	map_size = PAGE_ALIGN(map_offset + size);
+
+	vram = ioremap_wc(map_base, map_size);
+	if (!vram)
+		return -ENOMEM;
+
+	memcpy_fromio(buf, (u8 __iomem *)vram + map_offset, size);
+	iounmap(vram);
+
+	return 0;
+}
+
 /**
  * amdgpu_device_aper_access - access vram by vram aperture
  *
@@ -762,8 +800,11 @@ size_t amdgpu_device_aper_access(struct amdgpu_device *adev, loff_t pos,
 	size_t count = 0;
 	uint64_t last;
 
-	if (!adev->mman.aper_base_kaddr)
+	if (!adev->mman.aper_base_kaddr) {
+		if (!write && !amdgpu_device_read_fb_via_bar0(adev, pos, buf, size))
+			return size;
 		return 0;
+	}
 
 	last = min(pos + size, adev->gmc.visible_vram_size);
 	if (last > pos) {
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] drm/amdgpu: improve the amdgpu device init progress in sriov mode
  2026-07-01  5:53 [PATCH 1/2] drm/amdgpu: read FB through BAR0 when aperture is unavailable chong li
@ 2026-07-01  5:53 ` chong li
  2026-07-06 11:39   ` Christian König
  2026-07-06 11:36 ` [PATCH 1/2] drm/amdgpu: read FB through BAR0 when aperture is unavailable Christian König
  1 sibling, 1 reply; 4+ messages in thread
From: chong li @ 2026-07-01  5:53 UTC (permalink / raw)
  To: amd-gfx; +Cc: HaiJun.Chang, Emily.Deng, chong li, Cursor

Move the initialization of non-GPU resources
out of the full GPU access region during AMDGPU device initialization

Signed-off-by: chong li <chongli2@amd.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index 610d82b79de3..c2ce4659ddc7 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
@@ -1994,10 +1994,6 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
 	amdgpu_device_enable_virtual_display(adev);
 
 	if (amdgpu_sriov_vf(adev)) {
-		r = amdgpu_virt_request_full_gpu(adev, true);
-		if (r)
-			return r;
-
 		r = amdgpu_virt_init_critical_region(adev);
 		if (r)
 			return r;
@@ -2159,6 +2155,12 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
 	if (!total)
 		return -ENODEV;
 
+	if (amdgpu_sriov_vf(adev)) {
+		r = amdgpu_virt_request_full_gpu(adev, true);
+		if (r)
+			return r;
+	}
+
 	if (adev->gmc.xgmi.supported)
 		amdgpu_xgmi_early_init(adev);
 
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] drm/amdgpu: read FB through BAR0 when aperture is unavailable
  2026-07-01  5:53 [PATCH 1/2] drm/amdgpu: read FB through BAR0 when aperture is unavailable chong li
  2026-07-01  5:53 ` [PATCH 2/2] drm/amdgpu: improve the amdgpu device init progress in sriov mode chong li
@ 2026-07-06 11:36 ` Christian König
  1 sibling, 0 replies; 4+ messages in thread
From: Christian König @ 2026-07-06 11:36 UTC (permalink / raw)
  To: chong li, amd-gfx; +Cc: HaiJun.Chang, Emily.Deng, Cursor

On 7/1/26 07:53, chong li wrote:
> Allow early VRAM reads to fall back to a temporary BAR0 mapping
> when the normal aperture mapping has not been established yet.

Clear NAK.

You are just trying to fix a symptom of incorrect initialization order here.

Regards,
Christian.

> 
> Signed-off-by: chong li <chongli2@amd.com>
> Co-authored-by: Cursor <cursoragent@cursor.com>
> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 43 +++++++++++++++++++++-
>  1 file changed, 42 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> index 5442a1fc1c37..610d82b79de3 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> @@ -743,6 +743,44 @@ void amdgpu_device_mm_access(struct amdgpu_device *adev, loff_t pos,
>  	drm_dev_exit(idx);
>  }
>  
> +static int amdgpu_device_read_fb_via_bar0(struct amdgpu_device *adev,
> +					  u64 offset, void *buf, size_t size)
> +{
> +	resource_size_t bar_start, bar_size, map_base;
> +	void __iomem *vram;
> +	size_t map_offset, map_size;
> +	unsigned long flags;
> +	u64 end;
> +
> +	if (!buf || !size)
> +		return -EINVAL;
> +
> +	flags = pci_resource_flags(adev->pdev, 0);
> +	if ((flags & IORESOURCE_UNSET) || !(flags & IORESOURCE_MEM))
> +		return -EINVAL;
> +
> +	bar_size = pci_resource_len(adev->pdev, 0);
> +	if (!bar_size)
> +		return -ENODEV;
> +
> +	if (check_add_overflow(offset, size, &end) || end > bar_size)
> +		return -EINVAL;
> +
> +	bar_start = pci_resource_start(adev->pdev, 0);
> +	map_offset = offset_in_page(offset);
> +	map_base = bar_start + (offset & PAGE_MASK);
> +	map_size = PAGE_ALIGN(map_offset + size);
> +
> +	vram = ioremap_wc(map_base, map_size);
> +	if (!vram)
> +		return -ENOMEM;
> +
> +	memcpy_fromio(buf, (u8 __iomem *)vram + map_offset, size);
> +	iounmap(vram);
> +
> +	return 0;
> +}
> +
>  /**
>   * amdgpu_device_aper_access - access vram by vram aperture
>   *
> @@ -762,8 +800,11 @@ size_t amdgpu_device_aper_access(struct amdgpu_device *adev, loff_t pos,
>  	size_t count = 0;
>  	uint64_t last;
>  
> -	if (!adev->mman.aper_base_kaddr)
> +	if (!adev->mman.aper_base_kaddr) {
> +		if (!write && !amdgpu_device_read_fb_via_bar0(adev, pos, buf, size))
> +			return size;
>  		return 0;
> +	}
>  
>  	last = min(pos + size, adev->gmc.visible_vram_size);
>  	if (last > pos) {


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 2/2] drm/amdgpu: improve the amdgpu device init progress in sriov mode
  2026-07-01  5:53 ` [PATCH 2/2] drm/amdgpu: improve the amdgpu device init progress in sriov mode chong li
@ 2026-07-06 11:39   ` Christian König
  0 siblings, 0 replies; 4+ messages in thread
From: Christian König @ 2026-07-06 11:39 UTC (permalink / raw)
  To: chong li, amd-gfx; +Cc: HaiJun.Chang, Emily.Deng, Cursor

On 7/1/26 07:53, chong li wrote:
> Move the initialization of non-GPU resources
> out of the full GPU access region during AMDGPU device initialization

As far as I can see that won't work like this.

There are a lot of steps which require full GPU access.

What exactly is the justification of the change?

Regards,
Christian.

> 
> Signed-off-by: chong li <chongli2@amd.com>
> Co-authored-by: Cursor <cursoragent@cursor.com>
> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> index 610d82b79de3..c2ce4659ddc7 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> @@ -1994,10 +1994,6 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
>  	amdgpu_device_enable_virtual_display(adev);
>  
>  	if (amdgpu_sriov_vf(adev)) {
> -		r = amdgpu_virt_request_full_gpu(adev, true);
> -		if (r)
> -			return r;
> -
>  		r = amdgpu_virt_init_critical_region(adev);
>  		if (r)
>  			return r;
> @@ -2159,6 +2155,12 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
>  	if (!total)
>  		return -ENODEV;
>  
> +	if (amdgpu_sriov_vf(adev)) {
> +		r = amdgpu_virt_request_full_gpu(adev, true);
> +		if (r)
> +			return r;
> +	}
> +
>  	if (adev->gmc.xgmi.supported)
>  		amdgpu_xgmi_early_init(adev);
>  


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-07-06 11:39 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-01  5:53 [PATCH 1/2] drm/amdgpu: read FB through BAR0 when aperture is unavailable chong li
2026-07-01  5:53 ` [PATCH 2/2] drm/amdgpu: improve the amdgpu device init progress in sriov mode chong li
2026-07-06 11:39   ` Christian König
2026-07-06 11:36 ` [PATCH 1/2] drm/amdgpu: read FB through BAR0 when aperture is unavailable Christian König

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.