/* SPDX-License-Identifier: GPL-2.0-only */
/* Copyright (C) 2026 Intel Corporation */

#ifndef IPU7_MMU_HW_H
#define IPU7_MMU_HW_H

#define IPU7_MMU_REG_IRQ_MASK			0x2c
#define IPU7_MMU_REG_IRQ_ENABLE			0x30
#define IPU7_MMU_REG_PAGE_TABLE_BASE_ADDR	0x08
#define IPU7_MMU_REG_USER_INFO_BITS		0x0c
#define IPU7_MMU_REG_AXI_REFILL_IF_ID		0x10
#define IPU7_MMU_REG_COLLAPSE_ENABLE_BITMAP	0x18
#define IPU7_MMU_REG_AT_SP_ARB_CFG		0x20

#define IPU7_ZLX_REG_AXI_POOL			0x0
#define IPU7_ZLX_REG_EN				0x20
#define IPU7_ZLX_REG_CONF			0x24
#define IPU7_ZLX_POOL_NUM			8U

#define IPU7_MMU_MAX_TLB_L1_STREAMS		40U
#define IPU7_MMU_MAX_TLB_L2_STREAMS		40U
#define IPU7_UAO_PLANE_MAX_NUM			64U
#define IPU7_ZLX_MAX_NUM			32U

#define IPU7_MMU_REG_INVALIDATE_0		0x00
#define IPU7_MMU_REG_INVALIDATE_1		0x04
#define IPU7_MMU_REG_INVALIDATION_STATUS	0x24
#define IPU7_MMU_TLB_INVALIDATE_TIMEOUT		2000

#define IPU7_FW_CODE_REGION_SIZE	0x1000000 /* 16MB */
#define IPU7_FW_CODE_REGION_START	0x4000000 /* 64MB */
#define IPU7_FW_CODE_REGION_END		(IPU7_FW_CODE_REGION_START +	\
					 IPU7_FW_CODE_REGION_SIZE) /* 80MB */

#define IPU7_IS_MMU_FW_RD_OFFSET		0x274000
#define IPU7_IS_MMU_FW_RD_STREAM_NUM		3
#define IPU7_IS_MMU_FW_RD_L1_BLOCKNR_REG	0x54
#define IPU7_IS_MMU_FW_RD_L2_BLOCKNR_REG	0x60

#define IPU7_IS_MMU_FW_WR_OFFSET		0x275000
#define IPU7_IS_MMU_FW_WR_STREAM_NUM		3
#define IPU7_IS_MMU_FW_WR_L1_BLOCKNR_REG	0x54
#define IPU7_IS_MMU_FW_WR_L2_BLOCKNR_REG	0x60

#define IPU7_IS_MMU_M0_OFFSET			0x276000
#define IPU7_IS_MMU_M0_STREAM_NUM		8
#define IPU7_IS_MMU_M0_L1_BLOCKNR_REG		0x54
#define IPU7_IS_MMU_M0_L2_BLOCKNR_REG		0x74

#define IPU7_IS_MMU_M1_OFFSET			0x277000
#define IPU7_IS_MMU_M1_STREAM_NUM		16
#define IPU7_IS_MMU_M1_L1_BLOCKNR_REG		0x54
#define IPU7_IS_MMU_M1_L2_BLOCKNR_REG		0x94

#define IPU7_PS_MMU_FW_RD_OFFSET		0x148000
#define IPU7_PS_MMU_FW_RD_STREAM_NUM		20
#define IPU7_PS_MMU_FW_RD_L1_BLOCKNR_REG	0x54
#define IPU7_PS_MMU_FW_RD_L2_BLOCKNR_REG	0xa4

#define IPU7_PS_MMU_FW_WR_OFFSET		0x149000
#define IPU7_PS_MMU_FW_WR_STREAM_NUM		10
#define IPU7_PS_MMU_FW_WR_L1_BLOCKNR_REG	0x54
#define IPU7_PS_MMU_FW_WR_L2_BLOCKNR_REG	0x7c

#define IPU7_PS_MMU_SRT_RD_OFFSET		0x14a000
#define IPU7_PS_MMU_SRT_RD_STREAM_NUM		40
#define IPU7_PS_MMU_SRT_RD_L1_BLOCKNR_REG	0x54
#define IPU7_PS_MMU_SRT_RD_L2_BLOCKNR_REG	0xf4

#define IPU7_PS_MMU_SRT_WR_OFFSET		0x14b000
#define IPU7_PS_MMU_SRT_WR_STREAM_NUM		40
#define IPU7_PS_MMU_SRT_WR_L1_BLOCKNR_REG	0x54
#define IPU7_PS_MMU_SRT_WR_L2_BLOCKNR_REG	0xf4

#define IPU7_IS_UAO_UC_RD_OFFSET		0x27c000
#define IPU7_IS_UAO_UC_RD_PLANENUM		4

#define IPU7_IS_UAO_UC_WR_OFFSET		0x27d000
#define IPU7_IS_UAO_UC_WR_PLANENUM		4

#define IPU7_IS_UAO_M0_WR_OFFSET		0x27e000
#define IPU7_IS_UAO_M0_WR_PLANENUM		8

#define IPU7_IS_UAO_M1_WR_OFFSET		0x27f000
#define IPU7_IS_UAO_M1_WR_PLANENUM		16

#define IPU7_PS_UAO_FW_RD_OFFSET		0x156000
#define IPU7_PS_UAO_FW_RD_PLANENUM		20

#define IPU7_PS_UAO_FW_WR_OFFSET		0x157000
#define IPU7_PS_UAO_FW_WR_PLANENUM		16

#define IPU7_PS_UAO_SRT_RD_OFFSET		0x154000
#define IPU7_PS_UAO_SRT_RD_PLANENUM		40

#define IPU7_PS_UAO_SRT_WR_OFFSET		0x155000
#define IPU7_PS_UAO_SRT_WR_PLANENUM		40

#define IPU7_IS_ZLX_UC_RD_OFFSET		0x278000
#define IPU7_IS_ZLX_UC_WR_OFFSET		0x279000
#define IPU7_IS_ZLX_M0_OFFSET			0x27a000
#define IPU7_IS_ZLX_M1_OFFSET			0x27b000
#define IPU7_IS_ZLX_UC_RD_NUM			4
#define IPU7_IS_ZLX_UC_WR_NUM			4
#define IPU7_IS_ZLX_M0_NUM			8
#define IPU7_IS_ZLX_M1_NUM			16

#define IPU7_PS_ZLX_DATA_RD_OFFSET		0x14e000
#define IPU7_PS_ZLX_DATA_WR_OFFSET		0x14f000
#define IPU7_PS_ZLX_FW_RD_OFFSET		0x150000
#define IPU7_PS_ZLX_FW_WR_OFFSET		0x151000
#define IPU7_PS_ZLX_DATA_RD_NUM			32
#define IPU7_PS_ZLX_DATA_WR_NUM			32
#define IPU7_PS_ZLX_FW_RD_NUM			16
#define IPU7_PS_ZLX_FW_WR_NUM			10

/* IPU7P5 */
/* IS MMU Cmd RD */
#define IPU7P5_IS_MMU_FW_RD_OFFSET		0x274000
#define IPU7P5_IS_MMU_FW_RD_STREAM_NUM		3
#define IPU7P5_IS_MMU_FW_RD_L1_BLOCKNR_REG	0x54
#define IPU7P5_IS_MMU_FW_RD_L2_BLOCKNR_REG	0x60

/* IS MMU Cmd WR */
#define IPU7P5_IS_MMU_FW_WR_OFFSET		0x275000
#define IPU7P5_IS_MMU_FW_WR_STREAM_NUM		3
#define IPU7P5_IS_MMU_FW_WR_L1_BLOCKNR_REG	0x54
#define IPU7P5_IS_MMU_FW_WR_L2_BLOCKNR_REG	0x60

/* IS MMU Data WR Snoop */
#define IPU7P5_IS_MMU_M0_OFFSET			0x276000
#define IPU7P5_IS_MMU_M0_STREAM_NUM		16
#define IPU7P5_IS_MMU_M0_L1_BLOCKNR_REG		0x54
#define IPU7P5_IS_MMU_M0_L2_BLOCKNR_REG		0x94

/* IS MMU Data WR ISOC */
#define IPU7P5_IS_MMU_M1_OFFSET			0x277000
#define IPU7P5_IS_MMU_M1_STREAM_NUM		16
#define IPU7P5_IS_MMU_M1_L1_BLOCKNR_REG		0x54
#define IPU7P5_IS_MMU_M1_L2_BLOCKNR_REG		0x94

/* PS MMU FW RD */
#define IPU7P5_PS_MMU_FW_RD_OFFSET		0x148000
#define IPU7P5_PS_MMU_FW_RD_STREAM_NUM		16
#define IPU7P5_PS_MMU_FW_RD_L1_BLOCKNR_REG	0x54
#define IPU7P5_PS_MMU_FW_RD_L2_BLOCKNR_REG	0x94

/* PS MMU FW WR */
#define IPU7P5_PS_MMU_FW_WR_OFFSET		0x149000
#define IPU7P5_PS_MMU_FW_WR_STREAM_NUM		10
#define IPU7P5_PS_MMU_FW_WR_L1_BLOCKNR_REG	0x54
#define IPU7P5_PS_MMU_FW_WR_L2_BLOCKNR_REG	0x7c

/* PS MMU FW Data RD VC0 */
#define IPU7P5_PS_MMU_SRT_RD_OFFSET		0x14a000
#define IPU7P5_PS_MMU_SRT_RD_STREAM_NUM		22
#define IPU7P5_PS_MMU_SRT_RD_L1_BLOCKNR_REG	0x54
#define IPU7P5_PS_MMU_SRT_RD_L2_BLOCKNR_REG	0xac

/* PS MMU FW Data WR VC0 */
#define IPU7P5_PS_MMU_SRT_WR_OFFSET		0x14b000
#define IPU7P5_PS_MMU_SRT_WR_STREAM_NUM		32
#define IPU7P5_PS_MMU_SRT_WR_L1_BLOCKNR_REG	0x54
#define IPU7P5_PS_MMU_SRT_WR_L2_BLOCKNR_REG	0xd4

/* IS UAO UC RD */
#define IPU7P5_IS_UAO_UC_RD_OFFSET		0x27c000
#define IPU7P5_IS_UAO_UC_RD_PLANENUM		4

/* IS UAO UC WR */
#define IPU7P5_IS_UAO_UC_WR_OFFSET		0x27d000
#define IPU7P5_IS_UAO_UC_WR_PLANENUM		4

/* IS UAO M0 WR */
#define IPU7P5_IS_UAO_M0_WR_OFFSET		0x27e000
#define IPU7P5_IS_UAO_M0_WR_PLANENUM		16

/* IS UAO M1 WR */
#define IPU7P5_IS_UAO_M1_WR_OFFSET		0x27f000
#define IPU7P5_IS_UAO_M1_WR_PLANENUM		16

/* PS UAO FW RD */
#define IPU7P5_PS_UAO_FW_RD_OFFSET		0x156000
#define IPU7P5_PS_UAO_FW_RD_PLANENUM		16

/* PS UAO FW WR */
#define IPU7P5_PS_UAO_FW_WR_OFFSET		0x157000
#define IPU7P5_PS_UAO_FW_WR_PLANENUM		10

/* PS UAO SRT RD */
#define IPU7P5_PS_UAO_SRT_RD_OFFSET		0x154000
#define IPU7P5_PS_UAO_SRT_RD_PLANENUM		22

/* PS UAO SRT WR */
#define IPU7P5_PS_UAO_SRT_WR_OFFSET		0x155000
#define IPU7P5_PS_UAO_SRT_WR_PLANENUM		32

#define IPU7P5_IS_ZLX_UC_RD_OFFSET		0x278000
#define IPU7P5_IS_ZLX_UC_WR_OFFSET		0x279000
#define IPU7P5_IS_ZLX_M0_OFFSET			0x27a000
#define IPU7P5_IS_ZLX_M1_OFFSET			0x27b000
#define IPU7P5_IS_ZLX_UC_RD_NUM			4
#define IPU7P5_IS_ZLX_UC_WR_NUM			4
#define IPU7P5_IS_ZLX_M0_NUM			16
#define IPU7P5_IS_ZLX_M1_NUM			16

#define IPU7P5_PS_ZLX_DATA_RD_OFFSET		0x14e000
#define IPU7P5_PS_ZLX_DATA_WR_OFFSET		0x14f000
#define IPU7P5_PS_ZLX_FW_RD_OFFSET		0x150000
#define IPU7P5_PS_ZLX_FW_WR_OFFSET		0x151000
#define IPU7P5_PS_ZLX_DATA_RD_NUM		22
#define IPU7P5_PS_ZLX_DATA_WR_NUM		32
#define IPU7P5_PS_ZLX_FW_RD_NUM			16
#define IPU7P5_PS_ZLX_FW_WR_NUM			10

/* IPU8 */
/* IS MMU Cmd RD */
#define IPU8_IS_MMU_FW_RD_OFFSET		0x270000
#define IPU8_IS_MMU_FW_RD_STREAM_NUM		3
#define IPU8_IS_MMU_FW_RD_L1_BLOCKNR_REG	0x54
#define IPU8_IS_MMU_FW_RD_L2_BLOCKNR_REG	0x60

/* IS MMU Cmd WR */
#define IPU8_IS_MMU_FW_WR_OFFSET		0x271000
#define IPU8_IS_MMU_FW_WR_STREAM_NUM		3
#define IPU8_IS_MMU_FW_WR_L1_BLOCKNR_REG	0x54
#define IPU8_IS_MMU_FW_WR_L2_BLOCKNR_REG	0x60

/* IS MMU Data WR ISOC */
#define IPU8_IS_MMU_M0_OFFSET			0x272000
#define IPU8_IS_MMU_M0_STREAM_NUM		16
#define IPU8_IS_MMU_M0_L1_BLOCKNR_REG		0x54
#define IPU8_IS_MMU_M0_L2_BLOCKNR_REG		0x94

/* IS MMU Data WR Snoop */
#define IPU8_IS_MMU_M1_OFFSET			0x273000
#define IPU8_IS_MMU_M1_STREAM_NUM		16
#define IPU8_IS_MMU_M1_L1_BLOCKNR_REG		0x54
#define IPU8_IS_MMU_M1_L2_BLOCKNR_REG		0x94

/* IS MMU uPipe */
#define IPU8_IS_MMU_UPIPE_OFFSET		0x274000
#define IPU8_IS_MMU_UPIPE_STREAM_NUM		6
#define IPU8_IS_MMU_UPIPE_L1_BLOCKNR_REG	0x54
#define IPU8_IS_MMU_UPIPE_L2_BLOCKNR_REG	0x6c

/* IS UAO UC RD */
#define IPU8_IS_UAO_UC_RD_OFFSET		0x27a000
#define IPU8_IS_UAO_UC_RD_PLANENUM		4

/* IS UAO UC WR */
#define IPU8_IS_UAO_UC_WR_OFFSET		0x27b000
#define IPU8_IS_UAO_UC_WR_PLANENUM		4

/* IS UAO M0 WR */
#define IPU8_IS_UAO_M0_WR_OFFSET		0x27c000
#define IPU8_IS_UAO_M0_WR_PLANENUM		16

/* IS UAO M1 WR */
#define IPU8_IS_UAO_M1_WR_OFFSET		0x27d000
#define IPU8_IS_UAO_M1_WR_PLANENUM		16

/* IS UAO uPipe */
#define IPU8_IS_UAO_UPIPE_OFFSET		0x27e000
#define IPU8_IS_UAO_UPIPE_PLANENUM		6

#define IPU8_IS_ZLX_UC_RD_OFFSET		0x275000
#define IPU8_IS_ZLX_UC_WR_OFFSET		0x276000
#define IPU8_IS_ZLX_M0_OFFSET			0x277000
#define IPU8_IS_ZLX_M1_OFFSET			0x278000
#define IPU8_IS_ZLX_UPIPE_OFFSET		0x279000
#define IPU8_IS_ZLX_UC_RD_NUM			4
#define IPU8_IS_ZLX_UC_WR_NUM			4
#define IPU8_IS_ZLX_M0_NUM			16
#define IPU8_IS_ZLX_M1_NUM			16
#define IPU8_IS_ZLX_UPIPE_NUM			6

#define IPU8_IS_MMU_NUM			5U

/* PS MMU FW RD */
#define IPU8_PS_MMU_FW_RD_OFFSET		0x148000
#define IPU8_PS_MMU_FW_RD_STREAM_NUM		12
#define IPU8_PS_MMU_FW_RD_L1_BLOCKNR_REG	0x54
#define IPU8_PS_MMU_FW_RD_L2_BLOCKNR_REG	0x84

/* PS MMU FW WR */
#define IPU8_PS_MMU_FW_WR_OFFSET		0x149000
#define IPU8_PS_MMU_FW_WR_STREAM_NUM		8
#define IPU8_PS_MMU_FW_WR_L1_BLOCKNR_REG	0x54
#define IPU8_PS_MMU_FW_WR_L2_BLOCKNR_REG	0x74

/* PS MMU FW Data RD VC0 */
#define IPU8_PS_MMU_SRT_RD_OFFSET		0x14a000
#define IPU8_PS_MMU_SRT_RD_STREAM_NUM		26
#define IPU8_PS_MMU_SRT_RD_L1_BLOCKNR_REG	0x54
#define IPU8_PS_MMU_SRT_RD_L2_BLOCKNR_REG	0xbc

/* PS MMU FW Data WR VC0 */
#define IPU8_PS_MMU_SRT_WR_OFFSET		0x14b000
#define IPU8_PS_MMU_SRT_WR_STREAM_NUM		26
#define IPU8_PS_MMU_SRT_WR_L1_BLOCKNR_REG	0x54
#define IPU8_PS_MMU_SRT_WR_L2_BLOCKNR_REG	0xbc

/* PS UAO FW RD */
#define IPU8_PS_UAO_FW_RD_OFFSET		0x156000
#define IPU8_PS_UAO_FW_RD_PLANENUM		12

/* PS UAO FW WR */
#define IPU8_PS_UAO_FW_WR_OFFSET		0x157000
#define IPU8_PS_UAO_FW_WR_PLANENUM		8

/* PS UAO SRT RD */
#define IPU8_PS_UAO_SRT_RD_OFFSET		0x154000
#define IPU8_PS_UAO_SRT_RD_PLANENUM		26

/* PS UAO SRT WR */
#define IPU8_PS_UAO_SRT_WR_OFFSET		0x155000
#define IPU8_PS_UAO_SRT_WR_PLANENUM		26

#define IPU8_PS_ZLX_DATA_RD_OFFSET		0x14e000
#define IPU8_PS_ZLX_DATA_WR_OFFSET		0x14f000
#define IPU8_PS_ZLX_FW_RD_OFFSET		0x150000
#define IPU8_PS_ZLX_FW_WR_OFFSET		0x151000
#define IPU8_PS_ZLX_DATA_RD_NUM			26
#define IPU8_PS_ZLX_DATA_WR_NUM			26
#define IPU8_PS_ZLX_FW_RD_NUM			12
#define IPU8_PS_ZLX_FW_WR_NUM			8

#define IPU8_PS_MMU_NUM			4U

struct ipu7_mmu_hw {
	char name[32];

	void __iomem *base;
	void __iomem *zlx_base;
	void __iomem *uao_base;

	u32 offset;
	u32 zlx_offset;
	u32 uao_offset;

	u32 info_bits;
	u32 refill;
	u32 collapse_en_bitmap;
	u32 at_sp_arb_cfg;

	u32 l1_block;
	u32 l2_block;

	u8 nr_l1streams;
	u8 nr_l2streams;
	u32 l1_block_sz[IPU7_MMU_MAX_TLB_L1_STREAMS];
	u32 l2_block_sz[IPU7_MMU_MAX_TLB_L2_STREAMS];

	u8 zlx_nr;
	u32 zlx_axi_pool[IPU7_ZLX_POOL_NUM];
	u32 zlx_en[IPU7_ZLX_MAX_NUM];
	u32 zlx_conf[IPU7_ZLX_MAX_NUM];

	u32 uao_p_num;
	u32 uao_p2tlb[IPU7_UAO_PLANE_MAX_NUM];
};

struct ipu7_mmu_hwdata {
	struct ipu7_mmu_hw *hwdata;
	unsigned int nr_mmus;
};

#endif