18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Support PCI/PCIe on PowerNV platforms 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright 2011 Benjamin Herrenschmidt, IBM Corp. 68c2ecf20Sopenharmony_ci */ 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci#include <linux/kernel.h> 98c2ecf20Sopenharmony_ci#include <linux/pci.h> 108c2ecf20Sopenharmony_ci#include <linux/delay.h> 118c2ecf20Sopenharmony_ci#include <linux/string.h> 128c2ecf20Sopenharmony_ci#include <linux/init.h> 138c2ecf20Sopenharmony_ci#include <linux/irq.h> 148c2ecf20Sopenharmony_ci#include <linux/io.h> 158c2ecf20Sopenharmony_ci#include <linux/msi.h> 168c2ecf20Sopenharmony_ci#include <linux/iommu.h> 178c2ecf20Sopenharmony_ci#include <linux/sched/mm.h> 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ci#include <asm/sections.h> 208c2ecf20Sopenharmony_ci#include <asm/io.h> 218c2ecf20Sopenharmony_ci#include <asm/prom.h> 228c2ecf20Sopenharmony_ci#include <asm/pci-bridge.h> 238c2ecf20Sopenharmony_ci#include <asm/machdep.h> 248c2ecf20Sopenharmony_ci#include <asm/msi_bitmap.h> 258c2ecf20Sopenharmony_ci#include <asm/ppc-pci.h> 268c2ecf20Sopenharmony_ci#include <asm/pnv-pci.h> 278c2ecf20Sopenharmony_ci#include <asm/opal.h> 288c2ecf20Sopenharmony_ci#include <asm/iommu.h> 298c2ecf20Sopenharmony_ci#include <asm/tce.h> 308c2ecf20Sopenharmony_ci#include <asm/firmware.h> 318c2ecf20Sopenharmony_ci#include <asm/eeh_event.h> 328c2ecf20Sopenharmony_ci#include <asm/eeh.h> 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_ci#include "powernv.h" 358c2ecf20Sopenharmony_ci#include "pci.h" 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_cistatic DEFINE_MUTEX(tunnel_mutex); 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ciint pnv_pci_get_slot_id(struct device_node *np, uint64_t *id) 408c2ecf20Sopenharmony_ci{ 418c2ecf20Sopenharmony_ci struct device_node *node = np; 428c2ecf20Sopenharmony_ci u32 bdfn; 438c2ecf20Sopenharmony_ci u64 phbid; 448c2ecf20Sopenharmony_ci int ret; 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_ci ret = of_property_read_u32(np, "reg", &bdfn); 478c2ecf20Sopenharmony_ci if (ret) 488c2ecf20Sopenharmony_ci return -ENXIO; 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ci bdfn = ((bdfn & 0x00ffff00) >> 8); 518c2ecf20Sopenharmony_ci for (node = np; node; node = of_get_parent(node)) { 528c2ecf20Sopenharmony_ci if (!PCI_DN(node)) { 538c2ecf20Sopenharmony_ci of_node_put(node); 548c2ecf20Sopenharmony_ci break; 558c2ecf20Sopenharmony_ci } 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_ci if (!of_device_is_compatible(node, "ibm,ioda2-phb") && 588c2ecf20Sopenharmony_ci !of_device_is_compatible(node, "ibm,ioda3-phb") && 598c2ecf20Sopenharmony_ci !of_device_is_compatible(node, "ibm,ioda2-npu2-opencapi-phb")) { 608c2ecf20Sopenharmony_ci of_node_put(node); 618c2ecf20Sopenharmony_ci continue; 628c2ecf20Sopenharmony_ci } 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_ci ret = of_property_read_u64(node, "ibm,opal-phbid", &phbid); 658c2ecf20Sopenharmony_ci if (ret) { 668c2ecf20Sopenharmony_ci of_node_put(node); 678c2ecf20Sopenharmony_ci return -ENXIO; 688c2ecf20Sopenharmony_ci } 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_ci if (of_device_is_compatible(node, "ibm,ioda2-npu2-opencapi-phb")) 718c2ecf20Sopenharmony_ci *id = PCI_PHB_SLOT_ID(phbid); 728c2ecf20Sopenharmony_ci else 738c2ecf20Sopenharmony_ci *id = PCI_SLOT_ID(phbid, bdfn); 748c2ecf20Sopenharmony_ci return 0; 758c2ecf20Sopenharmony_ci } 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_ci return -ENODEV; 788c2ecf20Sopenharmony_ci} 798c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(pnv_pci_get_slot_id); 808c2ecf20Sopenharmony_ci 818c2ecf20Sopenharmony_ciint pnv_pci_get_device_tree(uint32_t phandle, void *buf, uint64_t len) 828c2ecf20Sopenharmony_ci{ 838c2ecf20Sopenharmony_ci int64_t rc; 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ci if (!opal_check_token(OPAL_GET_DEVICE_TREE)) 868c2ecf20Sopenharmony_ci return -ENXIO; 878c2ecf20Sopenharmony_ci 888c2ecf20Sopenharmony_ci rc = opal_get_device_tree(phandle, (uint64_t)buf, len); 898c2ecf20Sopenharmony_ci if (rc < OPAL_SUCCESS) 908c2ecf20Sopenharmony_ci return -EIO; 918c2ecf20Sopenharmony_ci 928c2ecf20Sopenharmony_ci return rc; 938c2ecf20Sopenharmony_ci} 948c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(pnv_pci_get_device_tree); 958c2ecf20Sopenharmony_ci 968c2ecf20Sopenharmony_ciint pnv_pci_get_presence_state(uint64_t id, uint8_t *state) 978c2ecf20Sopenharmony_ci{ 988c2ecf20Sopenharmony_ci int64_t rc; 998c2ecf20Sopenharmony_ci 1008c2ecf20Sopenharmony_ci if (!opal_check_token(OPAL_PCI_GET_PRESENCE_STATE)) 1018c2ecf20Sopenharmony_ci return -ENXIO; 1028c2ecf20Sopenharmony_ci 1038c2ecf20Sopenharmony_ci rc = opal_pci_get_presence_state(id, (uint64_t)state); 1048c2ecf20Sopenharmony_ci if (rc != OPAL_SUCCESS) 1058c2ecf20Sopenharmony_ci return -EIO; 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_ci return 0; 1088c2ecf20Sopenharmony_ci} 1098c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(pnv_pci_get_presence_state); 1108c2ecf20Sopenharmony_ci 1118c2ecf20Sopenharmony_ciint pnv_pci_get_power_state(uint64_t id, uint8_t *state) 1128c2ecf20Sopenharmony_ci{ 1138c2ecf20Sopenharmony_ci int64_t rc; 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_ci if (!opal_check_token(OPAL_PCI_GET_POWER_STATE)) 1168c2ecf20Sopenharmony_ci return -ENXIO; 1178c2ecf20Sopenharmony_ci 1188c2ecf20Sopenharmony_ci rc = opal_pci_get_power_state(id, (uint64_t)state); 1198c2ecf20Sopenharmony_ci if (rc != OPAL_SUCCESS) 1208c2ecf20Sopenharmony_ci return -EIO; 1218c2ecf20Sopenharmony_ci 1228c2ecf20Sopenharmony_ci return 0; 1238c2ecf20Sopenharmony_ci} 1248c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(pnv_pci_get_power_state); 1258c2ecf20Sopenharmony_ci 1268c2ecf20Sopenharmony_ciint pnv_pci_set_power_state(uint64_t id, uint8_t state, struct opal_msg *msg) 1278c2ecf20Sopenharmony_ci{ 1288c2ecf20Sopenharmony_ci struct opal_msg m; 1298c2ecf20Sopenharmony_ci int token, ret; 1308c2ecf20Sopenharmony_ci int64_t rc; 1318c2ecf20Sopenharmony_ci 1328c2ecf20Sopenharmony_ci if (!opal_check_token(OPAL_PCI_SET_POWER_STATE)) 1338c2ecf20Sopenharmony_ci return -ENXIO; 1348c2ecf20Sopenharmony_ci 1358c2ecf20Sopenharmony_ci token = opal_async_get_token_interruptible(); 1368c2ecf20Sopenharmony_ci if (unlikely(token < 0)) 1378c2ecf20Sopenharmony_ci return token; 1388c2ecf20Sopenharmony_ci 1398c2ecf20Sopenharmony_ci rc = opal_pci_set_power_state(token, id, (uint64_t)&state); 1408c2ecf20Sopenharmony_ci if (rc == OPAL_SUCCESS) { 1418c2ecf20Sopenharmony_ci ret = 0; 1428c2ecf20Sopenharmony_ci goto exit; 1438c2ecf20Sopenharmony_ci } else if (rc != OPAL_ASYNC_COMPLETION) { 1448c2ecf20Sopenharmony_ci ret = -EIO; 1458c2ecf20Sopenharmony_ci goto exit; 1468c2ecf20Sopenharmony_ci } 1478c2ecf20Sopenharmony_ci 1488c2ecf20Sopenharmony_ci ret = opal_async_wait_response(token, &m); 1498c2ecf20Sopenharmony_ci if (ret < 0) 1508c2ecf20Sopenharmony_ci goto exit; 1518c2ecf20Sopenharmony_ci 1528c2ecf20Sopenharmony_ci if (msg) { 1538c2ecf20Sopenharmony_ci ret = 1; 1548c2ecf20Sopenharmony_ci memcpy(msg, &m, sizeof(m)); 1558c2ecf20Sopenharmony_ci } 1568c2ecf20Sopenharmony_ci 1578c2ecf20Sopenharmony_ciexit: 1588c2ecf20Sopenharmony_ci opal_async_release_token(token); 1598c2ecf20Sopenharmony_ci return ret; 1608c2ecf20Sopenharmony_ci} 1618c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(pnv_pci_set_power_state); 1628c2ecf20Sopenharmony_ci 1638c2ecf20Sopenharmony_ciint pnv_setup_msi_irqs(struct pci_dev *pdev, int nvec, int type) 1648c2ecf20Sopenharmony_ci{ 1658c2ecf20Sopenharmony_ci struct pnv_phb *phb = pci_bus_to_pnvhb(pdev->bus); 1668c2ecf20Sopenharmony_ci struct msi_desc *entry; 1678c2ecf20Sopenharmony_ci struct msi_msg msg; 1688c2ecf20Sopenharmony_ci int hwirq; 1698c2ecf20Sopenharmony_ci unsigned int virq; 1708c2ecf20Sopenharmony_ci int rc; 1718c2ecf20Sopenharmony_ci 1728c2ecf20Sopenharmony_ci if (WARN_ON(!phb) || !phb->msi_bmp.bitmap) 1738c2ecf20Sopenharmony_ci return -ENODEV; 1748c2ecf20Sopenharmony_ci 1758c2ecf20Sopenharmony_ci if (pdev->no_64bit_msi && !phb->msi32_support) 1768c2ecf20Sopenharmony_ci return -ENODEV; 1778c2ecf20Sopenharmony_ci 1788c2ecf20Sopenharmony_ci for_each_pci_msi_entry(entry, pdev) { 1798c2ecf20Sopenharmony_ci if (!entry->msi_attrib.is_64 && !phb->msi32_support) { 1808c2ecf20Sopenharmony_ci pr_warn("%s: Supports only 64-bit MSIs\n", 1818c2ecf20Sopenharmony_ci pci_name(pdev)); 1828c2ecf20Sopenharmony_ci return -ENXIO; 1838c2ecf20Sopenharmony_ci } 1848c2ecf20Sopenharmony_ci hwirq = msi_bitmap_alloc_hwirqs(&phb->msi_bmp, 1); 1858c2ecf20Sopenharmony_ci if (hwirq < 0) { 1868c2ecf20Sopenharmony_ci pr_warn("%s: Failed to find a free MSI\n", 1878c2ecf20Sopenharmony_ci pci_name(pdev)); 1888c2ecf20Sopenharmony_ci return -ENOSPC; 1898c2ecf20Sopenharmony_ci } 1908c2ecf20Sopenharmony_ci virq = irq_create_mapping(NULL, phb->msi_base + hwirq); 1918c2ecf20Sopenharmony_ci if (!virq) { 1928c2ecf20Sopenharmony_ci pr_warn("%s: Failed to map MSI to linux irq\n", 1938c2ecf20Sopenharmony_ci pci_name(pdev)); 1948c2ecf20Sopenharmony_ci msi_bitmap_free_hwirqs(&phb->msi_bmp, hwirq, 1); 1958c2ecf20Sopenharmony_ci return -ENOMEM; 1968c2ecf20Sopenharmony_ci } 1978c2ecf20Sopenharmony_ci rc = phb->msi_setup(phb, pdev, phb->msi_base + hwirq, 1988c2ecf20Sopenharmony_ci virq, entry->msi_attrib.is_64, &msg); 1998c2ecf20Sopenharmony_ci if (rc) { 2008c2ecf20Sopenharmony_ci pr_warn("%s: Failed to setup MSI\n", pci_name(pdev)); 2018c2ecf20Sopenharmony_ci irq_dispose_mapping(virq); 2028c2ecf20Sopenharmony_ci msi_bitmap_free_hwirqs(&phb->msi_bmp, hwirq, 1); 2038c2ecf20Sopenharmony_ci return rc; 2048c2ecf20Sopenharmony_ci } 2058c2ecf20Sopenharmony_ci irq_set_msi_desc(virq, entry); 2068c2ecf20Sopenharmony_ci pci_write_msi_msg(virq, &msg); 2078c2ecf20Sopenharmony_ci } 2088c2ecf20Sopenharmony_ci return 0; 2098c2ecf20Sopenharmony_ci} 2108c2ecf20Sopenharmony_ci 2118c2ecf20Sopenharmony_civoid pnv_teardown_msi_irqs(struct pci_dev *pdev) 2128c2ecf20Sopenharmony_ci{ 2138c2ecf20Sopenharmony_ci struct pnv_phb *phb = pci_bus_to_pnvhb(pdev->bus); 2148c2ecf20Sopenharmony_ci struct msi_desc *entry; 2158c2ecf20Sopenharmony_ci irq_hw_number_t hwirq; 2168c2ecf20Sopenharmony_ci 2178c2ecf20Sopenharmony_ci if (WARN_ON(!phb)) 2188c2ecf20Sopenharmony_ci return; 2198c2ecf20Sopenharmony_ci 2208c2ecf20Sopenharmony_ci for_each_pci_msi_entry(entry, pdev) { 2218c2ecf20Sopenharmony_ci if (!entry->irq) 2228c2ecf20Sopenharmony_ci continue; 2238c2ecf20Sopenharmony_ci hwirq = virq_to_hw(entry->irq); 2248c2ecf20Sopenharmony_ci irq_set_msi_desc(entry->irq, NULL); 2258c2ecf20Sopenharmony_ci irq_dispose_mapping(entry->irq); 2268c2ecf20Sopenharmony_ci msi_bitmap_free_hwirqs(&phb->msi_bmp, hwirq - phb->msi_base, 1); 2278c2ecf20Sopenharmony_ci } 2288c2ecf20Sopenharmony_ci} 2298c2ecf20Sopenharmony_ci 2308c2ecf20Sopenharmony_ci/* Nicely print the contents of the PE State Tables (PEST). */ 2318c2ecf20Sopenharmony_cistatic void pnv_pci_dump_pest(__be64 pestA[], __be64 pestB[], int pest_size) 2328c2ecf20Sopenharmony_ci{ 2338c2ecf20Sopenharmony_ci __be64 prevA = ULONG_MAX, prevB = ULONG_MAX; 2348c2ecf20Sopenharmony_ci bool dup = false; 2358c2ecf20Sopenharmony_ci int i; 2368c2ecf20Sopenharmony_ci 2378c2ecf20Sopenharmony_ci for (i = 0; i < pest_size; i++) { 2388c2ecf20Sopenharmony_ci __be64 peA = be64_to_cpu(pestA[i]); 2398c2ecf20Sopenharmony_ci __be64 peB = be64_to_cpu(pestB[i]); 2408c2ecf20Sopenharmony_ci 2418c2ecf20Sopenharmony_ci if (peA != prevA || peB != prevB) { 2428c2ecf20Sopenharmony_ci if (dup) { 2438c2ecf20Sopenharmony_ci pr_info("PE[..%03x] A/B: as above\n", i-1); 2448c2ecf20Sopenharmony_ci dup = false; 2458c2ecf20Sopenharmony_ci } 2468c2ecf20Sopenharmony_ci prevA = peA; 2478c2ecf20Sopenharmony_ci prevB = peB; 2488c2ecf20Sopenharmony_ci if (peA & PNV_IODA_STOPPED_STATE || 2498c2ecf20Sopenharmony_ci peB & PNV_IODA_STOPPED_STATE) 2508c2ecf20Sopenharmony_ci pr_info("PE[%03x] A/B: %016llx %016llx\n", 2518c2ecf20Sopenharmony_ci i, peA, peB); 2528c2ecf20Sopenharmony_ci } else if (!dup && (peA & PNV_IODA_STOPPED_STATE || 2538c2ecf20Sopenharmony_ci peB & PNV_IODA_STOPPED_STATE)) { 2548c2ecf20Sopenharmony_ci dup = true; 2558c2ecf20Sopenharmony_ci } 2568c2ecf20Sopenharmony_ci } 2578c2ecf20Sopenharmony_ci} 2588c2ecf20Sopenharmony_ci 2598c2ecf20Sopenharmony_cistatic void pnv_pci_dump_p7ioc_diag_data(struct pci_controller *hose, 2608c2ecf20Sopenharmony_ci struct OpalIoPhbErrorCommon *common) 2618c2ecf20Sopenharmony_ci{ 2628c2ecf20Sopenharmony_ci struct OpalIoP7IOCPhbErrorData *data; 2638c2ecf20Sopenharmony_ci 2648c2ecf20Sopenharmony_ci data = (struct OpalIoP7IOCPhbErrorData *)common; 2658c2ecf20Sopenharmony_ci pr_info("P7IOC PHB#%x Diag-data (Version: %d)\n", 2668c2ecf20Sopenharmony_ci hose->global_number, be32_to_cpu(common->version)); 2678c2ecf20Sopenharmony_ci 2688c2ecf20Sopenharmony_ci if (data->brdgCtl) 2698c2ecf20Sopenharmony_ci pr_info("brdgCtl: %08x\n", 2708c2ecf20Sopenharmony_ci be32_to_cpu(data->brdgCtl)); 2718c2ecf20Sopenharmony_ci if (data->portStatusReg || data->rootCmplxStatus || 2728c2ecf20Sopenharmony_ci data->busAgentStatus) 2738c2ecf20Sopenharmony_ci pr_info("UtlSts: %08x %08x %08x\n", 2748c2ecf20Sopenharmony_ci be32_to_cpu(data->portStatusReg), 2758c2ecf20Sopenharmony_ci be32_to_cpu(data->rootCmplxStatus), 2768c2ecf20Sopenharmony_ci be32_to_cpu(data->busAgentStatus)); 2778c2ecf20Sopenharmony_ci if (data->deviceStatus || data->slotStatus || 2788c2ecf20Sopenharmony_ci data->linkStatus || data->devCmdStatus || 2798c2ecf20Sopenharmony_ci data->devSecStatus) 2808c2ecf20Sopenharmony_ci pr_info("RootSts: %08x %08x %08x %08x %08x\n", 2818c2ecf20Sopenharmony_ci be32_to_cpu(data->deviceStatus), 2828c2ecf20Sopenharmony_ci be32_to_cpu(data->slotStatus), 2838c2ecf20Sopenharmony_ci be32_to_cpu(data->linkStatus), 2848c2ecf20Sopenharmony_ci be32_to_cpu(data->devCmdStatus), 2858c2ecf20Sopenharmony_ci be32_to_cpu(data->devSecStatus)); 2868c2ecf20Sopenharmony_ci if (data->rootErrorStatus || data->uncorrErrorStatus || 2878c2ecf20Sopenharmony_ci data->corrErrorStatus) 2888c2ecf20Sopenharmony_ci pr_info("RootErrSts: %08x %08x %08x\n", 2898c2ecf20Sopenharmony_ci be32_to_cpu(data->rootErrorStatus), 2908c2ecf20Sopenharmony_ci be32_to_cpu(data->uncorrErrorStatus), 2918c2ecf20Sopenharmony_ci be32_to_cpu(data->corrErrorStatus)); 2928c2ecf20Sopenharmony_ci if (data->tlpHdr1 || data->tlpHdr2 || 2938c2ecf20Sopenharmony_ci data->tlpHdr3 || data->tlpHdr4) 2948c2ecf20Sopenharmony_ci pr_info("RootErrLog: %08x %08x %08x %08x\n", 2958c2ecf20Sopenharmony_ci be32_to_cpu(data->tlpHdr1), 2968c2ecf20Sopenharmony_ci be32_to_cpu(data->tlpHdr2), 2978c2ecf20Sopenharmony_ci be32_to_cpu(data->tlpHdr3), 2988c2ecf20Sopenharmony_ci be32_to_cpu(data->tlpHdr4)); 2998c2ecf20Sopenharmony_ci if (data->sourceId || data->errorClass || 3008c2ecf20Sopenharmony_ci data->correlator) 3018c2ecf20Sopenharmony_ci pr_info("RootErrLog1: %08x %016llx %016llx\n", 3028c2ecf20Sopenharmony_ci be32_to_cpu(data->sourceId), 3038c2ecf20Sopenharmony_ci be64_to_cpu(data->errorClass), 3048c2ecf20Sopenharmony_ci be64_to_cpu(data->correlator)); 3058c2ecf20Sopenharmony_ci if (data->p7iocPlssr || data->p7iocCsr) 3068c2ecf20Sopenharmony_ci pr_info("PhbSts: %016llx %016llx\n", 3078c2ecf20Sopenharmony_ci be64_to_cpu(data->p7iocPlssr), 3088c2ecf20Sopenharmony_ci be64_to_cpu(data->p7iocCsr)); 3098c2ecf20Sopenharmony_ci if (data->lemFir) 3108c2ecf20Sopenharmony_ci pr_info("Lem: %016llx %016llx %016llx\n", 3118c2ecf20Sopenharmony_ci be64_to_cpu(data->lemFir), 3128c2ecf20Sopenharmony_ci be64_to_cpu(data->lemErrorMask), 3138c2ecf20Sopenharmony_ci be64_to_cpu(data->lemWOF)); 3148c2ecf20Sopenharmony_ci if (data->phbErrorStatus) 3158c2ecf20Sopenharmony_ci pr_info("PhbErr: %016llx %016llx %016llx %016llx\n", 3168c2ecf20Sopenharmony_ci be64_to_cpu(data->phbErrorStatus), 3178c2ecf20Sopenharmony_ci be64_to_cpu(data->phbFirstErrorStatus), 3188c2ecf20Sopenharmony_ci be64_to_cpu(data->phbErrorLog0), 3198c2ecf20Sopenharmony_ci be64_to_cpu(data->phbErrorLog1)); 3208c2ecf20Sopenharmony_ci if (data->mmioErrorStatus) 3218c2ecf20Sopenharmony_ci pr_info("OutErr: %016llx %016llx %016llx %016llx\n", 3228c2ecf20Sopenharmony_ci be64_to_cpu(data->mmioErrorStatus), 3238c2ecf20Sopenharmony_ci be64_to_cpu(data->mmioFirstErrorStatus), 3248c2ecf20Sopenharmony_ci be64_to_cpu(data->mmioErrorLog0), 3258c2ecf20Sopenharmony_ci be64_to_cpu(data->mmioErrorLog1)); 3268c2ecf20Sopenharmony_ci if (data->dma0ErrorStatus) 3278c2ecf20Sopenharmony_ci pr_info("InAErr: %016llx %016llx %016llx %016llx\n", 3288c2ecf20Sopenharmony_ci be64_to_cpu(data->dma0ErrorStatus), 3298c2ecf20Sopenharmony_ci be64_to_cpu(data->dma0FirstErrorStatus), 3308c2ecf20Sopenharmony_ci be64_to_cpu(data->dma0ErrorLog0), 3318c2ecf20Sopenharmony_ci be64_to_cpu(data->dma0ErrorLog1)); 3328c2ecf20Sopenharmony_ci if (data->dma1ErrorStatus) 3338c2ecf20Sopenharmony_ci pr_info("InBErr: %016llx %016llx %016llx %016llx\n", 3348c2ecf20Sopenharmony_ci be64_to_cpu(data->dma1ErrorStatus), 3358c2ecf20Sopenharmony_ci be64_to_cpu(data->dma1FirstErrorStatus), 3368c2ecf20Sopenharmony_ci be64_to_cpu(data->dma1ErrorLog0), 3378c2ecf20Sopenharmony_ci be64_to_cpu(data->dma1ErrorLog1)); 3388c2ecf20Sopenharmony_ci 3398c2ecf20Sopenharmony_ci pnv_pci_dump_pest(data->pestA, data->pestB, OPAL_P7IOC_NUM_PEST_REGS); 3408c2ecf20Sopenharmony_ci} 3418c2ecf20Sopenharmony_ci 3428c2ecf20Sopenharmony_cistatic void pnv_pci_dump_phb3_diag_data(struct pci_controller *hose, 3438c2ecf20Sopenharmony_ci struct OpalIoPhbErrorCommon *common) 3448c2ecf20Sopenharmony_ci{ 3458c2ecf20Sopenharmony_ci struct OpalIoPhb3ErrorData *data; 3468c2ecf20Sopenharmony_ci 3478c2ecf20Sopenharmony_ci data = (struct OpalIoPhb3ErrorData*)common; 3488c2ecf20Sopenharmony_ci pr_info("PHB3 PHB#%x Diag-data (Version: %d)\n", 3498c2ecf20Sopenharmony_ci hose->global_number, be32_to_cpu(common->version)); 3508c2ecf20Sopenharmony_ci if (data->brdgCtl) 3518c2ecf20Sopenharmony_ci pr_info("brdgCtl: %08x\n", 3528c2ecf20Sopenharmony_ci be32_to_cpu(data->brdgCtl)); 3538c2ecf20Sopenharmony_ci if (data->portStatusReg || data->rootCmplxStatus || 3548c2ecf20Sopenharmony_ci data->busAgentStatus) 3558c2ecf20Sopenharmony_ci pr_info("UtlSts: %08x %08x %08x\n", 3568c2ecf20Sopenharmony_ci be32_to_cpu(data->portStatusReg), 3578c2ecf20Sopenharmony_ci be32_to_cpu(data->rootCmplxStatus), 3588c2ecf20Sopenharmony_ci be32_to_cpu(data->busAgentStatus)); 3598c2ecf20Sopenharmony_ci if (data->deviceStatus || data->slotStatus || 3608c2ecf20Sopenharmony_ci data->linkStatus || data->devCmdStatus || 3618c2ecf20Sopenharmony_ci data->devSecStatus) 3628c2ecf20Sopenharmony_ci pr_info("RootSts: %08x %08x %08x %08x %08x\n", 3638c2ecf20Sopenharmony_ci be32_to_cpu(data->deviceStatus), 3648c2ecf20Sopenharmony_ci be32_to_cpu(data->slotStatus), 3658c2ecf20Sopenharmony_ci be32_to_cpu(data->linkStatus), 3668c2ecf20Sopenharmony_ci be32_to_cpu(data->devCmdStatus), 3678c2ecf20Sopenharmony_ci be32_to_cpu(data->devSecStatus)); 3688c2ecf20Sopenharmony_ci if (data->rootErrorStatus || data->uncorrErrorStatus || 3698c2ecf20Sopenharmony_ci data->corrErrorStatus) 3708c2ecf20Sopenharmony_ci pr_info("RootErrSts: %08x %08x %08x\n", 3718c2ecf20Sopenharmony_ci be32_to_cpu(data->rootErrorStatus), 3728c2ecf20Sopenharmony_ci be32_to_cpu(data->uncorrErrorStatus), 3738c2ecf20Sopenharmony_ci be32_to_cpu(data->corrErrorStatus)); 3748c2ecf20Sopenharmony_ci if (data->tlpHdr1 || data->tlpHdr2 || 3758c2ecf20Sopenharmony_ci data->tlpHdr3 || data->tlpHdr4) 3768c2ecf20Sopenharmony_ci pr_info("RootErrLog: %08x %08x %08x %08x\n", 3778c2ecf20Sopenharmony_ci be32_to_cpu(data->tlpHdr1), 3788c2ecf20Sopenharmony_ci be32_to_cpu(data->tlpHdr2), 3798c2ecf20Sopenharmony_ci be32_to_cpu(data->tlpHdr3), 3808c2ecf20Sopenharmony_ci be32_to_cpu(data->tlpHdr4)); 3818c2ecf20Sopenharmony_ci if (data->sourceId || data->errorClass || 3828c2ecf20Sopenharmony_ci data->correlator) 3838c2ecf20Sopenharmony_ci pr_info("RootErrLog1: %08x %016llx %016llx\n", 3848c2ecf20Sopenharmony_ci be32_to_cpu(data->sourceId), 3858c2ecf20Sopenharmony_ci be64_to_cpu(data->errorClass), 3868c2ecf20Sopenharmony_ci be64_to_cpu(data->correlator)); 3878c2ecf20Sopenharmony_ci if (data->nFir) 3888c2ecf20Sopenharmony_ci pr_info("nFir: %016llx %016llx %016llx\n", 3898c2ecf20Sopenharmony_ci be64_to_cpu(data->nFir), 3908c2ecf20Sopenharmony_ci be64_to_cpu(data->nFirMask), 3918c2ecf20Sopenharmony_ci be64_to_cpu(data->nFirWOF)); 3928c2ecf20Sopenharmony_ci if (data->phbPlssr || data->phbCsr) 3938c2ecf20Sopenharmony_ci pr_info("PhbSts: %016llx %016llx\n", 3948c2ecf20Sopenharmony_ci be64_to_cpu(data->phbPlssr), 3958c2ecf20Sopenharmony_ci be64_to_cpu(data->phbCsr)); 3968c2ecf20Sopenharmony_ci if (data->lemFir) 3978c2ecf20Sopenharmony_ci pr_info("Lem: %016llx %016llx %016llx\n", 3988c2ecf20Sopenharmony_ci be64_to_cpu(data->lemFir), 3998c2ecf20Sopenharmony_ci be64_to_cpu(data->lemErrorMask), 4008c2ecf20Sopenharmony_ci be64_to_cpu(data->lemWOF)); 4018c2ecf20Sopenharmony_ci if (data->phbErrorStatus) 4028c2ecf20Sopenharmony_ci pr_info("PhbErr: %016llx %016llx %016llx %016llx\n", 4038c2ecf20Sopenharmony_ci be64_to_cpu(data->phbErrorStatus), 4048c2ecf20Sopenharmony_ci be64_to_cpu(data->phbFirstErrorStatus), 4058c2ecf20Sopenharmony_ci be64_to_cpu(data->phbErrorLog0), 4068c2ecf20Sopenharmony_ci be64_to_cpu(data->phbErrorLog1)); 4078c2ecf20Sopenharmony_ci if (data->mmioErrorStatus) 4088c2ecf20Sopenharmony_ci pr_info("OutErr: %016llx %016llx %016llx %016llx\n", 4098c2ecf20Sopenharmony_ci be64_to_cpu(data->mmioErrorStatus), 4108c2ecf20Sopenharmony_ci be64_to_cpu(data->mmioFirstErrorStatus), 4118c2ecf20Sopenharmony_ci be64_to_cpu(data->mmioErrorLog0), 4128c2ecf20Sopenharmony_ci be64_to_cpu(data->mmioErrorLog1)); 4138c2ecf20Sopenharmony_ci if (data->dma0ErrorStatus) 4148c2ecf20Sopenharmony_ci pr_info("InAErr: %016llx %016llx %016llx %016llx\n", 4158c2ecf20Sopenharmony_ci be64_to_cpu(data->dma0ErrorStatus), 4168c2ecf20Sopenharmony_ci be64_to_cpu(data->dma0FirstErrorStatus), 4178c2ecf20Sopenharmony_ci be64_to_cpu(data->dma0ErrorLog0), 4188c2ecf20Sopenharmony_ci be64_to_cpu(data->dma0ErrorLog1)); 4198c2ecf20Sopenharmony_ci if (data->dma1ErrorStatus) 4208c2ecf20Sopenharmony_ci pr_info("InBErr: %016llx %016llx %016llx %016llx\n", 4218c2ecf20Sopenharmony_ci be64_to_cpu(data->dma1ErrorStatus), 4228c2ecf20Sopenharmony_ci be64_to_cpu(data->dma1FirstErrorStatus), 4238c2ecf20Sopenharmony_ci be64_to_cpu(data->dma1ErrorLog0), 4248c2ecf20Sopenharmony_ci be64_to_cpu(data->dma1ErrorLog1)); 4258c2ecf20Sopenharmony_ci 4268c2ecf20Sopenharmony_ci pnv_pci_dump_pest(data->pestA, data->pestB, OPAL_PHB3_NUM_PEST_REGS); 4278c2ecf20Sopenharmony_ci} 4288c2ecf20Sopenharmony_ci 4298c2ecf20Sopenharmony_cistatic void pnv_pci_dump_phb4_diag_data(struct pci_controller *hose, 4308c2ecf20Sopenharmony_ci struct OpalIoPhbErrorCommon *common) 4318c2ecf20Sopenharmony_ci{ 4328c2ecf20Sopenharmony_ci struct OpalIoPhb4ErrorData *data; 4338c2ecf20Sopenharmony_ci 4348c2ecf20Sopenharmony_ci data = (struct OpalIoPhb4ErrorData*)common; 4358c2ecf20Sopenharmony_ci pr_info("PHB4 PHB#%d Diag-data (Version: %d)\n", 4368c2ecf20Sopenharmony_ci hose->global_number, be32_to_cpu(common->version)); 4378c2ecf20Sopenharmony_ci if (data->brdgCtl) 4388c2ecf20Sopenharmony_ci pr_info("brdgCtl: %08x\n", 4398c2ecf20Sopenharmony_ci be32_to_cpu(data->brdgCtl)); 4408c2ecf20Sopenharmony_ci if (data->deviceStatus || data->slotStatus || 4418c2ecf20Sopenharmony_ci data->linkStatus || data->devCmdStatus || 4428c2ecf20Sopenharmony_ci data->devSecStatus) 4438c2ecf20Sopenharmony_ci pr_info("RootSts: %08x %08x %08x %08x %08x\n", 4448c2ecf20Sopenharmony_ci be32_to_cpu(data->deviceStatus), 4458c2ecf20Sopenharmony_ci be32_to_cpu(data->slotStatus), 4468c2ecf20Sopenharmony_ci be32_to_cpu(data->linkStatus), 4478c2ecf20Sopenharmony_ci be32_to_cpu(data->devCmdStatus), 4488c2ecf20Sopenharmony_ci be32_to_cpu(data->devSecStatus)); 4498c2ecf20Sopenharmony_ci if (data->rootErrorStatus || data->uncorrErrorStatus || 4508c2ecf20Sopenharmony_ci data->corrErrorStatus) 4518c2ecf20Sopenharmony_ci pr_info("RootErrSts: %08x %08x %08x\n", 4528c2ecf20Sopenharmony_ci be32_to_cpu(data->rootErrorStatus), 4538c2ecf20Sopenharmony_ci be32_to_cpu(data->uncorrErrorStatus), 4548c2ecf20Sopenharmony_ci be32_to_cpu(data->corrErrorStatus)); 4558c2ecf20Sopenharmony_ci if (data->tlpHdr1 || data->tlpHdr2 || 4568c2ecf20Sopenharmony_ci data->tlpHdr3 || data->tlpHdr4) 4578c2ecf20Sopenharmony_ci pr_info("RootErrLog: %08x %08x %08x %08x\n", 4588c2ecf20Sopenharmony_ci be32_to_cpu(data->tlpHdr1), 4598c2ecf20Sopenharmony_ci be32_to_cpu(data->tlpHdr2), 4608c2ecf20Sopenharmony_ci be32_to_cpu(data->tlpHdr3), 4618c2ecf20Sopenharmony_ci be32_to_cpu(data->tlpHdr4)); 4628c2ecf20Sopenharmony_ci if (data->sourceId) 4638c2ecf20Sopenharmony_ci pr_info("sourceId: %08x\n", be32_to_cpu(data->sourceId)); 4648c2ecf20Sopenharmony_ci if (data->nFir) 4658c2ecf20Sopenharmony_ci pr_info("nFir: %016llx %016llx %016llx\n", 4668c2ecf20Sopenharmony_ci be64_to_cpu(data->nFir), 4678c2ecf20Sopenharmony_ci be64_to_cpu(data->nFirMask), 4688c2ecf20Sopenharmony_ci be64_to_cpu(data->nFirWOF)); 4698c2ecf20Sopenharmony_ci if (data->phbPlssr || data->phbCsr) 4708c2ecf20Sopenharmony_ci pr_info("PhbSts: %016llx %016llx\n", 4718c2ecf20Sopenharmony_ci be64_to_cpu(data->phbPlssr), 4728c2ecf20Sopenharmony_ci be64_to_cpu(data->phbCsr)); 4738c2ecf20Sopenharmony_ci if (data->lemFir) 4748c2ecf20Sopenharmony_ci pr_info("Lem: %016llx %016llx %016llx\n", 4758c2ecf20Sopenharmony_ci be64_to_cpu(data->lemFir), 4768c2ecf20Sopenharmony_ci be64_to_cpu(data->lemErrorMask), 4778c2ecf20Sopenharmony_ci be64_to_cpu(data->lemWOF)); 4788c2ecf20Sopenharmony_ci if (data->phbErrorStatus) 4798c2ecf20Sopenharmony_ci pr_info("PhbErr: %016llx %016llx %016llx %016llx\n", 4808c2ecf20Sopenharmony_ci be64_to_cpu(data->phbErrorStatus), 4818c2ecf20Sopenharmony_ci be64_to_cpu(data->phbFirstErrorStatus), 4828c2ecf20Sopenharmony_ci be64_to_cpu(data->phbErrorLog0), 4838c2ecf20Sopenharmony_ci be64_to_cpu(data->phbErrorLog1)); 4848c2ecf20Sopenharmony_ci if (data->phbTxeErrorStatus) 4858c2ecf20Sopenharmony_ci pr_info("PhbTxeErr: %016llx %016llx %016llx %016llx\n", 4868c2ecf20Sopenharmony_ci be64_to_cpu(data->phbTxeErrorStatus), 4878c2ecf20Sopenharmony_ci be64_to_cpu(data->phbTxeFirstErrorStatus), 4888c2ecf20Sopenharmony_ci be64_to_cpu(data->phbTxeErrorLog0), 4898c2ecf20Sopenharmony_ci be64_to_cpu(data->phbTxeErrorLog1)); 4908c2ecf20Sopenharmony_ci if (data->phbRxeArbErrorStatus) 4918c2ecf20Sopenharmony_ci pr_info("RxeArbErr: %016llx %016llx %016llx %016llx\n", 4928c2ecf20Sopenharmony_ci be64_to_cpu(data->phbRxeArbErrorStatus), 4938c2ecf20Sopenharmony_ci be64_to_cpu(data->phbRxeArbFirstErrorStatus), 4948c2ecf20Sopenharmony_ci be64_to_cpu(data->phbRxeArbErrorLog0), 4958c2ecf20Sopenharmony_ci be64_to_cpu(data->phbRxeArbErrorLog1)); 4968c2ecf20Sopenharmony_ci if (data->phbRxeMrgErrorStatus) 4978c2ecf20Sopenharmony_ci pr_info("RxeMrgErr: %016llx %016llx %016llx %016llx\n", 4988c2ecf20Sopenharmony_ci be64_to_cpu(data->phbRxeMrgErrorStatus), 4998c2ecf20Sopenharmony_ci be64_to_cpu(data->phbRxeMrgFirstErrorStatus), 5008c2ecf20Sopenharmony_ci be64_to_cpu(data->phbRxeMrgErrorLog0), 5018c2ecf20Sopenharmony_ci be64_to_cpu(data->phbRxeMrgErrorLog1)); 5028c2ecf20Sopenharmony_ci if (data->phbRxeTceErrorStatus) 5038c2ecf20Sopenharmony_ci pr_info("RxeTceErr: %016llx %016llx %016llx %016llx\n", 5048c2ecf20Sopenharmony_ci be64_to_cpu(data->phbRxeTceErrorStatus), 5058c2ecf20Sopenharmony_ci be64_to_cpu(data->phbRxeTceFirstErrorStatus), 5068c2ecf20Sopenharmony_ci be64_to_cpu(data->phbRxeTceErrorLog0), 5078c2ecf20Sopenharmony_ci be64_to_cpu(data->phbRxeTceErrorLog1)); 5088c2ecf20Sopenharmony_ci 5098c2ecf20Sopenharmony_ci if (data->phbPblErrorStatus) 5108c2ecf20Sopenharmony_ci pr_info("PblErr: %016llx %016llx %016llx %016llx\n", 5118c2ecf20Sopenharmony_ci be64_to_cpu(data->phbPblErrorStatus), 5128c2ecf20Sopenharmony_ci be64_to_cpu(data->phbPblFirstErrorStatus), 5138c2ecf20Sopenharmony_ci be64_to_cpu(data->phbPblErrorLog0), 5148c2ecf20Sopenharmony_ci be64_to_cpu(data->phbPblErrorLog1)); 5158c2ecf20Sopenharmony_ci if (data->phbPcieDlpErrorStatus) 5168c2ecf20Sopenharmony_ci pr_info("PcieDlp: %016llx %016llx %016llx\n", 5178c2ecf20Sopenharmony_ci be64_to_cpu(data->phbPcieDlpErrorLog1), 5188c2ecf20Sopenharmony_ci be64_to_cpu(data->phbPcieDlpErrorLog2), 5198c2ecf20Sopenharmony_ci be64_to_cpu(data->phbPcieDlpErrorStatus)); 5208c2ecf20Sopenharmony_ci if (data->phbRegbErrorStatus) 5218c2ecf20Sopenharmony_ci pr_info("RegbErr: %016llx %016llx %016llx %016llx\n", 5228c2ecf20Sopenharmony_ci be64_to_cpu(data->phbRegbErrorStatus), 5238c2ecf20Sopenharmony_ci be64_to_cpu(data->phbRegbFirstErrorStatus), 5248c2ecf20Sopenharmony_ci be64_to_cpu(data->phbRegbErrorLog0), 5258c2ecf20Sopenharmony_ci be64_to_cpu(data->phbRegbErrorLog1)); 5268c2ecf20Sopenharmony_ci 5278c2ecf20Sopenharmony_ci 5288c2ecf20Sopenharmony_ci pnv_pci_dump_pest(data->pestA, data->pestB, OPAL_PHB4_NUM_PEST_REGS); 5298c2ecf20Sopenharmony_ci} 5308c2ecf20Sopenharmony_ci 5318c2ecf20Sopenharmony_civoid pnv_pci_dump_phb_diag_data(struct pci_controller *hose, 5328c2ecf20Sopenharmony_ci unsigned char *log_buff) 5338c2ecf20Sopenharmony_ci{ 5348c2ecf20Sopenharmony_ci struct OpalIoPhbErrorCommon *common; 5358c2ecf20Sopenharmony_ci 5368c2ecf20Sopenharmony_ci if (!hose || !log_buff) 5378c2ecf20Sopenharmony_ci return; 5388c2ecf20Sopenharmony_ci 5398c2ecf20Sopenharmony_ci common = (struct OpalIoPhbErrorCommon *)log_buff; 5408c2ecf20Sopenharmony_ci switch (be32_to_cpu(common->ioType)) { 5418c2ecf20Sopenharmony_ci case OPAL_PHB_ERROR_DATA_TYPE_P7IOC: 5428c2ecf20Sopenharmony_ci pnv_pci_dump_p7ioc_diag_data(hose, common); 5438c2ecf20Sopenharmony_ci break; 5448c2ecf20Sopenharmony_ci case OPAL_PHB_ERROR_DATA_TYPE_PHB3: 5458c2ecf20Sopenharmony_ci pnv_pci_dump_phb3_diag_data(hose, common); 5468c2ecf20Sopenharmony_ci break; 5478c2ecf20Sopenharmony_ci case OPAL_PHB_ERROR_DATA_TYPE_PHB4: 5488c2ecf20Sopenharmony_ci pnv_pci_dump_phb4_diag_data(hose, common); 5498c2ecf20Sopenharmony_ci break; 5508c2ecf20Sopenharmony_ci default: 5518c2ecf20Sopenharmony_ci pr_warn("%s: Unrecognized ioType %d\n", 5528c2ecf20Sopenharmony_ci __func__, be32_to_cpu(common->ioType)); 5538c2ecf20Sopenharmony_ci } 5548c2ecf20Sopenharmony_ci} 5558c2ecf20Sopenharmony_ci 5568c2ecf20Sopenharmony_cistatic void pnv_pci_handle_eeh_config(struct pnv_phb *phb, u32 pe_no) 5578c2ecf20Sopenharmony_ci{ 5588c2ecf20Sopenharmony_ci unsigned long flags, rc; 5598c2ecf20Sopenharmony_ci int has_diag, ret = 0; 5608c2ecf20Sopenharmony_ci 5618c2ecf20Sopenharmony_ci spin_lock_irqsave(&phb->lock, flags); 5628c2ecf20Sopenharmony_ci 5638c2ecf20Sopenharmony_ci /* Fetch PHB diag-data */ 5648c2ecf20Sopenharmony_ci rc = opal_pci_get_phb_diag_data2(phb->opal_id, phb->diag_data, 5658c2ecf20Sopenharmony_ci phb->diag_data_size); 5668c2ecf20Sopenharmony_ci has_diag = (rc == OPAL_SUCCESS); 5678c2ecf20Sopenharmony_ci 5688c2ecf20Sopenharmony_ci /* If PHB supports compound PE, to handle it */ 5698c2ecf20Sopenharmony_ci if (phb->unfreeze_pe) { 5708c2ecf20Sopenharmony_ci ret = phb->unfreeze_pe(phb, 5718c2ecf20Sopenharmony_ci pe_no, 5728c2ecf20Sopenharmony_ci OPAL_EEH_ACTION_CLEAR_FREEZE_ALL); 5738c2ecf20Sopenharmony_ci } else { 5748c2ecf20Sopenharmony_ci rc = opal_pci_eeh_freeze_clear(phb->opal_id, 5758c2ecf20Sopenharmony_ci pe_no, 5768c2ecf20Sopenharmony_ci OPAL_EEH_ACTION_CLEAR_FREEZE_ALL); 5778c2ecf20Sopenharmony_ci if (rc) { 5788c2ecf20Sopenharmony_ci pr_warn("%s: Failure %ld clearing frozen " 5798c2ecf20Sopenharmony_ci "PHB#%x-PE#%x\n", 5808c2ecf20Sopenharmony_ci __func__, rc, phb->hose->global_number, 5818c2ecf20Sopenharmony_ci pe_no); 5828c2ecf20Sopenharmony_ci ret = -EIO; 5838c2ecf20Sopenharmony_ci } 5848c2ecf20Sopenharmony_ci } 5858c2ecf20Sopenharmony_ci 5868c2ecf20Sopenharmony_ci /* 5878c2ecf20Sopenharmony_ci * For now, let's only display the diag buffer when we fail to clear 5888c2ecf20Sopenharmony_ci * the EEH status. We'll do more sensible things later when we have 5898c2ecf20Sopenharmony_ci * proper EEH support. We need to make sure we don't pollute ourselves 5908c2ecf20Sopenharmony_ci * with the normal errors generated when probing empty slots 5918c2ecf20Sopenharmony_ci */ 5928c2ecf20Sopenharmony_ci if (has_diag && ret) 5938c2ecf20Sopenharmony_ci pnv_pci_dump_phb_diag_data(phb->hose, phb->diag_data); 5948c2ecf20Sopenharmony_ci 5958c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&phb->lock, flags); 5968c2ecf20Sopenharmony_ci} 5978c2ecf20Sopenharmony_ci 5988c2ecf20Sopenharmony_cistatic void pnv_pci_config_check_eeh(struct pci_dn *pdn) 5998c2ecf20Sopenharmony_ci{ 6008c2ecf20Sopenharmony_ci struct pnv_phb *phb = pdn->phb->private_data; 6018c2ecf20Sopenharmony_ci u8 fstate = 0; 6028c2ecf20Sopenharmony_ci __be16 pcierr = 0; 6038c2ecf20Sopenharmony_ci unsigned int pe_no; 6048c2ecf20Sopenharmony_ci s64 rc; 6058c2ecf20Sopenharmony_ci 6068c2ecf20Sopenharmony_ci /* 6078c2ecf20Sopenharmony_ci * Get the PE#. During the PCI probe stage, we might not 6088c2ecf20Sopenharmony_ci * setup that yet. So all ER errors should be mapped to 6098c2ecf20Sopenharmony_ci * reserved PE. 6108c2ecf20Sopenharmony_ci */ 6118c2ecf20Sopenharmony_ci pe_no = pdn->pe_number; 6128c2ecf20Sopenharmony_ci if (pe_no == IODA_INVALID_PE) { 6138c2ecf20Sopenharmony_ci pe_no = phb->ioda.reserved_pe_idx; 6148c2ecf20Sopenharmony_ci } 6158c2ecf20Sopenharmony_ci 6168c2ecf20Sopenharmony_ci /* 6178c2ecf20Sopenharmony_ci * Fetch frozen state. If the PHB support compound PE, 6188c2ecf20Sopenharmony_ci * we need handle that case. 6198c2ecf20Sopenharmony_ci */ 6208c2ecf20Sopenharmony_ci if (phb->get_pe_state) { 6218c2ecf20Sopenharmony_ci fstate = phb->get_pe_state(phb, pe_no); 6228c2ecf20Sopenharmony_ci } else { 6238c2ecf20Sopenharmony_ci rc = opal_pci_eeh_freeze_status(phb->opal_id, 6248c2ecf20Sopenharmony_ci pe_no, 6258c2ecf20Sopenharmony_ci &fstate, 6268c2ecf20Sopenharmony_ci &pcierr, 6278c2ecf20Sopenharmony_ci NULL); 6288c2ecf20Sopenharmony_ci if (rc) { 6298c2ecf20Sopenharmony_ci pr_warn("%s: Failure %lld getting PHB#%x-PE#%x state\n", 6308c2ecf20Sopenharmony_ci __func__, rc, phb->hose->global_number, pe_no); 6318c2ecf20Sopenharmony_ci return; 6328c2ecf20Sopenharmony_ci } 6338c2ecf20Sopenharmony_ci } 6348c2ecf20Sopenharmony_ci 6358c2ecf20Sopenharmony_ci pr_devel(" -> EEH check, bdfn=%04x PE#%x fstate=%x\n", 6368c2ecf20Sopenharmony_ci (pdn->busno << 8) | (pdn->devfn), pe_no, fstate); 6378c2ecf20Sopenharmony_ci 6388c2ecf20Sopenharmony_ci /* Clear the frozen state if applicable */ 6398c2ecf20Sopenharmony_ci if (fstate == OPAL_EEH_STOPPED_MMIO_FREEZE || 6408c2ecf20Sopenharmony_ci fstate == OPAL_EEH_STOPPED_DMA_FREEZE || 6418c2ecf20Sopenharmony_ci fstate == OPAL_EEH_STOPPED_MMIO_DMA_FREEZE) { 6428c2ecf20Sopenharmony_ci /* 6438c2ecf20Sopenharmony_ci * If PHB supports compound PE, freeze it for 6448c2ecf20Sopenharmony_ci * consistency. 6458c2ecf20Sopenharmony_ci */ 6468c2ecf20Sopenharmony_ci if (phb->freeze_pe) 6478c2ecf20Sopenharmony_ci phb->freeze_pe(phb, pe_no); 6488c2ecf20Sopenharmony_ci 6498c2ecf20Sopenharmony_ci pnv_pci_handle_eeh_config(phb, pe_no); 6508c2ecf20Sopenharmony_ci } 6518c2ecf20Sopenharmony_ci} 6528c2ecf20Sopenharmony_ci 6538c2ecf20Sopenharmony_ciint pnv_pci_cfg_read(struct pci_dn *pdn, 6548c2ecf20Sopenharmony_ci int where, int size, u32 *val) 6558c2ecf20Sopenharmony_ci{ 6568c2ecf20Sopenharmony_ci struct pnv_phb *phb = pdn->phb->private_data; 6578c2ecf20Sopenharmony_ci u32 bdfn = (pdn->busno << 8) | pdn->devfn; 6588c2ecf20Sopenharmony_ci s64 rc; 6598c2ecf20Sopenharmony_ci 6608c2ecf20Sopenharmony_ci switch (size) { 6618c2ecf20Sopenharmony_ci case 1: { 6628c2ecf20Sopenharmony_ci u8 v8; 6638c2ecf20Sopenharmony_ci rc = opal_pci_config_read_byte(phb->opal_id, bdfn, where, &v8); 6648c2ecf20Sopenharmony_ci *val = (rc == OPAL_SUCCESS) ? v8 : 0xff; 6658c2ecf20Sopenharmony_ci break; 6668c2ecf20Sopenharmony_ci } 6678c2ecf20Sopenharmony_ci case 2: { 6688c2ecf20Sopenharmony_ci __be16 v16; 6698c2ecf20Sopenharmony_ci rc = opal_pci_config_read_half_word(phb->opal_id, bdfn, where, 6708c2ecf20Sopenharmony_ci &v16); 6718c2ecf20Sopenharmony_ci *val = (rc == OPAL_SUCCESS) ? be16_to_cpu(v16) : 0xffff; 6728c2ecf20Sopenharmony_ci break; 6738c2ecf20Sopenharmony_ci } 6748c2ecf20Sopenharmony_ci case 4: { 6758c2ecf20Sopenharmony_ci __be32 v32; 6768c2ecf20Sopenharmony_ci rc = opal_pci_config_read_word(phb->opal_id, bdfn, where, &v32); 6778c2ecf20Sopenharmony_ci *val = (rc == OPAL_SUCCESS) ? be32_to_cpu(v32) : 0xffffffff; 6788c2ecf20Sopenharmony_ci break; 6798c2ecf20Sopenharmony_ci } 6808c2ecf20Sopenharmony_ci default: 6818c2ecf20Sopenharmony_ci return PCIBIOS_FUNC_NOT_SUPPORTED; 6828c2ecf20Sopenharmony_ci } 6838c2ecf20Sopenharmony_ci 6848c2ecf20Sopenharmony_ci pr_devel("%s: bus: %x devfn: %x +%x/%x -> %08x\n", 6858c2ecf20Sopenharmony_ci __func__, pdn->busno, pdn->devfn, where, size, *val); 6868c2ecf20Sopenharmony_ci return PCIBIOS_SUCCESSFUL; 6878c2ecf20Sopenharmony_ci} 6888c2ecf20Sopenharmony_ci 6898c2ecf20Sopenharmony_ciint pnv_pci_cfg_write(struct pci_dn *pdn, 6908c2ecf20Sopenharmony_ci int where, int size, u32 val) 6918c2ecf20Sopenharmony_ci{ 6928c2ecf20Sopenharmony_ci struct pnv_phb *phb = pdn->phb->private_data; 6938c2ecf20Sopenharmony_ci u32 bdfn = (pdn->busno << 8) | pdn->devfn; 6948c2ecf20Sopenharmony_ci 6958c2ecf20Sopenharmony_ci pr_devel("%s: bus: %x devfn: %x +%x/%x -> %08x\n", 6968c2ecf20Sopenharmony_ci __func__, pdn->busno, pdn->devfn, where, size, val); 6978c2ecf20Sopenharmony_ci switch (size) { 6988c2ecf20Sopenharmony_ci case 1: 6998c2ecf20Sopenharmony_ci opal_pci_config_write_byte(phb->opal_id, bdfn, where, val); 7008c2ecf20Sopenharmony_ci break; 7018c2ecf20Sopenharmony_ci case 2: 7028c2ecf20Sopenharmony_ci opal_pci_config_write_half_word(phb->opal_id, bdfn, where, val); 7038c2ecf20Sopenharmony_ci break; 7048c2ecf20Sopenharmony_ci case 4: 7058c2ecf20Sopenharmony_ci opal_pci_config_write_word(phb->opal_id, bdfn, where, val); 7068c2ecf20Sopenharmony_ci break; 7078c2ecf20Sopenharmony_ci default: 7088c2ecf20Sopenharmony_ci return PCIBIOS_FUNC_NOT_SUPPORTED; 7098c2ecf20Sopenharmony_ci } 7108c2ecf20Sopenharmony_ci 7118c2ecf20Sopenharmony_ci return PCIBIOS_SUCCESSFUL; 7128c2ecf20Sopenharmony_ci} 7138c2ecf20Sopenharmony_ci 7148c2ecf20Sopenharmony_ci#if CONFIG_EEH 7158c2ecf20Sopenharmony_cistatic bool pnv_pci_cfg_check(struct pci_dn *pdn) 7168c2ecf20Sopenharmony_ci{ 7178c2ecf20Sopenharmony_ci struct eeh_dev *edev = NULL; 7188c2ecf20Sopenharmony_ci struct pnv_phb *phb = pdn->phb->private_data; 7198c2ecf20Sopenharmony_ci 7208c2ecf20Sopenharmony_ci /* EEH not enabled ? */ 7218c2ecf20Sopenharmony_ci if (!(phb->flags & PNV_PHB_FLAG_EEH)) 7228c2ecf20Sopenharmony_ci return true; 7238c2ecf20Sopenharmony_ci 7248c2ecf20Sopenharmony_ci /* PE reset or device removed ? */ 7258c2ecf20Sopenharmony_ci edev = pdn->edev; 7268c2ecf20Sopenharmony_ci if (edev) { 7278c2ecf20Sopenharmony_ci if (edev->pe && 7288c2ecf20Sopenharmony_ci (edev->pe->state & EEH_PE_CFG_BLOCKED)) 7298c2ecf20Sopenharmony_ci return false; 7308c2ecf20Sopenharmony_ci 7318c2ecf20Sopenharmony_ci if (edev->mode & EEH_DEV_REMOVED) 7328c2ecf20Sopenharmony_ci return false; 7338c2ecf20Sopenharmony_ci } 7348c2ecf20Sopenharmony_ci 7358c2ecf20Sopenharmony_ci return true; 7368c2ecf20Sopenharmony_ci} 7378c2ecf20Sopenharmony_ci#else 7388c2ecf20Sopenharmony_cistatic inline pnv_pci_cfg_check(struct pci_dn *pdn) 7398c2ecf20Sopenharmony_ci{ 7408c2ecf20Sopenharmony_ci return true; 7418c2ecf20Sopenharmony_ci} 7428c2ecf20Sopenharmony_ci#endif /* CONFIG_EEH */ 7438c2ecf20Sopenharmony_ci 7448c2ecf20Sopenharmony_cistatic int pnv_pci_read_config(struct pci_bus *bus, 7458c2ecf20Sopenharmony_ci unsigned int devfn, 7468c2ecf20Sopenharmony_ci int where, int size, u32 *val) 7478c2ecf20Sopenharmony_ci{ 7488c2ecf20Sopenharmony_ci struct pci_dn *pdn; 7498c2ecf20Sopenharmony_ci struct pnv_phb *phb; 7508c2ecf20Sopenharmony_ci int ret; 7518c2ecf20Sopenharmony_ci 7528c2ecf20Sopenharmony_ci *val = 0xFFFFFFFF; 7538c2ecf20Sopenharmony_ci pdn = pci_get_pdn_by_devfn(bus, devfn); 7548c2ecf20Sopenharmony_ci if (!pdn) 7558c2ecf20Sopenharmony_ci return PCIBIOS_DEVICE_NOT_FOUND; 7568c2ecf20Sopenharmony_ci 7578c2ecf20Sopenharmony_ci if (!pnv_pci_cfg_check(pdn)) 7588c2ecf20Sopenharmony_ci return PCIBIOS_DEVICE_NOT_FOUND; 7598c2ecf20Sopenharmony_ci 7608c2ecf20Sopenharmony_ci ret = pnv_pci_cfg_read(pdn, where, size, val); 7618c2ecf20Sopenharmony_ci phb = pdn->phb->private_data; 7628c2ecf20Sopenharmony_ci if (phb->flags & PNV_PHB_FLAG_EEH && pdn->edev) { 7638c2ecf20Sopenharmony_ci if (*val == EEH_IO_ERROR_VALUE(size) && 7648c2ecf20Sopenharmony_ci eeh_dev_check_failure(pdn->edev)) 7658c2ecf20Sopenharmony_ci return PCIBIOS_DEVICE_NOT_FOUND; 7668c2ecf20Sopenharmony_ci } else { 7678c2ecf20Sopenharmony_ci pnv_pci_config_check_eeh(pdn); 7688c2ecf20Sopenharmony_ci } 7698c2ecf20Sopenharmony_ci 7708c2ecf20Sopenharmony_ci return ret; 7718c2ecf20Sopenharmony_ci} 7728c2ecf20Sopenharmony_ci 7738c2ecf20Sopenharmony_cistatic int pnv_pci_write_config(struct pci_bus *bus, 7748c2ecf20Sopenharmony_ci unsigned int devfn, 7758c2ecf20Sopenharmony_ci int where, int size, u32 val) 7768c2ecf20Sopenharmony_ci{ 7778c2ecf20Sopenharmony_ci struct pci_dn *pdn; 7788c2ecf20Sopenharmony_ci struct pnv_phb *phb; 7798c2ecf20Sopenharmony_ci int ret; 7808c2ecf20Sopenharmony_ci 7818c2ecf20Sopenharmony_ci pdn = pci_get_pdn_by_devfn(bus, devfn); 7828c2ecf20Sopenharmony_ci if (!pdn) 7838c2ecf20Sopenharmony_ci return PCIBIOS_DEVICE_NOT_FOUND; 7848c2ecf20Sopenharmony_ci 7858c2ecf20Sopenharmony_ci if (!pnv_pci_cfg_check(pdn)) 7868c2ecf20Sopenharmony_ci return PCIBIOS_DEVICE_NOT_FOUND; 7878c2ecf20Sopenharmony_ci 7888c2ecf20Sopenharmony_ci ret = pnv_pci_cfg_write(pdn, where, size, val); 7898c2ecf20Sopenharmony_ci phb = pdn->phb->private_data; 7908c2ecf20Sopenharmony_ci if (!(phb->flags & PNV_PHB_FLAG_EEH)) 7918c2ecf20Sopenharmony_ci pnv_pci_config_check_eeh(pdn); 7928c2ecf20Sopenharmony_ci 7938c2ecf20Sopenharmony_ci return ret; 7948c2ecf20Sopenharmony_ci} 7958c2ecf20Sopenharmony_ci 7968c2ecf20Sopenharmony_cistruct pci_ops pnv_pci_ops = { 7978c2ecf20Sopenharmony_ci .read = pnv_pci_read_config, 7988c2ecf20Sopenharmony_ci .write = pnv_pci_write_config, 7998c2ecf20Sopenharmony_ci}; 8008c2ecf20Sopenharmony_ci 8018c2ecf20Sopenharmony_cistruct iommu_table *pnv_pci_table_alloc(int nid) 8028c2ecf20Sopenharmony_ci{ 8038c2ecf20Sopenharmony_ci struct iommu_table *tbl; 8048c2ecf20Sopenharmony_ci 8058c2ecf20Sopenharmony_ci tbl = kzalloc_node(sizeof(struct iommu_table), GFP_KERNEL, nid); 8068c2ecf20Sopenharmony_ci if (!tbl) 8078c2ecf20Sopenharmony_ci return NULL; 8088c2ecf20Sopenharmony_ci 8098c2ecf20Sopenharmony_ci INIT_LIST_HEAD_RCU(&tbl->it_group_list); 8108c2ecf20Sopenharmony_ci kref_init(&tbl->it_kref); 8118c2ecf20Sopenharmony_ci 8128c2ecf20Sopenharmony_ci return tbl; 8138c2ecf20Sopenharmony_ci} 8148c2ecf20Sopenharmony_ci 8158c2ecf20Sopenharmony_cistruct device_node *pnv_pci_get_phb_node(struct pci_dev *dev) 8168c2ecf20Sopenharmony_ci{ 8178c2ecf20Sopenharmony_ci struct pci_controller *hose = pci_bus_to_host(dev->bus); 8188c2ecf20Sopenharmony_ci 8198c2ecf20Sopenharmony_ci return of_node_get(hose->dn); 8208c2ecf20Sopenharmony_ci} 8218c2ecf20Sopenharmony_ciEXPORT_SYMBOL(pnv_pci_get_phb_node); 8228c2ecf20Sopenharmony_ci 8238c2ecf20Sopenharmony_ciint pnv_pci_set_tunnel_bar(struct pci_dev *dev, u64 addr, int enable) 8248c2ecf20Sopenharmony_ci{ 8258c2ecf20Sopenharmony_ci struct pnv_phb *phb = pci_bus_to_pnvhb(dev->bus); 8268c2ecf20Sopenharmony_ci u64 tunnel_bar; 8278c2ecf20Sopenharmony_ci __be64 val; 8288c2ecf20Sopenharmony_ci int rc; 8298c2ecf20Sopenharmony_ci 8308c2ecf20Sopenharmony_ci if (!opal_check_token(OPAL_PCI_GET_PBCQ_TUNNEL_BAR)) 8318c2ecf20Sopenharmony_ci return -ENXIO; 8328c2ecf20Sopenharmony_ci if (!opal_check_token(OPAL_PCI_SET_PBCQ_TUNNEL_BAR)) 8338c2ecf20Sopenharmony_ci return -ENXIO; 8348c2ecf20Sopenharmony_ci 8358c2ecf20Sopenharmony_ci mutex_lock(&tunnel_mutex); 8368c2ecf20Sopenharmony_ci rc = opal_pci_get_pbcq_tunnel_bar(phb->opal_id, &val); 8378c2ecf20Sopenharmony_ci if (rc != OPAL_SUCCESS) { 8388c2ecf20Sopenharmony_ci rc = -EIO; 8398c2ecf20Sopenharmony_ci goto out; 8408c2ecf20Sopenharmony_ci } 8418c2ecf20Sopenharmony_ci tunnel_bar = be64_to_cpu(val); 8428c2ecf20Sopenharmony_ci if (enable) { 8438c2ecf20Sopenharmony_ci /* 8448c2ecf20Sopenharmony_ci * Only one device per PHB can use atomics. 8458c2ecf20Sopenharmony_ci * Our policy is first-come, first-served. 8468c2ecf20Sopenharmony_ci */ 8478c2ecf20Sopenharmony_ci if (tunnel_bar) { 8488c2ecf20Sopenharmony_ci if (tunnel_bar != addr) 8498c2ecf20Sopenharmony_ci rc = -EBUSY; 8508c2ecf20Sopenharmony_ci else 8518c2ecf20Sopenharmony_ci rc = 0; /* Setting same address twice is ok */ 8528c2ecf20Sopenharmony_ci goto out; 8538c2ecf20Sopenharmony_ci } 8548c2ecf20Sopenharmony_ci } else { 8558c2ecf20Sopenharmony_ci /* 8568c2ecf20Sopenharmony_ci * The device that owns atomics and wants to release 8578c2ecf20Sopenharmony_ci * them must pass the same address with enable == 0. 8588c2ecf20Sopenharmony_ci */ 8598c2ecf20Sopenharmony_ci if (tunnel_bar != addr) { 8608c2ecf20Sopenharmony_ci rc = -EPERM; 8618c2ecf20Sopenharmony_ci goto out; 8628c2ecf20Sopenharmony_ci } 8638c2ecf20Sopenharmony_ci addr = 0x0ULL; 8648c2ecf20Sopenharmony_ci } 8658c2ecf20Sopenharmony_ci rc = opal_pci_set_pbcq_tunnel_bar(phb->opal_id, addr); 8668c2ecf20Sopenharmony_ci rc = opal_error_code(rc); 8678c2ecf20Sopenharmony_ciout: 8688c2ecf20Sopenharmony_ci mutex_unlock(&tunnel_mutex); 8698c2ecf20Sopenharmony_ci return rc; 8708c2ecf20Sopenharmony_ci} 8718c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(pnv_pci_set_tunnel_bar); 8728c2ecf20Sopenharmony_ci 8738c2ecf20Sopenharmony_civoid pnv_pci_shutdown(void) 8748c2ecf20Sopenharmony_ci{ 8758c2ecf20Sopenharmony_ci struct pci_controller *hose; 8768c2ecf20Sopenharmony_ci 8778c2ecf20Sopenharmony_ci list_for_each_entry(hose, &hose_list, list_node) 8788c2ecf20Sopenharmony_ci if (hose->controller_ops.shutdown) 8798c2ecf20Sopenharmony_ci hose->controller_ops.shutdown(hose); 8808c2ecf20Sopenharmony_ci} 8818c2ecf20Sopenharmony_ci 8828c2ecf20Sopenharmony_ci/* Fixup wrong class code in p7ioc and p8 root complex */ 8838c2ecf20Sopenharmony_cistatic void pnv_p7ioc_rc_quirk(struct pci_dev *dev) 8848c2ecf20Sopenharmony_ci{ 8858c2ecf20Sopenharmony_ci dev->class = PCI_CLASS_BRIDGE_PCI << 8; 8868c2ecf20Sopenharmony_ci} 8878c2ecf20Sopenharmony_ciDECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_IBM, 0x3b9, pnv_p7ioc_rc_quirk); 8888c2ecf20Sopenharmony_ci 8898c2ecf20Sopenharmony_civoid __init pnv_pci_init(void) 8908c2ecf20Sopenharmony_ci{ 8918c2ecf20Sopenharmony_ci struct device_node *np; 8928c2ecf20Sopenharmony_ci 8938c2ecf20Sopenharmony_ci pci_add_flags(PCI_CAN_SKIP_ISA_ALIGN); 8948c2ecf20Sopenharmony_ci 8958c2ecf20Sopenharmony_ci /* If we don't have OPAL, eg. in sim, just skip PCI probe */ 8968c2ecf20Sopenharmony_ci if (!firmware_has_feature(FW_FEATURE_OPAL)) 8978c2ecf20Sopenharmony_ci return; 8988c2ecf20Sopenharmony_ci 8998c2ecf20Sopenharmony_ci#ifdef CONFIG_PCIEPORTBUS 9008c2ecf20Sopenharmony_ci /* 9018c2ecf20Sopenharmony_ci * On PowerNV PCIe devices are (currently) managed in cooperation 9028c2ecf20Sopenharmony_ci * with firmware. This isn't *strictly* required, but there's enough 9038c2ecf20Sopenharmony_ci * assumptions baked into both firmware and the platform code that 9048c2ecf20Sopenharmony_ci * it's unwise to allow the portbus services to be used. 9058c2ecf20Sopenharmony_ci * 9068c2ecf20Sopenharmony_ci * We need to fix this eventually, but for now set this flag to disable 9078c2ecf20Sopenharmony_ci * the portbus driver. The AER service isn't required since that AER 9088c2ecf20Sopenharmony_ci * events are handled via EEH. The pciehp hotplug driver can't work 9098c2ecf20Sopenharmony_ci * without kernel changes (and portbus binding breaks pnv_php). The 9108c2ecf20Sopenharmony_ci * other services also require some thinking about how we're going 9118c2ecf20Sopenharmony_ci * to integrate them. 9128c2ecf20Sopenharmony_ci */ 9138c2ecf20Sopenharmony_ci pcie_ports_disabled = true; 9148c2ecf20Sopenharmony_ci#endif 9158c2ecf20Sopenharmony_ci 9168c2ecf20Sopenharmony_ci /* Look for IODA IO-Hubs. */ 9178c2ecf20Sopenharmony_ci for_each_compatible_node(np, NULL, "ibm,ioda-hub") { 9188c2ecf20Sopenharmony_ci pnv_pci_init_ioda_hub(np); 9198c2ecf20Sopenharmony_ci } 9208c2ecf20Sopenharmony_ci 9218c2ecf20Sopenharmony_ci /* Look for ioda2 built-in PHB3's */ 9228c2ecf20Sopenharmony_ci for_each_compatible_node(np, NULL, "ibm,ioda2-phb") 9238c2ecf20Sopenharmony_ci pnv_pci_init_ioda2_phb(np); 9248c2ecf20Sopenharmony_ci 9258c2ecf20Sopenharmony_ci /* Look for ioda3 built-in PHB4's, we treat them as IODA2 */ 9268c2ecf20Sopenharmony_ci for_each_compatible_node(np, NULL, "ibm,ioda3-phb") 9278c2ecf20Sopenharmony_ci pnv_pci_init_ioda2_phb(np); 9288c2ecf20Sopenharmony_ci 9298c2ecf20Sopenharmony_ci /* Look for NPU PHBs */ 9308c2ecf20Sopenharmony_ci for_each_compatible_node(np, NULL, "ibm,ioda2-npu-phb") 9318c2ecf20Sopenharmony_ci pnv_pci_init_npu_phb(np); 9328c2ecf20Sopenharmony_ci 9338c2ecf20Sopenharmony_ci /* 9348c2ecf20Sopenharmony_ci * Look for NPU2 PHBs which we treat mostly as NPU PHBs with 9358c2ecf20Sopenharmony_ci * the exception of TCE kill which requires an OPAL call. 9368c2ecf20Sopenharmony_ci */ 9378c2ecf20Sopenharmony_ci for_each_compatible_node(np, NULL, "ibm,ioda2-npu2-phb") 9388c2ecf20Sopenharmony_ci pnv_pci_init_npu_phb(np); 9398c2ecf20Sopenharmony_ci 9408c2ecf20Sopenharmony_ci /* Look for NPU2 OpenCAPI PHBs */ 9418c2ecf20Sopenharmony_ci for_each_compatible_node(np, NULL, "ibm,ioda2-npu2-opencapi-phb") 9428c2ecf20Sopenharmony_ci pnv_pci_init_npu2_opencapi_phb(np); 9438c2ecf20Sopenharmony_ci 9448c2ecf20Sopenharmony_ci /* Configure IOMMU DMA hooks */ 9458c2ecf20Sopenharmony_ci set_pci_dma_ops(&dma_iommu_ops); 9468c2ecf20Sopenharmony_ci} 9478c2ecf20Sopenharmony_ci 9488c2ecf20Sopenharmony_cistatic int pnv_tce_iommu_bus_notifier(struct notifier_block *nb, 9498c2ecf20Sopenharmony_ci unsigned long action, void *data) 9508c2ecf20Sopenharmony_ci{ 9518c2ecf20Sopenharmony_ci struct device *dev = data; 9528c2ecf20Sopenharmony_ci 9538c2ecf20Sopenharmony_ci switch (action) { 9548c2ecf20Sopenharmony_ci case BUS_NOTIFY_DEL_DEVICE: 9558c2ecf20Sopenharmony_ci iommu_del_device(dev); 9568c2ecf20Sopenharmony_ci return 0; 9578c2ecf20Sopenharmony_ci default: 9588c2ecf20Sopenharmony_ci return 0; 9598c2ecf20Sopenharmony_ci } 9608c2ecf20Sopenharmony_ci} 9618c2ecf20Sopenharmony_ci 9628c2ecf20Sopenharmony_cistatic struct notifier_block pnv_tce_iommu_bus_nb = { 9638c2ecf20Sopenharmony_ci .notifier_call = pnv_tce_iommu_bus_notifier, 9648c2ecf20Sopenharmony_ci}; 9658c2ecf20Sopenharmony_ci 9668c2ecf20Sopenharmony_cistatic int __init pnv_tce_iommu_bus_notifier_init(void) 9678c2ecf20Sopenharmony_ci{ 9688c2ecf20Sopenharmony_ci bus_register_notifier(&pci_bus_type, &pnv_tce_iommu_bus_nb); 9698c2ecf20Sopenharmony_ci return 0; 9708c2ecf20Sopenharmony_ci} 9718c2ecf20Sopenharmony_cimachine_subsys_initcall_sync(powernv, pnv_tce_iommu_bus_notifier_init); 972