drm/komeda: use the bridge connector
Subsystems (4)
v7 cover drm/komeda: use the bridge connector
Bridges following the new DRM bridge model no longer create a connector
themselves: the display driver has to attach them with DRM_BRIDGE_ATTACH_NO_CONNECTOR and create one connector for the whole chain with drm_bridge_connector_init().
komeda_attach_bridge() is reached from the probe path, so the first patch reports its attach failures with dev_err_probe().
drm_bridge_connector_init() creates the connector with drmm_connector_init(), which does not allow a ->destroy hook, so the mode configuration has to be released by DRM as well. The second patch switches komeda to drmm_mode_config_init() and adapts the private object cleanup to the new teardown order, as a preparation for the connector switch.
The third patch converts komeda to the new model.
The fourth patch frees the interrupt before the mode configuration and drm->dev_private are torn down, so the shared interrupt handler cannot dereference a cleared dev_private.
Changes in v7:
- Added a preparation patch that uses dev_err_probe() when attaching a bridge, and used dev_err_probe() for the bridge connector init failure.
Luo Liu (4):
drm/komeda: Use dev_err_probe() when attaching a bridge drm/komeda: Use drmm_mode_config_init() drm/komeda: Use the bridge connector drm/komeda: Free the IRQ before clearing dev_private
drivers/gpu/drm/arm/display/Kconfig | 2 + .../gpu/drm/arm/display/komeda/komeda_crtc.c | 17 ++++++-- .../gpu/drm/arm/display/komeda/komeda_kms.c | 41 +++++++++++-------- .../gpu/drm/arm/display/komeda/komeda_kms.h | 2 +- .../arm/display/komeda/komeda_private_obj.c | 23 ++++++++--- 5 files changed, 59 insertions(+), 26 deletions(-)
Signature · 1 line
2.25.1
PATCH v7 1/4 drm/komeda: Use dev_err_probe() when attaching a bridge
komeda_attach_bridge() is called from the probe path, through the pipeline setup in komeda_kms_attach(). Report a failure of drm_bridge_attach() with dev_err_probe(), which also keeps -EPROBE_DEFER silent.
--- drivers/gpu/drm/arm/display/komeda/komeda_crtc.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/gpu/drm/arm/display/komeda/komeda_crtc.c +3 -4
@@ -616,7 +616,6 @@ static int komeda_attach_bridge(struct device *dev,struct komeda_pipeline *pipe, struct drm_encoder *encoder) { - struct drm_device *drm = encoder->dev; struct drm_bridge *bridge;int err;
@@ -628,10 +627,10 @@ static int komeda_attach_bridge(struct device *dev, err =drm_bridge_attach (encoder, bridge,NULL ,0 );if (err) -drm_err (drm,"bridge_attach() failed for pipe: %s\n" , -of_node_full_name (pipe->of_node)); +return dev_err_probe (dev, err,"bridge_attach() failed for pipe: %s\n" , +of_node_full_name (pipe->of_node)); -return err; +return 0 ; }static const struct drm_encoder_funcs komeda_encoder_funcs = {
Signature · 1 line
2.25.1
Re: [PATCH v7 1/4] drm/komeda: Use dev_err_probe() when attaching a bridge
Quoted 6 lines · Luo Liu
komeda_attach_bridge()is called from the probe path, through the pipeline setup inkomeda_kms_attach(). Report a failure ofdrm_bridge_attach()withdev_err_probe(), which also keeps -EPROBE_DEFER silent.Signed-off-by Luo Liu <[email protected]>
Best regards,
Liviu
Quoted 33 lines
--- drivers/gpu/drm/arm/display/komeda/komeda_crtc.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)drivers/gpu/drm/arm/display/komeda/komeda_crtc.c +3
-4@@ -616,7 +616,6 @@ static int komeda_attach_bridge(struct device *dev,struct komeda_pipeline *pipe, struct drm_encoder *encoder) { - struct drm_device *drm = encoder->dev; struct drm_bridge *bridge;int err;@@ -628,10 +627,10 @@ static int komeda_attach_bridge(struct device *dev, err =drm_bridge_attach (encoder, bridge,NULL ,0 );if (err) -drm_err (drm,"bridge_attach() failed for pipe: %s\n" , -of_node_full_name (pipe->of_node)); +return dev_err_probe (dev, err,"bridge_attach() failed for pipe: %s\n" , +of_node_full_name (pipe->of_node)); -return err; +return 0 ; }static const struct drm_encoder_funcs komeda_encoder_funcs = {Signature · 1 line
2.25.1
Signature · 8 lines
====================
| I would like to |
| fix the world, |
| but they're not |
| giving me the |
\ source code! /
---------------
¯\_(ツ)_/¯PATCH v7 2/4 drm/komeda: Use drmm_mode_config_init()
In reply to Luo LiuA later change converts komeda to the bridge connector. The connector created by drm_bridge_connector_init() is allocated with drmm_connector_init() and has no ->destroy hook, so the explicit drm_mode_config_cleanup() would drop its last reference and make drm_connector_free() call a NULL ->destroy on the komeda_kms_attach() error paths and on unbind.
Switch to drmm_mode_config_init() and drop the explicit cleanup calls, so DRM releases the mode configuration after the connector cleanup actions.
The mode configuration is now released after komeda_kms_detach() returns, so the bridges attached by the encoders are still private objects in privobj_list when komeda_kms_cleanup_private_objs() runs. Finalizing them there would make drm_bridge_detach() finalize them a second time, so walk the pipelines instead and finalize each private object once.
--- .../gpu/drm/arm/display/komeda/komeda_kms.c | 38 +++++++++++-------- .../gpu/drm/arm/display/komeda/komeda_kms.h | 2 +- .../arm/display/komeda/komeda_private_obj.c | 23 ++++++++--- 3 files changed, 41 insertions(+), 22 deletions(-)
drivers/gpu/drm/arm/display/komeda/komeda_kms.c +22 -16
@@ -253,12 +253,15 @@ static const struct drm_mode_config_funcs komeda_mode_config_funcs = { .atomic_commit = drm_atomic_helper_commit, }; -static void komeda_kms_mode_config_init (struct komeda_kms_dev *kms, -struct komeda_dev *mdev) +static int komeda_kms_mode_config_init (struct komeda_kms_dev *kms, +struct komeda_dev *mdev) {struct drm_mode_config *config = &kms->base.mode_config; +int err; -drm_mode_config_init (&kms->base); + err =drmm_mode_config_init (&kms->base); +if (err) +return err;komeda_kms_setup_crtcs (kms, mdev);
@@ -270,6 +273,8 @@ static void komeda_kms_mode_config_init(struct komeda_kms_dev *kms, config->funcs = &komeda_mode_config_funcs; config->helper_private = &komeda_mode_config_helpers; + +return 0 ; }struct komeda_kms_dev *komeda_kms_attach (struct komeda_dev *mdev)
@@ -287,37 +292,39 @@ struct komeda_kms_dev *komeda_kms_attach(struct komeda_dev *mdev) drm->dev_private = mdev; -komeda_kms_mode_config_init (kms, mdev); + err =komeda_kms_mode_config_init (kms, mdev); +if (err) +return ERR_PTR (err); err =komeda_kms_add_private_objs (kms, mdev);if (err) - goto cleanup_mode_config; + goto cleanup_private_objs; err =komeda_kms_add_planes (kms, mdev);if (err) - goto cleanup_mode_config; + goto cleanup_private_objs; err =drm_vblank_init (drm, kms->n_crtcs);if (err) - goto cleanup_mode_config; + goto cleanup_private_objs; err =komeda_kms_add_crtcs (kms, mdev);if (err) - goto cleanup_mode_config; + goto cleanup_private_objs; err =komeda_kms_add_wb_connectors (kms, mdev);if (err) - goto cleanup_mode_config; + goto cleanup_private_objs; err =drm_mode_config_create_initial_state (drm);if (err) - goto cleanup_mode_config; + goto cleanup_private_objs; err =devm_request_irq (drm->dev, mdev->irq, komeda_kms_irq_handler,IRQF_SHARED , drm->driver->name, drm);if (err) - goto cleanup_mode_config; + goto cleanup_private_objs;drm_kms_helper_poll_init (drm);
@@ -329,9 +336,8 @@ struct komeda_kms_dev *komeda_kms_attach(struct komeda_dev *mdev) free_interrupts:drm_kms_helper_poll_fini (drm); -cleanup_mode_config: -drm_mode_config_cleanup (drm); -komeda_kms_cleanup_private_objs (kms); +cleanup_private_objs: +komeda_kms_cleanup_private_objs (mdev); drm->dev_private =NULL ;return ERR_PTR (err); }
@@ -339,12 +345,12 @@ struct komeda_kms_dev *komeda_kms_attach(struct komeda_dev *mdev)void komeda_kms_detach (struct komeda_kms_dev *kms) {struct drm_device *drm = &kms->base; +struct komeda_dev *mdev = drm->dev_private;drm_dev_unregister (drm);drm_kms_helper_poll_fini (drm);drm_atomic_helper_shutdown (drm); -drm_mode_config_cleanup (drm); -komeda_kms_cleanup_private_objs (kms); +komeda_kms_cleanup_private_objs (mdev); drm->dev_private =NULL ; }
drivers/gpu/drm/arm/display/komeda/komeda_kms.h +1 -1
@@ -184,7 +184,7 @@ int komeda_kms_add_private_objs(struct komeda_kms_dev *kms, struct komeda_dev *mdev);int komeda_kms_add_wb_connectors (struct komeda_kms_dev *kms,struct komeda_dev *mdev); -void komeda_kms_cleanup_private_objs (struct komeda_kms_dev *kms); +void komeda_kms_cleanup_private_objs (struct komeda_dev *mdev);void komeda_crtc_handle_event (struct komeda_crtc *kcrtc,struct komeda_events *evts);
drivers/gpu/drm/arm/display/komeda/komeda_private_obj.c +18 -5
@@ -502,11 +502,24 @@ int komeda_kms_add_private_objs(struct komeda_kms_dev *kms,return 0 ; } -void komeda_kms_cleanup_private_objs (struct komeda_kms_dev *kms) +void komeda_kms_cleanup_private_objs (struct komeda_dev *mdev) { -struct drm_mode_config *config = &kms->base.mode_config; -struct drm_private_obj *obj, *next; +struct komeda_component *c; +struct komeda_pipeline *pipe; +unsigned long avail_comps; +int i, id; + +for (i =0 ; i < mdev->n_pipelines; i++) { + pipe = mdev->pipelines[i]; -list_for_each_entry_safe (obj, next, &config->privobj_list, head) -drm_atomic_private_obj_fini (obj); +if (pipe->obj.funcs) +drm_atomic_private_obj_fini (&pipe->obj); + + avail_comps = pipe->avail_comps; +for_each_set_bit (id, &avail_comps,32 ) { + c =komeda_pipeline_get_component (pipe, id); +if (c && c->obj.funcs) +drm_atomic_private_obj_fini (&c->obj); + } + } }
Signature · 1 line
2.25.1
PATCH v7 3/4 drm/komeda: Use the bridge connector
In reply to Luo LiuBridges following the new DRM bridge model no longer create a connector
themselves: the display driver has to attach them with DRM_BRIDGE_ATTACH_NO_CONNECTOR and create one connector for the whole chain with drm_bridge_connector_init().
Convert komeda to that model, so it keeps working with bridges that have moved to the new one.
Select DRM_BRIDGE_CONNECTOR for drm_bridge_connector_init() and DRM_DISPLAY_HELPER, as the bridge connector is only visible when the display helper is enabled.
--- drivers/gpu/drm/arm/display/Kconfig | 2 ++ drivers/gpu/drm/arm/display/komeda/komeda_crtc.c | 12 +++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-)
drivers/gpu/drm/arm/display/Kconfig +2 -0
@@ -6,6 +6,8 @@ config DRM_KOMEDA select DRM_CLIENT_SELECTION select DRM_KMS_HELPER select DRM_GEM_DMA_HELPER + select DRM_DISPLAY_HELPER + select DRM_BRIDGE_CONNECTOR select VIDEOMODE_HELPERS help Choose this option if you want to compile the ARM Komeda display
drivers/gpu/drm/arm/display/komeda/komeda_crtc.c +11 -1
@@ -15,6 +15,7 @@#include <drm/drm_print.h> #include <drm/drm_vblank.h> #include <drm/drm_bridge.h> +#include <drm/drm_bridge_connector.h> #include <drm/drm_panel.h> #include "komeda_dev.h"
@@ -616,6 +617,8 @@ static int komeda_attach_bridge(struct device *dev,struct komeda_pipeline *pipe, struct drm_encoder *encoder) { + struct drm_device *drm = encoder->dev; +struct drm_connector *connector;struct drm_bridge *bridge;int err;
@@ -625,11 +628,18 @@ static int komeda_attach_bridge(struct device *dev,return dev_err_probe (dev,PTR_ERR (bridge),"remote bridge not found for pipe: %s\n" ,of_node_full_name (pipe->of_node)); - err =drm_bridge_attach (encoder, bridge,NULL ,0 ); + err =drm_bridge_attach (encoder, bridge,NULL , +DRM_BRIDGE_ATTACH_NO_CONNECTOR );if (err)return dev_err_probe (dev, err,"bridge_attach() failed for pipe: %s\n" ,of_node_full_name (pipe->of_node)); + connector =drm_bridge_connector_init (drm, encoder); +if (IS_ERR (connector)) +return dev_err_probe (dev,PTR_ERR (connector), +"bridge connector init failed for pipe: %s\n" , +of_node_full_name (pipe->of_node)); +return 0 ; }
Signature · 1 line
2.25.1
PATCH v7 4/4 drm/komeda: Free the IRQ before clearing dev_private
In reply to Luo LiuThe interrupt is requested with devm_request_irq(), so it remains registered until the device is removed and its devres resources are released. komeda_kms_detach(), and the komeda_kms_attach() error path taken when drm_dev_register() fails, clear drm->dev_private before that, while komeda_kms_irq_handler() still reads mdev from it. The interrupt line is shared, so another device can raise it in that window and make the handler dereference a NULL pointer.
Free the interrupt explicitly with devm_free_irq() before dropping drm->dev_private. free_irq() removes the action and synchronizes with any handler in flight, so the handler cannot run afterwards.
--- drivers/gpu/drm/arm/display/komeda/komeda_kms.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/gpu/drm/arm/display/komeda/komeda_kms.c +3 -0
@@ -336,6 +336,7 @@ struct komeda_kms_dev *komeda_kms_attach(struct komeda_dev *mdev) free_interrupts:drm_kms_helper_poll_fini (drm); +devm_free_irq (drm->dev, mdev->irq, drm); cleanup_private_objs:komeda_kms_cleanup_private_objs (mdev); drm->dev_private =NULL ;
@@ -350,6 +351,8 @@ void komeda_kms_detach(struct komeda_kms_dev *kms)drm_dev_unregister (drm);drm_kms_helper_poll_fini (drm);drm_atomic_helper_shutdown (drm); +/* The handler dereferences drm->dev_private, which is about to go. */ +devm_free_irq (drm->dev, mdev->irq, drm);komeda_kms_cleanup_private_objs (mdev); drm->dev_private =NULL ; }
Signature · 1 line
2.25.1
Quoted 8 lines · Luo Liu
drm/komeda: use the bridge connector
Bridges following the new DRM bridge model no longer create a connector
themselves: the display driver has to attach them withDRM_BRIDGE_ATTACH_NO_CONNECTORand create one connector for the whole chain withdrm_bridge_connector_init().[...]
Signature · 3 lines
Luca Ceresoli, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
Quoted 31 lines · Luo Liu
Bridges following the new DRM bridge model no longer create a connector
themselves: the display driver has to attach them withDRM_BRIDGE_ATTACH_NO_CONNECTORand create one connector for the whole chain withdrm_bridge_connector_init().
komeda_attach_bridge()is reached from the probe path, so the first patch reports its attach failures withdev_err_probe().
drm_bridge_connector_init()creates the connector withdrmm_connector_init(), which does not allow a ->destroy hook, so the mode configuration has to be released by DRM as well. The second patch switches komeda todrmm_mode_config_init()and adapts the private object cleanup to the new teardown order, as a preparation for the connector switch.The third patch converts komeda to the new model.
The fourth patch frees the interrupt before the mode configuration and
drm->dev_privateare torn down, so the shared interrupt handler cannot dereference a cleareddev_private.Changes in v7:
- Added a preparation patch that usesdev_err_probe()when attaching a bridge, and useddev_err_probe()for the bridge connector init failure.Luo Liu (4):
drm/komeda: Usedev_err_probe()when attaching a bridge drm/komeda: Usedrmm_mode_config_init()drm/komeda: Use the bridge connector drm/komeda: Free the IRQ before clearingdev_private
Quoted 10 lines
drivers/gpu/drm/arm/display/Kconfig | 2 + .../gpu/drm/arm/display/komeda/komeda_crtc.c | 17 ++++++-- .../gpu/drm/arm/display/komeda/komeda_kms.c | 41 +++++++++++-------- .../gpu/drm/arm/display/komeda/komeda_kms.h | 2 +- .../arm/display/komeda/komeda_private_obj.c | 23 ++++++++--- 5 files changed, 59 insertions(+), 26 deletions(-)Signature · 1 line
2.25.1
Pushed to drm-misc-next.
Best regards,
Liviu
Signature · 8 lines
====================
| I would like to |
| fix the world, |
| but they're not |
| giving me the |
\ source code! /
---------------
¯\_(ツ)_/¯