drm/rockchip: add a common subdrv interfaces

Introduce a common subdrv register/unregister interfaces, help
sub-driver to hook the drm open/close event.

Change-Id: I42a563504dd8d8e26f34946067e6e60f1ee88379
Signed-off-by: Yakir Yang <ykk@rock-chips.com>
This commit is contained in:
Yakir Yang
2016-03-18 16:42:25 +08:00
committed by Gerrit Code Review
parent 780c7a3ec1
commit bb88c2a1c5
2 changed files with 68 additions and 0 deletions

View File

@@ -40,6 +40,9 @@
#define DRIVER_MAJOR 1
#define DRIVER_MINOR 0
static LIST_HEAD(rockchip_drm_subdrv_list);
static DEFINE_MUTEX(subdrv_list_mutex);
/*
* Attach a (component) device to the shared drm dma mapping from master drm
* device. This is used by the VOPs to map GEM buffers to a common DMA
@@ -307,9 +310,37 @@ static void rockchip_drm_crtc_cancel_pending_vblank(struct drm_crtc *crtc,
priv->crtc_funcs[pipe]->cancel_pending_vblank(crtc, file_priv);
}
int rockchip_drm_register_subdrv(struct drm_rockchip_subdrv *subdrv)
{
if (!subdrv)
return -EINVAL;
mutex_lock(&subdrv_list_mutex);
list_add_tail(&subdrv->list, &rockchip_drm_subdrv_list);
mutex_unlock(&subdrv_list_mutex);
return 0;
}
EXPORT_SYMBOL_GPL(rockchip_drm_register_subdrv);
int rockchip_drm_unregister_subdrv(struct drm_rockchip_subdrv *subdrv)
{
if (!subdrv)
return -EINVAL;
mutex_lock(&subdrv_list_mutex);
list_del(&subdrv->list);
mutex_unlock(&subdrv_list_mutex);
return 0;
}
EXPORT_SYMBOL_GPL(rockchip_drm_unregister_subdrv);
static int rockchip_drm_open(struct drm_device *dev, struct drm_file *file)
{
struct rockchip_drm_file_private *file_priv;
struct drm_rockchip_subdrv *subdrv;
int ret = 0;
file_priv = kzalloc(sizeof(*file_priv), GFP_KERNEL);
if (!file_priv)
@@ -318,7 +349,23 @@ static int rockchip_drm_open(struct drm_device *dev, struct drm_file *file)
file->driver_priv = file_priv;
mutex_lock(&subdrv_list_mutex);
list_for_each_entry(subdrv, &rockchip_drm_subdrv_list, list) {
ret = subdrv->open(dev, subdrv->dev, file);
if (ret) {
mutex_unlock(&subdrv_list_mutex);
goto err_free_file_priv;
}
}
mutex_unlock(&subdrv_list_mutex);
return 0;
err_free_file_priv:
kfree(file_priv);
file_priv = NULL;
return ret;
}
static void rockchip_drm_preclose(struct drm_device *dev,
@@ -326,6 +373,7 @@ static void rockchip_drm_preclose(struct drm_device *dev,
{
struct rockchip_drm_file_private *file_private = file_priv->driver_priv;
struct rockchip_gem_object_node *cur, *d;
struct drm_rockchip_subdrv *subdrv;
struct drm_crtc *crtc;
list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)
@@ -346,6 +394,11 @@ static void rockchip_drm_preclose(struct drm_device *dev,
*/
INIT_LIST_HEAD(&file_private->gem_cpu_acquire_list);
mutex_unlock(&dev->struct_mutex);
mutex_lock(&subdrv_list_mutex);
list_for_each_entry(subdrv, &rockchip_drm_subdrv_list, list)
subdrv->close(dev, subdrv->dev, file_priv);
mutex_unlock(&subdrv_list_mutex);
}
static void rockchip_drm_postclose(struct drm_device *dev, struct drm_file *file)

View File

@@ -43,6 +43,17 @@ struct rockchip_crtc_funcs {
void (*cancel_pending_vblank)(struct drm_crtc *crtc, struct drm_file *file_priv);
};
struct drm_rockchip_subdrv {
struct list_head list;
struct device *dev;
struct drm_device *drm_dev;
int (*open)(struct drm_device *drm_dev, struct device *dev,
struct drm_file *file);
void (*close)(struct drm_device *drm_dev, struct device *dev,
struct drm_file *file);
};
struct rockchip_atomic_commit {
struct work_struct work;
struct drm_atomic_state *state;
@@ -90,4 +101,8 @@ int rockchip_drm_dma_attach_device(struct drm_device *drm_dev,
struct device *dev);
void rockchip_drm_dma_detach_device(struct drm_device *drm_dev,
struct device *dev);
int rockchip_drm_register_subdrv(struct drm_rockchip_subdrv *subdrv);
int rockchip_drm_unregister_subdrv(struct drm_rockchip_subdrv *subdrv);
#endif /* _ROCKCHIP_DRM_DRV_H_ */