PM / sleep: Asynchronous threads for suspend_noirq
[linux/fpc-iii.git] / drivers / gpu / drm / nouveau / nouveau_agp.c
blob2953c4e91e1ae9fea8fff60501dfa863d56c63ea
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"
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);
14 struct nouveau_agpmode_quirk {
15 u16 hostbridge_vendor;
16 u16 hostbridge_device;
17 u16 chip_vendor;
18 u16 chip_device;
19 int mode;
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 },
26 {},
29 static unsigned long
30 get_agp_mode(struct nouveau_drm *drm, const struct drm_agp_info *info)
32 struct nouveau_device *device = nv_device(drm->device);
33 struct nouveau_agpmode_quirk *quirk = nouveau_agpmode_quirk_list;
34 int agpmode = nouveau_agpmode;
35 unsigned long mode = info->mode;
38 * FW seems to be broken on nv18, it makes the card lock up
39 * randomly.
41 if (device->chipset == 0x18)
42 mode &= ~PCI_AGP_COMMAND_FW;
45 * Go through the quirks list and adjust the agpmode accordingly.
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;
57 ++quirk;
61 * AGP mode set in the command line.
63 if (agpmode > 0) {
64 bool agpv3 = mode & 0x8;
65 int rate = agpv3 ? agpmode / 4 : agpmode;
67 mode = (mode & ~0x7) | (rate & 0x7);
70 return mode;
73 static bool
74 nouveau_agp_enabled(struct nouveau_drm *drm)
76 struct drm_device *dev = drm->dev;
78 if (!drm_pci_device_is_agp(dev) || !dev->agp)
79 return false;
81 if (drm->agp.stat == UNKNOWN) {
82 if (!nouveau_agpmode)
83 return false;
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...
93 if (nouveau_agpmode == -1)
94 return false;
95 #endif
96 return true;
99 return (drm->agp.stat == ENABLED);
101 #endif
103 void
104 nouveau_agp_reset(struct nouveau_drm *drm)
106 #if __OS_HAS_AGP
107 struct nouveau_device *device = nv_device(drm->device);
108 struct drm_device *dev = drm->dev;
109 u32 save[2];
110 int ret;
112 if (!nouveau_agp_enabled(drm))
113 return;
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. */
118 if ((nv_rd32(device, NV04_PBUS_PCI_NV_19) |
119 dev->agp->mode) & PCI_AGP_COMMAND_FW) {
120 struct drm_agp_info info;
121 struct drm_agp_mode mode;
123 ret = drm_agp_info(dev, &info);
124 if (ret)
125 return;
127 mode.mode = get_agp_mode(drm, &info);
128 mode.mode &= ~PCI_AGP_COMMAND_FW;
130 ret = drm_agp_enable(dev, mode);
131 if (ret)
132 return;
136 /* clear busmaster bit, and disable AGP */
137 save[0] = nv_mask(device, NV04_PBUS_PCI_NV_1, 0x00000004, 0x00000000);
138 nv_wr32(device, NV04_PBUS_PCI_NV_19, 0);
140 /* reset PGRAPH, PFIFO and PTIMER */
141 save[1] = nv_mask(device, 0x000200, 0x00011100, 0x00000000);
142 nv_mask(device, 0x000200, 0x00011100, save[1]);
144 /* and restore bustmaster bit (gives effect of resetting AGP) */
145 nv_wr32(device, NV04_PBUS_PCI_NV_1, save[0]);
146 #endif
149 void
150 nouveau_agp_init(struct nouveau_drm *drm)
152 #if __OS_HAS_AGP
153 struct nouveau_device *device = nv_device(drm->device);
154 struct drm_device *dev = drm->dev;
155 struct drm_agp_info info;
156 struct drm_agp_mode mode;
157 int ret;
159 if (!nouveau_agp_enabled(drm))
160 return;
161 drm->agp.stat = DISABLE;
163 ret = drm_agp_acquire(dev);
164 if (ret) {
165 nv_error(device, "unable to acquire AGP: %d\n", ret);
166 return;
169 ret = drm_agp_info(dev, &info);
170 if (ret) {
171 nv_error(device, "unable to get AGP info: %d\n", ret);
172 return;
175 /* see agp.h for the AGPSTAT_* modes available */
176 mode.mode = get_agp_mode(drm, &info);
178 ret = drm_agp_enable(dev, mode);
179 if (ret) {
180 nv_error(device, "unable to enable AGP: %d\n", ret);
181 return;
184 drm->agp.stat = ENABLED;
185 drm->agp.base = info.aperture_base;
186 drm->agp.size = info.aperture_size;
187 #endif
190 void
191 nouveau_agp_fini(struct nouveau_drm *drm)
193 #if __OS_HAS_AGP
194 struct drm_device *dev = drm->dev;
195 if (dev->agp && dev->agp->acquired)
196 drm_agp_release(dev);
197 #endif