LCOV - code coverage report
Current view: top level - dev/pci/drm/radeon - radeon_agp.c (source / functions) Hit Total Coverage
Test: 6.4 Lines: 0 92 0.0 %
Date: 2018-10-19 03:25:38 Functions: 0 4 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright 2008 Red Hat Inc.
       3             :  * Copyright 2009 Jerome Glisse.
       4             :  *
       5             :  * Permission is hereby granted, free of charge, to any person obtaining a
       6             :  * copy of this software and associated documentation files (the "Software"),
       7             :  * to deal in the Software without restriction, including without limitation
       8             :  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
       9             :  * and/or sell copies of the Software, and to permit persons to whom the
      10             :  * Software is furnished to do so, subject to the following conditions:
      11             :  *
      12             :  * The above copyright notice and this permission notice shall be included in
      13             :  * all copies or substantial portions of the Software.
      14             :  *
      15             :  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
      16             :  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      17             :  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
      18             :  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
      19             :  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
      20             :  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
      21             :  * OTHER DEALINGS IN THE SOFTWARE.
      22             :  *
      23             :  * Authors:
      24             :  *    Dave Airlie
      25             :  *    Jerome Glisse <glisse@freedesktop.org>
      26             :  */
      27             : #include <dev/pci/drm/drmP.h>
      28             : #include "radeon.h"
      29             : #include <dev/pci/drm/radeon_drm.h>
      30             : 
      31             : #if __OS_HAS_AGP
      32             : 
      33             : struct radeon_agpmode_quirk {
      34             :         u32 hostbridge_vendor;
      35             :         u32 hostbridge_device;
      36             :         u32 chip_vendor;
      37             :         u32 chip_device;
      38             :         u32 subsys_vendor;
      39             :         u32 subsys_device;
      40             :         u32 default_mode;
      41             : };
      42             : 
      43             : static struct radeon_agpmode_quirk radeon_agpmode_quirk_list[] = {
      44             :         /* Intel E7505 Memory Controller Hub / RV350 AR [Radeon 9600XT] Needs AGPMode 4 (deb #515326) */
      45             :         { PCI_VENDOR_ID_INTEL, 0x2550, PCI_VENDOR_ID_ATI, 0x4152, 0x1458, 0x4038, 4},
      46             :         /* Intel 82865G/PE/P DRAM Controller/Host-Hub / Mobility 9800 Needs AGPMode 4 (deb #462590) */
      47             :         { PCI_VENDOR_ID_INTEL, 0x2570, PCI_VENDOR_ID_ATI, 0x4a4e, PCI_VENDOR_ID_DELL, 0x5106, 4},
      48             :         /* Intel 82865G/PE/P DRAM Controller/Host-Hub / RV280 [Radeon 9200 SE] Needs AGPMode 4 (lp #300304) */
      49             :         { PCI_VENDOR_ID_INTEL, 0x2570, PCI_VENDOR_ID_ATI, 0x5964,
      50             :                 0x148c, 0x2073, 4},
      51             :         /* Intel 82855PM Processor to I/O Controller / Mobility M6 LY Needs AGPMode 1 (deb #467235) */
      52             :         { PCI_VENDOR_ID_INTEL, 0x3340, PCI_VENDOR_ID_ATI, 0x4c59,
      53             :                 PCI_VENDOR_ID_IBM, 0x052f, 1},
      54             :         /* Intel 82855PM host bridge / Mobility 9600 M10 RV350 Needs AGPMode 1 (lp #195051) */
      55             :         { PCI_VENDOR_ID_INTEL, 0x3340, PCI_VENDOR_ID_ATI, 0x4e50,
      56             :                 PCI_VENDOR_ID_IBM, 0x0550, 1},
      57             :         /* Intel 82855PM host bridge / RV250/M9 GL [Mobility FireGL 9000/Radeon 9000] needs AGPMode 1 (Thinkpad T40p) */
      58             :         { PCI_VENDOR_ID_INTEL, 0x3340, PCI_VENDOR_ID_ATI, 0x4c66,
      59             :                 PCI_VENDOR_ID_IBM, 0x054d, 1},
      60             :         /* Intel 82855PM host bridge / Mobility M7 needs AGPMode 1 */
      61             :         { PCI_VENDOR_ID_INTEL, 0x3340, PCI_VENDOR_ID_ATI, 0x4c57,
      62             :                 PCI_VENDOR_ID_IBM, 0x0530, 1},
      63             :         /* Intel 82855PM host bridge / FireGL Mobility T2 RV350 Needs AGPMode 2 (fdo #20647) */
      64             :         { PCI_VENDOR_ID_INTEL, 0x3340, PCI_VENDOR_ID_ATI, 0x4e54,
      65             :                 PCI_VENDOR_ID_IBM, 0x054f, 2},
      66             :         /* Intel 82855PM host bridge / Mobility M9+ / VaioPCG-V505DX Needs AGPMode 2 (fdo #17928) */
      67             :         { PCI_VENDOR_ID_INTEL, 0x3340, PCI_VENDOR_ID_ATI, 0x5c61,
      68             :                 PCI_VENDOR_ID_SONY, 0x816b, 2},
      69             :         /* Intel 82855PM Processor to I/O Controller / Mobility M9+ Needs AGPMode 8 (phoronix forum) */
      70             :         { PCI_VENDOR_ID_INTEL, 0x3340, PCI_VENDOR_ID_ATI, 0x5c61,
      71             :                 PCI_VENDOR_ID_SONY, 0x8195, 8},
      72             :         /* Intel 82830 830 Chipset Host Bridge / Mobility M6 LY Needs AGPMode 2 (fdo #17360)*/
      73             :         { PCI_VENDOR_ID_INTEL, 0x3575, PCI_VENDOR_ID_ATI, 0x4c59,
      74             :                 PCI_VENDOR_ID_DELL, 0x00e3, 2},
      75             :         /* Intel 82852/82855 host bridge / Mobility FireGL 9000 RV250 Needs AGPMode 1 (lp #296617) */
      76             :         { PCI_VENDOR_ID_INTEL, 0x3580, PCI_VENDOR_ID_ATI, 0x4c66,
      77             :                 PCI_VENDOR_ID_DELL, 0x0149, 1},
      78             :         /* Intel 82855PM host bridge / Mobility FireGL 9000 RV250 Needs AGPMode 1 for suspend/resume */
      79             :         { PCI_VENDOR_ID_INTEL, 0x3340, PCI_VENDOR_ID_ATI, 0x4c66,
      80             :                 PCI_VENDOR_ID_IBM, 0x0531, 1},
      81             :         /* Intel 82852/82855 host bridge / Mobility 9600 M10 RV350 Needs AGPMode 1 (deb #467460) */
      82             :         { PCI_VENDOR_ID_INTEL, 0x3580, PCI_VENDOR_ID_ATI, 0x4e50,
      83             :                 0x1025, 0x0061, 1},
      84             :         /* Intel 82852/82855 host bridge / Mobility 9600 M10 RV350 Needs AGPMode 1 (lp #203007) */
      85             :         { PCI_VENDOR_ID_INTEL, 0x3580, PCI_VENDOR_ID_ATI, 0x4e50,
      86             :                 0x1025, 0x0064, 1},
      87             :         /* Intel 82852/82855 host bridge / Mobility 9600 M10 RV350 Needs AGPMode 1 (lp #141551) */
      88             :         { PCI_VENDOR_ID_INTEL, 0x3580, PCI_VENDOR_ID_ATI, 0x4e50,
      89             :                 PCI_VENDOR_ID_ASUSTEK, 0x1942, 1},
      90             :         /* Intel 82852/82855 host bridge / Mobility 9600/9700 Needs AGPMode 1 (deb #510208) */
      91             :         { PCI_VENDOR_ID_INTEL, 0x3580, PCI_VENDOR_ID_ATI, 0x4e50,
      92             :                 0x10cf, 0x127f, 1},
      93             :         /* ASRock K7VT4A+ AGP 8x / ATI Radeon 9250 AGP Needs AGPMode 4 (lp #133192) */
      94             :         { 0x1849, 0x3189, PCI_VENDOR_ID_ATI, 0x5960,
      95             :                 0x1787, 0x5960, 4},
      96             :         /* VIA K8M800 Host Bridge / RV280 [Radeon 9200 PRO] Needs AGPMode 4 (fdo #12544) */
      97             :         { PCI_VENDOR_ID_VIA, 0x0204, PCI_VENDOR_ID_ATI, 0x5960,
      98             :                 0x17af, 0x2020, 4},
      99             :         /* VIA KT880 Host Bridge / RV350 [Radeon 9550] Needs AGPMode 4 (fdo #19981) */
     100             :         { PCI_VENDOR_ID_VIA, 0x0269, PCI_VENDOR_ID_ATI, 0x4153,
     101             :                 PCI_VENDOR_ID_ASUSTEK, 0x003c, 4},
     102             :         /* VIA VT8363 Host Bridge / R200 QL [Radeon 8500] Needs AGPMode 2 (lp #141551) */
     103             :         { PCI_VENDOR_ID_VIA, 0x0305, PCI_VENDOR_ID_ATI, 0x514c,
     104             :                 PCI_VENDOR_ID_ATI, 0x013a, 2},
     105             :         /* VIA VT82C693A Host Bridge / RV280 [Radeon 9200 PRO] Needs AGPMode 2 (deb #515512) */
     106             :         { PCI_VENDOR_ID_VIA, 0x0691, PCI_VENDOR_ID_ATI, 0x5960,
     107             :                 PCI_VENDOR_ID_ASUSTEK, 0x004c, 2},
     108             :         /* VIA VT82C693A Host Bridge / RV280 [Radeon 9200 PRO] Needs AGPMode 2 */
     109             :         { PCI_VENDOR_ID_VIA, 0x0691, PCI_VENDOR_ID_ATI, 0x5960,
     110             :                 PCI_VENDOR_ID_ASUSTEK, 0x0054, 2},
     111             :         /* VIA VT8377 Host Bridge / R200 QM [Radeon 9100] Needs AGPMode 4 (deb #461144) */
     112             :         { PCI_VENDOR_ID_VIA, 0x3189, PCI_VENDOR_ID_ATI, 0x514d,
     113             :                 0x174b, 0x7149, 4},
     114             :         /* VIA VT8377 Host Bridge / RV280 [Radeon 9200 PRO] Needs AGPMode 4 (lp #312693) */
     115             :         { PCI_VENDOR_ID_VIA, 0x3189, PCI_VENDOR_ID_ATI, 0x5960,
     116             :                 0x1462, 0x0380, 4},
     117             :         /* VIA VT8377 Host Bridge / RV280 Needs AGPMode 4 (ati ML) */
     118             :         { PCI_VENDOR_ID_VIA, 0x3189, PCI_VENDOR_ID_ATI, 0x5964,
     119             :                 0x148c, 0x2073, 4},
     120             :         /* ATI Host Bridge / RV280 [M9+] Needs AGPMode 1 (phoronix forum) */
     121             :         { PCI_VENDOR_ID_ATI, 0xcbb2, PCI_VENDOR_ID_ATI, 0x5c61,
     122             :                 PCI_VENDOR_ID_SONY, 0x8175, 1},
     123             :         { 0, 0, 0, 0, 0, 0, 0 },
     124             : };
     125             : #endif
     126             : 
     127           0 : int radeon_agp_init(struct radeon_device *rdev)
     128             : {
     129             : #if __OS_HAS_AGP
     130             :         struct radeon_agpmode_quirk *p = radeon_agpmode_quirk_list;
     131             :         struct drm_agp_mode mode;
     132           0 :         struct drm_agp_info info;
     133             :         paddr_t start, end;
     134             :         uint32_t agp_status;
     135             :         int default_mode;
     136             :         bool is_v3;
     137             :         int ret;
     138             : 
     139             :         /* Acquire AGP. */
     140           0 :         ret = drm_agp_acquire(rdev->ddev);
     141           0 :         if (ret) {
     142           0 :                 DRM_ERROR("Unable to acquire AGP: %d\n", ret);
     143           0 :                 return ret;
     144             :         }
     145             : 
     146           0 :         ret = drm_agp_info(rdev->ddev, &info);
     147           0 :         if (ret) {
     148           0 :                 drm_agp_release(rdev->ddev);
     149           0 :                 DRM_ERROR("Unable to get AGP info: %d\n", ret);
     150           0 :                 return ret;
     151             :         }
     152             : 
     153           0 :         if ((rdev->ddev->agp->info.ai_aperture_size >> 20) < 32) {
     154           0 :                 drm_agp_release(rdev->ddev);
     155           0 :                 dev_warn(rdev->dev, "AGP aperture too small (%zuM) "
     156             :                         "need at least 32M, disabling AGP\n",
     157             :                         rdev->ddev->agp->info.ai_aperture_size >> 20);
     158           0 :                 return -EINVAL;
     159             :         }
     160             : 
     161           0 :         mode.mode = info.mode;
     162             :         /* chips with the agp to pcie bridge don't have the AGP_STATUS register
     163             :          * Just use the whatever mode the host sets up.
     164             :          */
     165           0 :         if (rdev->family <= CHIP_RV350)
     166           0 :                 agp_status = (RREG32(RADEON_AGP_STATUS) | RADEON_AGPv3_MODE) & mode.mode;
     167             :         else
     168           0 :                 agp_status = mode.mode;
     169           0 :         is_v3 = !!(agp_status & RADEON_AGPv3_MODE);
     170             : 
     171           0 :         if (is_v3) {
     172           0 :                 default_mode = (agp_status & RADEON_AGPv3_8X_MODE) ? 8 : 4;
     173           0 :         } else {
     174           0 :                 if (agp_status & RADEON_AGP_4X_MODE) {
     175             :                         default_mode = 4;
     176           0 :                 } else if (agp_status & RADEON_AGP_2X_MODE) {
     177             :                         default_mode = 2;
     178           0 :                 } else {
     179             :                         default_mode = 1;
     180             :                 }
     181             :         }
     182             : 
     183             :         /* Apply AGPMode Quirks */
     184           0 :         while (p && p->chip_device != 0) {
     185           0 :                 if (info.id_vendor == p->hostbridge_vendor &&
     186           0 :                     info.id_device == p->hostbridge_device &&
     187           0 :                     rdev->pdev->vendor == p->chip_vendor &&
     188           0 :                     rdev->pdev->device == p->chip_device &&
     189           0 :                     rdev->pdev->subsystem_vendor == p->subsys_vendor &&
     190           0 :                     rdev->pdev->subsystem_device == p->subsys_device) {
     191           0 :                         default_mode = p->default_mode;
     192           0 :                 }
     193           0 :                 ++p;
     194             :         }
     195             : 
     196           0 :         if (radeon_agpmode > 0) {
     197           0 :                 if ((radeon_agpmode < (is_v3 ? 4 : 1)) ||
     198           0 :                     (radeon_agpmode > (is_v3 ? 8 : 4)) ||
     199           0 :                     (radeon_agpmode & (radeon_agpmode - 1))) {
     200           0 :                         DRM_ERROR("Illegal AGP Mode: %d (valid %s), leaving at %d\n",
     201             :                                   radeon_agpmode, is_v3 ? "4, 8" : "1, 2, 4",
     202             :                                   default_mode);
     203           0 :                         radeon_agpmode = default_mode;
     204           0 :                 } else {
     205             :                         DRM_INFO("AGP mode requested: %d\n", radeon_agpmode);
     206             :                 }
     207             :         } else {
     208           0 :                 radeon_agpmode = default_mode;
     209             :         }
     210             : 
     211           0 :         mode.mode &= ~RADEON_AGP_MODE_MASK;
     212           0 :         if (is_v3) {
     213           0 :                 switch (radeon_agpmode) {
     214             :                 case 8:
     215           0 :                         mode.mode |= RADEON_AGPv3_8X_MODE;
     216           0 :                         break;
     217             :                 case 4:
     218             :                 default:
     219           0 :                         mode.mode |= RADEON_AGPv3_4X_MODE;
     220           0 :                         break;
     221             :                 }
     222             :         } else {
     223           0 :                 switch (radeon_agpmode) {
     224             :                 case 4:
     225           0 :                         mode.mode |= RADEON_AGP_4X_MODE;
     226           0 :                         break;
     227             :                 case 2:
     228           0 :                         mode.mode |= RADEON_AGP_2X_MODE;
     229           0 :                         break;
     230             :                 case 1:
     231             :                 default:
     232           0 :                         mode.mode |= RADEON_AGP_1X_MODE;
     233           0 :                         break;
     234             :                 }
     235             :         }
     236             : 
     237           0 :         mode.mode &= ~RADEON_AGP_FW_MODE; /* disable fw */
     238           0 :         ret = drm_agp_enable(rdev->ddev, mode);
     239           0 :         if (ret) {
     240           0 :                 DRM_ERROR("Unable to enable AGP (mode = 0x%lx)\n", mode.mode);
     241           0 :                 drm_agp_release(rdev->ddev);
     242           0 :                 return ret;
     243             :         }
     244             : 
     245           0 :         rdev->mc.agp_base = rdev->ddev->agp->info.ai_aperture_base;
     246           0 :         rdev->mc.gtt_size = rdev->ddev->agp->info.ai_aperture_size;
     247           0 :         rdev->mc.gtt_start = rdev->mc.agp_base;
     248           0 :         rdev->mc.gtt_end = rdev->mc.gtt_start + rdev->mc.gtt_size - 1;
     249             :         dev_info(rdev->dev, "GTT: %lluM 0x%08llX - 0x%08llX\n",
     250             :                 rdev->mc.gtt_size >> 20, rdev->mc.gtt_start, rdev->mc.gtt_end);
     251             : 
     252           0 :         if (!rdev->ddev->agp->cant_use_aperture) {
     253           0 :                 start = atop(bus_space_mmap(rdev->memt, rdev->mc.gtt_start, 0, 0, 0));
     254           0 :                 end = start + atop(rdev->mc.gtt_size);
     255           0 :                 uvm_page_physload(start, end, start, end, PHYSLOAD_DEVICE);
     256           0 :         }
     257             : 
     258             :         /* workaround some hw issues */
     259           0 :         if (rdev->family < CHIP_R200) {
     260           0 :                 WREG32(RADEON_AGP_CNTL, RREG32(RADEON_AGP_CNTL) | 0x000e0000);
     261           0 :         }
     262           0 :         return 0;
     263             : #else
     264             :         return 0;
     265             : #endif
     266           0 : }
     267             : 
     268           0 : void radeon_agp_resume(struct radeon_device *rdev)
     269             : {
     270             : #if __OS_HAS_AGP
     271             :         int r;
     272           0 :         if (rdev->flags & RADEON_IS_AGP) {
     273           0 :                 r = radeon_agp_init(rdev);
     274           0 :                 if (r)
     275           0 :                         dev_warn(rdev->dev, "radeon AGP reinit failed\n");
     276             :         }
     277             : #endif
     278           0 : }
     279             : 
     280           0 : void radeon_agp_fini(struct radeon_device *rdev)
     281             : {
     282             : #if __OS_HAS_AGP
     283           0 :         if (rdev->ddev->agp && rdev->ddev->agp->acquired) {
     284           0 :                 drm_agp_release(rdev->ddev);
     285           0 :         }
     286             : #endif
     287           0 : }
     288             : 
     289           0 : void radeon_agp_suspend(struct radeon_device *rdev)
     290             : {
     291           0 :         radeon_agp_fini(rdev);
     292           0 : }

Generated by: LCOV version 1.13