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