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_NR_DEVICES CONFIG_PCI_NR_FUNCTIONS
47 /* list of all detected zpci devices */
48 static LIST_HEAD(zpci_list
);
49 static DEFINE_MUTEX(zpci_list_lock
);
51 static void zpci_enable_irq(struct irq_data
*data
);
52 static void zpci_disable_irq(struct irq_data
*data
);
54 static struct irq_chip zpci_irq_chip
= {
56 .irq_unmask
= zpci_enable_irq
,
57 .irq_mask
= zpci_disable_irq
,
60 static DECLARE_BITMAP(zpci_domain
, ZPCI_NR_DEVICES
);
61 static DEFINE_SPINLOCK(zpci_domain_lock
);
63 static struct airq_iv
*zpci_aisb_iv
;
64 static struct airq_iv
*zpci_aibv
[ZPCI_NR_DEVICES
];
66 /* Adapter interrupt definitions */
67 static void zpci_irq_handler(struct airq_struct
*airq
);
69 static struct airq_struct zpci_airq
= {
70 .handler
= zpci_irq_handler
,
75 static DEFINE_SPINLOCK(zpci_iomap_lock
);
76 static DECLARE_BITMAP(zpci_iomap
, ZPCI_IOMAP_MAX_ENTRIES
);
77 struct zpci_iomap_entry
*zpci_iomap_start
;
78 EXPORT_SYMBOL_GPL(zpci_iomap_start
);
80 static struct kmem_cache
*zdev_fmb_cache
;
82 struct zpci_dev
*get_zdev(struct pci_dev
*pdev
)
84 return (struct zpci_dev
*) pdev
->sysdata
;
87 struct zpci_dev
*get_zdev_by_fid(u32 fid
)
89 struct zpci_dev
*tmp
, *zdev
= NULL
;
91 mutex_lock(&zpci_list_lock
);
92 list_for_each_entry(tmp
, &zpci_list
, entry
) {
93 if (tmp
->fid
== fid
) {
98 mutex_unlock(&zpci_list_lock
);
102 bool zpci_fid_present(u32 fid
)
104 return (get_zdev_by_fid(fid
) != NULL
) ? true : false;
107 static struct zpci_dev
*get_zdev_by_bus(struct pci_bus
*bus
)
109 return (bus
&& bus
->sysdata
) ? (struct zpci_dev
*) bus
->sysdata
: NULL
;
112 int pci_domain_nr(struct pci_bus
*bus
)
114 return ((struct zpci_dev
*) bus
->sysdata
)->domain
;
116 EXPORT_SYMBOL_GPL(pci_domain_nr
);
118 int pci_proc_domain(struct pci_bus
*bus
)
120 return pci_domain_nr(bus
);
122 EXPORT_SYMBOL_GPL(pci_proc_domain
);
124 /* Modify PCI: Register adapter interruptions */
125 static int zpci_set_airq(struct zpci_dev
*zdev
)
127 u64 req
= ZPCI_CREATE_REQ(zdev
->fh
, 0, ZPCI_MOD_FC_REG_INT
);
128 struct zpci_fib
*fib
;
131 fib
= (void *) get_zeroed_page(GFP_KERNEL
);
136 fib
->sum
= 1; /* enable summary notifications */
137 fib
->noi
= airq_iv_end(zdev
->aibv
);
138 fib
->aibv
= (unsigned long) zdev
->aibv
->vector
;
139 fib
->aibvo
= 0; /* each zdev has its own interrupt vector */
140 fib
->aisb
= (unsigned long) zpci_aisb_iv
->vector
+ (zdev
->aisb
/64)*8;
141 fib
->aisbo
= zdev
->aisb
& 63;
143 rc
= zpci_mod_fc(req
, fib
);
144 pr_debug("%s mpcifc returned noi: %d\n", __func__
, fib
->noi
);
146 free_page((unsigned long) fib
);
150 struct mod_pci_args
{
157 static int mod_pci(struct zpci_dev
*zdev
, int fn
, u8 dmaas
, struct mod_pci_args
*args
)
159 u64 req
= ZPCI_CREATE_REQ(zdev
->fh
, dmaas
, fn
);
160 struct zpci_fib
*fib
;
163 /* The FIB must be available even if it's not used */
164 fib
= (void *) get_zeroed_page(GFP_KERNEL
);
168 fib
->pba
= args
->base
;
169 fib
->pal
= args
->limit
;
170 fib
->iota
= args
->iota
;
171 fib
->fmb_addr
= args
->fmb_addr
;
173 rc
= zpci_mod_fc(req
, fib
);
174 free_page((unsigned long) fib
);
178 /* Modify PCI: Register I/O address translation parameters */
179 int zpci_register_ioat(struct zpci_dev
*zdev
, u8 dmaas
,
180 u64 base
, u64 limit
, u64 iota
)
182 struct mod_pci_args args
= { base
, limit
, iota
, 0 };
184 WARN_ON_ONCE(iota
& 0x3fff);
185 args
.iota
|= ZPCI_IOTA_RTTO_FLAG
;
186 return mod_pci(zdev
, ZPCI_MOD_FC_REG_IOAT
, dmaas
, &args
);
189 /* Modify PCI: Unregister I/O address translation parameters */
190 int zpci_unregister_ioat(struct zpci_dev
*zdev
, u8 dmaas
)
192 struct mod_pci_args args
= { 0, 0, 0, 0 };
194 return mod_pci(zdev
, ZPCI_MOD_FC_DEREG_IOAT
, dmaas
, &args
);
197 /* Modify PCI: Unregister adapter interruptions */
198 static int zpci_clear_airq(struct zpci_dev
*zdev
)
200 struct mod_pci_args args
= { 0, 0, 0, 0 };
202 return mod_pci(zdev
, ZPCI_MOD_FC_DEREG_INT
, 0, &args
);
205 /* Modify PCI: Set PCI function measurement parameters */
206 int zpci_fmb_enable_device(struct zpci_dev
*zdev
)
208 struct mod_pci_args args
= { 0, 0, 0, 0 };
213 zdev
->fmb
= kmem_cache_zalloc(zdev_fmb_cache
, GFP_KERNEL
);
216 WARN_ON((u64
) zdev
->fmb
& 0xf);
218 args
.fmb_addr
= virt_to_phys(zdev
->fmb
);
219 return mod_pci(zdev
, ZPCI_MOD_FC_SET_MEASURE
, 0, &args
);
222 /* Modify PCI: Disable PCI function measurement */
223 int zpci_fmb_disable_device(struct zpci_dev
*zdev
)
225 struct mod_pci_args args
= { 0, 0, 0, 0 };
231 /* Function measurement is disabled if fmb address is zero */
232 rc
= mod_pci(zdev
, ZPCI_MOD_FC_SET_MEASURE
, 0, &args
);
234 kmem_cache_free(zdev_fmb_cache
, zdev
->fmb
);
239 #define ZPCI_PCIAS_CFGSPC 15
241 static int zpci_cfg_load(struct zpci_dev
*zdev
, int offset
, u32
*val
, u8 len
)
243 u64 req
= ZPCI_CREATE_REQ(zdev
->fh
, ZPCI_PCIAS_CFGSPC
, len
);
247 rc
= zpci_load(&data
, req
, offset
);
249 data
= data
<< ((8 - len
) * 8);
250 data
= le64_to_cpu(data
);
257 static int zpci_cfg_store(struct zpci_dev
*zdev
, int offset
, u32 val
, u8 len
)
259 u64 req
= ZPCI_CREATE_REQ(zdev
->fh
, ZPCI_PCIAS_CFGSPC
, len
);
263 data
= cpu_to_le64(data
);
264 data
= data
>> ((8 - len
) * 8);
265 rc
= zpci_store(data
, req
, offset
);
269 static int zpci_msi_set_mask_bits(struct msi_desc
*msi
, u32 mask
, u32 flag
)
274 if (msi
->msi_attrib
.is_msix
) {
275 offset
= msi
->msi_attrib
.entry_nr
* PCI_MSIX_ENTRY_SIZE
+
276 PCI_MSIX_ENTRY_VECTOR_CTRL
;
277 msi
->masked
= readl(msi
->mask_base
+ offset
);
278 writel(flag
, msi
->mask_base
+ offset
);
279 } else if (msi
->msi_attrib
.maskbit
) {
280 pos
= (long) msi
->mask_base
;
281 pci_read_config_dword(msi
->dev
, pos
, &mask_bits
);
282 mask_bits
&= ~(mask
);
283 mask_bits
|= flag
& mask
;
284 pci_write_config_dword(msi
->dev
, pos
, mask_bits
);
288 msi
->msi_attrib
.maskbit
= !!flag
;
292 static void zpci_enable_irq(struct irq_data
*data
)
294 struct msi_desc
*msi
= irq_get_msi_desc(data
->irq
);
296 zpci_msi_set_mask_bits(msi
, 1, 0);
299 static void zpci_disable_irq(struct irq_data
*data
)
301 struct msi_desc
*msi
= irq_get_msi_desc(data
->irq
);
303 zpci_msi_set_mask_bits(msi
, 1, 1);
306 void pcibios_fixup_bus(struct pci_bus
*bus
)
310 resource_size_t
pcibios_align_resource(void *data
, const struct resource
*res
,
311 resource_size_t size
,
312 resource_size_t align
)
317 /* combine single writes by using store-block insn */
318 void __iowrite64_copy(void __iomem
*to
, const void *from
, size_t count
)
320 zpci_memcpy_toio(to
, from
, count
);
323 /* Create a virtual mapping cookie for a PCI BAR */
324 void __iomem
*pci_iomap(struct pci_dev
*pdev
, int bar
, unsigned long max
)
326 struct zpci_dev
*zdev
= get_zdev(pdev
);
330 if ((bar
& 7) != bar
)
333 idx
= zdev
->bars
[bar
].map_idx
;
334 spin_lock(&zpci_iomap_lock
);
335 zpci_iomap_start
[idx
].fh
= zdev
->fh
;
336 zpci_iomap_start
[idx
].bar
= bar
;
337 spin_unlock(&zpci_iomap_lock
);
339 addr
= ZPCI_IOMAP_ADDR_BASE
| ((u64
) idx
<< 48);
340 return (void __iomem
*) addr
;
342 EXPORT_SYMBOL_GPL(pci_iomap
);
344 void pci_iounmap(struct pci_dev
*pdev
, void __iomem
*addr
)
348 idx
= (((__force u64
) addr
) & ~ZPCI_IOMAP_ADDR_BASE
) >> 48;
349 spin_lock(&zpci_iomap_lock
);
350 zpci_iomap_start
[idx
].fh
= 0;
351 zpci_iomap_start
[idx
].bar
= 0;
352 spin_unlock(&zpci_iomap_lock
);
354 EXPORT_SYMBOL_GPL(pci_iounmap
);
356 static int pci_read(struct pci_bus
*bus
, unsigned int devfn
, int where
,
359 struct zpci_dev
*zdev
= get_zdev_by_bus(bus
);
362 if (!zdev
|| devfn
!= ZPCI_DEVFN
)
365 ret
= zpci_cfg_load(zdev
, where
, val
, size
);
370 static int pci_write(struct pci_bus
*bus
, unsigned int devfn
, int where
,
373 struct zpci_dev
*zdev
= get_zdev_by_bus(bus
);
376 if (!zdev
|| devfn
!= ZPCI_DEVFN
)
379 ret
= zpci_cfg_store(zdev
, where
, val
, size
);
384 static struct pci_ops pci_root_ops
= {
389 static void zpci_irq_handler(struct airq_struct
*airq
)
391 unsigned long si
, ai
;
392 struct airq_iv
*aibv
;
395 inc_irq_stat(IRQIO_PCI
);
397 /* Scan adapter summary indicator bit vector */
398 si
= airq_iv_scan(zpci_aisb_iv
, si
, airq_iv_end(zpci_aisb_iv
));
401 /* End of second scan with interrupts on. */
403 /* First scan complete, reenable interrupts. */
404 zpci_set_irq_ctrl(SIC_IRQ_MODE_SINGLE
, NULL
, PCI_ISC
);
409 /* Scan the adapter interrupt vector for this device. */
410 aibv
= zpci_aibv
[si
];
412 ai
= airq_iv_scan(aibv
, ai
, airq_iv_end(aibv
));
415 inc_irq_stat(IRQIO_MSI
);
416 airq_iv_lock(aibv
, ai
);
417 generic_handle_irq(airq_iv_get_data(aibv
, ai
));
418 airq_iv_unlock(aibv
, ai
);
423 int arch_setup_msi_irqs(struct pci_dev
*pdev
, int nvec
, int type
)
425 struct zpci_dev
*zdev
= get_zdev(pdev
);
426 unsigned int hwirq
, irq
, msi_vecs
;
428 struct msi_desc
*msi
;
432 pr_debug("%s: requesting %d MSI-X interrupts...", __func__
, nvec
);
433 if (type
!= PCI_CAP_ID_MSIX
&& type
!= PCI_CAP_ID_MSI
)
435 msi_vecs
= min(nvec
, ZPCI_MSI_VEC_MAX
);
436 msi_vecs
= min_t(unsigned int, msi_vecs
, CONFIG_PCI_NR_MSI
);
438 /* Allocate adapter summary indicator bit */
440 aisb
= airq_iv_alloc_bit(zpci_aisb_iv
);
445 /* Create adapter interrupt vector */
447 zdev
->aibv
= airq_iv_create(msi_vecs
, AIRQ_IV_DATA
| AIRQ_IV_BITLOCK
);
451 /* Wire up shortcut pointer */
452 zpci_aibv
[aisb
] = zdev
->aibv
;
454 /* Request MSI interrupts */
456 list_for_each_entry(msi
, &pdev
->msi_list
, list
) {
458 irq
= irq_alloc_desc(0); /* Alloc irq on node 0 */
461 rc
= irq_set_msi_desc(irq
, msi
);
464 irq_set_chip_and_handler(irq
, &zpci_irq_chip
,
467 msg
.address_lo
= zdev
->msi_addr
& 0xffffffff;
468 msg
.address_hi
= zdev
->msi_addr
>> 32;
469 write_msi_msg(irq
, &msg
);
470 airq_iv_set_data(zdev
->aibv
, hwirq
, irq
);
474 /* Enable adapter interrupts */
475 rc
= zpci_set_airq(zdev
);
479 return (msi_vecs
== nvec
) ? 0 : msi_vecs
;
482 list_for_each_entry(msi
, &pdev
->msi_list
, list
) {
485 irq_set_msi_desc(msi
->irq
, NULL
);
486 irq_free_desc(msi
->irq
);
487 msi
->msg
.address_lo
= 0;
488 msi
->msg
.address_hi
= 0;
492 zpci_aibv
[aisb
] = NULL
;
493 airq_iv_release(zdev
->aibv
);
495 airq_iv_free_bit(zpci_aisb_iv
, aisb
);
497 dev_err(&pdev
->dev
, "register MSI failed with: %d\n", rc
);
501 void arch_teardown_msi_irqs(struct pci_dev
*pdev
)
503 struct zpci_dev
*zdev
= get_zdev(pdev
);
504 struct msi_desc
*msi
;
507 pr_info("%s: on pdev: %p\n", __func__
, pdev
);
509 /* Disable adapter interrupts */
510 rc
= zpci_clear_airq(zdev
);
512 dev_err(&pdev
->dev
, "deregister MSI failed with: %d\n", rc
);
516 /* Release MSI interrupts */
517 list_for_each_entry(msi
, &pdev
->msi_list
, list
) {
518 zpci_msi_set_mask_bits(msi
, 1, 1);
519 irq_set_msi_desc(msi
->irq
, NULL
);
520 irq_free_desc(msi
->irq
);
521 msi
->msg
.address_lo
= 0;
522 msi
->msg
.address_hi
= 0;
527 zpci_aibv
[zdev
->aisb
] = NULL
;
528 airq_iv_release(zdev
->aibv
);
529 airq_iv_free_bit(zpci_aisb_iv
, zdev
->aisb
);
532 static void zpci_map_resources(struct zpci_dev
*zdev
)
534 struct pci_dev
*pdev
= zdev
->pdev
;
538 for (i
= 0; i
< PCI_BAR_COUNT
; i
++) {
539 len
= pci_resource_len(pdev
, i
);
542 pdev
->resource
[i
].start
= (resource_size_t
) pci_iomap(pdev
, i
, 0);
543 pdev
->resource
[i
].end
= pdev
->resource
[i
].start
+ len
- 1;
547 static void zpci_unmap_resources(struct zpci_dev
*zdev
)
549 struct pci_dev
*pdev
= zdev
->pdev
;
553 for (i
= 0; i
< PCI_BAR_COUNT
; i
++) {
554 len
= pci_resource_len(pdev
, i
);
557 pci_iounmap(pdev
, (void *) pdev
->resource
[i
].start
);
561 struct zpci_dev
*zpci_alloc_device(void)
563 struct zpci_dev
*zdev
;
565 /* Alloc memory for our private pci device data */
566 zdev
= kzalloc(sizeof(*zdev
), GFP_KERNEL
);
567 return zdev
? : ERR_PTR(-ENOMEM
);
570 void zpci_free_device(struct zpci_dev
*zdev
)
575 int pcibios_add_platform_entries(struct pci_dev
*pdev
)
577 return zpci_sysfs_add_device(&pdev
->dev
);
580 static int __init
zpci_irq_init(void)
584 rc
= register_adapter_interrupt(&zpci_airq
);
587 /* Set summary to 1 to be called every time for the ISC. */
588 *zpci_airq
.lsi_ptr
= 1;
591 zpci_aisb_iv
= airq_iv_create(ZPCI_NR_DEVICES
, AIRQ_IV_ALLOC
);
595 zpci_set_irq_ctrl(SIC_IRQ_MODE_SINGLE
, NULL
, PCI_ISC
);
599 unregister_adapter_interrupt(&zpci_airq
);
604 static void zpci_irq_exit(void)
606 airq_iv_release(zpci_aisb_iv
);
607 unregister_adapter_interrupt(&zpci_airq
);
610 static struct resource
*zpci_alloc_bus_resource(unsigned long start
, unsigned long size
,
611 unsigned long flags
, int domain
)
617 r
= kzalloc(sizeof(*r
), GFP_KERNEL
);
619 return ERR_PTR(-ENOMEM
);
621 r
->end
= r
->start
+ size
- 1;
623 r
->parent
= &iomem_resource
;
624 name
= kmalloc(18, GFP_KERNEL
);
627 return ERR_PTR(-ENOMEM
);
629 sprintf(name
, "PCI Bus: %04x:%02x", domain
, ZPCI_BUS_NR
);
632 rc
= request_resource(&iomem_resource
, r
);
634 pr_debug("request resource %pR failed\n", r
);
638 static int zpci_alloc_iomap(struct zpci_dev
*zdev
)
642 spin_lock(&zpci_iomap_lock
);
643 entry
= find_first_zero_bit(zpci_iomap
, ZPCI_IOMAP_MAX_ENTRIES
);
644 if (entry
== ZPCI_IOMAP_MAX_ENTRIES
) {
645 spin_unlock(&zpci_iomap_lock
);
648 set_bit(entry
, zpci_iomap
);
649 spin_unlock(&zpci_iomap_lock
);
653 static void zpci_free_iomap(struct zpci_dev
*zdev
, int entry
)
655 spin_lock(&zpci_iomap_lock
);
656 memset(&zpci_iomap_start
[entry
], 0, sizeof(struct zpci_iomap_entry
));
657 clear_bit(entry
, zpci_iomap
);
658 spin_unlock(&zpci_iomap_lock
);
661 int pcibios_add_device(struct pci_dev
*pdev
)
663 struct zpci_dev
*zdev
= get_zdev(pdev
);
664 struct resource
*res
;
668 zpci_map_resources(zdev
);
670 for (i
= 0; i
< PCI_BAR_COUNT
; i
++) {
671 res
= &pdev
->resource
[i
];
672 if (res
->parent
|| !res
->flags
)
674 pci_claim_resource(pdev
, i
);
680 int pcibios_enable_device(struct pci_dev
*pdev
, int mask
)
682 struct zpci_dev
*zdev
= get_zdev(pdev
);
683 struct resource
*res
;
688 zpci_debug_init_device(zdev
);
689 zpci_fmb_enable_device(zdev
);
690 zpci_map_resources(zdev
);
692 pci_read_config_word(pdev
, PCI_COMMAND
, &cmd
);
693 for (i
= 0; i
< PCI_BAR_COUNT
; i
++) {
694 res
= &pdev
->resource
[i
];
696 if (res
->flags
& IORESOURCE_IO
)
699 if (res
->flags
& IORESOURCE_MEM
)
700 cmd
|= PCI_COMMAND_MEMORY
;
702 pci_write_config_word(pdev
, PCI_COMMAND
, cmd
);
706 void pcibios_disable_device(struct pci_dev
*pdev
)
708 struct zpci_dev
*zdev
= get_zdev(pdev
);
710 zpci_unmap_resources(zdev
);
711 zpci_fmb_disable_device(zdev
);
712 zpci_debug_exit_device(zdev
);
716 static int zpci_scan_bus(struct zpci_dev
*zdev
)
718 struct resource
*res
;
719 LIST_HEAD(resources
);
722 /* allocate mapping entry for each used bar */
723 for (i
= 0; i
< PCI_BAR_COUNT
; i
++) {
724 unsigned long addr
, size
, flags
;
727 if (!zdev
->bars
[i
].size
)
729 entry
= zpci_alloc_iomap(zdev
);
732 zdev
->bars
[i
].map_idx
= entry
;
734 /* only MMIO is supported */
735 flags
= IORESOURCE_MEM
;
736 if (zdev
->bars
[i
].val
& 8)
737 flags
|= IORESOURCE_PREFETCH
;
738 if (zdev
->bars
[i
].val
& 4)
739 flags
|= IORESOURCE_MEM_64
;
741 addr
= ZPCI_IOMAP_ADDR_BASE
+ ((u64
) entry
<< 48);
743 size
= 1UL << zdev
->bars
[i
].size
;
745 res
= zpci_alloc_bus_resource(addr
, size
, flags
, zdev
->domain
);
747 zpci_free_iomap(zdev
, entry
);
750 pci_add_resource(&resources
, res
);
753 zdev
->bus
= pci_scan_root_bus(NULL
, ZPCI_BUS_NR
, &pci_root_ops
,
758 zdev
->bus
->max_bus_speed
= zdev
->max_bus_speed
;
762 static int zpci_alloc_domain(struct zpci_dev
*zdev
)
764 spin_lock(&zpci_domain_lock
);
765 zdev
->domain
= find_first_zero_bit(zpci_domain
, ZPCI_NR_DEVICES
);
766 if (zdev
->domain
== ZPCI_NR_DEVICES
) {
767 spin_unlock(&zpci_domain_lock
);
770 set_bit(zdev
->domain
, zpci_domain
);
771 spin_unlock(&zpci_domain_lock
);
775 static void zpci_free_domain(struct zpci_dev
*zdev
)
777 spin_lock(&zpci_domain_lock
);
778 clear_bit(zdev
->domain
, zpci_domain
);
779 spin_unlock(&zpci_domain_lock
);
782 int zpci_enable_device(struct zpci_dev
*zdev
)
786 rc
= clp_enable_fh(zdev
, ZPCI_NR_DMA_SPACES
);
789 pr_info("Enabled fh: 0x%x fid: 0x%x\n", zdev
->fh
, zdev
->fid
);
791 rc
= zpci_dma_init_device(zdev
);
795 zdev
->state
= ZPCI_FN_STATE_ONLINE
;
799 clp_disable_fh(zdev
);
803 EXPORT_SYMBOL_GPL(zpci_enable_device
);
805 int zpci_disable_device(struct zpci_dev
*zdev
)
807 zpci_dma_exit_device(zdev
);
808 return clp_disable_fh(zdev
);
810 EXPORT_SYMBOL_GPL(zpci_disable_device
);
812 int zpci_create_device(struct zpci_dev
*zdev
)
816 rc
= zpci_alloc_domain(zdev
);
820 if (zdev
->state
== ZPCI_FN_STATE_CONFIGURED
) {
821 rc
= zpci_enable_device(zdev
);
825 rc
= zpci_scan_bus(zdev
);
829 mutex_lock(&zpci_list_lock
);
830 list_add_tail(&zdev
->entry
, &zpci_list
);
831 mutex_unlock(&zpci_list_lock
);
833 zpci_init_slot(zdev
);
838 if (zdev
->state
== ZPCI_FN_STATE_ONLINE
)
839 zpci_disable_device(zdev
);
841 zpci_free_domain(zdev
);
846 void zpci_stop_device(struct zpci_dev
*zdev
)
848 zpci_dma_exit_device(zdev
);
850 * Note: SCLP disables fh via set-pci-fn so don't
854 EXPORT_SYMBOL_GPL(zpci_stop_device
);
856 static inline int barsize(u8 size
)
858 return (size
) ? (1 << size
) >> 10 : 0;
861 static int zpci_mem_init(void)
863 zdev_fmb_cache
= kmem_cache_create("PCI_FMB_cache", sizeof(struct zpci_fmb
),
868 /* TODO: use realloc */
869 zpci_iomap_start
= kzalloc(ZPCI_IOMAP_MAX_ENTRIES
* sizeof(*zpci_iomap_start
),
871 if (!zpci_iomap_start
)
876 kmem_cache_destroy(zdev_fmb_cache
);
881 static void zpci_mem_exit(void)
883 kfree(zpci_iomap_start
);
884 kmem_cache_destroy(zdev_fmb_cache
);
887 static unsigned int s390_pci_probe
;
889 char * __init
pcibios_setup(char *str
)
891 if (!strcmp(str
, "on")) {
898 static int __init
pci_base_init(void)
905 if (!test_facility(2) || !test_facility(69)
906 || !test_facility(71) || !test_facility(72))
909 pr_info("Probing PCI hardware: PCI:%d SID:%d AEN:%d\n",
910 test_facility(69), test_facility(70),
913 rc
= zpci_debug_init();
917 rc
= zpci_mem_init();
921 rc
= zpci_irq_init();
925 rc
= zpci_dma_init();
929 rc
= clp_find_pci_devices();
946 subsys_initcall_sync(pci_base_init
);