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; 83e09db978SMikko 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); 95e09db978SMikko Perttunen int (*get_streamid_offset)(struct tegra_drm_client *client, u32 *offset); 96e09db978SMikko 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 103*bf0297acSMikko Perttunen static inline int 104*bf0297acSMikko Perttunen tegra_drm_get_streamid_offset_thi(struct tegra_drm_client *client, u32 *offset) 105*bf0297acSMikko Perttunen { 106*bf0297acSMikko Perttunen *offset = 0x30; 107*bf0297acSMikko Perttunen 108*bf0297acSMikko Perttunen return 0; 109*bf0297acSMikko Perttunen } 110*bf0297acSMikko Perttunen 111dee8268fSThierry Reding struct tegra_drm_client { 112dee8268fSThierry Reding struct host1x_client base; 113dee8268fSThierry Reding struct list_head list; 1148e5d19c6SThierry Reding struct tegra_drm *drm; 115e0f2977cSMikko Perttunen struct host1x_channel *shared_channel; 116dee8268fSThierry Reding 117e0f2977cSMikko Perttunen /* Set by driver */ 118f3b3cfccSThierry Reding unsigned int version; 119dee8268fSThierry Reding const struct tegra_drm_client_ops *ops; 120dee8268fSThierry Reding }; 121dee8268fSThierry Reding 122dee8268fSThierry Reding static inline struct tegra_drm_client * 123dee8268fSThierry Reding host1x_to_drm_client(struct host1x_client *client) 124dee8268fSThierry Reding { 125dee8268fSThierry Reding return container_of(client, struct tegra_drm_client, base); 126dee8268fSThierry Reding } 127dee8268fSThierry Reding 128688c59afSThierry Reding int tegra_drm_register_client(struct tegra_drm *tegra, 129dee8268fSThierry Reding struct tegra_drm_client *client); 130688c59afSThierry Reding int tegra_drm_unregister_client(struct tegra_drm *tegra, 131dee8268fSThierry Reding struct tegra_drm_client *client); 1327edd7961SThierry Reding int host1x_client_iommu_attach(struct host1x_client *client); 133aacdf198SThierry Reding void host1x_client_iommu_detach(struct host1x_client *client); 134dee8268fSThierry Reding 135688c59afSThierry Reding int tegra_drm_init(struct tegra_drm *tegra, struct drm_device *drm); 136688c59afSThierry Reding int tegra_drm_exit(struct tegra_drm *tegra); 137dee8268fSThierry Reding 138ad926015SMikko Perttunen void *tegra_drm_alloc(struct tegra_drm *tegra, size_t size, dma_addr_t *iova); 139ad926015SMikko Perttunen void tegra_drm_free(struct tegra_drm *tegra, size_t size, void *virt, 140ad926015SMikko Perttunen dma_addr_t iova); 141ad926015SMikko Perttunen 142fb83be88SHans Verkuil struct cec_notifier; 143fb83be88SHans Verkuil 144dee8268fSThierry Reding struct tegra_output { 145dee8268fSThierry Reding struct device_node *of_node; 146dee8268fSThierry Reding struct device *dev; 147dee8268fSThierry Reding 148f00b9dd5SDmitry Osipenko struct drm_bridge *bridge; 1499be7d864SThierry Reding struct drm_panel *panel; 150dee8268fSThierry Reding struct i2c_adapter *ddc; 151dee8268fSThierry Reding const struct edid *edid; 152f25d0a68SThierry Reding struct cec_notifier *cec; 153dee8268fSThierry Reding unsigned int hpd_irq; 154bbad6407SThierry Reding struct gpio_desc *hpd_gpio; 155dee8268fSThierry Reding 156dee8268fSThierry Reding struct drm_encoder encoder; 157dee8268fSThierry Reding struct drm_connector connector; 158dee8268fSThierry Reding }; 159dee8268fSThierry Reding 160dee8268fSThierry Reding static inline struct tegra_output *encoder_to_output(struct drm_encoder *e) 161dee8268fSThierry Reding { 162dee8268fSThierry Reding return container_of(e, struct tegra_output, encoder); 163dee8268fSThierry Reding } 164dee8268fSThierry Reding 165dee8268fSThierry Reding static inline struct tegra_output *connector_to_output(struct drm_connector *c) 166dee8268fSThierry Reding { 167dee8268fSThierry Reding return container_of(c, struct tegra_output, connector); 168dee8268fSThierry Reding } 169dee8268fSThierry Reding 170dee8268fSThierry Reding /* from output.c */ 171688c59afSThierry Reding int tegra_output_probe(struct tegra_output *output); 172328ec69eSThierry Reding void tegra_output_remove(struct tegra_output *output); 173688c59afSThierry Reding int tegra_output_init(struct drm_device *drm, struct tegra_output *output); 174328ec69eSThierry Reding void tegra_output_exit(struct tegra_output *output); 175c57997bcSThierry Reding void tegra_output_find_possible_crtcs(struct tegra_output *output, 176c57997bcSThierry Reding struct drm_device *drm); 177fd67e9c6SThierry Reding int tegra_output_suspend(struct tegra_output *output); 178fd67e9c6SThierry Reding int tegra_output_resume(struct tegra_output *output); 179dee8268fSThierry Reding 180132085d8SThierry Reding int tegra_output_connector_get_modes(struct drm_connector *connector); 181132085d8SThierry Reding enum drm_connector_status 182132085d8SThierry Reding tegra_output_connector_detect(struct drm_connector *connector, bool force); 183132085d8SThierry Reding void tegra_output_connector_destroy(struct drm_connector *connector); 184132085d8SThierry Reding 1856b6b6042SThierry Reding /* from dpaux.c */ 1869542c237SThierry Reding struct drm_dp_aux *drm_dp_aux_find_by_of_node(struct device_node *np); 1879542c237SThierry Reding enum drm_connector_status drm_dp_aux_detect(struct drm_dp_aux *aux); 1889542c237SThierry Reding int drm_dp_aux_attach(struct drm_dp_aux *aux, struct tegra_output *output); 1899542c237SThierry Reding int drm_dp_aux_detach(struct drm_dp_aux *aux); 1909542c237SThierry Reding int drm_dp_aux_enable(struct drm_dp_aux *aux); 1919542c237SThierry Reding int drm_dp_aux_disable(struct drm_dp_aux *aux); 1926b6b6042SThierry Reding 193dee8268fSThierry Reding /* from fb.c */ 194dee8268fSThierry Reding struct tegra_bo *tegra_fb_get_plane(struct drm_framebuffer *framebuffer, 195dee8268fSThierry Reding unsigned int index); 196db7fbdfdSThierry Reding bool tegra_fb_is_bottom_up(struct drm_framebuffer *framebuffer); 197c134f019SThierry Reding int tegra_fb_get_tiling(struct drm_framebuffer *framebuffer, 198c134f019SThierry Reding struct tegra_bo_tiling *tiling); 199f9914214SThierry Reding struct drm_framebuffer *tegra_fb_create(struct drm_device *drm, 200f9914214SThierry Reding struct drm_file *file, 2011eb83451SVille Syrjälä const struct drm_mode_fb_cmd2 *cmd); 202e2215321SThierry Reding int tegra_drm_fb_prepare(struct drm_device *drm); 2031d1e6fe9SThierry Reding void tegra_drm_fb_free(struct drm_device *drm); 204688c59afSThierry Reding int tegra_drm_fb_init(struct drm_device *drm); 205688c59afSThierry Reding void tegra_drm_fb_exit(struct drm_device *drm); 206dee8268fSThierry Reding 207c4755fb9SThierry Reding extern struct platform_driver tegra_display_hub_driver; 208dee8268fSThierry Reding extern struct platform_driver tegra_dc_driver; 209dee8268fSThierry Reding extern struct platform_driver tegra_hdmi_driver; 210473112e4SThierry Reding extern struct platform_driver tegra_dsi_driver; 2116b6b6042SThierry Reding extern struct platform_driver tegra_dpaux_driver; 212473112e4SThierry Reding extern struct platform_driver tegra_sor_driver; 213dee8268fSThierry Reding extern struct platform_driver tegra_gr2d_driver; 2145f60ed0dSThierry Reding extern struct platform_driver tegra_gr3d_driver; 2150ae797a8SArto Merilainen extern struct platform_driver tegra_vic_driver; 21646f226c9SMikko Perttunen extern struct platform_driver tegra_nvdec_driver; 217dee8268fSThierry Reding 218dee8268fSThierry Reding #endif /* HOST1X_DRM_H */ 219