Path: blob/master/arch/powerpc/platforms/powernv/pci-ioda.c
29274 views
// SPDX-License-Identifier: GPL-2.0-or-later1/*2* Support PCI/PCIe on PowerNV platforms3*4* Copyright 2011 Benjamin Herrenschmidt, IBM Corp.5*/67#undef DEBUG89#include <linux/kernel.h>10#include <linux/pci.h>11#include <linux/crash_dump.h>12#include <linux/delay.h>13#include <linux/string.h>14#include <linux/init.h>15#include <linux/memblock.h>16#include <linux/irq.h>17#include <linux/irqchip/irq-msi-lib.h>18#include <linux/io.h>19#include <linux/msi.h>20#include <linux/iommu.h>21#include <linux/rculist.h>22#include <linux/sizes.h>23#include <linux/debugfs.h>24#include <linux/of_address.h>25#include <linux/of_irq.h>2627#include <asm/sections.h>28#include <asm/io.h>29#include <asm/pci-bridge.h>30#include <asm/machdep.h>31#include <asm/msi_bitmap.h>32#include <asm/ppc-pci.h>33#include <asm/opal.h>34#include <asm/iommu.h>35#include <asm/tce.h>36#include <asm/xics.h>37#include <asm/firmware.h>38#include <asm/pnv-pci.h>39#include <asm/mmzone.h>4041#include "powernv.h"42#include "pci.h"43#include "../../../../drivers/pci/pci.h"4445/* This array is indexed with enum pnv_phb_type */46static const char * const pnv_phb_names[] = { "IODA2", "NPU_OCAPI" };4748static void pnv_pci_ioda2_set_bypass(struct pnv_ioda_pe *pe, bool enable);49static void pnv_pci_configure_bus(struct pci_bus *bus);5051void pe_level_printk(const struct pnv_ioda_pe *pe, const char *level,52const char *fmt, ...)53{54struct va_format vaf;55va_list args;56char pfix[32];5758va_start(args, fmt);5960vaf.fmt = fmt;61vaf.va = &args;6263if (pe->flags & PNV_IODA_PE_DEV)64strscpy(pfix, dev_name(&pe->pdev->dev), sizeof(pfix));65else if (pe->flags & (PNV_IODA_PE_BUS | PNV_IODA_PE_BUS_ALL))66sprintf(pfix, "%04x:%02x ",67pci_domain_nr(pe->pbus), pe->pbus->number);68#ifdef CONFIG_PCI_IOV69else if (pe->flags & PNV_IODA_PE_VF)70sprintf(pfix, "%04x:%02x:%2x.%d",71pci_domain_nr(pe->parent_dev->bus),72(pe->rid & 0xff00) >> 8,73PCI_SLOT(pe->rid), PCI_FUNC(pe->rid));74#endif /* CONFIG_PCI_IOV*/7576printk("%spci %s: [PE# %.2x] %pV",77level, pfix, pe->pe_number, &vaf);7879va_end(args);80}8182static bool pnv_iommu_bypass_disabled __read_mostly;83static bool pci_reset_phbs __read_mostly;8485static int __init iommu_setup(char *str)86{87if (!str)88return -EINVAL;8990while (*str) {91if (!strncmp(str, "nobypass", 8)) {92pnv_iommu_bypass_disabled = true;93pr_info("PowerNV: IOMMU bypass window disabled.\n");94break;95}96str += strcspn(str, ",");97if (*str == ',')98str++;99}100101return 0;102}103early_param("iommu", iommu_setup);104105static int __init pci_reset_phbs_setup(char *str)106{107pci_reset_phbs = true;108return 0;109}110111early_param("ppc_pci_reset_phbs", pci_reset_phbs_setup);112113static struct pnv_ioda_pe *pnv_ioda_init_pe(struct pnv_phb *phb, int pe_no)114{115s64 rc;116117phb->ioda.pe_array[pe_no].phb = phb;118phb->ioda.pe_array[pe_no].pe_number = pe_no;119phb->ioda.pe_array[pe_no].dma_setup_done = false;120121/*122* Clear the PE frozen state as it might be put into frozen state123* in the last PCI remove path. It's not harmful to do so when the124* PE is already in unfrozen state.125*/126rc = opal_pci_eeh_freeze_clear(phb->opal_id, pe_no,127OPAL_EEH_ACTION_CLEAR_FREEZE_ALL);128if (rc != OPAL_SUCCESS && rc != OPAL_UNSUPPORTED)129pr_warn("%s: Error %lld unfreezing PHB#%x-PE#%x\n",130__func__, rc, phb->hose->global_number, pe_no);131132return &phb->ioda.pe_array[pe_no];133}134135static void pnv_ioda_reserve_pe(struct pnv_phb *phb, int pe_no)136{137if (!(pe_no >= 0 && pe_no < phb->ioda.total_pe_num)) {138pr_warn("%s: Invalid PE %x on PHB#%x\n",139__func__, pe_no, phb->hose->global_number);140return;141}142143mutex_lock(&phb->ioda.pe_alloc_mutex);144if (test_and_set_bit(pe_no, phb->ioda.pe_alloc))145pr_debug("%s: PE %x was reserved on PHB#%x\n",146__func__, pe_no, phb->hose->global_number);147mutex_unlock(&phb->ioda.pe_alloc_mutex);148149pnv_ioda_init_pe(phb, pe_no);150}151152struct pnv_ioda_pe *pnv_ioda_alloc_pe(struct pnv_phb *phb, int count)153{154struct pnv_ioda_pe *ret = NULL;155int run = 0, pe, i;156157mutex_lock(&phb->ioda.pe_alloc_mutex);158159/* scan backwards for a run of @count cleared bits */160for (pe = phb->ioda.total_pe_num - 1; pe >= 0; pe--) {161if (test_bit(pe, phb->ioda.pe_alloc)) {162run = 0;163continue;164}165166run++;167if (run == count)168break;169}170if (run != count)171goto out;172173for (i = pe; i < pe + count; i++) {174set_bit(i, phb->ioda.pe_alloc);175pnv_ioda_init_pe(phb, i);176}177ret = &phb->ioda.pe_array[pe];178179out:180mutex_unlock(&phb->ioda.pe_alloc_mutex);181return ret;182}183184void pnv_ioda_free_pe(struct pnv_ioda_pe *pe)185{186struct pnv_phb *phb = pe->phb;187unsigned int pe_num = pe->pe_number;188189WARN_ON(pe->pdev);190memset(pe, 0, sizeof(struct pnv_ioda_pe));191192mutex_lock(&phb->ioda.pe_alloc_mutex);193clear_bit(pe_num, phb->ioda.pe_alloc);194mutex_unlock(&phb->ioda.pe_alloc_mutex);195}196197/* The default M64 BAR is shared by all PEs */198static int pnv_ioda2_init_m64(struct pnv_phb *phb)199{200const char *desc;201struct resource *r;202s64 rc;203204/* Configure the default M64 BAR */205rc = opal_pci_set_phb_mem_window(phb->opal_id,206OPAL_M64_WINDOW_TYPE,207phb->ioda.m64_bar_idx,208phb->ioda.m64_base,2090, /* unused */210phb->ioda.m64_size);211if (rc != OPAL_SUCCESS) {212desc = "configuring";213goto fail;214}215216/* Enable the default M64 BAR */217rc = opal_pci_phb_mmio_enable(phb->opal_id,218OPAL_M64_WINDOW_TYPE,219phb->ioda.m64_bar_idx,220OPAL_ENABLE_M64_SPLIT);221if (rc != OPAL_SUCCESS) {222desc = "enabling";223goto fail;224}225226/*227* Exclude the segments for reserved and root bus PE, which228* are first or last two PEs.229*/230r = &phb->hose->mem_resources[1];231if (phb->ioda.reserved_pe_idx == 0)232r->start += (2 * phb->ioda.m64_segsize);233else if (phb->ioda.reserved_pe_idx == (phb->ioda.total_pe_num - 1))234r->end -= (2 * phb->ioda.m64_segsize);235else236pr_warn(" Cannot strip M64 segment for reserved PE#%x\n",237phb->ioda.reserved_pe_idx);238239return 0;240241fail:242pr_warn(" Failure %lld %s M64 BAR#%d\n",243rc, desc, phb->ioda.m64_bar_idx);244opal_pci_phb_mmio_enable(phb->opal_id,245OPAL_M64_WINDOW_TYPE,246phb->ioda.m64_bar_idx,247OPAL_DISABLE_M64);248return -EIO;249}250251static void pnv_ioda_reserve_dev_m64_pe(struct pci_dev *pdev,252unsigned long *pe_bitmap)253{254struct pnv_phb *phb = pci_bus_to_pnvhb(pdev->bus);255struct resource *r;256resource_size_t base, sgsz, start, end;257int segno, i;258259base = phb->ioda.m64_base;260sgsz = phb->ioda.m64_segsize;261for (i = 0; i <= PCI_ROM_RESOURCE; i++) {262r = &pdev->resource[i];263if (!r->parent || !pnv_pci_is_m64(phb, r))264continue;265266start = ALIGN_DOWN(r->start - base, sgsz);267end = ALIGN(r->end - base, sgsz);268for (segno = start / sgsz; segno < end / sgsz; segno++) {269if (pe_bitmap)270set_bit(segno, pe_bitmap);271else272pnv_ioda_reserve_pe(phb, segno);273}274}275}276277static void pnv_ioda_reserve_m64_pe(struct pci_bus *bus,278unsigned long *pe_bitmap,279bool all)280{281struct pci_dev *pdev;282283list_for_each_entry(pdev, &bus->devices, bus_list) {284pnv_ioda_reserve_dev_m64_pe(pdev, pe_bitmap);285286if (all && pdev->subordinate)287pnv_ioda_reserve_m64_pe(pdev->subordinate,288pe_bitmap, all);289}290}291292static struct pnv_ioda_pe *pnv_ioda_pick_m64_pe(struct pci_bus *bus, bool all)293{294struct pnv_phb *phb = pci_bus_to_pnvhb(bus);295struct pnv_ioda_pe *master_pe, *pe;296unsigned long size, *pe_alloc;297int i;298299/* Root bus shouldn't use M64 */300if (pci_is_root_bus(bus))301return NULL;302303/* Allocate bitmap */304size = ALIGN(phb->ioda.total_pe_num / 8, sizeof(unsigned long));305pe_alloc = kzalloc(size, GFP_KERNEL);306if (!pe_alloc) {307pr_warn("%s: Out of memory !\n",308__func__);309return NULL;310}311312/* Figure out reserved PE numbers by the PE */313pnv_ioda_reserve_m64_pe(bus, pe_alloc, all);314315/*316* the current bus might not own M64 window and that's all317* contributed by its child buses. For the case, we needn't318* pick M64 dependent PE#.319*/320if (bitmap_empty(pe_alloc, phb->ioda.total_pe_num)) {321kfree(pe_alloc);322return NULL;323}324325/*326* Figure out the master PE and put all slave PEs to master327* PE's list to form compound PE.328*/329master_pe = NULL;330i = -1;331while ((i = find_next_bit(pe_alloc, phb->ioda.total_pe_num, i + 1)) <332phb->ioda.total_pe_num) {333pe = &phb->ioda.pe_array[i];334335phb->ioda.m64_segmap[pe->pe_number] = pe->pe_number;336if (!master_pe) {337pe->flags |= PNV_IODA_PE_MASTER;338INIT_LIST_HEAD(&pe->slaves);339master_pe = pe;340} else {341pe->flags |= PNV_IODA_PE_SLAVE;342pe->master = master_pe;343list_add_tail(&pe->list, &master_pe->slaves);344}345}346347kfree(pe_alloc);348return master_pe;349}350351static void __init pnv_ioda_parse_m64_window(struct pnv_phb *phb)352{353struct pci_controller *hose = phb->hose;354struct device_node *dn = hose->dn;355struct resource *res;356u32 m64_range[2], i;357const __be32 *r;358u64 pci_addr;359360if (phb->type != PNV_PHB_IODA2) {361pr_info(" Not support M64 window\n");362return;363}364365if (!firmware_has_feature(FW_FEATURE_OPAL)) {366pr_info(" Firmware too old to support M64 window\n");367return;368}369370r = of_get_property(dn, "ibm,opal-m64-window", NULL);371if (!r) {372pr_info(" No <ibm,opal-m64-window> on %pOF\n",373dn);374return;375}376377/*378* Find the available M64 BAR range and pickup the last one for379* covering the whole 64-bits space. We support only one range.380*/381if (of_property_read_u32_array(dn, "ibm,opal-available-m64-ranges",382m64_range, 2)) {383/* In absence of the property, assume 0..15 */384m64_range[0] = 0;385m64_range[1] = 16;386}387/* We only support 64 bits in our allocator */388if (m64_range[1] > 63) {389pr_warn("%s: Limiting M64 range to 63 (from %d) on PHB#%x\n",390__func__, m64_range[1], phb->hose->global_number);391m64_range[1] = 63;392}393/* Empty range, no m64 */394if (m64_range[1] <= m64_range[0]) {395pr_warn("%s: M64 empty, disabling M64 usage on PHB#%x\n",396__func__, phb->hose->global_number);397return;398}399400/* Configure M64 informations */401res = &hose->mem_resources[1];402res->name = dn->full_name;403res->start = of_translate_address(dn, r + 2);404res->end = res->start + of_read_number(r + 4, 2) - 1;405res->flags = (IORESOURCE_MEM | IORESOURCE_MEM_64 | IORESOURCE_PREFETCH);406pci_addr = of_read_number(r, 2);407hose->mem_offset[1] = res->start - pci_addr;408409phb->ioda.m64_size = resource_size(res);410phb->ioda.m64_segsize = phb->ioda.m64_size / phb->ioda.total_pe_num;411phb->ioda.m64_base = pci_addr;412413/* This lines up nicely with the display from processing OF ranges */414pr_info(" MEM 0x%016llx..0x%016llx -> 0x%016llx (M64 #%d..%d)\n",415res->start, res->end, pci_addr, m64_range[0],416m64_range[0] + m64_range[1] - 1);417418/* Mark all M64 used up by default */419phb->ioda.m64_bar_alloc = (unsigned long)-1;420421/* Use last M64 BAR to cover M64 window */422m64_range[1]--;423phb->ioda.m64_bar_idx = m64_range[0] + m64_range[1];424425pr_info(" Using M64 #%d as default window\n", phb->ioda.m64_bar_idx);426427/* Mark remaining ones free */428for (i = m64_range[0]; i < m64_range[1]; i++)429clear_bit(i, &phb->ioda.m64_bar_alloc);430431/*432* Setup init functions for M64 based on IODA version, IODA3 uses433* the IODA2 code.434*/435phb->init_m64 = pnv_ioda2_init_m64;436}437438static void pnv_ioda_freeze_pe(struct pnv_phb *phb, int pe_no)439{440struct pnv_ioda_pe *pe = &phb->ioda.pe_array[pe_no];441struct pnv_ioda_pe *slave;442s64 rc;443444/* Fetch master PE */445if (pe->flags & PNV_IODA_PE_SLAVE) {446pe = pe->master;447if (WARN_ON(!pe || !(pe->flags & PNV_IODA_PE_MASTER)))448return;449450pe_no = pe->pe_number;451}452453/* Freeze master PE */454rc = opal_pci_eeh_freeze_set(phb->opal_id,455pe_no,456OPAL_EEH_ACTION_SET_FREEZE_ALL);457if (rc != OPAL_SUCCESS) {458pr_warn("%s: Failure %lld freezing PHB#%x-PE#%x\n",459__func__, rc, phb->hose->global_number, pe_no);460return;461}462463/* Freeze slave PEs */464if (!(pe->flags & PNV_IODA_PE_MASTER))465return;466467list_for_each_entry(slave, &pe->slaves, list) {468rc = opal_pci_eeh_freeze_set(phb->opal_id,469slave->pe_number,470OPAL_EEH_ACTION_SET_FREEZE_ALL);471if (rc != OPAL_SUCCESS)472pr_warn("%s: Failure %lld freezing PHB#%x-PE#%x\n",473__func__, rc, phb->hose->global_number,474slave->pe_number);475}476}477478static int pnv_ioda_unfreeze_pe(struct pnv_phb *phb, int pe_no, int opt)479{480struct pnv_ioda_pe *pe, *slave;481s64 rc;482483/* Find master PE */484pe = &phb->ioda.pe_array[pe_no];485if (pe->flags & PNV_IODA_PE_SLAVE) {486pe = pe->master;487WARN_ON(!pe || !(pe->flags & PNV_IODA_PE_MASTER));488pe_no = pe->pe_number;489}490491/* Clear frozen state for master PE */492rc = opal_pci_eeh_freeze_clear(phb->opal_id, pe_no, opt);493if (rc != OPAL_SUCCESS) {494pr_warn("%s: Failure %lld clear %d on PHB#%x-PE#%x\n",495__func__, rc, opt, phb->hose->global_number, pe_no);496return -EIO;497}498499if (!(pe->flags & PNV_IODA_PE_MASTER))500return 0;501502/* Clear frozen state for slave PEs */503list_for_each_entry(slave, &pe->slaves, list) {504rc = opal_pci_eeh_freeze_clear(phb->opal_id,505slave->pe_number,506opt);507if (rc != OPAL_SUCCESS) {508pr_warn("%s: Failure %lld clear %d on PHB#%x-PE#%x\n",509__func__, rc, opt, phb->hose->global_number,510slave->pe_number);511return -EIO;512}513}514515return 0;516}517518static int pnv_ioda_get_pe_state(struct pnv_phb *phb, int pe_no)519{520struct pnv_ioda_pe *slave, *pe;521u8 fstate = 0, state;522__be16 pcierr = 0;523s64 rc;524525/* Sanity check on PE number */526if (pe_no < 0 || pe_no >= phb->ioda.total_pe_num)527return OPAL_EEH_STOPPED_PERM_UNAVAIL;528529/*530* Fetch the master PE and the PE instance might be531* not initialized yet.532*/533pe = &phb->ioda.pe_array[pe_no];534if (pe->flags & PNV_IODA_PE_SLAVE) {535pe = pe->master;536WARN_ON(!pe || !(pe->flags & PNV_IODA_PE_MASTER));537pe_no = pe->pe_number;538}539540/* Check the master PE */541rc = opal_pci_eeh_freeze_status(phb->opal_id, pe_no,542&state, &pcierr, NULL);543if (rc != OPAL_SUCCESS) {544pr_warn("%s: Failure %lld getting "545"PHB#%x-PE#%x state\n",546__func__, rc,547phb->hose->global_number, pe_no);548return OPAL_EEH_STOPPED_TEMP_UNAVAIL;549}550551/* Check the slave PE */552if (!(pe->flags & PNV_IODA_PE_MASTER))553return state;554555list_for_each_entry(slave, &pe->slaves, list) {556rc = opal_pci_eeh_freeze_status(phb->opal_id,557slave->pe_number,558&fstate,559&pcierr,560NULL);561if (rc != OPAL_SUCCESS) {562pr_warn("%s: Failure %lld getting "563"PHB#%x-PE#%x state\n",564__func__, rc,565phb->hose->global_number, slave->pe_number);566return OPAL_EEH_STOPPED_TEMP_UNAVAIL;567}568569/*570* Override the result based on the ascending571* priority.572*/573if (fstate > state)574state = fstate;575}576577return state;578}579580struct pnv_ioda_pe *pnv_pci_bdfn_to_pe(struct pnv_phb *phb, u16 bdfn)581{582int pe_number = phb->ioda.pe_rmap[bdfn];583584if (pe_number == IODA_INVALID_PE)585return NULL;586587return &phb->ioda.pe_array[pe_number];588}589590struct pnv_ioda_pe *pnv_ioda_get_pe(struct pci_dev *dev)591{592struct pnv_phb *phb = pci_bus_to_pnvhb(dev->bus);593struct pci_dn *pdn = pci_get_pdn(dev);594595if (!pdn)596return NULL;597if (pdn->pe_number == IODA_INVALID_PE)598return NULL;599return &phb->ioda.pe_array[pdn->pe_number];600}601602static int pnv_ioda_set_one_peltv(struct pnv_phb *phb,603struct pnv_ioda_pe *parent,604struct pnv_ioda_pe *child,605bool is_add)606{607const char *desc = is_add ? "adding" : "removing";608uint8_t op = is_add ? OPAL_ADD_PE_TO_DOMAIN :609OPAL_REMOVE_PE_FROM_DOMAIN;610struct pnv_ioda_pe *slave;611long rc;612613/* Parent PE affects child PE */614rc = opal_pci_set_peltv(phb->opal_id, parent->pe_number,615child->pe_number, op);616if (rc != OPAL_SUCCESS) {617pe_warn(child, "OPAL error %ld %s to parent PELTV\n",618rc, desc);619return -ENXIO;620}621622if (!(child->flags & PNV_IODA_PE_MASTER))623return 0;624625/* Compound case: parent PE affects slave PEs */626list_for_each_entry(slave, &child->slaves, list) {627rc = opal_pci_set_peltv(phb->opal_id, parent->pe_number,628slave->pe_number, op);629if (rc != OPAL_SUCCESS) {630pe_warn(slave, "OPAL error %ld %s to parent PELTV\n",631rc, desc);632return -ENXIO;633}634}635636return 0;637}638639static int pnv_ioda_set_peltv(struct pnv_phb *phb,640struct pnv_ioda_pe *pe,641bool is_add)642{643struct pnv_ioda_pe *slave;644struct pci_dev *pdev = NULL;645int ret;646647/*648* Clear PE frozen state. If it's master PE, we need649* clear slave PE frozen state as well.650*/651if (is_add) {652opal_pci_eeh_freeze_clear(phb->opal_id, pe->pe_number,653OPAL_EEH_ACTION_CLEAR_FREEZE_ALL);654if (pe->flags & PNV_IODA_PE_MASTER) {655list_for_each_entry(slave, &pe->slaves, list)656opal_pci_eeh_freeze_clear(phb->opal_id,657slave->pe_number,658OPAL_EEH_ACTION_CLEAR_FREEZE_ALL);659}660}661662/*663* Associate PE in PELT. We need add the PE into the664* corresponding PELT-V as well. Otherwise, the error665* originated from the PE might contribute to other666* PEs.667*/668ret = pnv_ioda_set_one_peltv(phb, pe, pe, is_add);669if (ret)670return ret;671672/* For compound PEs, any one affects all of them */673if (pe->flags & PNV_IODA_PE_MASTER) {674list_for_each_entry(slave, &pe->slaves, list) {675ret = pnv_ioda_set_one_peltv(phb, slave, pe, is_add);676if (ret)677return ret;678}679}680681if (pe->flags & (PNV_IODA_PE_BUS_ALL | PNV_IODA_PE_BUS))682pdev = pe->pbus->self;683else if (pe->flags & PNV_IODA_PE_DEV)684pdev = pe->pdev->bus->self;685#ifdef CONFIG_PCI_IOV686else if (pe->flags & PNV_IODA_PE_VF)687pdev = pe->parent_dev;688#endif /* CONFIG_PCI_IOV */689while (pdev) {690struct pci_dn *pdn = pci_get_pdn(pdev);691struct pnv_ioda_pe *parent;692693if (pdn && pdn->pe_number != IODA_INVALID_PE) {694parent = &phb->ioda.pe_array[pdn->pe_number];695ret = pnv_ioda_set_one_peltv(phb, parent, pe, is_add);696if (ret)697return ret;698}699700pdev = pdev->bus->self;701}702703return 0;704}705706static void pnv_ioda_unset_peltv(struct pnv_phb *phb,707struct pnv_ioda_pe *pe,708struct pci_dev *parent)709{710int64_t rc;711712while (parent) {713struct pci_dn *pdn = pci_get_pdn(parent);714715if (pdn && pdn->pe_number != IODA_INVALID_PE) {716rc = opal_pci_set_peltv(phb->opal_id, pdn->pe_number,717pe->pe_number,718OPAL_REMOVE_PE_FROM_DOMAIN);719/* XXX What to do in case of error ? */720}721parent = parent->bus->self;722}723724opal_pci_eeh_freeze_clear(phb->opal_id, pe->pe_number,725OPAL_EEH_ACTION_CLEAR_FREEZE_ALL);726727/* Disassociate PE in PELT */728rc = opal_pci_set_peltv(phb->opal_id, pe->pe_number,729pe->pe_number, OPAL_REMOVE_PE_FROM_DOMAIN);730if (rc)731pe_warn(pe, "OPAL error %lld remove self from PELTV\n", rc);732}733734int pnv_ioda_deconfigure_pe(struct pnv_phb *phb, struct pnv_ioda_pe *pe)735{736struct pci_dev *parent;737uint8_t bcomp, dcomp, fcomp;738int64_t rc;739long rid_end, rid;740741/* Currently, we just deconfigure VF PE. Bus PE will always there.*/742if (pe->pbus) {743int count;744745dcomp = OPAL_IGNORE_RID_DEVICE_NUMBER;746fcomp = OPAL_IGNORE_RID_FUNCTION_NUMBER;747parent = pe->pbus->self;748if (pe->flags & PNV_IODA_PE_BUS_ALL)749count = resource_size(&pe->pbus->busn_res);750else751count = 1;752753switch(count) {754case 1: bcomp = OpalPciBusAll; break;755case 2: bcomp = OpalPciBus7Bits; break;756case 4: bcomp = OpalPciBus6Bits; break;757case 8: bcomp = OpalPciBus5Bits; break;758case 16: bcomp = OpalPciBus4Bits; break;759case 32: bcomp = OpalPciBus3Bits; break;760default:761dev_err(&pe->pbus->dev, "Number of subordinate buses %d unsupported\n",762count);763/* Do an exact match only */764bcomp = OpalPciBusAll;765}766rid_end = pe->rid + (count << 8);767} else {768#ifdef CONFIG_PCI_IOV769if (pe->flags & PNV_IODA_PE_VF)770parent = pe->parent_dev;771else772#endif773parent = pe->pdev->bus->self;774bcomp = OpalPciBusAll;775dcomp = OPAL_COMPARE_RID_DEVICE_NUMBER;776fcomp = OPAL_COMPARE_RID_FUNCTION_NUMBER;777rid_end = pe->rid + 1;778}779780/* Clear the reverse map */781for (rid = pe->rid; rid < rid_end; rid++)782phb->ioda.pe_rmap[rid] = IODA_INVALID_PE;783784/*785* Release from all parents PELT-V. NPUs don't have a PELTV786* table787*/788if (phb->type != PNV_PHB_NPU_OCAPI)789pnv_ioda_unset_peltv(phb, pe, parent);790791rc = opal_pci_set_pe(phb->opal_id, pe->pe_number, pe->rid,792bcomp, dcomp, fcomp, OPAL_UNMAP_PE);793if (rc)794pe_err(pe, "OPAL error %lld trying to setup PELT table\n", rc);795796pe->pbus = NULL;797pe->pdev = NULL;798#ifdef CONFIG_PCI_IOV799pe->parent_dev = NULL;800#endif801802return 0;803}804805int pnv_ioda_configure_pe(struct pnv_phb *phb, struct pnv_ioda_pe *pe)806{807uint8_t bcomp, dcomp, fcomp;808long rc, rid_end, rid;809810/* Bus validation ? */811if (pe->pbus) {812int count;813814dcomp = OPAL_IGNORE_RID_DEVICE_NUMBER;815fcomp = OPAL_IGNORE_RID_FUNCTION_NUMBER;816if (pe->flags & PNV_IODA_PE_BUS_ALL)817count = resource_size(&pe->pbus->busn_res);818else819count = 1;820821switch(count) {822case 1: bcomp = OpalPciBusAll; break;823case 2: bcomp = OpalPciBus7Bits; break;824case 4: bcomp = OpalPciBus6Bits; break;825case 8: bcomp = OpalPciBus5Bits; break;826case 16: bcomp = OpalPciBus4Bits; break;827case 32: bcomp = OpalPciBus3Bits; break;828default:829dev_err(&pe->pbus->dev, "Number of subordinate buses %d unsupported\n",830count);831/* Do an exact match only */832bcomp = OpalPciBusAll;833}834rid_end = pe->rid + (count << 8);835} else {836bcomp = OpalPciBusAll;837dcomp = OPAL_COMPARE_RID_DEVICE_NUMBER;838fcomp = OPAL_COMPARE_RID_FUNCTION_NUMBER;839rid_end = pe->rid + 1;840}841842/*843* Associate PE in PELT. We need add the PE into the844* corresponding PELT-V as well. Otherwise, the error845* originated from the PE might contribute to other846* PEs.847*/848rc = opal_pci_set_pe(phb->opal_id, pe->pe_number, pe->rid,849bcomp, dcomp, fcomp, OPAL_MAP_PE);850if (rc) {851pe_err(pe, "OPAL error %ld trying to setup PELT table\n", rc);852return -ENXIO;853}854855/*856* Configure PELTV. NPUs don't have a PELTV table so skip857* configuration on them.858*/859if (phb->type != PNV_PHB_NPU_OCAPI)860pnv_ioda_set_peltv(phb, pe, true);861862/* Setup reverse map */863for (rid = pe->rid; rid < rid_end; rid++)864phb->ioda.pe_rmap[rid] = pe->pe_number;865866pe->mve_number = 0;867868return 0;869}870871static struct pnv_ioda_pe *pnv_ioda_setup_dev_PE(struct pci_dev *dev)872{873struct pnv_phb *phb = pci_bus_to_pnvhb(dev->bus);874struct pci_dn *pdn = pci_get_pdn(dev);875struct pnv_ioda_pe *pe;876877if (!pdn) {878pr_err("%s: Device tree node not associated properly\n",879pci_name(dev));880return NULL;881}882if (pdn->pe_number != IODA_INVALID_PE)883return NULL;884885pe = pnv_ioda_alloc_pe(phb, 1);886if (!pe) {887pr_warn("%s: Not enough PE# available, disabling device\n",888pci_name(dev));889return NULL;890}891892/* NOTE: We don't get a reference for the pointer in the PE893* data structure, both the device and PE structures should be894* destroyed at the same time.895*896* At some point we want to remove the PDN completely anyways897*/898pdn->pe_number = pe->pe_number;899pe->flags = PNV_IODA_PE_DEV;900pe->pdev = dev;901pe->pbus = NULL;902pe->mve_number = -1;903pe->rid = dev->bus->number << 8 | pdn->devfn;904pe->device_count++;905906pe_info(pe, "Associated device to PE\n");907908if (pnv_ioda_configure_pe(phb, pe)) {909/* XXX What do we do here ? */910pnv_ioda_free_pe(pe);911pdn->pe_number = IODA_INVALID_PE;912pe->pdev = NULL;913return NULL;914}915916/* Put PE to the list */917mutex_lock(&phb->ioda.pe_list_mutex);918list_add_tail(&pe->list, &phb->ioda.pe_list);919mutex_unlock(&phb->ioda.pe_list_mutex);920return pe;921}922923/*924* There're 2 types of PCI bus sensitive PEs: One that is compromised of925* single PCI bus. Another one that contains the primary PCI bus and its926* subordinate PCI devices and buses. The second type of PE is normally927* orgiriated by PCIe-to-PCI bridge or PLX switch downstream ports.928*/929static struct pnv_ioda_pe *pnv_ioda_setup_bus_PE(struct pci_bus *bus, bool all)930{931struct pnv_phb *phb = pci_bus_to_pnvhb(bus);932struct pnv_ioda_pe *pe = NULL;933unsigned int pe_num;934935/*936* In partial hotplug case, the PE instance might be still alive.937* We should reuse it instead of allocating a new one.938*/939pe_num = phb->ioda.pe_rmap[bus->number << 8];940if (WARN_ON(pe_num != IODA_INVALID_PE)) {941pe = &phb->ioda.pe_array[pe_num];942return NULL;943}944945/* PE number for root bus should have been reserved */946if (pci_is_root_bus(bus))947pe = &phb->ioda.pe_array[phb->ioda.root_pe_idx];948949/* Check if PE is determined by M64 */950if (!pe)951pe = pnv_ioda_pick_m64_pe(bus, all);952953/* The PE number isn't pinned by M64 */954if (!pe)955pe = pnv_ioda_alloc_pe(phb, 1);956957if (!pe) {958pr_warn("%s: Not enough PE# available for PCI bus %04x:%02x\n",959__func__, pci_domain_nr(bus), bus->number);960return NULL;961}962963pe->flags |= (all ? PNV_IODA_PE_BUS_ALL : PNV_IODA_PE_BUS);964pe->pbus = bus;965pe->pdev = NULL;966pe->mve_number = -1;967pe->rid = bus->busn_res.start << 8;968969if (all)970pe_info(pe, "Secondary bus %pad..%pad associated with PE#%x\n",971&bus->busn_res.start, &bus->busn_res.end,972pe->pe_number);973else974pe_info(pe, "Secondary bus %pad associated with PE#%x\n",975&bus->busn_res.start, pe->pe_number);976977if (pnv_ioda_configure_pe(phb, pe)) {978/* XXX What do we do here ? */979pnv_ioda_free_pe(pe);980pe->pbus = NULL;981return NULL;982}983984/* Put PE to the list */985list_add_tail(&pe->list, &phb->ioda.pe_list);986987return pe;988}989990static void pnv_pci_ioda_dma_dev_setup(struct pci_dev *pdev)991{992struct pnv_phb *phb = pci_bus_to_pnvhb(pdev->bus);993struct pci_dn *pdn = pci_get_pdn(pdev);994struct pnv_ioda_pe *pe;995996/* Check if the BDFN for this device is associated with a PE yet */997pe = pnv_pci_bdfn_to_pe(phb, pci_dev_id(pdev));998if (!pe) {999/* VF PEs should be pre-configured in pnv_pci_sriov_enable() */1000if (WARN_ON(pdev->is_virtfn))1001return;10021003pnv_pci_configure_bus(pdev->bus);1004pe = pnv_pci_bdfn_to_pe(phb, pci_dev_id(pdev));1005pci_info(pdev, "Configured PE#%x\n", pe ? pe->pe_number : 0xfffff);100610071008/*1009* If we can't setup the IODA PE something has gone horribly1010* wrong and we can't enable DMA for the device.1011*/1012if (WARN_ON(!pe))1013return;1014} else {1015pci_info(pdev, "Added to existing PE#%x\n", pe->pe_number);1016}10171018/*1019* We assume that bridges *probably* don't need to do any DMA so we can1020* skip allocating a TCE table, etc unless we get a non-bridge device.1021*/1022if (!pe->dma_setup_done && !pci_is_bridge(pdev)) {1023switch (phb->type) {1024case PNV_PHB_IODA2:1025pnv_pci_ioda2_setup_dma_pe(phb, pe);1026break;1027default:1028pr_warn("%s: No DMA for PHB#%x (type %d)\n",1029__func__, phb->hose->global_number, phb->type);1030}1031}10321033if (pdn)1034pdn->pe_number = pe->pe_number;1035pe->device_count++;10361037WARN_ON(get_dma_ops(&pdev->dev) != &dma_iommu_ops);1038pdev->dev.archdata.dma_offset = pe->tce_bypass_base;1039set_iommu_table_base(&pdev->dev, pe->table_group.tables[0]);10401041/* PEs with a DMA weight of zero won't have a group */1042if (pe->table_group.group)1043iommu_add_device(&pe->table_group, &pdev->dev);1044}10451046/*1047* Reconfigure TVE#0 to be usable as 64-bit DMA space.1048*1049* The first 4GB of virtual memory for a PE is reserved for 32-bit accesses.1050* Devices can only access more than that if bit 59 of the PCI address is set1051* by hardware, which indicates TVE#1 should be used instead of TVE#0.1052* Many PCI devices are not capable of addressing that many bits, and as a1053* result are limited to the 4GB of virtual memory made available to 32-bit1054* devices in TVE#0.1055*1056* In order to work around this, reconfigure TVE#0 to be suitable for 64-bit1057* devices by configuring the virtual memory past the first 4GB inaccessible1058* by 64-bit DMAs. This should only be used by devices that want more than1059* 4GB, and only on PEs that have no 32-bit devices.1060*1061* Currently this will only work on PHB3 (POWER8).1062*/1063static int pnv_pci_ioda_dma_64bit_bypass(struct pnv_ioda_pe *pe)1064{1065u64 window_size, table_size, tce_count, addr;1066struct page *table_pages;1067u64 tce_order = 28; /* 256MB TCEs */1068__be64 *tces;1069s64 rc;10701071/*1072* Window size needs to be a power of two, but needs to account for1073* shifting memory by the 4GB offset required to skip 32bit space.1074*/1075window_size = roundup_pow_of_two(memory_hotplug_max() + (1ULL << 32));1076tce_count = window_size >> tce_order;1077table_size = tce_count << 3;10781079if (table_size < PAGE_SIZE)1080table_size = PAGE_SIZE;10811082table_pages = alloc_pages_node(pe->phb->hose->node, GFP_KERNEL,1083get_order(table_size));1084if (!table_pages)1085goto err;10861087tces = page_address(table_pages);1088if (!tces)1089goto err;10901091memset(tces, 0, table_size);10921093for (addr = 0; addr < memory_hotplug_max(); addr += (1 << tce_order)) {1094tces[(addr + (1ULL << 32)) >> tce_order] =1095cpu_to_be64(addr | TCE_PCI_READ | TCE_PCI_WRITE);1096}10971098rc = opal_pci_map_pe_dma_window(pe->phb->opal_id,1099pe->pe_number,1100/* reconfigure window 0 */1101(pe->pe_number << 1) + 0,11021,1103__pa(tces),1104table_size,11051 << tce_order);1106if (rc == OPAL_SUCCESS) {1107pe_info(pe, "Using 64-bit DMA iommu bypass (through TVE#0)\n");1108return 0;1109}1110err:1111pe_err(pe, "Error configuring 64-bit DMA bypass\n");1112return -EIO;1113}11141115static bool pnv_pci_ioda_iommu_bypass_supported(struct pci_dev *pdev,1116u64 dma_mask)1117{1118struct pnv_phb *phb = pci_bus_to_pnvhb(pdev->bus);1119struct pci_dn *pdn = pci_get_pdn(pdev);1120struct pnv_ioda_pe *pe;11211122if (WARN_ON(!pdn || pdn->pe_number == IODA_INVALID_PE))1123return false;11241125pe = &phb->ioda.pe_array[pdn->pe_number];1126if (pe->tce_bypass_enabled) {1127u64 top = pe->tce_bypass_base + memblock_end_of_DRAM() - 1;1128if (dma_mask >= top)1129return true;1130}11311132/*1133* If the device can't set the TCE bypass bit but still wants1134* to access 4GB or more, on PHB3 we can reconfigure TVE#0 to1135* bypass the 32-bit region and be usable for 64-bit DMAs.1136* The device needs to be able to address all of this space.1137*/1138if (dma_mask >> 32 &&1139dma_mask > (memory_hotplug_max() + (1ULL << 32)) &&1140/* pe->pdev should be set if it's a single device, pe->pbus if not */1141(pe->device_count == 1 || !pe->pbus) &&1142phb->model == PNV_PHB_MODEL_PHB3) {1143/* Configure the bypass mode */1144s64 rc = pnv_pci_ioda_dma_64bit_bypass(pe);1145if (rc)1146return false;1147/* 4GB offset bypasses 32-bit space */1148pdev->dev.archdata.dma_offset = (1ULL << 32);1149return true;1150}11511152return false;1153}11541155static inline __be64 __iomem *pnv_ioda_get_inval_reg(struct pnv_phb *phb)1156{1157return phb->regs + 0x210;1158}11591160#ifdef CONFIG_IOMMU_API1161/* Common for IODA1 and IODA2 */1162static int pnv_ioda_tce_xchg_no_kill(struct iommu_table *tbl, long index,1163unsigned long *hpa, enum dma_data_direction *direction)1164{1165return pnv_tce_xchg(tbl, index, hpa, direction);1166}1167#endif11681169#define PHB3_TCE_KILL_INVAL_ALL PPC_BIT(0)1170#define PHB3_TCE_KILL_INVAL_PE PPC_BIT(1)1171#define PHB3_TCE_KILL_INVAL_ONE PPC_BIT(2)11721173static inline void pnv_pci_phb3_tce_invalidate_pe(struct pnv_ioda_pe *pe)1174{1175/* 01xb - invalidate TCEs that match the specified PE# */1176__be64 __iomem *invalidate = pnv_ioda_get_inval_reg(pe->phb);1177unsigned long val = PHB3_TCE_KILL_INVAL_PE | (pe->pe_number & 0xFF);11781179mb(); /* Ensure above stores are visible */1180__raw_writeq_be(val, invalidate);1181}11821183static void pnv_pci_phb3_tce_invalidate(struct pnv_ioda_pe *pe,1184unsigned shift, unsigned long index,1185unsigned long npages)1186{1187__be64 __iomem *invalidate = pnv_ioda_get_inval_reg(pe->phb);1188unsigned long start, end, inc;11891190/* We'll invalidate DMA address in PE scope */1191start = PHB3_TCE_KILL_INVAL_ONE;1192start |= (pe->pe_number & 0xFF);1193end = start;11941195/* Figure out the start, end and step */1196start |= (index << shift);1197end |= ((index + npages - 1) << shift);1198inc = (0x1ull << shift);1199mb();12001201while (start <= end) {1202__raw_writeq_be(start, invalidate);1203start += inc;1204}1205}12061207static inline void pnv_pci_ioda2_tce_invalidate_pe(struct pnv_ioda_pe *pe)1208{1209struct pnv_phb *phb = pe->phb;12101211if (phb->model == PNV_PHB_MODEL_PHB3 && phb->regs)1212pnv_pci_phb3_tce_invalidate_pe(pe);1213else1214opal_pci_tce_kill(phb->opal_id, OPAL_PCI_TCE_KILL_PE,1215pe->pe_number, 0, 0, 0);1216}12171218static void pnv_pci_ioda2_tce_invalidate(struct iommu_table *tbl,1219unsigned long index, unsigned long npages)1220{1221struct iommu_table_group_link *tgl;12221223list_for_each_entry_lockless(tgl, &tbl->it_group_list, next) {1224struct pnv_ioda_pe *pe = container_of(tgl->table_group,1225struct pnv_ioda_pe, table_group);1226struct pnv_phb *phb = pe->phb;1227unsigned int shift = tbl->it_page_shift;12281229if (phb->model == PNV_PHB_MODEL_PHB3 && phb->regs)1230pnv_pci_phb3_tce_invalidate(pe, shift,1231index, npages);1232else1233opal_pci_tce_kill(phb->opal_id,1234OPAL_PCI_TCE_KILL_PAGES,1235pe->pe_number, 1u << shift,1236index << shift, npages);1237}1238}12391240static int pnv_ioda2_tce_build(struct iommu_table *tbl, long index,1241long npages, unsigned long uaddr,1242enum dma_data_direction direction,1243unsigned long attrs)1244{1245int ret = pnv_tce_build(tbl, index, npages, uaddr, direction,1246attrs);12471248if (!ret)1249pnv_pci_ioda2_tce_invalidate(tbl, index, npages);12501251return ret;1252}12531254static void pnv_ioda2_tce_free(struct iommu_table *tbl, long index,1255long npages)1256{1257pnv_tce_free(tbl, index, npages);12581259pnv_pci_ioda2_tce_invalidate(tbl, index, npages);1260}12611262static struct iommu_table_ops pnv_ioda2_iommu_ops = {1263.set = pnv_ioda2_tce_build,1264#ifdef CONFIG_IOMMU_API1265.xchg_no_kill = pnv_ioda_tce_xchg_no_kill,1266.tce_kill = pnv_pci_ioda2_tce_invalidate,1267.useraddrptr = pnv_tce_useraddrptr,1268#endif1269.clear = pnv_ioda2_tce_free,1270.get = pnv_tce_get,1271.free = pnv_pci_ioda2_table_free_pages,1272};12731274static long pnv_pci_ioda2_set_window(struct iommu_table_group *table_group,1275int num, struct iommu_table *tbl)1276{1277struct pnv_ioda_pe *pe = container_of(table_group, struct pnv_ioda_pe,1278table_group);1279struct pnv_phb *phb = pe->phb;1280int64_t rc;1281const unsigned long size = tbl->it_indirect_levels ?1282tbl->it_level_size : tbl->it_size;1283const __u64 start_addr = tbl->it_offset << tbl->it_page_shift;1284const __u64 win_size = tbl->it_size << tbl->it_page_shift;12851286pe_info(pe, "Setting up window#%d %llx..%llx pg=%lx\n",1287num, start_addr, start_addr + win_size - 1,1288IOMMU_PAGE_SIZE(tbl));12891290/*1291* Map TCE table through TVT. The TVE index is the PE number1292* shifted by 1 bit for 32-bits DMA space.1293*/1294rc = opal_pci_map_pe_dma_window(phb->opal_id,1295pe->pe_number,1296(pe->pe_number << 1) + num,1297tbl->it_indirect_levels + 1,1298__pa(tbl->it_base),1299size << 3,1300IOMMU_PAGE_SIZE(tbl));1301if (rc) {1302pe_err(pe, "Failed to configure TCE table, err %lld\n", rc);1303return rc;1304}13051306pnv_pci_link_table_and_group(phb->hose->node, num,1307tbl, &pe->table_group);1308pnv_pci_ioda2_tce_invalidate_pe(pe);13091310return 0;1311}13121313static void pnv_pci_ioda2_set_bypass(struct pnv_ioda_pe *pe, bool enable)1314{1315uint16_t window_id = (pe->pe_number << 1 ) + 1;1316int64_t rc;13171318pe_info(pe, "%sabling 64-bit DMA bypass\n", enable ? "En" : "Dis");1319if (enable) {1320phys_addr_t top = memblock_end_of_DRAM();13211322top = roundup_pow_of_two(top);1323rc = opal_pci_map_pe_dma_window_real(pe->phb->opal_id,1324pe->pe_number,1325window_id,1326pe->tce_bypass_base,1327top);1328} else {1329rc = opal_pci_map_pe_dma_window_real(pe->phb->opal_id,1330pe->pe_number,1331window_id,1332pe->tce_bypass_base,13330);1334}1335if (rc)1336pe_err(pe, "OPAL error %lld configuring bypass window\n", rc);1337else1338pe->tce_bypass_enabled = enable;1339}13401341static long pnv_pci_ioda2_create_table(struct iommu_table_group *table_group,1342int num, __u32 page_shift, __u64 window_size, __u32 levels,1343bool alloc_userspace_copy, struct iommu_table **ptbl)1344{1345struct pnv_ioda_pe *pe = container_of(table_group, struct pnv_ioda_pe,1346table_group);1347int nid = pe->phb->hose->node;1348__u64 bus_offset = num ? pe->tce_bypass_base : table_group->tce32_start;1349long ret;1350struct iommu_table *tbl;13511352tbl = pnv_pci_table_alloc(nid);1353if (!tbl)1354return -ENOMEM;13551356tbl->it_ops = &pnv_ioda2_iommu_ops;13571358ret = pnv_pci_ioda2_table_alloc_pages(nid,1359bus_offset, page_shift, window_size,1360levels, alloc_userspace_copy, tbl);1361if (ret) {1362iommu_tce_table_put(tbl);1363return ret;1364}13651366*ptbl = tbl;13671368return 0;1369}13701371static long pnv_pci_ioda2_setup_default_config(struct pnv_ioda_pe *pe)1372{1373struct iommu_table *tbl = NULL;1374long rc;1375unsigned long res_start, res_end;13761377/*1378* crashkernel= specifies the kdump kernel's maximum memory at1379* some offset and there is no guaranteed the result is a power1380* of 2, which will cause errors later.1381*/1382const u64 max_memory = __rounddown_pow_of_two(memory_hotplug_max());13831384/*1385* In memory constrained environments, e.g. kdump kernel, the1386* DMA window can be larger than available memory, which will1387* cause errors later.1388*/1389const u64 maxblock = 1UL << (PAGE_SHIFT + MAX_PAGE_ORDER);13901391/*1392* We create the default window as big as we can. The constraint is1393* the max order of allocation possible. The TCE table is likely to1394* end up being multilevel and with on-demand allocation in place,1395* the initial use is not going to be huge as the default window aims1396* to support crippled devices (i.e. not fully 64bit DMAble) only.1397*/1398/* iommu_table::it_map uses 1 bit per IOMMU page, hence 8 */1399const u64 window_size = min((maxblock * 8) << PAGE_SHIFT, max_memory);1400/* Each TCE level cannot exceed maxblock so go multilevel if needed */1401unsigned long tces_order = ilog2(window_size >> PAGE_SHIFT);1402unsigned long tcelevel_order = ilog2(maxblock >> 3);1403unsigned int levels = tces_order / tcelevel_order;14041405if (tces_order % tcelevel_order)1406levels += 1;1407/*1408* We try to stick to default levels (which is >1 at the moment) in1409* order to save memory by relying on on-demain TCE level allocation.1410*/1411levels = max_t(unsigned int, levels, POWERNV_IOMMU_DEFAULT_LEVELS);14121413rc = pnv_pci_ioda2_create_table(&pe->table_group, 0, PAGE_SHIFT,1414window_size, levels, false, &tbl);1415if (rc) {1416pe_err(pe, "Failed to create 32-bit TCE table, err %ld",1417rc);1418return rc;1419}14201421/* We use top part of 32bit space for MMIO so exclude it from DMA */1422res_start = 0;1423res_end = 0;1424if (window_size > pe->phb->ioda.m32_pci_base) {1425res_start = pe->phb->ioda.m32_pci_base >> tbl->it_page_shift;1426res_end = min(window_size, SZ_4G) >> tbl->it_page_shift;1427}14281429tbl->it_index = (pe->phb->hose->global_number << 16) | pe->pe_number;1430if (iommu_init_table(tbl, pe->phb->hose->node, res_start, res_end))1431rc = pnv_pci_ioda2_set_window(&pe->table_group, 0, tbl);1432else1433rc = -ENOMEM;1434if (rc) {1435pe_err(pe, "Failed to configure 32-bit TCE table, err %ld\n", rc);1436iommu_tce_table_put(tbl);1437tbl = NULL; /* This clears iommu_table_base below */1438}1439if (!pnv_iommu_bypass_disabled)1440pnv_pci_ioda2_set_bypass(pe, true);14411442/*1443* Set table base for the case of IOMMU DMA use. Usually this is done1444* from dma_dev_setup() which is not called when a device is returned1445* from VFIO so do it here.1446*/1447if (pe->pdev)1448set_iommu_table_base(&pe->pdev->dev, tbl);14491450return 0;1451}14521453static long pnv_pci_ioda2_unset_window(struct iommu_table_group *table_group,1454int num)1455{1456struct pnv_ioda_pe *pe = container_of(table_group, struct pnv_ioda_pe,1457table_group);1458struct pnv_phb *phb = pe->phb;1459long ret;14601461pe_info(pe, "Removing DMA window #%d\n", num);14621463ret = opal_pci_map_pe_dma_window(phb->opal_id, pe->pe_number,1464(pe->pe_number << 1) + num,14650/* levels */, 0/* table address */,14660/* table size */, 0/* page size */);1467if (ret)1468pe_warn(pe, "Unmapping failed, ret = %ld\n", ret);1469else1470pnv_pci_ioda2_tce_invalidate_pe(pe);14711472pnv_pci_unlink_table_and_group(table_group->tables[num], table_group);14731474return ret;1475}14761477#ifdef CONFIG_IOMMU_API1478unsigned long pnv_pci_ioda2_get_table_size(__u32 page_shift,1479__u64 window_size, __u32 levels)1480{1481unsigned long bytes = 0;1482const unsigned window_shift = ilog2(window_size);1483unsigned entries_shift = window_shift - page_shift;1484unsigned table_shift = entries_shift + 3;1485unsigned long tce_table_size = max(0x1000UL, 1UL << table_shift);1486unsigned long direct_table_size;14871488if (!levels || (levels > POWERNV_IOMMU_MAX_LEVELS) ||1489!is_power_of_2(window_size))1490return 0;14911492/* Calculate a direct table size from window_size and levels */1493entries_shift = (entries_shift + levels - 1) / levels;1494table_shift = entries_shift + 3;1495table_shift = max_t(unsigned, table_shift, PAGE_SHIFT);1496direct_table_size = 1UL << table_shift;14971498for ( ; levels; --levels) {1499bytes += ALIGN(tce_table_size, direct_table_size);15001501tce_table_size /= direct_table_size;1502tce_table_size <<= 3;1503tce_table_size = max_t(unsigned long,1504tce_table_size, direct_table_size);1505}15061507return bytes + bytes; /* one for HW table, one for userspace copy */1508}15091510static long pnv_pci_ioda2_create_table_userspace(1511struct iommu_table_group *table_group,1512int num, __u32 page_shift, __u64 window_size, __u32 levels,1513struct iommu_table **ptbl)1514{1515long ret = pnv_pci_ioda2_create_table(table_group,1516num, page_shift, window_size, levels, true, ptbl);15171518if (!ret)1519(*ptbl)->it_allocated_size = pnv_pci_ioda2_get_table_size(1520page_shift, window_size, levels);1521return ret;1522}15231524static void pnv_ioda_setup_bus_dma(struct pnv_ioda_pe *pe, struct pci_bus *bus)1525{1526struct pci_dev *dev;15271528list_for_each_entry(dev, &bus->devices, bus_list) {1529set_iommu_table_base(&dev->dev, pe->table_group.tables[0]);1530dev->dev.archdata.dma_offset = pe->tce_bypass_base;15311532if ((pe->flags & PNV_IODA_PE_BUS_ALL) && dev->subordinate)1533pnv_ioda_setup_bus_dma(pe, dev->subordinate);1534}1535}15361537static long pnv_ioda2_take_ownership(struct iommu_table_group *table_group,1538struct device *dev __maybe_unused)1539{1540struct pnv_ioda_pe *pe = container_of(table_group, struct pnv_ioda_pe,1541table_group);1542/* Store @tbl as pnv_pci_ioda2_unset_window() resets it */1543struct iommu_table *tbl = pe->table_group.tables[0];15441545/*1546* iommu_ops transfers the ownership per a device and we mode1547* the group ownership with the first device in the group.1548*/1549if (!tbl)1550return 0;15511552pnv_pci_ioda2_set_bypass(pe, false);1553pnv_pci_ioda2_unset_window(&pe->table_group, 0);1554if (pe->pbus)1555pnv_ioda_setup_bus_dma(pe, pe->pbus);1556else if (pe->pdev)1557set_iommu_table_base(&pe->pdev->dev, NULL);1558iommu_tce_table_put(tbl);15591560return 0;1561}15621563static void pnv_ioda2_release_ownership(struct iommu_table_group *table_group,1564struct device *dev __maybe_unused)1565{1566struct pnv_ioda_pe *pe = container_of(table_group, struct pnv_ioda_pe,1567table_group);15681569/* See the comment about iommu_ops above */1570if (pe->table_group.tables[0])1571return;1572pnv_pci_ioda2_setup_default_config(pe);1573if (pe->pbus)1574pnv_ioda_setup_bus_dma(pe, pe->pbus);1575}15761577static struct iommu_table_group_ops pnv_pci_ioda2_ops = {1578.get_table_size = pnv_pci_ioda2_get_table_size,1579.create_table = pnv_pci_ioda2_create_table_userspace,1580.set_window = pnv_pci_ioda2_set_window,1581.unset_window = pnv_pci_ioda2_unset_window,1582.take_ownership = pnv_ioda2_take_ownership,1583.release_ownership = pnv_ioda2_release_ownership,1584};1585#endif15861587void pnv_pci_ioda2_setup_dma_pe(struct pnv_phb *phb,1588struct pnv_ioda_pe *pe)1589{1590int64_t rc;15911592/* TVE #1 is selected by PCI address bit 59 */1593pe->tce_bypass_base = 1ull << 59;15941595/* The PE will reserve all possible 32-bits space */1596pe_info(pe, "Setting up 32-bit TCE table at 0..%08x\n",1597phb->ioda.m32_pci_base);15981599/* Setup linux iommu table */1600pe->table_group.tce32_start = 0;1601pe->table_group.tce32_size = phb->ioda.m32_pci_base;1602pe->table_group.max_dynamic_windows_supported =1603IOMMU_TABLE_GROUP_MAX_TABLES;1604pe->table_group.max_levels = POWERNV_IOMMU_MAX_LEVELS;1605pe->table_group.pgsizes = pnv_ioda_parse_tce_sizes(phb);16061607rc = pnv_pci_ioda2_setup_default_config(pe);1608if (rc)1609return;16101611#ifdef CONFIG_IOMMU_API1612pe->table_group.ops = &pnv_pci_ioda2_ops;1613iommu_register_group(&pe->table_group, phb->hose->global_number,1614pe->pe_number);1615#endif1616pe->dma_setup_done = true;1617}16181619/*1620* Called from KVM in real mode to EOI passthru interrupts. The ICP1621* EOI is handled directly in KVM in kvmppc_deliver_irq_passthru().1622*1623* The IRQ data is mapped in the PCI-MSI domain and the EOI OPAL call1624* needs an HW IRQ number mapped in the XICS IRQ domain. The HW IRQ1625* numbers of the in-the-middle MSI domain are vector numbers and it's1626* good enough for OPAL. Use that.1627*/1628int64_t pnv_opal_pci_msi_eoi(struct irq_data *d)1629{1630struct pci_controller *hose = irq_data_get_irq_chip_data(d->parent_data);1631struct pnv_phb *phb = hose->private_data;16321633return opal_pci_msi_eoi(phb->opal_id, d->parent_data->hwirq);1634}16351636static struct irq_chip pnv_pci_msi_irq_chip;16371638/*1639* Returns true iff chip is something that we could call1640* pnv_opal_pci_msi_eoi for.1641*/1642bool is_pnv_opal_msi(struct irq_chip *chip)1643{1644return chip == &pnv_pci_msi_irq_chip;1645}1646EXPORT_SYMBOL_GPL(is_pnv_opal_msi);16471648static int __pnv_pci_ioda_msi_setup(struct pnv_phb *phb, struct pci_dev *dev,1649unsigned int xive_num,1650unsigned int is_64, struct msi_msg *msg)1651{1652struct pnv_ioda_pe *pe = pnv_ioda_get_pe(dev);1653__be32 data;1654int rc;16551656dev_dbg(&dev->dev, "%s: setup %s-bit MSI for vector #%d\n", __func__,1657is_64 ? "64" : "32", xive_num);16581659/* No PE assigned ? bail out ... no MSI for you ! */1660if (pe == NULL)1661return -ENXIO;16621663/* Check if we have an MVE */1664if (pe->mve_number < 0)1665return -ENXIO;16661667/* Force 32-bit MSI on some broken devices */1668if (dev->no_64bit_msi)1669is_64 = 0;16701671/* Assign XIVE to PE */1672rc = opal_pci_set_xive_pe(phb->opal_id, pe->pe_number, xive_num);1673if (rc) {1674pr_warn("%s: OPAL error %d setting XIVE %d PE\n",1675pci_name(dev), rc, xive_num);1676return -EIO;1677}16781679if (is_64) {1680__be64 addr64;16811682rc = opal_get_msi_64(phb->opal_id, pe->mve_number, xive_num, 1,1683&addr64, &data);1684if (rc) {1685pr_warn("%s: OPAL error %d getting 64-bit MSI data\n",1686pci_name(dev), rc);1687return -EIO;1688}1689msg->address_hi = be64_to_cpu(addr64) >> 32;1690msg->address_lo = be64_to_cpu(addr64) & 0xfffffffful;1691} else {1692__be32 addr32;16931694rc = opal_get_msi_32(phb->opal_id, pe->mve_number, xive_num, 1,1695&addr32, &data);1696if (rc) {1697pr_warn("%s: OPAL error %d getting 32-bit MSI data\n",1698pci_name(dev), rc);1699return -EIO;1700}1701msg->address_hi = 0;1702msg->address_lo = be32_to_cpu(addr32);1703}1704msg->data = be32_to_cpu(data);17051706return 0;1707}17081709static void pnv_msi_shutdown(struct irq_data *d)1710{1711d = d->parent_data;1712if (d->chip->irq_shutdown)1713d->chip->irq_shutdown(d);1714}17151716static bool pnv_init_dev_msi_info(struct device *dev, struct irq_domain *domain,1717struct irq_domain *real_parent, struct msi_domain_info *info)1718{1719struct irq_chip *chip = info->chip;17201721if (!msi_lib_init_dev_msi_info(dev, domain, real_parent, info))1722return false;17231724chip->irq_shutdown = pnv_msi_shutdown;1725return true;1726}17271728#define PNV_PCI_MSI_FLAGS_REQUIRED (MSI_FLAG_USE_DEF_DOM_OPS | \1729MSI_FLAG_USE_DEF_CHIP_OPS | \1730MSI_FLAG_PCI_MSI_MASK_PARENT)1731#define PNV_PCI_MSI_FLAGS_SUPPORTED (MSI_GENERIC_FLAGS_MASK | \1732MSI_FLAG_PCI_MSIX | \1733MSI_FLAG_MULTI_PCI_MSI)17341735static const struct msi_parent_ops pnv_msi_parent_ops = {1736.required_flags = PNV_PCI_MSI_FLAGS_REQUIRED,1737.supported_flags = PNV_PCI_MSI_FLAGS_SUPPORTED,1738.chip_flags = MSI_CHIP_FLAG_SET_EOI,1739.bus_select_token = DOMAIN_BUS_NEXUS,1740.bus_select_mask = MATCH_PCI_MSI,1741.prefix = "PNV-",1742.init_dev_msi_info = pnv_init_dev_msi_info,1743};17441745static void pnv_msi_compose_msg(struct irq_data *d, struct msi_msg *msg)1746{1747struct msi_desc *entry = irq_data_get_msi_desc(d);1748struct pci_dev *pdev = msi_desc_to_pci_dev(entry);1749struct pci_controller *hose = irq_data_get_irq_chip_data(d);1750struct pnv_phb *phb = hose->private_data;1751int rc;17521753rc = __pnv_pci_ioda_msi_setup(phb, pdev, d->hwirq,1754entry->pci.msi_attrib.is_64, msg);1755if (rc)1756dev_err(&pdev->dev, "Failed to setup %s-bit MSI #%ld : %d\n",1757entry->pci.msi_attrib.is_64 ? "64" : "32", d->hwirq, rc);1758}17591760/*1761* The IRQ data is mapped in the MSI domain in which HW IRQ numbers1762* correspond to vector numbers.1763*/1764static void pnv_msi_eoi(struct irq_data *d)1765{1766struct pci_controller *hose = irq_data_get_irq_chip_data(d);1767struct pnv_phb *phb = hose->private_data;17681769if (phb->model == PNV_PHB_MODEL_PHB3) {1770/*1771* The EOI OPAL call takes an OPAL HW IRQ number but1772* since it is translated into a vector number in1773* OPAL, use that directly.1774*/1775WARN_ON_ONCE(opal_pci_msi_eoi(phb->opal_id, d->hwirq));1776}17771778irq_chip_eoi_parent(d);1779}17801781static struct irq_chip pnv_msi_irq_chip = {1782.name = "PNV-MSI",1783.irq_shutdown = pnv_msi_shutdown,1784.irq_mask = irq_chip_mask_parent,1785.irq_unmask = irq_chip_unmask_parent,1786.irq_eoi = pnv_msi_eoi,1787.irq_set_affinity = irq_chip_set_affinity_parent,1788.irq_compose_msi_msg = pnv_msi_compose_msg,1789};17901791static int pnv_irq_parent_domain_alloc(struct irq_domain *domain,1792unsigned int virq, int hwirq)1793{1794struct irq_fwspec parent_fwspec;1795int ret;17961797parent_fwspec.fwnode = domain->parent->fwnode;1798parent_fwspec.param_count = 2;1799parent_fwspec.param[0] = hwirq;1800parent_fwspec.param[1] = IRQ_TYPE_EDGE_RISING;18011802ret = irq_domain_alloc_irqs_parent(domain, virq, 1, &parent_fwspec);1803if (ret)1804return ret;18051806return 0;1807}18081809static int pnv_irq_domain_alloc(struct irq_domain *domain, unsigned int virq,1810unsigned int nr_irqs, void *arg)1811{1812struct pci_controller *hose = domain->host_data;1813struct pnv_phb *phb = hose->private_data;1814msi_alloc_info_t *info = arg;1815struct pci_dev *pdev = msi_desc_to_pci_dev(info->desc);1816int hwirq;1817int i, ret;18181819hwirq = msi_bitmap_alloc_hwirqs(&phb->msi_bmp, nr_irqs);1820if (hwirq < 0) {1821dev_warn(&pdev->dev, "failed to find a free MSI\n");1822return -ENOSPC;1823}18241825dev_dbg(&pdev->dev, "%s bridge %pOF %d/%x #%d\n", __func__,1826hose->dn, virq, hwirq, nr_irqs);18271828for (i = 0; i < nr_irqs; i++) {1829ret = pnv_irq_parent_domain_alloc(domain, virq + i,1830phb->msi_base + hwirq + i);1831if (ret)1832goto out;18331834irq_domain_set_hwirq_and_chip(domain, virq + i, hwirq + i,1835&pnv_msi_irq_chip, hose);1836}18371838return 0;18391840out:1841irq_domain_free_irqs_parent(domain, virq, i);1842msi_bitmap_free_hwirqs(&phb->msi_bmp, hwirq, nr_irqs);1843return ret;1844}18451846static void pnv_irq_domain_free(struct irq_domain *domain, unsigned int virq,1847unsigned int nr_irqs)1848{1849struct irq_data *d = irq_domain_get_irq_data(domain, virq);1850struct pci_controller *hose = irq_data_get_irq_chip_data(d);1851struct pnv_phb *phb = hose->private_data;18521853pr_debug("%s bridge %pOF %d/%lx #%d\n", __func__, hose->dn,1854virq, d->hwirq, nr_irqs);18551856msi_bitmap_free_hwirqs(&phb->msi_bmp, d->hwirq, nr_irqs);1857irq_domain_free_irqs_parent(domain, virq, nr_irqs);1858}18591860static const struct irq_domain_ops pnv_irq_domain_ops = {1861.select = msi_lib_irq_domain_select,1862.alloc = pnv_irq_domain_alloc,1863.free = pnv_irq_domain_free,1864};18651866static int __init pnv_msi_allocate_domains(struct pci_controller *hose, unsigned int count)1867{1868struct irq_domain *parent = irq_get_default_domain();1869struct irq_domain_info info = {1870.fwnode = of_fwnode_handle(hose->dn),1871.ops = &pnv_irq_domain_ops,1872.host_data = hose,1873.size = count,1874.parent = parent,1875};18761877hose->dev_domain = msi_create_parent_irq_domain(&info, &pnv_msi_parent_ops);1878if (!hose->dev_domain) {1879pr_err("PCI: failed to create MSI IRQ domain bridge %pOF (domain %d)\n",1880hose->dn, hose->global_number);1881return -ENOMEM;1882}18831884return 0;1885}18861887static void __init pnv_pci_init_ioda_msis(struct pnv_phb *phb)1888{1889unsigned int count;1890const __be32 *prop = of_get_property(phb->hose->dn,1891"ibm,opal-msi-ranges", NULL);1892if (!prop) {1893/* BML Fallback */1894prop = of_get_property(phb->hose->dn, "msi-ranges", NULL);1895}1896if (!prop)1897return;18981899phb->msi_base = be32_to_cpup(prop);1900count = be32_to_cpup(prop + 1);1901if (msi_bitmap_alloc(&phb->msi_bmp, count, phb->hose->dn)) {1902pr_err("PCI %d: Failed to allocate MSI bitmap !\n",1903phb->hose->global_number);1904return;1905}19061907pr_info(" Allocated bitmap for %d MSIs (base IRQ 0x%x)\n",1908count, phb->msi_base);19091910pnv_msi_allocate_domains(phb->hose, count);1911}19121913static void pnv_ioda_setup_pe_res(struct pnv_ioda_pe *pe,1914struct resource *res)1915{1916struct pnv_phb *phb = pe->phb;1917struct pci_bus_region region;1918int index;1919int64_t rc;19201921if (!res || !res->flags || res->start > res->end ||1922res->flags & IORESOURCE_UNSET)1923return;19241925if (res->flags & IORESOURCE_IO) {1926region.start = res->start - phb->ioda.io_pci_base;1927region.end = res->end - phb->ioda.io_pci_base;1928index = region.start / phb->ioda.io_segsize;19291930while (index < phb->ioda.total_pe_num &&1931region.start <= region.end) {1932phb->ioda.io_segmap[index] = pe->pe_number;1933rc = opal_pci_map_pe_mmio_window(phb->opal_id,1934pe->pe_number, OPAL_IO_WINDOW_TYPE, 0, index);1935if (rc != OPAL_SUCCESS) {1936pr_err("%s: Error %lld mapping IO segment#%d to PE#%x\n",1937__func__, rc, index, pe->pe_number);1938break;1939}19401941region.start += phb->ioda.io_segsize;1942index++;1943}1944} else if ((res->flags & IORESOURCE_MEM) &&1945!pnv_pci_is_m64(phb, res)) {1946region.start = res->start -1947phb->hose->mem_offset[0] -1948phb->ioda.m32_pci_base;1949region.end = res->end -1950phb->hose->mem_offset[0] -1951phb->ioda.m32_pci_base;1952index = region.start / phb->ioda.m32_segsize;19531954while (index < phb->ioda.total_pe_num &&1955region.start <= region.end) {1956phb->ioda.m32_segmap[index] = pe->pe_number;1957rc = opal_pci_map_pe_mmio_window(phb->opal_id,1958pe->pe_number, OPAL_M32_WINDOW_TYPE, 0, index);1959if (rc != OPAL_SUCCESS) {1960pr_err("%s: Error %lld mapping M32 segment#%d to PE#%x",1961__func__, rc, index, pe->pe_number);1962break;1963}19641965region.start += phb->ioda.m32_segsize;1966index++;1967}1968}1969}19701971/*1972* This function is supposed to be called on basis of PE from top1973* to bottom style. So the I/O or MMIO segment assigned to1974* parent PE could be overridden by its child PEs if necessary.1975*/1976static void pnv_ioda_setup_pe_seg(struct pnv_ioda_pe *pe)1977{1978struct pci_dev *pdev;1979int i;19801981/*1982* NOTE: We only care PCI bus based PE for now. For PCI1983* device based PE, for example SRIOV sensitive VF should1984* be figured out later.1985*/1986BUG_ON(!(pe->flags & (PNV_IODA_PE_BUS | PNV_IODA_PE_BUS_ALL)));19871988list_for_each_entry(pdev, &pe->pbus->devices, bus_list) {1989for (i = 0; i <= PCI_ROM_RESOURCE; i++)1990pnv_ioda_setup_pe_res(pe, &pdev->resource[i]);19911992/*1993* If the PE contains all subordinate PCI buses, the1994* windows of the child bridges should be mapped to1995* the PE as well.1996*/1997if (!(pe->flags & PNV_IODA_PE_BUS_ALL) || !pci_is_bridge(pdev))1998continue;1999for (i = 0; i < PCI_BRIDGE_RESOURCE_NUM; i++)2000pnv_ioda_setup_pe_res(pe,2001&pdev->resource[PCI_BRIDGE_RESOURCES + i]);2002}2003}20042005#ifdef CONFIG_DEBUG_FS2006static int pnv_pci_diag_data_set(void *data, u64 val)2007{2008struct pnv_phb *phb = data;2009s64 ret;20102011/* Retrieve the diag data from firmware */2012ret = opal_pci_get_phb_diag_data2(phb->opal_id, phb->diag_data,2013phb->diag_data_size);2014if (ret != OPAL_SUCCESS)2015return -EIO;20162017/* Print the diag data to the kernel log */2018pnv_pci_dump_phb_diag_data(phb->hose, phb->diag_data);2019return 0;2020}20212022DEFINE_DEBUGFS_ATTRIBUTE(pnv_pci_diag_data_fops, NULL, pnv_pci_diag_data_set,2023"%llu\n");20242025static int pnv_pci_ioda_pe_dump(void *data, u64 val)2026{2027struct pnv_phb *phb = data;2028int pe_num;20292030for (pe_num = 0; pe_num < phb->ioda.total_pe_num; pe_num++) {2031struct pnv_ioda_pe *pe = &phb->ioda.pe_array[pe_num];20322033if (!test_bit(pe_num, phb->ioda.pe_alloc))2034continue;20352036pe_warn(pe, "rid: %04x dev count: %2d flags: %s%s%s%s%s%s\n",2037pe->rid, pe->device_count,2038(pe->flags & PNV_IODA_PE_DEV) ? "dev " : "",2039(pe->flags & PNV_IODA_PE_BUS) ? "bus " : "",2040(pe->flags & PNV_IODA_PE_BUS_ALL) ? "all " : "",2041(pe->flags & PNV_IODA_PE_MASTER) ? "master " : "",2042(pe->flags & PNV_IODA_PE_SLAVE) ? "slave " : "",2043(pe->flags & PNV_IODA_PE_VF) ? "vf " : "");2044}20452046return 0;2047}20482049DEFINE_DEBUGFS_ATTRIBUTE(pnv_pci_ioda_pe_dump_fops, NULL,2050pnv_pci_ioda_pe_dump, "%llu\n");20512052#endif /* CONFIG_DEBUG_FS */20532054static void pnv_pci_ioda_create_dbgfs(void)2055{2056#ifdef CONFIG_DEBUG_FS2057struct pci_controller *hose, *tmp;2058struct pnv_phb *phb;2059char name[16];20602061list_for_each_entry_safe(hose, tmp, &hose_list, list_node) {2062phb = hose->private_data;20632064sprintf(name, "PCI%04x", hose->global_number);2065phb->dbgfs = debugfs_create_dir(name, arch_debugfs_dir);20662067debugfs_create_file_unsafe("dump_diag_regs", 0200, phb->dbgfs,2068phb, &pnv_pci_diag_data_fops);2069debugfs_create_file_unsafe("dump_ioda_pe_state", 0200, phb->dbgfs,2070phb, &pnv_pci_ioda_pe_dump_fops);2071}2072#endif /* CONFIG_DEBUG_FS */2073}20742075static void pnv_pci_enable_bridge(struct pci_bus *bus)2076{2077struct pci_dev *dev = bus->self;2078struct pci_bus *child;20792080/* Empty bus ? bail */2081if (list_empty(&bus->devices))2082return;20832084/*2085* If there's a bridge associated with that bus enable it. This works2086* around races in the generic code if the enabling is done during2087* parallel probing. This can be removed once those races have been2088* fixed.2089*/2090if (dev) {2091int rc = pci_enable_device(dev);2092if (rc)2093pci_err(dev, "Error enabling bridge (%d)\n", rc);2094pci_set_master(dev);2095}20962097/* Perform the same to child busses */2098list_for_each_entry(child, &bus->children, node)2099pnv_pci_enable_bridge(child);2100}21012102static void pnv_pci_enable_bridges(void)2103{2104struct pci_controller *hose;21052106list_for_each_entry(hose, &hose_list, list_node)2107pnv_pci_enable_bridge(hose->bus);2108}21092110static void pnv_pci_ioda_fixup(void)2111{2112pnv_pci_ioda_create_dbgfs();21132114pnv_pci_enable_bridges();21152116#ifdef CONFIG_EEH2117pnv_eeh_post_init();2118#endif2119}21202121/*2122* Returns the alignment for I/O or memory windows for P2P2123* bridges. That actually depends on how PEs are segmented.2124* For now, we return I/O or M32 segment size for PE sensitive2125* P2P bridges. Otherwise, the default values (4KiB for I/O,2126* 1MiB for memory) will be returned.2127*2128* The current PCI bus might be put into one PE, which was2129* create against the parent PCI bridge. For that case, we2130* needn't enlarge the alignment so that we can save some2131* resources.2132*/2133static resource_size_t pnv_pci_window_alignment(struct pci_bus *bus,2134unsigned long type)2135{2136struct pnv_phb *phb = pci_bus_to_pnvhb(bus);2137int num_pci_bridges = 0;2138struct pci_dev *bridge;21392140bridge = bus->self;2141while (bridge) {2142if (pci_pcie_type(bridge) == PCI_EXP_TYPE_PCI_BRIDGE) {2143num_pci_bridges++;2144if (num_pci_bridges >= 2)2145return 1;2146}21472148bridge = bridge->bus->self;2149}21502151/*2152* We fall back to M32 if M64 isn't supported. We enforce the M642153* alignment for any 64-bit resource, PCIe doesn't care and2154* bridges only do 64-bit prefetchable anyway.2155*/2156if (phb->ioda.m64_segsize && pnv_pci_is_m64_flags(type))2157return phb->ioda.m64_segsize;2158if (type & IORESOURCE_MEM)2159return phb->ioda.m32_segsize;21602161return phb->ioda.io_segsize;2162}21632164/*2165* We are updating root port or the upstream port of the2166* bridge behind the root port with PHB's windows in order2167* to accommodate the changes on required resources during2168* PCI (slot) hotplug, which is connected to either root2169* port or the downstream ports of PCIe switch behind the2170* root port.2171*/2172static void pnv_pci_fixup_bridge_resources(struct pci_bus *bus,2173unsigned long type)2174{2175struct pci_controller *hose = pci_bus_to_host(bus);2176struct pnv_phb *phb = hose->private_data;2177struct pci_dev *bridge = bus->self;2178struct resource *r, *w;2179bool msi_region = false;2180int i;21812182/* Check if we need apply fixup to the bridge's windows */2183if (!pci_is_root_bus(bridge->bus) &&2184!pci_is_root_bus(bridge->bus->self->bus))2185return;21862187/* Fixup the resources */2188for (i = 0; i < PCI_BRIDGE_RESOURCE_NUM; i++) {2189r = &bridge->resource[PCI_BRIDGE_RESOURCES + i];2190if (!r->flags || !r->parent)2191continue;21922193w = NULL;2194if (r->flags & type & IORESOURCE_IO)2195w = &hose->io_resource;2196else if (pnv_pci_is_m64(phb, r) &&2197(type & IORESOURCE_PREFETCH) &&2198phb->ioda.m64_segsize)2199w = &hose->mem_resources[1];2200else if (r->flags & type & IORESOURCE_MEM) {2201w = &hose->mem_resources[0];2202msi_region = true;2203}22042205r->start = w->start;2206r->end = w->end;22072208/* The 64KB 32-bits MSI region shouldn't be included in2209* the 32-bits bridge window. Otherwise, we can see strange2210* issues. One of them is EEH error observed on Garrison.2211*2212* Exclude top 1MB region which is the minimal alignment of2213* 32-bits bridge window.2214*/2215if (msi_region) {2216r->end += 0x10000;2217r->end -= 0x100000;2218}2219}2220}22212222static void pnv_pci_configure_bus(struct pci_bus *bus)2223{2224struct pci_dev *bridge = bus->self;2225struct pnv_ioda_pe *pe;2226bool all = (bridge && pci_pcie_type(bridge) == PCI_EXP_TYPE_PCI_BRIDGE);22272228dev_info(&bus->dev, "Configuring PE for bus\n");22292230/* Don't assign PE to PCI bus, which doesn't have subordinate devices */2231if (WARN_ON(list_empty(&bus->devices)))2232return;22332234/* Reserve PEs according to used M64 resources */2235pnv_ioda_reserve_m64_pe(bus, NULL, all);22362237/*2238* Assign PE. We might run here because of partial hotplug.2239* For the case, we just pick up the existing PE and should2240* not allocate resources again.2241*/2242pe = pnv_ioda_setup_bus_PE(bus, all);2243if (!pe)2244return;22452246pnv_ioda_setup_pe_seg(pe);2247}22482249static resource_size_t pnv_pci_default_alignment(void)2250{2251return PAGE_SIZE;2252}22532254/* Prevent enabling devices for which we couldn't properly2255* assign a PE2256*/2257static bool pnv_pci_enable_device_hook(struct pci_dev *dev)2258{2259struct pci_dn *pdn;22602261pdn = pci_get_pdn(dev);2262if (!pdn || pdn->pe_number == IODA_INVALID_PE) {2263pci_err(dev, "pci_enable_device() blocked, no PE assigned.\n");2264return false;2265}22662267return true;2268}22692270static bool pnv_ocapi_enable_device_hook(struct pci_dev *dev)2271{2272struct pci_dn *pdn;2273struct pnv_ioda_pe *pe;22742275pdn = pci_get_pdn(dev);2276if (!pdn)2277return false;22782279if (pdn->pe_number == IODA_INVALID_PE) {2280pe = pnv_ioda_setup_dev_PE(dev);2281if (!pe)2282return false;2283}2284return true;2285}22862287void pnv_pci_ioda2_release_pe_dma(struct pnv_ioda_pe *pe)2288{2289struct iommu_table *tbl = pe->table_group.tables[0];2290int64_t rc;22912292if (!pe->dma_setup_done)2293return;22942295rc = pnv_pci_ioda2_unset_window(&pe->table_group, 0);2296if (rc)2297pe_warn(pe, "OPAL error %lld release DMA window\n", rc);22982299pnv_pci_ioda2_set_bypass(pe, false);2300if (pe->table_group.group) {2301iommu_group_put(pe->table_group.group);2302WARN_ON(pe->table_group.group);2303}23042305iommu_tce_table_put(tbl);2306}23072308static void pnv_ioda_free_pe_seg(struct pnv_ioda_pe *pe,2309unsigned short win,2310unsigned int *map)2311{2312struct pnv_phb *phb = pe->phb;2313int idx;2314int64_t rc;23152316for (idx = 0; idx < phb->ioda.total_pe_num; idx++) {2317if (map[idx] != pe->pe_number)2318continue;23192320rc = opal_pci_map_pe_mmio_window(phb->opal_id,2321phb->ioda.reserved_pe_idx, win, 0, idx);23222323if (rc != OPAL_SUCCESS)2324pe_warn(pe, "Error %lld unmapping (%d) segment#%d\n",2325rc, win, idx);23262327map[idx] = IODA_INVALID_PE;2328}2329}23302331static void pnv_ioda_release_pe_seg(struct pnv_ioda_pe *pe)2332{2333struct pnv_phb *phb = pe->phb;23342335if (phb->type == PNV_PHB_IODA2) {2336pnv_ioda_free_pe_seg(pe, OPAL_M32_WINDOW_TYPE,2337phb->ioda.m32_segmap);2338}2339}23402341static void pnv_ioda_release_pe(struct pnv_ioda_pe *pe)2342{2343struct pnv_phb *phb = pe->phb;2344struct pnv_ioda_pe *slave, *tmp;23452346pe_info(pe, "Releasing PE\n");23472348mutex_lock(&phb->ioda.pe_list_mutex);2349list_del(&pe->list);2350mutex_unlock(&phb->ioda.pe_list_mutex);23512352switch (phb->type) {2353case PNV_PHB_IODA2:2354pnv_pci_ioda2_release_pe_dma(pe);2355break;2356case PNV_PHB_NPU_OCAPI:2357break;2358default:2359WARN_ON(1);2360}23612362pnv_ioda_release_pe_seg(pe);2363pnv_ioda_deconfigure_pe(pe->phb, pe);23642365/* Release slave PEs in the compound PE */2366if (pe->flags & PNV_IODA_PE_MASTER) {2367list_for_each_entry_safe(slave, tmp, &pe->slaves, list) {2368list_del(&slave->list);2369pnv_ioda_free_pe(slave);2370}2371}23722373/*2374* The PE for root bus can be removed because of hotplug in EEH2375* recovery for fenced PHB error. We need to mark the PE dead so2376* that it can be populated again in PCI hot add path. The PE2377* shouldn't be destroyed as it's the global reserved resource.2378*/2379if (phb->ioda.root_pe_idx == pe->pe_number)2380return;23812382pnv_ioda_free_pe(pe);2383}23842385static void pnv_pci_release_device(struct pci_dev *pdev)2386{2387struct pnv_phb *phb = pci_bus_to_pnvhb(pdev->bus);2388struct pci_dn *pdn = pci_get_pdn(pdev);2389struct pnv_ioda_pe *pe;23902391/* The VF PE state is torn down when sriov_disable() is called */2392if (pdev->is_virtfn)2393return;23942395if (!pdn || pdn->pe_number == IODA_INVALID_PE)2396return;23972398#ifdef CONFIG_PCI_IOV2399/*2400* FIXME: Try move this to sriov_disable(). It's here since we allocate2401* the iov state at probe time since we need to fiddle with the IOV2402* resources.2403*/2404if (pdev->is_physfn)2405kfree(pdev->dev.archdata.iov_data);2406#endif24072408/*2409* PCI hotplug can happen as part of EEH error recovery. The @pdn2410* isn't removed and added afterwards in this scenario. We should2411* set the PE number in @pdn to an invalid one. Otherwise, the PE's2412* device count is decreased on removing devices while failing to2413* be increased on adding devices. It leads to unbalanced PE's device2414* count and eventually make normal PCI hotplug path broken.2415*/2416pe = &phb->ioda.pe_array[pdn->pe_number];2417pdn->pe_number = IODA_INVALID_PE;24182419WARN_ON(--pe->device_count < 0);2420if (pe->device_count == 0)2421pnv_ioda_release_pe(pe);2422}24232424static void pnv_pci_ioda_shutdown(struct pci_controller *hose)2425{2426struct pnv_phb *phb = hose->private_data;24272428opal_pci_reset(phb->opal_id, OPAL_RESET_PCI_IODA_TABLE,2429OPAL_ASSERT_RESET);2430}24312432static void pnv_pci_ioda_dma_bus_setup(struct pci_bus *bus)2433{2434struct pnv_phb *phb = pci_bus_to_pnvhb(bus);2435struct pnv_ioda_pe *pe;24362437list_for_each_entry(pe, &phb->ioda.pe_list, list) {2438if (!(pe->flags & (PNV_IODA_PE_BUS | PNV_IODA_PE_BUS_ALL)))2439continue;24402441if (!pe->pbus)2442continue;24432444if (bus->number == ((pe->rid >> 8) & 0xFF)) {2445pe->pbus = bus;2446break;2447}2448}2449}24502451#ifdef CONFIG_IOMMU_API2452static struct iommu_group *pnv_pci_device_group(struct pci_controller *hose,2453struct pci_dev *pdev)2454{2455struct pnv_phb *phb = hose->private_data;2456struct pnv_ioda_pe *pe;24572458if (WARN_ON(!phb))2459return ERR_PTR(-ENODEV);24602461pe = pnv_pci_bdfn_to_pe(phb, pci_dev_id(pdev));2462if (!pe)2463return ERR_PTR(-ENODEV);24642465if (!pe->table_group.group)2466return ERR_PTR(-ENODEV);24672468return iommu_group_ref_get(pe->table_group.group);2469}2470#endif24712472static const struct pci_controller_ops pnv_pci_ioda_controller_ops = {2473.dma_dev_setup = pnv_pci_ioda_dma_dev_setup,2474.dma_bus_setup = pnv_pci_ioda_dma_bus_setup,2475.iommu_bypass_supported = pnv_pci_ioda_iommu_bypass_supported,2476.enable_device_hook = pnv_pci_enable_device_hook,2477.release_device = pnv_pci_release_device,2478.window_alignment = pnv_pci_window_alignment,2479.setup_bridge = pnv_pci_fixup_bridge_resources,2480.reset_secondary_bus = pnv_pci_reset_secondary_bus,2481.shutdown = pnv_pci_ioda_shutdown,2482#ifdef CONFIG_IOMMU_API2483.device_group = pnv_pci_device_group,2484#endif2485};24862487static const struct pci_controller_ops pnv_npu_ocapi_ioda_controller_ops = {2488.enable_device_hook = pnv_ocapi_enable_device_hook,2489.release_device = pnv_pci_release_device,2490.window_alignment = pnv_pci_window_alignment,2491.reset_secondary_bus = pnv_pci_reset_secondary_bus,2492.shutdown = pnv_pci_ioda_shutdown,2493};24942495static void __init pnv_pci_init_ioda_phb(struct device_node *np,2496u64 hub_id, int ioda_type)2497{2498struct pci_controller *hose;2499struct pnv_phb *phb;2500unsigned long size, m64map_off, m32map_off, pemap_off;2501struct pnv_ioda_pe *root_pe;2502struct resource r;2503const __be64 *prop64;2504const __be32 *prop32;2505int len;2506unsigned int segno;2507u64 phb_id;2508void *aux;2509long rc;25102511if (!of_device_is_available(np))2512return;25132514pr_info("Initializing %s PHB (%pOF)\n", pnv_phb_names[ioda_type], np);25152516prop64 = of_get_property(np, "ibm,opal-phbid", NULL);2517if (!prop64) {2518pr_err(" Missing \"ibm,opal-phbid\" property !\n");2519return;2520}2521phb_id = be64_to_cpup(prop64);2522pr_debug(" PHB-ID : 0x%016llx\n", phb_id);25232524phb = kzalloc(sizeof(*phb), GFP_KERNEL);2525if (!phb)2526panic("%s: Failed to allocate %zu bytes\n", __func__,2527sizeof(*phb));25282529/* Allocate PCI controller */2530phb->hose = hose = pcibios_alloc_controller(np);2531if (!phb->hose) {2532pr_err(" Can't allocate PCI controller for %pOF\n",2533np);2534memblock_free(phb, sizeof(struct pnv_phb));2535return;2536}25372538spin_lock_init(&phb->lock);2539prop32 = of_get_property(np, "bus-range", &len);2540if (prop32 && len == 8) {2541hose->first_busno = be32_to_cpu(prop32[0]);2542hose->last_busno = be32_to_cpu(prop32[1]);2543} else {2544pr_warn(" Broken <bus-range> on %pOF\n", np);2545hose->first_busno = 0;2546hose->last_busno = 0xff;2547}2548hose->private_data = phb;2549phb->hub_id = hub_id;2550phb->opal_id = phb_id;2551phb->type = ioda_type;2552mutex_init(&phb->ioda.pe_alloc_mutex);25532554/* Detect specific models for error handling */2555if (of_device_is_compatible(np, "ibm,p7ioc-pciex"))2556phb->model = PNV_PHB_MODEL_P7IOC;2557else if (of_device_is_compatible(np, "ibm,power8-pciex"))2558phb->model = PNV_PHB_MODEL_PHB3;2559else2560phb->model = PNV_PHB_MODEL_UNKNOWN;25612562/* Initialize diagnostic data buffer */2563prop32 = of_get_property(np, "ibm,phb-diag-data-size", NULL);2564if (prop32)2565phb->diag_data_size = be32_to_cpup(prop32);2566else2567phb->diag_data_size = PNV_PCI_DIAG_BUF_SIZE;25682569phb->diag_data = kzalloc(phb->diag_data_size, GFP_KERNEL);2570if (!phb->diag_data)2571panic("%s: Failed to allocate %u bytes\n", __func__,2572phb->diag_data_size);25732574/* Parse 32-bit and IO ranges (if any) */2575pci_process_bridge_OF_ranges(hose, np, !hose->global_number);25762577/* Get registers */2578if (!of_address_to_resource(np, 0, &r)) {2579phb->regs_phys = r.start;2580phb->regs = ioremap(r.start, resource_size(&r));2581if (phb->regs == NULL)2582pr_err(" Failed to map registers !\n");2583}25842585/* Initialize more IODA stuff */2586phb->ioda.total_pe_num = 1;2587prop32 = of_get_property(np, "ibm,opal-num-pes", NULL);2588if (prop32)2589phb->ioda.total_pe_num = be32_to_cpup(prop32);2590prop32 = of_get_property(np, "ibm,opal-reserved-pe", NULL);2591if (prop32)2592phb->ioda.reserved_pe_idx = be32_to_cpup(prop32);25932594/* Invalidate RID to PE# mapping */2595for (segno = 0; segno < ARRAY_SIZE(phb->ioda.pe_rmap); segno++)2596phb->ioda.pe_rmap[segno] = IODA_INVALID_PE;25972598/* Parse 64-bit MMIO range */2599pnv_ioda_parse_m64_window(phb);26002601phb->ioda.m32_size = resource_size(&hose->mem_resources[0]);2602/* FW Has already off top 64k of M32 space (MSI space) */2603phb->ioda.m32_size += 0x10000;26042605phb->ioda.m32_segsize = phb->ioda.m32_size / phb->ioda.total_pe_num;2606phb->ioda.m32_pci_base = hose->mem_resources[0].start - hose->mem_offset[0];2607phb->ioda.io_size = hose->pci_io_size;2608phb->ioda.io_segsize = phb->ioda.io_size / phb->ioda.total_pe_num;2609phb->ioda.io_pci_base = 0; /* XXX calculate this ? */26102611/* Allocate aux data & arrays. We don't have IO ports on PHB3 */2612size = ALIGN(max_t(unsigned, phb->ioda.total_pe_num, 8) / 8,2613sizeof(unsigned long));2614m64map_off = size;2615size += phb->ioda.total_pe_num * sizeof(phb->ioda.m64_segmap[0]);2616m32map_off = size;2617size += phb->ioda.total_pe_num * sizeof(phb->ioda.m32_segmap[0]);2618pemap_off = size;2619size += phb->ioda.total_pe_num * sizeof(struct pnv_ioda_pe);2620aux = kzalloc(size, GFP_KERNEL);2621if (!aux)2622panic("%s: Failed to allocate %lu bytes\n", __func__, size);26232624phb->ioda.pe_alloc = aux;2625phb->ioda.m64_segmap = aux + m64map_off;2626phb->ioda.m32_segmap = aux + m32map_off;2627for (segno = 0; segno < phb->ioda.total_pe_num; segno++) {2628phb->ioda.m64_segmap[segno] = IODA_INVALID_PE;2629phb->ioda.m32_segmap[segno] = IODA_INVALID_PE;2630}2631phb->ioda.pe_array = aux + pemap_off;26322633/*2634* Choose PE number for root bus, which shouldn't have2635* M64 resources consumed by its child devices. To pick2636* the PE number adjacent to the reserved one if possible.2637*/2638pnv_ioda_reserve_pe(phb, phb->ioda.reserved_pe_idx);2639if (phb->ioda.reserved_pe_idx == 0) {2640phb->ioda.root_pe_idx = 1;2641pnv_ioda_reserve_pe(phb, phb->ioda.root_pe_idx);2642} else if (phb->ioda.reserved_pe_idx == (phb->ioda.total_pe_num - 1)) {2643phb->ioda.root_pe_idx = phb->ioda.reserved_pe_idx - 1;2644pnv_ioda_reserve_pe(phb, phb->ioda.root_pe_idx);2645} else {2646/* otherwise just allocate one */2647root_pe = pnv_ioda_alloc_pe(phb, 1);2648phb->ioda.root_pe_idx = root_pe->pe_number;2649}26502651INIT_LIST_HEAD(&phb->ioda.pe_list);2652mutex_init(&phb->ioda.pe_list_mutex);26532654#if 0 /* We should really do that ... */2655rc = opal_pci_set_phb_mem_window(opal->phb_id,2656window_type,2657window_num,2658starting_real_address,2659starting_pci_address,2660segment_size);2661#endif26622663pr_info(" %03d (%03d) PE's M32: 0x%x [segment=0x%x]\n",2664phb->ioda.total_pe_num, phb->ioda.reserved_pe_idx,2665phb->ioda.m32_size, phb->ioda.m32_segsize);2666if (phb->ioda.m64_size)2667pr_info(" M64: 0x%lx [segment=0x%lx]\n",2668phb->ioda.m64_size, phb->ioda.m64_segsize);2669if (phb->ioda.io_size)2670pr_info(" IO: 0x%x [segment=0x%x]\n",2671phb->ioda.io_size, phb->ioda.io_segsize);267226732674phb->hose->ops = &pnv_pci_ops;2675phb->get_pe_state = pnv_ioda_get_pe_state;2676phb->freeze_pe = pnv_ioda_freeze_pe;2677phb->unfreeze_pe = pnv_ioda_unfreeze_pe;26782679/* Setup MSI support */2680pnv_pci_init_ioda_msis(phb);26812682/*2683* We pass the PCI probe flag PCI_REASSIGN_ALL_RSRC here2684* to let the PCI core do resource assignment. It's supposed2685* that the PCI core will do correct I/O and MMIO alignment2686* for the P2P bridge bars so that each PCI bus (excluding2687* the child P2P bridges) can form individual PE.2688*/2689ppc_md.pcibios_fixup = pnv_pci_ioda_fixup;26902691switch (phb->type) {2692case PNV_PHB_NPU_OCAPI:2693hose->controller_ops = pnv_npu_ocapi_ioda_controller_ops;2694break;2695default:2696hose->controller_ops = pnv_pci_ioda_controller_ops;2697}26982699ppc_md.pcibios_default_alignment = pnv_pci_default_alignment;27002701#ifdef CONFIG_PCI_IOV2702ppc_md.pcibios_fixup_sriov = pnv_pci_ioda_fixup_iov;2703ppc_md.pcibios_iov_resource_alignment = pnv_pci_iov_resource_alignment;2704ppc_md.pcibios_sriov_enable = pnv_pcibios_sriov_enable;2705ppc_md.pcibios_sriov_disable = pnv_pcibios_sriov_disable;2706#endif27072708pci_add_flags(PCI_REASSIGN_ALL_RSRC);27092710/* Reset IODA tables to a clean state */2711rc = opal_pci_reset(phb_id, OPAL_RESET_PCI_IODA_TABLE, OPAL_ASSERT_RESET);2712if (rc)2713pr_warn(" OPAL Error %ld performing IODA table reset !\n", rc);27142715/*2716* If we're running in kdump kernel, the previous kernel never2717* shutdown PCI devices correctly. We already got IODA table2718* cleaned out. So we have to issue PHB reset to stop all PCI2719* transactions from previous kernel. The ppc_pci_reset_phbs2720* kernel parameter will force this reset too. Additionally,2721* if the IODA reset above failed then use a bigger hammer.2722* This can happen if we get a PHB fatal error in very early2723* boot.2724*/2725if (is_kdump_kernel() || pci_reset_phbs || rc) {2726pr_info(" Issue PHB reset ...\n");2727pnv_eeh_phb_reset(hose, EEH_RESET_FUNDAMENTAL);2728pnv_eeh_phb_reset(hose, EEH_RESET_DEACTIVATE);2729}27302731/* Remove M64 resource if we can't configure it successfully */2732if (!phb->init_m64 || phb->init_m64(phb))2733hose->mem_resources[1].flags = 0;27342735/* create pci_dn's for DT nodes under this PHB */2736pci_devs_phb_init_dynamic(hose);2737}27382739void __init pnv_pci_init_ioda2_phb(struct device_node *np)2740{2741pnv_pci_init_ioda_phb(np, 0, PNV_PHB_IODA2);2742}27432744void __init pnv_pci_init_npu2_opencapi_phb(struct device_node *np)2745{2746pnv_pci_init_ioda_phb(np, 0, PNV_PHB_NPU_OCAPI);2747}27482749static void pnv_npu2_opencapi_cfg_size_fixup(struct pci_dev *dev)2750{2751struct pnv_phb *phb = pci_bus_to_pnvhb(dev->bus);27522753if (!machine_is(powernv))2754return;27552756if (phb->type == PNV_PHB_NPU_OCAPI)2757dev->cfg_size = PCI_CFG_SPACE_EXP_SIZE;2758}2759DECLARE_PCI_FIXUP_EARLY(PCI_ANY_ID, PCI_ANY_ID, pnv_npu2_opencapi_cfg_size_fixup);276027612762