Skip to content

Commit fd141d1

Browse files
ozbenhmpe
authored andcommitted
powerpc/powernv/pci: Rework accessing the TCE invalidate register
It's architected, always in a known place, so there is no need to keep a separate pointer to it, we use the existing "regs", and we complement it with a real mode variant. Signed-off-by: Benjamin Herrenschmidt <[email protected]> # Conflicts: # arch/powerpc/platforms/powernv/pci-ioda.c # arch/powerpc/platforms/powernv/pci.h Signed-off-by: Michael Ellerman <[email protected]>
1 parent 08acce1 commit fd141d1

File tree

2 files changed

+28
-48
lines changed

2 files changed

+28
-48
lines changed

arch/powerpc/platforms/powernv/pci-ioda.c

Lines changed: 27 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1721,6 +1721,13 @@ static void pnv_ioda_setup_bus_dma(struct pnv_ioda_pe *pe,
17211721
}
17221722
}
17231723

1724+
static inline __be64 __iomem *pnv_ioda_get_inval_reg(struct pnv_phb *phb,
1725+
bool real_mode)
1726+
{
1727+
return real_mode ? (__be64 __iomem *)(phb->regs_phys + 0x210) :
1728+
(phb->regs + 0x210);
1729+
}
1730+
17241731
static void pnv_pci_p7ioc_tce_invalidate(struct iommu_table *tbl,
17251732
unsigned long index, unsigned long npages, bool rm)
17261733
{
@@ -1729,9 +1736,7 @@ static void pnv_pci_p7ioc_tce_invalidate(struct iommu_table *tbl,
17291736
next);
17301737
struct pnv_ioda_pe *pe = container_of(tgl->table_group,
17311738
struct pnv_ioda_pe, table_group);
1732-
__be64 __iomem *invalidate = rm ?
1733-
(__be64 __iomem *)pe->phb->ioda.tce_inval_reg_phys :
1734-
pe->phb->ioda.tce_inval_reg;
1739+
__be64 __iomem *invalidate = pnv_ioda_get_inval_reg(pe->phb, rm);
17351740
unsigned long start, end, inc;
17361741

17371742
start = __pa(((__be64 *)tbl->it_base) + index - tbl->it_offset);
@@ -1809,39 +1814,36 @@ static struct iommu_table_ops pnv_ioda1_iommu_ops = {
18091814

18101815
void pnv_pci_phb3_tce_invalidate_entire(struct pnv_phb *phb, bool rm)
18111816
{
1817+
__be64 __iomem *invalidate = pnv_ioda_get_inval_reg(phb, rm);
18121818
const unsigned long val = PHB3_TCE_KILL_INVAL_ALL;
18131819

18141820
mb(); /* Ensure previous TCE table stores are visible */
18151821
if (rm)
1816-
__raw_rm_writeq(cpu_to_be64(val),
1817-
(__be64 __iomem *)
1818-
phb->ioda.tce_inval_reg_phys);
1822+
__raw_rm_writeq(cpu_to_be64(val), invalidate);
18191823
else
1820-
__raw_writeq(cpu_to_be64(val), phb->ioda.tce_inval_reg);
1824+
__raw_writeq(cpu_to_be64(val), invalidate);
18211825
}
18221826

18231827
static inline void pnv_pci_phb3_tce_invalidate_pe(struct pnv_ioda_pe *pe)
18241828
{
18251829
/* 01xb - invalidate TCEs that match the specified PE# */
1830+
__be64 __iomem *invalidate = pnv_ioda_get_inval_reg(pe->phb, false);
18261831
unsigned long val = PHB3_TCE_KILL_INVAL_PE | (pe->pe_number & 0xFF);
1827-
struct pnv_phb *phb = pe->phb;
1828-
1829-
if (!phb->ioda.tce_inval_reg)
1830-
return;
18311832

18321833
mb(); /* Ensure above stores are visible */
1833-
__raw_writeq(cpu_to_be64(val), phb->ioda.tce_inval_reg);
1834+
__raw_writeq(cpu_to_be64(val), invalidate);
18341835
}
18351836

1836-
static void pnv_pci_phb3_tce_invalidate(unsigned pe_number, bool rm,
1837-
__be64 __iomem *invalidate, unsigned shift,
1838-
unsigned long index, unsigned long npages)
1837+
static void pnv_pci_phb3_tce_invalidate(struct pnv_ioda_pe *pe, bool rm,
1838+
unsigned shift, unsigned long index,
1839+
unsigned long npages)
18391840
{
1841+
__be64 __iomem *invalidate = pnv_ioda_get_inval_reg(pe->phb, false);
18401842
unsigned long start, end, inc;
18411843

18421844
/* We'll invalidate DMA address in PE scope */
18431845
start = PHB3_TCE_KILL_INVAL_ONE;
1844-
start |= (pe_number & 0xFF);
1846+
start |= (pe->pe_number & 0xFF);
18451847
end = start;
18461848

18471849
/* Figure out the start, end and step */
@@ -1867,10 +1869,6 @@ static void pnv_pci_ioda2_tce_invalidate(struct iommu_table *tbl,
18671869
list_for_each_entry_rcu(tgl, &tbl->it_group_list, next) {
18681870
struct pnv_ioda_pe *pe = container_of(tgl->table_group,
18691871
struct pnv_ioda_pe, table_group);
1870-
__be64 __iomem *invalidate = rm ?
1871-
(__be64 __iomem *)pe->phb->ioda.tce_inval_reg_phys :
1872-
pe->phb->ioda.tce_inval_reg;
1873-
18741872
if (pe->phb->type == PNV_PHB_NPU) {
18751873
/*
18761874
* The NVLink hardware does not support TCE kill
@@ -1880,9 +1878,8 @@ static void pnv_pci_ioda2_tce_invalidate(struct iommu_table *tbl,
18801878
pnv_pci_phb3_tce_invalidate_entire(pe->phb, rm);
18811879
continue;
18821880
}
1883-
pnv_pci_phb3_tce_invalidate(pe->pe_number, rm,
1884-
invalidate, tbl->it_page_shift,
1885-
index, npages);
1881+
pnv_pci_phb3_tce_invalidate(pe, rm, tbl->it_page_shift,
1882+
index, npages);
18861883
}
18871884
}
18881885

@@ -2467,19 +2464,6 @@ static void pnv_pci_ioda_setup_iommu_api(void)
24672464
static void pnv_pci_ioda_setup_iommu_api(void) { };
24682465
#endif
24692466

2470-
static void pnv_pci_ioda_setup_opal_tce_kill(struct pnv_phb *phb)
2471-
{
2472-
const __be64 *swinvp;
2473-
2474-
/* OPAL variant of PHB3 invalidated TCEs */
2475-
swinvp = of_get_property(phb->hose->dn, "ibm,opal-tce-kill", NULL);
2476-
if (!swinvp)
2477-
return;
2478-
2479-
phb->ioda.tce_inval_reg_phys = be64_to_cpup(swinvp);
2480-
phb->ioda.tce_inval_reg = ioremap(phb->ioda.tce_inval_reg_phys, 8);
2481-
}
2482-
24832467
static __be64 *pnv_pci_ioda2_table_do_alloc_pages(int nid, unsigned shift,
24842468
unsigned levels, unsigned long limit,
24852469
unsigned long *current_offset, unsigned long *total_allocated)
@@ -3459,6 +3443,7 @@ static void __init pnv_pci_init_ioda_phb(struct device_node *np,
34593443
struct pnv_phb *phb;
34603444
unsigned long size, m64map_off, m32map_off, pemap_off;
34613445
unsigned long iomap_off = 0, dma32map_off = 0;
3446+
struct resource r;
34623447
const __be64 *prop64;
34633448
const __be32 *prop32;
34643449
int len;
@@ -3519,12 +3504,12 @@ static void __init pnv_pci_init_ioda_phb(struct device_node *np,
35193504
pci_process_bridge_OF_ranges(hose, np, !hose->global_number);
35203505

35213506
/* Get registers */
3522-
phb->regs = of_iomap(np, 0);
3523-
if (phb->regs == NULL)
3524-
pr_err(" Failed to map registers !\n");
3525-
3526-
/* Initialize TCE kill register */
3527-
pnv_pci_ioda_setup_opal_tce_kill(phb);
3507+
if (!of_address_to_resource(np, 0, &r)) {
3508+
phb->regs_phys = r.start;
3509+
phb->regs = ioremap(r.start, resource_size(&r));
3510+
if (phb->regs == NULL)
3511+
pr_err(" Failed to map registers !\n");
3512+
}
35283513

35293514
/* Initialize more IODA stuff */
35303515
phb->ioda.total_pe_num = 1;

arch/powerpc/platforms/powernv/pci.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ struct pnv_phb {
8686
u64 opal_id;
8787
int flags;
8888
void __iomem *regs;
89+
u64 regs_phys;
8990
int initialized;
9091
spinlock_t lock;
9192

@@ -162,12 +163,6 @@ struct pnv_phb {
162163

163164
/* Reverse map of PEs, indexed by {bus, devfn} */
164165
unsigned int pe_rmap[0x10000];
165-
166-
/* TCE cache invalidate registers (physical and
167-
* remapped)
168-
*/
169-
phys_addr_t tce_inval_reg_phys;
170-
__be64 __iomem *tce_inval_reg;
171166
} ioda;
172167

173168
/* PHB and hub status structure */

0 commit comments

Comments
 (0)