2013-07-31 02:14:10 -06:00
|
|
|
/*
|
|
|
|
* Synopsys Designware PCIe host controller driver
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013 Samsung Electronics Co., Ltd.
|
|
|
|
* http://www.samsung.com
|
|
|
|
*
|
|
|
|
* Author: Jingoo Han <jg1.han@samsung.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*/
|
|
|
|
|
2013-10-09 09:12:21 -06:00
|
|
|
#ifndef _PCIE_DESIGNWARE_H
|
|
|
|
#define _PCIE_DESIGNWARE_H
|
|
|
|
|
2013-09-06 00:54:59 -06:00
|
|
|
/*
|
|
|
|
* Maximum number of MSI IRQs can be 256 per controller. But keep
|
|
|
|
* it 32 as of now. Probably we will never need more than 32. If needed,
|
|
|
|
* then increment it in multiple of 32.
|
|
|
|
*/
|
|
|
|
#define MAX_MSI_IRQS 32
|
|
|
|
#define MAX_MSI_CTRLS (MAX_MSI_IRQS / 32)
|
|
|
|
|
PCI: designware: Add generic dw_pcie_wait_for_link()
Several DesignWare-based drivers (dra7xx, exynos, imx6, keystone, qcom, and
spear13xx) had similar loops waiting for the link to come up.
Add a generic dw_pcie_wait_for_link() for use by all these drivers so the
waiting is done consistently, e.g., always using usleep_range() rather than
mdelay() and using similar timeouts and retry counts.
Note that this changes the Keystone link training/wait for link strategy,
so we initiate link training, then wait longer for the link to come up
before re-initiating link training.
[bhelgaas: changelog, split into its own patch, update pci-keystone.c, pcie-qcom.c]
Signed-off-by: Joao Pinto <jpinto@synopsys.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Acked-by: Pratyush Anand <pratyush.anand@gmail.com>
2016-03-10 13:44:35 -07:00
|
|
|
/* Parameters for the waiting for link up routine */
|
|
|
|
#define LINK_WAIT_MAX_RETRIES 10
|
|
|
|
#define LINK_WAIT_USLEEP_MIN 90000
|
|
|
|
#define LINK_WAIT_USLEEP_MAX 100000
|
|
|
|
|
2013-07-31 02:14:10 -06:00
|
|
|
struct pcie_port {
|
|
|
|
struct device *dev;
|
|
|
|
u8 root_bus_nr;
|
|
|
|
void __iomem *dbi_base;
|
|
|
|
u64 cfg0_base;
|
|
|
|
void __iomem *va_cfg0_base;
|
2014-09-05 17:48:54 -06:00
|
|
|
u32 cfg0_size;
|
2013-07-31 02:14:10 -06:00
|
|
|
u64 cfg1_base;
|
|
|
|
void __iomem *va_cfg1_base;
|
2014-09-05 17:48:54 -06:00
|
|
|
u32 cfg1_size;
|
2015-10-29 18:57:06 -06:00
|
|
|
resource_size_t io_base;
|
2014-09-05 17:48:54 -06:00
|
|
|
phys_addr_t io_bus_addr;
|
|
|
|
u32 io_size;
|
2013-07-31 02:14:10 -06:00
|
|
|
u64 mem_base;
|
2014-09-05 17:48:54 -06:00
|
|
|
phys_addr_t mem_bus_addr;
|
|
|
|
u32 mem_size;
|
2015-10-29 18:57:06 -06:00
|
|
|
struct resource *cfg;
|
|
|
|
struct resource *io;
|
|
|
|
struct resource *mem;
|
|
|
|
struct resource *busn;
|
2013-07-31 02:14:10 -06:00
|
|
|
int irq;
|
|
|
|
u32 lanes;
|
|
|
|
struct pcie_host_ops *ops;
|
2013-09-06 00:54:59 -06:00
|
|
|
int msi_irq;
|
2013-10-09 06:32:12 -06:00
|
|
|
struct irq_domain *irq_domain;
|
2013-09-06 00:54:59 -06:00
|
|
|
unsigned long msi_data;
|
|
|
|
DECLARE_BITMAP(msi_irq_in_use, MAX_MSI_IRQS);
|
2013-07-31 02:14:10 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
struct pcie_host_ops {
|
|
|
|
void (*readl_rc)(struct pcie_port *pp,
|
|
|
|
void __iomem *dbi_base, u32 *val);
|
|
|
|
void (*writel_rc)(struct pcie_port *pp,
|
|
|
|
u32 val, void __iomem *dbi_base);
|
|
|
|
int (*rd_own_conf)(struct pcie_port *pp, int where, int size, u32 *val);
|
|
|
|
int (*wr_own_conf)(struct pcie_port *pp, int where, int size, u32 val);
|
2014-07-21 10:58:41 -06:00
|
|
|
int (*rd_other_conf)(struct pcie_port *pp, struct pci_bus *bus,
|
|
|
|
unsigned int devfn, int where, int size, u32 *val);
|
|
|
|
int (*wr_other_conf)(struct pcie_port *pp, struct pci_bus *bus,
|
|
|
|
unsigned int devfn, int where, int size, u32 val);
|
2013-07-31 02:14:10 -06:00
|
|
|
int (*link_up)(struct pcie_port *pp);
|
|
|
|
void (*host_init)(struct pcie_port *pp);
|
2014-07-21 10:58:42 -06:00
|
|
|
void (*msi_set_irq)(struct pcie_port *pp, int irq);
|
|
|
|
void (*msi_clear_irq)(struct pcie_port *pp, int irq);
|
2015-09-18 12:58:35 -06:00
|
|
|
phys_addr_t (*get_msi_addr)(struct pcie_port *pp);
|
2014-09-23 08:28:59 -06:00
|
|
|
u32 (*get_msi_data)(struct pcie_port *pp, int pos);
|
2014-07-23 12:54:51 -06:00
|
|
|
void (*scan_bus)(struct pcie_port *pp);
|
2014-11-11 17:45:45 -07:00
|
|
|
int (*msi_host_init)(struct pcie_port *pp, struct msi_controller *chip);
|
2013-07-31 02:14:10 -06:00
|
|
|
};
|
|
|
|
|
2015-10-08 13:27:48 -06:00
|
|
|
int dw_pcie_cfg_read(void __iomem *addr, int size, u32 *val);
|
|
|
|
int dw_pcie_cfg_write(void __iomem *addr, int size, u32 val);
|
2014-03-28 10:52:58 -06:00
|
|
|
irqreturn_t dw_handle_msi_irq(struct pcie_port *pp);
|
2013-09-06 00:54:59 -06:00
|
|
|
void dw_pcie_msi_init(struct pcie_port *pp);
|
PCI: designware: Add generic dw_pcie_wait_for_link()
Several DesignWare-based drivers (dra7xx, exynos, imx6, keystone, qcom, and
spear13xx) had similar loops waiting for the link to come up.
Add a generic dw_pcie_wait_for_link() for use by all these drivers so the
waiting is done consistently, e.g., always using usleep_range() rather than
mdelay() and using similar timeouts and retry counts.
Note that this changes the Keystone link training/wait for link strategy,
so we initiate link training, then wait longer for the link to come up
before re-initiating link training.
[bhelgaas: changelog, split into its own patch, update pci-keystone.c, pcie-qcom.c]
Signed-off-by: Joao Pinto <jpinto@synopsys.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Acked-by: Pratyush Anand <pratyush.anand@gmail.com>
2016-03-10 13:44:35 -07:00
|
|
|
int dw_pcie_wait_for_link(struct pcie_port *pp);
|
2013-07-31 02:14:10 -06:00
|
|
|
int dw_pcie_link_up(struct pcie_port *pp);
|
|
|
|
void dw_pcie_setup_rc(struct pcie_port *pp);
|
|
|
|
int dw_pcie_host_init(struct pcie_port *pp);
|
2013-10-09 09:12:21 -06:00
|
|
|
|
|
|
|
#endif /* _PCIE_DESIGNWARE_H */
|