1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /*
3  * NVIDIA Tegra Video decoder driver
4  *
5  * Copyright (C) 2016-2019 GRATE-DRIVER project
6  */
7 
8 #ifndef TEGRA_VDE_H
9 #define TEGRA_VDE_H
10 
11 #include <linux/completion.h>
12 #include <linux/dma-direction.h>
13 #include <linux/iova.h>
14 #include <linux/list.h>
15 #include <linux/miscdevice.h>
16 #include <linux/mutex.h>
17 #include <linux/types.h>
18 
19 struct clk;
20 struct dma_buf;
21 struct gen_pool;
22 struct iommu_group;
23 struct iommu_domain;
24 struct reset_control;
25 struct dma_buf_attachment;
26 
27 struct tegra_vde {
28 	void __iomem *sxe;
29 	void __iomem *bsev;
30 	void __iomem *mbe;
31 	void __iomem *ppe;
32 	void __iomem *mce;
33 	void __iomem *tfe;
34 	void __iomem *ppb;
35 	void __iomem *vdma;
36 	void __iomem *frameid;
37 	struct mutex lock;
38 	struct mutex map_lock;
39 	struct list_head map_list;
40 	struct miscdevice miscdev;
41 	struct reset_control *rst;
42 	struct reset_control *rst_mc;
43 	struct gen_pool *iram_pool;
44 	struct completion decode_completion;
45 	struct clk *clk;
46 	struct iommu_domain *domain;
47 	struct iommu_group *group;
48 	struct iova_domain iova;
49 	struct iova *iova_resv_static_addresses;
50 	struct iova *iova_resv_last_page;
51 	dma_addr_t iram_lists_addr;
52 	u32 *iram;
53 };
54 
55 int tegra_vde_iommu_init(struct tegra_vde *vde);
56 void tegra_vde_iommu_deinit(struct tegra_vde *vde);
57 int tegra_vde_iommu_map(struct tegra_vde *vde,
58 			struct sg_table *sgt,
59 			struct iova **iovap,
60 			size_t size);
61 void tegra_vde_iommu_unmap(struct tegra_vde *vde, struct iova *iova);
62 
63 int tegra_vde_dmabuf_cache_map(struct tegra_vde *vde,
64 			       struct dma_buf *dmabuf,
65 			       enum dma_data_direction dma_dir,
66 			       struct dma_buf_attachment **ap,
67 			       dma_addr_t *addrp);
68 void tegra_vde_dmabuf_cache_unmap(struct tegra_vde *vde,
69 				  struct dma_buf_attachment *a,
70 				  bool release);
71 void tegra_vde_dmabuf_cache_unmap_sync(struct tegra_vde *vde);
72 void tegra_vde_dmabuf_cache_unmap_all(struct tegra_vde *vde);
73 
74 static __maybe_unused char const *
tegra_vde_reg_base_name(struct tegra_vde * vde,void __iomem * base)75 tegra_vde_reg_base_name(struct tegra_vde *vde, void __iomem *base)
76 {
77 	if (vde->sxe == base)
78 		return "SXE";
79 
80 	if (vde->bsev == base)
81 		return "BSEV";
82 
83 	if (vde->mbe == base)
84 		return "MBE";
85 
86 	if (vde->ppe == base)
87 		return "PPE";
88 
89 	if (vde->mce == base)
90 		return "MCE";
91 
92 	if (vde->tfe == base)
93 		return "TFE";
94 
95 	if (vde->ppb == base)
96 		return "PPB";
97 
98 	if (vde->vdma == base)
99 		return "VDMA";
100 
101 	if (vde->frameid == base)
102 		return "FRAMEID";
103 
104 	return "???";
105 }
106 
107 #endif /* TEGRA_VDE_H */
108