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