18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * Marvell MBUS common definitions.
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * Copyright (C) 2008 Marvell Semiconductor
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * This file is licensed under the terms of the GNU General Public
78c2ecf20Sopenharmony_ci * License version 2.  This program is licensed "as is" without any
88c2ecf20Sopenharmony_ci * warranty of any kind, whether express or implied.
98c2ecf20Sopenharmony_ci */
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#ifndef __LINUX_MBUS_H
128c2ecf20Sopenharmony_ci#define __LINUX_MBUS_H
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci#include <linux/errno.h>
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_cistruct resource;
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_cistruct mbus_dram_target_info
198c2ecf20Sopenharmony_ci{
208c2ecf20Sopenharmony_ci	/*
218c2ecf20Sopenharmony_ci	 * The 4-bit MBUS target ID of the DRAM controller.
228c2ecf20Sopenharmony_ci	 */
238c2ecf20Sopenharmony_ci	u8		mbus_dram_target_id;
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci	/*
268c2ecf20Sopenharmony_ci	 * The base address, size, and MBUS attribute ID for each
278c2ecf20Sopenharmony_ci	 * of the possible DRAM chip selects.  Peripherals are
288c2ecf20Sopenharmony_ci	 * required to support at least 4 decode windows.
298c2ecf20Sopenharmony_ci	 */
308c2ecf20Sopenharmony_ci	int		num_cs;
318c2ecf20Sopenharmony_ci	struct mbus_dram_window {
328c2ecf20Sopenharmony_ci		u8	cs_index;
338c2ecf20Sopenharmony_ci		u8	mbus_attr;
348c2ecf20Sopenharmony_ci		u64	base;
358c2ecf20Sopenharmony_ci		u64	size;
368c2ecf20Sopenharmony_ci	} cs[4];
378c2ecf20Sopenharmony_ci};
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci/* Flags for PCI/PCIe address decoding regions */
408c2ecf20Sopenharmony_ci#define MVEBU_MBUS_PCI_IO  0x1
418c2ecf20Sopenharmony_ci#define MVEBU_MBUS_PCI_MEM 0x2
428c2ecf20Sopenharmony_ci#define MVEBU_MBUS_PCI_WA  0x3
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci/*
458c2ecf20Sopenharmony_ci * Magic value that explicits that we don't need a remapping-capable
468c2ecf20Sopenharmony_ci * address decoding window.
478c2ecf20Sopenharmony_ci */
488c2ecf20Sopenharmony_ci#define MVEBU_MBUS_NO_REMAP (0xffffffff)
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci/* Maximum size of a mbus window name */
518c2ecf20Sopenharmony_ci#define MVEBU_MBUS_MAX_WINNAME_SZ 32
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_ci/*
548c2ecf20Sopenharmony_ci * The Marvell mbus is to be found only on SOCs from the Orion family
558c2ecf20Sopenharmony_ci * at the moment.  Provide a dummy stub for other architectures.
568c2ecf20Sopenharmony_ci */
578c2ecf20Sopenharmony_ci#ifdef CONFIG_PLAT_ORION
588c2ecf20Sopenharmony_ciextern const struct mbus_dram_target_info *mv_mbus_dram_info(void);
598c2ecf20Sopenharmony_ciextern const struct mbus_dram_target_info *mv_mbus_dram_info_nooverlap(void);
608c2ecf20Sopenharmony_ciint mvebu_mbus_get_io_win_info(phys_addr_t phyaddr, u32 *size, u8 *target,
618c2ecf20Sopenharmony_ci			       u8 *attr);
628c2ecf20Sopenharmony_ci#else
638c2ecf20Sopenharmony_cistatic inline const struct mbus_dram_target_info *mv_mbus_dram_info(void)
648c2ecf20Sopenharmony_ci{
658c2ecf20Sopenharmony_ci	return NULL;
668c2ecf20Sopenharmony_ci}
678c2ecf20Sopenharmony_cistatic inline const struct mbus_dram_target_info *mv_mbus_dram_info_nooverlap(void)
688c2ecf20Sopenharmony_ci{
698c2ecf20Sopenharmony_ci	return NULL;
708c2ecf20Sopenharmony_ci}
718c2ecf20Sopenharmony_cistatic inline int mvebu_mbus_get_io_win_info(phys_addr_t phyaddr, u32 *size,
728c2ecf20Sopenharmony_ci					     u8 *target, u8 *attr)
738c2ecf20Sopenharmony_ci{
748c2ecf20Sopenharmony_ci	/*
758c2ecf20Sopenharmony_ci	 * On all ARM32 MVEBU platforms with MBus support, this stub
768c2ecf20Sopenharmony_ci	 * function will not get called. The real function from the
778c2ecf20Sopenharmony_ci	 * MBus driver is called instead. ARM64 MVEBU platforms like
788c2ecf20Sopenharmony_ci	 * the Armada 3700 could use the mv_xor device driver which calls
798c2ecf20Sopenharmony_ci	 * into this function
808c2ecf20Sopenharmony_ci	 */
818c2ecf20Sopenharmony_ci	return -EINVAL;
828c2ecf20Sopenharmony_ci}
838c2ecf20Sopenharmony_ci#endif
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_ci#ifdef CONFIG_MVEBU_MBUS
868c2ecf20Sopenharmony_ciint mvebu_mbus_save_cpu_target(u32 __iomem *store_addr);
878c2ecf20Sopenharmony_civoid mvebu_mbus_get_pcie_mem_aperture(struct resource *res);
888c2ecf20Sopenharmony_civoid mvebu_mbus_get_pcie_io_aperture(struct resource *res);
898c2ecf20Sopenharmony_ciint mvebu_mbus_get_dram_win_info(phys_addr_t phyaddr, u8 *target, u8 *attr);
908c2ecf20Sopenharmony_ciint mvebu_mbus_add_window_remap_by_id(unsigned int target,
918c2ecf20Sopenharmony_ci				      unsigned int attribute,
928c2ecf20Sopenharmony_ci				      phys_addr_t base, size_t size,
938c2ecf20Sopenharmony_ci				      phys_addr_t remap);
948c2ecf20Sopenharmony_ciint mvebu_mbus_add_window_by_id(unsigned int target, unsigned int attribute,
958c2ecf20Sopenharmony_ci				phys_addr_t base, size_t size);
968c2ecf20Sopenharmony_ciint mvebu_mbus_del_window(phys_addr_t base, size_t size);
978c2ecf20Sopenharmony_ciint mvebu_mbus_init(const char *soc, phys_addr_t mbus_phys_base,
988c2ecf20Sopenharmony_ci		    size_t mbus_size, phys_addr_t sdram_phys_base,
998c2ecf20Sopenharmony_ci		    size_t sdram_size);
1008c2ecf20Sopenharmony_ciint mvebu_mbus_dt_init(bool is_coherent);
1018c2ecf20Sopenharmony_ci#else
1028c2ecf20Sopenharmony_cistatic inline int mvebu_mbus_get_dram_win_info(phys_addr_t phyaddr, u8 *target,
1038c2ecf20Sopenharmony_ci					       u8 *attr)
1048c2ecf20Sopenharmony_ci{
1058c2ecf20Sopenharmony_ci	return -EINVAL;
1068c2ecf20Sopenharmony_ci}
1078c2ecf20Sopenharmony_ci#endif /* CONFIG_MVEBU_MBUS */
1088c2ecf20Sopenharmony_ci
1098c2ecf20Sopenharmony_ci#endif /* __LINUX_MBUS_H */
110