2011-09-20 00:45:05 +07:00
|
|
|
#ifndef __POWERNV_PCI_H
|
|
|
|
#define __POWERNV_PCI_H
|
|
|
|
|
|
|
|
struct pci_dn;
|
|
|
|
|
|
|
|
enum pnv_phb_type {
|
2016-02-08 11:08:20 +07:00
|
|
|
PNV_PHB_IODA1 = 0,
|
|
|
|
PNV_PHB_IODA2 = 1,
|
|
|
|
PNV_PHB_NPU = 2,
|
2011-09-20 00:45:05 +07:00
|
|
|
};
|
|
|
|
|
2011-11-30 01:22:53 +07:00
|
|
|
/* Precise PHB model for error management */
|
|
|
|
enum pnv_phb_model {
|
|
|
|
PNV_PHB_MODEL_UNKNOWN,
|
|
|
|
PNV_PHB_MODEL_P7IOC,
|
2013-04-26 02:20:57 +07:00
|
|
|
PNV_PHB_MODEL_PHB3,
|
2015-12-17 09:43:13 +07:00
|
|
|
PNV_PHB_MODEL_NPU,
|
2011-11-30 01:22:53 +07:00
|
|
|
};
|
|
|
|
|
2013-09-06 08:00:03 +07:00
|
|
|
#define PNV_PCI_DIAG_BUF_SIZE 8192
|
2012-08-20 10:49:15 +07:00
|
|
|
#define PNV_IODA_PE_DEV (1 << 0) /* PE has single PCI device */
|
|
|
|
#define PNV_IODA_PE_BUS (1 << 1) /* PE has primary PCI bus */
|
|
|
|
#define PNV_IODA_PE_BUS_ALL (1 << 2) /* PE has subordinate buses */
|
2014-07-21 11:42:30 +07:00
|
|
|
#define PNV_IODA_PE_MASTER (1 << 3) /* Master PE in compound case */
|
|
|
|
#define PNV_IODA_PE_SLAVE (1 << 4) /* Slave PE in compound case */
|
2015-03-25 15:23:57 +07:00
|
|
|
#define PNV_IODA_PE_VF (1 << 5) /* PE for one VF */
|
2011-11-30 01:22:53 +07:00
|
|
|
|
2011-11-16 00:29:08 +07:00
|
|
|
/* Data associated with a PE, including IOMMU tracking etc.. */
|
2013-04-26 02:21:00 +07:00
|
|
|
struct pnv_phb;
|
2011-11-16 00:29:08 +07:00
|
|
|
struct pnv_ioda_pe {
|
2012-08-20 10:49:15 +07:00
|
|
|
unsigned long flags;
|
2013-04-26 02:21:00 +07:00
|
|
|
struct pnv_phb *phb;
|
2012-08-20 10:49:15 +07:00
|
|
|
|
2011-11-16 00:29:08 +07:00
|
|
|
/* A PE can be associated with a single device or an
|
|
|
|
* entire bus (& children). In the former case, pdev
|
|
|
|
* is populated, in the later case, pbus is.
|
|
|
|
*/
|
2015-03-25 15:23:57 +07:00
|
|
|
#ifdef CONFIG_PCI_IOV
|
|
|
|
struct pci_dev *parent_dev;
|
|
|
|
#endif
|
2011-11-16 00:29:08 +07:00
|
|
|
struct pci_dev *pdev;
|
|
|
|
struct pci_bus *pbus;
|
|
|
|
|
|
|
|
/* Effective RID (device RID for a device PE and base bus
|
|
|
|
* RID with devfn 0 for a bus PE)
|
|
|
|
*/
|
|
|
|
unsigned int rid;
|
|
|
|
|
|
|
|
/* PE number */
|
|
|
|
unsigned int pe_number;
|
|
|
|
|
|
|
|
/* "Base" iommu table, ie, 4K TCEs, 32-bit DMA */
|
2015-06-05 13:35:08 +07:00
|
|
|
struct iommu_table_group table_group;
|
2011-11-16 00:29:08 +07:00
|
|
|
|
2014-02-11 07:32:38 +07:00
|
|
|
/* 64-bit TCE bypass region */
|
|
|
|
bool tce_bypass_enabled;
|
|
|
|
uint64_t tce_bypass_base;
|
2011-11-16 00:29:08 +07:00
|
|
|
|
|
|
|
/* MSIs. MVE index is identical for for 32 and 64 bit MSI
|
|
|
|
* and -1 if not supported. (It's actually identical to the
|
|
|
|
* PE number)
|
|
|
|
*/
|
|
|
|
int mve_number;
|
|
|
|
|
2014-07-21 11:42:30 +07:00
|
|
|
/* PEs in compound case */
|
|
|
|
struct pnv_ioda_pe *master;
|
|
|
|
struct list_head slaves;
|
|
|
|
|
2011-11-16 00:29:08 +07:00
|
|
|
/* Link in list of PE#s */
|
2012-08-20 10:49:15 +07:00
|
|
|
struct list_head list;
|
2011-11-16 00:29:08 +07:00
|
|
|
};
|
|
|
|
|
2014-04-24 15:00:09 +07:00
|
|
|
#define PNV_PHB_FLAG_EEH (1 << 0)
|
|
|
|
|
2011-09-20 00:45:05 +07:00
|
|
|
struct pnv_phb {
|
|
|
|
struct pci_controller *hose;
|
|
|
|
enum pnv_phb_type type;
|
2011-11-30 01:22:53 +07:00
|
|
|
enum pnv_phb_model model;
|
2013-06-20 12:21:06 +07:00
|
|
|
u64 hub_id;
|
2011-09-20 00:45:05 +07:00
|
|
|
u64 opal_id;
|
2014-04-24 15:00:09 +07:00
|
|
|
int flags;
|
2011-09-20 00:45:05 +07:00
|
|
|
void __iomem *regs;
|
2012-08-20 10:49:18 +07:00
|
|
|
int initialized;
|
2011-09-20 00:45:05 +07:00
|
|
|
spinlock_t lock;
|
|
|
|
|
2013-06-20 17:13:25 +07:00
|
|
|
#ifdef CONFIG_DEBUG_FS
|
2014-04-24 15:00:18 +07:00
|
|
|
int has_dbgfs;
|
2013-06-20 17:13:25 +07:00
|
|
|
struct dentry *dbgfs;
|
|
|
|
#endif
|
|
|
|
|
2011-09-20 00:45:06 +07:00
|
|
|
#ifdef CONFIG_PCI_MSI
|
|
|
|
unsigned int msi_base;
|
|
|
|
unsigned int msi32_support;
|
2013-03-06 04:12:37 +07:00
|
|
|
struct msi_bitmap msi_bmp;
|
2011-09-20 00:45:06 +07:00
|
|
|
#endif
|
|
|
|
int (*msi_setup)(struct pnv_phb *phb, struct pci_dev *dev,
|
2013-04-26 02:20:59 +07:00
|
|
|
unsigned int hwirq, unsigned int virq,
|
|
|
|
unsigned int is_64, struct msi_msg *msg);
|
2011-09-20 00:45:05 +07:00
|
|
|
void (*dma_dev_setup)(struct pnv_phb *phb, struct pci_dev *pdev);
|
|
|
|
void (*fixup_phb)(struct pci_controller *hose);
|
2014-07-21 11:42:30 +07:00
|
|
|
int (*init_m64)(struct pnv_phb *phb);
|
2015-06-19 09:26:17 +07:00
|
|
|
void (*reserve_m64_pe)(struct pci_bus *bus,
|
|
|
|
unsigned long *pe_bitmap, bool all);
|
2016-05-03 12:41:36 +07:00
|
|
|
struct pnv_ioda_pe *(*pick_m64_pe)(struct pci_bus *bus, bool all);
|
2014-07-21 11:42:33 +07:00
|
|
|
int (*get_pe_state)(struct pnv_phb *phb, int pe_no);
|
|
|
|
void (*freeze_pe)(struct pnv_phb *phb, int pe_no);
|
|
|
|
int (*unfreeze_pe)(struct pnv_phb *phb, int pe_no, int opt);
|
2011-09-20 00:45:05 +07:00
|
|
|
|
2016-02-08 11:08:20 +07:00
|
|
|
struct {
|
|
|
|
/* Global bridge info */
|
2016-05-03 12:41:24 +07:00
|
|
|
unsigned int total_pe_num;
|
|
|
|
unsigned int reserved_pe_idx;
|
2016-02-08 11:08:20 +07:00
|
|
|
|
|
|
|
/* 32-bit MMIO window */
|
|
|
|
unsigned int m32_size;
|
|
|
|
unsigned int m32_segsize;
|
|
|
|
unsigned int m32_pci_base;
|
|
|
|
|
|
|
|
/* 64-bit MMIO window */
|
|
|
|
unsigned int m64_bar_idx;
|
|
|
|
unsigned long m64_size;
|
|
|
|
unsigned long m64_segsize;
|
|
|
|
unsigned long m64_base;
|
|
|
|
unsigned long m64_bar_alloc;
|
|
|
|
|
|
|
|
/* IO ports */
|
|
|
|
unsigned int io_size;
|
|
|
|
unsigned int io_segsize;
|
|
|
|
unsigned int io_pci_base;
|
|
|
|
|
2016-05-03 12:41:23 +07:00
|
|
|
/* PE allocation */
|
2016-02-08 11:08:20 +07:00
|
|
|
struct mutex pe_alloc_mutex;
|
2016-05-03 12:41:23 +07:00
|
|
|
unsigned long *pe_alloc;
|
|
|
|
struct pnv_ioda_pe *pe_array;
|
2016-02-08 11:08:20 +07:00
|
|
|
|
|
|
|
/* M32 & IO segment maps */
|
2016-05-03 12:41:29 +07:00
|
|
|
unsigned int *m64_segmap;
|
2016-02-08 11:08:20 +07:00
|
|
|
unsigned int *m32_segmap;
|
|
|
|
unsigned int *io_segmap;
|
|
|
|
|
2016-05-05 09:04:16 +07:00
|
|
|
/* DMA32 segment maps - IODA1 only */
|
|
|
|
unsigned int dma32_count;
|
|
|
|
unsigned int *dma32_segmap;
|
|
|
|
|
2016-02-08 11:08:20 +07:00
|
|
|
/* IRQ chip */
|
|
|
|
int irq_chip_init;
|
|
|
|
struct irq_chip irq_chip;
|
|
|
|
|
|
|
|
/* Sorted list of used PE's based
|
|
|
|
* on the sequence of creation
|
|
|
|
*/
|
|
|
|
struct list_head pe_list;
|
|
|
|
struct mutex pe_list_mutex;
|
|
|
|
|
2016-05-20 13:41:29 +07:00
|
|
|
/* Reverse map of PEs, indexed by {bus, devfn} */
|
|
|
|
unsigned int pe_rmap[0x10000];
|
2016-02-08 11:08:20 +07:00
|
|
|
|
|
|
|
/* TCE cache invalidate registers (physical and
|
|
|
|
* remapped)
|
|
|
|
*/
|
|
|
|
phys_addr_t tce_inval_reg_phys;
|
|
|
|
__be64 __iomem *tce_inval_reg;
|
|
|
|
} ioda;
|
2011-11-30 01:22:53 +07:00
|
|
|
|
2013-12-21 02:06:01 +07:00
|
|
|
/* PHB and hub status structure */
|
2011-11-30 01:22:53 +07:00
|
|
|
union {
|
|
|
|
unsigned char blob[PNV_PCI_DIAG_BUF_SIZE];
|
|
|
|
struct OpalIoP7IOCPhbErrorData p7ioc;
|
2013-11-22 15:28:45 +07:00
|
|
|
struct OpalIoPhb3ErrorData phb3;
|
2013-12-21 02:06:01 +07:00
|
|
|
struct OpalIoP7IOCErrorData hub_diag;
|
2011-11-30 01:22:53 +07:00
|
|
|
} diag;
|
2013-12-21 02:06:01 +07:00
|
|
|
|
2011-09-20 00:45:05 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
extern struct pci_ops pnv_pci_ops;
|
2015-06-05 13:35:06 +07:00
|
|
|
extern int pnv_tce_build(struct iommu_table *tbl, long index, long npages,
|
|
|
|
unsigned long uaddr, enum dma_data_direction direction,
|
|
|
|
struct dma_attrs *attrs);
|
|
|
|
extern void pnv_tce_free(struct iommu_table *tbl, long index, long npages);
|
2015-06-05 13:35:15 +07:00
|
|
|
extern int pnv_tce_xchg(struct iommu_table *tbl, long index,
|
|
|
|
unsigned long *hpa, enum dma_data_direction *direction);
|
2015-06-05 13:35:06 +07:00
|
|
|
extern unsigned long pnv_tce_get(struct iommu_table *tbl, long index);
|
2011-09-20 00:45:05 +07:00
|
|
|
|
2013-11-22 15:28:45 +07:00
|
|
|
void pnv_pci_dump_phb_diag_data(struct pci_controller *hose,
|
|
|
|
unsigned char *log_buff);
|
2015-03-17 12:15:03 +07:00
|
|
|
int pnv_pci_cfg_read(struct pci_dn *pdn,
|
2013-06-27 12:46:48 +07:00
|
|
|
int where, int size, u32 *val);
|
2015-03-17 12:15:03 +07:00
|
|
|
int pnv_pci_cfg_write(struct pci_dn *pdn,
|
2013-06-27 12:46:48 +07:00
|
|
|
int where, int size, u32 val);
|
2015-06-05 13:35:09 +07:00
|
|
|
extern struct iommu_table *pnv_pci_table_alloc(int nid);
|
|
|
|
|
|
|
|
extern long pnv_pci_link_table_and_group(int node, int num,
|
|
|
|
struct iommu_table *tbl,
|
|
|
|
struct iommu_table_group *table_group);
|
|
|
|
extern void pnv_pci_unlink_table_and_group(struct iommu_table *tbl,
|
|
|
|
struct iommu_table_group *table_group);
|
2011-09-20 00:45:05 +07:00
|
|
|
extern void pnv_pci_setup_iommu_table(struct iommu_table *tbl,
|
|
|
|
void *tce_mem, u64 tce_size,
|
2014-06-06 15:44:03 +07:00
|
|
|
u64 dma_offset, unsigned page_shift);
|
2011-11-16 00:29:08 +07:00
|
|
|
extern void pnv_pci_init_ioda_hub(struct device_node *np);
|
2013-04-26 02:20:57 +07:00
|
|
|
extern void pnv_pci_init_ioda2_phb(struct device_node *np);
|
2015-12-17 09:43:13 +07:00
|
|
|
extern void pnv_pci_init_npu_phb(struct device_node *np);
|
2013-04-26 02:21:00 +07:00
|
|
|
extern void pnv_pci_ioda_tce_invalidate(struct iommu_table *tbl,
|
2013-10-11 14:23:53 +07:00
|
|
|
__be64 *startp, __be64 *endp, bool rm);
|
2014-04-24 15:00:24 +07:00
|
|
|
extern void pnv_pci_reset_secondary_bus(struct pci_dev *dev);
|
2015-02-16 10:45:47 +07:00
|
|
|
extern int pnv_eeh_phb_reset(struct pci_controller *hose, int option);
|
2013-05-10 13:59:18 +07:00
|
|
|
|
2015-04-28 12:12:05 +07:00
|
|
|
extern void pnv_pci_dma_dev_setup(struct pci_dev *pdev);
|
2016-02-09 11:50:22 +07:00
|
|
|
extern void pnv_pci_dma_bus_setup(struct pci_bus *bus);
|
2015-04-28 12:12:05 +07:00
|
|
|
extern int pnv_setup_msi_irqs(struct pci_dev *pdev, int nvec, int type);
|
|
|
|
extern void pnv_teardown_msi_irqs(struct pci_dev *pdev);
|
|
|
|
|
2016-04-29 15:55:21 +07:00
|
|
|
extern void pe_level_printk(const struct pnv_ioda_pe *pe, const char *level,
|
|
|
|
const char *fmt, ...);
|
|
|
|
#define pe_err(pe, fmt, ...) \
|
|
|
|
pe_level_printk(pe, KERN_ERR, fmt, ##__VA_ARGS__)
|
|
|
|
#define pe_warn(pe, fmt, ...) \
|
|
|
|
pe_level_printk(pe, KERN_WARNING, fmt, ##__VA_ARGS__)
|
|
|
|
#define pe_info(pe, fmt, ...) \
|
|
|
|
pe_level_printk(pe, KERN_INFO, fmt, ##__VA_ARGS__)
|
|
|
|
|
2015-12-17 09:43:13 +07:00
|
|
|
/* Nvlink functions */
|
2016-04-29 15:55:20 +07:00
|
|
|
extern void pnv_npu_try_dma_set_bypass(struct pci_dev *gpdev, bool bypass);
|
2016-04-29 15:55:18 +07:00
|
|
|
extern void pnv_pci_ioda2_tce_invalidate_entire(struct pnv_phb *phb, bool rm);
|
2016-04-29 15:55:24 +07:00
|
|
|
extern struct pnv_ioda_pe *pnv_pci_npu_setup_iommu(struct pnv_ioda_pe *npe);
|
|
|
|
extern long pnv_npu_set_window(struct pnv_ioda_pe *npe, int num,
|
|
|
|
struct iommu_table *tbl);
|
|
|
|
extern long pnv_npu_unset_window(struct pnv_ioda_pe *npe, int num);
|
|
|
|
extern void pnv_npu_take_ownership(struct pnv_ioda_pe *npe);
|
|
|
|
extern void pnv_npu_release_ownership(struct pnv_ioda_pe *npe);
|
2015-12-17 09:43:13 +07:00
|
|
|
|
2011-09-20 00:45:05 +07:00
|
|
|
#endif /* __POWERNV_PCI_H */
|