14 #include <linux/kernel.h>
15 #include <linux/pci.h>
17 #include <linux/string.h>
24 #include <asm/sections.h>
27 #include <asm/pci-bridge.h>
28 #include <asm/machdep.h>
31 #include <asm/iommu.h>
43 strlcpy(pfix, dev_name(&pe->
pdev->dev),
sizeof(pfix));
47 return printk(
"pci %s%s: [PE# %.3d] %pV", level, pfix, pe->
pe_number, vaf);
50 #define define_pe_printk_level(func, kern_level) \
51 static int func(const struct pnv_ioda_pe *pe, const char *fmt, ...) \
53 struct va_format vaf; \
57 va_start(args, fmt); \
62 r = __pe_printk(kern_level, pe, &vaf); \
72 static struct pci_dn *pnv_ioda_get_pdn(
struct pci_dev *
dev)
76 np = pci_device_to_OF_node(dev);
88 phb->
ioda.total_pe, 0);
89 if (pe >= phb->
ioda.total_pe)
90 return IODA_INVALID_PE;
93 phb->
ioda.pe_array[pe].pe_number = pe;
108 #ifdef CONFIG_PCI_MSI
112 struct pnv_phb *phb = hose->private_data;
113 struct pci_dn *pdn = pnv_ioda_get_pdn(dev);
117 if (pdn->pe_number == IODA_INVALID_PE)
119 return &phb->
ioda.pe_array[pdn->pe_number];
128 long rc, rid_end, rid;
136 parent = pe->
pbus->self;
138 count = pe->
pbus->busn_res.end - pe->
pbus->busn_res.start + 1;
150 pr_err(
"%s: Number of subordinate busses %d"
152 pci_name(pe->
pbus->self), count);
156 rid_end = pe->
rid + (count << 8);
158 parent = pe->
pdev->bus->self;
162 rid_end = pe->
rid + 1;
169 pe_err(pe,
"OPAL error %ld trying to setup PELT table\n", rc);
177 struct pci_dn *pdn = pnv_ioda_get_pdn(parent);
178 if (pdn && pdn->pe_number != IODA_INVALID_PE) {
183 parent = parent->
bus->self;
186 for (rid = pe->
rid; rid < rid_end; rid++)
195 pe_err(pe,
"OPAL error %ld setting up MVE %d\n",
202 pe_err(pe,
"OPAL error %ld enabling MVE %d\n",
227 static unsigned int pnv_ioda_dma_weight(
struct pci_dev *dev)
255 struct pnv_phb *phb = hose->private_data;
256 struct pci_dn *pdn = pnv_ioda_get_pdn(dev);
261 pr_err(
"%s: Device tree node not associated properly\n",
265 if (pdn->pe_number != IODA_INVALID_PE)
269 if (dev->
bus->number == 0)
272 pe_num = pnv_ioda_alloc_pe(phb);
273 if (pe_num == IODA_INVALID_PE) {
274 pr_warning(
"%s: Not enough PE# available, disabling device\n",
286 pe = &phb->
ioda.pe_array[pe_num];
289 pdn->pe_number = pe_num;
294 pe->
rid = dev->
bus->number << 8 | pdn->devfn;
296 pe_info(pe,
"Associated device to PE\n");
298 if (pnv_ioda_configure_pe(phb, pe)) {
301 pnv_ioda_free_pe(phb, pe_num);
302 pdn->pe_number = IODA_INVALID_PE;
312 phb->
ioda.dma_pe_count++;
316 pnv_ioda_link_pe_by_weight(phb, pe);
327 struct pci_dn *pdn = pnv_ioda_get_pdn(dev);
330 pr_warn(
"%s: No device node associated with device !\n",
352 struct pnv_phb *phb = hose->private_data;
356 pe_num = pnv_ioda_alloc_pe(phb);
357 if (pe_num == IODA_INVALID_PE) {
358 pr_warning(
"%s: Not enough PE# available for PCI bus %04x:%02x\n",
363 pe = &phb->
ioda.pe_array[pe_num];
373 pe_info(pe,
"Secondary bus %d..%d associated with PE#%d\n",
376 pe_info(pe,
"Secondary bus %d associated with PE#%d\n",
379 if (pnv_ioda_configure_pe(phb, pe)) {
382 pnv_ioda_free_pe(phb, pe_num);
388 pnv_ioda_setup_same_PE(bus, pe);
398 phb->
ioda.dma_pe_count++;
402 pnv_ioda_link_pe_by_weight(phb, pe);
409 pnv_ioda_setup_bus_PE(bus, 0);
429 static void __devinit pnv_pci_ioda_setup_PEs(
void)
434 pnv_ioda_setup_PEs(hose->bus);
470 #define TCE32_TABLE_SIZE ((0x10000000 / 0x1000) * 8)
482 pe_info(pe,
" Setting up 32-bit TCE table at %08x..%08x\n",
483 (base << 28), ((base + segs) << 28) - 1);
493 pe_err(pe,
" Failed to allocate a 32-bit TCE memory\n");
497 memset(addr, 0, TCE32_TABLE_SIZE * segs);
500 for (i = 0; i < segs; i++) {
504 __pa(addr) + TCE32_TABLE_SIZE * i,
505 TCE32_TABLE_SIZE, 0x1000);
507 pe_err(pe,
" Failed to configure 32-bit TCE table,"
528 tbl->it_type = TCE_PCI_SWINV_CREATE | TCE_PCI_SWINV_FREE
529 | TCE_PCI_SWINV_PAIR;
534 set_iommu_table_base(&pe->
pdev->dev, tbl);
536 pnv_ioda_setup_bus_dma(pe, pe->
pbus);
550 unsigned int residual, remaining, segs,
tw, base;
558 if (phb->
ioda.dma_pe_count > phb->
ioda.tce32_count)
561 residual = phb->
ioda.tce32_count -
562 phb->
ioda.dma_pe_count;
564 pr_info(
"PCI: Domain %04x has %ld available 32-bit DMA segments\n",
565 hose->global_number, phb->
ioda.tce32_count);
566 pr_info(
"PCI: %d PE# for a total weight of %d\n",
567 phb->
ioda.dma_pe_count, phb->
ioda.dma_weight);
573 remaining = phb->
ioda.tce32_count;
574 tw = phb->
ioda.dma_weight;
580 pe_warn(pe,
"No DMA32 resources available\n");
586 if (segs > remaining)
589 pe_info(pe,
"DMA weight %d, assigned %d DMA32 segments\n",
591 pnv_pci_ioda_setup_dma_pe(phb, pe, base, segs);
597 #ifdef CONFIG_PCI_MSI
598 static int pnv_pci_ioda_msi_setup(
struct pnv_phb *phb,
struct pci_dev *dev,
599 unsigned int hwirq,
unsigned int is_64,
603 unsigned int xive_num = hwirq - phb->msi_base;
619 pr_warn(
"%s: OPAL error %d setting XIVE %d PE\n",
620 pci_name(dev), rc, xive_num);
628 pr_warn(
"%s: OPAL error %d getting 64-bit MSI data\n",
638 pr_warn(
"%s: OPAL error %d getting 32-bit MSI data\n",
647 pr_devel(
"%s: %s-bit MSI on hwirq %x (xive #%d),"
648 " address=%x_%08x data=%x PE# %d\n",
649 pci_name(dev), is_64 ?
"64" :
"32", hwirq, xive_num,
655 static void pnv_pci_init_ioda_msis(
struct pnv_phb *phb)
657 unsigned int bmap_size;
659 "ibm,opal-msi-ranges",
NULL);
672 pr_err(
"PCI %d: Failed to allocate MSI bitmap !\n",
673 phb->
hose->global_number);
677 phb->msi32_support = 1;
678 pr_info(
" Allocated bitmap for %d MSIs (base IRQ 0x%x)\n",
679 phb->msi_count, phb->msi_base);
682 static void pnv_pci_init_ioda_msis(
struct pnv_phb *phb) { }
693 struct pnv_phb *phb = hose->private_data;
706 pci_bus_for_each_resource(pe->
pbus, res, i) {
707 if (!res || !res->
flags ||
716 while (index < phb->ioda.total_pe &&
722 pr_err(
"%s: OPAL error %d when mapping IO "
723 "segment #%d to PE#%d\n",
733 hose->pci_mem_offset -
734 phb->
ioda.m32_pci_base;
736 hose->pci_mem_offset -
737 phb->
ioda.m32_pci_base;
740 while (index < phb->ioda.total_pe &&
746 pr_err(
"%s: OPAL error %d when mapping M32 "
747 "segment#%d to PE#%d",
759 static void __devinit pnv_pci_ioda_setup_seg(
void)
766 phb = hose->private_data;
768 pnv_ioda_setup_pe_seg(hose, pe);
773 static void __devinit pnv_pci_ioda_setup_DMA(
void)
779 pnv_ioda_setup_dma(hose->private_data);
782 phb = hose->private_data;
787 static void __devinit pnv_pci_ioda_fixup(
void)
789 pnv_pci_ioda_setup_PEs();
790 pnv_pci_ioda_setup_seg();
791 pnv_pci_ioda_setup_DMA();
811 struct pnv_phb *phb = hose->private_data;
812 int num_pci_bridges = 0;
818 if (num_pci_bridges >= 2)
822 bridge = bridge->
bus->self;
827 return phb->
ioda.m32_segsize;
829 return phb->
ioda.io_segsize;
838 struct pnv_phb *phb = hose->private_data;
849 pdn = pnv_ioda_get_pdn(dev);
850 if (!pdn || pdn->pe_number == IODA_INVALID_PE)
859 return phb->
ioda.pe_rmap[(bus->
number << 8) | devfn];
867 unsigned long size, m32map_off, iomap_off, pemap_off;
877 pr_err(
" Missing \"ibm,opal-phbid\" property !\n");
881 pr_debug(
" PHB-ID : 0x%016llx\n", phb_id);
888 if (!phb || !phb->
hose) {
889 pr_err(
"PCI: Failed to allocate PCI controller for %s\n",
898 hose->private_data = phb;
917 pr_err(
" Failed to map registers !\n");
927 phb->
ioda.total_pe = 128;
931 phb->
ioda.m32_size += 0x10000;
933 phb->
ioda.m32_segsize = phb->
ioda.m32_size / phb->
ioda.total_pe;
935 hose->pci_mem_offset;
936 phb->
ioda.io_size = hose->pci_io_size;
937 phb->
ioda.io_segsize = phb->
ioda.io_size / phb->
ioda.total_pe;
938 phb->
ioda.io_pci_base = 0;
941 size =
_ALIGN_UP(phb->
ioda.total_pe / 8,
sizeof(
unsigned long));
943 size += phb->
ioda.total_pe *
sizeof(phb->
ioda.m32_segmap[0]);
945 size += phb->
ioda.total_pe *
sizeof(phb->
ioda.io_segmap[0]);
951 phb->
ioda.m32_segmap = aux + m32map_off;
952 phb->
ioda.io_segmap = aux + iomap_off;
953 phb->
ioda.pe_array = aux + pemap_off;
956 INIT_LIST_HEAD(&phb->
ioda.pe_dma_list);
957 INIT_LIST_HEAD(&phb->
ioda.pe_list);
960 phb->
ioda.tce32_count = phb->
ioda.m32_pci_base >> 28;
974 starting_real_address,
975 starting_pci_address,
979 pr_info(
" %d PE's M32: 0x%x [segment=0x%x] IO: 0x%x [segment=0x%x]\n",
981 phb->
ioda.m32_size, phb->
ioda.m32_segsize,
982 phb->
ioda.io_size, phb->
ioda.io_segsize);
985 pr_devel(
" BUID = 0x%016llx\n", in_be64(phb->
regs + 0x100));
986 pr_devel(
" PHB2_CR = 0x%016llx\n", in_be64(phb->
regs + 0x160));
987 pr_devel(
" IO_BAR = 0x%016llx\n", in_be64(phb->
regs + 0x170));
988 pr_devel(
" IO_BAMR = 0x%016llx\n", in_be64(phb->
regs + 0x178));
989 pr_devel(
" IO_SAR = 0x%016llx\n", in_be64(phb->
regs + 0x180));
990 pr_devel(
" M32_BAR = 0x%016llx\n", in_be64(phb->
regs + 0x190));
991 pr_devel(
" M32_BAMR = 0x%016llx\n", in_be64(phb->
regs + 0x198));
992 pr_devel(
" M32_SAR = 0x%016llx\n", in_be64(phb->
regs + 0x1a0));
1003 pnv_pci_init_ioda_msis(phb);
1012 ppc_md.pcibios_fixup = pnv_pci_ioda_fixup;
1013 ppc_md.pcibios_enable_device_hook = pnv_pci_enable_device_hook;
1014 ppc_md.pcibios_window_alignment = pnv_pci_window_alignment;
1015 pci_add_flags(PCI_REASSIGN_ALL_RSRC);
1020 pr_warning(
" OPAL Error %ld performing IODA table reset !\n", rc);
1034 pr_err(
" Missing \"ibm,opal-hubid\" property !\n");
1038 pr_devel(
" HUB-ID : 0x%016llx\n", hub_id);