]> git.karo-electronics.de Git - linux-beck.git/commitdiff
drm/radeon/kms: fix VRAM sizing like DDX does it.
authorDave Airlie <airlied@linux.ie>
Fri, 10 Jul 2009 18:44:47 +0000 (04:44 +1000)
committerDave Airlie <airlied@redhat.com>
Wed, 15 Jul 2009 07:13:19 +0000 (17:13 +1000)
Doing this like the DDX seems like the most sure fire way to avoid
having to reinvent it slowly and painfully. At the moment we keep
getting things wrong with aper vs vram, so we know the DDX does it right.

booted on PCI r100, PCIE rv370, IGP rs400.

Signed-off-by: Dave Airlie <airlied@redhat.com>
drivers/gpu/drm/radeon/r100.c
drivers/gpu/drm/radeon/r300.c
drivers/gpu/drm/radeon/r520.c
drivers/gpu/drm/radeon/radeon.h
drivers/gpu/drm/radeon/radeon_device.c
drivers/gpu/drm/radeon/rs400.c
drivers/gpu/drm/radeon/rv515.c

index 154648a2c0277910fc0bc247249485110a75880f..97c9229b9299ce0fb0c2bb2b3139af306a2cb376 100644 (file)
@@ -1360,9 +1360,50 @@ static void r100_vram_get_type(struct radeon_device *rdev)
        }
 }
 
-void r100_vram_info(struct radeon_device *rdev)
+static u32 r100_get_accessible_vram(struct radeon_device *rdev)
 {
-       r100_vram_get_type(rdev);
+       u32 aper_size;
+       u8 byte;
+
+       aper_size = RREG32(RADEON_CONFIG_APER_SIZE);
+
+       /* Set HDP_APER_CNTL only on cards that are known not to be broken,
+        * that is has the 2nd generation multifunction PCI interface
+        */
+       if (rdev->family == CHIP_RV280 ||
+           rdev->family >= CHIP_RV350) {
+               WREG32_P(RADEON_HOST_PATH_CNTL, RADEON_HDP_APER_CNTL,
+                      ~RADEON_HDP_APER_CNTL);
+               DRM_INFO("Generation 2 PCI interface, using max accessible memory\n");
+               return aper_size * 2;
+       }
+
+       /* Older cards have all sorts of funny issues to deal with. First
+        * check if it's a multifunction card by reading the PCI config
+        * header type... Limit those to one aperture size
+        */
+       pci_read_config_byte(rdev->pdev, 0xe, &byte);
+       if (byte & 0x80) {
+               DRM_INFO("Generation 1 PCI interface in multifunction mode\n");
+               DRM_INFO("Limiting VRAM to one aperture\n");
+               return aper_size;
+       }
+
+       /* Single function older card. We read HDP_APER_CNTL to see how the BIOS
+        * have set it up. We don't write this as it's broken on some ASICs but
+        * we expect the BIOS to have done the right thing (might be too optimistic...)
+        */
+       if (RREG32(RADEON_HOST_PATH_CNTL) & RADEON_HDP_APER_CNTL)
+               return aper_size * 2;
+       return aper_size;
+}
+
+void r100_vram_init_sizes(struct radeon_device *rdev)
+{
+       u64 config_aper_size;
+       u32 accessible;
+
+       config_aper_size = RREG32(RADEON_CONFIG_APER_SIZE);
 
        if (rdev->flags & RADEON_IS_IGP) {
                uint32_t tom;
@@ -1383,10 +1424,30 @@ void r100_vram_info(struct radeon_device *rdev)
                }
                /* let driver place VRAM */
                rdev->mc.vram_location = 0xFFFFFFFFUL;
+                /* Fix for RN50, M6, M7 with 8/16/32(??) MBs of VRAM - 
+                 * Novell bug 204882 + along with lots of ubuntu ones */
+               if (config_aper_size > rdev->mc.vram_size)
+                       rdev->mc.vram_size = config_aper_size;
        }
 
+       /* work out accessible VRAM */
+       accessible = r100_get_accessible_vram(rdev);
+
        rdev->mc.aper_base = drm_get_resource_start(rdev->ddev, 0);
        rdev->mc.aper_size = drm_get_resource_len(rdev->ddev, 0);
+
+       if (accessible > rdev->mc.aper_size)
+               accessible = rdev->mc.aper_size;
+
+       if (rdev->mc.vram_size > rdev->mc.aper_size)
+               rdev->mc.vram_size = rdev->mc.aper_size;
+}
+
+void r100_vram_info(struct radeon_device *rdev)
+{
+       r100_vram_get_type(rdev);
+
+       r100_vram_init_sizes(rdev);
 }
 
 
index 6435d659cbd13d1f86117d44f02e90f36874b996..0e0e094da50308b2c31f2501ff3a1e7dd9e0a28e 100644 (file)
@@ -585,10 +585,8 @@ void r300_vram_info(struct radeon_device *rdev)
        } else {
                rdev->mc.vram_width = 64;
        }
-       rdev->mc.vram_size = RREG32(RADEON_CONFIG_MEMSIZE);
 
-       rdev->mc.aper_base = drm_get_resource_start(rdev->ddev, 0);
-       rdev->mc.aper_size = drm_get_resource_len(rdev->ddev, 0);
+       r100_vram_init_sizes(rdev);
 }
 
 
index 570a244bd88b6815725129def0a3d8280281a8ed..b6bd3758db6b871d90c0c84c7e057522869c209d 100644 (file)
@@ -227,8 +227,6 @@ static void r520_vram_get_type(struct radeon_device *rdev)
 void r520_vram_info(struct radeon_device *rdev)
 {
        r520_vram_get_type(rdev);
-       rdev->mc.vram_size = RREG32(RADEON_CONFIG_MEMSIZE);
 
-       rdev->mc.aper_base = drm_get_resource_start(rdev->ddev, 0);
-       rdev->mc.aper_size = drm_get_resource_len(rdev->ddev, 0);
+       r100_vram_init_sizes(rdev);
 }
index 3060ce14071e2c35e9da4bbf72a80f6f187a0e46..248e3341a984621f193fead3111473270afdfab8 100644 (file)
@@ -541,6 +541,8 @@ union radeon_asic_config {
        struct r300_asic        r300;
 };
 
+/* r100 */
+void r100_vram_init_sizes(struct radeon_device *rdev);
 
 /*
  * IOCTL.
index 27a5ac969953333714ee345387c7aa666c8ece04..cdef6eb01baf096adadea61915c6dfa60888d881 100644 (file)
@@ -561,12 +561,7 @@ int radeon_device_init(struct radeon_device *rdev,
        }
        /* Get vram informations */
        radeon_vram_info(rdev);
-       /* Device is severly broken if aper size > vram size.
-        * for RN50/M6/M7 - Novell bug 204882 ?
-        */
-       if (rdev->mc.vram_size < rdev->mc.aper_size) {
-               rdev->mc.vram_size = rdev->mc.aper_size;
-       }
+
        /* Add an MTRR for the VRAM */
        rdev->mc.vram_mtrr = mtrr_add(rdev->mc.aper_base, rdev->mc.aper_size,
                                      MTRR_TYPE_WRCOMB, 1);
index a18d053065c0877b732824e9f1a82b04bbd4d0c5..daf24e85cba30d571fbdc899d7fe77374fb60879 100644 (file)
@@ -292,24 +292,12 @@ void rs400_gpu_init(struct radeon_device *rdev)
  */
 void rs400_vram_info(struct radeon_device *rdev)
 {
-       uint32_t tom;
-
        rs400_gart_adjust_size(rdev);
        /* DDR for all card after R300 & IGP */
        rdev->mc.vram_is_ddr = true;
        rdev->mc.vram_width = 128;
 
-       /* read NB_TOM to get the amount of ram stolen for the GPU */
-       tom = RREG32(RADEON_NB_TOM);
-       rdev->mc.vram_size = (((tom >> 16) - (tom & 0xffff) + 1) << 16);
-       WREG32(RADEON_CONFIG_MEMSIZE, rdev->mc.vram_size);
-
-       /* RS480 IGPs don't seem to translate to main RAM, they
-        * just reserve and scan out of it. So setting VRAM location
-        * to say 0, will actually trash the OS. */
-       rdev->mc.vram_location = (tom & 0xffff) << 16;
-       rdev->mc.aper_base = drm_get_resource_start(rdev->ddev, 0);
-       rdev->mc.aper_size = drm_get_resource_len(rdev->ddev, 0);
+       r100_vram_init_sizes(rdev);
 }
 
 
index d1384d3991add87d3b7596c98534c1bb232e3370..677929ed8ed3648188cfff96e1132432f896818f 100644 (file)
@@ -395,10 +395,8 @@ static void rv515_vram_get_type(struct radeon_device *rdev)
 void rv515_vram_info(struct radeon_device *rdev)
 {
        rv515_vram_get_type(rdev);
-       rdev->mc.vram_size = RREG32(RADEON_CONFIG_MEMSIZE);
-
-       rdev->mc.aper_base = drm_get_resource_start(rdev->ddev, 0);
-       rdev->mc.aper_size = drm_get_resource_len(rdev->ddev, 0);
+       
+       r100_vram_init_sizes(rdev);
 }