18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci#ifndef __POWERNV_PCI_H
38c2ecf20Sopenharmony_ci#define __POWERNV_PCI_H
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci#include <linux/compiler.h>		/* for __printf */
68c2ecf20Sopenharmony_ci#include <linux/iommu.h>
78c2ecf20Sopenharmony_ci#include <asm/iommu.h>
88c2ecf20Sopenharmony_ci#include <asm/msi_bitmap.h>
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_cistruct pci_dn;
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_cienum pnv_phb_type {
138c2ecf20Sopenharmony_ci	PNV_PHB_IODA1		= 0,
148c2ecf20Sopenharmony_ci	PNV_PHB_IODA2		= 1,
158c2ecf20Sopenharmony_ci	PNV_PHB_NPU_NVLINK	= 2,
168c2ecf20Sopenharmony_ci	PNV_PHB_NPU_OCAPI	= 3,
178c2ecf20Sopenharmony_ci};
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci/* Precise PHB model for error management */
208c2ecf20Sopenharmony_cienum pnv_phb_model {
218c2ecf20Sopenharmony_ci	PNV_PHB_MODEL_UNKNOWN,
228c2ecf20Sopenharmony_ci	PNV_PHB_MODEL_P7IOC,
238c2ecf20Sopenharmony_ci	PNV_PHB_MODEL_PHB3,
248c2ecf20Sopenharmony_ci	PNV_PHB_MODEL_NPU,
258c2ecf20Sopenharmony_ci	PNV_PHB_MODEL_NPU2,
268c2ecf20Sopenharmony_ci};
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci#define PNV_PCI_DIAG_BUF_SIZE	8192
298c2ecf20Sopenharmony_ci#define PNV_IODA_PE_DEV		(1 << 0)	/* PE has single PCI device	*/
308c2ecf20Sopenharmony_ci#define PNV_IODA_PE_BUS		(1 << 1)	/* PE has primary PCI bus	*/
318c2ecf20Sopenharmony_ci#define PNV_IODA_PE_BUS_ALL	(1 << 2)	/* PE has subordinate buses	*/
328c2ecf20Sopenharmony_ci#define PNV_IODA_PE_MASTER	(1 << 3)	/* Master PE in compound case	*/
338c2ecf20Sopenharmony_ci#define PNV_IODA_PE_SLAVE	(1 << 4)	/* Slave PE in compound case	*/
348c2ecf20Sopenharmony_ci#define PNV_IODA_PE_VF		(1 << 5)	/* PE for one VF 		*/
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci/*
378c2ecf20Sopenharmony_ci * A brief note on PNV_IODA_PE_BUS_ALL
388c2ecf20Sopenharmony_ci *
398c2ecf20Sopenharmony_ci * This is needed because of the behaviour of PCIe-to-PCI bridges. The PHB uses
408c2ecf20Sopenharmony_ci * the Requester ID field of the PCIe request header to determine the device
418c2ecf20Sopenharmony_ci * (and PE) that initiated a DMA. In legacy PCI individual memory read/write
428c2ecf20Sopenharmony_ci * requests aren't tagged with the RID. To work around this the PCIe-to-PCI
438c2ecf20Sopenharmony_ci * bridge will use (secondary_bus_no << 8) | 0x00 as the RID on the PCIe side.
448c2ecf20Sopenharmony_ci *
458c2ecf20Sopenharmony_ci * PCIe-to-X bridges have a similar issue even though PCI-X requests also have
468c2ecf20Sopenharmony_ci * a RID in the transaction header. The PCIe-to-X bridge is permitted to "take
478c2ecf20Sopenharmony_ci * ownership" of a transaction by a PCI-X device when forwarding it to the PCIe
488c2ecf20Sopenharmony_ci * side of the bridge.
498c2ecf20Sopenharmony_ci *
508c2ecf20Sopenharmony_ci * To work around these problems we use the BUS_ALL flag since every subordinate
518c2ecf20Sopenharmony_ci * bus of the bridge should go into the same PE.
528c2ecf20Sopenharmony_ci */
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_ci/* Indicates operations are frozen for a PE: MMIO in PESTA & DMA in PESTB. */
558c2ecf20Sopenharmony_ci#define PNV_IODA_STOPPED_STATE	0x8000000000000000
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ci/* Data associated with a PE, including IOMMU tracking etc.. */
588c2ecf20Sopenharmony_cistruct pnv_phb;
598c2ecf20Sopenharmony_cistruct pnv_ioda_pe {
608c2ecf20Sopenharmony_ci	unsigned long		flags;
618c2ecf20Sopenharmony_ci	struct pnv_phb		*phb;
628c2ecf20Sopenharmony_ci	int			device_count;
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_ci	/* A PE can be associated with a single device or an
658c2ecf20Sopenharmony_ci	 * entire bus (& children). In the former case, pdev
668c2ecf20Sopenharmony_ci	 * is populated, in the later case, pbus is.
678c2ecf20Sopenharmony_ci	 */
688c2ecf20Sopenharmony_ci#ifdef CONFIG_PCI_IOV
698c2ecf20Sopenharmony_ci	struct pci_dev          *parent_dev;
708c2ecf20Sopenharmony_ci#endif
718c2ecf20Sopenharmony_ci	struct pci_dev		*pdev;
728c2ecf20Sopenharmony_ci	struct pci_bus		*pbus;
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci	/* Effective RID (device RID for a device PE and base bus
758c2ecf20Sopenharmony_ci	 * RID with devfn 0 for a bus PE)
768c2ecf20Sopenharmony_ci	 */
778c2ecf20Sopenharmony_ci	unsigned int		rid;
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ci	/* PE number */
808c2ecf20Sopenharmony_ci	unsigned int		pe_number;
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_ci	/* "Base" iommu table, ie, 4K TCEs, 32-bit DMA */
838c2ecf20Sopenharmony_ci	struct iommu_table_group table_group;
848c2ecf20Sopenharmony_ci	struct npu_comp		*npucomp;
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ci	/* 64-bit TCE bypass region */
878c2ecf20Sopenharmony_ci	bool			tce_bypass_enabled;
888c2ecf20Sopenharmony_ci	uint64_t		tce_bypass_base;
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_ci	/*
918c2ecf20Sopenharmony_ci	 * Used to track whether we've done DMA setup for this PE or not. We
928c2ecf20Sopenharmony_ci	 * want to defer allocating TCE tables, etc until we've added a
938c2ecf20Sopenharmony_ci	 * non-bridge device to the PE.
948c2ecf20Sopenharmony_ci	 */
958c2ecf20Sopenharmony_ci	bool			dma_setup_done;
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ci	/* MSIs. MVE index is identical for 32 and 64 bit MSI
988c2ecf20Sopenharmony_ci	 * and -1 if not supported. (It's actually identical to the
998c2ecf20Sopenharmony_ci	 * PE number)
1008c2ecf20Sopenharmony_ci	 */
1018c2ecf20Sopenharmony_ci	int			mve_number;
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_ci	/* PEs in compound case */
1048c2ecf20Sopenharmony_ci	struct pnv_ioda_pe	*master;
1058c2ecf20Sopenharmony_ci	struct list_head	slaves;
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_ci	/* Link in list of PE#s */
1088c2ecf20Sopenharmony_ci	struct list_head	list;
1098c2ecf20Sopenharmony_ci};
1108c2ecf20Sopenharmony_ci
1118c2ecf20Sopenharmony_ci#define PNV_PHB_FLAG_EEH	(1 << 0)
1128c2ecf20Sopenharmony_ci
1138c2ecf20Sopenharmony_cistruct pnv_phb {
1148c2ecf20Sopenharmony_ci	struct pci_controller	*hose;
1158c2ecf20Sopenharmony_ci	enum pnv_phb_type	type;
1168c2ecf20Sopenharmony_ci	enum pnv_phb_model	model;
1178c2ecf20Sopenharmony_ci	u64			hub_id;
1188c2ecf20Sopenharmony_ci	u64			opal_id;
1198c2ecf20Sopenharmony_ci	int			flags;
1208c2ecf20Sopenharmony_ci	void __iomem		*regs;
1218c2ecf20Sopenharmony_ci	u64			regs_phys;
1228c2ecf20Sopenharmony_ci	int			initialized;
1238c2ecf20Sopenharmony_ci	spinlock_t		lock;
1248c2ecf20Sopenharmony_ci
1258c2ecf20Sopenharmony_ci#ifdef CONFIG_DEBUG_FS
1268c2ecf20Sopenharmony_ci	int			has_dbgfs;
1278c2ecf20Sopenharmony_ci	struct dentry		*dbgfs;
1288c2ecf20Sopenharmony_ci#endif
1298c2ecf20Sopenharmony_ci
1308c2ecf20Sopenharmony_ci	unsigned int		msi_base;
1318c2ecf20Sopenharmony_ci	unsigned int		msi32_support;
1328c2ecf20Sopenharmony_ci	struct msi_bitmap	msi_bmp;
1338c2ecf20Sopenharmony_ci	int (*msi_setup)(struct pnv_phb *phb, struct pci_dev *dev,
1348c2ecf20Sopenharmony_ci			 unsigned int hwirq, unsigned int virq,
1358c2ecf20Sopenharmony_ci			 unsigned int is_64, struct msi_msg *msg);
1368c2ecf20Sopenharmony_ci	int (*init_m64)(struct pnv_phb *phb);
1378c2ecf20Sopenharmony_ci	int (*get_pe_state)(struct pnv_phb *phb, int pe_no);
1388c2ecf20Sopenharmony_ci	void (*freeze_pe)(struct pnv_phb *phb, int pe_no);
1398c2ecf20Sopenharmony_ci	int (*unfreeze_pe)(struct pnv_phb *phb, int pe_no, int opt);
1408c2ecf20Sopenharmony_ci
1418c2ecf20Sopenharmony_ci	struct {
1428c2ecf20Sopenharmony_ci		/* Global bridge info */
1438c2ecf20Sopenharmony_ci		unsigned int		total_pe_num;
1448c2ecf20Sopenharmony_ci		unsigned int		reserved_pe_idx;
1458c2ecf20Sopenharmony_ci		unsigned int		root_pe_idx;
1468c2ecf20Sopenharmony_ci
1478c2ecf20Sopenharmony_ci		/* 32-bit MMIO window */
1488c2ecf20Sopenharmony_ci		unsigned int		m32_size;
1498c2ecf20Sopenharmony_ci		unsigned int		m32_segsize;
1508c2ecf20Sopenharmony_ci		unsigned int		m32_pci_base;
1518c2ecf20Sopenharmony_ci
1528c2ecf20Sopenharmony_ci		/* 64-bit MMIO window */
1538c2ecf20Sopenharmony_ci		unsigned int		m64_bar_idx;
1548c2ecf20Sopenharmony_ci		unsigned long		m64_size;
1558c2ecf20Sopenharmony_ci		unsigned long		m64_segsize;
1568c2ecf20Sopenharmony_ci		unsigned long		m64_base;
1578c2ecf20Sopenharmony_ci#define MAX_M64_BARS 64
1588c2ecf20Sopenharmony_ci		unsigned long		m64_bar_alloc;
1598c2ecf20Sopenharmony_ci
1608c2ecf20Sopenharmony_ci		/* IO ports */
1618c2ecf20Sopenharmony_ci		unsigned int		io_size;
1628c2ecf20Sopenharmony_ci		unsigned int		io_segsize;
1638c2ecf20Sopenharmony_ci		unsigned int		io_pci_base;
1648c2ecf20Sopenharmony_ci
1658c2ecf20Sopenharmony_ci		/* PE allocation */
1668c2ecf20Sopenharmony_ci		struct mutex		pe_alloc_mutex;
1678c2ecf20Sopenharmony_ci		unsigned long		*pe_alloc;
1688c2ecf20Sopenharmony_ci		struct pnv_ioda_pe	*pe_array;
1698c2ecf20Sopenharmony_ci
1708c2ecf20Sopenharmony_ci		/* M32 & IO segment maps */
1718c2ecf20Sopenharmony_ci		unsigned int		*m64_segmap;
1728c2ecf20Sopenharmony_ci		unsigned int		*m32_segmap;
1738c2ecf20Sopenharmony_ci		unsigned int		*io_segmap;
1748c2ecf20Sopenharmony_ci
1758c2ecf20Sopenharmony_ci		/* DMA32 segment maps - IODA1 only */
1768c2ecf20Sopenharmony_ci		unsigned int		dma32_count;
1778c2ecf20Sopenharmony_ci		unsigned int		*dma32_segmap;
1788c2ecf20Sopenharmony_ci
1798c2ecf20Sopenharmony_ci		/* IRQ chip */
1808c2ecf20Sopenharmony_ci		int			irq_chip_init;
1818c2ecf20Sopenharmony_ci		struct irq_chip		irq_chip;
1828c2ecf20Sopenharmony_ci
1838c2ecf20Sopenharmony_ci		/* Sorted list of used PE's based
1848c2ecf20Sopenharmony_ci		 * on the sequence of creation
1858c2ecf20Sopenharmony_ci		 */
1868c2ecf20Sopenharmony_ci		struct list_head	pe_list;
1878c2ecf20Sopenharmony_ci		struct mutex            pe_list_mutex;
1888c2ecf20Sopenharmony_ci
1898c2ecf20Sopenharmony_ci		/* Reverse map of PEs, indexed by {bus, devfn} */
1908c2ecf20Sopenharmony_ci		unsigned int		pe_rmap[0x10000];
1918c2ecf20Sopenharmony_ci	} ioda;
1928c2ecf20Sopenharmony_ci
1938c2ecf20Sopenharmony_ci	/* PHB and hub diagnostics */
1948c2ecf20Sopenharmony_ci	unsigned int		diag_data_size;
1958c2ecf20Sopenharmony_ci	u8			*diag_data;
1968c2ecf20Sopenharmony_ci};
1978c2ecf20Sopenharmony_ci
1988c2ecf20Sopenharmony_ci
1998c2ecf20Sopenharmony_ci/* IODA PE management */
2008c2ecf20Sopenharmony_ci
2018c2ecf20Sopenharmony_cistatic inline bool pnv_pci_is_m64(struct pnv_phb *phb, struct resource *r)
2028c2ecf20Sopenharmony_ci{
2038c2ecf20Sopenharmony_ci	/*
2048c2ecf20Sopenharmony_ci	 * WARNING: We cannot rely on the resource flags. The Linux PCI
2058c2ecf20Sopenharmony_ci	 * allocation code sometimes decides to put a 64-bit prefetchable
2068c2ecf20Sopenharmony_ci	 * BAR in the 32-bit window, so we have to compare the addresses.
2078c2ecf20Sopenharmony_ci	 *
2088c2ecf20Sopenharmony_ci	 * For simplicity we only test resource start.
2098c2ecf20Sopenharmony_ci	 */
2108c2ecf20Sopenharmony_ci	return (r->start >= phb->ioda.m64_base &&
2118c2ecf20Sopenharmony_ci		r->start < (phb->ioda.m64_base + phb->ioda.m64_size));
2128c2ecf20Sopenharmony_ci}
2138c2ecf20Sopenharmony_ci
2148c2ecf20Sopenharmony_cistatic inline bool pnv_pci_is_m64_flags(unsigned long resource_flags)
2158c2ecf20Sopenharmony_ci{
2168c2ecf20Sopenharmony_ci	unsigned long flags = (IORESOURCE_MEM_64 | IORESOURCE_PREFETCH);
2178c2ecf20Sopenharmony_ci
2188c2ecf20Sopenharmony_ci	return (resource_flags & flags) == flags;
2198c2ecf20Sopenharmony_ci}
2208c2ecf20Sopenharmony_ci
2218c2ecf20Sopenharmony_ciint pnv_ioda_configure_pe(struct pnv_phb *phb, struct pnv_ioda_pe *pe);
2228c2ecf20Sopenharmony_ciint pnv_ioda_deconfigure_pe(struct pnv_phb *phb, struct pnv_ioda_pe *pe);
2238c2ecf20Sopenharmony_ci
2248c2ecf20Sopenharmony_civoid pnv_pci_ioda2_setup_dma_pe(struct pnv_phb *phb, struct pnv_ioda_pe *pe);
2258c2ecf20Sopenharmony_civoid pnv_pci_ioda2_release_pe_dma(struct pnv_ioda_pe *pe);
2268c2ecf20Sopenharmony_ci
2278c2ecf20Sopenharmony_cistruct pnv_ioda_pe *pnv_ioda_alloc_pe(struct pnv_phb *phb, int count);
2288c2ecf20Sopenharmony_civoid pnv_ioda_free_pe(struct pnv_ioda_pe *pe);
2298c2ecf20Sopenharmony_ci
2308c2ecf20Sopenharmony_ci#ifdef CONFIG_PCI_IOV
2318c2ecf20Sopenharmony_ci/*
2328c2ecf20Sopenharmony_ci * For SR-IOV we want to put each VF's MMIO resource in to a separate PE.
2338c2ecf20Sopenharmony_ci * This requires a bit of acrobatics with the MMIO -> PE configuration
2348c2ecf20Sopenharmony_ci * and this structure is used to keep track of it all.
2358c2ecf20Sopenharmony_ci */
2368c2ecf20Sopenharmony_cistruct pnv_iov_data {
2378c2ecf20Sopenharmony_ci	/* number of VFs enabled */
2388c2ecf20Sopenharmony_ci	u16     num_vfs;
2398c2ecf20Sopenharmony_ci
2408c2ecf20Sopenharmony_ci	/* pointer to the array of VF PEs. num_vfs long*/
2418c2ecf20Sopenharmony_ci	struct pnv_ioda_pe *vf_pe_arr;
2428c2ecf20Sopenharmony_ci
2438c2ecf20Sopenharmony_ci	/* Did we map the VF BAR with single-PE IODA BARs? */
2448c2ecf20Sopenharmony_ci	bool    m64_single_mode[PCI_SRIOV_NUM_BARS];
2458c2ecf20Sopenharmony_ci
2468c2ecf20Sopenharmony_ci	/*
2478c2ecf20Sopenharmony_ci	 * True if we're using any segmented windows. In that case we need
2488c2ecf20Sopenharmony_ci	 * shift the start of the IOV resource the segment corresponding to
2498c2ecf20Sopenharmony_ci	 * the allocated PE.
2508c2ecf20Sopenharmony_ci	 */
2518c2ecf20Sopenharmony_ci	bool    need_shift;
2528c2ecf20Sopenharmony_ci
2538c2ecf20Sopenharmony_ci	/*
2548c2ecf20Sopenharmony_ci	 * Bit mask used to track which m64 windows are used to map the
2558c2ecf20Sopenharmony_ci	 * SR-IOV BARs for this device.
2568c2ecf20Sopenharmony_ci	 */
2578c2ecf20Sopenharmony_ci	DECLARE_BITMAP(used_m64_bar_mask, MAX_M64_BARS);
2588c2ecf20Sopenharmony_ci
2598c2ecf20Sopenharmony_ci	/*
2608c2ecf20Sopenharmony_ci	 * If we map the SR-IOV BARs with a segmented window then
2618c2ecf20Sopenharmony_ci	 * parts of that window will be "claimed" by other PEs.
2628c2ecf20Sopenharmony_ci	 *
2638c2ecf20Sopenharmony_ci	 * "holes" here is used to reserve the leading portion
2648c2ecf20Sopenharmony_ci	 * of the window that is used by other (non VF) PEs.
2658c2ecf20Sopenharmony_ci	 */
2668c2ecf20Sopenharmony_ci	struct resource holes[PCI_SRIOV_NUM_BARS];
2678c2ecf20Sopenharmony_ci};
2688c2ecf20Sopenharmony_ci
2698c2ecf20Sopenharmony_cistatic inline struct pnv_iov_data *pnv_iov_get(struct pci_dev *pdev)
2708c2ecf20Sopenharmony_ci{
2718c2ecf20Sopenharmony_ci	return pdev->dev.archdata.iov_data;
2728c2ecf20Sopenharmony_ci}
2738c2ecf20Sopenharmony_ci
2748c2ecf20Sopenharmony_civoid pnv_pci_ioda_fixup_iov(struct pci_dev *pdev);
2758c2ecf20Sopenharmony_ciresource_size_t pnv_pci_iov_resource_alignment(struct pci_dev *pdev, int resno);
2768c2ecf20Sopenharmony_ci
2778c2ecf20Sopenharmony_ciint pnv_pcibios_sriov_enable(struct pci_dev *pdev, u16 num_vfs);
2788c2ecf20Sopenharmony_ciint pnv_pcibios_sriov_disable(struct pci_dev *pdev);
2798c2ecf20Sopenharmony_ci#endif /* CONFIG_PCI_IOV */
2808c2ecf20Sopenharmony_ci
2818c2ecf20Sopenharmony_ciextern struct pci_ops pnv_pci_ops;
2828c2ecf20Sopenharmony_ci
2838c2ecf20Sopenharmony_civoid pnv_pci_dump_phb_diag_data(struct pci_controller *hose,
2848c2ecf20Sopenharmony_ci				unsigned char *log_buff);
2858c2ecf20Sopenharmony_ciint pnv_pci_cfg_read(struct pci_dn *pdn,
2868c2ecf20Sopenharmony_ci		     int where, int size, u32 *val);
2878c2ecf20Sopenharmony_ciint pnv_pci_cfg_write(struct pci_dn *pdn,
2888c2ecf20Sopenharmony_ci		      int where, int size, u32 val);
2898c2ecf20Sopenharmony_ciextern struct iommu_table *pnv_pci_table_alloc(int nid);
2908c2ecf20Sopenharmony_ci
2918c2ecf20Sopenharmony_ciextern void pnv_pci_init_ioda_hub(struct device_node *np);
2928c2ecf20Sopenharmony_ciextern void pnv_pci_init_ioda2_phb(struct device_node *np);
2938c2ecf20Sopenharmony_ciextern void pnv_pci_init_npu_phb(struct device_node *np);
2948c2ecf20Sopenharmony_ciextern void pnv_pci_init_npu2_opencapi_phb(struct device_node *np);
2958c2ecf20Sopenharmony_ciextern void pnv_npu2_map_lpar(struct pnv_ioda_pe *gpe, unsigned long msr);
2968c2ecf20Sopenharmony_ciextern void pnv_pci_reset_secondary_bus(struct pci_dev *dev);
2978c2ecf20Sopenharmony_ciextern int pnv_eeh_phb_reset(struct pci_controller *hose, int option);
2988c2ecf20Sopenharmony_ci
2998c2ecf20Sopenharmony_ciextern int pnv_setup_msi_irqs(struct pci_dev *pdev, int nvec, int type);
3008c2ecf20Sopenharmony_ciextern void pnv_teardown_msi_irqs(struct pci_dev *pdev);
3018c2ecf20Sopenharmony_ciextern struct pnv_ioda_pe *pnv_pci_bdfn_to_pe(struct pnv_phb *phb, u16 bdfn);
3028c2ecf20Sopenharmony_ciextern struct pnv_ioda_pe *pnv_ioda_get_pe(struct pci_dev *dev);
3038c2ecf20Sopenharmony_ciextern void pnv_set_msi_irq_chip(struct pnv_phb *phb, unsigned int virq);
3048c2ecf20Sopenharmony_ciextern unsigned long pnv_pci_ioda2_get_table_size(__u32 page_shift,
3058c2ecf20Sopenharmony_ci		__u64 window_size, __u32 levels);
3068c2ecf20Sopenharmony_ciextern int pnv_eeh_post_init(void);
3078c2ecf20Sopenharmony_ci
3088c2ecf20Sopenharmony_ci__printf(3, 4)
3098c2ecf20Sopenharmony_ciextern void pe_level_printk(const struct pnv_ioda_pe *pe, const char *level,
3108c2ecf20Sopenharmony_ci			    const char *fmt, ...);
3118c2ecf20Sopenharmony_ci#define pe_err(pe, fmt, ...)					\
3128c2ecf20Sopenharmony_ci	pe_level_printk(pe, KERN_ERR, fmt, ##__VA_ARGS__)
3138c2ecf20Sopenharmony_ci#define pe_warn(pe, fmt, ...)					\
3148c2ecf20Sopenharmony_ci	pe_level_printk(pe, KERN_WARNING, fmt, ##__VA_ARGS__)
3158c2ecf20Sopenharmony_ci#define pe_info(pe, fmt, ...)					\
3168c2ecf20Sopenharmony_ci	pe_level_printk(pe, KERN_INFO, fmt, ##__VA_ARGS__)
3178c2ecf20Sopenharmony_ci
3188c2ecf20Sopenharmony_ci/* Nvlink functions */
3198c2ecf20Sopenharmony_ciextern void pnv_npu_try_dma_set_bypass(struct pci_dev *gpdev, bool bypass);
3208c2ecf20Sopenharmony_ciextern void pnv_pci_ioda2_tce_invalidate_entire(struct pnv_phb *phb, bool rm);
3218c2ecf20Sopenharmony_ciextern void pnv_pci_npu_setup_iommu_groups(void);
3228c2ecf20Sopenharmony_ci
3238c2ecf20Sopenharmony_ci/* pci-ioda-tce.c */
3248c2ecf20Sopenharmony_ci#define POWERNV_IOMMU_DEFAULT_LEVELS	2
3258c2ecf20Sopenharmony_ci#define POWERNV_IOMMU_MAX_LEVELS	5
3268c2ecf20Sopenharmony_ci
3278c2ecf20Sopenharmony_ciextern int pnv_tce_build(struct iommu_table *tbl, long index, long npages,
3288c2ecf20Sopenharmony_ci		unsigned long uaddr, enum dma_data_direction direction,
3298c2ecf20Sopenharmony_ci		unsigned long attrs);
3308c2ecf20Sopenharmony_ciextern void pnv_tce_free(struct iommu_table *tbl, long index, long npages);
3318c2ecf20Sopenharmony_ciextern int pnv_tce_xchg(struct iommu_table *tbl, long index,
3328c2ecf20Sopenharmony_ci		unsigned long *hpa, enum dma_data_direction *direction,
3338c2ecf20Sopenharmony_ci		bool alloc);
3348c2ecf20Sopenharmony_ciextern __be64 *pnv_tce_useraddrptr(struct iommu_table *tbl, long index,
3358c2ecf20Sopenharmony_ci		bool alloc);
3368c2ecf20Sopenharmony_ciextern unsigned long pnv_tce_get(struct iommu_table *tbl, long index);
3378c2ecf20Sopenharmony_ci
3388c2ecf20Sopenharmony_ciextern long pnv_pci_ioda2_table_alloc_pages(int nid, __u64 bus_offset,
3398c2ecf20Sopenharmony_ci		__u32 page_shift, __u64 window_size, __u32 levels,
3408c2ecf20Sopenharmony_ci		bool alloc_userspace_copy, struct iommu_table *tbl);
3418c2ecf20Sopenharmony_ciextern void pnv_pci_ioda2_table_free_pages(struct iommu_table *tbl);
3428c2ecf20Sopenharmony_ci
3438c2ecf20Sopenharmony_ciextern long pnv_pci_link_table_and_group(int node, int num,
3448c2ecf20Sopenharmony_ci		struct iommu_table *tbl,
3458c2ecf20Sopenharmony_ci		struct iommu_table_group *table_group);
3468c2ecf20Sopenharmony_ciextern void pnv_pci_unlink_table_and_group(struct iommu_table *tbl,
3478c2ecf20Sopenharmony_ci		struct iommu_table_group *table_group);
3488c2ecf20Sopenharmony_ciextern void pnv_pci_setup_iommu_table(struct iommu_table *tbl,
3498c2ecf20Sopenharmony_ci		void *tce_mem, u64 tce_size,
3508c2ecf20Sopenharmony_ci		u64 dma_offset, unsigned int page_shift);
3518c2ecf20Sopenharmony_ci
3528c2ecf20Sopenharmony_ciextern unsigned long pnv_ioda_parse_tce_sizes(struct pnv_phb *phb);
3538c2ecf20Sopenharmony_ci
3548c2ecf20Sopenharmony_cistatic inline struct pnv_phb *pci_bus_to_pnvhb(struct pci_bus *bus)
3558c2ecf20Sopenharmony_ci{
3568c2ecf20Sopenharmony_ci	struct pci_controller *hose = bus->sysdata;
3578c2ecf20Sopenharmony_ci
3588c2ecf20Sopenharmony_ci	if (hose)
3598c2ecf20Sopenharmony_ci		return hose->private_data;
3608c2ecf20Sopenharmony_ci
3618c2ecf20Sopenharmony_ci	return NULL;
3628c2ecf20Sopenharmony_ci}
3638c2ecf20Sopenharmony_ci
3648c2ecf20Sopenharmony_ci#endif /* __POWERNV_PCI_H */
365