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