1 #include <linux/module.h>
3 #include <core/device.h>
5 #include "nouveau_drm.h"
6 #include "nouveau_agp.h"
7 #include "nouveau_reg.h"
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);
15 get_agp_mode(struct nouveau_drm *drm, unsigned long mode)
17 struct nouveau_device *device = nv_device(drm->device);
20 * FW seems to be broken on nv18, it makes the card lock up
23 if (device->chipset == 0x18)
24 mode &= ~PCI_AGP_COMMAND_FW;
27 * AGP mode set in the command line.
29 if (nouveau_agpmode > 0) {
30 bool agpv3 = mode & 0x8;
31 int rate = agpv3 ? nouveau_agpmode / 4 : nouveau_agpmode;
33 mode = (mode & ~0x7) | (rate & 0x7);
40 nouveau_agp_enabled(struct nouveau_drm *drm)
42 struct drm_device *dev = drm->dev;
44 if (!drm_pci_device_is_agp(dev) || !dev->agp)
47 if (drm->agp.stat == UNKNOWN) {
53 return (drm->agp.stat == ENABLED);
58 nouveau_agp_reset(struct nouveau_drm *drm)
61 struct nouveau_device *device = nv_device(drm->device);
62 struct drm_device *dev = drm->dev;
66 if (!nouveau_agp_enabled(drm))
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. */
72 if ((nv_rd32(device, NV04_PBUS_PCI_NV_19) |
73 dev->agp->mode) & PCI_AGP_COMMAND_FW) {
74 struct drm_agp_info info;
75 struct drm_agp_mode mode;
77 ret = drm_agp_info(dev, &info);
81 mode.mode = get_agp_mode(drm, info.mode);
82 mode.mode &= ~PCI_AGP_COMMAND_FW;
84 ret = drm_agp_enable(dev, mode);
90 /* clear busmaster bit, and disable AGP */
91 save[0] = nv_mask(device, NV04_PBUS_PCI_NV_1, 0x00000004, 0x00000000);
92 nv_wr32(device, NV04_PBUS_PCI_NV_19, 0);
94 /* reset PGRAPH, PFIFO and PTIMER */
95 save[1] = nv_mask(device, 0x000200, 0x00011100, 0x00000000);
96 nv_mask(device, 0x000200, 0x00011100, save[1]);
98 /* and restore bustmaster bit (gives effect of resetting AGP) */
99 nv_wr32(device, NV04_PBUS_PCI_NV_1, save[0]);
104 nouveau_agp_init(struct nouveau_drm *drm)
107 struct nouveau_device *device = nv_device(drm->device);
108 struct drm_device *dev = drm->dev;
109 struct drm_agp_info info;
110 struct drm_agp_mode mode;
113 if (!nouveau_agp_enabled(drm))
115 drm->agp.stat = DISABLE;
117 ret = drm_agp_acquire(dev);
119 nv_error(device, "unable to acquire AGP: %d\n", ret);
123 ret = drm_agp_info(dev, &info);
125 nv_error(device, "unable to get AGP info: %d\n", ret);
129 /* see agp.h for the AGPSTAT_* modes available */
130 mode.mode = get_agp_mode(drm, info.mode);
132 ret = drm_agp_enable(dev, mode);
134 nv_error(device, "unable to enable AGP: %d\n", ret);
138 drm->agp.stat = ENABLED;
139 drm->agp.base = info.aperture_base;
140 drm->agp.size = info.aperture_size;
145 nouveau_agp_fini(struct nouveau_drm *drm)
148 struct drm_device *dev = drm->dev;
149 if (dev->agp && dev->agp->acquired)
150 drm_agp_release(dev);