1 #include <linux/module.h>
3 #include "nouveau_drm.h"
4 #include "nouveau_agp.h"
5 #include "nouveau_reg.h"
8 MODULE_PARM_DESC(agpmode, "AGP mode (0 to disable AGP)");
9 static int nouveau_agpmode = -1;
10 module_param_named(agpmode, nouveau_agpmode, int, 0400);
12 struct nouveau_agpmode_quirk {
13 u16 hostbridge_vendor;
14 u16 hostbridge_device;
20 static struct nouveau_agpmode_quirk nouveau_agpmode_quirk_list[] = {
21 /* VIA Apollo PRO133x / GeForce FX 5600 Ultra, max agpmode 2, fdo #20341 */
22 { PCI_VENDOR_ID_VIA, 0x0691, PCI_VENDOR_ID_NVIDIA, 0x0311, 2 },
28 get_agp_mode(struct nouveau_drm *drm, const struct drm_agp_info *info)
30 struct nvif_device *device = &drm->device;
31 struct nouveau_agpmode_quirk *quirk = nouveau_agpmode_quirk_list;
32 int agpmode = nouveau_agpmode;
33 unsigned long mode = info->mode;
36 * FW seems to be broken on nv18, it makes the card lock up
39 if (device->info.chipset == 0x18)
40 mode &= ~PCI_AGP_COMMAND_FW;
43 * Go through the quirks list and adjust the agpmode accordingly.
45 while (agpmode == -1 && quirk->hostbridge_vendor) {
46 if (info->id_vendor == quirk->hostbridge_vendor &&
47 info->id_device == quirk->hostbridge_device &&
48 nvxx_device(device)->pdev->vendor == quirk->chip_vendor &&
49 nvxx_device(device)->pdev->device == quirk->chip_device) {
50 agpmode = quirk->mode;
51 NV_INFO(drm, "Forcing agp mode to %dX. Use agpmode to override.\n",
59 * AGP mode set in the command line.
62 bool agpv3 = mode & 0x8;
63 int rate = agpv3 ? agpmode / 4 : agpmode;
65 mode = (mode & ~0x7) | (rate & 0x7);
72 nouveau_agp_enabled(struct nouveau_drm *drm)
74 struct drm_device *dev = drm->dev;
76 if (!dev->pdev || !drm_pci_device_is_agp(dev) || !dev->agp)
79 if (drm->agp.stat == UNKNOWN) {
83 /* Disable AGP by default on all PowerPC machines for
84 * now -- At least some UniNorth-2 AGP bridges are
85 * known to be broken: DMA from the host to the card
86 * works just fine, but writeback from the card to the
87 * host goes straight to memory untranslated bypassing
88 * the GATT somehow, making them quite painful to deal
91 if (nouveau_agpmode == -1)
97 return (drm->agp.stat == ENABLED);
102 nouveau_agp_reset(struct nouveau_drm *drm)
105 struct nvif_device *device = &drm->device;
106 struct drm_device *dev = drm->dev;
110 if (!nouveau_agp_enabled(drm))
113 /* First of all, disable fast writes, otherwise if it's
114 * already enabled in the AGP bridge and we disable the card's
115 * AGP controller we might be locking ourselves out of it. */
116 if ((nvif_rd32(device, NV04_PBUS_PCI_NV_19) |
117 dev->agp->mode) & PCI_AGP_COMMAND_FW) {
118 struct drm_agp_info info;
119 struct drm_agp_mode mode;
121 ret = drm_agp_info(dev, &info);
125 mode.mode = get_agp_mode(drm, &info);
126 mode.mode &= ~PCI_AGP_COMMAND_FW;
128 ret = drm_agp_enable(dev, mode);
134 /* clear busmaster bit, and disable AGP */
135 save[0] = nvif_mask(device, NV04_PBUS_PCI_NV_1, 0x00000004, 0x00000000);
136 nvif_wr32(device, NV04_PBUS_PCI_NV_19, 0);
138 /* reset PGRAPH, PFIFO and PTIMER */
139 save[1] = nvif_mask(device, 0x000200, 0x00011100, 0x00000000);
140 nvif_mask(device, 0x000200, 0x00011100, save[1]);
142 /* and restore bustmaster bit (gives effect of resetting AGP) */
143 nvif_wr32(device, NV04_PBUS_PCI_NV_1, save[0]);
148 nouveau_agp_init(struct nouveau_drm *drm)
151 struct drm_device *dev = drm->dev;
152 struct drm_agp_info info;
153 struct drm_agp_mode mode;
156 if (!nouveau_agp_enabled(drm))
158 drm->agp.stat = DISABLE;
160 ret = drm_agp_acquire(dev);
162 NV_ERROR(drm, "unable to acquire AGP: %d\n", ret);
166 ret = drm_agp_info(dev, &info);
168 NV_ERROR(drm, "unable to get AGP info: %d\n", ret);
172 /* see agp.h for the AGPSTAT_* modes available */
173 mode.mode = get_agp_mode(drm, &info);
175 ret = drm_agp_enable(dev, mode);
177 NV_ERROR(drm, "unable to enable AGP: %d\n", ret);
181 drm->agp.stat = ENABLED;
182 drm->agp.base = info.aperture_base;
183 drm->agp.size = info.aperture_size;
188 nouveau_agp_fini(struct nouveau_drm *drm)
191 struct drm_device *dev = drm->dev;
192 if (dev->agp && dev->agp->acquired)
193 drm_agp_release(dev);