2 * Copyright IBM Corp. 2012
5 * Jan Glauber <jang@linux.vnet.ibm.com>
7 * The System z PCI code is a rewrite from a prototype by
8 * the following people (Kudoz!):
18 #define COMPONENT "zPCI"
19 #define pr_fmt(fmt) COMPONENT ": " fmt
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>
26 #include <linux/irq.h>
27 #include <linux/kernel_stat.h>
28 #include <linux/seq_file.h>
29 #include <linux/pci.h>
30 #include <linux/msi.h>
34 #include <asm/facility.h>
35 #include <asm/pci_insn.h>
36 #include <asm/pci_clp.h>
37 #include <asm/pci_dma.h>
39 #define DEBUG /* enable pr_debug */
41 #define SIC_IRQ_MODE_ALL 0
42 #define SIC_IRQ_MODE_SINGLE 1
44 #define ZPCI_NR_DMA_SPACES 1
45 #define ZPCI_MSI_VEC_BITS 6
46 #define ZPCI_NR_DEVICES CONFIG_PCI_NR_FUNCTIONS
48 /* list of all detected zpci devices */
50 EXPORT_SYMBOL_GPL(zpci_list);
51 DEFINE_MUTEX(zpci_list_lock);
52 EXPORT_SYMBOL_GPL(zpci_list_lock);
54 static struct pci_hp_callback_ops *hotplug_ops;
56 static DECLARE_BITMAP(zpci_domain, ZPCI_NR_DEVICES);
57 static DEFINE_SPINLOCK(zpci_domain_lock);
60 irq_handler_t handler;
65 unsigned long aibv; /* AI bit vector */
66 int msi_vecs; /* consecutive MSI-vectors used */
68 struct callback cb[ZPCI_NR_MSI_VECS]; /* callback handler array */
69 spinlock_t lock; /* protect callbacks against de-reg */
73 /* amap of adapters, one bit per dev, corresponds to one irq nr */
75 /* AI summary bit, global page for all devices */
77 /* pointer to aibv and callback data in zdev */
78 struct zdev_irq_map *imap[ZPCI_NR_DEVICES];
79 /* protects the whole bucket struct */
83 static struct intr_bucket *bucket;
85 /* Adapter local summary indicator */
86 static u8 *zpci_irq_si;
89 static DEFINE_SPINLOCK(zpci_iomap_lock);
90 static DECLARE_BITMAP(zpci_iomap, ZPCI_IOMAP_MAX_ENTRIES);
91 struct zpci_iomap_entry *zpci_iomap_start;
92 EXPORT_SYMBOL_GPL(zpci_iomap_start);
94 /* highest irq summary bit */
95 static int __read_mostly aisb_max;
97 static struct kmem_cache *zdev_irq_cache;
98 static struct kmem_cache *zdev_fmb_cache;
100 static inline int irq_to_msi_nr(unsigned int irq)
102 return irq & ZPCI_MSI_MASK;
105 static inline int irq_to_dev_nr(unsigned int irq)
107 return irq >> ZPCI_MSI_VEC_BITS;
110 static inline struct zdev_irq_map *get_imap(unsigned int irq)
112 return bucket->imap[irq_to_dev_nr(irq)];
115 struct zpci_dev *get_zdev(struct pci_dev *pdev)
117 return (struct zpci_dev *) pdev->sysdata;
120 struct zpci_dev *get_zdev_by_fid(u32 fid)
122 struct zpci_dev *tmp, *zdev = NULL;
124 mutex_lock(&zpci_list_lock);
125 list_for_each_entry(tmp, &zpci_list, entry) {
126 if (tmp->fid == fid) {
131 mutex_unlock(&zpci_list_lock);
135 bool zpci_fid_present(u32 fid)
137 return (get_zdev_by_fid(fid) != NULL) ? true : false;
140 static struct zpci_dev *get_zdev_by_bus(struct pci_bus *bus)
142 return (bus && bus->sysdata) ? (struct zpci_dev *) bus->sysdata : NULL;
145 int pci_domain_nr(struct pci_bus *bus)
147 return ((struct zpci_dev *) bus->sysdata)->domain;
149 EXPORT_SYMBOL_GPL(pci_domain_nr);
151 int pci_proc_domain(struct pci_bus *bus)
153 return pci_domain_nr(bus);
155 EXPORT_SYMBOL_GPL(pci_proc_domain);
157 /* Modify PCI: Register adapter interruptions */
158 static int zpci_register_airq(struct zpci_dev *zdev, unsigned int aisb,
161 u64 req = ZPCI_CREATE_REQ(zdev->fh, 0, ZPCI_MOD_FC_REG_INT);
162 struct zpci_fib *fib;
165 fib = (void *) get_zeroed_page(GFP_KERNEL);
170 fib->noi = zdev->irq_map->msi_vecs;
171 fib->sum = 1; /* enable summary notifications */
173 fib->aibvo = 0; /* every function has its own page */
174 fib->aisb = (u64) bucket->aisb + aisb / 8;
175 fib->aisbo = aisb & ZPCI_MSI_MASK;
177 rc = s390pci_mod_fc(req, fib);
178 pr_debug("%s mpcifc returned noi: %d\n", __func__, fib->noi);
180 free_page((unsigned long) fib);
184 struct mod_pci_args {
191 static int mod_pci(struct zpci_dev *zdev, int fn, u8 dmaas, struct mod_pci_args *args)
193 u64 req = ZPCI_CREATE_REQ(zdev->fh, dmaas, fn);
194 struct zpci_fib *fib;
197 /* The FIB must be available even if it's not used */
198 fib = (void *) get_zeroed_page(GFP_KERNEL);
202 fib->pba = args->base;
203 fib->pal = args->limit;
204 fib->iota = args->iota;
205 fib->fmb_addr = args->fmb_addr;
207 rc = s390pci_mod_fc(req, fib);
208 free_page((unsigned long) fib);
212 /* Modify PCI: Register I/O address translation parameters */
213 int zpci_register_ioat(struct zpci_dev *zdev, u8 dmaas,
214 u64 base, u64 limit, u64 iota)
216 struct mod_pci_args args = { base, limit, iota, 0 };
218 WARN_ON_ONCE(iota & 0x3fff);
219 args.iota |= ZPCI_IOTA_RTTO_FLAG;
220 return mod_pci(zdev, ZPCI_MOD_FC_REG_IOAT, dmaas, &args);
223 /* Modify PCI: Unregister I/O address translation parameters */
224 int zpci_unregister_ioat(struct zpci_dev *zdev, u8 dmaas)
226 struct mod_pci_args args = { 0, 0, 0, 0 };
228 return mod_pci(zdev, ZPCI_MOD_FC_DEREG_IOAT, dmaas, &args);
231 /* Modify PCI: Unregister adapter interruptions */
232 static int zpci_unregister_airq(struct zpci_dev *zdev)
234 struct mod_pci_args args = { 0, 0, 0, 0 };
236 return mod_pci(zdev, ZPCI_MOD_FC_DEREG_INT, 0, &args);
239 /* Modify PCI: Set PCI function measurement parameters */
240 int zpci_fmb_enable_device(struct zpci_dev *zdev)
242 struct mod_pci_args args = { 0, 0, 0, 0 };
247 zdev->fmb = kmem_cache_zalloc(zdev_fmb_cache, GFP_KERNEL);
250 WARN_ON((u64) zdev->fmb & 0xf);
252 args.fmb_addr = virt_to_phys(zdev->fmb);
253 return mod_pci(zdev, ZPCI_MOD_FC_SET_MEASURE, 0, &args);
256 /* Modify PCI: Disable PCI function measurement */
257 int zpci_fmb_disable_device(struct zpci_dev *zdev)
259 struct mod_pci_args args = { 0, 0, 0, 0 };
265 /* Function measurement is disabled if fmb address is zero */
266 rc = mod_pci(zdev, ZPCI_MOD_FC_SET_MEASURE, 0, &args);
268 kmem_cache_free(zdev_fmb_cache, zdev->fmb);
273 #define ZPCI_PCIAS_CFGSPC 15
275 static int zpci_cfg_load(struct zpci_dev *zdev, int offset, u32 *val, u8 len)
277 u64 req = ZPCI_CREATE_REQ(zdev->fh, ZPCI_PCIAS_CFGSPC, len);
281 rc = s390pci_load(&data, req, offset);
283 data = data << ((8 - len) * 8);
284 data = le64_to_cpu(data);
291 static int zpci_cfg_store(struct zpci_dev *zdev, int offset, u32 val, u8 len)
293 u64 req = ZPCI_CREATE_REQ(zdev->fh, ZPCI_PCIAS_CFGSPC, len);
297 data = cpu_to_le64(data);
298 data = data >> ((8 - len) * 8);
299 rc = s390pci_store(data, req, offset);
303 void enable_irq(unsigned int irq)
305 struct msi_desc *msi = irq_get_msi_desc(irq);
307 zpci_msi_set_mask_bits(msi, 1, 0);
309 EXPORT_SYMBOL_GPL(enable_irq);
311 void disable_irq(unsigned int irq)
313 struct msi_desc *msi = irq_get_msi_desc(irq);
315 zpci_msi_set_mask_bits(msi, 1, 1);
317 EXPORT_SYMBOL_GPL(disable_irq);
319 void pcibios_fixup_bus(struct pci_bus *bus)
323 resource_size_t pcibios_align_resource(void *data, const struct resource *res,
324 resource_size_t size,
325 resource_size_t align)
330 /* combine single writes by using store-block insn */
331 void __iowrite64_copy(void __iomem *to, const void *from, size_t count)
333 zpci_memcpy_toio(to, from, count);
336 /* Create a virtual mapping cookie for a PCI BAR */
337 void __iomem *pci_iomap(struct pci_dev *pdev, int bar, unsigned long max)
339 struct zpci_dev *zdev = get_zdev(pdev);
343 if ((bar & 7) != bar)
346 idx = zdev->bars[bar].map_idx;
347 spin_lock(&zpci_iomap_lock);
348 zpci_iomap_start[idx].fh = zdev->fh;
349 zpci_iomap_start[idx].bar = bar;
350 spin_unlock(&zpci_iomap_lock);
352 addr = ZPCI_IOMAP_ADDR_BASE | ((u64) idx << 48);
353 return (void __iomem *) addr;
355 EXPORT_SYMBOL_GPL(pci_iomap);
357 void pci_iounmap(struct pci_dev *pdev, void __iomem *addr)
361 idx = (((__force u64) addr) & ~ZPCI_IOMAP_ADDR_BASE) >> 48;
362 spin_lock(&zpci_iomap_lock);
363 zpci_iomap_start[idx].fh = 0;
364 zpci_iomap_start[idx].bar = 0;
365 spin_unlock(&zpci_iomap_lock);
367 EXPORT_SYMBOL_GPL(pci_iounmap);
369 static int pci_read(struct pci_bus *bus, unsigned int devfn, int where,
372 struct zpci_dev *zdev = get_zdev_by_bus(bus);
375 if (!zdev || devfn != ZPCI_DEVFN)
378 ret = zpci_cfg_load(zdev, where, val, size);
383 static int pci_write(struct pci_bus *bus, unsigned int devfn, int where,
386 struct zpci_dev *zdev = get_zdev_by_bus(bus);
389 if (!zdev || devfn != ZPCI_DEVFN)
392 ret = zpci_cfg_store(zdev, where, val, size);
397 static struct pci_ops pci_root_ops = {
402 /* store the last handled bit to implement fair scheduling of devices */
403 static DEFINE_PER_CPU(unsigned long, next_sbit);
405 static void zpci_irq_handler(void *dont, void *need)
407 unsigned long sbit, mbit, last = 0, start = __get_cpu_var(next_sbit);
408 int rescan = 0, max = aisb_max;
409 struct zdev_irq_map *imap;
411 inc_irq_stat(IRQIO_PCI);
415 /* find summary_bit */
416 for_each_set_bit_left_cont(sbit, bucket->aisb, max) {
417 clear_bit(63 - (sbit & 63), bucket->aisb + (sbit >> 6));
420 /* find vector bit */
421 imap = bucket->imap[sbit];
422 for_each_set_bit_left(mbit, &imap->aibv, imap->msi_vecs) {
423 inc_irq_stat(IRQIO_MSI);
424 clear_bit(63 - mbit, &imap->aibv);
426 spin_lock(&imap->lock);
427 if (imap->cb[mbit].handler)
428 imap->cb[mbit].handler(mbit,
429 imap->cb[mbit].data);
430 spin_unlock(&imap->lock);
437 /* scan the skipped bits */
445 /* enable interrupts again */
446 set_irq_ctrl(SIC_IRQ_MODE_SINGLE, NULL, PCI_ISC);
448 /* check again to not lose initiative */
451 sbit = find_first_bit_left(bucket->aisb, max);
457 /* store next device bit to scan */
458 __get_cpu_var(next_sbit) = (++last >= aisb_max) ? 0 : last;
461 /* msi_vecs - number of requested interrupts, 0 place function to error state */
462 static int zpci_setup_msi(struct pci_dev *pdev, int msi_vecs)
464 struct zpci_dev *zdev = get_zdev(pdev);
465 unsigned int aisb, msi_nr;
466 struct msi_desc *msi;
469 /* store the number of used MSI vectors */
470 zdev->irq_map->msi_vecs = min(msi_vecs, ZPCI_NR_MSI_VECS);
472 spin_lock(&bucket->lock);
473 aisb = find_first_zero_bit(bucket->alloc, PAGE_SIZE);
474 /* alloc map exhausted? */
475 if (aisb == PAGE_SIZE) {
476 spin_unlock(&bucket->lock);
479 set_bit(aisb, bucket->alloc);
480 spin_unlock(&bucket->lock);
483 if (aisb + 1 > aisb_max)
486 /* wire up IRQ shortcut pointer */
487 bucket->imap[zdev->aisb] = zdev->irq_map;
488 pr_debug("%s: imap[%u] linked to %p\n", __func__, zdev->aisb, zdev->irq_map);
490 /* TODO: irq number 0 wont be found if we return less than requested MSIs.
491 * ignore it for now and fix in common code.
493 msi_nr = aisb << ZPCI_MSI_VEC_BITS;
495 list_for_each_entry(msi, &pdev->msi_list, list) {
496 rc = zpci_setup_msi_irq(zdev, msi, msi_nr,
497 aisb << ZPCI_MSI_VEC_BITS);
503 rc = zpci_register_airq(zdev, aisb, (u64) &zdev->irq_map->aibv);
505 clear_bit(aisb, bucket->alloc);
506 dev_err(&pdev->dev, "register MSI failed with: %d\n", rc);
509 return (zdev->irq_map->msi_vecs == msi_vecs) ?
510 0 : zdev->irq_map->msi_vecs;
513 static void zpci_teardown_msi(struct pci_dev *pdev)
515 struct zpci_dev *zdev = get_zdev(pdev);
516 struct msi_desc *msi;
519 rc = zpci_unregister_airq(zdev);
521 dev_err(&pdev->dev, "deregister MSI failed with: %d\n", rc);
525 msi = list_first_entry(&pdev->msi_list, struct msi_desc, list);
526 aisb = irq_to_dev_nr(msi->irq);
528 list_for_each_entry(msi, &pdev->msi_list, list)
529 zpci_teardown_msi_irq(zdev, msi);
531 clear_bit(aisb, bucket->alloc);
532 if (aisb + 1 == aisb_max)
536 int arch_setup_msi_irqs(struct pci_dev *pdev, int nvec, int type)
538 pr_debug("%s: requesting %d MSI-X interrupts...", __func__, nvec);
539 if (type != PCI_CAP_ID_MSIX && type != PCI_CAP_ID_MSI)
541 return zpci_setup_msi(pdev, nvec);
544 void arch_teardown_msi_irqs(struct pci_dev *pdev)
546 pr_info("%s: on pdev: %p\n", __func__, pdev);
547 zpci_teardown_msi(pdev);
550 static void zpci_map_resources(struct zpci_dev *zdev)
552 struct pci_dev *pdev = zdev->pdev;
556 for (i = 0; i < PCI_BAR_COUNT; i++) {
557 len = pci_resource_len(pdev, i);
560 pdev->resource[i].start = (resource_size_t) pci_iomap(pdev, i, 0);
561 pdev->resource[i].end = pdev->resource[i].start + len - 1;
562 pr_debug("BAR%i: -> start: %Lx end: %Lx\n",
563 i, pdev->resource[i].start, pdev->resource[i].end);
567 static void zpci_unmap_resources(struct zpci_dev *zdev)
569 struct pci_dev *pdev = zdev->pdev;
573 for (i = 0; i < PCI_BAR_COUNT; i++) {
574 len = pci_resource_len(pdev, i);
577 pci_iounmap(pdev, (void *) pdev->resource[i].start);
581 struct zpci_dev *zpci_alloc_device(void)
583 struct zpci_dev *zdev;
585 /* Alloc memory for our private pci device data */
586 zdev = kzalloc(sizeof(*zdev), GFP_KERNEL);
588 return ERR_PTR(-ENOMEM);
590 /* Alloc aibv & callback space */
591 zdev->irq_map = kmem_cache_zalloc(zdev_irq_cache, GFP_KERNEL);
594 WARN_ON((u64) zdev->irq_map & 0xff);
599 return ERR_PTR(-ENOMEM);
602 void zpci_free_device(struct zpci_dev *zdev)
604 kmem_cache_free(zdev_irq_cache, zdev->irq_map);
609 * Too late for any s390 specific setup, since interrupts must be set up
610 * already which requires DMA setup too and the pci scan will access the
611 * config space, which only works if the function handle is enabled.
613 int pcibios_enable_device(struct pci_dev *pdev, int mask)
615 struct resource *res;
619 pci_read_config_word(pdev, PCI_COMMAND, &cmd);
621 for (i = 0; i < PCI_BAR_COUNT; i++) {
622 res = &pdev->resource[i];
624 if (res->flags & IORESOURCE_IO)
627 if (res->flags & IORESOURCE_MEM)
628 cmd |= PCI_COMMAND_MEMORY;
630 pci_write_config_word(pdev, PCI_COMMAND, cmd);
634 int pcibios_add_platform_entries(struct pci_dev *pdev)
636 return zpci_sysfs_add_device(&pdev->dev);
639 int zpci_request_irq(unsigned int irq, irq_handler_t handler, void *data)
641 int msi_nr = irq_to_msi_nr(irq);
642 struct zdev_irq_map *imap;
643 struct msi_desc *msi;
645 msi = irq_get_msi_desc(irq);
649 imap = get_imap(irq);
650 spin_lock_init(&imap->lock);
652 pr_debug("%s: register handler for IRQ:MSI %d:%d\n", __func__, irq >> 6, msi_nr);
653 imap->cb[msi_nr].handler = handler;
654 imap->cb[msi_nr].data = data;
657 * The generic MSI code returns with the interrupt disabled on the
658 * card, using the MSI mask bits. Firmware doesn't appear to unmask
659 * at that level, so we do it here by hand.
661 zpci_msi_set_mask_bits(msi, 1, 0);
665 void zpci_free_irq(unsigned int irq)
667 struct zdev_irq_map *imap = get_imap(irq);
668 int msi_nr = irq_to_msi_nr(irq);
671 pr_debug("%s: for irq: %d\n", __func__, irq);
673 spin_lock_irqsave(&imap->lock, flags);
674 imap->cb[msi_nr].handler = NULL;
675 imap->cb[msi_nr].data = NULL;
676 spin_unlock_irqrestore(&imap->lock, flags);
679 int request_irq(unsigned int irq, irq_handler_t handler,
680 unsigned long irqflags, const char *devname, void *dev_id)
682 pr_debug("%s: irq: %d handler: %p flags: %lx dev: %s\n",
683 __func__, irq, handler, irqflags, devname);
685 return zpci_request_irq(irq, handler, dev_id);
687 EXPORT_SYMBOL_GPL(request_irq);
689 void free_irq(unsigned int irq, void *dev_id)
693 EXPORT_SYMBOL_GPL(free_irq);
695 static int __init zpci_irq_init(void)
699 bucket = kzalloc(sizeof(*bucket), GFP_KERNEL);
703 bucket->aisb = (unsigned long *) get_zeroed_page(GFP_KERNEL);
709 bucket->alloc = (unsigned long *) get_zeroed_page(GFP_KERNEL);
710 if (!bucket->alloc) {
715 isc_register(PCI_ISC);
716 zpci_irq_si = s390_register_adapter_interrupt(&zpci_irq_handler, NULL, PCI_ISC);
717 if (IS_ERR(zpci_irq_si)) {
718 rc = PTR_ERR(zpci_irq_si);
723 for_each_online_cpu(cpu)
724 per_cpu(next_sbit, cpu) = 0;
726 spin_lock_init(&bucket->lock);
727 /* set summary to 1 to be called every time for the ISC */
729 set_irq_ctrl(SIC_IRQ_MODE_SINGLE, NULL, PCI_ISC);
733 isc_unregister(PCI_ISC);
734 free_page((unsigned long) bucket->alloc);
736 free_page((unsigned long) bucket->aisb);
742 static void zpci_irq_exit(void)
744 free_page((unsigned long) bucket->alloc);
745 free_page((unsigned long) bucket->aisb);
746 s390_unregister_adapter_interrupt(zpci_irq_si, PCI_ISC);
747 isc_unregister(PCI_ISC);
751 static struct resource *zpci_alloc_bus_resource(unsigned long start, unsigned long size,
752 unsigned long flags, int domain)
758 r = kzalloc(sizeof(*r), GFP_KERNEL);
760 return ERR_PTR(-ENOMEM);
762 r->end = r->start + size - 1;
764 r->parent = &iomem_resource;
765 name = kmalloc(18, GFP_KERNEL);
768 return ERR_PTR(-ENOMEM);
770 sprintf(name, "PCI Bus: %04x:%02x", domain, ZPCI_BUS_NR);
773 rc = request_resource(&iomem_resource, r);
775 pr_debug("request resource %pR failed\n", r);
779 static int zpci_alloc_iomap(struct zpci_dev *zdev)
783 spin_lock(&zpci_iomap_lock);
784 entry = find_first_zero_bit(zpci_iomap, ZPCI_IOMAP_MAX_ENTRIES);
785 if (entry == ZPCI_IOMAP_MAX_ENTRIES) {
786 spin_unlock(&zpci_iomap_lock);
789 set_bit(entry, zpci_iomap);
790 spin_unlock(&zpci_iomap_lock);
794 static void zpci_free_iomap(struct zpci_dev *zdev, int entry)
796 spin_lock(&zpci_iomap_lock);
797 memset(&zpci_iomap_start[entry], 0, sizeof(struct zpci_iomap_entry));
798 clear_bit(entry, zpci_iomap);
799 spin_unlock(&zpci_iomap_lock);
802 int pcibios_add_device(struct pci_dev *pdev)
804 struct zpci_dev *zdev = get_zdev(pdev);
807 zpci_debug_init_device(zdev);
808 zpci_fmb_enable_device(zdev);
809 zpci_map_resources(zdev);
814 void pcibios_release_device(struct pci_dev *pdev)
816 struct zpci_dev *zdev = get_zdev(pdev);
818 zpci_unmap_resources(zdev);
819 zpci_fmb_disable_device(zdev);
820 zpci_debug_exit_device(zdev);
824 static int zpci_scan_bus(struct zpci_dev *zdev)
826 struct resource *res;
827 LIST_HEAD(resources);
830 /* allocate mapping entry for each used bar */
831 for (i = 0; i < PCI_BAR_COUNT; i++) {
832 unsigned long addr, size, flags;
835 if (!zdev->bars[i].size)
837 entry = zpci_alloc_iomap(zdev);
840 zdev->bars[i].map_idx = entry;
842 /* only MMIO is supported */
843 flags = IORESOURCE_MEM;
844 if (zdev->bars[i].val & 8)
845 flags |= IORESOURCE_PREFETCH;
846 if (zdev->bars[i].val & 4)
847 flags |= IORESOURCE_MEM_64;
849 addr = ZPCI_IOMAP_ADDR_BASE + ((u64) entry << 48);
851 size = 1UL << zdev->bars[i].size;
853 res = zpci_alloc_bus_resource(addr, size, flags, zdev->domain);
855 zpci_free_iomap(zdev, entry);
858 pci_add_resource(&resources, res);
861 zdev->bus = pci_scan_root_bus(NULL, ZPCI_BUS_NR, &pci_root_ops,
866 zdev->bus->max_bus_speed = zdev->max_bus_speed;
870 static int zpci_alloc_domain(struct zpci_dev *zdev)
872 spin_lock(&zpci_domain_lock);
873 zdev->domain = find_first_zero_bit(zpci_domain, ZPCI_NR_DEVICES);
874 if (zdev->domain == ZPCI_NR_DEVICES) {
875 spin_unlock(&zpci_domain_lock);
878 set_bit(zdev->domain, zpci_domain);
879 spin_unlock(&zpci_domain_lock);
883 static void zpci_free_domain(struct zpci_dev *zdev)
885 spin_lock(&zpci_domain_lock);
886 clear_bit(zdev->domain, zpci_domain);
887 spin_unlock(&zpci_domain_lock);
890 int zpci_enable_device(struct zpci_dev *zdev)
894 rc = clp_enable_fh(zdev, ZPCI_NR_DMA_SPACES);
897 pr_info("Enabled fh: 0x%x fid: 0x%x\n", zdev->fh, zdev->fid);
899 rc = zpci_dma_init_device(zdev);
905 clp_disable_fh(zdev);
909 EXPORT_SYMBOL_GPL(zpci_enable_device);
911 int zpci_disable_device(struct zpci_dev *zdev)
913 zpci_dma_exit_device(zdev);
914 return clp_disable_fh(zdev);
916 EXPORT_SYMBOL_GPL(zpci_disable_device);
918 int zpci_create_device(struct zpci_dev *zdev)
922 rc = zpci_alloc_domain(zdev);
926 if (zdev->state == ZPCI_FN_STATE_CONFIGURED) {
927 rc = zpci_enable_device(zdev);
931 zdev->state = ZPCI_FN_STATE_ONLINE;
933 rc = zpci_scan_bus(zdev);
937 mutex_lock(&zpci_list_lock);
938 list_add_tail(&zdev->entry, &zpci_list);
940 hotplug_ops->create_slot(zdev);
941 mutex_unlock(&zpci_list_lock);
946 if (zdev->state == ZPCI_FN_STATE_ONLINE)
947 zpci_disable_device(zdev);
949 zpci_free_domain(zdev);
954 void zpci_stop_device(struct zpci_dev *zdev)
956 zpci_dma_exit_device(zdev);
958 * Note: SCLP disables fh via set-pci-fn so don't
962 EXPORT_SYMBOL_GPL(zpci_stop_device);
964 static inline int barsize(u8 size)
966 return (size) ? (1 << size) >> 10 : 0;
969 static int zpci_mem_init(void)
971 zdev_irq_cache = kmem_cache_create("PCI_IRQ_cache", sizeof(struct zdev_irq_map),
972 L1_CACHE_BYTES, SLAB_HWCACHE_ALIGN, NULL);
976 zdev_fmb_cache = kmem_cache_create("PCI_FMB_cache", sizeof(struct zpci_fmb),
981 /* TODO: use realloc */
982 zpci_iomap_start = kzalloc(ZPCI_IOMAP_MAX_ENTRIES * sizeof(*zpci_iomap_start),
984 if (!zpci_iomap_start)
989 kmem_cache_destroy(zdev_fmb_cache);
991 kmem_cache_destroy(zdev_irq_cache);
996 static void zpci_mem_exit(void)
998 kfree(zpci_iomap_start);
999 kmem_cache_destroy(zdev_irq_cache);
1000 kmem_cache_destroy(zdev_fmb_cache);
1003 void zpci_register_hp_ops(struct pci_hp_callback_ops *ops)
1005 mutex_lock(&zpci_list_lock);
1007 mutex_unlock(&zpci_list_lock);
1009 EXPORT_SYMBOL_GPL(zpci_register_hp_ops);
1011 void zpci_deregister_hp_ops(void)
1013 mutex_lock(&zpci_list_lock);
1015 mutex_unlock(&zpci_list_lock);
1017 EXPORT_SYMBOL_GPL(zpci_deregister_hp_ops);
1019 unsigned int s390_pci_probe;
1020 EXPORT_SYMBOL_GPL(s390_pci_probe);
1022 char * __init pcibios_setup(char *str)
1024 if (!strcmp(str, "on")) {
1031 static int __init pci_base_init(void)
1035 if (!s390_pci_probe)
1038 if (!test_facility(2) || !test_facility(69)
1039 || !test_facility(71) || !test_facility(72))
1042 pr_info("Probing PCI hardware: PCI:%d SID:%d AEN:%d\n",
1043 test_facility(69), test_facility(70),
1046 rc = zpci_debug_init();
1050 rc = zpci_mem_init();
1054 rc = zpci_msihash_init();
1058 rc = zpci_irq_init();
1062 rc = zpci_dma_init();
1066 rc = clp_find_pci_devices();
1077 zpci_msihash_exit();
1084 subsys_initcall(pci_base_init);