18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Synopsys DesignWare PCIe host controller driver
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (C) 2013 Samsung Electronics Co., Ltd.
68c2ecf20Sopenharmony_ci *		https://www.samsung.com
78c2ecf20Sopenharmony_ci *
88c2ecf20Sopenharmony_ci * Author: Jingoo Han <jg1.han@samsung.com>
98c2ecf20Sopenharmony_ci */
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#ifndef _PCIE_DESIGNWARE_H
128c2ecf20Sopenharmony_ci#define _PCIE_DESIGNWARE_H
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci#include <linux/bitfield.h>
158c2ecf20Sopenharmony_ci#include <linux/dma-mapping.h>
168c2ecf20Sopenharmony_ci#include <linux/irq.h>
178c2ecf20Sopenharmony_ci#include <linux/msi.h>
188c2ecf20Sopenharmony_ci#include <linux/pci.h>
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci#include <linux/pci-epc.h>
218c2ecf20Sopenharmony_ci#include <linux/pci-epf.h>
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci/* Parameters for the waiting for link up routine */
248c2ecf20Sopenharmony_ci#define LINK_WAIT_MAX_RETRIES		10
258c2ecf20Sopenharmony_ci#define LINK_WAIT_USLEEP_MIN		90000
268c2ecf20Sopenharmony_ci#define LINK_WAIT_USLEEP_MAX		100000
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci/* Parameters for the waiting for iATU enabled routine */
298c2ecf20Sopenharmony_ci#define LINK_WAIT_MAX_IATU_RETRIES	5
308c2ecf20Sopenharmony_ci#define LINK_WAIT_IATU			9
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ci/* Synopsys-specific PCIe configuration registers */
338c2ecf20Sopenharmony_ci#define PCIE_PORT_AFR			0x70C
348c2ecf20Sopenharmony_ci#define PORT_AFR_N_FTS_MASK		GENMASK(15, 8)
358c2ecf20Sopenharmony_ci#define PORT_AFR_N_FTS(n)		FIELD_PREP(PORT_AFR_N_FTS_MASK, n)
368c2ecf20Sopenharmony_ci#define PORT_AFR_CC_N_FTS_MASK		GENMASK(23, 16)
378c2ecf20Sopenharmony_ci#define PORT_AFR_CC_N_FTS(n)		FIELD_PREP(PORT_AFR_CC_N_FTS_MASK, n)
388c2ecf20Sopenharmony_ci#define PORT_AFR_ENTER_ASPM		BIT(30)
398c2ecf20Sopenharmony_ci#define PORT_AFR_L0S_ENTRANCE_LAT_SHIFT	24
408c2ecf20Sopenharmony_ci#define PORT_AFR_L0S_ENTRANCE_LAT_MASK	GENMASK(26, 24)
418c2ecf20Sopenharmony_ci#define PORT_AFR_L1_ENTRANCE_LAT_SHIFT	27
428c2ecf20Sopenharmony_ci#define PORT_AFR_L1_ENTRANCE_LAT_MASK	GENMASK(29, 27)
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci#define PCIE_PORT_LINK_CONTROL		0x710
458c2ecf20Sopenharmony_ci#define PORT_LINK_DLL_LINK_EN		BIT(5)
468c2ecf20Sopenharmony_ci#define PORT_LINK_FAST_LINK_MODE	BIT(7)
478c2ecf20Sopenharmony_ci#define PORT_LINK_MODE_MASK		GENMASK(21, 16)
488c2ecf20Sopenharmony_ci#define PORT_LINK_MODE(n)		FIELD_PREP(PORT_LINK_MODE_MASK, n)
498c2ecf20Sopenharmony_ci#define PORT_LINK_MODE_1_LANES		PORT_LINK_MODE(0x1)
508c2ecf20Sopenharmony_ci#define PORT_LINK_MODE_2_LANES		PORT_LINK_MODE(0x3)
518c2ecf20Sopenharmony_ci#define PORT_LINK_MODE_4_LANES		PORT_LINK_MODE(0x7)
528c2ecf20Sopenharmony_ci#define PORT_LINK_MODE_8_LANES		PORT_LINK_MODE(0xf)
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_ci#define PCIE_PORT_DEBUG0		0x728
558c2ecf20Sopenharmony_ci#define PORT_LOGIC_LTSSM_STATE_MASK	0x1f
568c2ecf20Sopenharmony_ci#define PORT_LOGIC_LTSSM_STATE_L0	0x11
578c2ecf20Sopenharmony_ci#define PCIE_PORT_DEBUG1		0x72C
588c2ecf20Sopenharmony_ci#define PCIE_PORT_DEBUG1_LINK_UP		BIT(4)
598c2ecf20Sopenharmony_ci#define PCIE_PORT_DEBUG1_LINK_IN_TRAINING	BIT(29)
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_ci#define PCIE_LINK_WIDTH_SPEED_CONTROL	0x80C
628c2ecf20Sopenharmony_ci#define PORT_LOGIC_N_FTS_MASK		GENMASK(7, 0)
638c2ecf20Sopenharmony_ci#define PORT_LOGIC_SPEED_CHANGE		BIT(17)
648c2ecf20Sopenharmony_ci#define PORT_LOGIC_LINK_WIDTH_MASK	GENMASK(12, 8)
658c2ecf20Sopenharmony_ci#define PORT_LOGIC_LINK_WIDTH(n)	FIELD_PREP(PORT_LOGIC_LINK_WIDTH_MASK, n)
668c2ecf20Sopenharmony_ci#define PORT_LOGIC_LINK_WIDTH_1_LANES	PORT_LOGIC_LINK_WIDTH(0x1)
678c2ecf20Sopenharmony_ci#define PORT_LOGIC_LINK_WIDTH_2_LANES	PORT_LOGIC_LINK_WIDTH(0x2)
688c2ecf20Sopenharmony_ci#define PORT_LOGIC_LINK_WIDTH_4_LANES	PORT_LOGIC_LINK_WIDTH(0x4)
698c2ecf20Sopenharmony_ci#define PORT_LOGIC_LINK_WIDTH_8_LANES	PORT_LOGIC_LINK_WIDTH(0x8)
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_ci#define PCIE_MSI_ADDR_LO		0x820
728c2ecf20Sopenharmony_ci#define PCIE_MSI_ADDR_HI		0x824
738c2ecf20Sopenharmony_ci#define PCIE_MSI_INTR0_ENABLE		0x828
748c2ecf20Sopenharmony_ci#define PCIE_MSI_INTR0_MASK		0x82C
758c2ecf20Sopenharmony_ci#define PCIE_MSI_INTR0_STATUS		0x830
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_ci#define PCIE_PORT_MULTI_LANE_CTRL	0x8C0
788c2ecf20Sopenharmony_ci#define PORT_MLTI_UPCFG_SUPPORT		BIT(7)
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_ci#define PCIE_ATU_VIEWPORT		0x900
818c2ecf20Sopenharmony_ci#define PCIE_ATU_REGION_INBOUND		BIT(31)
828c2ecf20Sopenharmony_ci#define PCIE_ATU_REGION_OUTBOUND	0
838c2ecf20Sopenharmony_ci#define PCIE_ATU_REGION_INDEX2		0x2
848c2ecf20Sopenharmony_ci#define PCIE_ATU_REGION_INDEX1		0x1
858c2ecf20Sopenharmony_ci#define PCIE_ATU_REGION_INDEX0		0x0
868c2ecf20Sopenharmony_ci#define PCIE_ATU_CR1			0x904
878c2ecf20Sopenharmony_ci#define PCIE_ATU_TYPE_MEM		0x0
888c2ecf20Sopenharmony_ci#define PCIE_ATU_TYPE_IO		0x2
898c2ecf20Sopenharmony_ci#define PCIE_ATU_TYPE_CFG0		0x4
908c2ecf20Sopenharmony_ci#define PCIE_ATU_TYPE_CFG1		0x5
918c2ecf20Sopenharmony_ci#define PCIE_ATU_FUNC_NUM(pf)           ((pf) << 20)
928c2ecf20Sopenharmony_ci#define PCIE_ATU_CR2			0x908
938c2ecf20Sopenharmony_ci#define PCIE_ATU_ENABLE			BIT(31)
948c2ecf20Sopenharmony_ci#define PCIE_ATU_BAR_MODE_ENABLE	BIT(30)
958c2ecf20Sopenharmony_ci#define PCIE_ATU_FUNC_NUM_MATCH_EN      BIT(19)
968c2ecf20Sopenharmony_ci#define PCIE_ATU_LOWER_BASE		0x90C
978c2ecf20Sopenharmony_ci#define PCIE_ATU_UPPER_BASE		0x910
988c2ecf20Sopenharmony_ci#define PCIE_ATU_LIMIT			0x914
998c2ecf20Sopenharmony_ci#define PCIE_ATU_LOWER_TARGET		0x918
1008c2ecf20Sopenharmony_ci#define PCIE_ATU_BUS(x)			FIELD_PREP(GENMASK(31, 24), x)
1018c2ecf20Sopenharmony_ci#define PCIE_ATU_DEV(x)			FIELD_PREP(GENMASK(23, 19), x)
1028c2ecf20Sopenharmony_ci#define PCIE_ATU_FUNC(x)		FIELD_PREP(GENMASK(18, 16), x)
1038c2ecf20Sopenharmony_ci#define PCIE_ATU_UPPER_TARGET		0x91C
1048c2ecf20Sopenharmony_ci
1058c2ecf20Sopenharmony_ci#define PCIE_MISC_CONTROL_1_OFF		0x8BC
1068c2ecf20Sopenharmony_ci#define PCIE_DBI_RO_WR_EN		BIT(0)
1078c2ecf20Sopenharmony_ci
1088c2ecf20Sopenharmony_ci#define PCIE_MSIX_DOORBELL		0x948
1098c2ecf20Sopenharmony_ci#define PCIE_MSIX_DOORBELL_PF_SHIFT	24
1108c2ecf20Sopenharmony_ci
1118c2ecf20Sopenharmony_ci#define PCIE_PL_CHK_REG_CONTROL_STATUS			0xB20
1128c2ecf20Sopenharmony_ci#define PCIE_PL_CHK_REG_CHK_REG_START			BIT(0)
1138c2ecf20Sopenharmony_ci#define PCIE_PL_CHK_REG_CHK_REG_CONTINUOUS		BIT(1)
1148c2ecf20Sopenharmony_ci#define PCIE_PL_CHK_REG_CHK_REG_COMPARISON_ERROR	BIT(16)
1158c2ecf20Sopenharmony_ci#define PCIE_PL_CHK_REG_CHK_REG_LOGIC_ERROR		BIT(17)
1168c2ecf20Sopenharmony_ci#define PCIE_PL_CHK_REG_CHK_REG_COMPLETE		BIT(18)
1178c2ecf20Sopenharmony_ci
1188c2ecf20Sopenharmony_ci#define PCIE_PL_CHK_REG_ERR_ADDR			0xB28
1198c2ecf20Sopenharmony_ci
1208c2ecf20Sopenharmony_ci/*
1218c2ecf20Sopenharmony_ci * iATU Unroll-specific register definitions
1228c2ecf20Sopenharmony_ci * From 4.80 core version the address translation will be made by unroll
1238c2ecf20Sopenharmony_ci */
1248c2ecf20Sopenharmony_ci#define PCIE_ATU_UNR_REGION_CTRL1	0x00
1258c2ecf20Sopenharmony_ci#define PCIE_ATU_UNR_REGION_CTRL2	0x04
1268c2ecf20Sopenharmony_ci#define PCIE_ATU_UNR_LOWER_BASE		0x08
1278c2ecf20Sopenharmony_ci#define PCIE_ATU_UNR_UPPER_BASE		0x0C
1288c2ecf20Sopenharmony_ci#define PCIE_ATU_UNR_LOWER_LIMIT	0x10
1298c2ecf20Sopenharmony_ci#define PCIE_ATU_UNR_LOWER_TARGET	0x14
1308c2ecf20Sopenharmony_ci#define PCIE_ATU_UNR_UPPER_TARGET	0x18
1318c2ecf20Sopenharmony_ci#define PCIE_ATU_UNR_UPPER_LIMIT	0x20
1328c2ecf20Sopenharmony_ci
1338c2ecf20Sopenharmony_ci/*
1348c2ecf20Sopenharmony_ci * The default address offset between dbi_base and atu_base. Root controller
1358c2ecf20Sopenharmony_ci * drivers are not required to initialize atu_base if the offset matches this
1368c2ecf20Sopenharmony_ci * default; the driver core automatically derives atu_base from dbi_base using
1378c2ecf20Sopenharmony_ci * this offset, if atu_base not set.
1388c2ecf20Sopenharmony_ci */
1398c2ecf20Sopenharmony_ci#define DEFAULT_DBI_ATU_OFFSET (0x3 << 20)
1408c2ecf20Sopenharmony_ci
1418c2ecf20Sopenharmony_ci/* Register address builder */
1428c2ecf20Sopenharmony_ci#define PCIE_GET_ATU_OUTB_UNR_REG_OFFSET(region) \
1438c2ecf20Sopenharmony_ci		((region) << 9)
1448c2ecf20Sopenharmony_ci
1458c2ecf20Sopenharmony_ci#define PCIE_GET_ATU_INB_UNR_REG_OFFSET(region) \
1468c2ecf20Sopenharmony_ci		(((region) << 9) | BIT(8))
1478c2ecf20Sopenharmony_ci
1488c2ecf20Sopenharmony_ci#define MAX_MSI_IRQS			256
1498c2ecf20Sopenharmony_ci#define MAX_MSI_IRQS_PER_CTRL		32
1508c2ecf20Sopenharmony_ci#define MAX_MSI_CTRLS			(MAX_MSI_IRQS / MAX_MSI_IRQS_PER_CTRL)
1518c2ecf20Sopenharmony_ci#define MSI_REG_CTRL_BLOCK_SIZE		12
1528c2ecf20Sopenharmony_ci#define MSI_DEF_NUM_VECTORS		32
1538c2ecf20Sopenharmony_ci
1548c2ecf20Sopenharmony_ci/* Maximum number of inbound/outbound iATUs */
1558c2ecf20Sopenharmony_ci#define MAX_IATU_IN			256
1568c2ecf20Sopenharmony_ci#define MAX_IATU_OUT			256
1578c2ecf20Sopenharmony_ci
1588c2ecf20Sopenharmony_cistruct pcie_port;
1598c2ecf20Sopenharmony_cistruct dw_pcie;
1608c2ecf20Sopenharmony_cistruct dw_pcie_ep;
1618c2ecf20Sopenharmony_ci
1628c2ecf20Sopenharmony_cienum dw_pcie_region_type {
1638c2ecf20Sopenharmony_ci	DW_PCIE_REGION_UNKNOWN,
1648c2ecf20Sopenharmony_ci	DW_PCIE_REGION_INBOUND,
1658c2ecf20Sopenharmony_ci	DW_PCIE_REGION_OUTBOUND,
1668c2ecf20Sopenharmony_ci};
1678c2ecf20Sopenharmony_ci
1688c2ecf20Sopenharmony_cienum dw_pcie_device_mode {
1698c2ecf20Sopenharmony_ci	DW_PCIE_UNKNOWN_TYPE,
1708c2ecf20Sopenharmony_ci	DW_PCIE_EP_TYPE,
1718c2ecf20Sopenharmony_ci	DW_PCIE_LEG_EP_TYPE,
1728c2ecf20Sopenharmony_ci	DW_PCIE_RC_TYPE,
1738c2ecf20Sopenharmony_ci};
1748c2ecf20Sopenharmony_ci
1758c2ecf20Sopenharmony_cistruct dw_pcie_host_ops {
1768c2ecf20Sopenharmony_ci	int (*host_init)(struct pcie_port *pp);
1778c2ecf20Sopenharmony_ci	void (*set_num_vectors)(struct pcie_port *pp);
1788c2ecf20Sopenharmony_ci	int (*msi_host_init)(struct pcie_port *pp);
1798c2ecf20Sopenharmony_ci};
1808c2ecf20Sopenharmony_ci
1818c2ecf20Sopenharmony_cistruct pcie_port {
1828c2ecf20Sopenharmony_ci	u64			cfg0_base;
1838c2ecf20Sopenharmony_ci	void __iomem		*va_cfg0_base;
1848c2ecf20Sopenharmony_ci	u32			cfg0_size;
1858c2ecf20Sopenharmony_ci	resource_size_t		io_base;
1868c2ecf20Sopenharmony_ci	phys_addr_t		io_bus_addr;
1878c2ecf20Sopenharmony_ci	u32			io_size;
1888c2ecf20Sopenharmony_ci	int			irq;
1898c2ecf20Sopenharmony_ci	const struct dw_pcie_host_ops *ops;
1908c2ecf20Sopenharmony_ci	int			msi_irq;
1918c2ecf20Sopenharmony_ci	struct irq_domain	*irq_domain;
1928c2ecf20Sopenharmony_ci	struct irq_domain	*msi_domain;
1938c2ecf20Sopenharmony_ci	u16			msi_msg;
1948c2ecf20Sopenharmony_ci	dma_addr_t		msi_data;
1958c2ecf20Sopenharmony_ci	struct irq_chip		*msi_irq_chip;
1968c2ecf20Sopenharmony_ci	u32			num_vectors;
1978c2ecf20Sopenharmony_ci	u32			irq_mask[MAX_MSI_CTRLS];
1988c2ecf20Sopenharmony_ci	struct pci_host_bridge  *bridge;
1998c2ecf20Sopenharmony_ci	raw_spinlock_t		lock;
2008c2ecf20Sopenharmony_ci	DECLARE_BITMAP(msi_irq_in_use, MAX_MSI_IRQS);
2018c2ecf20Sopenharmony_ci};
2028c2ecf20Sopenharmony_ci
2038c2ecf20Sopenharmony_cienum dw_pcie_as_type {
2048c2ecf20Sopenharmony_ci	DW_PCIE_AS_UNKNOWN,
2058c2ecf20Sopenharmony_ci	DW_PCIE_AS_MEM,
2068c2ecf20Sopenharmony_ci	DW_PCIE_AS_IO,
2078c2ecf20Sopenharmony_ci};
2088c2ecf20Sopenharmony_ci
2098c2ecf20Sopenharmony_cistruct dw_pcie_ep_ops {
2108c2ecf20Sopenharmony_ci	void	(*ep_init)(struct dw_pcie_ep *ep);
2118c2ecf20Sopenharmony_ci	int	(*raise_irq)(struct dw_pcie_ep *ep, u8 func_no,
2128c2ecf20Sopenharmony_ci			     enum pci_epc_irq_type type, u16 interrupt_num);
2138c2ecf20Sopenharmony_ci	const struct pci_epc_features* (*get_features)(struct dw_pcie_ep *ep);
2148c2ecf20Sopenharmony_ci	/*
2158c2ecf20Sopenharmony_ci	 * Provide a method to implement the different func config space
2168c2ecf20Sopenharmony_ci	 * access for different platform, if different func have different
2178c2ecf20Sopenharmony_ci	 * offset, return the offset of func. if use write a register way
2188c2ecf20Sopenharmony_ci	 * return a 0, and implement code in callback function of platform
2198c2ecf20Sopenharmony_ci	 * driver.
2208c2ecf20Sopenharmony_ci	 */
2218c2ecf20Sopenharmony_ci	unsigned int (*func_conf_select)(struct dw_pcie_ep *ep, u8 func_no);
2228c2ecf20Sopenharmony_ci};
2238c2ecf20Sopenharmony_ci
2248c2ecf20Sopenharmony_cistruct dw_pcie_ep_func {
2258c2ecf20Sopenharmony_ci	struct list_head	list;
2268c2ecf20Sopenharmony_ci	u8			func_no;
2278c2ecf20Sopenharmony_ci	u8			msi_cap;	/* MSI capability offset */
2288c2ecf20Sopenharmony_ci	u8			msix_cap;	/* MSI-X capability offset */
2298c2ecf20Sopenharmony_ci};
2308c2ecf20Sopenharmony_ci
2318c2ecf20Sopenharmony_cistruct dw_pcie_ep {
2328c2ecf20Sopenharmony_ci	struct pci_epc		*epc;
2338c2ecf20Sopenharmony_ci	struct list_head	func_list;
2348c2ecf20Sopenharmony_ci	const struct dw_pcie_ep_ops *ops;
2358c2ecf20Sopenharmony_ci	phys_addr_t		phys_base;
2368c2ecf20Sopenharmony_ci	size_t			addr_size;
2378c2ecf20Sopenharmony_ci	size_t			page_size;
2388c2ecf20Sopenharmony_ci	u8			bar_to_atu[PCI_STD_NUM_BARS];
2398c2ecf20Sopenharmony_ci	phys_addr_t		*outbound_addr;
2408c2ecf20Sopenharmony_ci	unsigned long		*ib_window_map;
2418c2ecf20Sopenharmony_ci	unsigned long		*ob_window_map;
2428c2ecf20Sopenharmony_ci	u32			num_ib_windows;
2438c2ecf20Sopenharmony_ci	u32			num_ob_windows;
2448c2ecf20Sopenharmony_ci	void __iomem		*msi_mem;
2458c2ecf20Sopenharmony_ci	phys_addr_t		msi_mem_phys;
2468c2ecf20Sopenharmony_ci	struct pci_epf_bar	*epf_bar[PCI_STD_NUM_BARS];
2478c2ecf20Sopenharmony_ci};
2488c2ecf20Sopenharmony_ci
2498c2ecf20Sopenharmony_cistruct dw_pcie_ops {
2508c2ecf20Sopenharmony_ci	u64	(*cpu_addr_fixup)(struct dw_pcie *pcie, u64 cpu_addr);
2518c2ecf20Sopenharmony_ci	u32	(*read_dbi)(struct dw_pcie *pcie, void __iomem *base, u32 reg,
2528c2ecf20Sopenharmony_ci			    size_t size);
2538c2ecf20Sopenharmony_ci	void	(*write_dbi)(struct dw_pcie *pcie, void __iomem *base, u32 reg,
2548c2ecf20Sopenharmony_ci			     size_t size, u32 val);
2558c2ecf20Sopenharmony_ci	void    (*write_dbi2)(struct dw_pcie *pcie, void __iomem *base, u32 reg,
2568c2ecf20Sopenharmony_ci			      size_t size, u32 val);
2578c2ecf20Sopenharmony_ci	int	(*link_up)(struct dw_pcie *pcie);
2588c2ecf20Sopenharmony_ci	int	(*start_link)(struct dw_pcie *pcie);
2598c2ecf20Sopenharmony_ci	void	(*stop_link)(struct dw_pcie *pcie);
2608c2ecf20Sopenharmony_ci};
2618c2ecf20Sopenharmony_ci
2628c2ecf20Sopenharmony_cistruct dw_pcie {
2638c2ecf20Sopenharmony_ci	struct device		*dev;
2648c2ecf20Sopenharmony_ci	void __iomem		*dbi_base;
2658c2ecf20Sopenharmony_ci	void __iomem		*dbi_base2;
2668c2ecf20Sopenharmony_ci	/* Used when iatu_unroll_enabled is true */
2678c2ecf20Sopenharmony_ci	void __iomem		*atu_base;
2688c2ecf20Sopenharmony_ci	u32			num_viewport;
2698c2ecf20Sopenharmony_ci	u8			iatu_unroll_enabled;
2708c2ecf20Sopenharmony_ci	struct pcie_port	pp;
2718c2ecf20Sopenharmony_ci	struct dw_pcie_ep	ep;
2728c2ecf20Sopenharmony_ci	const struct dw_pcie_ops *ops;
2738c2ecf20Sopenharmony_ci	unsigned int		version;
2748c2ecf20Sopenharmony_ci	int			num_lanes;
2758c2ecf20Sopenharmony_ci	int			link_gen;
2768c2ecf20Sopenharmony_ci	u8			n_fts[2];
2778c2ecf20Sopenharmony_ci};
2788c2ecf20Sopenharmony_ci
2798c2ecf20Sopenharmony_ci#define to_dw_pcie_from_pp(port) container_of((port), struct dw_pcie, pp)
2808c2ecf20Sopenharmony_ci
2818c2ecf20Sopenharmony_ci#define to_dw_pcie_from_ep(endpoint)   \
2828c2ecf20Sopenharmony_ci		container_of((endpoint), struct dw_pcie, ep)
2838c2ecf20Sopenharmony_ci
2848c2ecf20Sopenharmony_ciu8 dw_pcie_find_capability(struct dw_pcie *pci, u8 cap);
2858c2ecf20Sopenharmony_ciu16 dw_pcie_find_ext_capability(struct dw_pcie *pci, u8 cap);
2868c2ecf20Sopenharmony_ci
2878c2ecf20Sopenharmony_ciint dw_pcie_read(void __iomem *addr, int size, u32 *val);
2888c2ecf20Sopenharmony_ciint dw_pcie_write(void __iomem *addr, int size, u32 val);
2898c2ecf20Sopenharmony_ci
2908c2ecf20Sopenharmony_ciu32 dw_pcie_read_dbi(struct dw_pcie *pci, u32 reg, size_t size);
2918c2ecf20Sopenharmony_civoid dw_pcie_write_dbi(struct dw_pcie *pci, u32 reg, size_t size, u32 val);
2928c2ecf20Sopenharmony_civoid dw_pcie_write_dbi2(struct dw_pcie *pci, u32 reg, size_t size, u32 val);
2938c2ecf20Sopenharmony_ciint dw_pcie_link_up(struct dw_pcie *pci);
2948c2ecf20Sopenharmony_civoid dw_pcie_upconfig_setup(struct dw_pcie *pci);
2958c2ecf20Sopenharmony_ciint dw_pcie_wait_for_link(struct dw_pcie *pci);
2968c2ecf20Sopenharmony_civoid dw_pcie_prog_outbound_atu(struct dw_pcie *pci, int index,
2978c2ecf20Sopenharmony_ci			       int type, u64 cpu_addr, u64 pci_addr,
2988c2ecf20Sopenharmony_ci			       u32 size);
2998c2ecf20Sopenharmony_civoid dw_pcie_prog_ep_outbound_atu(struct dw_pcie *pci, u8 func_no, int index,
3008c2ecf20Sopenharmony_ci				  int type, u64 cpu_addr, u64 pci_addr,
3018c2ecf20Sopenharmony_ci				  u32 size);
3028c2ecf20Sopenharmony_ciint dw_pcie_prog_inbound_atu(struct dw_pcie *pci, u8 func_no, int index,
3038c2ecf20Sopenharmony_ci			     int bar, u64 cpu_addr,
3048c2ecf20Sopenharmony_ci			     enum dw_pcie_as_type as_type);
3058c2ecf20Sopenharmony_civoid dw_pcie_disable_atu(struct dw_pcie *pci, int index,
3068c2ecf20Sopenharmony_ci			 enum dw_pcie_region_type type);
3078c2ecf20Sopenharmony_civoid dw_pcie_setup(struct dw_pcie *pci);
3088c2ecf20Sopenharmony_ci
3098c2ecf20Sopenharmony_cistatic inline void dw_pcie_writel_dbi(struct dw_pcie *pci, u32 reg, u32 val)
3108c2ecf20Sopenharmony_ci{
3118c2ecf20Sopenharmony_ci	dw_pcie_write_dbi(pci, reg, 0x4, val);
3128c2ecf20Sopenharmony_ci}
3138c2ecf20Sopenharmony_ci
3148c2ecf20Sopenharmony_cistatic inline u32 dw_pcie_readl_dbi(struct dw_pcie *pci, u32 reg)
3158c2ecf20Sopenharmony_ci{
3168c2ecf20Sopenharmony_ci	return dw_pcie_read_dbi(pci, reg, 0x4);
3178c2ecf20Sopenharmony_ci}
3188c2ecf20Sopenharmony_ci
3198c2ecf20Sopenharmony_cistatic inline void dw_pcie_writew_dbi(struct dw_pcie *pci, u32 reg, u16 val)
3208c2ecf20Sopenharmony_ci{
3218c2ecf20Sopenharmony_ci	dw_pcie_write_dbi(pci, reg, 0x2, val);
3228c2ecf20Sopenharmony_ci}
3238c2ecf20Sopenharmony_ci
3248c2ecf20Sopenharmony_cistatic inline u16 dw_pcie_readw_dbi(struct dw_pcie *pci, u32 reg)
3258c2ecf20Sopenharmony_ci{
3268c2ecf20Sopenharmony_ci	return dw_pcie_read_dbi(pci, reg, 0x2);
3278c2ecf20Sopenharmony_ci}
3288c2ecf20Sopenharmony_ci
3298c2ecf20Sopenharmony_cistatic inline void dw_pcie_writeb_dbi(struct dw_pcie *pci, u32 reg, u8 val)
3308c2ecf20Sopenharmony_ci{
3318c2ecf20Sopenharmony_ci	dw_pcie_write_dbi(pci, reg, 0x1, val);
3328c2ecf20Sopenharmony_ci}
3338c2ecf20Sopenharmony_ci
3348c2ecf20Sopenharmony_cistatic inline u8 dw_pcie_readb_dbi(struct dw_pcie *pci, u32 reg)
3358c2ecf20Sopenharmony_ci{
3368c2ecf20Sopenharmony_ci	return dw_pcie_read_dbi(pci, reg, 0x1);
3378c2ecf20Sopenharmony_ci}
3388c2ecf20Sopenharmony_ci
3398c2ecf20Sopenharmony_cistatic inline void dw_pcie_writel_dbi2(struct dw_pcie *pci, u32 reg, u32 val)
3408c2ecf20Sopenharmony_ci{
3418c2ecf20Sopenharmony_ci	dw_pcie_write_dbi2(pci, reg, 0x4, val);
3428c2ecf20Sopenharmony_ci}
3438c2ecf20Sopenharmony_ci
3448c2ecf20Sopenharmony_cistatic inline void dw_pcie_dbi_ro_wr_en(struct dw_pcie *pci)
3458c2ecf20Sopenharmony_ci{
3468c2ecf20Sopenharmony_ci	u32 reg;
3478c2ecf20Sopenharmony_ci	u32 val;
3488c2ecf20Sopenharmony_ci
3498c2ecf20Sopenharmony_ci	reg = PCIE_MISC_CONTROL_1_OFF;
3508c2ecf20Sopenharmony_ci	val = dw_pcie_readl_dbi(pci, reg);
3518c2ecf20Sopenharmony_ci	val |= PCIE_DBI_RO_WR_EN;
3528c2ecf20Sopenharmony_ci	dw_pcie_writel_dbi(pci, reg, val);
3538c2ecf20Sopenharmony_ci}
3548c2ecf20Sopenharmony_ci
3558c2ecf20Sopenharmony_cistatic inline void dw_pcie_dbi_ro_wr_dis(struct dw_pcie *pci)
3568c2ecf20Sopenharmony_ci{
3578c2ecf20Sopenharmony_ci	u32 reg;
3588c2ecf20Sopenharmony_ci	u32 val;
3598c2ecf20Sopenharmony_ci
3608c2ecf20Sopenharmony_ci	reg = PCIE_MISC_CONTROL_1_OFF;
3618c2ecf20Sopenharmony_ci	val = dw_pcie_readl_dbi(pci, reg);
3628c2ecf20Sopenharmony_ci	val &= ~PCIE_DBI_RO_WR_EN;
3638c2ecf20Sopenharmony_ci	dw_pcie_writel_dbi(pci, reg, val);
3648c2ecf20Sopenharmony_ci}
3658c2ecf20Sopenharmony_ci
3668c2ecf20Sopenharmony_ci#ifdef CONFIG_PCIE_DW_HOST
3678c2ecf20Sopenharmony_ciirqreturn_t dw_handle_msi_irq(struct pcie_port *pp);
3688c2ecf20Sopenharmony_civoid dw_pcie_msi_init(struct pcie_port *pp);
3698c2ecf20Sopenharmony_civoid dw_pcie_free_msi(struct pcie_port *pp);
3708c2ecf20Sopenharmony_civoid dw_pcie_setup_rc(struct pcie_port *pp);
3718c2ecf20Sopenharmony_ciint dw_pcie_host_init(struct pcie_port *pp);
3728c2ecf20Sopenharmony_civoid dw_pcie_host_deinit(struct pcie_port *pp);
3738c2ecf20Sopenharmony_ciint dw_pcie_allocate_domains(struct pcie_port *pp);
3748c2ecf20Sopenharmony_civoid __iomem *dw_pcie_own_conf_map_bus(struct pci_bus *bus, unsigned int devfn,
3758c2ecf20Sopenharmony_ci				       int where);
3768c2ecf20Sopenharmony_ci#else
3778c2ecf20Sopenharmony_cistatic inline irqreturn_t dw_handle_msi_irq(struct pcie_port *pp)
3788c2ecf20Sopenharmony_ci{
3798c2ecf20Sopenharmony_ci	return IRQ_NONE;
3808c2ecf20Sopenharmony_ci}
3818c2ecf20Sopenharmony_ci
3828c2ecf20Sopenharmony_cistatic inline void dw_pcie_msi_init(struct pcie_port *pp)
3838c2ecf20Sopenharmony_ci{
3848c2ecf20Sopenharmony_ci}
3858c2ecf20Sopenharmony_ci
3868c2ecf20Sopenharmony_cistatic inline void dw_pcie_free_msi(struct pcie_port *pp)
3878c2ecf20Sopenharmony_ci{
3888c2ecf20Sopenharmony_ci}
3898c2ecf20Sopenharmony_ci
3908c2ecf20Sopenharmony_cistatic inline void dw_pcie_setup_rc(struct pcie_port *pp)
3918c2ecf20Sopenharmony_ci{
3928c2ecf20Sopenharmony_ci}
3938c2ecf20Sopenharmony_ci
3948c2ecf20Sopenharmony_cistatic inline int dw_pcie_host_init(struct pcie_port *pp)
3958c2ecf20Sopenharmony_ci{
3968c2ecf20Sopenharmony_ci	return 0;
3978c2ecf20Sopenharmony_ci}
3988c2ecf20Sopenharmony_ci
3998c2ecf20Sopenharmony_cistatic inline void dw_pcie_host_deinit(struct pcie_port *pp)
4008c2ecf20Sopenharmony_ci{
4018c2ecf20Sopenharmony_ci}
4028c2ecf20Sopenharmony_ci
4038c2ecf20Sopenharmony_cistatic inline int dw_pcie_allocate_domains(struct pcie_port *pp)
4048c2ecf20Sopenharmony_ci{
4058c2ecf20Sopenharmony_ci	return 0;
4068c2ecf20Sopenharmony_ci}
4078c2ecf20Sopenharmony_cistatic inline void __iomem *dw_pcie_own_conf_map_bus(struct pci_bus *bus,
4088c2ecf20Sopenharmony_ci						     unsigned int devfn,
4098c2ecf20Sopenharmony_ci						     int where)
4108c2ecf20Sopenharmony_ci{
4118c2ecf20Sopenharmony_ci	return NULL;
4128c2ecf20Sopenharmony_ci}
4138c2ecf20Sopenharmony_ci#endif
4148c2ecf20Sopenharmony_ci
4158c2ecf20Sopenharmony_ci#ifdef CONFIG_PCIE_DW_EP
4168c2ecf20Sopenharmony_civoid dw_pcie_ep_linkup(struct dw_pcie_ep *ep);
4178c2ecf20Sopenharmony_ciint dw_pcie_ep_init(struct dw_pcie_ep *ep);
4188c2ecf20Sopenharmony_ciint dw_pcie_ep_init_complete(struct dw_pcie_ep *ep);
4198c2ecf20Sopenharmony_civoid dw_pcie_ep_init_notify(struct dw_pcie_ep *ep);
4208c2ecf20Sopenharmony_civoid dw_pcie_ep_exit(struct dw_pcie_ep *ep);
4218c2ecf20Sopenharmony_ciint dw_pcie_ep_raise_legacy_irq(struct dw_pcie_ep *ep, u8 func_no);
4228c2ecf20Sopenharmony_ciint dw_pcie_ep_raise_msi_irq(struct dw_pcie_ep *ep, u8 func_no,
4238c2ecf20Sopenharmony_ci			     u8 interrupt_num);
4248c2ecf20Sopenharmony_ciint dw_pcie_ep_raise_msix_irq(struct dw_pcie_ep *ep, u8 func_no,
4258c2ecf20Sopenharmony_ci			     u16 interrupt_num);
4268c2ecf20Sopenharmony_ciint dw_pcie_ep_raise_msix_irq_doorbell(struct dw_pcie_ep *ep, u8 func_no,
4278c2ecf20Sopenharmony_ci				       u16 interrupt_num);
4288c2ecf20Sopenharmony_civoid dw_pcie_ep_reset_bar(struct dw_pcie *pci, enum pci_barno bar);
4298c2ecf20Sopenharmony_cistruct dw_pcie_ep_func *
4308c2ecf20Sopenharmony_cidw_pcie_ep_get_func_from_ep(struct dw_pcie_ep *ep, u8 func_no);
4318c2ecf20Sopenharmony_ci#else
4328c2ecf20Sopenharmony_cistatic inline void dw_pcie_ep_linkup(struct dw_pcie_ep *ep)
4338c2ecf20Sopenharmony_ci{
4348c2ecf20Sopenharmony_ci}
4358c2ecf20Sopenharmony_ci
4368c2ecf20Sopenharmony_cistatic inline int dw_pcie_ep_init(struct dw_pcie_ep *ep)
4378c2ecf20Sopenharmony_ci{
4388c2ecf20Sopenharmony_ci	return 0;
4398c2ecf20Sopenharmony_ci}
4408c2ecf20Sopenharmony_ci
4418c2ecf20Sopenharmony_cistatic inline int dw_pcie_ep_init_complete(struct dw_pcie_ep *ep)
4428c2ecf20Sopenharmony_ci{
4438c2ecf20Sopenharmony_ci	return 0;
4448c2ecf20Sopenharmony_ci}
4458c2ecf20Sopenharmony_ci
4468c2ecf20Sopenharmony_cistatic inline void dw_pcie_ep_init_notify(struct dw_pcie_ep *ep)
4478c2ecf20Sopenharmony_ci{
4488c2ecf20Sopenharmony_ci}
4498c2ecf20Sopenharmony_ci
4508c2ecf20Sopenharmony_cistatic inline void dw_pcie_ep_exit(struct dw_pcie_ep *ep)
4518c2ecf20Sopenharmony_ci{
4528c2ecf20Sopenharmony_ci}
4538c2ecf20Sopenharmony_ci
4548c2ecf20Sopenharmony_cistatic inline int dw_pcie_ep_raise_legacy_irq(struct dw_pcie_ep *ep, u8 func_no)
4558c2ecf20Sopenharmony_ci{
4568c2ecf20Sopenharmony_ci	return 0;
4578c2ecf20Sopenharmony_ci}
4588c2ecf20Sopenharmony_ci
4598c2ecf20Sopenharmony_cistatic inline int dw_pcie_ep_raise_msi_irq(struct dw_pcie_ep *ep, u8 func_no,
4608c2ecf20Sopenharmony_ci					   u8 interrupt_num)
4618c2ecf20Sopenharmony_ci{
4628c2ecf20Sopenharmony_ci	return 0;
4638c2ecf20Sopenharmony_ci}
4648c2ecf20Sopenharmony_ci
4658c2ecf20Sopenharmony_cistatic inline int dw_pcie_ep_raise_msix_irq(struct dw_pcie_ep *ep, u8 func_no,
4668c2ecf20Sopenharmony_ci					   u16 interrupt_num)
4678c2ecf20Sopenharmony_ci{
4688c2ecf20Sopenharmony_ci	return 0;
4698c2ecf20Sopenharmony_ci}
4708c2ecf20Sopenharmony_ci
4718c2ecf20Sopenharmony_cistatic inline int dw_pcie_ep_raise_msix_irq_doorbell(struct dw_pcie_ep *ep,
4728c2ecf20Sopenharmony_ci						     u8 func_no,
4738c2ecf20Sopenharmony_ci						     u16 interrupt_num)
4748c2ecf20Sopenharmony_ci{
4758c2ecf20Sopenharmony_ci	return 0;
4768c2ecf20Sopenharmony_ci}
4778c2ecf20Sopenharmony_ci
4788c2ecf20Sopenharmony_cistatic inline void dw_pcie_ep_reset_bar(struct dw_pcie *pci, enum pci_barno bar)
4798c2ecf20Sopenharmony_ci{
4808c2ecf20Sopenharmony_ci}
4818c2ecf20Sopenharmony_ci
4828c2ecf20Sopenharmony_cistatic inline struct dw_pcie_ep_func *
4838c2ecf20Sopenharmony_cidw_pcie_ep_get_func_from_ep(struct dw_pcie_ep *ep, u8 func_no)
4848c2ecf20Sopenharmony_ci{
4858c2ecf20Sopenharmony_ci	return NULL;
4868c2ecf20Sopenharmony_ci}
4878c2ecf20Sopenharmony_ci#endif
4888c2ecf20Sopenharmony_ci#endif /* _PCIE_DESIGNWARE_H */
489