aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjorn Helgaas <bhelgaas@google.com>2018-05-02 13:50:55 -0400
committerBjorn Helgaas <helgaas@kernel.org>2018-05-10 17:48:09 -0400
commit780473508ace12fa58fb50339d3899c055ec4cad (patch)
treeb892a052492adc787a9711b19a1e6c0b97ed4550
parent60cc43fc888428bb2f18f08997432d426a243338 (diff)
PCI: Reorder quirks infrastructure code
The infrastructure that applies PCI quirks was buried in the middle of the quirks themselves (at one time it was probably at the end of the file, but new quirks tend to be added at the end of the file). Move it all to the top of the file so it's easy to find. No functional change intended. Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
-rw-r--r--drivers/pci/quirks.c314
1 files changed, 156 insertions, 158 deletions
diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c
index 2990ad1e7c99..0f2b117cc59c 100644
--- a/drivers/pci/quirks.c
+++ b/drivers/pci/quirks.c
@@ -30,6 +30,162 @@
30#include <asm/dma.h> /* isa_dma_bridge_buggy */ 30#include <asm/dma.h> /* isa_dma_bridge_buggy */
31#include "pci.h" 31#include "pci.h"
32 32
33static ktime_t fixup_debug_start(struct pci_dev *dev,
34 void (*fn)(struct pci_dev *dev))
35{
36 if (initcall_debug)
37 pci_info(dev, "calling %pF @ %i\n", fn, task_pid_nr(current));
38
39 return ktime_get();
40}
41
42static void fixup_debug_report(struct pci_dev *dev, ktime_t calltime,
43 void (*fn)(struct pci_dev *dev))
44{
45 ktime_t delta, rettime;
46 unsigned long long duration;
47
48 rettime = ktime_get();
49 delta = ktime_sub(rettime, calltime);
50 duration = (unsigned long long) ktime_to_ns(delta) >> 10;
51 if (initcall_debug || duration > 10000)
52 pci_info(dev, "%pF took %lld usecs\n", fn, duration);
53}
54
55static void pci_do_fixups(struct pci_dev *dev, struct pci_fixup *f,
56 struct pci_fixup *end)
57{
58 ktime_t calltime;
59
60 for (; f < end; f++)
61 if ((f->class == (u32) (dev->class >> f->class_shift) ||
62 f->class == (u32) PCI_ANY_ID) &&
63 (f->vendor == dev->vendor ||
64 f->vendor == (u16) PCI_ANY_ID) &&
65 (f->device == dev->device ||
66 f->device == (u16) PCI_ANY_ID)) {
67 calltime = fixup_debug_start(dev, f->hook);
68 f->hook(dev);
69 fixup_debug_report(dev, calltime, f->hook);
70 }
71}
72
73extern struct pci_fixup __start_pci_fixups_early[];
74extern struct pci_fixup __end_pci_fixups_early[];
75extern struct pci_fixup __start_pci_fixups_header[];
76extern struct pci_fixup __end_pci_fixups_header[];
77extern struct pci_fixup __start_pci_fixups_final[];
78extern struct pci_fixup __end_pci_fixups_final[];
79extern struct pci_fixup __start_pci_fixups_enable[];
80extern struct pci_fixup __end_pci_fixups_enable[];
81extern struct pci_fixup __start_pci_fixups_resume[];
82extern struct pci_fixup __end_pci_fixups_resume[];
83extern struct pci_fixup __start_pci_fixups_resume_early[];
84extern struct pci_fixup __end_pci_fixups_resume_early[];
85extern struct pci_fixup __start_pci_fixups_suspend[];
86extern struct pci_fixup __end_pci_fixups_suspend[];
87extern struct pci_fixup __start_pci_fixups_suspend_late[];
88extern struct pci_fixup __end_pci_fixups_suspend_late[];
89
90static bool pci_apply_fixup_final_quirks;
91
92void pci_fixup_device(enum pci_fixup_pass pass, struct pci_dev *dev)
93{
94 struct pci_fixup *start, *end;
95
96 switch (pass) {
97 case pci_fixup_early:
98 start = __start_pci_fixups_early;
99 end = __end_pci_fixups_early;
100 break;
101
102 case pci_fixup_header:
103 start = __start_pci_fixups_header;
104 end = __end_pci_fixups_header;
105 break;
106
107 case pci_fixup_final:
108 if (!pci_apply_fixup_final_quirks)
109 return;
110 start = __start_pci_fixups_final;
111 end = __end_pci_fixups_final;
112 break;
113
114 case pci_fixup_enable:
115 start = __start_pci_fixups_enable;
116 end = __end_pci_fixups_enable;
117 break;
118
119 case pci_fixup_resume:
120 start = __start_pci_fixups_resume;
121 end = __end_pci_fixups_resume;
122 break;
123
124 case pci_fixup_resume_early:
125 start = __start_pci_fixups_resume_early;
126 end = __end_pci_fixups_resume_early;
127 break;
128
129 case pci_fixup_suspend:
130 start = __start_pci_fixups_suspend;
131 end = __end_pci_fixups_suspend;
132 break;
133
134 case pci_fixup_suspend_late:
135 start = __start_pci_fixups_suspend_late;
136 end = __end_pci_fixups_suspend_late;
137 break;
138
139 default:
140 /* stupid compiler warning, you would think with an enum... */
141 return;
142 }
143 pci_do_fixups(dev, start, end);
144}
145EXPORT_SYMBOL(pci_fixup_device);
146
147static int __init pci_apply_final_quirks(void)
148{
149 struct pci_dev *dev = NULL;
150 u8 cls = 0;
151 u8 tmp;
152
153 if (pci_cache_line_size)
154 printk(KERN_DEBUG "PCI: CLS %u bytes\n",
155 pci_cache_line_size << 2);
156
157 pci_apply_fixup_final_quirks = true;
158 for_each_pci_dev(dev) {
159 pci_fixup_device(pci_fixup_final, dev);
160 /*
161 * If arch hasn't set it explicitly yet, use the CLS
162 * value shared by all PCI devices. If there's a
163 * mismatch, fall back to the default value.
164 */
165 if (!pci_cache_line_size) {
166 pci_read_config_byte(dev, PCI_CACHE_LINE_SIZE, &tmp);
167 if (!cls)
168 cls = tmp;
169 if (!tmp || cls == tmp)
170 continue;
171
172 printk(KERN_DEBUG "PCI: CLS mismatch (%u != %u), using %u bytes\n",
173 cls << 2, tmp << 2,
174 pci_dfl_cache_line_size << 2);
175 pci_cache_line_size = pci_dfl_cache_line_size;
176 }
177 }
178
179 if (!pci_cache_line_size) {
180 printk(KERN_DEBUG "PCI: CLS %u bytes, default %u\n",
181 cls << 2, pci_dfl_cache_line_size << 2);
182 pci_cache_line_size = cls ? cls : pci_dfl_cache_line_size;
183 }
184
185 return 0;
186}
187fs_initcall_sync(pci_apply_final_quirks);
188
33/* 189/*
34 * Decoding should be disabled for a PCI device during BAR sizing to avoid 190 * Decoding should be disabled for a PCI device during BAR sizing to avoid
35 * conflict. But doing so may cause problems on host bridge and perhaps other 191 * conflict. But doing so may cause problems on host bridge and perhaps other
@@ -2981,28 +3137,6 @@ static void quirk_intel_ntb(struct pci_dev *dev)
2981DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x0e08, quirk_intel_ntb); 3137DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x0e08, quirk_intel_ntb);
2982DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x0e0d, quirk_intel_ntb); 3138DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x0e0d, quirk_intel_ntb);
2983 3139
2984static ktime_t fixup_debug_start(struct pci_dev *dev,
2985 void (*fn)(struct pci_dev *dev))
2986{
2987 if (initcall_debug)
2988 pci_info(dev, "calling %pF @ %i\n", fn, task_pid_nr(current));
2989
2990 return ktime_get();
2991}
2992
2993static void fixup_debug_report(struct pci_dev *dev, ktime_t calltime,
2994 void (*fn)(struct pci_dev *dev))
2995{
2996 ktime_t delta, rettime;
2997 unsigned long long duration;
2998
2999 rettime = ktime_get();
3000 delta = ktime_sub(rettime, calltime);
3001 duration = (unsigned long long) ktime_to_ns(delta) >> 10;
3002 if (initcall_debug || duration > 10000)
3003 pci_info(dev, "%pF took %lld usecs\n", fn, duration);
3004}
3005
3006/* 3140/*
3007 * Some BIOS implementations leave the Intel GPU interrupts enabled, 3141 * Some BIOS implementations leave the Intel GPU interrupts enabled,
3008 * even though no one is handling them (f.e. i915 driver is never loaded). 3142 * even though no one is handling them (f.e. i915 driver is never loaded).
@@ -3397,142 +3531,6 @@ DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_INTEL,
3397 quirk_apple_wait_for_thunderbolt); 3531 quirk_apple_wait_for_thunderbolt);
3398#endif 3532#endif
3399 3533
3400static void pci_do_fixups(struct pci_dev *dev, struct pci_fixup *f,
3401 struct pci_fixup *end)
3402{
3403 ktime_t calltime;
3404
3405 for (; f < end; f++)
3406 if ((f->class == (u32) (dev->class >> f->class_shift) ||
3407 f->class == (u32) PCI_ANY_ID) &&
3408 (f->vendor == dev->vendor ||
3409 f->vendor == (u16) PCI_ANY_ID) &&
3410 (f->device == dev->device ||
3411 f->device == (u16) PCI_ANY_ID)) {
3412 calltime = fixup_debug_start(dev, f->hook);
3413 f->hook(dev);
3414 fixup_debug_report(dev, calltime, f->hook);
3415 }
3416}
3417
3418extern struct pci_fixup __start_pci_fixups_early[];
3419extern struct pci_fixup __end_pci_fixups_early[];
3420extern struct pci_fixup __start_pci_fixups_header[];
3421extern struct pci_fixup __end_pci_fixups_header[];
3422extern struct pci_fixup __start_pci_fixups_final[];
3423extern struct pci_fixup __end_pci_fixups_final[];
3424extern struct pci_fixup __start_pci_fixups_enable[];
3425extern struct pci_fixup __end_pci_fixups_enable[];
3426extern struct pci_fixup __start_pci_fixups_resume[];
3427extern struct pci_fixup __end_pci_fixups_resume[];
3428extern struct pci_fixup __start_pci_fixups_resume_early[];
3429extern struct pci_fixup __end_pci_fixups_resume_early[];
3430extern struct pci_fixup __start_pci_fixups_suspend[];
3431extern struct pci_fixup __end_pci_fixups_suspend[];
3432extern struct pci_fixup __start_pci_fixups_suspend_late[];
3433extern struct pci_fixup __end_pci_fixups_suspend_late[];
3434
3435static bool pci_apply_fixup_final_quirks;
3436
3437void pci_fixup_device(enum pci_fixup_pass pass, struct pci_dev *dev)
3438{
3439 struct pci_fixup *start, *end;
3440
3441 switch (pass) {
3442 case pci_fixup_early:
3443 start = __start_pci_fixups_early;
3444 end = __end_pci_fixups_early;
3445 break;
3446
3447 case pci_fixup_header:
3448 start = __start_pci_fixups_header;
3449 end = __end_pci_fixups_header;
3450 break;
3451
3452 case pci_fixup_final:
3453 if (!pci_apply_fixup_final_quirks)
3454 return;
3455 start = __start_pci_fixups_final;
3456 end = __end_pci_fixups_final;
3457 break;
3458
3459 case pci_fixup_enable:
3460 start = __start_pci_fixups_enable;
3461 end = __end_pci_fixups_enable;
3462 break;
3463
3464 case pci_fixup_resume:
3465 start = __start_pci_fixups_resume;
3466 end = __end_pci_fixups_resume;
3467 break;
3468
3469 case pci_fixup_resume_early:
3470 start = __start_pci_fixups_resume_early;
3471 end = __end_pci_fixups_resume_early;
3472 break;
3473
3474 case pci_fixup_suspend:
3475 start = __start_pci_fixups_suspend;
3476 end = __end_pci_fixups_suspend;
3477 break;
3478
3479 case pci_fixup_suspend_late:
3480 start = __start_pci_fixups_suspend_late;
3481 end = __end_pci_fixups_suspend_late;
3482 break;
3483
3484 default:
3485 /* stupid compiler warning, you would think with an enum... */
3486 return;
3487 }
3488 pci_do_fixups(dev, start, end);
3489}
3490EXPORT_SYMBOL(pci_fixup_device);
3491
3492
3493static int __init pci_apply_final_quirks(void)
3494{
3495 struct pci_dev *dev = NULL;
3496 u8 cls = 0;
3497 u8 tmp;
3498
3499 if (pci_cache_line_size)
3500 printk(KERN_DEBUG "PCI: CLS %u bytes\n",
3501 pci_cache_line_size << 2);
3502
3503 pci_apply_fixup_final_quirks = true;
3504 for_each_pci_dev(dev) {
3505 pci_fixup_device(pci_fixup_final, dev);
3506 /*
3507 * If arch hasn't set it explicitly yet, use the CLS
3508 * value shared by all PCI devices. If there's a
3509 * mismatch, fall back to the default value.
3510 */
3511 if (!pci_cache_line_size) {
3512 pci_read_config_byte(dev, PCI_CACHE_LINE_SIZE, &tmp);
3513 if (!cls)
3514 cls = tmp;
3515 if (!tmp || cls == tmp)
3516 continue;
3517
3518 printk(KERN_DEBUG "PCI: CLS mismatch (%u != %u), using %u bytes\n",
3519 cls << 2, tmp << 2,
3520 pci_dfl_cache_line_size << 2);
3521 pci_cache_line_size = pci_dfl_cache_line_size;
3522 }
3523 }
3524
3525 if (!pci_cache_line_size) {
3526 printk(KERN_DEBUG "PCI: CLS %u bytes, default %u\n",
3527 cls << 2, pci_dfl_cache_line_size << 2);
3528 pci_cache_line_size = cls ? cls : pci_dfl_cache_line_size;
3529 }
3530
3531 return 0;
3532}
3533
3534fs_initcall_sync(pci_apply_final_quirks);
3535
3536/* 3534/*
3537 * Following are device-specific reset methods which can be used to 3535 * Following are device-specific reset methods which can be used to
3538 * reset a single function if other methods (e.g. FLR, PM D0->D3) are 3536 * reset a single function if other methods (e.g. FLR, PM D0->D3) are