Ben Skeggs | aa4cc5d2 | 2012-07-05 21:36:32 +1000 | [diff] [blame] | 1 | #include <linux/module.h> |
| 2 | |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 3 | #include <core/device.h> |
Ben Skeggs | aa4cc5d2 | 2012-07-05 21:36:32 +1000 | [diff] [blame] | 4 | |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 5 | #include "nouveau_drm.h" |
Ben Skeggs | aa4cc5d2 | 2012-07-05 21:36:32 +1000 | [diff] [blame] | 6 | #include "nouveau_agp.h" |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 7 | #include "nouveau_reg.h" |
Ben Skeggs | aa4cc5d2 | 2012-07-05 21:36:32 +1000 | [diff] [blame] | 8 | |
| 9 | #if __OS_HAS_AGP |
| 10 | MODULE_PARM_DESC(agpmode, "AGP mode (0 to disable AGP)"); |
| 11 | static int nouveau_agpmode = -1; |
| 12 | module_param_named(agpmode, nouveau_agpmode, int, 0400); |
| 13 | |
Ilia Mirkin | fd34381b | 2013-10-27 11:54:09 -0400 | [diff] [blame] | 14 | struct nouveau_agpmode_quirk { |
| 15 | u16 hostbridge_vendor; |
| 16 | u16 hostbridge_device; |
| 17 | u16 chip_vendor; |
| 18 | u16 chip_device; |
| 19 | int mode; |
| 20 | }; |
| 21 | |
| 22 | static struct nouveau_agpmode_quirk nouveau_agpmode_quirk_list[] = { |
| 23 | /* VIA Apollo PRO133x / GeForce FX 5600 Ultra, max agpmode 2, fdo #20341 */ |
| 24 | { PCI_VENDOR_ID_VIA, 0x0691, PCI_VENDOR_ID_NVIDIA, 0x0311, 2 }, |
| 25 | |
| 26 | {}, |
| 27 | }; |
| 28 | |
Ben Skeggs | aa4cc5d2 | 2012-07-05 21:36:32 +1000 | [diff] [blame] | 29 | static unsigned long |
Ilia Mirkin | fd34381b | 2013-10-27 11:54:09 -0400 | [diff] [blame] | 30 | get_agp_mode(struct nouveau_drm *drm, const struct drm_agp_info *info) |
Ben Skeggs | aa4cc5d2 | 2012-07-05 21:36:32 +1000 | [diff] [blame] | 31 | { |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 32 | struct nouveau_device *device = nv_device(drm->device); |
Ilia Mirkin | fd34381b | 2013-10-27 11:54:09 -0400 | [diff] [blame] | 33 | struct nouveau_agpmode_quirk *quirk = nouveau_agpmode_quirk_list; |
| 34 | int agpmode = nouveau_agpmode; |
| 35 | unsigned long mode = info->mode; |
Ben Skeggs | aa4cc5d2 | 2012-07-05 21:36:32 +1000 | [diff] [blame] | 36 | |
| 37 | /* |
| 38 | * FW seems to be broken on nv18, it makes the card lock up |
| 39 | * randomly. |
| 40 | */ |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 41 | if (device->chipset == 0x18) |
Ben Skeggs | aa4cc5d2 | 2012-07-05 21:36:32 +1000 | [diff] [blame] | 42 | mode &= ~PCI_AGP_COMMAND_FW; |
| 43 | |
| 44 | /* |
Ilia Mirkin | fd34381b | 2013-10-27 11:54:09 -0400 | [diff] [blame] | 45 | * Go through the quirks list and adjust the agpmode accordingly. |
| 46 | */ |
| 47 | while (agpmode == -1 && quirk->hostbridge_vendor) { |
| 48 | if (info->id_vendor == quirk->hostbridge_vendor && |
| 49 | info->id_device == quirk->hostbridge_device && |
| 50 | device->pdev->vendor == quirk->chip_vendor && |
| 51 | device->pdev->device == quirk->chip_device) { |
| 52 | agpmode = quirk->mode; |
| 53 | nv_info(device, "Forcing agp mode to %dX. Use agpmode to override.\n", |
| 54 | agpmode); |
| 55 | break; |
| 56 | } |
| 57 | ++quirk; |
| 58 | } |
| 59 | |
| 60 | /* |
Ben Skeggs | aa4cc5d2 | 2012-07-05 21:36:32 +1000 | [diff] [blame] | 61 | * AGP mode set in the command line. |
| 62 | */ |
Ilia Mirkin | fd34381b | 2013-10-27 11:54:09 -0400 | [diff] [blame] | 63 | if (agpmode > 0) { |
Ben Skeggs | aa4cc5d2 | 2012-07-05 21:36:32 +1000 | [diff] [blame] | 64 | bool agpv3 = mode & 0x8; |
Ilia Mirkin | fd34381b | 2013-10-27 11:54:09 -0400 | [diff] [blame] | 65 | int rate = agpv3 ? agpmode / 4 : agpmode; |
Ben Skeggs | aa4cc5d2 | 2012-07-05 21:36:32 +1000 | [diff] [blame] | 66 | |
| 67 | mode = (mode & ~0x7) | (rate & 0x7); |
| 68 | } |
| 69 | |
| 70 | return mode; |
| 71 | } |
| 72 | |
| 73 | static bool |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 74 | nouveau_agp_enabled(struct nouveau_drm *drm) |
Ben Skeggs | aa4cc5d2 | 2012-07-05 21:36:32 +1000 | [diff] [blame] | 75 | { |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 76 | struct drm_device *dev = drm->dev; |
Ben Skeggs | aa4cc5d2 | 2012-07-05 21:36:32 +1000 | [diff] [blame] | 77 | |
Alexandre Courbot | 420b946 | 2014-02-17 15:17:26 +0900 | [diff] [blame] | 78 | if (!dev->pdev || !drm_pci_device_is_agp(dev) || !dev->agp) |
Ben Skeggs | aa4cc5d2 | 2012-07-05 21:36:32 +1000 | [diff] [blame] | 79 | return false; |
| 80 | |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 81 | if (drm->agp.stat == UNKNOWN) { |
Ben Skeggs | aa4cc5d2 | 2012-07-05 21:36:32 +1000 | [diff] [blame] | 82 | if (!nouveau_agpmode) |
| 83 | return false; |
Francisco Jerez | 650e120 | 2013-02-26 02:33:11 +0100 | [diff] [blame] | 84 | #ifdef __powerpc__ |
| 85 | /* Disable AGP by default on all PowerPC machines for |
| 86 | * now -- At least some UniNorth-2 AGP bridges are |
| 87 | * known to be broken: DMA from the host to the card |
| 88 | * works just fine, but writeback from the card to the |
| 89 | * host goes straight to memory untranslated bypassing |
| 90 | * the GATT somehow, making them quite painful to deal |
| 91 | * with... |
| 92 | */ |
| 93 | if (nouveau_agpmode == -1) |
| 94 | return false; |
| 95 | #endif |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 96 | return true; |
Ben Skeggs | aa4cc5d2 | 2012-07-05 21:36:32 +1000 | [diff] [blame] | 97 | } |
| 98 | |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 99 | return (drm->agp.stat == ENABLED); |
Ben Skeggs | aa4cc5d2 | 2012-07-05 21:36:32 +1000 | [diff] [blame] | 100 | } |
| 101 | #endif |
| 102 | |
| 103 | void |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 104 | nouveau_agp_reset(struct nouveau_drm *drm) |
Ben Skeggs | aa4cc5d2 | 2012-07-05 21:36:32 +1000 | [diff] [blame] | 105 | { |
| 106 | #if __OS_HAS_AGP |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 107 | struct nouveau_device *device = nv_device(drm->device); |
| 108 | struct drm_device *dev = drm->dev; |
Ben Skeggs | aa4cc5d2 | 2012-07-05 21:36:32 +1000 | [diff] [blame] | 109 | u32 save[2]; |
| 110 | int ret; |
| 111 | |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 112 | if (!nouveau_agp_enabled(drm)) |
Ben Skeggs | aa4cc5d2 | 2012-07-05 21:36:32 +1000 | [diff] [blame] | 113 | return; |
| 114 | |
| 115 | /* First of all, disable fast writes, otherwise if it's |
| 116 | * already enabled in the AGP bridge and we disable the card's |
| 117 | * AGP controller we might be locking ourselves out of it. */ |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 118 | if ((nv_rd32(device, NV04_PBUS_PCI_NV_19) | |
Ben Skeggs | aa4cc5d2 | 2012-07-05 21:36:32 +1000 | [diff] [blame] | 119 | dev->agp->mode) & PCI_AGP_COMMAND_FW) { |
| 120 | struct drm_agp_info info; |
| 121 | struct drm_agp_mode mode; |
| 122 | |
| 123 | ret = drm_agp_info(dev, &info); |
| 124 | if (ret) |
| 125 | return; |
| 126 | |
Ilia Mirkin | fd34381b | 2013-10-27 11:54:09 -0400 | [diff] [blame] | 127 | mode.mode = get_agp_mode(drm, &info); |
Ben Skeggs | aa4cc5d2 | 2012-07-05 21:36:32 +1000 | [diff] [blame] | 128 | mode.mode &= ~PCI_AGP_COMMAND_FW; |
| 129 | |
| 130 | ret = drm_agp_enable(dev, mode); |
| 131 | if (ret) |
| 132 | return; |
| 133 | } |
| 134 | |
| 135 | |
| 136 | /* clear busmaster bit, and disable AGP */ |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 137 | save[0] = nv_mask(device, NV04_PBUS_PCI_NV_1, 0x00000004, 0x00000000); |
| 138 | nv_wr32(device, NV04_PBUS_PCI_NV_19, 0); |
Ben Skeggs | aa4cc5d2 | 2012-07-05 21:36:32 +1000 | [diff] [blame] | 139 | |
| 140 | /* reset PGRAPH, PFIFO and PTIMER */ |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 141 | save[1] = nv_mask(device, 0x000200, 0x00011100, 0x00000000); |
| 142 | nv_mask(device, 0x000200, 0x00011100, save[1]); |
Ben Skeggs | aa4cc5d2 | 2012-07-05 21:36:32 +1000 | [diff] [blame] | 143 | |
| 144 | /* and restore bustmaster bit (gives effect of resetting AGP) */ |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 145 | nv_wr32(device, NV04_PBUS_PCI_NV_1, save[0]); |
Ben Skeggs | aa4cc5d2 | 2012-07-05 21:36:32 +1000 | [diff] [blame] | 146 | #endif |
| 147 | } |
| 148 | |
| 149 | void |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 150 | nouveau_agp_init(struct nouveau_drm *drm) |
Ben Skeggs | aa4cc5d2 | 2012-07-05 21:36:32 +1000 | [diff] [blame] | 151 | { |
| 152 | #if __OS_HAS_AGP |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 153 | struct nouveau_device *device = nv_device(drm->device); |
| 154 | struct drm_device *dev = drm->dev; |
Ben Skeggs | aa4cc5d2 | 2012-07-05 21:36:32 +1000 | [diff] [blame] | 155 | struct drm_agp_info info; |
| 156 | struct drm_agp_mode mode; |
| 157 | int ret; |
| 158 | |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 159 | if (!nouveau_agp_enabled(drm)) |
Ben Skeggs | aa4cc5d2 | 2012-07-05 21:36:32 +1000 | [diff] [blame] | 160 | return; |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 161 | drm->agp.stat = DISABLE; |
Ben Skeggs | aa4cc5d2 | 2012-07-05 21:36:32 +1000 | [diff] [blame] | 162 | |
| 163 | ret = drm_agp_acquire(dev); |
| 164 | if (ret) { |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 165 | nv_error(device, "unable to acquire AGP: %d\n", ret); |
Ben Skeggs | aa4cc5d2 | 2012-07-05 21:36:32 +1000 | [diff] [blame] | 166 | return; |
| 167 | } |
| 168 | |
| 169 | ret = drm_agp_info(dev, &info); |
| 170 | if (ret) { |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 171 | nv_error(device, "unable to get AGP info: %d\n", ret); |
Ben Skeggs | aa4cc5d2 | 2012-07-05 21:36:32 +1000 | [diff] [blame] | 172 | return; |
| 173 | } |
| 174 | |
| 175 | /* see agp.h for the AGPSTAT_* modes available */ |
Ilia Mirkin | fd34381b | 2013-10-27 11:54:09 -0400 | [diff] [blame] | 176 | mode.mode = get_agp_mode(drm, &info); |
Ben Skeggs | aa4cc5d2 | 2012-07-05 21:36:32 +1000 | [diff] [blame] | 177 | |
| 178 | ret = drm_agp_enable(dev, mode); |
| 179 | if (ret) { |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 180 | nv_error(device, "unable to enable AGP: %d\n", ret); |
Ben Skeggs | aa4cc5d2 | 2012-07-05 21:36:32 +1000 | [diff] [blame] | 181 | return; |
| 182 | } |
| 183 | |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 184 | drm->agp.stat = ENABLED; |
| 185 | drm->agp.base = info.aperture_base; |
| 186 | drm->agp.size = info.aperture_size; |
Ben Skeggs | aa4cc5d2 | 2012-07-05 21:36:32 +1000 | [diff] [blame] | 187 | #endif |
| 188 | } |
| 189 | |
| 190 | void |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 191 | nouveau_agp_fini(struct nouveau_drm *drm) |
Ben Skeggs | aa4cc5d2 | 2012-07-05 21:36:32 +1000 | [diff] [blame] | 192 | { |
| 193 | #if __OS_HAS_AGP |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 194 | struct drm_device *dev = drm->dev; |
Ben Skeggs | aa4cc5d2 | 2012-07-05 21:36:32 +1000 | [diff] [blame] | 195 | if (dev->agp && dev->agp->acquired) |
| 196 | drm_agp_release(dev); |
| 197 | #endif |
| 198 | } |