Skip to contentSkip to conversation

drm/amdgpu: reserve 64M stolen memory for Apple 5K iMac

PATCH Superseded Richard Lane 4 participants 9 messages Oct 26 – Oct 28

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 drm/amdgpu: reserve 64M stolen memory for Apple 5K iMac

Apple 27" 5K iMacs report a single 2560x2880 tile (28.125 MiB) in VIEWPORT_SIZE while scanning out up to 64 MiB across the relocated EFI framebuffer.

Override the stolen VGA memory allocation size to 64 MiB when matching PCI_VENDOR_ID_APPLE with a 2560x2880x4 viewport size to prevent framebuffer corruption during boot handover.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +9 -1
index 4204c3c750a8..8b196fbfa724 100644
@@ -1232,7 +1232,15 @@ void amdgpu_gmc_init_vga_resv_regions(struct amdgpu_device *adev)
 	} else {
 		size = amdgpu_gmc_get_vbios_fb_size(adev);
 
-		if (adev->mman.keep_stolen_vga_memory)
+		/*
+		 * Apple 5K iMacs report one 2560x2880 tile in VIEWPORT_SIZE
+		 * while scanning out up to 64M across the relocated EFI
+		 * framebuffer.
+		 */
+		if (adev->pdev->subsystem_vendor == PCI_VENDOR_ID_APPLE &&
+		    size == (2560 * 2880 * 4))
+			size = 64U * 1024 * 1024;
+		else if (adev->mman.keep_stolen_vga_memory)
 			size = max(size, (unsigned)AMDGPU_VBIOS_VGA_ALLOCATION);
 	}
 
Signature · 1 line
2.55.0
maintainer
#1 lore raw
Quoted 7 lines · Richard Lane

Apple 27" 5K iMacs report a single 2560x2880 tile (28.125 MiB) in VIEWPORT_SIZE while scanning out up to 64 MiB across the relocated EFI framebuffer.

Override the stolen VGA memory allocation size to 64 MiB when matching PCI_VENDOR_ID_APPLE with a 2560x2880x4 viewport size to prevent framebuffer corruption during boot handover.

Hacks like those are usually a big no-go.

Why is that framebuffer handling not working with DC out of the box?

Regards,
Christian.

Quoted 29 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +9 -2
index 4204c3c750a8..8b196fbfa724 100644
@@ -1232,7 +1232,15 @@ void amdgpu_gmc_init_vga_resv_regions(struct amdgpu_device *adev)
        } else {
                size = amdgpu_gmc_get_vbios_fb_size(adev);
 
-               if (adev->mman.keep_stolen_vga_memory)
+               /*
+                * Apple 5K iMacs report one 2560x2880 tile in VIEWPORT_SIZE
+                * while scanning out up to 64M across the relocated EFI
+                * framebuffer.
+                */
+               if (adev->pdev->subsystem_vendor == PCI_VENDOR_ID_APPLE &&
+                   size == (2560 * 2880 * 4))
+                       size = 64U * 1024 * 1024;
+               else if (adev->mman.keep_stolen_vga_memory)
                        size = max(size, (unsigned)AMDGPU_VBIOS_VGA_ALLOCATION);
        }
 
--

2.55.0

#2 lore raw
Quoted 6 lines · Christian König
Quoted 4 lines · Richard Lane

Apple 27" 5K iMacs report a single 2560x2880 tile (28.125 MiB) in VIEWPORT_SIZE while scanning out up to 64 MiB across the relocated EFI framebuffer.

Quoted 7 lines
Quoted 3 lines

Override the stolen VGA memory allocation size to 64 MiB when matching PCI_VENDOR_ID_APPLE with a 2560x2880x4 viewport size to prevent framebuffer corruption during boot handover.

Hacks like those are usually a big no-go.

Why is that framebuffer handling not working with DC out of the box?

The GMC IP code reserves the memory used by the display hardware from the pre-OS console. The gmc get_vbios_fb_size() callback looks to see what display viewport was set by the pre-OS environment. If the Macs need a workaround, that's where it should go. Since these displays require multiple display pipes, my guess is you need to double the allocation in that case since the current code just checks the first pipe.

Alex

Quoted 34 lines

Regards,
Christian.

Quoted 29 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +9 -2
index 4204c3c750a8..8b196fbfa724 100644
@@ -1232,7 +1232,15 @@ void amdgpu_gmc_init_vga_resv_regions(struct amdgpu_device *adev)
        } else {
                size = amdgpu_gmc_get_vbios_fb_size(adev);
 
-               if (adev->mman.keep_stolen_vga_memory)
+               /*
+                * Apple 5K iMacs report one 2560x2880 tile in VIEWPORT_SIZE
+                * while scanning out up to 64M across the relocated EFI
+                * framebuffer.
+                */
+               if (adev->pdev->subsystem_vendor == PCI_VENDOR_ID_APPLE &&
+                   size == (2560 * 2880 * 4))
+                       size = 64U * 1024 * 1024;
+               else if (adev->mman.keep_stolen_vga_memory)
                        size = max(size, (unsigned)AMDGPU_VBIOS_VGA_ALLOCATION);
        }
 
--

2.55.0

#3 lore raw
Quoted 16 lines · Alex Deucher
Quoted 6 lines · Christian König
Quoted 4 lines · Richard Lane

Apple 27" 5K iMacs report a single 2560x2880 tile (28.125 MiB) in VIEWPORT_SIZE while scanning out up to 64 MiB across the relocated EFI framebuffer.

Quoted 7 lines
Quoted 3 lines

Override the stolen VGA memory allocation size to 64 MiB when matching PCI_VENDOR_ID_APPLE with a 2560x2880x4 viewport size to prevent framebuffer corruption during boot handover.

Hacks like those are usually a big no-go.

Why is that framebuffer handling not working with DC out of the box?

Quoted 7 lines

The GMC IP code reserves the memory used by the display hardware from the pre-OS console. The gmc get_vbios_fb_size() callback looks to see what display viewport was set by the pre-OS environment. If the Macs need a workaround, that's where it should go. Since these displays require multiple display pipes, my guess is you need to double the allocation in that case since the current code just checks the first pipe.

Could this also be a logic error in that callback? Would it be worth double checking all the register values in that callback for this system?

I know for example there are a few different IP specific implementations in gmc_v9_0_get_vbios_fb_size().

Quoted 37 lines

Alex

Quoted 34 lines

Regards,
Christian.

Quoted 29 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 10 +++++++++-
  1 file changed, 9 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +9 -2
index 4204c3c750a8..8b196fbfa724 100644
@@ -1232,7 +1232,15 @@ void amdgpu_gmc_init_vga_resv_regions(struct amdgpu_device *adev)
         } else {
                 size = amdgpu_gmc_get_vbios_fb_size(adev);
 
-               if (adev->mman.keep_stolen_vga_memory)
+               /*
+                * Apple 5K iMacs report one 2560x2880 tile in VIEWPORT_SIZE
+                * while scanning out up to 64M across the relocated EFI
+                * framebuffer.
+                */
+               if (adev->pdev->subsystem_vendor == PCI_VENDOR_ID_APPLE &&
+                   size == (2560 * 2880 * 4))
+                       size = 64U * 1024 * 1024;
+               else if (adev->mman.keep_stolen_vga_memory)
                         size = max(size, (unsigned)AMDGPU_VBIOS_VGA_ALLOCATION);
         }
 
--

2.55.0

#4 lore raw
Quoted 29 lines · Mario Limonciello
Quoted 16 lines · Alex Deucher
Quoted 6 lines · Christian König
Quoted 4 lines · Richard Lane

Apple 27" 5K iMacs report a single 2560x2880 tile (28.125 MiB) in VIEWPORT_SIZE while scanning out up to 64 MiB across the relocated EFI framebuffer.

Quoted 7 lines
Quoted 3 lines

Override the stolen VGA memory allocation size to 64 MiB when matching PCI_VENDOR_ID_APPLE with a 2560x2880x4 viewport size to prevent framebuffer corruption during boot handover.

Hacks like those are usually a big no-go.

Why is that framebuffer handling not working with DC out of the box?

Quoted 7 lines

The GMC IP code reserves the memory used by the display hardware from the pre-OS console. The gmc get_vbios_fb_size() callback looks to see what display viewport was set by the pre-OS environment. If the Macs need a workaround, that's where it should go. Since these displays require multiple display pipes, my guess is you need to double the allocation in that case since the current code just checks the first pipe.

Quoted 5 lines

Could this also be a logic error in that callback? Would it be worth double checking all the register values in that callback for this system?

I know for example there are a few different IP specific implementations in gmc_v9_0_get_vbios_fb_size().

Not likely. I suspect the issue is that these systems use two display pipes so we only reserve enough memory to cover half of the display. On PCs the vbios never sets up MST.

Alex

Quoted 39 lines
Quoted 38 lines

Alex

Quoted 34 lines

Regards,
Christian.

Quoted 29 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 10 +++++++++-
  1 file changed, 9 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +9 -2
index 4204c3c750a8..8b196fbfa724 100644
@@ -1232,7 +1232,15 @@ void amdgpu_gmc_init_vga_resv_regions(struct amdgpu_device *adev)
         } else {
                 size = amdgpu_gmc_get_vbios_fb_size(adev);
 
-               if (adev->mman.keep_stolen_vga_memory)
+               /*
+                * Apple 5K iMacs report one 2560x2880 tile in VIEWPORT_SIZE
+                * while scanning out up to 64M across the relocated EFI
+                * framebuffer.
+                */
+               if (adev->pdev->subsystem_vendor == PCI_VENDOR_ID_APPLE &&
+                   size == (2560 * 2880 * 4))
+                       size = 64U * 1024 * 1024;
+               else if (adev->mman.keep_stolen_vga_memory)
                         size = max(size, (unsigned)AMDGPU_VBIOS_VGA_ALLOCATION);
         }
 
--

2.55.0

#5 lore raw
Quoted 34 lines · Alex Deucher
Quoted 32 lines · Mario Limonciello
Quoted 16 lines · Alex Deucher
Quoted 6 lines · Christian König
Quoted 4 lines · Richard Lane

Apple 27" 5K iMacs report a single 2560x2880 tile (28.125 MiB) in VIEWPORT_SIZE while scanning out up to 64 MiB across the relocated EFI framebuffer.

Quoted 7 lines
Quoted 3 lines

Override the stolen VGA memory allocation size to 64 MiB when matching PCI_VENDOR_ID_APPLE with a 2560x2880x4 viewport size to prevent framebuffer corruption during boot handover.

Hacks like those are usually a big no-go.

Why is that framebuffer handling not working with DC out of the box?

Quoted 7 lines

The GMC IP code reserves the memory used by the display hardware from the pre-OS console. The gmc get_vbios_fb_size() callback looks to see what display viewport was set by the pre-OS environment. If the Macs need a workaround, that's where it should go. Since these displays require multiple display pipes, my guess is you need to double the allocation in that case since the current code just checks the first pipe.

Could this also be a logic error in that callback? Would it be worth double checking all the register values in that callback for this system?

Quoted 9 lines
Quoted 2 lines

I know for example there are a few different IP specific implementations in gmc_v9_0_get_vbios_fb_size().

Not likely. I suspect the issue is that these systems use two display pipes so we only reserve enough memory to cover half of the display. On PCs the vbios never sets up MST.

Alex

I tested doubling the allocation in gmc_v8_0_get_vbios_fb_size():

	if (adev->pdev->subsystem_vendor == PCI_VENDOR_ID_APPLE &&
	    size == (2560 * 2880 * 4))
		size *= 2;

That eliminated the corruption across the middle (45-60%) of the screen, but still left a band of corruption along the very bottom (95-100%) of the screen.

Dumping the DCE registers inside gmc_v8_0_get_vbios_fb_size() on the iMac17,1 showed:

vram_start = 0xf400000000, d1vga = 0x0
CRTC0: grph_en=0x1 surf_hi=0xf4 surf_lo=0x300000 pitch=5120 vp_size=2560x2880
CRTC1: grph_en=0x80000000 surf_hi=0x0 surf_lo=0x0 pitch=0 vp_size=0x0

Even though only CRTC0 is active at EFI boot with a 2560x2880 viewport, Apple's EFI allocates a full 5120-pixel stride surface (mmGRPH_PITCH) and places mmGRPH_PRIMARY_SURFACE_ADDRESS at a 3 MiB offset (0x300000) from vram_start.

Because CRTC0 scans out 2880 lines at a 5120-pixel pitch starting at offset 3 MiB, the active pre-OS scanout spans [3 MiB, 59.25 MiB) in VRAM:
- Reserving 2560 * 2880 * 4 (28.125 MiB) places permanent driver BOs at ~28.125..32 MiB, corrupting the middle (40-60%) of the screen.
- Reserving 2 * 2560 * 2880 * 4 (56.25 MiB) places those BOs at ~56.25..59.25 MiB, leaving the final 3 MiB exposed due to the 0x300000 surface offset and corrupting the bottom (95-100%) of the screen.
- Accounting for the 5120 pitch and the 0x300000 surface offset reserves the full 59.25 MiB span and eliminates the corruption completely.

For v2 of the patch, which of the following two approaches in both gmc_v7_0/v8_0_get_vbios_fb_size() would you prefer? Both tested working.

Option A (change whole function):

static unsigned gmc_v8_0_get_vbios_fb_size(struct amdgpu_device *adev) {
u32 d1vga_control = RREG32(mmD1VGA_CONTROL); unsigned size;

if (REG_GET_FIELD(d1vga_control, D1VGA_CONTROL, D1VGA_MODE_ENABLE)) {
size = AMDGPU_VBIOS_VGA_ALLOCATION;
} else {
u32 viewport = RREG32(mmVIEWPORT_SIZE);
- size = (REG_GET_FIELD(viewport, VIEWPORT_SIZE, VIEWPORT_HEIGHT) *
- REG_GET_FIELD(viewport, VIEWPORT_SIZE, VIEWPORT_WIDTH) * 4);
+ size = REG_GET_FIELD(viewport, VIEWPORT_SIZE, VIEWPORT_HEIGHT) *
+ RREG32(mmGRPH_PITCH) * 4;
+ if (size)
+ size += RREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS) -
+ lower_32_bits(adev->gmc.vram_start);
}

return size;
}

Option B (add Apple 5K iMacs quirk):

static unsigned gmc_v8_0_get_vbios_fb_size(struct amdgpu_device *adev) {
u32 d1vga_control = RREG32(mmD1VGA_CONTROL); unsigned size;

if (REG_GET_FIELD(d1vga_control, D1VGA_CONTROL, D1VGA_MODE_ENABLE)) {
size = AMDGPU_VBIOS_VGA_ALLOCATION;
} else {
u32 viewport = RREG32(mmVIEWPORT_SIZE);
size = (REG_GET_FIELD(viewport, VIEWPORT_SIZE, VIEWPORT_HEIGHT) *
REG_GET_FIELD(viewport, VIEWPORT_SIZE, VIEWPORT_WIDTH) * 4);
+
+ if (adev->pdev->subsystem_vendor == PCI_VENDOR_ID_APPLE &&
+ size == (2560 * 2880 * 4))
+ size = size * 2 + RREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS);
}

return size;
}

Richard

Quoted 39 lines
Quoted 39 lines
Quoted 38 lines

Alex

Quoted 34 lines

Regards,
Christian.

Quoted 29 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 10 +++++++++-
  1 file changed, 9 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +9 -2
index 4204c3c750a8..8b196fbfa724 100644
@@ -1232,7 +1232,15 @@ void amdgpu_gmc_init_vga_resv_regions(struct amdgpu_device *adev)
         } else {
                 size = amdgpu_gmc_get_vbios_fb_size(adev);
 
-               if (adev->mman.keep_stolen_vga_memory)
+               /*
+                * Apple 5K iMacs report one 2560x2880 tile in VIEWPORT_SIZE
+                * while scanning out up to 64M across the relocated EFI
+                * framebuffer.
+                */
+               if (adev->pdev->subsystem_vendor == PCI_VENDOR_ID_APPLE &&
+                   size == (2560 * 2880 * 4))
+                       size = 64U * 1024 * 1024;
+               else if (adev->mman.keep_stolen_vga_memory)
                         size = max(size, (unsigned)AMDGPU_VBIOS_VGA_ALLOCATION);
         }
 
--

2.55.0

#6 lore raw
Quoted 77 lines · Richard Lane
Quoted 34 lines · Alex Deucher
Quoted 32 lines · Mario Limonciello
Quoted 16 lines · Alex Deucher
Quoted 6 lines · Christian König
Quoted 4 lines · Richard Lane

Apple 27" 5K iMacs report a single 2560x2880 tile (28.125 MiB) in VIEWPORT_SIZE while scanning out up to 64 MiB across the relocated EFI framebuffer.

Quoted 7 lines
Quoted 3 lines

Override the stolen VGA memory allocation size to 64 MiB when matching PCI_VENDOR_ID_APPLE with a 2560x2880x4 viewport size to prevent framebuffer corruption during boot handover.

Hacks like those are usually a big no-go.

Why is that framebuffer handling not working with DC out of the box?

Quoted 7 lines

The GMC IP code reserves the memory used by the display hardware from the pre-OS console. The gmc get_vbios_fb_size() callback looks to see what display viewport was set by the pre-OS environment. If the Macs need a workaround, that's where it should go. Since these displays require multiple display pipes, my guess is you need to double the allocation in that case since the current code just checks the first pipe.

Could this also be a logic error in that callback? Would it be worth double checking all the register values in that callback for this system?

Quoted 9 lines
Quoted 2 lines

I know for example there are a few different IP specific implementations in gmc_v9_0_get_vbios_fb_size().

Not likely. I suspect the issue is that these systems use two display pipes so we only reserve enough memory to cover half of the display. On PCs the vbios never sets up MST.

Alex

I tested doubling the allocation in gmc_v8_0_get_vbios_fb_size():

	if (adev->pdev->subsystem_vendor == PCI_VENDOR_ID_APPLE &&
	    size == (2560 * 2880 * 4))
		size *= 2;

That eliminated the corruption across the middle (45-60%) of the screen, but still left a band of corruption along the very bottom (95-100%) of the screen.

Dumping the DCE registers inside gmc_v8_0_get_vbios_fb_size() on the iMac17,1 showed:

   vram_start = 0xf400000000, d1vga = 0x0
   CRTC0: grph_en=0x1 surf_hi=0xf4 surf_lo=0x300000 pitch=5120 vp_size=2560x2880
   CRTC1: grph_en=0x80000000 surf_hi=0x0 surf_lo=0x0 pitch=0 vp_size=0x0

Even though only CRTC0 is active at EFI boot with a 2560x2880 viewport, Apple's EFI allocates a full 5120-pixel stride surface (mmGRPH_PITCH) and places mmGRPH_PRIMARY_SURFACE_ADDRESS at a 3 MiB offset (0x300000) from vram_start.

Because CRTC0 scans out 2880 lines at a 5120-pixel pitch starting at offset 3 MiB, the active pre-OS scanout spans [3 MiB, 59.25 MiB) in VRAM:
- Reserving 2560 * 2880 * 4 (28.125 MiB) places permanent driver BOs at ~28.125..32 MiB, corrupting the middle (40-60%) of the screen.
- Reserving 2 * 2560 * 2880 * 4 (56.25 MiB) places those BOs at ~56.25..59.25 MiB, leaving the final 3 MiB exposed due to the 0x300000 surface offset and corrupting the bottom (95-100%) of the screen.
- Accounting for the 5120 pitch and the 0x300000 surface offset reserves the full 59.25 MiB span and eliminates the corruption completely.

Quoted 2 lines

For v2 of the patch, which of the following two approaches in both gmc_v7_0/v8_0_get_vbios_fb_size() would you prefer? Both tested working.

My feeling is that Option A is less magical. I'd actually wonder if we should be doing this more widely. I'd *think* the same problem could happen on a non-Apple display that behaves similarly.

Quoted 89 lines

Option A (change whole function):

  static unsigned gmc_v8_0_get_vbios_fb_size(struct amdgpu_device *adev)
  {
  	u32 d1vga_control = RREG32(mmD1VGA_CONTROL);
  	unsigned size;
  
  	if (REG_GET_FIELD(d1vga_control, D1VGA_CONTROL, D1VGA_MODE_ENABLE)) {
  		size = AMDGPU_VBIOS_VGA_ALLOCATION;
  	} else {
  		u32 viewport = RREG32(mmVIEWPORT_SIZE);
(quoted diff) +5 -2
-		size = (REG_GET_FIELD(viewport, VIEWPORT_SIZE, VIEWPORT_HEIGHT) *
-			REG_GET_FIELD(viewport, VIEWPORT_SIZE, VIEWPORT_WIDTH) * 4);
+		size = REG_GET_FIELD(viewport, VIEWPORT_SIZE, VIEWPORT_HEIGHT) *
+		       RREG32(mmGRPH_PITCH) * 4;
+		if (size)
+			size += RREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS) -
+				lower_32_bits(adev->gmc.vram_start);
  	}
 
  	return size;
  }

Option B (add Apple 5K iMacs quirk):

  static unsigned gmc_v8_0_get_vbios_fb_size(struct amdgpu_device *adev)
  {
  	u32 d1vga_control = RREG32(mmD1VGA_CONTROL);
  	unsigned size;
  
  	if (REG_GET_FIELD(d1vga_control, D1VGA_CONTROL, D1VGA_MODE_ENABLE)) {
  		size = AMDGPU_VBIOS_VGA_ALLOCATION;
  	} else {
  		u32 viewport = RREG32(mmVIEWPORT_SIZE);
  		size = (REG_GET_FIELD(viewport, VIEWPORT_SIZE, VIEWPORT_HEIGHT) *
  			REG_GET_FIELD(viewport, VIEWPORT_SIZE, VIEWPORT_WIDTH) * 4);
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +4 -0
+
+		if (adev->pdev->subsystem_vendor == PCI_VENDOR_ID_APPLE &&
+		    size == (2560 * 2880 * 4))
+			size = size * 2 + RREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS);
  	}
 
  	return size;
  }

Richard

Quoted 39 lines
Quoted 39 lines
Quoted 38 lines

Alex

Quoted 34 lines

Regards,
Christian.

Quoted 29 lines
---
   drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 10 +++++++++-
   1 file changed, 9 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +9 -2
index 4204c3c750a8..8b196fbfa724 100644
@@ -1232,7 +1232,15 @@ void amdgpu_gmc_init_vga_resv_regions(struct amdgpu_device *adev)
          } else {
                  size = amdgpu_gmc_get_vbios_fb_size(adev);
 
-               if (adev->mman.keep_stolen_vga_memory)
+               /*
+                * Apple 5K iMacs report one 2560x2880 tile in VIEWPORT_SIZE
+                * while scanning out up to 64M across the relocated EFI
+                * framebuffer.
+                */
+               if (adev->pdev->subsystem_vendor == PCI_VENDOR_ID_APPLE &&
+                   size == (2560 * 2880 * 4))
+                       size = 64U * 1024 * 1024;
+               else if (adev->mman.keep_stolen_vga_memory)
                          size = max(size, (unsigned)AMDGPU_VBIOS_VGA_ALLOCATION);
          }
 
--

2.55.0

maintainer
#7 lore raw
Quoted 80 lines · Mario Limonciello
Quoted 77 lines · Richard Lane
Quoted 34 lines · Alex Deucher
Quoted 32 lines · Mario Limonciello
Quoted 16 lines · Alex Deucher
Quoted 6 lines · Christian König
Quoted 4 lines · Richard Lane

Apple 27" 5K iMacs report a single 2560x2880 tile (28.125 MiB) in VIEWPORT_SIZE while scanning out up to 64 MiB across the relocated EFI framebuffer.

Quoted 7 lines
Quoted 3 lines

Override the stolen VGA memory allocation size to 64 MiB when matching PCI_VENDOR_ID_APPLE with a 2560x2880x4 viewport size to prevent framebuffer corruption during boot handover.

Hacks like those are usually a big no-go.

Why is that framebuffer handling not working with DC out of the box?

Quoted 7 lines

The GMC IP code reserves the memory used by the display hardware from the pre-OS console.  The gmc get_vbios_fb_size() callback looks to see what display viewport was set by the pre-OS environment.  If the Macs need a workaround, that's where it should go.  Since these displays require multiple display pipes, my guess is you need to double the allocation in that case since the current code just checks the first pipe.

Could this also be a logic error in that callback?  Would it be worth double checking all the register values in that callback for this system?

Quoted 9 lines
Quoted 2 lines

I know for example there are a few different IP specific implementations in gmc_v9_0_get_vbios_fb_size().

Not likely.  I suspect the issue is that these systems use two display pipes so we only reserve enough memory to cover half of the display. On PCs the vbios never sets up MST.

Alex

I tested doubling the allocation in gmc_v8_0_get_vbios_fb_size():

    if (adev->pdev->subsystem_vendor == PCI_VENDOR_ID_APPLE && size == (2560 * 2880 * 4))
        size *= 2;

That eliminated the corruption across the middle (45-60%) of the screen, but still left a band of corruption along the very bottom (95-100%) of the screen.

Dumping the DCE registers inside gmc_v8_0_get_vbios_fb_size() on the iMac17,1 showed:

   vram_start = 0xf400000000, d1vga = 0x0
   CRTC0: grph_en=0x1 surf_hi=0xf4 surf_lo=0x300000 pitch=5120 vp_size=2560x2880
   CRTC1: grph_en=0x80000000 surf_hi=0x0 surf_lo=0x0 pitch=0 vp_size=0x0

Even though only CRTC0 is active at EFI boot with a 2560x2880 viewport, Apple's EFI allocates a full 5120-pixel stride surface (mmGRPH_PITCH) and places mmGRPH_PRIMARY_SURFACE_ADDRESS at a 3 MiB offset (0x300000) from vram_start.

Because CRTC0 scans out 2880 lines at a 5120-pixel pitch starting at offset 3 MiB, the active pre-OS scanout spans [3 MiB, 59.25 MiB) in VRAM:
- Reserving 2560 * 2880 * 4 (28.125 MiB) places permanent driver BOs at ~28.125..32 MiB, corrupting the middle (40-60%) of the screen.
- Reserving 2 * 2560 * 2880 * 4 (56.25 MiB) places those BOs at ~56.25..59.25 MiB, leaving the final 3 MiB exposed due to the 0x300000 surface offset and corrupting the bottom (95-100%) of the screen.
- Accounting for the 5120 pitch and the 0x300000 surface offset reserves the full 59.25 MiB span and eliminates the corruption completely.

Quoted 4 lines
Quoted 2 lines

For v2 of the patch, which of the following two approaches in both gmc_v7_0/v8_0_get_vbios_fb_size() would you prefer? Both tested working.

My feeling is that Option A is less magical.  I'd actually wonder if we should be doing this more widely.  I'd *think* the same problem could happen on a non-Apple display that behaves similarly.

Yeah agree.

That the Mac EFI uses such an unaligned offset is very strange but perfectly supported by the HW and so we should also support it in the SW as well.

I'm just not sure if extending the size is the right approach. We should maybe have a function to read the base address of the framebuffer as well.

We already handle quite a number of those things for other use cases as well, so it should probably not to hard to get right.

Richard just take a look at how amdgpu_ttm_init_vram_resv() is used in amdgpu_gmc_init_vga_resv_regions().

Regards,
Christian.

Quoted 87 lines
Quoted 86 lines

Option A (change whole function):

  static unsigned gmc_v8_0_get_vbios_fb_size(struct amdgpu_device *adev) {
      u32 d1vga_control = RREG32(mmD1VGA_CONTROL);
      unsigned size;
        if (REG_GET_FIELD(d1vga_control, D1VGA_CONTROL, D1VGA_MODE_ENABLE)) { size = AMDGPU_VBIOS_VGA_ALLOCATION;
      } else {
          u32 viewport = RREG32(mmVIEWPORT_SIZE);
-        size = (REG_GET_FIELD(viewport, VIEWPORT_SIZE, VIEWPORT_HEIGHT) * -            REG_GET_FIELD(viewport, VIEWPORT_SIZE, VIEWPORT_WIDTH) * 4); +        size = REG_GET_FIELD(viewport, VIEWPORT_SIZE, VIEWPORT_HEIGHT) * +               RREG32(mmGRPH_PITCH) * 4;
+        if (size)
+            size += RREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS) -
+                lower_32_bits(adev->gmc.vram_start);
      }
        return size;
  }

Option B (add Apple 5K iMacs quirk):

  static unsigned gmc_v8_0_get_vbios_fb_size(struct amdgpu_device *adev) {
      u32 d1vga_control = RREG32(mmD1VGA_CONTROL);
      unsigned size;
        if (REG_GET_FIELD(d1vga_control, D1VGA_CONTROL, D1VGA_MODE_ENABLE)) { size = AMDGPU_VBIOS_VGA_ALLOCATION;
      } else {
          u32 viewport = RREG32(mmVIEWPORT_SIZE);
          size = (REG_GET_FIELD(viewport, VIEWPORT_SIZE, VIEWPORT_HEIGHT) * REG_GET_FIELD(viewport, VIEWPORT_SIZE, VIEWPORT_WIDTH) * 4); +
+        if (adev->pdev->subsystem_vendor == PCI_VENDOR_ID_APPLE && +            size == (2560 * 2880 * 4))
+            size = size * 2 + RREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS); }
        return size;
  }

Richard

Quoted 39 lines
Quoted 39 lines
Quoted 38 lines

Alex

Quoted 34 lines

Regards,
Christian.

Quoted 29 lines

---
   drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 10 +++++++++-

   1 file changed, 9 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +9 -1
index 4204c3c750a8..8b196fbfa724 100644
@@ -1232,7 +1232,15 @@ void amdgpu_gmc_init_vga_resv_regions(struct amdgpu_device *adev)
           } else {
                   size = amdgpu_gmc_get_vbios_fb_size(adev);
 
-               if (adev->mman.keep_stolen_vga_memory)
+               /*
+                * Apple 5K iMacs report one 2560x2880 tile in VIEWPORT_SIZE
+                * while scanning out up to 64M across the relocated EFI
+                * framebuffer.
+                */
+               if (adev->pdev->subsystem_vendor == PCI_VENDOR_ID_APPLE &&
+                   size == (2560 * 2880 * 4))
+                       size = 64U * 1024 * 1024;
+               else if (adev->mman.keep_stolen_vga_memory)
                           size = max(size, (unsigned)AMDGPU_VBIOS_VGA_ALLOCATION);
           }
 
Signature · 1 line
2.55.0
#8 lore raw
In reply to Mario Limonciello
Quoted 81 lines · Mario Limonciello
Quoted 77 lines · Richard Lane
Quoted 34 lines · Alex Deucher
Quoted 32 lines · Mario Limonciello
Quoted 16 lines · Alex Deucher
Quoted 6 lines · Christian König
Quoted 4 lines · Richard Lane

Apple 27" 5K iMacs report a single 2560x2880 tile (28.125 MiB) in VIEWPORT_SIZE while scanning out up to 64 MiB across the relocated EFI framebuffer.

Quoted 7 lines
Quoted 3 lines

Override the stolen VGA memory allocation size to 64 MiB when matching PCI_VENDOR_ID_APPLE with a 2560x2880x4 viewport size to prevent framebuffer corruption during boot handover.

Hacks like those are usually a big no-go.

Why is that framebuffer handling not working with DC out of the box?

Quoted 7 lines

The GMC IP code reserves the memory used by the display hardware from the pre-OS console. The gmc get_vbios_fb_size() callback looks to see what display viewport was set by the pre-OS environment. If the Macs need a workaround, that's where it should go. Since these displays require multiple display pipes, my guess is you need to double the allocation in that case since the current code just checks the first pipe.

Could this also be a logic error in that callback? Would it be worth double checking all the register values in that callback for this system?

Quoted 9 lines
Quoted 2 lines

I know for example there are a few different IP specific implementations in gmc_v9_0_get_vbios_fb_size().

Not likely. I suspect the issue is that these systems use two display pipes so we only reserve enough memory to cover half of the display. On PCs the vbios never sets up MST.

Alex

I tested doubling the allocation in gmc_v8_0_get_vbios_fb_size():

      if (adev->pdev->subsystem_vendor == PCI_VENDOR_ID_APPLE &&
          size == (2560 * 2880 * 4))
              size *= 2;

That eliminated the corruption across the middle (45-60%) of the screen, but still left a band of corruption along the very bottom (95-100%) of the screen.

Dumping the DCE registers inside gmc_v8_0_get_vbios_fb_size() on the iMac17,1 showed:

   vram_start = 0xf400000000, d1vga = 0x0
   CRTC0: grph_en=0x1 surf_hi=0xf4 surf_lo=0x300000 pitch=5120 vp_size=2560x2880
   CRTC1: grph_en=0x80000000 surf_hi=0x0 surf_lo=0x0 pitch=0 vp_size=0x0

Even though only CRTC0 is active at EFI boot with a 2560x2880 viewport, Apple's EFI allocates a full 5120-pixel stride surface (mmGRPH_PITCH) and places mmGRPH_PRIMARY_SURFACE_ADDRESS at a 3 MiB offset (0x300000) from vram_start.

Because CRTC0 scans out 2880 lines at a 5120-pixel pitch starting at offset 3 MiB, the active pre-OS scanout spans [3 MiB, 59.25 MiB) in VRAM:
- Reserving 2560 * 2880 * 4 (28.125 MiB) places permanent driver BOs at ~28.125..32 MiB, corrupting the middle (40-60%) of the screen.
- Reserving 2 * 2560 * 2880 * 4 (56.25 MiB) places those BOs at ~56.25..59.25 MiB, leaving the final 3 MiB exposed due to the 0x300000 surface offset and corrupting the bottom (95-100%) of the screen.
- Accounting for the 5120 pitch and the 0x300000 surface offset reserves the full 59.25 MiB span and eliminates the corruption completely.

Quoted 6 lines
Quoted 2 lines

For v2 of the patch, which of the following two approaches in both gmc_v7_0/v8_0_get_vbios_fb_size() would you prefer? Both tested working.

My feeling is that Option A is less magical. I'd actually wonder if we should be doing this more widely. I'd *think* the same problem could happen on a non-Apple display that behaves similarly.

I had discussions with the vbios teams when this code was added. They said the display base was always put at the start of VRAM. The only area I have a concern about is adding the surface address. It works ok if the the displays are put near the start of VRAM, but if not (e.g., the pre-OS environment puts then at the top of VRAM), we'll end up reserving most or all of VRAM. I think the right solution is to add an offset to the reservation and then use the surface address as the offset. That's more work however so maybe it would be better as a follow up clean up.

Alex

Quoted 91 lines
Quoted 90 lines

Option A (change whole function):

  static unsigned gmc_v8_0_get_vbios_fb_size(struct amdgpu_device *adev)
  {
      u32 d1vga_control = RREG32(mmD1VGA_CONTROL);
      unsigned size;
      if (REG_GET_FIELD(d1vga_control, D1VGA_CONTROL, D1VGA_MODE_ENABLE)) {
              size = AMDGPU_VBIOS_VGA_ALLOCATION;
      } else {
              u32 viewport = RREG32(mmVIEWPORT_SIZE);
(quoted diff) +5 -2
-             size = (REG_GET_FIELD(viewport, VIEWPORT_SIZE, VIEWPORT_HEIGHT) *
-                     REG_GET_FIELD(viewport, VIEWPORT_SIZE, VIEWPORT_WIDTH) * 4);
+             size = REG_GET_FIELD(viewport, VIEWPORT_SIZE, VIEWPORT_HEIGHT) *
+                    RREG32(mmGRPH_PITCH) * 4;
+             if (size)
+                     size += RREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS) -
+                             lower_32_bits(adev->gmc.vram_start);
      }
 
      return size;
  }

Option B (add Apple 5K iMacs quirk):

  static unsigned gmc_v8_0_get_vbios_fb_size(struct amdgpu_device *adev)
  {
      u32 d1vga_control = RREG32(mmD1VGA_CONTROL);
      unsigned size;
      if (REG_GET_FIELD(d1vga_control, D1VGA_CONTROL, D1VGA_MODE_ENABLE)) {
              size = AMDGPU_VBIOS_VGA_ALLOCATION;
      } else {
              u32 viewport = RREG32(mmVIEWPORT_SIZE);
              size = (REG_GET_FIELD(viewport, VIEWPORT_SIZE, VIEWPORT_HEIGHT) *
                      REG_GET_FIELD(viewport, VIEWPORT_SIZE, VIEWPORT_WIDTH) * 4);
(quoted diff) +4 -0
+
+             if (adev->pdev->subsystem_vendor == PCI_VENDOR_ID_APPLE &&
+                 size == (2560 * 2880 * 4))
+                     size = size * 2 + RREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS);
      }
 
      return size;
  }

Richard

Quoted 39 lines
Quoted 39 lines
Quoted 38 lines

Alex

Quoted 34 lines

Regards,
Christian.

Quoted 29 lines
---
   drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 10 +++++++++-
   1 file changed, 9 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +9 -2
index 4204c3c750a8..8b196fbfa724 100644
@@ -1232,7 +1232,15 @@ void amdgpu_gmc_init_vga_resv_regions(struct amdgpu_device *adev)
          } else {
                  size = amdgpu_gmc_get_vbios_fb_size(adev);
 
-               if (adev->mman.keep_stolen_vga_memory)
+               /*
+                * Apple 5K iMacs report one 2560x2880 tile in VIEWPORT_SIZE
+                * while scanning out up to 64M across the relocated EFI
+                * framebuffer.
+                */
+               if (adev->pdev->subsystem_vendor == PCI_VENDOR_ID_APPLE &&
+                   size == (2560 * 2880 * 4))
+                       size = 64U * 1024 * 1024;
+               else if (adev->mman.keep_stolen_vga_memory)
                          size = max(size, (unsigned)AMDGPU_VBIOS_VGA_ALLOCATION);
          }
 
--

2.55.0