2019-06-04 10:11:33 +02:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
2012-11-15 21:28:22 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2012 Avionic Design GmbH
|
2013-03-22 16:34:09 +02:00
|
|
|
* Copyright (C) 2012-2013 NVIDIA CORPORATION. All rights reserved.
|
2012-11-15 21:28:22 +00:00
|
|
|
*/
|
|
|
|
|
2013-03-22 16:34:05 +02:00
|
|
|
#ifndef HOST1X_DRM_H
|
|
|
|
#define HOST1X_DRM_H 1
|
2012-11-15 21:28:22 +00:00
|
|
|
|
2013-09-24 13:59:01 +02:00
|
|
|
#include <linux/host1x.h>
|
2016-12-14 13:16:11 +02:00
|
|
|
#include <linux/iova.h>
|
2020-04-15 14:24:27 +02:00
|
|
|
#include <linux/gpio/consumer.h>
|
2013-09-24 13:59:01 +02:00
|
|
|
|
2017-11-13 11:08:13 +01:00
|
|
|
#include <drm/drm_atomic.h>
|
2020-08-14 01:06:54 +03:00
|
|
|
#include <drm/drm_bridge.h>
|
2016-11-28 20:51:09 +02:00
|
|
|
#include <drm/drm_encoder.h>
|
2012-11-15 21:28:22 +00:00
|
|
|
#include <drm/drm_fixed.h>
|
2019-01-17 22:03:34 +01:00
|
|
|
#include <drm/drm_probe_helper.h>
|
2019-08-04 11:41:30 +02:00
|
|
|
#include <uapi/drm/tegra_drm.h>
|
2012-11-15 21:28:22 +00:00
|
|
|
|
2014-06-03 14:48:12 +02:00
|
|
|
#include "gem.h"
|
2017-11-13 11:08:13 +01:00
|
|
|
#include "hub.h"
|
2017-08-15 15:41:10 +02:00
|
|
|
#include "trace.h"
|
2014-06-03 14:48:12 +02:00
|
|
|
|
2021-03-26 15:51:39 +01:00
|
|
|
/* XXX move to include/uapi/drm/drm_fourcc.h? */
|
2021-05-30 22:55:06 +03:00
|
|
|
#define DRM_FORMAT_MOD_NVIDIA_SECTOR_LAYOUT BIT_ULL(22)
|
2021-03-26 15:51:39 +01:00
|
|
|
|
2024-09-24 09:13:16 +02:00
|
|
|
struct drm_fb_helper;
|
|
|
|
struct drm_fb_helper_surface_size;
|
|
|
|
|
2023-12-13 12:19:51 +02:00
|
|
|
struct edid;
|
2013-11-06 16:20:54 -07:00
|
|
|
struct reset_control;
|
|
|
|
|
2013-09-24 13:22:17 +02:00
|
|
|
struct tegra_drm {
|
2012-11-15 21:28:22 +00:00
|
|
|
struct drm_device *drm;
|
|
|
|
|
2014-06-26 21:41:53 +02:00
|
|
|
struct iommu_domain *domain;
|
2019-10-28 13:37:18 +01:00
|
|
|
bool use_explicit_iommu;
|
2017-03-09 20:04:56 +01:00
|
|
|
struct mutex mm_lock;
|
2014-06-26 21:41:53 +02:00
|
|
|
struct drm_mm mm;
|
|
|
|
|
2016-12-14 13:16:11 +02:00
|
|
|
struct {
|
|
|
|
struct iova_domain domain;
|
|
|
|
unsigned long shift;
|
|
|
|
unsigned long limit;
|
|
|
|
} carveout;
|
|
|
|
|
2012-11-15 21:28:22 +00:00
|
|
|
struct mutex clients_lock;
|
|
|
|
struct list_head clients;
|
|
|
|
|
2021-03-26 15:51:33 +01:00
|
|
|
unsigned int hmask, vmask;
|
2014-07-11 08:29:14 +02:00
|
|
|
unsigned int pitch_align;
|
2021-03-26 15:51:38 +01:00
|
|
|
unsigned int num_crtcs;
|
2014-11-24 17:41:23 +01:00
|
|
|
|
2017-11-13 11:08:13 +01:00
|
|
|
struct tegra_display_hub *hub;
|
2012-11-15 21:28:22 +00:00
|
|
|
};
|
|
|
|
|
2021-06-10 14:04:51 +03:00
|
|
|
static inline struct host1x *tegra_drm_to_host1x(struct tegra_drm *tegra)
|
|
|
|
{
|
|
|
|
return dev_get_drvdata(tegra->drm->dev->parent);
|
|
|
|
}
|
|
|
|
|
2013-09-24 15:35:40 +02:00
|
|
|
struct tegra_drm_client;
|
2012-11-15 21:28:22 +00:00
|
|
|
|
2013-09-26 16:08:22 +02:00
|
|
|
struct tegra_drm_context {
|
2013-09-24 15:35:40 +02:00
|
|
|
struct tegra_drm_client *client;
|
2013-03-22 16:34:09 +02:00
|
|
|
struct host1x_channel *channel;
|
2021-06-10 14:04:51 +03:00
|
|
|
|
|
|
|
/* Only used by legacy UAPI. */
|
2017-03-09 20:04:55 +01:00
|
|
|
unsigned int id;
|
2021-06-10 14:04:51 +03:00
|
|
|
|
|
|
|
/* Only used by new UAPI. */
|
|
|
|
struct xarray mappings;
|
2022-06-27 17:19:53 +03:00
|
|
|
struct host1x_memory_context *memory_context;
|
2013-03-22 16:34:09 +02:00
|
|
|
};
|
|
|
|
|
2013-09-24 15:35:40 +02:00
|
|
|
struct tegra_drm_client_ops {
|
|
|
|
int (*open_channel)(struct tegra_drm_client *client,
|
2013-09-26 16:08:22 +02:00
|
|
|
struct tegra_drm_context *context);
|
|
|
|
void (*close_channel)(struct tegra_drm_context *context);
|
2013-10-10 11:00:33 +02:00
|
|
|
int (*is_addr_reg)(struct device *dev, u32 class, u32 offset);
|
2017-06-15 02:18:37 +03:00
|
|
|
int (*is_valid_class)(u32 class);
|
2013-09-26 16:08:22 +02:00
|
|
|
int (*submit)(struct tegra_drm_context *context,
|
2013-03-22 16:34:09 +02:00
|
|
|
struct drm_tegra_submit *args, struct drm_device *drm,
|
|
|
|
struct drm_file *file);
|
2022-06-27 17:19:53 +03:00
|
|
|
int (*get_streamid_offset)(struct tegra_drm_client *client, u32 *offset);
|
|
|
|
int (*can_use_memory_ctx)(struct tegra_drm_client *client, bool *supported);
|
2013-03-22 16:34:09 +02:00
|
|
|
};
|
|
|
|
|
2013-10-10 11:00:33 +02:00
|
|
|
int tegra_drm_submit(struct tegra_drm_context *context,
|
|
|
|
struct drm_tegra_submit *args, struct drm_device *drm,
|
|
|
|
struct drm_file *file);
|
|
|
|
|
2022-06-27 17:19:54 +03:00
|
|
|
static inline int
|
|
|
|
tegra_drm_get_streamid_offset_thi(struct tegra_drm_client *client, u32 *offset)
|
|
|
|
{
|
|
|
|
*offset = 0x30;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-09-24 15:35:40 +02:00
|
|
|
struct tegra_drm_client {
|
|
|
|
struct host1x_client base;
|
2013-10-14 14:43:22 +02:00
|
|
|
struct list_head list;
|
2019-02-01 14:28:31 +01:00
|
|
|
struct tegra_drm *drm;
|
2021-06-10 14:04:50 +03:00
|
|
|
struct host1x_channel *shared_channel;
|
2013-03-22 16:34:09 +02:00
|
|
|
|
2021-06-10 14:04:50 +03:00
|
|
|
/* Set by driver */
|
2018-05-16 17:05:04 +02:00
|
|
|
unsigned int version;
|
2013-09-24 15:35:40 +02:00
|
|
|
const struct tegra_drm_client_ops *ops;
|
2012-11-15 21:28:22 +00:00
|
|
|
};
|
|
|
|
|
2013-09-24 15:35:40 +02:00
|
|
|
static inline struct tegra_drm_client *
|
2013-10-14 14:43:22 +02:00
|
|
|
host1x_to_drm_client(struct host1x_client *client)
|
2013-09-24 15:35:40 +02:00
|
|
|
{
|
|
|
|
return container_of(client, struct tegra_drm_client, base);
|
|
|
|
}
|
|
|
|
|
2014-04-16 09:54:21 +02:00
|
|
|
int tegra_drm_register_client(struct tegra_drm *tegra,
|
|
|
|
struct tegra_drm_client *client);
|
|
|
|
int tegra_drm_unregister_client(struct tegra_drm *tegra,
|
|
|
|
struct tegra_drm_client *client);
|
2019-10-28 13:37:08 +01:00
|
|
|
int host1x_client_iommu_attach(struct host1x_client *client);
|
2019-02-08 14:35:13 +01:00
|
|
|
void host1x_client_iommu_detach(struct host1x_client *client);
|
2013-10-14 14:43:22 +02:00
|
|
|
|
2016-12-14 13:16:11 +02:00
|
|
|
void *tegra_drm_alloc(struct tegra_drm *tegra, size_t size, dma_addr_t *iova);
|
|
|
|
void tegra_drm_free(struct tegra_drm *tegra, size_t size, void *virt,
|
|
|
|
dma_addr_t iova);
|
|
|
|
|
2017-09-11 14:29:52 +02:00
|
|
|
struct cec_notifier;
|
|
|
|
|
2012-11-15 21:28:22 +00:00
|
|
|
struct tegra_output {
|
|
|
|
struct device_node *of_node;
|
|
|
|
struct device *dev;
|
|
|
|
|
2020-08-14 01:06:54 +03:00
|
|
|
struct drm_bridge *bridge;
|
2013-08-30 15:22:36 +02:00
|
|
|
struct drm_panel *panel;
|
2012-11-15 21:28:22 +00:00
|
|
|
struct i2c_adapter *ddc;
|
2024-08-22 20:42:50 +03:00
|
|
|
const struct drm_edid *drm_edid;
|
2018-12-10 17:34:54 +01:00
|
|
|
struct cec_notifier *cec;
|
2012-11-15 21:28:22 +00:00
|
|
|
unsigned int hpd_irq;
|
2019-06-05 10:46:46 +02:00
|
|
|
struct gpio_desc *hpd_gpio;
|
2012-11-15 21:28:22 +00:00
|
|
|
|
|
|
|
struct drm_encoder encoder;
|
|
|
|
struct drm_connector connector;
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline struct tegra_output *encoder_to_output(struct drm_encoder *e)
|
|
|
|
{
|
|
|
|
return container_of(e, struct tegra_output, encoder);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct tegra_output *connector_to_output(struct drm_connector *c)
|
|
|
|
{
|
|
|
|
return container_of(c, struct tegra_output, connector);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* from output.c */
|
2014-04-16 09:54:21 +02:00
|
|
|
int tegra_output_probe(struct tegra_output *output);
|
2014-12-19 15:55:08 +01:00
|
|
|
void tegra_output_remove(struct tegra_output *output);
|
2014-04-16 09:54:21 +02:00
|
|
|
int tegra_output_init(struct drm_device *drm, struct tegra_output *output);
|
2014-12-19 15:55:08 +01:00
|
|
|
void tegra_output_exit(struct tegra_output *output);
|
2017-10-12 19:12:57 +02:00
|
|
|
void tegra_output_find_possible_crtcs(struct tegra_output *output,
|
|
|
|
struct drm_device *drm);
|
2019-12-02 15:29:03 +01:00
|
|
|
int tegra_output_suspend(struct tegra_output *output);
|
|
|
|
int tegra_output_resume(struct tegra_output *output);
|
2012-11-15 21:28:22 +00:00
|
|
|
|
2014-11-28 15:38:40 +01:00
|
|
|
int tegra_output_connector_get_modes(struct drm_connector *connector);
|
|
|
|
enum drm_connector_status
|
|
|
|
tegra_output_connector_detect(struct drm_connector *connector, bool force);
|
|
|
|
void tegra_output_connector_destroy(struct drm_connector *connector);
|
|
|
|
|
2013-11-15 16:06:05 +01:00
|
|
|
/* from dpaux.c */
|
2015-07-08 13:39:09 +02:00
|
|
|
struct drm_dp_aux *drm_dp_aux_find_by_of_node(struct device_node *np);
|
|
|
|
enum drm_connector_status drm_dp_aux_detect(struct drm_dp_aux *aux);
|
|
|
|
int drm_dp_aux_attach(struct drm_dp_aux *aux, struct tegra_output *output);
|
|
|
|
int drm_dp_aux_detach(struct drm_dp_aux *aux);
|
|
|
|
int drm_dp_aux_enable(struct drm_dp_aux *aux);
|
|
|
|
int drm_dp_aux_disable(struct drm_dp_aux *aux);
|
2013-11-15 16:06:05 +01:00
|
|
|
|
2012-11-15 21:28:22 +00:00
|
|
|
/* from fb.c */
|
2013-03-22 16:34:08 +02:00
|
|
|
struct tegra_bo *tegra_fb_get_plane(struct drm_framebuffer *framebuffer,
|
|
|
|
unsigned int index);
|
2013-10-07 09:47:58 +02:00
|
|
|
bool tegra_fb_is_bottom_up(struct drm_framebuffer *framebuffer);
|
2014-06-03 14:48:12 +02:00
|
|
|
int tegra_fb_get_tiling(struct drm_framebuffer *framebuffer,
|
|
|
|
struct tegra_bo_tiling *tiling);
|
2023-03-30 10:36:05 +02:00
|
|
|
struct drm_framebuffer *tegra_fb_alloc(struct drm_device *drm,
|
2025-07-01 12:07:19 +03:00
|
|
|
const struct drm_format_info *info,
|
2023-03-30 10:36:05 +02:00
|
|
|
const struct drm_mode_fb_cmd2 *mode_cmd,
|
|
|
|
struct tegra_bo **planes,
|
|
|
|
unsigned int num_planes);
|
2014-11-26 13:03:57 +01:00
|
|
|
struct drm_framebuffer *tegra_fb_create(struct drm_device *drm,
|
|
|
|
struct drm_file *file,
|
drm: Pass the format info to .fb_create()
Pass along the format information from the top to .fb_create()
so that we can avoid redundant (and somewhat expensive) lookups
in the drivers.
Done with cocci (with some manual fixups):
@@
identifier func =~ ".*create.*";
identifier dev, file, mode_cmd;
@@
struct drm_framebuffer *func(
struct drm_device *dev,
struct drm_file *file,
+ const struct drm_format_info *info,
const struct drm_mode_fb_cmd2 *mode_cmd)
{
...
(
- const struct drm_format_info *info = drm_get_format_info(...);
|
- const struct drm_format_info *info;
...
- info = drm_get_format_info(...);
)
<...
- if (!info)
- return ...;
...>
}
@@
identifier func =~ ".*create.*";
identifier dev, file, mode_cmd;
@@
struct drm_framebuffer *func(
struct drm_device *dev,
struct drm_file *file,
+ const struct drm_format_info *info,
const struct drm_mode_fb_cmd2 *mode_cmd)
{
...
}
@find@
identifier fb_create_func =~ ".*create.*";
identifier dev, file, mode_cmd;
@@
struct drm_framebuffer *fb_create_func(
struct drm_device *dev,
struct drm_file *file,
+ const struct drm_format_info *info,
const struct drm_mode_fb_cmd2 *mode_cmd);
@@
identifier find.fb_create_func;
expression dev, file, mode_cmd;
@@
fb_create_func(dev, file
+ ,info
,mode_cmd)
@@
expression dev, file, mode_cmd;
@@
drm_gem_fb_create(dev, file
+ ,info
,mode_cmd)
@@
expression dev, file, mode_cmd;
@@
drm_gem_fb_create_with_dirty(dev, file
+ ,info
,mode_cmd)
@@
expression dev, file_priv, mode_cmd;
identifier info, fb;
@@
info = drm_get_format_info(...);
...
fb = dev->mode_config.funcs->fb_create(dev, file_priv
+ ,info
,mode_cmd);
@@
identifier dev, file_priv, mode_cmd;
@@
struct drm_mode_config_funcs {
...
struct drm_framebuffer *(*fb_create)(struct drm_device *dev,
struct drm_file *file_priv,
+ const struct drm_format_info *info,
const struct drm_mode_fb_cmd2 *mode_cmd);
...
};
v2: Fix kernel docs (Laurent)
Fix commit msg (Geert)
Cc: Alex Deucher <alexander.deucher@amd.com>
Cc: Liviu Dudau <liviu.dudau@arm.com>
Cc: Maxime Ripard <mripard@kernel.org>
Cc: Russell King <linux@armlinux.org.uk>
Cc: Inki Dae <inki.dae@samsung.com>
Cc: Seung-Woo Kim <sw0312.kim@samsung.com>
Cc: Kyungmin Park <kyungmin.park@samsung.com>
Cc: Patrik Jakobsson <patrik.r.jakobsson@gmail.com>
Cc: Chun-Kuang Hu <chunkuang.hu@kernel.org>
Cc: Philipp Zabel <p.zabel@pengutronix.de>
Cc: Rob Clark <robdclark@gmail.com>
Cc: Abhinav Kumar <quic_abhinavk@quicinc.com>
Cc: Dmitry Baryshkov <lumag@kernel.org>
Cc: Sean Paul <sean@poorly.run>
Cc: Marijn Suijten <marijn.suijten@somainline.org>
Cc: Marek Vasut <marex@denx.de>
Cc: Stefan Agner <stefan@agner.ch>
Cc: Lyude Paul <lyude@redhat.com>
Cc: Danilo Krummrich <dakr@kernel.org>
Cc: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Cc: Dave Airlie <airlied@redhat.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Kieran Bingham <kieran.bingham+renesas@ideasonboard.com>
Cc: Biju Das <biju.das.jz@bp.renesas.com>
Cc: Sandy Huang <hjc@rock-chips.com>
Cc: "Heiko Stübner" <heiko@sntech.de>
Cc: Andy Yan <andy.yan@rock-chips.com>
Cc: Thierry Reding <thierry.reding@gmail.com>
Cc: Mikko Perttunen <mperttunen@nvidia.com>
Cc: Dave Stevenson <dave.stevenson@raspberrypi.com>
Cc: "Maíra Canal" <mcanal@igalia.com>
Cc: Raspberry Pi Kernel Maintenance <kernel-list@raspberrypi.com>
Cc: Dmitry Osipenko <dmitry.osipenko@collabora.com>
Cc: Gurchetan Singh <gurchetansingh@chromium.org>
Cc: Chia-I Wu <olvaffe@gmail.com>
Cc: Zack Rusin <zack.rusin@broadcom.com>
Cc: Broadcom internal kernel review list <bcm-kernel-feedback-list@broadcom.com>
Cc: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
Cc: amd-gfx@lists.freedesktop.org
Cc: linux-arm-msm@vger.kernel.org
Cc: freedreno@lists.freedesktop.org
Cc: nouveau@lists.freedesktop.org
Cc: virtualization@lists.linux.dev
Cc: spice-devel@lists.freedesktop.org
Cc: linux-renesas-soc@vger.kernel.org
Cc: linux-tegra@vger.kernel.org
Cc: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
Reviewed-by: Thomas Zimmermann <tzimmermann@suse.de>
Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
Acked-by: Liviu Dudau <liviu.dudau@arm.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Acked-by: Alex Deucher <alexander.deucher@amd.com>
Acked-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20250701090722.13645-5-ville.syrjala@linux.intel.com
2025-07-01 12:07:07 +03:00
|
|
|
const struct drm_format_info *info,
|
2015-11-11 19:11:29 +02:00
|
|
|
const struct drm_mode_fb_cmd2 *cmd);
|
2023-03-30 10:36:05 +02:00
|
|
|
|
|
|
|
#ifdef CONFIG_DRM_FBDEV_EMULATION
|
2024-09-24 09:13:16 +02:00
|
|
|
int tegra_fbdev_driver_fbdev_probe(struct drm_fb_helper *helper,
|
|
|
|
struct drm_fb_helper_surface_size *sizes);
|
|
|
|
#define TEGRA_FBDEV_DRIVER_OPS \
|
|
|
|
.fbdev_probe = tegra_fbdev_driver_fbdev_probe
|
2023-03-30 10:36:05 +02:00
|
|
|
#else
|
2024-09-24 09:13:16 +02:00
|
|
|
#define TEGRA_FBDEV_DRIVER_OPS \
|
|
|
|
.fbdev_probe = NULL
|
2023-03-30 10:36:05 +02:00
|
|
|
#endif
|
2012-11-15 21:28:22 +00:00
|
|
|
|
2017-11-13 11:08:13 +01:00
|
|
|
extern struct platform_driver tegra_display_hub_driver;
|
2013-10-14 14:43:22 +02:00
|
|
|
extern struct platform_driver tegra_dc_driver;
|
|
|
|
extern struct platform_driver tegra_hdmi_driver;
|
2015-09-10 16:07:14 +02:00
|
|
|
extern struct platform_driver tegra_dsi_driver;
|
2013-11-15 16:06:05 +01:00
|
|
|
extern struct platform_driver tegra_dpaux_driver;
|
2015-09-10 16:07:14 +02:00
|
|
|
extern struct platform_driver tegra_sor_driver;
|
2013-10-14 14:43:22 +02:00
|
|
|
extern struct platform_driver tegra_gr2d_driver;
|
2013-02-28 08:08:01 +01:00
|
|
|
extern struct platform_driver tegra_gr3d_driver;
|
2016-12-14 13:16:13 +02:00
|
|
|
extern struct platform_driver tegra_vic_driver;
|
2021-09-16 17:55:17 +03:00
|
|
|
extern struct platform_driver tegra_nvdec_driver;
|
2012-11-15 21:28:22 +00:00
|
|
|
|
2013-03-22 16:34:05 +02:00
|
|
|
#endif /* HOST1X_DRM_H */
|