xref: /OK3568_Linux_fs/kernel/drivers/video/rockchip/rga3/include/rga_iommu.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __RGA_MMU_INFO_H__
3 #define __RGA_MMU_INFO_H__
4 
5 #include "rga_drv.h"
6 
7 /* RGA_IOMMU register offsets */
8 #define RGA_IOMMU_BASE				0xf00
9 #define RGA_IOMMU_DTE_ADDR			(RGA_IOMMU_BASE + 0x00) /* Directory table address */
10 #define RGA_IOMMU_STATUS			(RGA_IOMMU_BASE + 0x04)
11 #define RGA_IOMMU_COMMAND			(RGA_IOMMU_BASE + 0x08)
12 #define RGA_IOMMU_PAGE_FAULT_ADDR		(RGA_IOMMU_BASE + 0x0C) /* IOVA of last page fault */
13 #define RGA_IOMMU_ZAP_ONE_LINE			(RGA_IOMMU_BASE + 0x10) /* Shootdown one IOTLB entry */
14 #define RGA_IOMMU_INT_RAWSTAT			(RGA_IOMMU_BASE + 0x14) /* IRQ status ignoring mask */
15 #define RGA_IOMMU_INT_CLEAR			(RGA_IOMMU_BASE + 0x18) /* Acknowledge and re-arm irq */
16 #define RGA_IOMMU_INT_MASK			(RGA_IOMMU_BASE + 0x1C) /* IRQ enable */
17 #define RGA_IOMMU_INT_STATUS			(RGA_IOMMU_BASE + 0x20) /* IRQ status after masking */
18 #define RGA_IOMMU_AUTO_GATING			(RGA_IOMMU_BASE + 0x24)
19 
20 /* RGA_IOMMU_STATUS fields */
21 #define RGA_IOMMU_STATUS_PAGING_ENABLED		BIT(0)
22 #define RGA_IOMMU_STATUS_PAGE_FAULT_ACTIVE	BIT(1)
23 #define RGA_IOMMU_STATUS_STALL_ACTIVE		BIT(2)
24 #define RGA_IOMMU_STATUS_IDLE			BIT(3)
25 #define RGA_IOMMU_STATUS_REPLAY_BUFFER_EMPTY	BIT(4)
26 #define RGA_IOMMU_STATUS_PAGE_FAULT_IS_WRITE	BIT(5)
27 #define RGA_IOMMU_STATUS_STALL_NOT_ACTIVE	BIT(31)
28 
29 /* RGA_IOMMU_COMMAND command values */
30 #define RGA_IOMMU_CMD_ENABLE_PAGING		0 /* Enable memory translation */
31 #define RGA_IOMMU_CMD_DISABLE_PAGING		1 /* Disable memory translation */
32 #define RGA_IOMMU_CMD_ENABLE_STALL		2 /* Stall paging to allow other cmds */
33 #define RGA_IOMMU_CMD_DISABLE_STALL		3 /* Stop stall re-enables paging */
34 #define RGA_IOMMU_CMD_ZAP_CACHE			4 /* Shoot down entire IOTLB */
35 #define RGA_IOMMU_CMD_PAGE_FAULT_DONE		5 /* Clear page fault */
36 #define RGA_IOMMU_CMD_FORCE_RESET		6 /* Reset all registers */
37 
38 /* RGA_IOMMU_INT_* register fields */
39 #define RGA_IOMMU_IRQ_PAGE_FAULT		0x01 /* page fault */
40 #define RGA_IOMMU_IRQ_BUS_ERROR			0x02 /* bus read error */
41 #define RGA_IOMMU_IRQ_MASK			(RGA_IOMMU_IRQ_PAGE_FAULT | RGA_IOMMU_IRQ_BUS_ERROR)
42 
43 /*
44  * The maximum input is 8192*8192, the maximum output is 4096*4096
45  * The size of physical pages requested is:
46  * (( maximum_input_value *
47  *         maximum_input_value * format_bpp ) / 4K_page_size) + 1
48  */
49 #define RGA2_PHY_PAGE_SIZE	 (((8192 * 8192 * 4) / 4096) + 1)
50 
51 struct rga_mmu_base {
52 	unsigned int *buf_virtual;
53 	struct page **pages;
54 	u8 buf_order;
55 	u8 pages_order;
56 
57 	int32_t front;
58 	int32_t back;
59 	int32_t size;
60 	int32_t curr;
61 };
62 
63 int rga_user_memory_check(struct page **pages, u32 w, u32 h, u32 format, int flag);
64 int rga_set_mmu_base(struct rga_job *job, struct rga2_req *req);
65 unsigned int *rga_mmu_buf_get(struct rga_mmu_base *mmu_base, uint32_t size);
66 
67 struct rga_mmu_base *rga_mmu_base_init(size_t size);
68 void rga_mmu_base_free(struct rga_mmu_base **mmu_base);
69 
70 int rga_iommu_detach(struct rga_iommu_info *info);
71 int rga_iommu_attach(struct rga_iommu_info *info);
72 struct rga_iommu_info *rga_iommu_probe(struct device *dev);
73 int rga_iommu_remove(struct rga_iommu_info *info);
74 
75 int rga_iommu_bind(void);
76 void rga_iommu_unbind(void);
77 
78 #endif
79 
80