xref: /linux/drivers/gpu/drm/tegra/drm.h (revision 527a0f2bdcfe77fce22f006b97e42e4da3137c86)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright (C) 2012 Avionic Design GmbH
4  * Copyright (C) 2012-2013 NVIDIA CORPORATION.  All rights reserved.
5  */
6 
7 #ifndef HOST1X_DRM_H
8 #define HOST1X_DRM_H 1
9 
10 #include <linux/host1x.h>
11 #include <linux/iova.h>
12 #include <linux/gpio/consumer.h>
13 
14 #include <drm/drm_atomic.h>
15 #include <drm/drm_bridge.h>
16 #include <drm/drm_encoder.h>
17 #include <drm/drm_fixed.h>
18 #include <drm/drm_probe_helper.h>
19 #include <uapi/drm/tegra_drm.h>
20 
21 #include "gem.h"
22 #include "hub.h"
23 #include "trace.h"
24 
25 /* XXX move to include/uapi/drm/drm_fourcc.h? */
26 #define DRM_FORMAT_MOD_NVIDIA_SECTOR_LAYOUT BIT_ULL(22)
27 
28 struct edid;
29 struct reset_control;
30 
31 struct tegra_drm {
32 	struct drm_device *drm;
33 
34 	struct iommu_domain *domain;
35 	bool use_explicit_iommu;
36 	struct mutex mm_lock;
37 	struct drm_mm mm;
38 
39 	struct {
40 		struct iova_domain domain;
41 		unsigned long shift;
42 		unsigned long limit;
43 	} carveout;
44 
45 	struct mutex clients_lock;
46 	struct list_head clients;
47 
48 	unsigned int hmask, vmask;
49 	unsigned int pitch_align;
50 	unsigned int num_crtcs;
51 
52 	struct tegra_display_hub *hub;
53 };
54 
55 static inline struct host1x *tegra_drm_to_host1x(struct tegra_drm *tegra)
56 {
57 	return dev_get_drvdata(tegra->drm->dev->parent);
58 }
59 
60 struct tegra_drm_client;
61 
62 struct tegra_drm_context {
63 	struct tegra_drm_client *client;
64 	struct host1x_channel *channel;
65 
66 	/* Only used by legacy UAPI. */
67 	unsigned int id;
68 
69 	/* Only used by new UAPI. */
70 	struct xarray mappings;
71 	struct host1x_memory_context *memory_context;
72 };
73 
74 struct tegra_drm_client_ops {
75 	int (*open_channel)(struct tegra_drm_client *client,
76 			    struct tegra_drm_context *context);
77 	void (*close_channel)(struct tegra_drm_context *context);
78 	int (*is_addr_reg)(struct device *dev, u32 class, u32 offset);
79 	int (*is_valid_class)(u32 class);
80 	int (*submit)(struct tegra_drm_context *context,
81 		      struct drm_tegra_submit *args, struct drm_device *drm,
82 		      struct drm_file *file);
83 	int (*get_streamid_offset)(struct tegra_drm_client *client, u32 *offset);
84 	int (*can_use_memory_ctx)(struct tegra_drm_client *client, bool *supported);
85 };
86 
87 int tegra_drm_submit(struct tegra_drm_context *context,
88 		     struct drm_tegra_submit *args, struct drm_device *drm,
89 		     struct drm_file *file);
90 
91 static inline int
92 tegra_drm_get_streamid_offset_thi(struct tegra_drm_client *client, u32 *offset)
93 {
94 	*offset = 0x30;
95 
96 	return 0;
97 }
98 
99 struct tegra_drm_client {
100 	struct host1x_client base;
101 	struct list_head list;
102 	struct tegra_drm *drm;
103 	struct host1x_channel *shared_channel;
104 
105 	/* Set by driver */
106 	unsigned int version;
107 	const struct tegra_drm_client_ops *ops;
108 };
109 
110 static inline struct tegra_drm_client *
111 host1x_to_drm_client(struct host1x_client *client)
112 {
113 	return container_of(client, struct tegra_drm_client, base);
114 }
115 
116 int tegra_drm_register_client(struct tegra_drm *tegra,
117 			      struct tegra_drm_client *client);
118 int tegra_drm_unregister_client(struct tegra_drm *tegra,
119 				struct tegra_drm_client *client);
120 int host1x_client_iommu_attach(struct host1x_client *client);
121 void host1x_client_iommu_detach(struct host1x_client *client);
122 
123 void *tegra_drm_alloc(struct tegra_drm *tegra, size_t size, dma_addr_t *iova);
124 void tegra_drm_free(struct tegra_drm *tegra, size_t size, void *virt,
125 		    dma_addr_t iova);
126 
127 struct cec_notifier;
128 
129 struct tegra_output {
130 	struct device_node *of_node;
131 	struct device *dev;
132 
133 	struct drm_bridge *bridge;
134 	struct drm_panel *panel;
135 	struct i2c_adapter *ddc;
136 	const struct drm_edid *drm_edid;
137 	struct cec_notifier *cec;
138 	unsigned int hpd_irq;
139 	struct gpio_desc *hpd_gpio;
140 
141 	struct drm_encoder encoder;
142 	struct drm_connector connector;
143 };
144 
145 static inline struct tegra_output *encoder_to_output(struct drm_encoder *e)
146 {
147 	return container_of(e, struct tegra_output, encoder);
148 }
149 
150 static inline struct tegra_output *connector_to_output(struct drm_connector *c)
151 {
152 	return container_of(c, struct tegra_output, connector);
153 }
154 
155 /* from output.c */
156 int tegra_output_probe(struct tegra_output *output);
157 void tegra_output_remove(struct tegra_output *output);
158 int tegra_output_init(struct drm_device *drm, struct tegra_output *output);
159 void tegra_output_exit(struct tegra_output *output);
160 void tegra_output_find_possible_crtcs(struct tegra_output *output,
161 				      struct drm_device *drm);
162 int tegra_output_suspend(struct tegra_output *output);
163 int tegra_output_resume(struct tegra_output *output);
164 
165 int tegra_output_connector_get_modes(struct drm_connector *connector);
166 enum drm_connector_status
167 tegra_output_connector_detect(struct drm_connector *connector, bool force);
168 void tegra_output_connector_destroy(struct drm_connector *connector);
169 
170 /* from dpaux.c */
171 struct drm_dp_aux *drm_dp_aux_find_by_of_node(struct device_node *np);
172 enum drm_connector_status drm_dp_aux_detect(struct drm_dp_aux *aux);
173 int drm_dp_aux_attach(struct drm_dp_aux *aux, struct tegra_output *output);
174 int drm_dp_aux_detach(struct drm_dp_aux *aux);
175 int drm_dp_aux_enable(struct drm_dp_aux *aux);
176 int drm_dp_aux_disable(struct drm_dp_aux *aux);
177 
178 /* from fb.c */
179 struct tegra_bo *tegra_fb_get_plane(struct drm_framebuffer *framebuffer,
180 				    unsigned int index);
181 bool tegra_fb_is_bottom_up(struct drm_framebuffer *framebuffer);
182 int tegra_fb_get_tiling(struct drm_framebuffer *framebuffer,
183 			struct tegra_bo_tiling *tiling);
184 struct drm_framebuffer *tegra_fb_alloc(struct drm_device *drm,
185 				       const struct drm_mode_fb_cmd2 *mode_cmd,
186 				       struct tegra_bo **planes,
187 				       unsigned int num_planes);
188 struct drm_framebuffer *tegra_fb_create(struct drm_device *drm,
189 					struct drm_file *file,
190 					const struct drm_mode_fb_cmd2 *cmd);
191 
192 #ifdef CONFIG_DRM_FBDEV_EMULATION
193 void tegra_fbdev_setup(struct drm_device *drm);
194 #else
195 static inline void tegra_fbdev_setup(struct drm_device *drm)
196 { }
197 #endif
198 
199 extern struct platform_driver tegra_display_hub_driver;
200 extern struct platform_driver tegra_dc_driver;
201 extern struct platform_driver tegra_hdmi_driver;
202 extern struct platform_driver tegra_dsi_driver;
203 extern struct platform_driver tegra_dpaux_driver;
204 extern struct platform_driver tegra_sor_driver;
205 extern struct platform_driver tegra_gr2d_driver;
206 extern struct platform_driver tegra_gr3d_driver;
207 extern struct platform_driver tegra_vic_driver;
208 extern struct platform_driver tegra_nvdec_driver;
209 
210 #endif /* HOST1X_DRM_H */
211