This source file includes following definitions.
- nvkm_agp_fini
- nvkm_agp_preinit
- nvkm_agp_init
- nvkm_agp_dtor
- nvkm_agp_ctor
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 #include "agp.h"
23 #ifdef __NVKM_PCI_AGP_H__
24 #include <core/option.h>
25
26 struct nvkm_device_agp_quirk {
27 u16 hostbridge_vendor;
28 u16 hostbridge_device;
29 u16 chip_vendor;
30 u16 chip_device;
31 int mode;
32 };
33
34 static const struct nvkm_device_agp_quirk
35 nvkm_device_agp_quirks[] = {
36
37 { PCI_VENDOR_ID_VIA, 0x0691, PCI_VENDOR_ID_NVIDIA, 0x0311, 2 },
38
39 { PCI_VENDOR_ID_SI, 0x0761, PCI_ANY_ID, PCI_ANY_ID, 0 },
40 {},
41 };
42
43 void
44 nvkm_agp_fini(struct nvkm_pci *pci)
45 {
46 if (pci->agp.acquired) {
47 agp_backend_release(pci->agp.bridge);
48 pci->agp.acquired = false;
49 }
50 }
51
52
53
54
55 void
56 nvkm_agp_preinit(struct nvkm_pci *pci)
57 {
58 struct nvkm_device *device = pci->subdev.device;
59 u32 mode = nvkm_pci_rd32(pci, 0x004c);
60 u32 save[2];
61
62
63
64
65
66 if ((mode | pci->agp.mode) & PCI_AGP_COMMAND_FW) {
67 mode = pci->agp.mode & ~PCI_AGP_COMMAND_FW;
68 agp_enable(pci->agp.bridge, mode);
69 }
70
71
72 save[0] = nvkm_pci_rd32(pci, 0x0004);
73 nvkm_pci_wr32(pci, 0x0004, save[0] & ~0x00000004);
74 nvkm_pci_wr32(pci, 0x004c, 0x00000000);
75
76
77 save[1] = nvkm_mask(device, 0x000200, 0x00011100, 0x00000000);
78 nvkm_mask(device, 0x000200, 0x00011100, save[1]);
79
80
81 nvkm_pci_wr32(pci, 0x0004, save[0]);
82 }
83
84 int
85 nvkm_agp_init(struct nvkm_pci *pci)
86 {
87 if (!agp_backend_acquire(pci->pdev)) {
88 nvkm_error(&pci->subdev, "failed to acquire agp\n");
89 return -ENODEV;
90 }
91
92 agp_enable(pci->agp.bridge, pci->agp.mode);
93 pci->agp.acquired = true;
94 return 0;
95 }
96
97 void
98 nvkm_agp_dtor(struct nvkm_pci *pci)
99 {
100 arch_phys_wc_del(pci->agp.mtrr);
101 }
102
103 void
104 nvkm_agp_ctor(struct nvkm_pci *pci)
105 {
106 const struct nvkm_device_agp_quirk *quirk = nvkm_device_agp_quirks;
107 struct nvkm_subdev *subdev = &pci->subdev;
108 struct nvkm_device *device = subdev->device;
109 struct agp_kern_info info;
110 int mode = -1;
111
112 #ifdef __powerpc__
113
114
115
116
117
118
119
120 mode = 0;
121 #endif
122 mode = nvkm_longopt(device->cfgopt, "NvAGP", mode);
123
124
125 if (!(pci->agp.bridge = agp_backend_acquire(pci->pdev))) {
126 nvkm_warn(subdev, "failed to acquire agp\n");
127 return;
128 }
129 agp_copy_info(pci->agp.bridge, &info);
130 agp_backend_release(pci->agp.bridge);
131
132 pci->agp.mode = info.mode;
133 pci->agp.base = info.aper_base;
134 pci->agp.size = info.aper_size * 1024 * 1024;
135 pci->agp.cma = info.cant_use_aperture;
136 pci->agp.mtrr = -1;
137
138
139 while (quirk->hostbridge_vendor) {
140 if (info.device->vendor == quirk->hostbridge_vendor &&
141 info.device->device == quirk->hostbridge_device &&
142 (quirk->chip_vendor == (u16)PCI_ANY_ID ||
143 pci->pdev->vendor == quirk->chip_vendor) &&
144 (quirk->chip_device == (u16)PCI_ANY_ID ||
145 pci->pdev->device == quirk->chip_device)) {
146 nvkm_info(subdev, "forcing default agp mode to %dX, "
147 "use NvAGP=<mode> to override\n",
148 quirk->mode);
149 mode = quirk->mode;
150 break;
151 }
152 quirk++;
153 }
154
155
156 if (mode >= 1) {
157 if (pci->agp.mode & 0x00000008)
158 mode /= 4;
159 pci->agp.mode &= ~0x00000007;
160 pci->agp.mode |= (mode & 0x7);
161 } else
162 if (mode == 0) {
163 pci->agp.bridge = NULL;
164 return;
165 }
166
167
168
169
170 if (device->chipset == 0x18)
171 pci->agp.mode &= ~PCI_AGP_COMMAND_FW;
172
173 pci->agp.mtrr = arch_phys_wc_add(pci->agp.base, pci->agp.size);
174 }
175 #endif