support for platform devices
[deliverable/linux.git] / drivers / gpu / drm / nouveau / nouveau_agp.c
1 #include <linux/module.h>
2
3 #include <core/device.h>
4
5 #include "nouveau_drm.h"
6 #include "nouveau_agp.h"
7 #include "nouveau_reg.h"
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 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
29 static unsigned long
30 get_agp_mode(struct nouveau_drm *drm, const struct drm_agp_info *info)
31 {
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;
36
37 /*
38 * FW seems to be broken on nv18, it makes the card lock up
39 * randomly.
40 */
41 if (device->chipset == 0x18)
42 mode &= ~PCI_AGP_COMMAND_FW;
43
44 /*
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 /*
61 * AGP mode set in the command line.
62 */
63 if (agpmode > 0) {
64 bool agpv3 = mode & 0x8;
65 int rate = agpv3 ? agpmode / 4 : agpmode;
66
67 mode = (mode & ~0x7) | (rate & 0x7);
68 }
69
70 return mode;
71 }
72
73 static bool
74 nouveau_agp_enabled(struct nouveau_drm *drm)
75 {
76 struct drm_device *dev = drm->dev;
77
78 if (!dev->pdev || !drm_pci_device_is_agp(dev) || !dev->agp)
79 return false;
80
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...
92 */
93 if (nouveau_agpmode == -1)
94 return false;
95 #endif
96 return true;
97 }
98
99 return (drm->agp.stat == ENABLED);
100 }
101 #endif
102
103 void
104 nouveau_agp_reset(struct nouveau_drm *drm)
105 {
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;
111
112 if (!nouveau_agp_enabled(drm))
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. */
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;
122
123 ret = drm_agp_info(dev, &info);
124 if (ret)
125 return;
126
127 mode.mode = get_agp_mode(drm, &info);
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 */
137 save[0] = nv_mask(device, NV04_PBUS_PCI_NV_1, 0x00000004, 0x00000000);
138 nv_wr32(device, NV04_PBUS_PCI_NV_19, 0);
139
140 /* reset PGRAPH, PFIFO and PTIMER */
141 save[1] = nv_mask(device, 0x000200, 0x00011100, 0x00000000);
142 nv_mask(device, 0x000200, 0x00011100, save[1]);
143
144 /* and restore bustmaster bit (gives effect of resetting AGP) */
145 nv_wr32(device, NV04_PBUS_PCI_NV_1, save[0]);
146 #endif
147 }
148
149 void
150 nouveau_agp_init(struct nouveau_drm *drm)
151 {
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;
158
159 if (!nouveau_agp_enabled(drm))
160 return;
161 drm->agp.stat = DISABLE;
162
163 ret = drm_agp_acquire(dev);
164 if (ret) {
165 nv_error(device, "unable to acquire AGP: %d\n", ret);
166 return;
167 }
168
169 ret = drm_agp_info(dev, &info);
170 if (ret) {
171 nv_error(device, "unable to get AGP info: %d\n", ret);
172 return;
173 }
174
175 /* see agp.h for the AGPSTAT_* modes available */
176 mode.mode = get_agp_mode(drm, &info);
177
178 ret = drm_agp_enable(dev, mode);
179 if (ret) {
180 nv_error(device, "unable to enable AGP: %d\n", ret);
181 return;
182 }
183
184 drm->agp.stat = ENABLED;
185 drm->agp.base = info.aperture_base;
186 drm->agp.size = info.aperture_size;
187 #endif
188 }
189
190 void
191 nouveau_agp_fini(struct nouveau_drm *drm)
192 {
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
198 }
This page took 0.035331 seconds and 5 git commands to generate.