xref: /linux/drivers/gpu/drm/tegra/drm.h (revision de848da12f752170c2ebe114804a985314fd5a6a)
1d2912cb1SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
2dee8268fSThierry Reding /*
3dee8268fSThierry Reding  * Copyright (C) 2012 Avionic Design GmbH
4dee8268fSThierry Reding  * Copyright (C) 2012-2013 NVIDIA CORPORATION.  All rights reserved.
5dee8268fSThierry Reding  */
6dee8268fSThierry Reding 
7dee8268fSThierry Reding #ifndef HOST1X_DRM_H
8dee8268fSThierry Reding #define HOST1X_DRM_H 1
9dee8268fSThierry Reding 
10dee8268fSThierry Reding #include <linux/host1x.h>
11ad926015SMikko Perttunen #include <linux/iova.h>
12ac2caae6SLinus Walleij #include <linux/gpio/consumer.h>
13dee8268fSThierry Reding 
14c4755fb9SThierry Reding #include <drm/drm_atomic.h>
15f00b9dd5SDmitry Osipenko #include <drm/drm_bridge.h>
169338203cSLaurent Pinchart #include <drm/drm_encoder.h>
17dee8268fSThierry Reding #include <drm/drm_fixed.h>
18fcd70cd3SDaniel Vetter #include <drm/drm_probe_helper.h>
19eb1df694SSam Ravnborg #include <uapi/drm/tegra_drm.h>
20dee8268fSThierry Reding 
21c134f019SThierry Reding #include "gem.h"
22c4755fb9SThierry Reding #include "hub.h"
2367e04d1aSThierry Reding #include "trace.h"
24c134f019SThierry Reding 
257b6f8467SThierry Reding /* XXX move to include/uapi/drm/drm_fourcc.h? */
26671cc352SDmitry Osipenko #define DRM_FORMAT_MOD_NVIDIA_SECTOR_LAYOUT BIT_ULL(22)
277b6f8467SThierry Reding 
2811aa6d78SJani Nikula struct edid;
29ca48080aSStephen Warren struct reset_control;
30ca48080aSStephen Warren 
31dee8268fSThierry Reding struct tegra_drm {
32dee8268fSThierry Reding 	struct drm_device *drm;
33dee8268fSThierry Reding 
34df06b759SThierry Reding 	struct iommu_domain *domain;
35fa6661b7SThierry Reding 	bool use_explicit_iommu;
36347ad49dSThierry Reding 	struct mutex mm_lock;
37df06b759SThierry Reding 	struct drm_mm mm;
38df06b759SThierry Reding 
39ad926015SMikko Perttunen 	struct {
40ad926015SMikko Perttunen 		struct iova_domain domain;
41ad926015SMikko Perttunen 		unsigned long shift;
42ad926015SMikko Perttunen 		unsigned long limit;
43ad926015SMikko Perttunen 	} carveout;
44ad926015SMikko Perttunen 
45dee8268fSThierry Reding 	struct mutex clients_lock;
46dee8268fSThierry Reding 	struct list_head clients;
47dee8268fSThierry Reding 
48042c0bd7SThierry Reding 	unsigned int hmask, vmask;
49d1f3e1e0SThierry Reding 	unsigned int pitch_align;
5005d1adfeSThierry Reding 	unsigned int num_crtcs;
511503ca47SThierry Reding 
52c4755fb9SThierry Reding 	struct tegra_display_hub *hub;
53dee8268fSThierry Reding };
54dee8268fSThierry Reding 
55d7c591bcSMikko Perttunen static inline struct host1x *tegra_drm_to_host1x(struct tegra_drm *tegra)
56d7c591bcSMikko Perttunen {
57d7c591bcSMikko Perttunen 	return dev_get_drvdata(tegra->drm->dev->parent);
58d7c591bcSMikko Perttunen }
59d7c591bcSMikko Perttunen 
60dee8268fSThierry Reding struct tegra_drm_client;
61dee8268fSThierry Reding 
62dee8268fSThierry Reding struct tegra_drm_context {
63dee8268fSThierry Reding 	struct tegra_drm_client *client;
64dee8268fSThierry Reding 	struct host1x_channel *channel;
65d7c591bcSMikko Perttunen 
66d7c591bcSMikko Perttunen 	/* Only used by legacy UAPI. */
67bdd2f9cdSThierry Reding 	unsigned int id;
68d7c591bcSMikko Perttunen 
69d7c591bcSMikko Perttunen 	/* Only used by new UAPI. */
70d7c591bcSMikko Perttunen 	struct xarray mappings;
71e09db978SMikko Perttunen 	struct host1x_memory_context *memory_context;
72dee8268fSThierry Reding };
73dee8268fSThierry Reding 
74dee8268fSThierry Reding struct tegra_drm_client_ops {
75dee8268fSThierry Reding 	int (*open_channel)(struct tegra_drm_client *client,
76dee8268fSThierry Reding 			    struct tegra_drm_context *context);
77dee8268fSThierry Reding 	void (*close_channel)(struct tegra_drm_context *context);
78c40f0f1aSThierry Reding 	int (*is_addr_reg)(struct device *dev, u32 class, u32 offset);
790f563a4bSDmitry Osipenko 	int (*is_valid_class)(u32 class);
80dee8268fSThierry Reding 	int (*submit)(struct tegra_drm_context *context,
81dee8268fSThierry Reding 		      struct drm_tegra_submit *args, struct drm_device *drm,
82dee8268fSThierry Reding 		      struct drm_file *file);
83e09db978SMikko Perttunen 	int (*get_streamid_offset)(struct tegra_drm_client *client, u32 *offset);
84e09db978SMikko Perttunen 	int (*can_use_memory_ctx)(struct tegra_drm_client *client, bool *supported);
85dee8268fSThierry Reding };
86dee8268fSThierry Reding 
87c40f0f1aSThierry Reding int tegra_drm_submit(struct tegra_drm_context *context,
88c40f0f1aSThierry Reding 		     struct drm_tegra_submit *args, struct drm_device *drm,
89c40f0f1aSThierry Reding 		     struct drm_file *file);
90c40f0f1aSThierry Reding 
91bf0297acSMikko Perttunen static inline int
92bf0297acSMikko Perttunen tegra_drm_get_streamid_offset_thi(struct tegra_drm_client *client, u32 *offset)
93bf0297acSMikko Perttunen {
94bf0297acSMikko Perttunen 	*offset = 0x30;
95bf0297acSMikko Perttunen 
96bf0297acSMikko Perttunen 	return 0;
97bf0297acSMikko Perttunen }
98bf0297acSMikko Perttunen 
99dee8268fSThierry Reding struct tegra_drm_client {
100dee8268fSThierry Reding 	struct host1x_client base;
101dee8268fSThierry Reding 	struct list_head list;
1028e5d19c6SThierry Reding 	struct tegra_drm *drm;
103e0f2977cSMikko Perttunen 	struct host1x_channel *shared_channel;
104dee8268fSThierry Reding 
105e0f2977cSMikko Perttunen 	/* Set by driver */
106f3b3cfccSThierry Reding 	unsigned int version;
107dee8268fSThierry Reding 	const struct tegra_drm_client_ops *ops;
108dee8268fSThierry Reding };
109dee8268fSThierry Reding 
110dee8268fSThierry Reding static inline struct tegra_drm_client *
111dee8268fSThierry Reding host1x_to_drm_client(struct host1x_client *client)
112dee8268fSThierry Reding {
113dee8268fSThierry Reding 	return container_of(client, struct tegra_drm_client, base);
114dee8268fSThierry Reding }
115dee8268fSThierry Reding 
116688c59afSThierry Reding int tegra_drm_register_client(struct tegra_drm *tegra,
117dee8268fSThierry Reding 			      struct tegra_drm_client *client);
118688c59afSThierry Reding int tegra_drm_unregister_client(struct tegra_drm *tegra,
119dee8268fSThierry Reding 				struct tegra_drm_client *client);
1207edd7961SThierry Reding int host1x_client_iommu_attach(struct host1x_client *client);
121aacdf198SThierry Reding void host1x_client_iommu_detach(struct host1x_client *client);
122dee8268fSThierry Reding 
123ad926015SMikko Perttunen void *tegra_drm_alloc(struct tegra_drm *tegra, size_t size, dma_addr_t *iova);
124ad926015SMikko Perttunen void tegra_drm_free(struct tegra_drm *tegra, size_t size, void *virt,
125ad926015SMikko Perttunen 		    dma_addr_t iova);
126ad926015SMikko Perttunen 
127fb83be88SHans Verkuil struct cec_notifier;
128fb83be88SHans Verkuil 
129dee8268fSThierry Reding struct tegra_output {
130dee8268fSThierry Reding 	struct device_node *of_node;
131dee8268fSThierry Reding 	struct device *dev;
132dee8268fSThierry Reding 
133f00b9dd5SDmitry Osipenko 	struct drm_bridge *bridge;
1349be7d864SThierry Reding 	struct drm_panel *panel;
135dee8268fSThierry Reding 	struct i2c_adapter *ddc;
136*98365ca7SJani Nikula 	const struct drm_edid *drm_edid;
137f25d0a68SThierry Reding 	struct cec_notifier *cec;
138dee8268fSThierry Reding 	unsigned int hpd_irq;
139bbad6407SThierry Reding 	struct gpio_desc *hpd_gpio;
140dee8268fSThierry Reding 
141dee8268fSThierry Reding 	struct drm_encoder encoder;
142dee8268fSThierry Reding 	struct drm_connector connector;
143dee8268fSThierry Reding };
144dee8268fSThierry Reding 
145dee8268fSThierry Reding static inline struct tegra_output *encoder_to_output(struct drm_encoder *e)
146dee8268fSThierry Reding {
147dee8268fSThierry Reding 	return container_of(e, struct tegra_output, encoder);
148dee8268fSThierry Reding }
149dee8268fSThierry Reding 
150dee8268fSThierry Reding static inline struct tegra_output *connector_to_output(struct drm_connector *c)
151dee8268fSThierry Reding {
152dee8268fSThierry Reding 	return container_of(c, struct tegra_output, connector);
153dee8268fSThierry Reding }
154dee8268fSThierry Reding 
155dee8268fSThierry Reding /* from output.c */
156688c59afSThierry Reding int tegra_output_probe(struct tegra_output *output);
157328ec69eSThierry Reding void tegra_output_remove(struct tegra_output *output);
158688c59afSThierry Reding int tegra_output_init(struct drm_device *drm, struct tegra_output *output);
159328ec69eSThierry Reding void tegra_output_exit(struct tegra_output *output);
160c57997bcSThierry Reding void tegra_output_find_possible_crtcs(struct tegra_output *output,
161c57997bcSThierry Reding 				      struct drm_device *drm);
162fd67e9c6SThierry Reding int tegra_output_suspend(struct tegra_output *output);
163fd67e9c6SThierry Reding int tegra_output_resume(struct tegra_output *output);
164dee8268fSThierry Reding 
165132085d8SThierry Reding int tegra_output_connector_get_modes(struct drm_connector *connector);
166132085d8SThierry Reding enum drm_connector_status
167132085d8SThierry Reding tegra_output_connector_detect(struct drm_connector *connector, bool force);
168132085d8SThierry Reding void tegra_output_connector_destroy(struct drm_connector *connector);
169132085d8SThierry Reding 
1706b6b6042SThierry Reding /* from dpaux.c */
1719542c237SThierry Reding struct drm_dp_aux *drm_dp_aux_find_by_of_node(struct device_node *np);
1729542c237SThierry Reding enum drm_connector_status drm_dp_aux_detect(struct drm_dp_aux *aux);
1739542c237SThierry Reding int drm_dp_aux_attach(struct drm_dp_aux *aux, struct tegra_output *output);
1749542c237SThierry Reding int drm_dp_aux_detach(struct drm_dp_aux *aux);
1759542c237SThierry Reding int drm_dp_aux_enable(struct drm_dp_aux *aux);
1769542c237SThierry Reding int drm_dp_aux_disable(struct drm_dp_aux *aux);
1776b6b6042SThierry Reding 
178dee8268fSThierry Reding /* from fb.c */
179dee8268fSThierry Reding struct tegra_bo *tegra_fb_get_plane(struct drm_framebuffer *framebuffer,
180dee8268fSThierry Reding 				    unsigned int index);
181db7fbdfdSThierry Reding bool tegra_fb_is_bottom_up(struct drm_framebuffer *framebuffer);
182c134f019SThierry Reding int tegra_fb_get_tiling(struct drm_framebuffer *framebuffer,
183c134f019SThierry Reding 			struct tegra_bo_tiling *tiling);
1841ac45068SThomas Zimmermann struct drm_framebuffer *tegra_fb_alloc(struct drm_device *drm,
1851ac45068SThomas Zimmermann 				       const struct drm_mode_fb_cmd2 *mode_cmd,
1861ac45068SThomas Zimmermann 				       struct tegra_bo **planes,
1871ac45068SThomas Zimmermann 				       unsigned int num_planes);
188f9914214SThierry Reding struct drm_framebuffer *tegra_fb_create(struct drm_device *drm,
189f9914214SThierry Reding 					struct drm_file *file,
1901eb83451SVille Syrjälä 					const struct drm_mode_fb_cmd2 *cmd);
1911ac45068SThomas Zimmermann 
1921ac45068SThomas Zimmermann #ifdef CONFIG_DRM_FBDEV_EMULATION
19371ec16f4SThomas Zimmermann void tegra_fbdev_setup(struct drm_device *drm);
1941ac45068SThomas Zimmermann #else
19571ec16f4SThomas Zimmermann static inline void tegra_fbdev_setup(struct drm_device *drm)
1961ac45068SThomas Zimmermann { }
1971ac45068SThomas Zimmermann #endif
198dee8268fSThierry Reding 
199c4755fb9SThierry Reding extern struct platform_driver tegra_display_hub_driver;
200dee8268fSThierry Reding extern struct platform_driver tegra_dc_driver;
201dee8268fSThierry Reding extern struct platform_driver tegra_hdmi_driver;
202473112e4SThierry Reding extern struct platform_driver tegra_dsi_driver;
2036b6b6042SThierry Reding extern struct platform_driver tegra_dpaux_driver;
204473112e4SThierry Reding extern struct platform_driver tegra_sor_driver;
205dee8268fSThierry Reding extern struct platform_driver tegra_gr2d_driver;
2065f60ed0dSThierry Reding extern struct platform_driver tegra_gr3d_driver;
2070ae797a8SArto Merilainen extern struct platform_driver tegra_vic_driver;
20846f226c9SMikko Perttunen extern struct platform_driver tegra_nvdec_driver;
209dee8268fSThierry Reding 
210dee8268fSThierry Reding #endif /* HOST1X_DRM_H */
211