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_fixed.h>
19 #include <drm/drm_probe_helper.h>
20 #include <uapi/drm/tegra_drm.h>
21
22 #include "gem.h"
23 #include "hub.h"
24 #include "trace.h"
25
26 /* XXX move to include/uapi/drm/drm_fourcc.h? */
27 #define DRM_FORMAT_MOD_NVIDIA_SECTOR_LAYOUT BIT_ULL(22)
28
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
tegra_drm_to_host1x(struct tegra_drm * tegra)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
tegra_drm_get_streamid_offset_thi(struct tegra_drm_client * client,u32 * offset)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 *
host1x_to_drm_client(struct host1x_client * 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 int tegra_drm_init(struct tegra_drm *tegra, struct drm_device *drm);
124 int tegra_drm_exit(struct tegra_drm *tegra);
125
126 void *tegra_drm_alloc(struct tegra_drm *tegra, size_t size, dma_addr_t *iova);
127 void tegra_drm_free(struct tegra_drm *tegra, size_t size, void *virt,
128 dma_addr_t iova);
129
130 struct cec_notifier;
131
132 struct tegra_output {
133 struct device_node *of_node;
134 struct device *dev;
135
136 struct drm_bridge *bridge;
137 struct drm_panel *panel;
138 struct i2c_adapter *ddc;
139 const struct edid *edid;
140 struct cec_notifier *cec;
141 unsigned int hpd_irq;
142 struct gpio_desc *hpd_gpio;
143
144 struct drm_encoder encoder;
145 struct drm_connector connector;
146 };
147
encoder_to_output(struct drm_encoder * e)148 static inline struct tegra_output *encoder_to_output(struct drm_encoder *e)
149 {
150 return container_of(e, struct tegra_output, encoder);
151 }
152
connector_to_output(struct drm_connector * c)153 static inline struct tegra_output *connector_to_output(struct drm_connector *c)
154 {
155 return container_of(c, struct tegra_output, connector);
156 }
157
158 /* from output.c */
159 int tegra_output_probe(struct tegra_output *output);
160 void tegra_output_remove(struct tegra_output *output);
161 int tegra_output_init(struct drm_device *drm, struct tegra_output *output);
162 void tegra_output_exit(struct tegra_output *output);
163 void tegra_output_find_possible_crtcs(struct tegra_output *output,
164 struct drm_device *drm);
165 int tegra_output_suspend(struct tegra_output *output);
166 int tegra_output_resume(struct tegra_output *output);
167
168 int tegra_output_connector_get_modes(struct drm_connector *connector);
169 enum drm_connector_status
170 tegra_output_connector_detect(struct drm_connector *connector, bool force);
171 void tegra_output_connector_destroy(struct drm_connector *connector);
172
173 /* from dpaux.c */
174 struct drm_dp_aux *drm_dp_aux_find_by_of_node(struct device_node *np);
175 enum drm_connector_status drm_dp_aux_detect(struct drm_dp_aux *aux);
176 int drm_dp_aux_attach(struct drm_dp_aux *aux, struct tegra_output *output);
177 int drm_dp_aux_detach(struct drm_dp_aux *aux);
178 int drm_dp_aux_enable(struct drm_dp_aux *aux);
179 int drm_dp_aux_disable(struct drm_dp_aux *aux);
180
181 /* from fb.c */
182 struct tegra_bo *tegra_fb_get_plane(struct drm_framebuffer *framebuffer,
183 unsigned int index);
184 bool tegra_fb_is_bottom_up(struct drm_framebuffer *framebuffer);
185 int tegra_fb_get_tiling(struct drm_framebuffer *framebuffer,
186 struct tegra_bo_tiling *tiling);
187 struct drm_framebuffer *tegra_fb_alloc(struct drm_device *drm,
188 const struct drm_mode_fb_cmd2 *mode_cmd,
189 struct tegra_bo **planes,
190 unsigned int num_planes);
191 struct drm_framebuffer *tegra_fb_create(struct drm_device *drm,
192 struct drm_file *file,
193 const struct drm_mode_fb_cmd2 *cmd);
194
195 #ifdef CONFIG_DRM_FBDEV_EMULATION
196 void tegra_fbdev_setup(struct drm_device *drm);
197 #else
tegra_fbdev_setup(struct drm_device * drm)198 static inline void tegra_fbdev_setup(struct drm_device *drm)
199 { }
200 #endif
201
202 extern struct platform_driver tegra_display_hub_driver;
203 extern struct platform_driver tegra_dc_driver;
204 extern struct platform_driver tegra_hdmi_driver;
205 extern struct platform_driver tegra_dsi_driver;
206 extern struct platform_driver tegra_dpaux_driver;
207 extern struct platform_driver tegra_sor_driver;
208 extern struct platform_driver tegra_gr2d_driver;
209 extern struct platform_driver tegra_gr3d_driver;
210 extern struct platform_driver tegra_vic_driver;
211 extern struct platform_driver tegra_nvdec_driver;
212
213 #endif /* HOST1X_DRM_H */
214