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);
14 struct nouveau_agpmode_quirk
{
15 u16 hostbridge_vendor
;
16 u16 hostbridge_device
;
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 },
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
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",
61 * AGP mode set in the command line.
64 bool agpv3
= mode
& 0x8;
65 int rate
= agpv3
? agpmode
/ 4 : agpmode
;
67 mode
= (mode
& ~0x7) | (rate
& 0x7);
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
)
81 if (drm
->agp
.stat
== UNKNOWN
) {
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
93 if (nouveau_agpmode
== -1)
99 return (drm
->agp
.stat
== ENABLED
);
104 nouveau_agp_reset(struct nouveau_drm
*drm
)
107 struct nouveau_device
*device
= nv_device(drm
->device
);
108 struct drm_device
*dev
= drm
->dev
;
112 if (!nouveau_agp_enabled(drm
))
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
);
127 mode
.mode
= get_agp_mode(drm
, &info
);
128 mode
.mode
&= ~PCI_AGP_COMMAND_FW
;
130 ret
= drm_agp_enable(dev
, mode
);
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]);
150 nouveau_agp_init(struct nouveau_drm
*drm
)
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
;
159 if (!nouveau_agp_enabled(drm
))
161 drm
->agp
.stat
= DISABLE
;
163 ret
= drm_agp_acquire(dev
);
165 nv_error(device
, "unable to acquire AGP: %d\n", ret
);
169 ret
= drm_agp_info(dev
, &info
);
171 nv_error(device
, "unable to get AGP info: %d\n", ret
);
175 /* see agp.h for the AGPSTAT_* modes available */
176 mode
.mode
= get_agp_mode(drm
, &info
);
178 ret
= drm_agp_enable(dev
, mode
);
180 nv_error(device
, "unable to enable AGP: %d\n", ret
);
184 drm
->agp
.stat
= ENABLED
;
185 drm
->agp
.base
= info
.aperture_base
;
186 drm
->agp
.size
= info
.aperture_size
;
191 nouveau_agp_fini(struct nouveau_drm
*drm
)
194 struct drm_device
*dev
= drm
->dev
;
195 if (dev
->agp
&& dev
->agp
->acquired
)
196 drm_agp_release(dev
);