162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci#ifndef _PSYCHO_COMMON_H
362306a36Sopenharmony_ci#define _PSYCHO_COMMON_H
462306a36Sopenharmony_ci
562306a36Sopenharmony_ci/* U2P Programmer's Manual, page 13-55, configuration space
662306a36Sopenharmony_ci * address format:
762306a36Sopenharmony_ci *
862306a36Sopenharmony_ci *  32             24 23 16 15    11 10       8 7   2  1 0
962306a36Sopenharmony_ci * ---------------------------------------------------------
1062306a36Sopenharmony_ci * |0 0 0 0 0 0 0 0 1| bus | device | function | reg | 0 0 |
1162306a36Sopenharmony_ci * ---------------------------------------------------------
1262306a36Sopenharmony_ci */
1362306a36Sopenharmony_ci#define PSYCHO_CONFIG_BASE(PBM)	\
1462306a36Sopenharmony_ci	((PBM)->config_space | (1UL << 24))
1562306a36Sopenharmony_ci#define PSYCHO_CONFIG_ENCODE(BUS, DEVFN, REG)	\
1662306a36Sopenharmony_ci	(((unsigned long)(BUS)   << 16) |	\
1762306a36Sopenharmony_ci	 ((unsigned long)(DEVFN) << 8)  |	\
1862306a36Sopenharmony_ci	 ((unsigned long)(REG)))
1962306a36Sopenharmony_ci
2062306a36Sopenharmony_cistatic inline void *psycho_pci_config_mkaddr(struct pci_pbm_info *pbm,
2162306a36Sopenharmony_ci					     unsigned char bus,
2262306a36Sopenharmony_ci					     unsigned int devfn,
2362306a36Sopenharmony_ci					     int where)
2462306a36Sopenharmony_ci{
2562306a36Sopenharmony_ci	return (void *)
2662306a36Sopenharmony_ci		(PSYCHO_CONFIG_BASE(pbm) |
2762306a36Sopenharmony_ci		 PSYCHO_CONFIG_ENCODE(bus, devfn, where));
2862306a36Sopenharmony_ci}
2962306a36Sopenharmony_ci
3062306a36Sopenharmony_cienum psycho_error_type {
3162306a36Sopenharmony_ci	UE_ERR, CE_ERR, PCI_ERR
3262306a36Sopenharmony_ci};
3362306a36Sopenharmony_ci
3462306a36Sopenharmony_civoid psycho_check_iommu_error(struct pci_pbm_info *pbm,
3562306a36Sopenharmony_ci			      unsigned long afsr,
3662306a36Sopenharmony_ci			      unsigned long afar,
3762306a36Sopenharmony_ci			      enum psycho_error_type type);
3862306a36Sopenharmony_ci
3962306a36Sopenharmony_ciirqreturn_t psycho_pcierr_intr(int irq, void *dev_id);
4062306a36Sopenharmony_ci
4162306a36Sopenharmony_ciint psycho_iommu_init(struct pci_pbm_info *pbm, int tsbsize,
4262306a36Sopenharmony_ci		      u32 dvma_offset, u32 dma_mask,
4362306a36Sopenharmony_ci		      unsigned long write_complete_offset);
4462306a36Sopenharmony_ci
4562306a36Sopenharmony_civoid psycho_pbm_init_common(struct pci_pbm_info *pbm,
4662306a36Sopenharmony_ci			    struct platform_device *op,
4762306a36Sopenharmony_ci			    const char *chip_name, int chip_type);
4862306a36Sopenharmony_ci
4962306a36Sopenharmony_ci#endif /* _PSYCHO_COMMON_H */
50