Commit | Line | Data |
---|---|---|
cd248341 JG |
1 | /* |
2 | * Copyright IBM Corp. 2012 | |
3 | * | |
4 | * Author(s): | |
5 | * Jan Glauber <jang@linux.vnet.ibm.com> | |
6 | * | |
7 | * The System z PCI code is a rewrite from a prototype by | |
8 | * the following people (Kudoz!): | |
bedef755 JG |
9 | * Alexander Schmidt |
10 | * Christoph Raisch | |
11 | * Hannes Hering | |
12 | * Hoang-Nam Nguyen | |
13 | * Jan-Bernd Themann | |
14 | * Stefan Roscher | |
15 | * Thomas Klein | |
cd248341 JG |
16 | */ |
17 | ||
18 | #define COMPONENT "zPCI" | |
19 | #define pr_fmt(fmt) COMPONENT ": " fmt | |
20 | ||
21 | #include <linux/kernel.h> | |
22 | #include <linux/slab.h> | |
23 | #include <linux/err.h> | |
24 | #include <linux/export.h> | |
25 | #include <linux/delay.h> | |
9a4da8a5 JG |
26 | #include <linux/irq.h> |
27 | #include <linux/kernel_stat.h> | |
cd248341 JG |
28 | #include <linux/seq_file.h> |
29 | #include <linux/pci.h> | |
30 | #include <linux/msi.h> | |
31 | ||
9a4da8a5 JG |
32 | #include <asm/isc.h> |
33 | #include <asm/airq.h> | |
cd248341 JG |
34 | #include <asm/facility.h> |
35 | #include <asm/pci_insn.h> | |
a755a45d | 36 | #include <asm/pci_clp.h> |
828b35f6 | 37 | #include <asm/pci_dma.h> |
cd248341 JG |
38 | |
39 | #define DEBUG /* enable pr_debug */ | |
40 | ||
9a4da8a5 JG |
41 | #define SIC_IRQ_MODE_ALL 0 |
42 | #define SIC_IRQ_MODE_SINGLE 1 | |
43 | ||
cd248341 | 44 | #define ZPCI_NR_DMA_SPACES 1 |
9a4da8a5 | 45 | #define ZPCI_MSI_VEC_BITS 6 |
cd248341 JG |
46 | #define ZPCI_NR_DEVICES CONFIG_PCI_NR_FUNCTIONS |
47 | ||
48 | /* list of all detected zpci devices */ | |
49 | LIST_HEAD(zpci_list); | |
7441b062 | 50 | EXPORT_SYMBOL_GPL(zpci_list); |
cd248341 | 51 | DEFINE_MUTEX(zpci_list_lock); |
7441b062 JG |
52 | EXPORT_SYMBOL_GPL(zpci_list_lock); |
53 | ||
53923354 | 54 | static struct pci_hp_callback_ops *hotplug_ops; |
cd248341 JG |
55 | |
56 | static DECLARE_BITMAP(zpci_domain, ZPCI_NR_DEVICES); | |
57 | static DEFINE_SPINLOCK(zpci_domain_lock); | |
58 | ||
9a4da8a5 JG |
59 | struct callback { |
60 | irq_handler_t handler; | |
61 | void *data; | |
62 | }; | |
63 | ||
64 | struct zdev_irq_map { | |
65 | unsigned long aibv; /* AI bit vector */ | |
66 | int msi_vecs; /* consecutive MSI-vectors used */ | |
67 | int __unused; | |
68 | struct callback cb[ZPCI_NR_MSI_VECS]; /* callback handler array */ | |
69 | spinlock_t lock; /* protect callbacks against de-reg */ | |
70 | }; | |
71 | ||
72 | struct intr_bucket { | |
73 | /* amap of adapters, one bit per dev, corresponds to one irq nr */ | |
74 | unsigned long *alloc; | |
75 | /* AI summary bit, global page for all devices */ | |
76 | unsigned long *aisb; | |
77 | /* pointer to aibv and callback data in zdev */ | |
78 | struct zdev_irq_map *imap[ZPCI_NR_DEVICES]; | |
79 | /* protects the whole bucket struct */ | |
80 | spinlock_t lock; | |
81 | }; | |
82 | ||
83 | static struct intr_bucket *bucket; | |
84 | ||
85 | /* Adapter local summary indicator */ | |
86 | static u8 *zpci_irq_si; | |
87 | ||
88 | static atomic_t irq_retries = ATOMIC_INIT(0); | |
89 | ||
cd248341 JG |
90 | /* I/O Map */ |
91 | static DEFINE_SPINLOCK(zpci_iomap_lock); | |
92 | static DECLARE_BITMAP(zpci_iomap, ZPCI_IOMAP_MAX_ENTRIES); | |
93 | struct zpci_iomap_entry *zpci_iomap_start; | |
94 | EXPORT_SYMBOL_GPL(zpci_iomap_start); | |
95 | ||
9a4da8a5 JG |
96 | /* highest irq summary bit */ |
97 | static int __read_mostly aisb_max; | |
98 | ||
99 | static struct kmem_cache *zdev_irq_cache; | |
d0b08853 JG |
100 | static struct kmem_cache *zdev_fmb_cache; |
101 | ||
9a4da8a5 JG |
102 | static inline int irq_to_msi_nr(unsigned int irq) |
103 | { | |
104 | return irq & ZPCI_MSI_MASK; | |
105 | } | |
106 | ||
107 | static inline int irq_to_dev_nr(unsigned int irq) | |
108 | { | |
109 | return irq >> ZPCI_MSI_VEC_BITS; | |
110 | } | |
111 | ||
112 | static inline struct zdev_irq_map *get_imap(unsigned int irq) | |
113 | { | |
114 | return bucket->imap[irq_to_dev_nr(irq)]; | |
115 | } | |
116 | ||
cd248341 JG |
117 | struct zpci_dev *get_zdev(struct pci_dev *pdev) |
118 | { | |
119 | return (struct zpci_dev *) pdev->sysdata; | |
120 | } | |
121 | ||
122 | struct zpci_dev *get_zdev_by_fid(u32 fid) | |
123 | { | |
124 | struct zpci_dev *tmp, *zdev = NULL; | |
125 | ||
126 | mutex_lock(&zpci_list_lock); | |
127 | list_for_each_entry(tmp, &zpci_list, entry) { | |
128 | if (tmp->fid == fid) { | |
129 | zdev = tmp; | |
130 | break; | |
131 | } | |
132 | } | |
133 | mutex_unlock(&zpci_list_lock); | |
134 | return zdev; | |
135 | } | |
136 | ||
137 | bool zpci_fid_present(u32 fid) | |
138 | { | |
139 | return (get_zdev_by_fid(fid) != NULL) ? true : false; | |
140 | } | |
141 | ||
142 | static struct zpci_dev *get_zdev_by_bus(struct pci_bus *bus) | |
143 | { | |
144 | return (bus && bus->sysdata) ? (struct zpci_dev *) bus->sysdata : NULL; | |
145 | } | |
146 | ||
147 | int pci_domain_nr(struct pci_bus *bus) | |
148 | { | |
149 | return ((struct zpci_dev *) bus->sysdata)->domain; | |
150 | } | |
151 | EXPORT_SYMBOL_GPL(pci_domain_nr); | |
152 | ||
153 | int pci_proc_domain(struct pci_bus *bus) | |
154 | { | |
155 | return pci_domain_nr(bus); | |
156 | } | |
157 | EXPORT_SYMBOL_GPL(pci_proc_domain); | |
158 | ||
9a4da8a5 JG |
159 | /* Modify PCI: Register adapter interruptions */ |
160 | static int zpci_register_airq(struct zpci_dev *zdev, unsigned int aisb, | |
161 | u64 aibv) | |
162 | { | |
163 | u64 req = ZPCI_CREATE_REQ(zdev->fh, 0, ZPCI_MOD_FC_REG_INT); | |
164 | struct zpci_fib *fib; | |
165 | int rc; | |
166 | ||
167 | fib = (void *) get_zeroed_page(GFP_KERNEL); | |
168 | if (!fib) | |
169 | return -ENOMEM; | |
170 | ||
171 | fib->isc = PCI_ISC; | |
172 | fib->noi = zdev->irq_map->msi_vecs; | |
173 | fib->sum = 1; /* enable summary notifications */ | |
174 | fib->aibv = aibv; | |
175 | fib->aibvo = 0; /* every function has its own page */ | |
176 | fib->aisb = (u64) bucket->aisb + aisb / 8; | |
177 | fib->aisbo = aisb & ZPCI_MSI_MASK; | |
178 | ||
179 | rc = mpcifc_instr(req, fib); | |
180 | pr_debug("%s mpcifc returned noi: %d\n", __func__, fib->noi); | |
181 | ||
182 | free_page((unsigned long) fib); | |
183 | return rc; | |
184 | } | |
185 | ||
186 | struct mod_pci_args { | |
187 | u64 base; | |
188 | u64 limit; | |
189 | u64 iota; | |
d0b08853 | 190 | u64 fmb_addr; |
9a4da8a5 JG |
191 | }; |
192 | ||
193 | static int mod_pci(struct zpci_dev *zdev, int fn, u8 dmaas, struct mod_pci_args *args) | |
194 | { | |
195 | u64 req = ZPCI_CREATE_REQ(zdev->fh, dmaas, fn); | |
196 | struct zpci_fib *fib; | |
197 | int rc; | |
198 | ||
199 | /* The FIB must be available even if it's not used */ | |
200 | fib = (void *) get_zeroed_page(GFP_KERNEL); | |
201 | if (!fib) | |
202 | return -ENOMEM; | |
203 | ||
204 | fib->pba = args->base; | |
205 | fib->pal = args->limit; | |
206 | fib->iota = args->iota; | |
d0b08853 | 207 | fib->fmb_addr = args->fmb_addr; |
9a4da8a5 JG |
208 | |
209 | rc = mpcifc_instr(req, fib); | |
210 | free_page((unsigned long) fib); | |
211 | return rc; | |
212 | } | |
213 | ||
828b35f6 JG |
214 | /* Modify PCI: Register I/O address translation parameters */ |
215 | int zpci_register_ioat(struct zpci_dev *zdev, u8 dmaas, | |
216 | u64 base, u64 limit, u64 iota) | |
217 | { | |
d0b08853 | 218 | struct mod_pci_args args = { base, limit, iota, 0 }; |
828b35f6 JG |
219 | |
220 | WARN_ON_ONCE(iota & 0x3fff); | |
221 | args.iota |= ZPCI_IOTA_RTTO_FLAG; | |
222 | return mod_pci(zdev, ZPCI_MOD_FC_REG_IOAT, dmaas, &args); | |
223 | } | |
224 | ||
225 | /* Modify PCI: Unregister I/O address translation parameters */ | |
226 | int zpci_unregister_ioat(struct zpci_dev *zdev, u8 dmaas) | |
227 | { | |
d0b08853 | 228 | struct mod_pci_args args = { 0, 0, 0, 0 }; |
828b35f6 JG |
229 | |
230 | return mod_pci(zdev, ZPCI_MOD_FC_DEREG_IOAT, dmaas, &args); | |
231 | } | |
232 | ||
9a4da8a5 JG |
233 | /* Modify PCI: Unregister adapter interruptions */ |
234 | static int zpci_unregister_airq(struct zpci_dev *zdev) | |
235 | { | |
d0b08853 | 236 | struct mod_pci_args args = { 0, 0, 0, 0 }; |
9a4da8a5 JG |
237 | |
238 | return mod_pci(zdev, ZPCI_MOD_FC_DEREG_INT, 0, &args); | |
239 | } | |
240 | ||
d0b08853 JG |
241 | /* Modify PCI: Set PCI function measurement parameters */ |
242 | int zpci_fmb_enable_device(struct zpci_dev *zdev) | |
243 | { | |
244 | struct mod_pci_args args = { 0, 0, 0, 0 }; | |
245 | ||
246 | if (zdev->fmb) | |
247 | return -EINVAL; | |
248 | ||
08b42124 | 249 | zdev->fmb = kmem_cache_zalloc(zdev_fmb_cache, GFP_KERNEL); |
d0b08853 JG |
250 | if (!zdev->fmb) |
251 | return -ENOMEM; | |
d0b08853 JG |
252 | WARN_ON((u64) zdev->fmb & 0xf); |
253 | ||
254 | args.fmb_addr = virt_to_phys(zdev->fmb); | |
255 | return mod_pci(zdev, ZPCI_MOD_FC_SET_MEASURE, 0, &args); | |
256 | } | |
257 | ||
258 | /* Modify PCI: Disable PCI function measurement */ | |
259 | int zpci_fmb_disable_device(struct zpci_dev *zdev) | |
260 | { | |
261 | struct mod_pci_args args = { 0, 0, 0, 0 }; | |
262 | int rc; | |
263 | ||
264 | if (!zdev->fmb) | |
265 | return -EINVAL; | |
266 | ||
267 | /* Function measurement is disabled if fmb address is zero */ | |
268 | rc = mod_pci(zdev, ZPCI_MOD_FC_SET_MEASURE, 0, &args); | |
269 | ||
270 | kmem_cache_free(zdev_fmb_cache, zdev->fmb); | |
271 | zdev->fmb = NULL; | |
272 | return rc; | |
273 | } | |
274 | ||
cd248341 JG |
275 | #define ZPCI_PCIAS_CFGSPC 15 |
276 | ||
277 | static int zpci_cfg_load(struct zpci_dev *zdev, int offset, u32 *val, u8 len) | |
278 | { | |
279 | u64 req = ZPCI_CREATE_REQ(zdev->fh, ZPCI_PCIAS_CFGSPC, len); | |
280 | u64 data; | |
281 | int rc; | |
282 | ||
283 | rc = pcilg_instr(&data, req, offset); | |
284 | data = data << ((8 - len) * 8); | |
285 | data = le64_to_cpu(data); | |
286 | if (!rc) | |
287 | *val = (u32) data; | |
288 | else | |
289 | *val = 0xffffffff; | |
290 | return rc; | |
291 | } | |
292 | ||
293 | static int zpci_cfg_store(struct zpci_dev *zdev, int offset, u32 val, u8 len) | |
294 | { | |
295 | u64 req = ZPCI_CREATE_REQ(zdev->fh, ZPCI_PCIAS_CFGSPC, len); | |
296 | u64 data = val; | |
297 | int rc; | |
298 | ||
299 | data = cpu_to_le64(data); | |
300 | data = data >> ((8 - len) * 8); | |
301 | rc = pcistg_instr(data, req, offset); | |
302 | return rc; | |
303 | } | |
304 | ||
9a4da8a5 JG |
305 | void synchronize_irq(unsigned int irq) |
306 | { | |
307 | /* | |
308 | * Not needed, the handler is protected by a lock and IRQs that occur | |
309 | * after the handler is deleted are just NOPs. | |
310 | */ | |
311 | } | |
312 | EXPORT_SYMBOL_GPL(synchronize_irq); | |
313 | ||
314 | void enable_irq(unsigned int irq) | |
315 | { | |
316 | struct msi_desc *msi = irq_get_msi_desc(irq); | |
317 | ||
318 | zpci_msi_set_mask_bits(msi, 1, 0); | |
319 | } | |
320 | EXPORT_SYMBOL_GPL(enable_irq); | |
321 | ||
322 | void disable_irq(unsigned int irq) | |
323 | { | |
324 | struct msi_desc *msi = irq_get_msi_desc(irq); | |
325 | ||
326 | zpci_msi_set_mask_bits(msi, 1, 1); | |
327 | } | |
328 | EXPORT_SYMBOL_GPL(disable_irq); | |
329 | ||
330 | void disable_irq_nosync(unsigned int irq) | |
331 | { | |
332 | disable_irq(irq); | |
333 | } | |
334 | EXPORT_SYMBOL_GPL(disable_irq_nosync); | |
335 | ||
336 | unsigned long probe_irq_on(void) | |
337 | { | |
338 | return 0; | |
339 | } | |
340 | EXPORT_SYMBOL_GPL(probe_irq_on); | |
341 | ||
342 | int probe_irq_off(unsigned long val) | |
343 | { | |
344 | return 0; | |
345 | } | |
346 | EXPORT_SYMBOL_GPL(probe_irq_off); | |
347 | ||
348 | unsigned int probe_irq_mask(unsigned long val) | |
349 | { | |
350 | return val; | |
351 | } | |
352 | EXPORT_SYMBOL_GPL(probe_irq_mask); | |
353 | ||
b881bc46 | 354 | void pcibios_fixup_bus(struct pci_bus *bus) |
cd248341 JG |
355 | { |
356 | } | |
357 | ||
358 | resource_size_t pcibios_align_resource(void *data, const struct resource *res, | |
359 | resource_size_t size, | |
360 | resource_size_t align) | |
361 | { | |
362 | return 0; | |
363 | } | |
364 | ||
87bc359b JG |
365 | /* combine single writes by using store-block insn */ |
366 | void __iowrite64_copy(void __iomem *to, const void *from, size_t count) | |
367 | { | |
368 | zpci_memcpy_toio(to, from, count); | |
369 | } | |
370 | ||
cd248341 JG |
371 | /* Create a virtual mapping cookie for a PCI BAR */ |
372 | void __iomem *pci_iomap(struct pci_dev *pdev, int bar, unsigned long max) | |
373 | { | |
374 | struct zpci_dev *zdev = get_zdev(pdev); | |
375 | u64 addr; | |
376 | int idx; | |
377 | ||
378 | if ((bar & 7) != bar) | |
379 | return NULL; | |
380 | ||
381 | idx = zdev->bars[bar].map_idx; | |
382 | spin_lock(&zpci_iomap_lock); | |
383 | zpci_iomap_start[idx].fh = zdev->fh; | |
384 | zpci_iomap_start[idx].bar = bar; | |
385 | spin_unlock(&zpci_iomap_lock); | |
386 | ||
387 | addr = ZPCI_IOMAP_ADDR_BASE | ((u64) idx << 48); | |
388 | return (void __iomem *) addr; | |
389 | } | |
390 | EXPORT_SYMBOL_GPL(pci_iomap); | |
391 | ||
392 | void pci_iounmap(struct pci_dev *pdev, void __iomem *addr) | |
393 | { | |
394 | unsigned int idx; | |
395 | ||
396 | idx = (((__force u64) addr) & ~ZPCI_IOMAP_ADDR_BASE) >> 48; | |
397 | spin_lock(&zpci_iomap_lock); | |
398 | zpci_iomap_start[idx].fh = 0; | |
399 | zpci_iomap_start[idx].bar = 0; | |
400 | spin_unlock(&zpci_iomap_lock); | |
401 | } | |
402 | EXPORT_SYMBOL_GPL(pci_iounmap); | |
403 | ||
404 | static int pci_read(struct pci_bus *bus, unsigned int devfn, int where, | |
405 | int size, u32 *val) | |
406 | { | |
407 | struct zpci_dev *zdev = get_zdev_by_bus(bus); | |
408 | ||
409 | if (!zdev || devfn != ZPCI_DEVFN) | |
410 | return 0; | |
411 | return zpci_cfg_load(zdev, where, val, size); | |
412 | } | |
413 | ||
414 | static int pci_write(struct pci_bus *bus, unsigned int devfn, int where, | |
415 | int size, u32 val) | |
416 | { | |
417 | struct zpci_dev *zdev = get_zdev_by_bus(bus); | |
418 | ||
419 | if (!zdev || devfn != ZPCI_DEVFN) | |
420 | return 0; | |
421 | return zpci_cfg_store(zdev, where, val, size); | |
422 | } | |
423 | ||
424 | static struct pci_ops pci_root_ops = { | |
425 | .read = pci_read, | |
426 | .write = pci_write, | |
427 | }; | |
428 | ||
9a4da8a5 JG |
429 | /* store the last handled bit to implement fair scheduling of devices */ |
430 | static DEFINE_PER_CPU(unsigned long, next_sbit); | |
431 | ||
432 | static void zpci_irq_handler(void *dont, void *need) | |
433 | { | |
434 | unsigned long sbit, mbit, last = 0, start = __get_cpu_var(next_sbit); | |
435 | int rescan = 0, max = aisb_max; | |
436 | struct zdev_irq_map *imap; | |
437 | ||
420f42ec | 438 | inc_irq_stat(IRQIO_PCI); |
9a4da8a5 JG |
439 | sbit = start; |
440 | ||
441 | scan: | |
442 | /* find summary_bit */ | |
443 | for_each_set_bit_left_cont(sbit, bucket->aisb, max) { | |
444 | clear_bit(63 - (sbit & 63), bucket->aisb + (sbit >> 6)); | |
445 | last = sbit; | |
446 | ||
447 | /* find vector bit */ | |
448 | imap = bucket->imap[sbit]; | |
449 | for_each_set_bit_left(mbit, &imap->aibv, imap->msi_vecs) { | |
420f42ec | 450 | inc_irq_stat(IRQIO_MSI); |
9a4da8a5 JG |
451 | clear_bit(63 - mbit, &imap->aibv); |
452 | ||
453 | spin_lock(&imap->lock); | |
454 | if (imap->cb[mbit].handler) | |
455 | imap->cb[mbit].handler(mbit, | |
456 | imap->cb[mbit].data); | |
457 | spin_unlock(&imap->lock); | |
458 | } | |
459 | } | |
460 | ||
461 | if (rescan) | |
462 | goto out; | |
463 | ||
464 | /* scan the skipped bits */ | |
465 | if (start > 0) { | |
466 | sbit = 0; | |
467 | max = start; | |
468 | start = 0; | |
469 | goto scan; | |
470 | } | |
471 | ||
472 | /* enable interrupts again */ | |
473 | sic_instr(SIC_IRQ_MODE_SINGLE, NULL, PCI_ISC); | |
474 | ||
475 | /* check again to not lose initiative */ | |
476 | rmb(); | |
477 | max = aisb_max; | |
478 | sbit = find_first_bit_left(bucket->aisb, max); | |
479 | if (sbit != max) { | |
480 | atomic_inc(&irq_retries); | |
481 | rescan++; | |
482 | goto scan; | |
483 | } | |
484 | out: | |
485 | /* store next device bit to scan */ | |
486 | __get_cpu_var(next_sbit) = (++last >= aisb_max) ? 0 : last; | |
487 | } | |
488 | ||
489 | /* msi_vecs - number of requested interrupts, 0 place function to error state */ | |
490 | static int zpci_setup_msi(struct pci_dev *pdev, int msi_vecs) | |
491 | { | |
492 | struct zpci_dev *zdev = get_zdev(pdev); | |
493 | unsigned int aisb, msi_nr; | |
494 | struct msi_desc *msi; | |
495 | int rc; | |
496 | ||
497 | /* store the number of used MSI vectors */ | |
498 | zdev->irq_map->msi_vecs = min(msi_vecs, ZPCI_NR_MSI_VECS); | |
499 | ||
500 | spin_lock(&bucket->lock); | |
501 | aisb = find_first_zero_bit(bucket->alloc, PAGE_SIZE); | |
502 | /* alloc map exhausted? */ | |
503 | if (aisb == PAGE_SIZE) { | |
504 | spin_unlock(&bucket->lock); | |
505 | return -EIO; | |
506 | } | |
507 | set_bit(aisb, bucket->alloc); | |
508 | spin_unlock(&bucket->lock); | |
509 | ||
510 | zdev->aisb = aisb; | |
511 | if (aisb + 1 > aisb_max) | |
512 | aisb_max = aisb + 1; | |
513 | ||
514 | /* wire up IRQ shortcut pointer */ | |
515 | bucket->imap[zdev->aisb] = zdev->irq_map; | |
516 | pr_debug("%s: imap[%u] linked to %p\n", __func__, zdev->aisb, zdev->irq_map); | |
517 | ||
518 | /* TODO: irq number 0 wont be found if we return less than requested MSIs. | |
519 | * ignore it for now and fix in common code. | |
520 | */ | |
521 | msi_nr = aisb << ZPCI_MSI_VEC_BITS; | |
522 | ||
523 | list_for_each_entry(msi, &pdev->msi_list, list) { | |
524 | rc = zpci_setup_msi_irq(zdev, msi, msi_nr, | |
525 | aisb << ZPCI_MSI_VEC_BITS); | |
526 | if (rc) | |
527 | return rc; | |
528 | msi_nr++; | |
529 | } | |
530 | ||
531 | rc = zpci_register_airq(zdev, aisb, (u64) &zdev->irq_map->aibv); | |
532 | if (rc) { | |
533 | clear_bit(aisb, bucket->alloc); | |
534 | dev_err(&pdev->dev, "register MSI failed with: %d\n", rc); | |
535 | return rc; | |
536 | } | |
537 | return (zdev->irq_map->msi_vecs == msi_vecs) ? | |
538 | 0 : zdev->irq_map->msi_vecs; | |
539 | } | |
540 | ||
541 | static void zpci_teardown_msi(struct pci_dev *pdev) | |
542 | { | |
543 | struct zpci_dev *zdev = get_zdev(pdev); | |
544 | struct msi_desc *msi; | |
545 | int aisb, rc; | |
546 | ||
547 | rc = zpci_unregister_airq(zdev); | |
548 | if (rc) { | |
549 | dev_err(&pdev->dev, "deregister MSI failed with: %d\n", rc); | |
550 | return; | |
551 | } | |
552 | ||
553 | msi = list_first_entry(&pdev->msi_list, struct msi_desc, list); | |
554 | aisb = irq_to_dev_nr(msi->irq); | |
555 | ||
556 | list_for_each_entry(msi, &pdev->msi_list, list) | |
557 | zpci_teardown_msi_irq(zdev, msi); | |
558 | ||
559 | clear_bit(aisb, bucket->alloc); | |
560 | if (aisb + 1 == aisb_max) | |
561 | aisb_max--; | |
562 | } | |
563 | ||
564 | int arch_setup_msi_irqs(struct pci_dev *pdev, int nvec, int type) | |
565 | { | |
566 | pr_debug("%s: requesting %d MSI-X interrupts...", __func__, nvec); | |
567 | if (type != PCI_CAP_ID_MSIX && type != PCI_CAP_ID_MSI) | |
568 | return -EINVAL; | |
569 | return zpci_setup_msi(pdev, nvec); | |
570 | } | |
571 | ||
572 | void arch_teardown_msi_irqs(struct pci_dev *pdev) | |
573 | { | |
574 | pr_info("%s: on pdev: %p\n", __func__, pdev); | |
575 | zpci_teardown_msi(pdev); | |
576 | } | |
577 | ||
cd248341 JG |
578 | static void zpci_map_resources(struct zpci_dev *zdev) |
579 | { | |
580 | struct pci_dev *pdev = zdev->pdev; | |
581 | resource_size_t len; | |
582 | int i; | |
583 | ||
584 | for (i = 0; i < PCI_BAR_COUNT; i++) { | |
585 | len = pci_resource_len(pdev, i); | |
586 | if (!len) | |
587 | continue; | |
588 | pdev->resource[i].start = (resource_size_t) pci_iomap(pdev, i, 0); | |
589 | pdev->resource[i].end = pdev->resource[i].start + len - 1; | |
590 | pr_debug("BAR%i: -> start: %Lx end: %Lx\n", | |
591 | i, pdev->resource[i].start, pdev->resource[i].end); | |
592 | } | |
593 | }; | |
594 | ||
595 | static void zpci_unmap_resources(struct pci_dev *pdev) | |
596 | { | |
597 | resource_size_t len; | |
598 | int i; | |
599 | ||
600 | for (i = 0; i < PCI_BAR_COUNT; i++) { | |
601 | len = pci_resource_len(pdev, i); | |
602 | if (!len) | |
603 | continue; | |
604 | pci_iounmap(pdev, (void *) pdev->resource[i].start); | |
605 | } | |
606 | }; | |
607 | ||
608 | struct zpci_dev *zpci_alloc_device(void) | |
609 | { | |
610 | struct zpci_dev *zdev; | |
611 | ||
612 | /* Alloc memory for our private pci device data */ | |
613 | zdev = kzalloc(sizeof(*zdev), GFP_KERNEL); | |
614 | if (!zdev) | |
615 | return ERR_PTR(-ENOMEM); | |
9a4da8a5 JG |
616 | |
617 | /* Alloc aibv & callback space */ | |
4118fee7 | 618 | zdev->irq_map = kmem_cache_zalloc(zdev_irq_cache, GFP_KERNEL); |
9a4da8a5 JG |
619 | if (!zdev->irq_map) |
620 | goto error; | |
9a4da8a5 | 621 | WARN_ON((u64) zdev->irq_map & 0xff); |
cd248341 | 622 | return zdev; |
9a4da8a5 JG |
623 | |
624 | error: | |
625 | kfree(zdev); | |
626 | return ERR_PTR(-ENOMEM); | |
cd248341 JG |
627 | } |
628 | ||
629 | void zpci_free_device(struct zpci_dev *zdev) | |
630 | { | |
9a4da8a5 | 631 | kmem_cache_free(zdev_irq_cache, zdev->irq_map); |
cd248341 JG |
632 | kfree(zdev); |
633 | } | |
634 | ||
635 | /* Called on removal of pci_dev, leaves zpci and bus device */ | |
636 | static void zpci_remove_device(struct pci_dev *pdev) | |
637 | { | |
638 | struct zpci_dev *zdev = get_zdev(pdev); | |
639 | ||
640 | dev_info(&pdev->dev, "Removing device %u\n", zdev->domain); | |
641 | zdev->state = ZPCI_FN_STATE_CONFIGURED; | |
828b35f6 | 642 | zpci_dma_exit_device(zdev); |
d0b08853 | 643 | zpci_fmb_disable_device(zdev); |
1e8da956 | 644 | zpci_sysfs_remove_device(&pdev->dev); |
cd248341 JG |
645 | zpci_unmap_resources(pdev); |
646 | list_del(&zdev->entry); /* can be called from init */ | |
647 | zdev->pdev = NULL; | |
648 | } | |
649 | ||
650 | static void zpci_scan_devices(void) | |
651 | { | |
652 | struct zpci_dev *zdev; | |
653 | ||
654 | mutex_lock(&zpci_list_lock); | |
655 | list_for_each_entry(zdev, &zpci_list, entry) | |
656 | if (zdev->state == ZPCI_FN_STATE_CONFIGURED) | |
657 | zpci_scan_device(zdev); | |
658 | mutex_unlock(&zpci_list_lock); | |
659 | } | |
660 | ||
661 | /* | |
662 | * Too late for any s390 specific setup, since interrupts must be set up | |
663 | * already which requires DMA setup too and the pci scan will access the | |
664 | * config space, which only works if the function handle is enabled. | |
665 | */ | |
666 | int pcibios_enable_device(struct pci_dev *pdev, int mask) | |
667 | { | |
668 | struct resource *res; | |
669 | u16 cmd; | |
670 | int i; | |
671 | ||
672 | pci_read_config_word(pdev, PCI_COMMAND, &cmd); | |
673 | ||
674 | for (i = 0; i < PCI_BAR_COUNT; i++) { | |
675 | res = &pdev->resource[i]; | |
676 | ||
677 | if (res->flags & IORESOURCE_IO) | |
678 | return -EINVAL; | |
679 | ||
680 | if (res->flags & IORESOURCE_MEM) | |
681 | cmd |= PCI_COMMAND_MEMORY; | |
682 | } | |
683 | pci_write_config_word(pdev, PCI_COMMAND, cmd); | |
684 | return 0; | |
685 | } | |
686 | ||
687 | void pcibios_disable_device(struct pci_dev *pdev) | |
688 | { | |
689 | zpci_remove_device(pdev); | |
690 | pdev->sysdata = NULL; | |
691 | } | |
692 | ||
1e8da956 JG |
693 | int pcibios_add_platform_entries(struct pci_dev *pdev) |
694 | { | |
695 | return zpci_sysfs_add_device(&pdev->dev); | |
696 | } | |
697 | ||
9a4da8a5 JG |
698 | int zpci_request_irq(unsigned int irq, irq_handler_t handler, void *data) |
699 | { | |
700 | int msi_nr = irq_to_msi_nr(irq); | |
701 | struct zdev_irq_map *imap; | |
702 | struct msi_desc *msi; | |
703 | ||
704 | msi = irq_get_msi_desc(irq); | |
705 | if (!msi) | |
706 | return -EIO; | |
707 | ||
708 | imap = get_imap(irq); | |
709 | spin_lock_init(&imap->lock); | |
710 | ||
711 | pr_debug("%s: register handler for IRQ:MSI %d:%d\n", __func__, irq >> 6, msi_nr); | |
712 | imap->cb[msi_nr].handler = handler; | |
713 | imap->cb[msi_nr].data = data; | |
714 | ||
715 | /* | |
716 | * The generic MSI code returns with the interrupt disabled on the | |
717 | * card, using the MSI mask bits. Firmware doesn't appear to unmask | |
718 | * at that level, so we do it here by hand. | |
719 | */ | |
720 | zpci_msi_set_mask_bits(msi, 1, 0); | |
721 | return 0; | |
722 | } | |
723 | ||
724 | void zpci_free_irq(unsigned int irq) | |
725 | { | |
726 | struct zdev_irq_map *imap = get_imap(irq); | |
727 | int msi_nr = irq_to_msi_nr(irq); | |
728 | unsigned long flags; | |
729 | ||
730 | pr_debug("%s: for irq: %d\n", __func__, irq); | |
731 | ||
732 | spin_lock_irqsave(&imap->lock, flags); | |
733 | imap->cb[msi_nr].handler = NULL; | |
734 | imap->cb[msi_nr].data = NULL; | |
735 | spin_unlock_irqrestore(&imap->lock, flags); | |
736 | } | |
737 | ||
738 | int request_irq(unsigned int irq, irq_handler_t handler, | |
739 | unsigned long irqflags, const char *devname, void *dev_id) | |
740 | { | |
741 | pr_debug("%s: irq: %d handler: %p flags: %lx dev: %s\n", | |
742 | __func__, irq, handler, irqflags, devname); | |
743 | ||
744 | return zpci_request_irq(irq, handler, dev_id); | |
745 | } | |
746 | EXPORT_SYMBOL_GPL(request_irq); | |
747 | ||
748 | void free_irq(unsigned int irq, void *dev_id) | |
749 | { | |
750 | zpci_free_irq(irq); | |
751 | } | |
752 | EXPORT_SYMBOL_GPL(free_irq); | |
753 | ||
754 | static int __init zpci_irq_init(void) | |
755 | { | |
756 | int cpu, rc; | |
757 | ||
758 | bucket = kzalloc(sizeof(*bucket), GFP_KERNEL); | |
759 | if (!bucket) | |
760 | return -ENOMEM; | |
761 | ||
762 | bucket->aisb = (unsigned long *) get_zeroed_page(GFP_KERNEL); | |
763 | if (!bucket->aisb) { | |
764 | rc = -ENOMEM; | |
765 | goto out_aisb; | |
766 | } | |
767 | ||
768 | bucket->alloc = (unsigned long *) get_zeroed_page(GFP_KERNEL); | |
769 | if (!bucket->alloc) { | |
770 | rc = -ENOMEM; | |
771 | goto out_alloc; | |
772 | } | |
773 | ||
774 | isc_register(PCI_ISC); | |
775 | zpci_irq_si = s390_register_adapter_interrupt(&zpci_irq_handler, NULL, PCI_ISC); | |
776 | if (IS_ERR(zpci_irq_si)) { | |
777 | rc = PTR_ERR(zpci_irq_si); | |
778 | zpci_irq_si = NULL; | |
779 | goto out_ai; | |
780 | } | |
781 | ||
782 | for_each_online_cpu(cpu) | |
783 | per_cpu(next_sbit, cpu) = 0; | |
784 | ||
785 | spin_lock_init(&bucket->lock); | |
786 | /* set summary to 1 to be called every time for the ISC */ | |
787 | *zpci_irq_si = 1; | |
788 | sic_instr(SIC_IRQ_MODE_SINGLE, NULL, PCI_ISC); | |
789 | return 0; | |
790 | ||
791 | out_ai: | |
792 | isc_unregister(PCI_ISC); | |
793 | free_page((unsigned long) bucket->alloc); | |
794 | out_alloc: | |
795 | free_page((unsigned long) bucket->aisb); | |
796 | out_aisb: | |
797 | kfree(bucket); | |
798 | return rc; | |
799 | } | |
800 | ||
801 | static void zpci_irq_exit(void) | |
802 | { | |
803 | free_page((unsigned long) bucket->alloc); | |
804 | free_page((unsigned long) bucket->aisb); | |
805 | s390_unregister_adapter_interrupt(zpci_irq_si, PCI_ISC); | |
806 | isc_unregister(PCI_ISC); | |
807 | kfree(bucket); | |
808 | } | |
809 | ||
d0b08853 JG |
810 | void zpci_debug_info(struct zpci_dev *zdev, struct seq_file *m) |
811 | { | |
812 | if (!zdev) | |
813 | return; | |
814 | ||
815 | seq_printf(m, "global irq retries: %u\n", atomic_read(&irq_retries)); | |
816 | seq_printf(m, "aibv[0]:%016lx aibv[1]:%016lx aisb:%016lx\n", | |
817 | get_imap(0)->aibv, get_imap(1)->aibv, *bucket->aisb); | |
818 | } | |
819 | ||
cd248341 JG |
820 | static struct resource *zpci_alloc_bus_resource(unsigned long start, unsigned long size, |
821 | unsigned long flags, int domain) | |
822 | { | |
823 | struct resource *r; | |
824 | char *name; | |
825 | int rc; | |
826 | ||
827 | r = kzalloc(sizeof(*r), GFP_KERNEL); | |
828 | if (!r) | |
829 | return ERR_PTR(-ENOMEM); | |
830 | r->start = start; | |
831 | r->end = r->start + size - 1; | |
832 | r->flags = flags; | |
833 | r->parent = &iomem_resource; | |
834 | name = kmalloc(18, GFP_KERNEL); | |
835 | if (!name) { | |
836 | kfree(r); | |
837 | return ERR_PTR(-ENOMEM); | |
838 | } | |
839 | sprintf(name, "PCI Bus: %04x:%02x", domain, ZPCI_BUS_NR); | |
840 | r->name = name; | |
841 | ||
842 | rc = request_resource(&iomem_resource, r); | |
843 | if (rc) | |
844 | pr_debug("request resource %pR failed\n", r); | |
845 | return r; | |
846 | } | |
847 | ||
848 | static int zpci_alloc_iomap(struct zpci_dev *zdev) | |
849 | { | |
850 | int entry; | |
851 | ||
852 | spin_lock(&zpci_iomap_lock); | |
853 | entry = find_first_zero_bit(zpci_iomap, ZPCI_IOMAP_MAX_ENTRIES); | |
854 | if (entry == ZPCI_IOMAP_MAX_ENTRIES) { | |
855 | spin_unlock(&zpci_iomap_lock); | |
856 | return -ENOSPC; | |
857 | } | |
858 | set_bit(entry, zpci_iomap); | |
859 | spin_unlock(&zpci_iomap_lock); | |
860 | return entry; | |
861 | } | |
862 | ||
863 | static void zpci_free_iomap(struct zpci_dev *zdev, int entry) | |
864 | { | |
865 | spin_lock(&zpci_iomap_lock); | |
866 | memset(&zpci_iomap_start[entry], 0, sizeof(struct zpci_iomap_entry)); | |
867 | clear_bit(entry, zpci_iomap); | |
868 | spin_unlock(&zpci_iomap_lock); | |
869 | } | |
870 | ||
871 | static int zpci_create_device_bus(struct zpci_dev *zdev) | |
872 | { | |
873 | struct resource *res; | |
874 | LIST_HEAD(resources); | |
875 | int i; | |
876 | ||
877 | /* allocate mapping entry for each used bar */ | |
878 | for (i = 0; i < PCI_BAR_COUNT; i++) { | |
879 | unsigned long addr, size, flags; | |
880 | int entry; | |
881 | ||
882 | if (!zdev->bars[i].size) | |
883 | continue; | |
884 | entry = zpci_alloc_iomap(zdev); | |
885 | if (entry < 0) | |
886 | return entry; | |
887 | zdev->bars[i].map_idx = entry; | |
888 | ||
889 | /* only MMIO is supported */ | |
890 | flags = IORESOURCE_MEM; | |
891 | if (zdev->bars[i].val & 8) | |
892 | flags |= IORESOURCE_PREFETCH; | |
893 | if (zdev->bars[i].val & 4) | |
894 | flags |= IORESOURCE_MEM_64; | |
895 | ||
896 | addr = ZPCI_IOMAP_ADDR_BASE + ((u64) entry << 48); | |
897 | ||
898 | size = 1UL << zdev->bars[i].size; | |
899 | ||
900 | res = zpci_alloc_bus_resource(addr, size, flags, zdev->domain); | |
901 | if (IS_ERR(res)) { | |
902 | zpci_free_iomap(zdev, entry); | |
903 | return PTR_ERR(res); | |
904 | } | |
905 | pci_add_resource(&resources, res); | |
906 | } | |
907 | ||
908 | zdev->bus = pci_create_root_bus(NULL, ZPCI_BUS_NR, &pci_root_ops, | |
909 | zdev, &resources); | |
910 | if (!zdev->bus) | |
911 | return -EIO; | |
912 | ||
913 | zdev->bus->max_bus_speed = zdev->max_bus_speed; | |
914 | return 0; | |
915 | } | |
916 | ||
917 | static int zpci_alloc_domain(struct zpci_dev *zdev) | |
918 | { | |
919 | spin_lock(&zpci_domain_lock); | |
920 | zdev->domain = find_first_zero_bit(zpci_domain, ZPCI_NR_DEVICES); | |
921 | if (zdev->domain == ZPCI_NR_DEVICES) { | |
922 | spin_unlock(&zpci_domain_lock); | |
923 | return -ENOSPC; | |
924 | } | |
925 | set_bit(zdev->domain, zpci_domain); | |
926 | spin_unlock(&zpci_domain_lock); | |
927 | return 0; | |
928 | } | |
929 | ||
930 | static void zpci_free_domain(struct zpci_dev *zdev) | |
931 | { | |
932 | spin_lock(&zpci_domain_lock); | |
933 | clear_bit(zdev->domain, zpci_domain); | |
934 | spin_unlock(&zpci_domain_lock); | |
935 | } | |
936 | ||
a755a45d JG |
937 | int zpci_enable_device(struct zpci_dev *zdev) |
938 | { | |
939 | int rc; | |
940 | ||
941 | rc = clp_enable_fh(zdev, ZPCI_NR_DMA_SPACES); | |
942 | if (rc) | |
943 | goto out; | |
944 | pr_info("Enabled fh: 0x%x fid: 0x%x\n", zdev->fh, zdev->fid); | |
828b35f6 JG |
945 | |
946 | rc = zpci_dma_init_device(zdev); | |
947 | if (rc) | |
948 | goto out_dma; | |
a755a45d | 949 | return 0; |
828b35f6 JG |
950 | |
951 | out_dma: | |
952 | clp_disable_fh(zdev); | |
a755a45d JG |
953 | out: |
954 | return rc; | |
955 | } | |
956 | EXPORT_SYMBOL_GPL(zpci_enable_device); | |
957 | ||
cb65a669 SO |
958 | int zpci_disable_device(struct zpci_dev *zdev) |
959 | { | |
960 | zpci_dma_exit_device(zdev); | |
961 | return clp_disable_fh(zdev); | |
962 | } | |
963 | EXPORT_SYMBOL_GPL(zpci_disable_device); | |
964 | ||
cd248341 JG |
965 | int zpci_create_device(struct zpci_dev *zdev) |
966 | { | |
967 | int rc; | |
968 | ||
969 | rc = zpci_alloc_domain(zdev); | |
970 | if (rc) | |
971 | goto out; | |
972 | ||
973 | rc = zpci_create_device_bus(zdev); | |
974 | if (rc) | |
975 | goto out_bus; | |
976 | ||
977 | mutex_lock(&zpci_list_lock); | |
978 | list_add_tail(&zdev->entry, &zpci_list); | |
53923354 SO |
979 | if (hotplug_ops) |
980 | hotplug_ops->create_slot(zdev); | |
cd248341 JG |
981 | mutex_unlock(&zpci_list_lock); |
982 | ||
983 | if (zdev->state == ZPCI_FN_STATE_STANDBY) | |
984 | return 0; | |
985 | ||
a755a45d JG |
986 | rc = zpci_enable_device(zdev); |
987 | if (rc) | |
988 | goto out_start; | |
cd248341 JG |
989 | return 0; |
990 | ||
a755a45d JG |
991 | out_start: |
992 | mutex_lock(&zpci_list_lock); | |
993 | list_del(&zdev->entry); | |
53923354 SO |
994 | if (hotplug_ops) |
995 | hotplug_ops->remove_slot(zdev); | |
a755a45d | 996 | mutex_unlock(&zpci_list_lock); |
cd248341 JG |
997 | out_bus: |
998 | zpci_free_domain(zdev); | |
999 | out: | |
1000 | return rc; | |
1001 | } | |
1002 | ||
1003 | void zpci_stop_device(struct zpci_dev *zdev) | |
1004 | { | |
828b35f6 | 1005 | zpci_dma_exit_device(zdev); |
cd248341 JG |
1006 | /* |
1007 | * Note: SCLP disables fh via set-pci-fn so don't | |
1008 | * do that here. | |
1009 | */ | |
1010 | } | |
1011 | EXPORT_SYMBOL_GPL(zpci_stop_device); | |
1012 | ||
1013 | int zpci_scan_device(struct zpci_dev *zdev) | |
1014 | { | |
1015 | zdev->pdev = pci_scan_single_device(zdev->bus, ZPCI_DEVFN); | |
1016 | if (!zdev->pdev) { | |
1017 | pr_err("pci_scan_single_device failed for fid: 0x%x\n", | |
1018 | zdev->fid); | |
1019 | goto out; | |
1020 | } | |
1021 | ||
d0b08853 JG |
1022 | zpci_debug_init_device(zdev); |
1023 | zpci_fmb_enable_device(zdev); | |
cd248341 JG |
1024 | zpci_map_resources(zdev); |
1025 | pci_bus_add_devices(zdev->bus); | |
1026 | ||
1027 | /* now that pdev was added to the bus mark it as used */ | |
1028 | zdev->state = ZPCI_FN_STATE_ONLINE; | |
1029 | return 0; | |
1030 | ||
1031 | out: | |
828b35f6 | 1032 | zpci_dma_exit_device(zdev); |
a755a45d | 1033 | clp_disable_fh(zdev); |
cd248341 JG |
1034 | return -EIO; |
1035 | } | |
1036 | EXPORT_SYMBOL_GPL(zpci_scan_device); | |
1037 | ||
1038 | static inline int barsize(u8 size) | |
1039 | { | |
1040 | return (size) ? (1 << size) >> 10 : 0; | |
1041 | } | |
1042 | ||
1043 | static int zpci_mem_init(void) | |
1044 | { | |
9a4da8a5 JG |
1045 | zdev_irq_cache = kmem_cache_create("PCI_IRQ_cache", sizeof(struct zdev_irq_map), |
1046 | L1_CACHE_BYTES, SLAB_HWCACHE_ALIGN, NULL); | |
1047 | if (!zdev_irq_cache) | |
1048 | goto error_zdev; | |
1049 | ||
d0b08853 JG |
1050 | zdev_fmb_cache = kmem_cache_create("PCI_FMB_cache", sizeof(struct zpci_fmb), |
1051 | 16, 0, NULL); | |
1052 | if (!zdev_fmb_cache) | |
1053 | goto error_fmb; | |
1054 | ||
cd248341 JG |
1055 | /* TODO: use realloc */ |
1056 | zpci_iomap_start = kzalloc(ZPCI_IOMAP_MAX_ENTRIES * sizeof(*zpci_iomap_start), | |
1057 | GFP_KERNEL); | |
1058 | if (!zpci_iomap_start) | |
9a4da8a5 | 1059 | goto error_iomap; |
cd248341 JG |
1060 | return 0; |
1061 | ||
9a4da8a5 | 1062 | error_iomap: |
d0b08853 JG |
1063 | kmem_cache_destroy(zdev_fmb_cache); |
1064 | error_fmb: | |
9a4da8a5 | 1065 | kmem_cache_destroy(zdev_irq_cache); |
cd248341 JG |
1066 | error_zdev: |
1067 | return -ENOMEM; | |
1068 | } | |
1069 | ||
1070 | static void zpci_mem_exit(void) | |
1071 | { | |
1072 | kfree(zpci_iomap_start); | |
9a4da8a5 | 1073 | kmem_cache_destroy(zdev_irq_cache); |
d0b08853 | 1074 | kmem_cache_destroy(zdev_fmb_cache); |
cd248341 JG |
1075 | } |
1076 | ||
53923354 SO |
1077 | void zpci_register_hp_ops(struct pci_hp_callback_ops *ops) |
1078 | { | |
1079 | mutex_lock(&zpci_list_lock); | |
1080 | hotplug_ops = ops; | |
1081 | mutex_unlock(&zpci_list_lock); | |
1082 | } | |
1083 | EXPORT_SYMBOL_GPL(zpci_register_hp_ops); | |
1084 | ||
1085 | void zpci_deregister_hp_ops(void) | |
1086 | { | |
1087 | mutex_lock(&zpci_list_lock); | |
1088 | hotplug_ops = NULL; | |
1089 | mutex_unlock(&zpci_list_lock); | |
1090 | } | |
1091 | EXPORT_SYMBOL_GPL(zpci_deregister_hp_ops); | |
1092 | ||
1e5635d1 HC |
1093 | unsigned int s390_pci_probe = 1; |
1094 | EXPORT_SYMBOL_GPL(s390_pci_probe); | |
cd248341 JG |
1095 | |
1096 | char * __init pcibios_setup(char *str) | |
1097 | { | |
1098 | if (!strcmp(str, "off")) { | |
1e5635d1 | 1099 | s390_pci_probe = 0; |
cd248341 JG |
1100 | return NULL; |
1101 | } | |
1102 | return str; | |
1103 | } | |
1104 | ||
1105 | static int __init pci_base_init(void) | |
1106 | { | |
1107 | int rc; | |
1108 | ||
1e5635d1 | 1109 | if (!s390_pci_probe) |
cd248341 JG |
1110 | return 0; |
1111 | ||
1112 | if (!test_facility(2) || !test_facility(69) | |
1113 | || !test_facility(71) || !test_facility(72)) | |
1114 | return 0; | |
1115 | ||
1116 | pr_info("Probing PCI hardware: PCI:%d SID:%d AEN:%d\n", | |
1117 | test_facility(69), test_facility(70), | |
1118 | test_facility(71)); | |
1119 | ||
d0b08853 JG |
1120 | rc = zpci_debug_init(); |
1121 | if (rc) | |
1122 | return rc; | |
1123 | ||
cd248341 JG |
1124 | rc = zpci_mem_init(); |
1125 | if (rc) | |
1126 | goto out_mem; | |
1127 | ||
9a4da8a5 JG |
1128 | rc = zpci_msihash_init(); |
1129 | if (rc) | |
1130 | goto out_hash; | |
1131 | ||
1132 | rc = zpci_irq_init(); | |
1133 | if (rc) | |
1134 | goto out_irq; | |
1135 | ||
828b35f6 JG |
1136 | rc = zpci_dma_init(); |
1137 | if (rc) | |
1138 | goto out_dma; | |
1139 | ||
a755a45d JG |
1140 | rc = clp_find_pci_devices(); |
1141 | if (rc) | |
1142 | goto out_find; | |
1143 | ||
cd248341 JG |
1144 | zpci_scan_devices(); |
1145 | return 0; | |
1146 | ||
a755a45d | 1147 | out_find: |
828b35f6 JG |
1148 | zpci_dma_exit(); |
1149 | out_dma: | |
9a4da8a5 JG |
1150 | zpci_irq_exit(); |
1151 | out_irq: | |
1152 | zpci_msihash_exit(); | |
1153 | out_hash: | |
cd248341 JG |
1154 | zpci_mem_exit(); |
1155 | out_mem: | |
d0b08853 | 1156 | zpci_debug_exit(); |
cd248341 JG |
1157 | return rc; |
1158 | } | |
1159 | subsys_initcall(pci_base_init); |