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> 16dee8268fSThierry Reding #include <drm/drm_edid.h> 179338203cSLaurent Pinchart #include <drm/drm_encoder.h> 18dee8268fSThierry Reding #include <drm/drm_fb_helper.h> 19dee8268fSThierry Reding #include <drm/drm_fixed.h> 20fcd70cd3SDaniel Vetter #include <drm/drm_probe_helper.h> 21eb1df694SSam Ravnborg #include <uapi/drm/tegra_drm.h> 22dee8268fSThierry Reding 23c134f019SThierry Reding #include "gem.h" 24c4755fb9SThierry Reding #include "hub.h" 2567e04d1aSThierry Reding #include "trace.h" 26c134f019SThierry Reding 277b6f8467SThierry Reding /* XXX move to include/uapi/drm/drm_fourcc.h? */ 28671cc352SDmitry Osipenko #define DRM_FORMAT_MOD_NVIDIA_SECTOR_LAYOUT BIT_ULL(22) 297b6f8467SThierry Reding 30ca48080aSStephen Warren struct reset_control; 31ca48080aSStephen Warren 32b110ef37SArchit Taneja #ifdef CONFIG_DRM_FBDEV_EMULATION 33dee8268fSThierry Reding struct tegra_fbdev { 34dee8268fSThierry Reding struct drm_fb_helper base; 35dbc33c7dSDaniel Stone struct drm_framebuffer *fb; 36dee8268fSThierry Reding }; 3760c2f709SThierry Reding #endif 38dee8268fSThierry Reding 39dee8268fSThierry Reding struct tegra_drm { 40dee8268fSThierry Reding struct drm_device *drm; 41dee8268fSThierry Reding 42df06b759SThierry Reding struct iommu_domain *domain; 43fa6661b7SThierry Reding bool use_explicit_iommu; 44347ad49dSThierry Reding struct mutex mm_lock; 45df06b759SThierry Reding struct drm_mm mm; 46df06b759SThierry Reding 47ad926015SMikko Perttunen struct { 48ad926015SMikko Perttunen struct iova_domain domain; 49ad926015SMikko Perttunen unsigned long shift; 50ad926015SMikko Perttunen unsigned long limit; 51ad926015SMikko Perttunen } carveout; 52ad926015SMikko Perttunen 53dee8268fSThierry Reding struct mutex clients_lock; 54dee8268fSThierry Reding struct list_head clients; 55dee8268fSThierry Reding 56b110ef37SArchit Taneja #ifdef CONFIG_DRM_FBDEV_EMULATION 57dee8268fSThierry Reding struct tegra_fbdev *fbdev; 5860c2f709SThierry Reding #endif 59d1f3e1e0SThierry Reding 60042c0bd7SThierry Reding unsigned int hmask, vmask; 61d1f3e1e0SThierry Reding unsigned int pitch_align; 6205d1adfeSThierry Reding unsigned int num_crtcs; 631503ca47SThierry Reding 64c4755fb9SThierry Reding struct tegra_display_hub *hub; 65dee8268fSThierry Reding }; 66dee8268fSThierry Reding 67d7c591bcSMikko Perttunen static inline struct host1x *tegra_drm_to_host1x(struct tegra_drm *tegra) 68d7c591bcSMikko Perttunen { 69d7c591bcSMikko Perttunen return dev_get_drvdata(tegra->drm->dev->parent); 70d7c591bcSMikko Perttunen } 71d7c591bcSMikko Perttunen 72dee8268fSThierry Reding struct tegra_drm_client; 73dee8268fSThierry Reding 74dee8268fSThierry Reding struct tegra_drm_context { 75dee8268fSThierry Reding struct tegra_drm_client *client; 76dee8268fSThierry Reding struct host1x_channel *channel; 77d7c591bcSMikko Perttunen 78d7c591bcSMikko Perttunen /* Only used by legacy UAPI. */ 79bdd2f9cdSThierry Reding unsigned int id; 80d7c591bcSMikko Perttunen 81d7c591bcSMikko Perttunen /* Only used by new UAPI. */ 82d7c591bcSMikko Perttunen struct xarray mappings; 83*e09db978SMikko Perttunen struct host1x_memory_context *memory_context; 84dee8268fSThierry Reding }; 85dee8268fSThierry Reding 86dee8268fSThierry Reding struct tegra_drm_client_ops { 87dee8268fSThierry Reding int (*open_channel)(struct tegra_drm_client *client, 88dee8268fSThierry Reding struct tegra_drm_context *context); 89dee8268fSThierry Reding void (*close_channel)(struct tegra_drm_context *context); 90c40f0f1aSThierry Reding int (*is_addr_reg)(struct device *dev, u32 class, u32 offset); 910f563a4bSDmitry Osipenko int (*is_valid_class)(u32 class); 92dee8268fSThierry Reding int (*submit)(struct tegra_drm_context *context, 93dee8268fSThierry Reding struct drm_tegra_submit *args, struct drm_device *drm, 94dee8268fSThierry Reding struct drm_file *file); 95*e09db978SMikko Perttunen int (*get_streamid_offset)(struct tegra_drm_client *client, u32 *offset); 96*e09db978SMikko Perttunen int (*can_use_memory_ctx)(struct tegra_drm_client *client, bool *supported); 97dee8268fSThierry Reding }; 98dee8268fSThierry Reding 99c40f0f1aSThierry Reding int tegra_drm_submit(struct tegra_drm_context *context, 100c40f0f1aSThierry Reding struct drm_tegra_submit *args, struct drm_device *drm, 101c40f0f1aSThierry Reding struct drm_file *file); 102c40f0f1aSThierry Reding 103dee8268fSThierry Reding struct tegra_drm_client { 104dee8268fSThierry Reding struct host1x_client base; 105dee8268fSThierry Reding struct list_head list; 1068e5d19c6SThierry Reding struct tegra_drm *drm; 107e0f2977cSMikko Perttunen struct host1x_channel *shared_channel; 108dee8268fSThierry Reding 109e0f2977cSMikko Perttunen /* Set by driver */ 110f3b3cfccSThierry Reding unsigned int version; 111dee8268fSThierry Reding const struct tegra_drm_client_ops *ops; 112dee8268fSThierry Reding }; 113dee8268fSThierry Reding 114dee8268fSThierry Reding static inline struct tegra_drm_client * 115dee8268fSThierry Reding host1x_to_drm_client(struct host1x_client *client) 116dee8268fSThierry Reding { 117dee8268fSThierry Reding return container_of(client, struct tegra_drm_client, base); 118dee8268fSThierry Reding } 119dee8268fSThierry Reding 120688c59afSThierry Reding int tegra_drm_register_client(struct tegra_drm *tegra, 121dee8268fSThierry Reding struct tegra_drm_client *client); 122688c59afSThierry Reding int tegra_drm_unregister_client(struct tegra_drm *tegra, 123dee8268fSThierry Reding struct tegra_drm_client *client); 1247edd7961SThierry Reding int host1x_client_iommu_attach(struct host1x_client *client); 125aacdf198SThierry Reding void host1x_client_iommu_detach(struct host1x_client *client); 126dee8268fSThierry Reding 127688c59afSThierry Reding int tegra_drm_init(struct tegra_drm *tegra, struct drm_device *drm); 128688c59afSThierry Reding int tegra_drm_exit(struct tegra_drm *tegra); 129dee8268fSThierry Reding 130ad926015SMikko Perttunen void *tegra_drm_alloc(struct tegra_drm *tegra, size_t size, dma_addr_t *iova); 131ad926015SMikko Perttunen void tegra_drm_free(struct tegra_drm *tegra, size_t size, void *virt, 132ad926015SMikko Perttunen dma_addr_t iova); 133ad926015SMikko Perttunen 134fb83be88SHans Verkuil struct cec_notifier; 135fb83be88SHans Verkuil 136dee8268fSThierry Reding struct tegra_output { 137dee8268fSThierry Reding struct device_node *of_node; 138dee8268fSThierry Reding struct device *dev; 139dee8268fSThierry Reding 140f00b9dd5SDmitry Osipenko struct drm_bridge *bridge; 1419be7d864SThierry Reding struct drm_panel *panel; 142dee8268fSThierry Reding struct i2c_adapter *ddc; 143dee8268fSThierry Reding const struct edid *edid; 144f25d0a68SThierry Reding struct cec_notifier *cec; 145dee8268fSThierry Reding unsigned int hpd_irq; 146bbad6407SThierry Reding struct gpio_desc *hpd_gpio; 147dee8268fSThierry Reding 148dee8268fSThierry Reding struct drm_encoder encoder; 149dee8268fSThierry Reding struct drm_connector connector; 150dee8268fSThierry Reding }; 151dee8268fSThierry Reding 152dee8268fSThierry Reding static inline struct tegra_output *encoder_to_output(struct drm_encoder *e) 153dee8268fSThierry Reding { 154dee8268fSThierry Reding return container_of(e, struct tegra_output, encoder); 155dee8268fSThierry Reding } 156dee8268fSThierry Reding 157dee8268fSThierry Reding static inline struct tegra_output *connector_to_output(struct drm_connector *c) 158dee8268fSThierry Reding { 159dee8268fSThierry Reding return container_of(c, struct tegra_output, connector); 160dee8268fSThierry Reding } 161dee8268fSThierry Reding 162dee8268fSThierry Reding /* from output.c */ 163688c59afSThierry Reding int tegra_output_probe(struct tegra_output *output); 164328ec69eSThierry Reding void tegra_output_remove(struct tegra_output *output); 165688c59afSThierry Reding int tegra_output_init(struct drm_device *drm, struct tegra_output *output); 166328ec69eSThierry Reding void tegra_output_exit(struct tegra_output *output); 167c57997bcSThierry Reding void tegra_output_find_possible_crtcs(struct tegra_output *output, 168c57997bcSThierry Reding struct drm_device *drm); 169fd67e9c6SThierry Reding int tegra_output_suspend(struct tegra_output *output); 170fd67e9c6SThierry Reding int tegra_output_resume(struct tegra_output *output); 171dee8268fSThierry Reding 172132085d8SThierry Reding int tegra_output_connector_get_modes(struct drm_connector *connector); 173132085d8SThierry Reding enum drm_connector_status 174132085d8SThierry Reding tegra_output_connector_detect(struct drm_connector *connector, bool force); 175132085d8SThierry Reding void tegra_output_connector_destroy(struct drm_connector *connector); 176132085d8SThierry Reding 1776b6b6042SThierry Reding /* from dpaux.c */ 1789542c237SThierry Reding struct drm_dp_aux *drm_dp_aux_find_by_of_node(struct device_node *np); 1799542c237SThierry Reding enum drm_connector_status drm_dp_aux_detect(struct drm_dp_aux *aux); 1809542c237SThierry Reding int drm_dp_aux_attach(struct drm_dp_aux *aux, struct tegra_output *output); 1819542c237SThierry Reding int drm_dp_aux_detach(struct drm_dp_aux *aux); 1829542c237SThierry Reding int drm_dp_aux_enable(struct drm_dp_aux *aux); 1839542c237SThierry Reding int drm_dp_aux_disable(struct drm_dp_aux *aux); 1846b6b6042SThierry Reding 185dee8268fSThierry Reding /* from fb.c */ 186dee8268fSThierry Reding struct tegra_bo *tegra_fb_get_plane(struct drm_framebuffer *framebuffer, 187dee8268fSThierry Reding unsigned int index); 188db7fbdfdSThierry Reding bool tegra_fb_is_bottom_up(struct drm_framebuffer *framebuffer); 189c134f019SThierry Reding int tegra_fb_get_tiling(struct drm_framebuffer *framebuffer, 190c134f019SThierry Reding struct tegra_bo_tiling *tiling); 191f9914214SThierry Reding struct drm_framebuffer *tegra_fb_create(struct drm_device *drm, 192f9914214SThierry Reding struct drm_file *file, 1931eb83451SVille Syrjälä const struct drm_mode_fb_cmd2 *cmd); 194e2215321SThierry Reding int tegra_drm_fb_prepare(struct drm_device *drm); 1951d1e6fe9SThierry Reding void tegra_drm_fb_free(struct drm_device *drm); 196688c59afSThierry Reding int tegra_drm_fb_init(struct drm_device *drm); 197688c59afSThierry Reding void tegra_drm_fb_exit(struct drm_device *drm); 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