Re: [PATCH 1/2] drm/amdgpu/gmc: steal the appropriate amount of vram for fw hand-over (v2)

2018-04-10 Thread Andrey Grodzovsky
Indeed :( After 2 tries i see the problem, if I remove "drm/amdgpu: Free 
VGA stolen memory as soon as possible." problem goes away.


Andrey


On 04/10/2018 06:53 AM, Huang Rui wrote:

On Mon, Apr 09, 2018 at 11:17:58AM -0400, Andrey Grodzovsky wrote:

OK, tested with DC disabled , no issues on resume (no visible
corruption on display or errors in log). Now the display itself
freezes after amdgpu is loaded with DC disabled, this happens only
when BIOS in VGA mode , in console mode no such problem. Happens
before my and Alex patches, looks like a separate issue.

So anyway, if corruption would be there (beginning of VRAM and hence
scanout FB corrupted) , i should have seen it with grub in console
mode where display is fine and not freezing.


Reproduce steps:
1. sudo modprobe amdgpu dc=0 ip_block_mask=0x7f
2. pm-suspend/resume two times.

You will see the start of vram is corrupted after S3 resume.

[  570.343635] [drm] PCIE GART of 512M enabled (table at 0x00F4).
[  570.343642] [drm] PSP is resuming...
[  570.343713] gmc_v9_0_process_interrupt: 12 callbacks suppressed
[  570.343715] amdgpu :03:00.0: [mmhub] VMC page fault (src_id:0 ring:0 
vmid:0 pasid:0)
[  570.343716] amdgpu :03:00.0:   at page 0x00f60070 from 18
[  570.343716] amdgpu :03:00.0: VM_L2_PROTECTION_FAULT_STATUS:0x0010
[  570.525510] [drm:psp_resume [amdgpu]] *ERROR* PSP resume failed
[  570.525523] [drm:amdgpu_device_ip_resume_phase2 [amdgpu]] *ERROR* resume of IP 
block  failed -62
[  570.525536] [drm:amdgpu_device_resume [amdgpu]] *ERROR* 
amdgpu_device_ip_resume failed (-62).
[  570.536704] e1000e: enp0s31f6 NIC Link is Up 100 Mbps Full Duplex, Flow 
Control: Rx/Tx
[  570.540496] dpm_run_callback(): pci_pm_resume+0x0/0xa0 returns -62
[  570.547879] e1000e :00:1f.6 enp0s31f6: 10/100 speed: disabling TSO
[  570.555434] call :03:00.0+ returned -62 after 1973202 usecs
[  570.689812] PM: Device :03:00.0 failed to resume async: error -62

I attached the whole dmesg.

Thanks,
Ray


___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


Re: [PATCH 1/2] drm/amdgpu/gmc: steal the appropriate amount of vram for fw hand-over (v2)

2018-04-10 Thread Andrey Grodzovsky
So with my and Alex's patches you still observe corruption ? What if you 
remove my patch and keep Alex's patch ?


Andrey


On 04/10/2018 06:53 AM, Huang Rui wrote:

On Mon, Apr 09, 2018 at 11:17:58AM -0400, Andrey Grodzovsky wrote:

OK, tested with DC disabled , no issues on resume (no visible
corruption on display or errors in log). Now the display itself
freezes after amdgpu is loaded with DC disabled, this happens only
when BIOS in VGA mode , in console mode no such problem. Happens
before my and Alex patches, looks like a separate issue.

So anyway, if corruption would be there (beginning of VRAM and hence
scanout FB corrupted) , i should have seen it with grub in console
mode where display is fine and not freezing.


Reproduce steps:
1. sudo modprobe amdgpu dc=0 ip_block_mask=0x7f
2. pm-suspend/resume two times.

You will see the start of vram is corrupted after S3 resume.

[  570.343635] [drm] PCIE GART of 512M enabled (table at 0x00F4).
[  570.343642] [drm] PSP is resuming...
[  570.343713] gmc_v9_0_process_interrupt: 12 callbacks suppressed
[  570.343715] amdgpu :03:00.0: [mmhub] VMC page fault (src_id:0 ring:0 
vmid:0 pasid:0)
[  570.343716] amdgpu :03:00.0:   at page 0x00f60070 from 18
[  570.343716] amdgpu :03:00.0: VM_L2_PROTECTION_FAULT_STATUS:0x0010
[  570.525510] [drm:psp_resume [amdgpu]] *ERROR* PSP resume failed
[  570.525523] [drm:amdgpu_device_ip_resume_phase2 [amdgpu]] *ERROR* resume of IP 
block  failed -62
[  570.525536] [drm:amdgpu_device_resume [amdgpu]] *ERROR* 
amdgpu_device_ip_resume failed (-62).
[  570.536704] e1000e: enp0s31f6 NIC Link is Up 100 Mbps Full Duplex, Flow 
Control: Rx/Tx
[  570.540496] dpm_run_callback(): pci_pm_resume+0x0/0xa0 returns -62
[  570.547879] e1000e :00:1f.6 enp0s31f6: 10/100 speed: disabling TSO
[  570.555434] call :03:00.0+ returned -62 after 1973202 usecs
[  570.689812] PM: Device :03:00.0 failed to resume async: error -62

I attached the whole dmesg.

Thanks,
Ray


___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


Re: [PATCH 1/2] drm/amdgpu/gmc: steal the appropriate amount of vram for fw hand-over (v2)

2018-04-10 Thread Huang Rui
On Mon, Apr 09, 2018 at 09:50:19PM +0800, Christian König wrote:
> Hi Andrey,
> 
> I think the problem Ray wants to point to is that we now release the 
> stolen memory after device initialization.
> 
> So during S3 we might run into issues because the first 8MB of VRAM are 
> corrupted after startup.
> 

Yes. Andrey, Christian. That's why I reserve 8M stolen size bo at the first
of the vram. I will forward the history information to you ;-)

And nevermind, let me find a vega10 card to test whether these two patches
impact the case that I encountered before. Will let you know the result
later.

Thanks,
Ray

> Christian.
> 
> Am 09.04.2018 um 15:26 schrieb Grodzovsky, Andrey:
> > Top posting (mobile)
> >
> > I tested S3 with DC enabled only. Even if I disable DC I need a device with 
> > less then 8M VRAM to reproduce it, don't I ? Otherwise we just gonna 
> > reserve pre OS FB size of VRAM and not corrupt it. Right ? Should probably 
> > test it with forcing VRAM size to less then 8M...
> >
> > Andrey
> >
> > 
> > From: Huang Rui 
> > Sent: 09 April 2018 04:23:06
> > To: Alex Deucher; Grodzovsky, Andrey
> > Cc: amd-gfx@lists.freedesktop.org; Deucher, Alexander
> > Subject: Re: [PATCH 1/2] drm/amdgpu/gmc: steal the appropriate amount of 
> > vram for fw hand-over (v2)
> >
> > On Fri, Apr 06, 2018 at 02:54:09PM -0500, Alex Deucher wrote:
> >> Steal 9 MB for vga emulation and fb if vga is enabled, otherwise,
> >> steal enough to cover the current display size as set by the vbios.
> >>
> >> If no memory is used (e.g., secondary or headless card), skip
> >> stolen memory reserve.
> >>
> >> v2: skip reservation if vram is limited, address Christian's comments
> >>
> >> Reviewed-and-Tested-by: Andrey Grodzovsky  (v1)
> >> Signed-off-by: Alex Deucher 
> >> ---
> >>   drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 14 +
> >>   drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c   | 23 +--
> >>   drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c   | 23 +--
> >>   drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c   | 23 +--
> >>   drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c   | 51 
> >> +
> >>   5 files changed, 116 insertions(+), 18 deletions(-)
> >>
> >> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c 
> >> b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> >> index 205da3ff9cd0..46c69ad34461 100644
> >> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> >> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> >> @@ -1454,12 +1454,14 @@ int amdgpu_ttm_init(struct amdgpu_device *adev)
> >>return r;
> >>}
> >>
> >> - r = amdgpu_bo_create_kernel(adev, adev->gmc.stolen_size, PAGE_SIZE,
> >> - AMDGPU_GEM_DOMAIN_VRAM,
> >> - >stolen_vga_memory,
> >> - NULL, NULL);
> >> - if (r)
> >> - return r;
> >> + if (adev->gmc.stolen_size) {
> >> + r = amdgpu_bo_create_kernel(adev, adev->gmc.stolen_size, 
> >> PAGE_SIZE,
> >> + AMDGPU_GEM_DOMAIN_VRAM,
> >> + >stolen_vga_memory,
> >> + NULL, NULL);
> >> + if (r)
> >> + return r;
> >> + }
> >>DRM_INFO("amdgpu: %uM of VRAM memory ready\n",
> >> (unsigned) (adev->gmc.real_vram_size / (1024 * 1024)));
> >>
> >> diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c 
> >> b/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c
> >> index 5617cf62c566..24e1ea36b454 100644
> >> --- a/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c
> >> +++ b/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c
> >> @@ -825,6 +825,25 @@ static int gmc_v6_0_late_init(void *handle)
> >>return 0;
> >>   }
> >>
> >> +static unsigned gmc_v6_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 = 9 * 1024 * 1024; /* reserve 8MB for vga emulator and 
> >> 1 MB for FB */
> >> + } else {
> >> + u32 viewport = RREG32(mmVIEWPORT_SIZE);
> >> + size = (REG_GET_FIELD(viewport, VIEWPORT_SIZE, 
> >> VIEWPORT_HEIGHT) *
> >> + REG_GET_FIELD(viewport, VIEWPORT_SIZE, 
> >> VIEWPORT_WIDTH) *
> >> + 4);
> >> + }
> >> + /* return 0 if the pre-OS buffer uses up most of vram */
> >> + if ((adev->gmc.real_vram_size - size) < (8 * 1024 * 1024))
> >> + return 0;
> >> + return size;
> >> +}
> >> +
> >>   static int gmc_v6_0_sw_init(void *handle)
> >>   {
> >>int r;
> >> @@ -851,8 +870,6 @@ static int gmc_v6_0_sw_init(void *handle)
> >>
> >>adev->gmc.mc_mask = 0xffULL;
> >>
> >> - 

Re: [PATCH 1/2] drm/amdgpu/gmc: steal the appropriate amount of vram for fw hand-over (v2)

2018-04-09 Thread Alex Deucher
On Mon, Apr 9, 2018 at 3:47 AM, Michel Dänzer  wrote:
> On 2018-04-06 09:54 PM, Alex Deucher wrote:
>> Steal 9 MB for vga emulation and fb if vga is enabled, otherwise,
>> steal enough to cover the current display size as set by the vbios.
>>
>> If no memory is used (e.g., secondary or headless card), skip
>> stolen memory reserve.
>>
>> v2: skip reservation if vram is limited, address Christian's comments
>>
>> Reviewed-and-Tested-by: Andrey Grodzovsky  (v1)
>> Signed-off-by: Alex Deucher 
>
> [...]
>
>> diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c 
>> b/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c
>> index 5617cf62c566..24e1ea36b454 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c
>> @@ -825,6 +825,25 @@ static int gmc_v6_0_late_init(void *handle)
>>   return 0;
>>  }
>>
>> +static unsigned gmc_v6_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 = 9 * 1024 * 1024; /* reserve 8MB for vga emulator and 1 
>> MB for FB */
>> + } else {
>> + u32 viewport = RREG32(mmVIEWPORT_SIZE);
>> + size = (REG_GET_FIELD(viewport, VIEWPORT_SIZE, 
>> VIEWPORT_HEIGHT) *
>> + REG_GET_FIELD(viewport, VIEWPORT_SIZE, VIEWPORT_WIDTH) 
>> *
>> + 4);
>> + }
>
> Any particular reason for not calculating the FB size based on the
> viewport even if VGA is enabled? VGA text mode can use higher
> resolutions as well.
>
> Other than that, these patches look good to me.

According to the vbios team the 9 MB is all that is used in legacy vga
text mode.


Alex
___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


Re: [PATCH 1/2] drm/amdgpu/gmc: steal the appropriate amount of vram for fw hand-over (v2)

2018-04-09 Thread Andrey Grodzovsky
OK, tested with DC disabled , no issues on resume (no visible corruption 
on display or errors in log). Now the display itself freezes after 
amdgpu is loaded with DC disabled, this happens only when BIOS in VGA 
mode , in console mode no such problem. Happens before my and Alex 
patches, looks like a separate issue.


So anyway, if corruption would be there (beginning of VRAM and hence 
scanout FB corrupted) , i should have seen it with grub in console mode 
where display is fine and not freezing.


Andrey


On 04/09/2018 09:50 AM, Christian König wrote:

Hi Andrey,

I think the problem Ray wants to point to is that we now release the 
stolen memory after device initialization.


So during S3 we might run into issues because the first 8MB of VRAM 
are corrupted after startup.


Christian.

Am 09.04.2018 um 15:26 schrieb Grodzovsky, Andrey:

Top posting (mobile)

I tested S3 with DC enabled only. Even if I disable DC I need a 
device with less then 8M VRAM to reproduce it, don't I ? Otherwise we 
just gonna reserve pre OS FB size of VRAM and not corrupt it. Right ? 
Should probably test it with forcing VRAM size to less then 8M...


Andrey


From: Huang Rui 
Sent: 09 April 2018 04:23:06
To: Alex Deucher; Grodzovsky, Andrey
Cc: amd-gfx@lists.freedesktop.org; Deucher, Alexander
Subject: Re: [PATCH 1/2] drm/amdgpu/gmc: steal the appropriate amount 
of vram for fw hand-over (v2)


On Fri, Apr 06, 2018 at 02:54:09PM -0500, Alex Deucher wrote:

Steal 9 MB for vga emulation and fb if vga is enabled, otherwise,
steal enough to cover the current display size as set by the vbios.

If no memory is used (e.g., secondary or headless card), skip
stolen memory reserve.

v2: skip reservation if vram is limited, address Christian's comments

Reviewed-and-Tested-by: Andrey Grodzovsky 
 (v1)

Signed-off-by: Alex Deucher 
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 14 +
  drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c   | 23 +--
  drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c   | 23 +--
  drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c   | 23 +--
  drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c   | 51 
+

  5 files changed, 116 insertions(+), 18 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c

index 205da3ff9cd0..46c69ad34461 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
@@ -1454,12 +1454,14 @@ int amdgpu_ttm_init(struct amdgpu_device *adev)
   return r;
   }

- r = amdgpu_bo_create_kernel(adev, adev->gmc.stolen_size, 
PAGE_SIZE,

- AMDGPU_GEM_DOMAIN_VRAM,
- >stolen_vga_memory,
- NULL, NULL);
- if (r)
- return r;
+ if (adev->gmc.stolen_size) {
+ r = amdgpu_bo_create_kernel(adev, 
adev->gmc.stolen_size, PAGE_SIZE,

+ AMDGPU_GEM_DOMAIN_VRAM,
+ >stolen_vga_memory,
+ NULL, NULL);
+ if (r)
+ return r;
+ }
   DRM_INFO("amdgpu: %uM of VRAM memory ready\n",
    (unsigned) (adev->gmc.real_vram_size / (1024 * 1024)));

diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c 
b/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c

index 5617cf62c566..24e1ea36b454 100644
--- a/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c
@@ -825,6 +825,25 @@ static int gmc_v6_0_late_init(void *handle)
   return 0;
  }

+static unsigned gmc_v6_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 = 9 * 1024 * 1024; /* reserve 8MB for vga 
emulator and 1 MB for FB */

+ } else {
+ u32 viewport = RREG32(mmVIEWPORT_SIZE);
+ size = (REG_GET_FIELD(viewport, VIEWPORT_SIZE, 
VIEWPORT_HEIGHT) *
+ REG_GET_FIELD(viewport, VIEWPORT_SIZE, 
VIEWPORT_WIDTH) *

+ 4);
+ }
+ /* return 0 if the pre-OS buffer uses up most of vram */
+ if ((adev->gmc.real_vram_size - size) < (8 * 1024 * 1024))
+ return 0;
+ return size;
+}
+
  static int gmc_v6_0_sw_init(void *handle)
  {
   int r;
@@ -851,8 +870,6 @@ static int gmc_v6_0_sw_init(void *handle)

   adev->gmc.mc_mask = 0xffULL;

- adev->gmc.stolen_size = 256 * 1024;
-
   adev->need_dma32 = false;
   dma_bits = adev->need_dma32 ? 32 : 40;
   r = pci_set_dma_mask(adev->pdev, DMA_BIT_MASK(dma_bits));
@@ -878,6 +895,8 @@ static int gmc_v6_0_sw_init(void *handle)
   if (r)
   return r;

+ adev->gmc.stolen_size = gmc_v6_0_get_vbios_fb_size(adev);
+
   r = amdgpu_bo_init(adev);
   if (r)
   return r;
diff 

Re: [PATCH 1/2] drm/amdgpu/gmc: steal the appropriate amount of vram for fw hand-over (v2)

2018-04-09 Thread Christian König

Hi Andrey,

I think the problem Ray wants to point to is that we now release the 
stolen memory after device initialization.


So during S3 we might run into issues because the first 8MB of VRAM are 
corrupted after startup.


Christian.

Am 09.04.2018 um 15:26 schrieb Grodzovsky, Andrey:

Top posting (mobile)

I tested S3 with DC enabled only. Even if I disable DC I need a device with 
less then 8M VRAM to reproduce it, don't I ? Otherwise we just gonna reserve 
pre OS FB size of VRAM and not corrupt it. Right ? Should probably test it with 
forcing VRAM size to less then 8M...

Andrey


From: Huang Rui 
Sent: 09 April 2018 04:23:06
To: Alex Deucher; Grodzovsky, Andrey
Cc: amd-gfx@lists.freedesktop.org; Deucher, Alexander
Subject: Re: [PATCH 1/2] drm/amdgpu/gmc: steal the appropriate amount of vram 
for fw hand-over (v2)

On Fri, Apr 06, 2018 at 02:54:09PM -0500, Alex Deucher wrote:

Steal 9 MB for vga emulation and fb if vga is enabled, otherwise,
steal enough to cover the current display size as set by the vbios.

If no memory is used (e.g., secondary or headless card), skip
stolen memory reserve.

v2: skip reservation if vram is limited, address Christian's comments

Reviewed-and-Tested-by: Andrey Grodzovsky  (v1)
Signed-off-by: Alex Deucher 
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 14 +
  drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c   | 23 +--
  drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c   | 23 +--
  drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c   | 23 +--
  drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c   | 51 +
  5 files changed, 116 insertions(+), 18 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
index 205da3ff9cd0..46c69ad34461 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
@@ -1454,12 +1454,14 @@ int amdgpu_ttm_init(struct amdgpu_device *adev)
   return r;
   }

- r = amdgpu_bo_create_kernel(adev, adev->gmc.stolen_size, PAGE_SIZE,
- AMDGPU_GEM_DOMAIN_VRAM,
- >stolen_vga_memory,
- NULL, NULL);
- if (r)
- return r;
+ if (adev->gmc.stolen_size) {
+ r = amdgpu_bo_create_kernel(adev, adev->gmc.stolen_size, 
PAGE_SIZE,
+ AMDGPU_GEM_DOMAIN_VRAM,
+ >stolen_vga_memory,
+ NULL, NULL);
+ if (r)
+ return r;
+ }
   DRM_INFO("amdgpu: %uM of VRAM memory ready\n",
(unsigned) (adev->gmc.real_vram_size / (1024 * 1024)));

diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c 
b/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c
index 5617cf62c566..24e1ea36b454 100644
--- a/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c
@@ -825,6 +825,25 @@ static int gmc_v6_0_late_init(void *handle)
   return 0;
  }

+static unsigned gmc_v6_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 = 9 * 1024 * 1024; /* reserve 8MB for vga emulator and 1 MB 
for FB */
+ } else {
+ u32 viewport = RREG32(mmVIEWPORT_SIZE);
+ size = (REG_GET_FIELD(viewport, VIEWPORT_SIZE, VIEWPORT_HEIGHT) *
+ REG_GET_FIELD(viewport, VIEWPORT_SIZE, VIEWPORT_WIDTH) *
+ 4);
+ }
+ /* return 0 if the pre-OS buffer uses up most of vram */
+ if ((adev->gmc.real_vram_size - size) < (8 * 1024 * 1024))
+ return 0;
+ return size;
+}
+
  static int gmc_v6_0_sw_init(void *handle)
  {
   int r;
@@ -851,8 +870,6 @@ static int gmc_v6_0_sw_init(void *handle)

   adev->gmc.mc_mask = 0xffULL;

- adev->gmc.stolen_size = 256 * 1024;
-
   adev->need_dma32 = false;
   dma_bits = adev->need_dma32 ? 32 : 40;
   r = pci_set_dma_mask(adev->pdev, DMA_BIT_MASK(dma_bits));
@@ -878,6 +895,8 @@ static int gmc_v6_0_sw_init(void *handle)
   if (r)
   return r;

+ adev->gmc.stolen_size = gmc_v6_0_get_vbios_fb_size(adev);
+
   r = amdgpu_bo_init(adev);
   if (r)
   return r;
diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c 
b/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c
index 80054f36e487..93861f9c7773 100644
--- a/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c
@@ -964,6 +964,25 @@ static int gmc_v7_0_late_init(void *handle)
   return 0;
  }

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

Re: [PATCH 1/2] drm/amdgpu/gmc: steal the appropriate amount of vram for fw hand-over (v2)

2018-04-09 Thread Grodzovsky, Andrey
Top posting (mobile)

I tested S3 with DC enabled only. Even if I disable DC I need a device with 
less then 8M VRAM to reproduce it, don't I ? Otherwise we just gonna reserve 
pre OS FB size of VRAM and not corrupt it. Right ? Should probably test it with 
forcing VRAM size to less then 8M...

Andrey


From: Huang Rui 
Sent: 09 April 2018 04:23:06
To: Alex Deucher; Grodzovsky, Andrey
Cc: amd-gfx@lists.freedesktop.org; Deucher, Alexander
Subject: Re: [PATCH 1/2] drm/amdgpu/gmc: steal the appropriate amount of vram 
for fw hand-over (v2)

On Fri, Apr 06, 2018 at 02:54:09PM -0500, Alex Deucher wrote:
> Steal 9 MB for vga emulation and fb if vga is enabled, otherwise,
> steal enough to cover the current display size as set by the vbios.
>
> If no memory is used (e.g., secondary or headless card), skip
> stolen memory reserve.
>
> v2: skip reservation if vram is limited, address Christian's comments
>
> Reviewed-and-Tested-by: Andrey Grodzovsky  (v1)
> Signed-off-by: Alex Deucher 
> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 14 +
>  drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c   | 23 +--
>  drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c   | 23 +--
>  drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c   | 23 +--
>  drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c   | 51 
> +
>  5 files changed, 116 insertions(+), 18 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c 
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> index 205da3ff9cd0..46c69ad34461 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> @@ -1454,12 +1454,14 @@ int amdgpu_ttm_init(struct amdgpu_device *adev)
>   return r;
>   }
>
> - r = amdgpu_bo_create_kernel(adev, adev->gmc.stolen_size, PAGE_SIZE,
> - AMDGPU_GEM_DOMAIN_VRAM,
> - >stolen_vga_memory,
> - NULL, NULL);
> - if (r)
> - return r;
> + if (adev->gmc.stolen_size) {
> + r = amdgpu_bo_create_kernel(adev, adev->gmc.stolen_size, 
> PAGE_SIZE,
> + AMDGPU_GEM_DOMAIN_VRAM,
> + >stolen_vga_memory,
> + NULL, NULL);
> + if (r)
> + return r;
> + }
>   DRM_INFO("amdgpu: %uM of VRAM memory ready\n",
>(unsigned) (adev->gmc.real_vram_size / (1024 * 1024)));
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c 
> b/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c
> index 5617cf62c566..24e1ea36b454 100644
> --- a/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c
> +++ b/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c
> @@ -825,6 +825,25 @@ static int gmc_v6_0_late_init(void *handle)
>   return 0;
>  }
>
> +static unsigned gmc_v6_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 = 9 * 1024 * 1024; /* reserve 8MB for vga emulator and 1 
> MB for FB */
> + } else {
> + u32 viewport = RREG32(mmVIEWPORT_SIZE);
> + size = (REG_GET_FIELD(viewport, VIEWPORT_SIZE, VIEWPORT_HEIGHT) 
> *
> + REG_GET_FIELD(viewport, VIEWPORT_SIZE, VIEWPORT_WIDTH) *
> + 4);
> + }
> + /* return 0 if the pre-OS buffer uses up most of vram */
> + if ((adev->gmc.real_vram_size - size) < (8 * 1024 * 1024))
> + return 0;
> + return size;
> +}
> +
>  static int gmc_v6_0_sw_init(void *handle)
>  {
>   int r;
> @@ -851,8 +870,6 @@ static int gmc_v6_0_sw_init(void *handle)
>
>   adev->gmc.mc_mask = 0xffULL;
>
> - adev->gmc.stolen_size = 256 * 1024;
> -
>   adev->need_dma32 = false;
>   dma_bits = adev->need_dma32 ? 32 : 40;
>   r = pci_set_dma_mask(adev->pdev, DMA_BIT_MASK(dma_bits));
> @@ -878,6 +895,8 @@ static int gmc_v6_0_sw_init(void *handle)
>   if (r)
>   return r;
>
> + adev->gmc.stolen_size = gmc_v6_0_get_vbios_fb_size(adev);
> +
>   r = amdgpu_bo_init(adev);
>   if (r)
>   return r;
> diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c 
> b/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c
> index 80054f36e487..93861f9c7773 100644
> --- a/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c
> +++ b/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c
> @@ -964,6 +964,25 @@ static int gmc_v7_0_late_init(void *handle)
>   return 0;
>  }
>
> +static unsigned gmc_v7_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 = 9 * 1024 * 

Re: [PATCH 1/2] drm/amdgpu/gmc: steal the appropriate amount of vram for fw hand-over (v2)

2018-04-09 Thread Huang Rui
On Fri, Apr 06, 2018 at 02:54:09PM -0500, Alex Deucher wrote:
> Steal 9 MB for vga emulation and fb if vga is enabled, otherwise,
> steal enough to cover the current display size as set by the vbios.
> 
> If no memory is used (e.g., secondary or headless card), skip
> stolen memory reserve.
> 
> v2: skip reservation if vram is limited, address Christian's comments
> 
> Reviewed-and-Tested-by: Andrey Grodzovsky  (v1)
> Signed-off-by: Alex Deucher 
> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 14 +
>  drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c   | 23 +--
>  drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c   | 23 +--
>  drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c   | 23 +--
>  drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c   | 51 
> +
>  5 files changed, 116 insertions(+), 18 deletions(-)
> 
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c 
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> index 205da3ff9cd0..46c69ad34461 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> @@ -1454,12 +1454,14 @@ int amdgpu_ttm_init(struct amdgpu_device *adev)
>   return r;
>   }
>  
> - r = amdgpu_bo_create_kernel(adev, adev->gmc.stolen_size, PAGE_SIZE,
> - AMDGPU_GEM_DOMAIN_VRAM,
> - >stolen_vga_memory,
> - NULL, NULL);
> - if (r)
> - return r;
> + if (adev->gmc.stolen_size) {
> + r = amdgpu_bo_create_kernel(adev, adev->gmc.stolen_size, 
> PAGE_SIZE,
> + AMDGPU_GEM_DOMAIN_VRAM,
> + >stolen_vga_memory,
> + NULL, NULL);
> + if (r)
> + return r;
> + }
>   DRM_INFO("amdgpu: %uM of VRAM memory ready\n",
>(unsigned) (adev->gmc.real_vram_size / (1024 * 1024)));
>  
> diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c 
> b/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c
> index 5617cf62c566..24e1ea36b454 100644
> --- a/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c
> +++ b/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c
> @@ -825,6 +825,25 @@ static int gmc_v6_0_late_init(void *handle)
>   return 0;
>  }
>  
> +static unsigned gmc_v6_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 = 9 * 1024 * 1024; /* reserve 8MB for vga emulator and 1 
> MB for FB */
> + } else {
> + u32 viewport = RREG32(mmVIEWPORT_SIZE);
> + size = (REG_GET_FIELD(viewport, VIEWPORT_SIZE, VIEWPORT_HEIGHT) 
> *
> + REG_GET_FIELD(viewport, VIEWPORT_SIZE, VIEWPORT_WIDTH) *
> + 4);
> + }
> + /* return 0 if the pre-OS buffer uses up most of vram */
> + if ((adev->gmc.real_vram_size - size) < (8 * 1024 * 1024))
> + return 0;
> + return size;
> +}
> +
>  static int gmc_v6_0_sw_init(void *handle)
>  {
>   int r;
> @@ -851,8 +870,6 @@ static int gmc_v6_0_sw_init(void *handle)
>  
>   adev->gmc.mc_mask = 0xffULL;
>  
> - adev->gmc.stolen_size = 256 * 1024;
> -
>   adev->need_dma32 = false;
>   dma_bits = adev->need_dma32 ? 32 : 40;
>   r = pci_set_dma_mask(adev->pdev, DMA_BIT_MASK(dma_bits));
> @@ -878,6 +895,8 @@ static int gmc_v6_0_sw_init(void *handle)
>   if (r)
>   return r;
>  
> + adev->gmc.stolen_size = gmc_v6_0_get_vbios_fb_size(adev);
> +
>   r = amdgpu_bo_init(adev);
>   if (r)
>   return r;
> diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c 
> b/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c
> index 80054f36e487..93861f9c7773 100644
> --- a/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c
> +++ b/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c
> @@ -964,6 +964,25 @@ static int gmc_v7_0_late_init(void *handle)
>   return 0;
>  }
>  
> +static unsigned gmc_v7_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 = 9 * 1024 * 1024; /* reserve 8MB for vga emulator and 1 
> MB for FB */
> + } else {
> + u32 viewport = RREG32(mmVIEWPORT_SIZE);
> + size = (REG_GET_FIELD(viewport, VIEWPORT_SIZE, VIEWPORT_HEIGHT) 
> *
> + REG_GET_FIELD(viewport, VIEWPORT_SIZE, VIEWPORT_WIDTH) *
> + 4);
> + }
> + /* return 0 if the pre-OS buffer uses up most of vram */
> + if ((adev->gmc.real_vram_size - size) < (8 * 1024 * 1024))
> + return 0;
> + return size;
> +}
> +
>  static int gmc_v7_0_sw_init(void *handle)
>  {
>   int 

Re: [PATCH 1/2] drm/amdgpu/gmc: steal the appropriate amount of vram for fw hand-over (v2)

2018-04-09 Thread Michel Dänzer
On 2018-04-06 09:54 PM, Alex Deucher wrote:
> Steal 9 MB for vga emulation and fb if vga is enabled, otherwise,
> steal enough to cover the current display size as set by the vbios.
> 
> If no memory is used (e.g., secondary or headless card), skip
> stolen memory reserve.
> 
> v2: skip reservation if vram is limited, address Christian's comments
> 
> Reviewed-and-Tested-by: Andrey Grodzovsky  (v1)
> Signed-off-by: Alex Deucher 

[...]

> diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c 
> b/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c
> index 5617cf62c566..24e1ea36b454 100644
> --- a/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c
> +++ b/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c
> @@ -825,6 +825,25 @@ static int gmc_v6_0_late_init(void *handle)
>   return 0;
>  }
>  
> +static unsigned gmc_v6_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 = 9 * 1024 * 1024; /* reserve 8MB for vga emulator and 1 
> MB for FB */
> + } else {
> + u32 viewport = RREG32(mmVIEWPORT_SIZE);
> + size = (REG_GET_FIELD(viewport, VIEWPORT_SIZE, VIEWPORT_HEIGHT) 
> *
> + REG_GET_FIELD(viewport, VIEWPORT_SIZE, VIEWPORT_WIDTH) *
> + 4);
> + }

Any particular reason for not calculating the FB size based on the
viewport even if VGA is enabled? VGA text mode can use higher
resolutions as well.

Other than that, these patches look good to me.


-- 
Earthling Michel Dänzer   |   http://www.amd.com
Libre software enthusiast | Mesa and X developer
___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


Re: [PATCH 1/2] drm/amdgpu/gmc: steal the appropriate amount of vram for fw hand-over (v2)

2018-04-06 Thread Andrey Grodzovsky

OK, sorry for the noise.

Andrey


On 04/06/2018 04:17 PM, Alex Deucher wrote:

This will not work unless gmc_v6_0_mc_init in gmc_v6_0_sw_init will be moved
before gmc_v6_0_get_vbios_fb_size, real_vram_size
is not initialized in this point. Same for other ASICs.

Yeah, I moved it down.  See below.

Alex



___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


Re: [PATCH 1/2] drm/amdgpu/gmc: steal the appropriate amount of vram for fw hand-over (v2)

2018-04-06 Thread Alex Deucher
On Fri, Apr 6, 2018 at 4:06 PM, Andrey Grodzovsky
 wrote:
> On 04/06/2018 03:54 PM, Alex Deucher wrote:
>
>> Steal 9 MB for vga emulation and fb if vga is enabled, otherwise,
>> steal enough to cover the current display size as set by the vbios.
>>
>> If no memory is used (e.g., secondary or headless card), skip
>> stolen memory reserve.
>>
>> v2: skip reservation if vram is limited, address Christian's comments
>>
>> Reviewed-and-Tested-by: Andrey Grodzovsky  (v1)
>> Signed-off-by: Alex Deucher 
>> ---
>>   drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 14 +
>>   drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c   | 23 +--
>>   drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c   | 23 +--
>>   drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c   | 23 +--
>>   drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c   | 51
>> +
>>   5 files changed, 116 insertions(+), 18 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
>> index 205da3ff9cd0..46c69ad34461 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
>> @@ -1454,12 +1454,14 @@ int amdgpu_ttm_init(struct amdgpu_device *adev)
>> return r;
>> }
>>   - r = amdgpu_bo_create_kernel(adev, adev->gmc.stolen_size,
>> PAGE_SIZE,
>> -   AMDGPU_GEM_DOMAIN_VRAM,
>> -   >stolen_vga_memory,
>> -   NULL, NULL);
>> -   if (r)
>> -   return r;
>> +   if (adev->gmc.stolen_size) {
>> +   r = amdgpu_bo_create_kernel(adev, adev->gmc.stolen_size,
>> PAGE_SIZE,
>> +   AMDGPU_GEM_DOMAIN_VRAM,
>> +   >stolen_vga_memory,
>> +   NULL, NULL);
>> +   if (r)
>> +   return r;
>> +   }
>> DRM_INFO("amdgpu: %uM of VRAM memory ready\n",
>>  (unsigned) (adev->gmc.real_vram_size / (1024 * 1024)));
>>   diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c
>> b/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c
>> index 5617cf62c566..24e1ea36b454 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c
>> @@ -825,6 +825,25 @@ static int gmc_v6_0_late_init(void *handle)
>> return 0;
>>   }
>>   +static unsigned gmc_v6_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 = 9 * 1024 * 1024; /* reserve 8MB for vga emulator
>> and 1 MB for FB */
>> +   } else {
>> +   u32 viewport = RREG32(mmVIEWPORT_SIZE);
>> +   size = (REG_GET_FIELD(viewport, VIEWPORT_SIZE,
>> VIEWPORT_HEIGHT) *
>> +   REG_GET_FIELD(viewport, VIEWPORT_SIZE,
>> VIEWPORT_WIDTH) *
>> +   4);
>> +   }
>> +   /* return 0 if the pre-OS buffer uses up most of vram */
>> +   if ((adev->gmc.real_vram_size - size) < (8 * 1024 * 1024))
>> +   return 0;
>
>
> This will not work unless gmc_v6_0_mc_init in gmc_v6_0_sw_init will be moved
> before gmc_v6_0_get_vbios_fb_size, real_vram_size
> is not initialized in this point. Same for other ASICs.

Yeah, I moved it down.  See below.

Alex

>
> Andrey
>
>> +   return size;
>> +}
>> +
>>   static int gmc_v6_0_sw_init(void *handle)
>>   {
>> int r;
>> @@ -851,8 +870,6 @@ static int gmc_v6_0_sw_init(void *handle)
>> adev->gmc.mc_mask = 0xffULL;
>>   - adev->gmc.stolen_size = 256 * 1024;
>> -
>> adev->need_dma32 = false;
>> dma_bits = adev->need_dma32 ? 32 : 40;
>> r = pci_set_dma_mask(adev->pdev, DMA_BIT_MASK(dma_bits));
>> @@ -878,6 +895,8 @@ static int gmc_v6_0_sw_init(void *handle)
>> if (r)
>> return r;
>>   + adev->gmc.stolen_size = gmc_v6_0_get_vbios_fb_size(adev);
>> +
>> r = amdgpu_bo_init(adev);
>> if (r)
>> return r;
>> diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c
>> b/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c
>> index 80054f36e487..93861f9c7773 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c
>> @@ -964,6 +964,25 @@ static int gmc_v7_0_late_init(void *handle)
>> return 0;
>>   }
>>   +static unsigned gmc_v7_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 = 9 * 1024 * 1024; /* reserve 8MB for vga emulator
>> and 1 MB for FB */
>> +   

Re: [PATCH 1/2] drm/amdgpu/gmc: steal the appropriate amount of vram for fw hand-over (v2)

2018-04-06 Thread Andrey Grodzovsky

On 04/06/2018 03:54 PM, Alex Deucher wrote:


Steal 9 MB for vga emulation and fb if vga is enabled, otherwise,
steal enough to cover the current display size as set by the vbios.

If no memory is used (e.g., secondary or headless card), skip
stolen memory reserve.

v2: skip reservation if vram is limited, address Christian's comments

Reviewed-and-Tested-by: Andrey Grodzovsky  (v1)
Signed-off-by: Alex Deucher 
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 14 +
  drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c   | 23 +--
  drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c   | 23 +--
  drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c   | 23 +--
  drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c   | 51 +
  5 files changed, 116 insertions(+), 18 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
index 205da3ff9cd0..46c69ad34461 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
@@ -1454,12 +1454,14 @@ int amdgpu_ttm_init(struct amdgpu_device *adev)
return r;
}
  
-	r = amdgpu_bo_create_kernel(adev, adev->gmc.stolen_size, PAGE_SIZE,

-   AMDGPU_GEM_DOMAIN_VRAM,
-   >stolen_vga_memory,
-   NULL, NULL);
-   if (r)
-   return r;
+   if (adev->gmc.stolen_size) {
+   r = amdgpu_bo_create_kernel(adev, adev->gmc.stolen_size, 
PAGE_SIZE,
+   AMDGPU_GEM_DOMAIN_VRAM,
+   >stolen_vga_memory,
+   NULL, NULL);
+   if (r)
+   return r;
+   }
DRM_INFO("amdgpu: %uM of VRAM memory ready\n",
 (unsigned) (adev->gmc.real_vram_size / (1024 * 1024)));
  
diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c b/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c

index 5617cf62c566..24e1ea36b454 100644
--- a/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c
@@ -825,6 +825,25 @@ static int gmc_v6_0_late_init(void *handle)
return 0;
  }
  
+static unsigned gmc_v6_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 = 9 * 1024 * 1024; /* reserve 8MB for vga emulator and 1 
MB for FB */
+   } else {
+   u32 viewport = RREG32(mmVIEWPORT_SIZE);
+   size = (REG_GET_FIELD(viewport, VIEWPORT_SIZE, VIEWPORT_HEIGHT) 
*
+   REG_GET_FIELD(viewport, VIEWPORT_SIZE, VIEWPORT_WIDTH) *
+   4);
+   }
+   /* return 0 if the pre-OS buffer uses up most of vram */
+   if ((adev->gmc.real_vram_size - size) < (8 * 1024 * 1024))
+   return 0;


This will not work unless gmc_v6_0_mc_init in gmc_v6_0_sw_init will be 
moved before gmc_v6_0_get_vbios_fb_size, real_vram_size

is not initialized in this point. Same for other ASICs.

Andrey

+   return size;
+}
+
  static int gmc_v6_0_sw_init(void *handle)
  {
int r;
@@ -851,8 +870,6 @@ static int gmc_v6_0_sw_init(void *handle)
  
  	adev->gmc.mc_mask = 0xffULL;
  
-	adev->gmc.stolen_size = 256 * 1024;

-
adev->need_dma32 = false;
dma_bits = adev->need_dma32 ? 32 : 40;
r = pci_set_dma_mask(adev->pdev, DMA_BIT_MASK(dma_bits));
@@ -878,6 +895,8 @@ static int gmc_v6_0_sw_init(void *handle)
if (r)
return r;
  
+	adev->gmc.stolen_size = gmc_v6_0_get_vbios_fb_size(adev);

+
r = amdgpu_bo_init(adev);
if (r)
return r;
diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c 
b/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c
index 80054f36e487..93861f9c7773 100644
--- a/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c
@@ -964,6 +964,25 @@ static int gmc_v7_0_late_init(void *handle)
return 0;
  }
  
+static unsigned gmc_v7_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 = 9 * 1024 * 1024; /* reserve 8MB for vga emulator and 1 
MB for FB */
+   } else {
+   u32 viewport = RREG32(mmVIEWPORT_SIZE);
+   size = (REG_GET_FIELD(viewport, VIEWPORT_SIZE, VIEWPORT_HEIGHT) 
*
+   REG_GET_FIELD(viewport, VIEWPORT_SIZE, VIEWPORT_WIDTH) *
+   4);
+   }
+   /* return 0 if the pre-OS buffer uses up most of vram */
+   if ((adev->gmc.real_vram_size - size) < (8 * 1024 * 1024))
+   return 0;
+   return size;
+}
+
  static int 

Re: [PATCH 1/2] drm/amdgpu/gmc: steal the appropriate amount of vram for fw hand-over

2018-04-06 Thread Alex Deucher
On Fri, Apr 6, 2018 at 3:04 PM, Christian König
 wrote:
> Am 06.04.2018 um 19:24 schrieb Alex Deucher:
>>
>> Steal 9 MB for vga emulation and fb if vga is enabled, otherwise,
>> steal enough to cover the current display size as set by the vbios.
>>
>> If no memory is used (e.g., secondary or headless card), skip
>> stolen memory reserve.
>>
>> Signed-off-by: Alex Deucher 
>> ---
>>   drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 17 +++--
>>   drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c   | 17 -
>>   drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c   | 17 -
>>   drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c   | 17 -
>>   drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c   | 42
>> -
>>   5 files changed, 99 insertions(+), 11 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
>> index 205da3ff9cd0..2de2f5e5a0f9 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
>> @@ -1454,12 +1454,14 @@ int amdgpu_ttm_init(struct amdgpu_device *adev)
>> return r;
>> }
>>   - r = amdgpu_bo_create_kernel(adev, adev->gmc.stolen_size,
>> PAGE_SIZE,
>> -   AMDGPU_GEM_DOMAIN_VRAM,
>> -   >stolen_vga_memory,
>> -   NULL, NULL);
>> -   if (r)
>> -   return r;
>> +   if (adev->gmc.stolen_size) {
>> +   r = amdgpu_bo_create_kernel(adev, adev->gmc.stolen_size,
>> PAGE_SIZE,
>> +   AMDGPU_GEM_DOMAIN_VRAM,
>> +   >stolen_vga_memory,
>> +   NULL, NULL);
>> +   if (r)
>> +   return r;
>> +   }
>
>
> We should probably rather handle zero size in amdgpu_bo_create_kernel() as
> just setting the pointer to NULL instead of trying to allocate a zero sized
> BO.

yeah, I guess that would work too.

>
>> DRM_INFO("amdgpu: %uM of VRAM memory ready\n",
>>  (unsigned) (adev->gmc.real_vram_size / (1024 * 1024)));
>>   @@ -1534,7 +1536,8 @@ void amdgpu_ttm_fini(struct amdgpu_device *adev)
>> return;
>> amdgpu_ttm_debugfs_fini(adev);
>> -   amdgpu_bo_free_kernel(>stolen_vga_memory, NULL, NULL);
>> +   if (adev->gmc.stolen_size)
>> +   amdgpu_bo_free_kernel(>stolen_vga_memory, NULL,
>> NULL);
>
>
> The if can be skipped here, freeing a NULL pointer is harmless.


Ok.

>
>
>> amdgpu_ttm_fw_reserve_vram_fini(adev);
>> if (adev->mman.aper_base_kaddr)
>> iounmap(adev->mman.aper_base_kaddr);
>> diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c
>> b/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c
>> index 5617cf62c566..63f0b65854a3 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c
>> @@ -825,6 +825,21 @@ static int gmc_v6_0_late_init(void *handle)
>> return 0;
>>   }
>>   +static unsigned gmc_v6_0_get_vbios_fb_size(struct amdgpu_device *adev)
>> +{
>> +   u32 d1vga_control = RREG32(mmD1VGA_CONTROL);
>> +
>> +   if (REG_GET_FIELD(d1vga_control, D1VGA_CONTROL,
>> D1VGA_MODE_ENABLE)) {
>> +   return 9 * 1024 * 1024; /* reserve 8MB for vga emulator
>> and 1 MB for FB */
>> +   } else {
>> +   u32 viewport = RREG32(mmVIEWPORT_SIZE);
>> +   unsigned size = (REG_GET_FIELD(viewport, VIEWPORT_SIZE,
>> VIEWPORT_HEIGHT) *
>> +REG_GET_FIELD(viewport, VIEWPORT_SIZE,
>> VIEWPORT_WIDTH) *
>> +4);
>> +   return size;
>> +   }
>> +}
>> +
>>   static int gmc_v6_0_sw_init(void *handle)
>>   {
>> int r;
>> @@ -851,7 +866,7 @@ static int gmc_v6_0_sw_init(void *handle)
>> adev->gmc.mc_mask = 0xffULL;
>>   - adev->gmc.stolen_size = 256 * 1024;
>> +   adev->gmc.stolen_size = gmc_v6_0_get_vbios_fb_size(adev);
>> adev->need_dma32 = false;
>> dma_bits = adev->need_dma32 ? 32 : 40;
>> diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c
>> b/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c
>> index 80054f36e487..2deb5c93ef28 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c
>> @@ -964,6 +964,21 @@ static int gmc_v7_0_late_init(void *handle)
>> return 0;
>>   }
>>   +static unsigned gmc_v7_0_get_vbios_fb_size(struct amdgpu_device *adev)
>> +{
>> +   u32 d1vga_control = RREG32(mmD1VGA_CONTROL);
>> +
>> +   if (REG_GET_FIELD(d1vga_control, D1VGA_CONTROL,
>> D1VGA_MODE_ENABLE)) {
>> +   return 9 * 1024 * 1024; /* reserve 8MB for vga emulator
>> and 1 MB for FB */
>> +   } else {
>> +   u32 viewport = RREG32(mmVIEWPORT_SIZE);
>> +   unsigned size 

Re: [PATCH 1/2] drm/amdgpu/gmc: steal the appropriate amount of vram for fw hand-over

2018-04-06 Thread Christian König

Am 06.04.2018 um 19:24 schrieb Alex Deucher:

Steal 9 MB for vga emulation and fb if vga is enabled, otherwise,
steal enough to cover the current display size as set by the vbios.

If no memory is used (e.g., secondary or headless card), skip
stolen memory reserve.

Signed-off-by: Alex Deucher 
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 17 +++--
  drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c   | 17 -
  drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c   | 17 -
  drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c   | 17 -
  drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c   | 42 -
  5 files changed, 99 insertions(+), 11 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
index 205da3ff9cd0..2de2f5e5a0f9 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
@@ -1454,12 +1454,14 @@ int amdgpu_ttm_init(struct amdgpu_device *adev)
return r;
}
  
-	r = amdgpu_bo_create_kernel(adev, adev->gmc.stolen_size, PAGE_SIZE,

-   AMDGPU_GEM_DOMAIN_VRAM,
-   >stolen_vga_memory,
-   NULL, NULL);
-   if (r)
-   return r;
+   if (adev->gmc.stolen_size) {
+   r = amdgpu_bo_create_kernel(adev, adev->gmc.stolen_size, 
PAGE_SIZE,
+   AMDGPU_GEM_DOMAIN_VRAM,
+   >stolen_vga_memory,
+   NULL, NULL);
+   if (r)
+   return r;
+   }


We should probably rather handle zero size in amdgpu_bo_create_kernel() 
as just setting the pointer to NULL instead of trying to allocate a zero 
sized BO.



DRM_INFO("amdgpu: %uM of VRAM memory ready\n",
 (unsigned) (adev->gmc.real_vram_size / (1024 * 1024)));
  
@@ -1534,7 +1536,8 @@ void amdgpu_ttm_fini(struct amdgpu_device *adev)

return;
  
  	amdgpu_ttm_debugfs_fini(adev);

-   amdgpu_bo_free_kernel(>stolen_vga_memory, NULL, NULL);
+   if (adev->gmc.stolen_size)
+   amdgpu_bo_free_kernel(>stolen_vga_memory, NULL, NULL);


The if can be skipped here, freeing a NULL pointer is harmless.


amdgpu_ttm_fw_reserve_vram_fini(adev);
if (adev->mman.aper_base_kaddr)
iounmap(adev->mman.aper_base_kaddr);
diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c 
b/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c
index 5617cf62c566..63f0b65854a3 100644
--- a/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c
@@ -825,6 +825,21 @@ static int gmc_v6_0_late_init(void *handle)
return 0;
  }
  
+static unsigned gmc_v6_0_get_vbios_fb_size(struct amdgpu_device *adev)

+{
+   u32 d1vga_control = RREG32(mmD1VGA_CONTROL);
+
+   if (REG_GET_FIELD(d1vga_control, D1VGA_CONTROL, D1VGA_MODE_ENABLE)) {
+   return 9 * 1024 * 1024; /* reserve 8MB for vga emulator and 1 
MB for FB */
+   } else {
+   u32 viewport = RREG32(mmVIEWPORT_SIZE);
+   unsigned size = (REG_GET_FIELD(viewport, VIEWPORT_SIZE, 
VIEWPORT_HEIGHT) *
+REG_GET_FIELD(viewport, VIEWPORT_SIZE, 
VIEWPORT_WIDTH) *
+4);
+   return size;
+   }
+}
+
  static int gmc_v6_0_sw_init(void *handle)
  {
int r;
@@ -851,7 +866,7 @@ static int gmc_v6_0_sw_init(void *handle)
  
  	adev->gmc.mc_mask = 0xffULL;
  
-	adev->gmc.stolen_size = 256 * 1024;

+   adev->gmc.stolen_size = gmc_v6_0_get_vbios_fb_size(adev);
  
  	adev->need_dma32 = false;

dma_bits = adev->need_dma32 ? 32 : 40;
diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c 
b/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c
index 80054f36e487..2deb5c93ef28 100644
--- a/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c
@@ -964,6 +964,21 @@ static int gmc_v7_0_late_init(void *handle)
return 0;
  }
  
+static unsigned gmc_v7_0_get_vbios_fb_size(struct amdgpu_device *adev)

+{
+   u32 d1vga_control = RREG32(mmD1VGA_CONTROL);
+
+   if (REG_GET_FIELD(d1vga_control, D1VGA_CONTROL, D1VGA_MODE_ENABLE)) {
+   return 9 * 1024 * 1024; /* reserve 8MB for vga emulator and 1 
MB for FB */
+   } else {
+   u32 viewport = RREG32(mmVIEWPORT_SIZE);
+   unsigned size = (REG_GET_FIELD(viewport, VIEWPORT_SIZE, 
VIEWPORT_HEIGHT) *
+REG_GET_FIELD(viewport, VIEWPORT_SIZE, 
VIEWPORT_WIDTH) *
+4);
+   return size;
+   }
+}
+
  static int gmc_v7_0_sw_init(void *handle)
  {
int r;
@@ -998,7 +1013,7 @@ static int gmc_v7_0_sw_init(void *handle)
 */
adev->gmc.mc_mask = 0xffULL; /* 40 bit MC */
  
-	adev->gmc.stolen_size 

Re: [PATCH 1/2] drm/amdgpu/gmc: steal the appropriate amount of vram for fw hand-over

2018-04-06 Thread Andrey Grodzovsky

Reviewed-and-Tested-by: Andrey Grodzovsky 

Andrey


On 04/06/2018 01:24 PM, Alex Deucher wrote:

Steal 9 MB for vga emulation and fb if vga is enabled, otherwise,
steal enough to cover the current display size as set by the vbios.

If no memory is used (e.g., secondary or headless card), skip
stolen memory reserve.

Signed-off-by: Alex Deucher 
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 17 +++--
  drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c   | 17 -
  drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c   | 17 -
  drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c   | 17 -
  drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c   | 42 -
  5 files changed, 99 insertions(+), 11 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
index 205da3ff9cd0..2de2f5e5a0f9 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
@@ -1454,12 +1454,14 @@ int amdgpu_ttm_init(struct amdgpu_device *adev)
return r;
}
  
-	r = amdgpu_bo_create_kernel(adev, adev->gmc.stolen_size, PAGE_SIZE,

-   AMDGPU_GEM_DOMAIN_VRAM,
-   >stolen_vga_memory,
-   NULL, NULL);
-   if (r)
-   return r;
+   if (adev->gmc.stolen_size) {
+   r = amdgpu_bo_create_kernel(adev, adev->gmc.stolen_size, 
PAGE_SIZE,
+   AMDGPU_GEM_DOMAIN_VRAM,
+   >stolen_vga_memory,
+   NULL, NULL);
+   if (r)
+   return r;
+   }
DRM_INFO("amdgpu: %uM of VRAM memory ready\n",
 (unsigned) (adev->gmc.real_vram_size / (1024 * 1024)));
  
@@ -1534,7 +1536,8 @@ void amdgpu_ttm_fini(struct amdgpu_device *adev)

return;
  
  	amdgpu_ttm_debugfs_fini(adev);

-   amdgpu_bo_free_kernel(>stolen_vga_memory, NULL, NULL);
+   if (adev->gmc.stolen_size)
+   amdgpu_bo_free_kernel(>stolen_vga_memory, NULL, NULL);
amdgpu_ttm_fw_reserve_vram_fini(adev);
if (adev->mman.aper_base_kaddr)
iounmap(adev->mman.aper_base_kaddr);
diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c 
b/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c
index 5617cf62c566..63f0b65854a3 100644
--- a/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c
@@ -825,6 +825,21 @@ static int gmc_v6_0_late_init(void *handle)
return 0;
  }
  
+static unsigned gmc_v6_0_get_vbios_fb_size(struct amdgpu_device *adev)

+{
+   u32 d1vga_control = RREG32(mmD1VGA_CONTROL);
+
+   if (REG_GET_FIELD(d1vga_control, D1VGA_CONTROL, D1VGA_MODE_ENABLE)) {
+   return 9 * 1024 * 1024; /* reserve 8MB for vga emulator and 1 
MB for FB */
+   } else {
+   u32 viewport = RREG32(mmVIEWPORT_SIZE);
+   unsigned size = (REG_GET_FIELD(viewport, VIEWPORT_SIZE, 
VIEWPORT_HEIGHT) *
+REG_GET_FIELD(viewport, VIEWPORT_SIZE, 
VIEWPORT_WIDTH) *
+4);
+   return size;
+   }
+}
+
  static int gmc_v6_0_sw_init(void *handle)
  {
int r;
@@ -851,7 +866,7 @@ static int gmc_v6_0_sw_init(void *handle)
  
  	adev->gmc.mc_mask = 0xffULL;
  
-	adev->gmc.stolen_size = 256 * 1024;

+   adev->gmc.stolen_size = gmc_v6_0_get_vbios_fb_size(adev);
  
  	adev->need_dma32 = false;

dma_bits = adev->need_dma32 ? 32 : 40;
diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c 
b/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c
index 80054f36e487..2deb5c93ef28 100644
--- a/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c
@@ -964,6 +964,21 @@ static int gmc_v7_0_late_init(void *handle)
return 0;
  }
  
+static unsigned gmc_v7_0_get_vbios_fb_size(struct amdgpu_device *adev)

+{
+   u32 d1vga_control = RREG32(mmD1VGA_CONTROL);
+
+   if (REG_GET_FIELD(d1vga_control, D1VGA_CONTROL, D1VGA_MODE_ENABLE)) {
+   return 9 * 1024 * 1024; /* reserve 8MB for vga emulator and 1 
MB for FB */
+   } else {
+   u32 viewport = RREG32(mmVIEWPORT_SIZE);
+   unsigned size = (REG_GET_FIELD(viewport, VIEWPORT_SIZE, 
VIEWPORT_HEIGHT) *
+REG_GET_FIELD(viewport, VIEWPORT_SIZE, 
VIEWPORT_WIDTH) *
+4);
+   return size;
+   }
+}
+
  static int gmc_v7_0_sw_init(void *handle)
  {
int r;
@@ -998,7 +1013,7 @@ static int gmc_v7_0_sw_init(void *handle)
 */
adev->gmc.mc_mask = 0xffULL; /* 40 bit MC */
  
-	adev->gmc.stolen_size = 256 * 1024;

+   adev->gmc.stolen_size = gmc_v7_0_get_vbios_fb_size(adev);
  
  	/* set DMA mask + need_dma32 flags.

 * PCIE - can