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 | |
| 14 | static unsigned long |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 15 | get_agp_mode(struct nouveau_drm *drm, unsigned long mode) |
Ben Skeggs | aa4cc5d2 | 2012-07-05 21:36:32 +1000 | [diff] [blame] | 16 | { |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 17 | struct nouveau_device *device = nv_device(drm->device); |
Ben Skeggs | aa4cc5d2 | 2012-07-05 21:36:32 +1000 | [diff] [blame] | 18 | |
| 19 | /* |
| 20 | * FW seems to be broken on nv18, it makes the card lock up |
| 21 | * randomly. |
| 22 | */ |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 23 | if (device->chipset == 0x18) |
Ben Skeggs | aa4cc5d2 | 2012-07-05 21:36:32 +1000 | [diff] [blame] | 24 | mode &= ~PCI_AGP_COMMAND_FW; |
| 25 | |
| 26 | /* |
| 27 | * AGP mode set in the command line. |
| 28 | */ |
| 29 | if (nouveau_agpmode > 0) { |
| 30 | bool agpv3 = mode & 0x8; |
| 31 | int rate = agpv3 ? nouveau_agpmode / 4 : nouveau_agpmode; |
| 32 | |
| 33 | mode = (mode & ~0x7) | (rate & 0x7); |
| 34 | } |
| 35 | |
| 36 | return mode; |
| 37 | } |
| 38 | |
| 39 | static bool |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 40 | nouveau_agp_enabled(struct nouveau_drm *drm) |
Ben Skeggs | aa4cc5d2 | 2012-07-05 21:36:32 +1000 | [diff] [blame] | 41 | { |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 42 | struct drm_device *dev = drm->dev; |
Ben Skeggs | aa4cc5d2 | 2012-07-05 21:36:32 +1000 | [diff] [blame] | 43 | |
| 44 | if (!drm_pci_device_is_agp(dev) || !dev->agp) |
| 45 | return false; |
| 46 | |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 47 | if (drm->agp.stat == UNKNOWN) { |
Ben Skeggs | aa4cc5d2 | 2012-07-05 21:36:32 +1000 | [diff] [blame] | 48 | if (!nouveau_agpmode) |
| 49 | return false; |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 50 | return true; |
Ben Skeggs | aa4cc5d2 | 2012-07-05 21:36:32 +1000 | [diff] [blame] | 51 | } |
| 52 | |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 53 | return (drm->agp.stat == ENABLED); |
Ben Skeggs | aa4cc5d2 | 2012-07-05 21:36:32 +1000 | [diff] [blame] | 54 | } |
| 55 | #endif |
| 56 | |
| 57 | void |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 58 | nouveau_agp_reset(struct nouveau_drm *drm) |
Ben Skeggs | aa4cc5d2 | 2012-07-05 21:36:32 +1000 | [diff] [blame] | 59 | { |
| 60 | #if __OS_HAS_AGP |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 61 | struct nouveau_device *device = nv_device(drm->device); |
| 62 | struct drm_device *dev = drm->dev; |
Ben Skeggs | aa4cc5d2 | 2012-07-05 21:36:32 +1000 | [diff] [blame] | 63 | u32 save[2]; |
| 64 | int ret; |
| 65 | |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 66 | if (!nouveau_agp_enabled(drm)) |
Ben Skeggs | aa4cc5d2 | 2012-07-05 21:36:32 +1000 | [diff] [blame] | 67 | return; |
| 68 | |
| 69 | /* First of all, disable fast writes, otherwise if it's |
| 70 | * already enabled in the AGP bridge and we disable the card's |
| 71 | * AGP controller we might be locking ourselves out of it. */ |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 72 | if ((nv_rd32(device, NV04_PBUS_PCI_NV_19) | |
Ben Skeggs | aa4cc5d2 | 2012-07-05 21:36:32 +1000 | [diff] [blame] | 73 | dev->agp->mode) & PCI_AGP_COMMAND_FW) { |
| 74 | struct drm_agp_info info; |
| 75 | struct drm_agp_mode mode; |
| 76 | |
| 77 | ret = drm_agp_info(dev, &info); |
| 78 | if (ret) |
| 79 | return; |
| 80 | |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 81 | mode.mode = get_agp_mode(drm, info.mode); |
Ben Skeggs | aa4cc5d2 | 2012-07-05 21:36:32 +1000 | [diff] [blame] | 82 | mode.mode &= ~PCI_AGP_COMMAND_FW; |
| 83 | |
| 84 | ret = drm_agp_enable(dev, mode); |
| 85 | if (ret) |
| 86 | return; |
| 87 | } |
| 88 | |
| 89 | |
| 90 | /* clear busmaster bit, and disable AGP */ |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 91 | save[0] = nv_mask(device, NV04_PBUS_PCI_NV_1, 0x00000004, 0x00000000); |
| 92 | nv_wr32(device, NV04_PBUS_PCI_NV_19, 0); |
Ben Skeggs | aa4cc5d2 | 2012-07-05 21:36:32 +1000 | [diff] [blame] | 93 | |
| 94 | /* reset PGRAPH, PFIFO and PTIMER */ |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 95 | save[1] = nv_mask(device, 0x000200, 0x00011100, 0x00000000); |
| 96 | nv_mask(device, 0x000200, 0x00011100, save[1]); |
Ben Skeggs | aa4cc5d2 | 2012-07-05 21:36:32 +1000 | [diff] [blame] | 97 | |
| 98 | /* and restore bustmaster bit (gives effect of resetting AGP) */ |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 99 | nv_wr32(device, NV04_PBUS_PCI_NV_1, save[0]); |
Ben Skeggs | aa4cc5d2 | 2012-07-05 21:36:32 +1000 | [diff] [blame] | 100 | #endif |
| 101 | } |
| 102 | |
| 103 | void |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 104 | nouveau_agp_init(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 | struct drm_agp_info info; |
| 110 | struct drm_agp_mode mode; |
| 111 | int ret; |
| 112 | |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 113 | if (!nouveau_agp_enabled(drm)) |
Ben Skeggs | aa4cc5d2 | 2012-07-05 21:36:32 +1000 | [diff] [blame] | 114 | return; |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 115 | drm->agp.stat = DISABLE; |
Ben Skeggs | aa4cc5d2 | 2012-07-05 21:36:32 +1000 | [diff] [blame] | 116 | |
| 117 | ret = drm_agp_acquire(dev); |
| 118 | if (ret) { |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 119 | nv_error(device, "unable to acquire AGP: %d\n", ret); |
Ben Skeggs | aa4cc5d2 | 2012-07-05 21:36:32 +1000 | [diff] [blame] | 120 | return; |
| 121 | } |
| 122 | |
| 123 | ret = drm_agp_info(dev, &info); |
| 124 | if (ret) { |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 125 | nv_error(device, "unable to get AGP info: %d\n", ret); |
Ben Skeggs | aa4cc5d2 | 2012-07-05 21:36:32 +1000 | [diff] [blame] | 126 | return; |
| 127 | } |
| 128 | |
| 129 | /* see agp.h for the AGPSTAT_* modes available */ |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 130 | mode.mode = get_agp_mode(drm, info.mode); |
Ben Skeggs | aa4cc5d2 | 2012-07-05 21:36:32 +1000 | [diff] [blame] | 131 | |
| 132 | ret = drm_agp_enable(dev, mode); |
| 133 | if (ret) { |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 134 | nv_error(device, "unable to enable AGP: %d\n", ret); |
Ben Skeggs | aa4cc5d2 | 2012-07-05 21:36:32 +1000 | [diff] [blame] | 135 | return; |
| 136 | } |
| 137 | |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 138 | drm->agp.stat = ENABLED; |
| 139 | drm->agp.base = info.aperture_base; |
| 140 | drm->agp.size = info.aperture_size; |
Ben Skeggs | aa4cc5d2 | 2012-07-05 21:36:32 +1000 | [diff] [blame] | 141 | #endif |
| 142 | } |
| 143 | |
| 144 | void |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 145 | nouveau_agp_fini(struct nouveau_drm *drm) |
Ben Skeggs | aa4cc5d2 | 2012-07-05 21:36:32 +1000 | [diff] [blame] | 146 | { |
| 147 | #if __OS_HAS_AGP |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 148 | struct drm_device *dev = drm->dev; |
Ben Skeggs | aa4cc5d2 | 2012-07-05 21:36:32 +1000 | [diff] [blame] | 149 | if (dev->agp && dev->agp->acquired) |
| 150 | drm_agp_release(dev); |
| 151 | #endif |
| 152 | } |