Merge git://git.kernel.org/pub/scm/linux/kernel/git/rusty/linux-2.6-for-linus
[linux-2.6] / arch / x86 / kernel / quirks.c
1 /*
2  * This file contains work-arounds for x86 and x86_64 platform bugs.
3  */
4 #include <linux/pci.h>
5 #include <linux/irq.h>
6
7 #include <asm/hpet.h>
8
9 #if defined(CONFIG_X86_IO_APIC) && defined(CONFIG_SMP) && defined(CONFIG_PCI)
10
11 static void __devinit quirk_intel_irqbalance(struct pci_dev *dev)
12 {
13         u8 config, rev;
14         u32 word;
15
16         /* BIOS may enable hardware IRQ balancing for
17          * E7520/E7320/E7525(revision ID 0x9 and below)
18          * based platforms.
19          * Disable SW irqbalance/affinity on those platforms.
20          */
21         pci_read_config_byte(dev, PCI_CLASS_REVISION, &rev);
22         if (rev > 0x9)
23                 return;
24
25         /* enable access to config space*/
26         pci_read_config_byte(dev, 0xf4, &config);
27         pci_write_config_byte(dev, 0xf4, config|0x2);
28
29         /* read xTPR register */
30         raw_pci_ops->read(0, 0, 0x40, 0x4c, 2, &word);
31
32         if (!(word & (1 << 13))) {
33                 printk(KERN_INFO "Intel E7520/7320/7525 detected. "
34                         "Disabling irq balancing and affinity\n");
35 #ifdef CONFIG_IRQBALANCE
36                 irqbalance_disable("");
37 #endif
38                 noirqdebug_setup("");
39 #ifdef CONFIG_PROC_FS
40                 no_irq_affinity = 1;
41 #endif
42         }
43
44         /* put back the original value for config space*/
45         if (!(config & 0x2))
46                 pci_write_config_byte(dev, 0xf4, config);
47 }
48 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_E7320_MCH,
49                         quirk_intel_irqbalance);
50 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_E7525_MCH,
51                         quirk_intel_irqbalance);
52 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_E7520_MCH,
53                         quirk_intel_irqbalance);
54 #endif
55
56 #if defined(CONFIG_HPET_TIMER)
57 unsigned long force_hpet_address;
58
59 static enum {
60         NONE_FORCE_HPET_RESUME,
61         OLD_ICH_FORCE_HPET_RESUME,
62         ICH_FORCE_HPET_RESUME,
63         VT8237_FORCE_HPET_RESUME,
64         NVIDIA_FORCE_HPET_RESUME,
65 } force_hpet_resume_type;
66
67 static void __iomem *rcba_base;
68
69 static void ich_force_hpet_resume(void)
70 {
71         u32 val;
72
73         if (!force_hpet_address)
74                 return;
75
76         if (rcba_base == NULL)
77                 BUG();
78
79         /* read the Function Disable register, dword mode only */
80         val = readl(rcba_base + 0x3404);
81         if (!(val & 0x80)) {
82                 /* HPET disabled in HPTC. Trying to enable */
83                 writel(val | 0x80, rcba_base + 0x3404);
84         }
85
86         val = readl(rcba_base + 0x3404);
87         if (!(val & 0x80))
88                 BUG();
89         else
90                 printk(KERN_DEBUG "Force enabled HPET at resume\n");
91
92         return;
93 }
94
95 static void ich_force_enable_hpet(struct pci_dev *dev)
96 {
97         u32 val;
98         u32 uninitialized_var(rcba);
99         int err = 0;
100
101         if (hpet_address || force_hpet_address)
102                 return;
103
104         pci_read_config_dword(dev, 0xF0, &rcba);
105         rcba &= 0xFFFFC000;
106         if (rcba == 0) {
107                 printk(KERN_DEBUG "RCBA disabled. Cannot force enable HPET\n");
108                 return;
109         }
110
111         /* use bits 31:14, 16 kB aligned */
112         rcba_base = ioremap_nocache(rcba, 0x4000);
113         if (rcba_base == NULL) {
114                 printk(KERN_DEBUG "ioremap failed. Cannot force enable HPET\n");
115                 return;
116         }
117
118         /* read the Function Disable register, dword mode only */
119         val = readl(rcba_base + 0x3404);
120
121         if (val & 0x80) {
122                 /* HPET is enabled in HPTC. Just not reported by BIOS */
123                 val = val & 0x3;
124                 force_hpet_address = 0xFED00000 | (val << 12);
125                 printk(KERN_DEBUG "Force enabled HPET at base address 0x%lx\n",
126                                force_hpet_address);
127                 iounmap(rcba_base);
128                 return;
129         }
130
131         /* HPET disabled in HPTC. Trying to enable */
132         writel(val | 0x80, rcba_base + 0x3404);
133
134         val = readl(rcba_base + 0x3404);
135         if (!(val & 0x80)) {
136                 err = 1;
137         } else {
138                 val = val & 0x3;
139                 force_hpet_address = 0xFED00000 | (val << 12);
140         }
141
142         if (err) {
143                 force_hpet_address = 0;
144                 iounmap(rcba_base);
145                 printk(KERN_DEBUG "Failed to force enable HPET\n");
146         } else {
147                 force_hpet_resume_type = ICH_FORCE_HPET_RESUME;
148                 printk(KERN_DEBUG "Force enabled HPET at base address 0x%lx\n",
149                                force_hpet_address);
150         }
151 }
152
153 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ESB2_0,
154                          ich_force_enable_hpet);
155 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_1,
156                          ich_force_enable_hpet);
157 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH7_0,
158                          ich_force_enable_hpet);
159 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH7_1,
160                          ich_force_enable_hpet);
161 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH7_31,
162                          ich_force_enable_hpet);
163 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH8_1,
164                          ich_force_enable_hpet);
165 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH9_7,
166                          ich_force_enable_hpet);
167
168
169 static struct pci_dev *cached_dev;
170
171 static void old_ich_force_hpet_resume(void)
172 {
173         u32 val;
174         u32 uninitialized_var(gen_cntl);
175
176         if (!force_hpet_address || !cached_dev)
177                 return;
178
179         pci_read_config_dword(cached_dev, 0xD0, &gen_cntl);
180         gen_cntl &= (~(0x7 << 15));
181         gen_cntl |= (0x4 << 15);
182
183         pci_write_config_dword(cached_dev, 0xD0, gen_cntl);
184         pci_read_config_dword(cached_dev, 0xD0, &gen_cntl);
185         val = gen_cntl >> 15;
186         val &= 0x7;
187         if (val == 0x4)
188                 printk(KERN_DEBUG "Force enabled HPET at resume\n");
189         else
190                 BUG();
191 }
192
193 static void old_ich_force_enable_hpet(struct pci_dev *dev)
194 {
195         u32 val;
196         u32 uninitialized_var(gen_cntl);
197
198         if (hpet_address || force_hpet_address)
199                 return;
200
201         pci_read_config_dword(dev, 0xD0, &gen_cntl);
202         /*
203          * Bit 17 is HPET enable bit.
204          * Bit 16:15 control the HPET base address.
205          */
206         val = gen_cntl >> 15;
207         val &= 0x7;
208         if (val & 0x4) {
209                 val &= 0x3;
210                 force_hpet_address = 0xFED00000 | (val << 12);
211                 printk(KERN_DEBUG "HPET at base address 0x%lx\n",
212                                force_hpet_address);
213                 return;
214         }
215
216         /*
217          * HPET is disabled. Trying enabling at FED00000 and check
218          * whether it sticks
219          */
220         gen_cntl &= (~(0x7 << 15));
221         gen_cntl |= (0x4 << 15);
222         pci_write_config_dword(dev, 0xD0, gen_cntl);
223
224         pci_read_config_dword(dev, 0xD0, &gen_cntl);
225
226         val = gen_cntl >> 15;
227         val &= 0x7;
228         if (val & 0x4) {
229                 /* HPET is enabled in HPTC. Just not reported by BIOS */
230                 val &= 0x3;
231                 force_hpet_address = 0xFED00000 | (val << 12);
232                 printk(KERN_DEBUG "Force enabled HPET at base address 0x%lx\n",
233                                force_hpet_address);
234                 cached_dev = dev;
235                 force_hpet_resume_type = OLD_ICH_FORCE_HPET_RESUME;
236                 return;
237         }
238
239         printk(KERN_DEBUG "Failed to force enable HPET\n");
240 }
241
242 /*
243  * Undocumented chipset features. Make sure that the user enforced
244  * this.
245  */
246 static void old_ich_force_enable_hpet_user(struct pci_dev *dev)
247 {
248         if (hpet_force_user)
249                 old_ich_force_enable_hpet(dev);
250 }
251
252 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_0,
253                          old_ich_force_enable_hpet_user);
254 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_12,
255                          old_ich_force_enable_hpet_user);
256 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_0,
257                          old_ich_force_enable_hpet_user);
258 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_12,
259                          old_ich_force_enable_hpet_user);
260 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_0,
261                          old_ich_force_enable_hpet);
262 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_12,
263                          old_ich_force_enable_hpet);
264
265
266 static void vt8237_force_hpet_resume(void)
267 {
268         u32 val;
269
270         if (!force_hpet_address || !cached_dev)
271                 return;
272
273         val = 0xfed00000 | 0x80;
274         pci_write_config_dword(cached_dev, 0x68, val);
275
276         pci_read_config_dword(cached_dev, 0x68, &val);
277         if (val & 0x80)
278                 printk(KERN_DEBUG "Force enabled HPET at resume\n");
279         else
280                 BUG();
281 }
282
283 static void vt8237_force_enable_hpet(struct pci_dev *dev)
284 {
285         u32 uninitialized_var(val);
286
287         if (!hpet_force_user || hpet_address || force_hpet_address)
288                 return;
289
290         pci_read_config_dword(dev, 0x68, &val);
291         /*
292          * Bit 7 is HPET enable bit.
293          * Bit 31:10 is HPET base address (contrary to what datasheet claims)
294          */
295         if (val & 0x80) {
296                 force_hpet_address = (val & ~0x3ff);
297                 printk(KERN_DEBUG "HPET at base address 0x%lx\n",
298                                force_hpet_address);
299                 return;
300         }
301
302         /*
303          * HPET is disabled. Trying enabling at FED00000 and check
304          * whether it sticks
305          */
306         val = 0xfed00000 | 0x80;
307         pci_write_config_dword(dev, 0x68, val);
308
309         pci_read_config_dword(dev, 0x68, &val);
310         if (val & 0x80) {
311                 force_hpet_address = (val & ~0x3ff);
312                 printk(KERN_DEBUG "Force enabled HPET at base address 0x%lx\n",
313                                force_hpet_address);
314                 cached_dev = dev;
315                 force_hpet_resume_type = VT8237_FORCE_HPET_RESUME;
316                 return;
317         }
318
319         printk(KERN_DEBUG "Failed to force enable HPET\n");
320 }
321
322 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8235,
323                          vt8237_force_enable_hpet);
324 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237,
325                          vt8237_force_enable_hpet);
326
327 /*
328  * Undocumented chipset feature taken from LinuxBIOS.
329  */
330 static void nvidia_force_hpet_resume(void)
331 {
332         pci_write_config_dword(cached_dev, 0x44, 0xfed00001);
333         printk(KERN_DEBUG "Force enabled HPET at resume\n");
334 }
335
336 static void nvidia_force_enable_hpet(struct pci_dev *dev)
337 {
338         u32 uninitialized_var(val);
339
340         if (!hpet_force_user || hpet_address || force_hpet_address)
341                 return;
342
343         pci_write_config_dword(dev, 0x44, 0xfed00001);
344         pci_read_config_dword(dev, 0x44, &val);
345         force_hpet_address = val & 0xfffffffe;
346         force_hpet_resume_type = NVIDIA_FORCE_HPET_RESUME;
347         printk(KERN_DEBUG "Force enabled HPET at base address 0x%lx\n",
348                 force_hpet_address);
349         cached_dev = dev;
350         return;
351 }
352
353 /* ISA Bridges */
354 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_NVIDIA, 0x0050,
355                         nvidia_force_enable_hpet);
356 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_NVIDIA, 0x0051,
357                         nvidia_force_enable_hpet);
358
359 /* LPC bridges */
360 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_NVIDIA, 0x0360,
361                         nvidia_force_enable_hpet);
362 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_NVIDIA, 0x0361,
363                         nvidia_force_enable_hpet);
364 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_NVIDIA, 0x0362,
365                         nvidia_force_enable_hpet);
366 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_NVIDIA, 0x0363,
367                         nvidia_force_enable_hpet);
368 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_NVIDIA, 0x0364,
369                         nvidia_force_enable_hpet);
370 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_NVIDIA, 0x0365,
371                         nvidia_force_enable_hpet);
372 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_NVIDIA, 0x0366,
373                         nvidia_force_enable_hpet);
374 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_NVIDIA, 0x0367,
375                         nvidia_force_enable_hpet);
376
377 void force_hpet_resume(void)
378 {
379         switch (force_hpet_resume_type) {
380             case ICH_FORCE_HPET_RESUME:
381                 return ich_force_hpet_resume();
382
383             case OLD_ICH_FORCE_HPET_RESUME:
384                 return old_ich_force_hpet_resume();
385
386             case VT8237_FORCE_HPET_RESUME:
387                 return vt8237_force_hpet_resume();
388
389             case NVIDIA_FORCE_HPET_RESUME:
390                 return nvidia_force_hpet_resume();
391
392             default:
393                 break;
394         }
395 }
396
397 #endif