Commit ffc26740 authored by Eric Anholt's avatar Eric Anholt

drm/vc4: Disable V3D interactions if the v3d component didn't probe.

One might want to use the VC4 display stack without using Mesa.
Similar to the debugfs fixes for not having all of the possible
display bits enabled, make sure you can't oops in vc4 if v3d isn't
enabled.

v2: Fix matching against other v3d variants (review by Paul), don't
    forget to set irq_enabled so that the vblank uapi works
v3: Use -ENODEV instead of -EINVAL on Paul's suggestion.
Signed-off-by: default avatarEric Anholt <eric@anholt.net>
Link: https://patchwork.freedesktop.org/patch/msgid/20190401183559.3823-2-eric@anholt.netReviewed-by: default avatarPaul Kocialkowski <paul.kocialkowski@bootlin.com>
parent c9be804c
...@@ -72,6 +72,9 @@ static int vc4_get_param_ioctl(struct drm_device *dev, void *data, ...@@ -72,6 +72,9 @@ static int vc4_get_param_ioctl(struct drm_device *dev, void *data,
if (args->pad != 0) if (args->pad != 0)
return -EINVAL; return -EINVAL;
if (!vc4->v3d)
return -ENODEV;
switch (args->param) { switch (args->param) {
case DRM_VC4_PARAM_V3D_IDENT0: case DRM_VC4_PARAM_V3D_IDENT0:
ret = vc4_v3d_pm_get(vc4); ret = vc4_v3d_pm_get(vc4);
...@@ -248,6 +251,7 @@ static int vc4_drm_bind(struct device *dev) ...@@ -248,6 +251,7 @@ static int vc4_drm_bind(struct device *dev)
struct platform_device *pdev = to_platform_device(dev); struct platform_device *pdev = to_platform_device(dev);
struct drm_device *drm; struct drm_device *drm;
struct vc4_dev *vc4; struct vc4_dev *vc4;
struct device_node *node;
int ret = 0; int ret = 0;
dev->coherent_dma_mask = DMA_BIT_MASK(32); dev->coherent_dma_mask = DMA_BIT_MASK(32);
...@@ -256,6 +260,12 @@ static int vc4_drm_bind(struct device *dev) ...@@ -256,6 +260,12 @@ static int vc4_drm_bind(struct device *dev)
if (!vc4) if (!vc4)
return -ENOMEM; return -ENOMEM;
/* If VC4 V3D is missing, don't advertise render nodes. */
node = of_find_matching_node_and_match(NULL, vc4_v3d_dt_match, NULL);
if (!node || !of_device_is_available(node))
vc4_drm_driver.driver_features &= ~DRIVER_RENDER;
of_node_put(node);
drm = drm_dev_alloc(&vc4_drm_driver, dev); drm = drm_dev_alloc(&vc4_drm_driver, dev);
if (IS_ERR(drm)) if (IS_ERR(drm))
return PTR_ERR(drm); return PTR_ERR(drm);
......
...@@ -831,6 +831,7 @@ void vc4_plane_async_set_fb(struct drm_plane *plane, ...@@ -831,6 +831,7 @@ void vc4_plane_async_set_fb(struct drm_plane *plane,
/* vc4_v3d.c */ /* vc4_v3d.c */
extern struct platform_driver vc4_v3d_driver; extern struct platform_driver vc4_v3d_driver;
extern const struct of_device_id vc4_v3d_dt_match[];
int vc4_v3d_get_bin_slot(struct vc4_dev *vc4); int vc4_v3d_get_bin_slot(struct vc4_dev *vc4);
int vc4_v3d_pm_get(struct vc4_dev *vc4); int vc4_v3d_pm_get(struct vc4_dev *vc4);
void vc4_v3d_pm_put(struct vc4_dev *vc4); void vc4_v3d_pm_put(struct vc4_dev *vc4);
......
...@@ -74,6 +74,11 @@ vc4_get_hang_state_ioctl(struct drm_device *dev, void *data, ...@@ -74,6 +74,11 @@ vc4_get_hang_state_ioctl(struct drm_device *dev, void *data,
u32 i; u32 i;
int ret = 0; int ret = 0;
if (!vc4->v3d) {
DRM_DEBUG("VC4_GET_HANG_STATE with no VC4 V3D probed\n");
return -ENODEV;
}
spin_lock_irqsave(&vc4->job_lock, irqflags); spin_lock_irqsave(&vc4->job_lock, irqflags);
kernel_state = vc4->hang_state; kernel_state = vc4->hang_state;
if (!kernel_state) { if (!kernel_state) {
...@@ -1119,6 +1124,11 @@ vc4_submit_cl_ioctl(struct drm_device *dev, void *data, ...@@ -1119,6 +1124,11 @@ vc4_submit_cl_ioctl(struct drm_device *dev, void *data,
struct dma_fence *in_fence; struct dma_fence *in_fence;
int ret = 0; int ret = 0;
if (!vc4->v3d) {
DRM_DEBUG("VC4_SUBMIT_CL with no VC4 V3D probed\n");
return -ENODEV;
}
if ((args->flags & ~(VC4_SUBMIT_CL_USE_CLEAR_COLOR | if ((args->flags & ~(VC4_SUBMIT_CL_USE_CLEAR_COLOR |
VC4_SUBMIT_CL_FIXED_RCL_ORDER | VC4_SUBMIT_CL_FIXED_RCL_ORDER |
VC4_SUBMIT_CL_RCL_ORDER_INCREASING_X | VC4_SUBMIT_CL_RCL_ORDER_INCREASING_X |
......
...@@ -229,6 +229,9 @@ vc4_irq_preinstall(struct drm_device *dev) ...@@ -229,6 +229,9 @@ vc4_irq_preinstall(struct drm_device *dev)
{ {
struct vc4_dev *vc4 = to_vc4_dev(dev); struct vc4_dev *vc4 = to_vc4_dev(dev);
if (!vc4->v3d)
return;
init_waitqueue_head(&vc4->job_wait_queue); init_waitqueue_head(&vc4->job_wait_queue);
INIT_WORK(&vc4->overflow_mem_work, vc4_overflow_mem_work); INIT_WORK(&vc4->overflow_mem_work, vc4_overflow_mem_work);
...@@ -243,6 +246,9 @@ vc4_irq_postinstall(struct drm_device *dev) ...@@ -243,6 +246,9 @@ vc4_irq_postinstall(struct drm_device *dev)
{ {
struct vc4_dev *vc4 = to_vc4_dev(dev); struct vc4_dev *vc4 = to_vc4_dev(dev);
if (!vc4->v3d)
return 0;
/* Enable both the render done and out of memory interrupts. */ /* Enable both the render done and out of memory interrupts. */
V3D_WRITE(V3D_INTENA, V3D_DRIVER_IRQS); V3D_WRITE(V3D_INTENA, V3D_DRIVER_IRQS);
...@@ -254,6 +260,9 @@ vc4_irq_uninstall(struct drm_device *dev) ...@@ -254,6 +260,9 @@ vc4_irq_uninstall(struct drm_device *dev)
{ {
struct vc4_dev *vc4 = to_vc4_dev(dev); struct vc4_dev *vc4 = to_vc4_dev(dev);
if (!vc4->v3d)
return;
/* Disable sending interrupts for our driver's IRQs. */ /* Disable sending interrupts for our driver's IRQs. */
V3D_WRITE(V3D_INTDIS, V3D_DRIVER_IRQS); V3D_WRITE(V3D_INTDIS, V3D_DRIVER_IRQS);
......
...@@ -525,6 +525,7 @@ int vc4_kms_load(struct drm_device *dev) ...@@ -525,6 +525,7 @@ int vc4_kms_load(struct drm_device *dev)
/* Set support for vblank irq fast disable, before drm_vblank_init() */ /* Set support for vblank irq fast disable, before drm_vblank_init() */
dev->vblank_disable_immediate = true; dev->vblank_disable_immediate = true;
dev->irq_enabled = true;
ret = drm_vblank_init(dev, dev->mode_config.num_crtc); ret = drm_vblank_init(dev, dev->mode_config.num_crtc);
if (ret < 0) { if (ret < 0) {
dev_err(dev->dev, "failed to initialize vblank\n"); dev_err(dev->dev, "failed to initialize vblank\n");
......
...@@ -100,12 +100,18 @@ void vc4_perfmon_close_file(struct vc4_file *vc4file) ...@@ -100,12 +100,18 @@ void vc4_perfmon_close_file(struct vc4_file *vc4file)
int vc4_perfmon_create_ioctl(struct drm_device *dev, void *data, int vc4_perfmon_create_ioctl(struct drm_device *dev, void *data,
struct drm_file *file_priv) struct drm_file *file_priv)
{ {
struct vc4_dev *vc4 = to_vc4_dev(dev);
struct vc4_file *vc4file = file_priv->driver_priv; struct vc4_file *vc4file = file_priv->driver_priv;
struct drm_vc4_perfmon_create *req = data; struct drm_vc4_perfmon_create *req = data;
struct vc4_perfmon *perfmon; struct vc4_perfmon *perfmon;
unsigned int i; unsigned int i;
int ret; int ret;
if (!vc4->v3d) {
DRM_DEBUG("Creating perfmon no VC4 V3D probed\n");
return -ENODEV;
}
/* Number of monitored counters cannot exceed HW limits. */ /* Number of monitored counters cannot exceed HW limits. */
if (req->ncounters > DRM_VC4_MAX_PERF_COUNTERS || if (req->ncounters > DRM_VC4_MAX_PERF_COUNTERS ||
!req->ncounters) !req->ncounters)
...@@ -146,10 +152,16 @@ int vc4_perfmon_create_ioctl(struct drm_device *dev, void *data, ...@@ -146,10 +152,16 @@ int vc4_perfmon_create_ioctl(struct drm_device *dev, void *data,
int vc4_perfmon_destroy_ioctl(struct drm_device *dev, void *data, int vc4_perfmon_destroy_ioctl(struct drm_device *dev, void *data,
struct drm_file *file_priv) struct drm_file *file_priv)
{ {
struct vc4_dev *vc4 = to_vc4_dev(dev);
struct vc4_file *vc4file = file_priv->driver_priv; struct vc4_file *vc4file = file_priv->driver_priv;
struct drm_vc4_perfmon_destroy *req = data; struct drm_vc4_perfmon_destroy *req = data;
struct vc4_perfmon *perfmon; struct vc4_perfmon *perfmon;
if (!vc4->v3d) {
DRM_DEBUG("Destroying perfmon no VC4 V3D probed\n");
return -ENODEV;
}
mutex_lock(&vc4file->perfmon.lock); mutex_lock(&vc4file->perfmon.lock);
perfmon = idr_remove(&vc4file->perfmon.idr, req->id); perfmon = idr_remove(&vc4file->perfmon.idr, req->id);
mutex_unlock(&vc4file->perfmon.lock); mutex_unlock(&vc4file->perfmon.lock);
...@@ -164,11 +176,17 @@ int vc4_perfmon_destroy_ioctl(struct drm_device *dev, void *data, ...@@ -164,11 +176,17 @@ int vc4_perfmon_destroy_ioctl(struct drm_device *dev, void *data,
int vc4_perfmon_get_values_ioctl(struct drm_device *dev, void *data, int vc4_perfmon_get_values_ioctl(struct drm_device *dev, void *data,
struct drm_file *file_priv) struct drm_file *file_priv)
{ {
struct vc4_dev *vc4 = to_vc4_dev(dev);
struct vc4_file *vc4file = file_priv->driver_priv; struct vc4_file *vc4file = file_priv->driver_priv;
struct drm_vc4_perfmon_get_values *req = data; struct drm_vc4_perfmon_get_values *req = data;
struct vc4_perfmon *perfmon; struct vc4_perfmon *perfmon;
int ret; int ret;
if (!vc4->v3d) {
DRM_DEBUG("Getting perfmon no VC4 V3D probed\n");
return -ENODEV;
}
mutex_lock(&vc4file->perfmon.lock); mutex_lock(&vc4file->perfmon.lock);
perfmon = idr_find(&vc4file->perfmon.idr, req->id); perfmon = idr_find(&vc4file->perfmon.idr, req->id);
vc4_perfmon_get(perfmon); vc4_perfmon_get(perfmon);
......
...@@ -474,7 +474,7 @@ static int vc4_v3d_dev_remove(struct platform_device *pdev) ...@@ -474,7 +474,7 @@ static int vc4_v3d_dev_remove(struct platform_device *pdev)
return 0; return 0;
} }
static const struct of_device_id vc4_v3d_dt_match[] = { const struct of_device_id vc4_v3d_dt_match[] = {
{ .compatible = "brcm,bcm2835-v3d" }, { .compatible = "brcm,bcm2835-v3d" },
{ .compatible = "brcm,cygnus-v3d" }, { .compatible = "brcm,cygnus-v3d" },
{ .compatible = "brcm,vc4-v3d" }, { .compatible = "brcm,vc4-v3d" },
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment