12 #include <linux/kernel.h>
13 #include <linux/pci.h>
15 #include <linux/string.h>
22 #include <asm/sections.h>
25 #include <asm/pci-bridge.h>
26 #include <asm/machdep.h>
28 #include <asm/iommu.h>
30 #include <asm/debug.h>
41 #define MAX_TABLE_TVT_COUNT 8
78 #define NUM_DMA32_REGIONS 1
105 #define cfg_debug(fmt...)
108 static int wsp_pcie_read_config(
struct pci_bus *
bus,
unsigned int devfn,
115 hose = pci_bus_to_host(bus);
118 if (offset >= 0x1000)
136 >> (suboff << 3)) & 0xff;
137 cfg_debug(
"read 1 %02x:%02x:%02x + %02x/%x addr=0x%llx val=%02x\n",
138 bus->
number, devfn >> 3, devfn & 7,
139 offset, suboff, addr, *val);
145 >> (suboff << 3)) & 0xffff;
146 cfg_debug(
"read 2 %02x:%02x:%02x + %02x/%x addr=0x%llx val=%04x\n",
147 bus->
number, devfn >> 3, devfn & 7,
148 offset, suboff, addr, *val);
154 cfg_debug(
"read 4 %02x:%02x:%02x + %02x/%x addr=0x%llx val=%08x\n",
155 bus->
number, devfn >> 3, devfn & 7,
156 offset, suboff, addr, *val);
162 static int wsp_pcie_write_config(
struct pci_bus *
bus,
unsigned int devfn,
169 hose = pci_bus_to_host(bus);
172 if (offset >= 0x1000)
190 cfg_debug(
"write 1 %02x:%02x:%02x + %02x/%x addr=0x%llx val=%02x\n",
191 bus->
number, devfn >> 3, devfn & 7,
192 offset, suboff, addr, val);
199 cfg_debug(
"write 2 %02x:%02x:%02x + %02x/%x addr=0x%llx val=%04x\n",
200 bus->
number, devfn >> 3, devfn & 7,
201 offset, suboff, addr, val);
207 cfg_debug(
"write 4 %02x:%02x:%02x + %02x/%x addr=0x%llx val=%08x\n",
208 bus->
number, devfn >> 3, devfn & 7,
209 offset, suboff, addr, val);
215 static struct pci_ops wsp_pcie_pci_ops =
217 .read = wsp_pcie_read_config,
218 .write = wsp_pcie_write_config,
222 #define TCE_PAGE_SIZE (1 << TCE_SHIFT)
223 #define TCE_PCI_WRITE 0x2
224 #define TCE_PCI_READ 0x1
225 #define TCE_RPN_MASK 0x3fffffffffful
226 #define TCE_RPN_SHIFT 12
229 #define dma_debug(fmt...)
243 #ifdef CONFIG_WSP_DD1_WORKAROUND_DD1_TCE_BUGS
256 tcep += (index & 0xffff);
262 dma_debug(
"[DMA] TCE %p set to 0x%016llx (dma addr: 0x%lx)\n",
276 #ifndef CONFIG_WSP_DD1_WORKAROUND_DD1_TCE_BUGS
288 tcep += (index & 0xffff);
289 dma_debug(
"[DMA] TCE %p cleared\n", tcep);
291 #ifndef CONFIG_WSP_DD1_WORKAROUND_DD1_TCE_BUGS
309 int tvts_per_table,
i, tvt, nid;
315 tvts_per_table = size / 0x10000000;
316 if (tvts_per_table == 0)
322 tvt = region * tvts_per_table;
325 pr_debug(
" DMA range : 0x%08lx..0x%08lx\n", addr, addr + size - 1);
326 pr_debug(
" Number of TVTs : %d\n", tvts_per_table);
336 for (i = 0; i < tvts_per_table; i++) {
337 u64 tvt_data1, tvt_data0;
362 tvt_data0 |= validate->
bus->number;
379 spin_unlock_irqrestore(&phb->
lock, flags);
383 tbl->
table.it_blocksize = 16;
397 pr_debug(
" Failed to allocate a 256M TCE table !\n");
398 for (i = 0; i < tvts_per_table; i++)
409 struct wsp_phb *phb = hose->private_data;
418 pr_debug(
"%s: Setting up DMA...\n", pci_name(pdev));
424 spin_unlock_irqrestore(&phb->
lock, flags);
426 table = wsp_pci_create_dma32_table(phb, 0,
NULL);
436 spin_unlock_irqrestore(&phb->
lock, flags);
437 table = wsp_pci_create_dma32_table(phb, i, pdev);
443 pr_err(
"%s: Failed to create DMA table, err %ld !\n",
444 pci_name(pdev), PTR_ERR(table));
450 pr_info(
"%s: Setup iommu: 32-bit DMA region 0x%08lx..0x%08lx\n",
452 table->
table.it_offset << IOMMU_PAGE_SHIFT,
453 (table->
table.it_offset << IOMMU_PAGE_SHIFT)
460 spin_unlock_irqrestore(&phb->
lock, flags);
461 pr_err(
"%s: Out of DMA space !\n", pci_name(pdev));
469 #define DUMP_REG(x) \
470 pr_debug("%-30s : 0x%016llx\n", #x, in_be64(hose->cfg_data + x))
477 pr_debug(
"PCI-E SYS_CFG1 : 0x%llx\n", val);
482 #ifdef CONFIG_WSP_DD1_WORKAROUND_DD1_TCE_BUGS
484 out_be64(hose->cfg_data + 0xe50,
485 in_be64(hose->cfg_data + 0xe50) | (3ull << 62));
486 printk(
"PCI-E DEBUG CONTROL 5 = 0x%llx\n", in_be64(hose->cfg_data + 0xe50));
492 (~(hose->io_resource.end - hose->io_resource.start)) &
498 printk(
"Want to write to M32A_BASE_MASK : 0x%llx\n",
530 pr_debug(
"Will write config: 0x%llx\n", val);
534 out_be64(hose->cfg_data + 0xe00,
535 in_be64(hose->cfg_data + 0xe00) | 0x0008000000000000ull);
572 static void wsp_pci_wait_io_idle(
struct wsp_phb *phb,
unsigned long port)
577 for (i = 0; i < 10000; i++) {
578 val = in_be64(phb->
hose->cfg_data + 0xe08);
579 if ((val & 0x1900000000000000ull) == 0x0100000000000000ull)
583 pr_warning(
"PCI IO timeout on domain %d port 0x%lx\n",
584 phb->
hose->global_number, port);
587 #define DEF_PCI_AC_RET_pio(name, ret, at, al, aa) \
588 static ret wsp_pci_##name at \
590 struct iowa_bus *bus; \
591 struct wsp_phb *phb; \
592 unsigned long flags; \
594 bus = iowa_pio_find_bus(aa); \
596 phb = bus->private; \
597 spin_lock_irqsave(&phb->lock, flags); \
598 wsp_pci_wait_io_idle(phb, aa); \
599 rval = __do_##name al; \
600 spin_unlock_irqrestore(&phb->lock, flags); \
604 #define DEF_PCI_AC_NORET_pio(name, at, al, aa) \
605 static void wsp_pci_##name at \
607 struct iowa_bus *bus; \
608 struct wsp_phb *phb; \
609 unsigned long flags; \
610 bus = iowa_pio_find_bus(aa); \
612 phb = bus->private; \
613 spin_lock_irqsave(&phb->lock, flags); \
614 wsp_pci_wait_io_idle(phb, aa); \
616 spin_unlock_irqrestore(&phb->lock, flags); \
619 #define DEF_PCI_AC_RET_mem(name, ret, at, al, aa)
620 #define DEF_PCI_AC_NORET_mem(name, at, al, aa)
622 #define DEF_PCI_AC_RET(name, ret, at, al, space, aa) \
623 DEF_PCI_AC_RET_##space(name, ret, at, al, aa)
625 #define DEF_PCI_AC_NORET(name, at, al, space, aa) \
626 DEF_PCI_AC_NORET_##space(name, at, al, aa) \
631 #undef DEF_PCI_AC_RET
632 #undef DEF_PCI_AC_NORET
634 static struct ppc_pci_io wsp_pci_iops = {
638 .outb = wsp_pci_outb,
639 .outw = wsp_pci_outw,
640 .outl = wsp_pci_outl,
641 .insb = wsp_pci_insb,
642 .insw = wsp_pci_insw,
643 .insl = wsp_pci_insl,
644 .outsb = wsp_pci_outsb,
645 .outsw = wsp_pci_outsw,
646 .outsl = wsp_pci_outsl,
664 hose->private_data = phb;
676 hose->cfg_data =
of_iomap(hose->dn, 0);
678 pr_debug(
"PCIe registers mapped at 0x%p\n", hose->cfg_data);
684 pci_add_flags(PCI_REASSIGN_ALL_BUS | PCI_REASSIGN_ALL_RSRC |
685 PCI_ENABLE_PROC_DOMAINS);
691 pr_warning(
"IOMMU: Clamped to %d DMA32 regions\n",
700 hose->
ops = &wsp_pcie_pci_ops;
703 wsp_pcie_configure_hw(hose);
707 #ifdef CONFIG_PCI_MSI
712 list_add(&phb->
all, &wsp_phbs);
724 rc = wsp_setup_one_phb(np);
726 pr_err(
"Failed to setup PCIe bridge %s, rc=%d\n",
735 pr_info(
"PCI-E: Disabled TCEs, using direct DMA\n");
738 ppc_md.pci_dma_dev_setup = wsp_pci_dma_dev_setup;
739 ppc_md.tce_build = tce_build_wsp;
740 ppc_md.tce_free = tce_free_wsp;
745 #define err_debug(fmt...) pr_debug(fmt)
764 hw_irq = prop[5] & 0xf;
771 hw_irq |= prop[5] & ~0xf;
773 err_debug(
"PCI: Using 0x%x as error IRQ for %s\n",
774 hw_irq, np->
parent->full_name);
778 static const struct {
782 #define DREG(x) { PCIE_REG_##x, #x }
783 #define DUTL(x) { PCIE_UTL_##x, "UTL_" #x }
787 DREG(DMA_CHAN_STATUS),
788 DREG(CPU_LOADSTORE_STATUS),
795 DREG(M32A_BASE_ADDR),
796 DREG(M32A_BASE_MASK),
797 DREG(M32A_START_ADDR),
798 DREG(M32B_BASE_ADDR),
799 DREG(M32B_BASE_MASK),
800 DREG(M32B_START_ADDR),
803 DREG(M64_START_ADDR),
810 DREG(PAPR_ERR_INJ_CONTROL),
811 DREG(PAPR_ERR_INJ_ADDR),
812 DREG(PAPR_ERR_INJ_MASK),
815 DUTL(SYS_BUS_CONTROL),
817 DUTL(SYS_BUS_AGENT_STATUS),
818 DUTL(SYS_BUS_AGENT_ERR_SEV),
819 DUTL(SYS_BUS_AGENT_IRQ_EN),
820 DUTL(SYS_BUS_BURST_SZ_CONF),
822 DUTL(OUT_POST_HDR_BUF_ALLOC),
823 DUTL(OUT_POST_DAT_BUF_ALLOC),
824 DUTL(IN_POST_HDR_BUF_ALLOC),
825 DUTL(IN_POST_DAT_BUF_ALLOC),
826 DUTL(OUT_NP_BUF_ALLOC),
827 DUTL(IN_NP_BUF_ALLOC),
828 DUTL(PCIE_TAGS_ALLOC),
829 DUTL(GBIF_READ_TAGS_ALLOC),
831 DUTL(PCIE_PORT_CONTROL),
832 DUTL(PCIE_PORT_STATUS),
833 DUTL(PCIE_PORT_ERROR_SEV),
834 DUTL(PCIE_PORT_IRQ_EN),
836 DUTL(RC_ERR_SEVERITY),
839 DUTL(EP_ERR_SEVERITY),
845 DREG(SYSTEM_CONFIG1),
846 DREG(SYSTEM_CONFIG2),
847 DREG(EP_SYSTEM_CONFIG),
854 DREG(ERR_REPORT_CONTROL),
858 DREG(BUFFERS_CONFIG),
861 DREG(PF0_SRIOV_STATUS),
862 DREG(PF1_SRIOV_STATUS),
864 DREG(POR_SYSTEM_CONFIG),
870 DREG(PHB_TIMEOUT_CONTROL1),
871 DREG(PHB_QUIESCE_DMA),
872 DREG(PHB_DMA_READ_TAG_ACTV),
873 DREG(PHB_TCE_READ_TAG_ACTV),
877 DREG(LEM_FIR_AND_MASK),
878 DREG(LEM_FIR_OR_MASK),
881 DREG(LEM_ERROR_MASK),
882 DREG(LEM_ERROR_AND_MASK),
883 DREG(LEM_ERROR_OR_MASK),
886 DREG(PHB_ERR_STATUS),
887 DREG(PHB_ERR_STATUS),
888 DREG(PHB_ERR1_STATUS),
889 DREG(PHB_ERR_INJECT),
890 DREG(PHB_ERR_LEM_ENABLE),
891 DREG(PHB_ERR_IRQ_ENABLE),
892 DREG(PHB_ERR_FREEZE_ENABLE),
893 DREG(PHB_ERR_SIDE_ENABLE),
896 DREG(PHB_ERR_STATUS_MASK),
897 DREG(PHB_ERR1_STATUS_MASK),
898 DREG(MMIO_ERR_STATUS),
899 DREG(MMIO_ERR1_STATUS),
900 DREG(MMIO_ERR_INJECT),
901 DREG(MMIO_ERR_LEM_ENABLE),
902 DREG(MMIO_ERR_IRQ_ENABLE),
903 DREG(MMIO_ERR_FREEZE_ENABLE),
904 DREG(MMIO_ERR_SIDE_ENABLE),
905 DREG(MMIO_ERR_LOG_0),
906 DREG(MMIO_ERR_LOG_1),
907 DREG(MMIO_ERR_STATUS_MASK),
908 DREG(MMIO_ERR1_STATUS_MASK),
909 DREG(DMA_ERR_STATUS),
910 DREG(DMA_ERR1_STATUS),
911 DREG(DMA_ERR_INJECT),
912 DREG(DMA_ERR_LEM_ENABLE),
913 DREG(DMA_ERR_IRQ_ENABLE),
914 DREG(DMA_ERR_FREEZE_ENABLE),
915 DREG(DMA_ERR_SIDE_ENABLE),
918 DREG(DMA_ERR_STATUS_MASK),
919 DREG(DMA_ERR1_STATUS_MASK),
922 DREG(PHB_DEBUG_CONTROL0),
923 DREG(PHB_DEBUG_STATUS0),
924 DREG(PHB_DEBUG_CONTROL1),
925 DREG(PHB_DEBUG_STATUS1),
926 DREG(PHB_DEBUG_CONTROL2),
927 DREG(PHB_DEBUG_STATUS2),
928 DREG(PHB_DEBUG_CONTROL3),
929 DREG(PHB_DEBUG_STATUS3),
930 DREG(PHB_DEBUG_CONTROL4),
931 DREG(PHB_DEBUG_STATUS4),
932 DREG(PHB_DEBUG_CONTROL5),
933 DREG(PHB_DEBUG_STATUS5),
941 static int wsp_pci_regs_show(
struct seq_file *
m,
void *
private)
947 for (i = 0; i <
ARRAY_SIZE(wsp_pci_regs); i++) {
949 if (wsp_pci_regs[i].offset == 0xc08 ||
950 wsp_pci_regs[i].offset == 0xc10 ||
951 wsp_pci_regs[i].offset == 0xc38 ||
952 wsp_pci_regs[i].offset == 0xc40)
955 wsp_pci_regs[i].offset,
956 in_be64(hose->cfg_data + wsp_pci_regs[i].offset),
957 wsp_pci_regs[i].name);
968 .open = wsp_pci_regs_open,
974 static int wsp_pci_reg_set(
void *
data,
u64 val)
976 out_be64((
void __iomem *)data, val);
980 static int wsp_pci_reg_get(
void *data,
u64 *val)
982 *val = in_be64((
void __iomem *)data);
995 pr_err(
"PCI: Error interrupt on %s (PHB %d)\n",
996 hose->dn->full_name, hose->global_number);
1005 if (
ed.utl_port_err)
1039 pr_err(
" PHB Error Status : 0x%016llx\n",
ed.phb_err);
1040 pr_err(
" PHB First Error Status: 0x%016llx\n",
ed.phb_err1);
1041 pr_err(
" PHB Error Log 0 : 0x%016llx\n",
ed.phb_log0);
1042 pr_err(
" PHB Error Log 1 : 0x%016llx\n",
ed.phb_log1);
1045 pr_err(
" MMIO Error Status : 0x%016llx\n",
ed.mmio_err);
1046 pr_err(
" MMIO First Error Status: 0x%016llx\n",
ed.mmio_err1);
1047 pr_err(
" MMIO Error Log 0 : 0x%016llx\n",
ed.mmio_log0);
1048 pr_err(
" MMIO Error Log 1 : 0x%016llx\n",
ed.mmio_log1);
1051 pr_err(
" DMA Error Status : 0x%016llx\n",
ed.dma_err);
1052 pr_err(
" DMA First Error Status: 0x%016llx\n",
ed.dma_err1);
1053 pr_err(
" DMA Error Log 0 : 0x%016llx\n",
ed.dma_log0);
1054 pr_err(
" DMA Error Log 1 : 0x%016llx\n",
ed.dma_log1);
1057 pr_err(
" UTL Sys Error Status : 0x%016llx\n",
ed.utl_sys_err);
1058 if (
ed.utl_port_err)
1059 pr_err(
" UTL Port Error Status : 0x%016llx\n",
ed.utl_port_err);
1061 pr_err(
" UTL RC Error Status : 0x%016llx\n",
ed.utl_rc_err);
1067 if (
ed.dma_err ||
ed.mmio_err ||
ed.phb_err) {
1074 static void __init wsp_setup_pci_err_reporting(
struct wsp_phb *phb)
1081 sprintf(fname,
"phb%d", phb->
hose->global_number);
1089 for (i = 0; i <
ARRAY_SIZE(wsp_pci_regs); i++) {
1090 sprintf(tmp,
"%03x_%s", wsp_pci_regs[i].offset,
1091 wsp_pci_regs[i].
name);
1093 hose->cfg_data + wsp_pci_regs[i].offset,
1103 err_irq = wsp_pci_get_err_irq_no_dt(hose->dn);
1105 pr_err(
"PCI: Failed to fetch error interrupt for %s\n",
1106 hose->dn->full_name);
1110 rc =
request_irq(err_irq, wsp_pci_err_irq, 0,
"wsp_pci error", phb);
1112 pr_err(
"PCI: Failed to request interrupt for %s\n",
1113 hose->dn->full_name);
1124 static int __init wsp_setup_pci_late(
void)
1129 wsp_setup_pci_err_reporting(phb);