Commit 32266b45 authored by Russell King's avatar Russell King

imx-drm: use supplied drm_device where possible

The component helper provides us the drm_device which is being
registered.  Rather than having to reference a global in imx-drm-core,
use this to get the imxdrm device, and also use it to register the CRTC
against.

This means we never have CRTCs/encoders/connectors without the drivers
private data being accessible.

Remove the module owner field as well; this provides no protection
against the device being unbound.
Acked-by: default avatarPhilipp Zabel <p.zabel@pengutronix.de>
Acked-by: default avatarShawn Guo <shawn.guo@linaro.org>
Reviewed-by: default avatarFabio Estevam <fabio.estevam@freescale.com>
Signed-off-by: default avatarRussell King <rmk+kernel@arm.linux.org.uk>
parent 1df8b530
...@@ -52,7 +52,6 @@ struct imx_drm_crtc { ...@@ -52,7 +52,6 @@ struct imx_drm_crtc {
struct imx_drm_device *imxdrm; struct imx_drm_device *imxdrm;
int pipe; int pipe;
struct imx_drm_crtc_helper_funcs imx_drm_helper_funcs; struct imx_drm_crtc_helper_funcs imx_drm_helper_funcs;
struct module *owner;
struct crtc_cookie cookie; struct crtc_cookie cookie;
int mux_id; int mux_id;
}; };
...@@ -74,7 +73,6 @@ static int legacyfb_depth = 16; ...@@ -74,7 +73,6 @@ static int legacyfb_depth = 16;
module_param(legacyfb_depth, int, 0444); module_param(legacyfb_depth, int, 0444);
static void imx_drm_device_put(void); static void imx_drm_device_put(void);
static struct imx_drm_device *__imx_drm_device(void);
int imx_drm_crtc_id(struct imx_drm_crtc *crtc) int imx_drm_crtc_id(struct imx_drm_crtc *crtc)
{ {
...@@ -114,7 +112,7 @@ static int imx_drm_driver_unload(struct drm_device *drm) ...@@ -114,7 +112,7 @@ static int imx_drm_driver_unload(struct drm_device *drm)
struct imx_drm_crtc *imx_drm_find_crtc(struct drm_crtc *crtc) struct imx_drm_crtc *imx_drm_find_crtc(struct drm_crtc *crtc)
{ {
struct imx_drm_device *imxdrm = __imx_drm_device(); struct imx_drm_device *imxdrm = crtc->dev->dev_private;
unsigned i; unsigned i;
for (i = 0; i < MAX_CRTC; i++) for (i = 0; i < MAX_CRTC; i++)
...@@ -241,7 +239,6 @@ static struct drm_device *imx_drm_device_get(void) ...@@ -241,7 +239,6 @@ static struct drm_device *imx_drm_device_get(void)
struct imx_drm_device *imxdrm = __imx_drm_device(); struct imx_drm_device *imxdrm = __imx_drm_device();
struct imx_drm_encoder *enc; struct imx_drm_encoder *enc;
struct imx_drm_connector *con; struct imx_drm_connector *con;
struct imx_drm_crtc *crtc;
list_for_each_entry(enc, &imxdrm->encoder_list, list) { list_for_each_entry(enc, &imxdrm->encoder_list, list) {
if (!try_module_get(enc->owner)) { if (!try_module_get(enc->owner)) {
...@@ -259,19 +256,8 @@ static struct drm_device *imx_drm_device_get(void) ...@@ -259,19 +256,8 @@ static struct drm_device *imx_drm_device_get(void)
} }
} }
list_for_each_entry(crtc, &imxdrm->crtc_list, list) {
if (!try_module_get(crtc->owner)) {
dev_err(imxdrm->dev, "could not get module %s\n",
module_name(crtc->owner));
goto unwind_crtc;
}
}
return imxdrm->drm; return imxdrm->drm;
unwind_crtc:
list_for_each_entry_continue_reverse(crtc, &imxdrm->crtc_list, list)
module_put(crtc->owner);
unwind_con: unwind_con:
list_for_each_entry_continue_reverse(con, &imxdrm->connector_list, list) list_for_each_entry_continue_reverse(con, &imxdrm->connector_list, list)
module_put(con->owner); module_put(con->owner);
...@@ -290,13 +276,9 @@ static void imx_drm_device_put(void) ...@@ -290,13 +276,9 @@ static void imx_drm_device_put(void)
struct imx_drm_device *imxdrm = __imx_drm_device(); struct imx_drm_device *imxdrm = __imx_drm_device();
struct imx_drm_encoder *enc; struct imx_drm_encoder *enc;
struct imx_drm_connector *con; struct imx_drm_connector *con;
struct imx_drm_crtc *crtc;
mutex_lock(&imxdrm->mutex); mutex_lock(&imxdrm->mutex);
list_for_each_entry(crtc, &imxdrm->crtc_list, list)
module_put(crtc->owner);
list_for_each_entry(con, &imxdrm->connector_list, list) list_for_each_entry(con, &imxdrm->connector_list, list)
module_put(con->owner); module_put(con->owner);
...@@ -536,12 +518,12 @@ static void imx_drm_update_possible_crtcs(void) ...@@ -536,12 +518,12 @@ static void imx_drm_update_possible_crtcs(void)
* The return value if !NULL is a cookie for the caller to pass to * The return value if !NULL is a cookie for the caller to pass to
* imx_drm_remove_crtc later. * imx_drm_remove_crtc later.
*/ */
int imx_drm_add_crtc(struct drm_crtc *crtc, int imx_drm_add_crtc(struct drm_device *drm, struct drm_crtc *crtc,
struct imx_drm_crtc **new_crtc, struct imx_drm_crtc **new_crtc,
const struct imx_drm_crtc_helper_funcs *imx_drm_helper_funcs, const struct imx_drm_crtc_helper_funcs *imx_drm_helper_funcs,
struct module *owner, void *cookie, int id) void *cookie, int id)
{ {
struct imx_drm_device *imxdrm = __imx_drm_device(); struct imx_drm_device *imxdrm = drm->dev_private;
struct imx_drm_crtc *imx_drm_crtc; struct imx_drm_crtc *imx_drm_crtc;
int ret; int ret;
...@@ -575,8 +557,6 @@ int imx_drm_add_crtc(struct drm_crtc *crtc, ...@@ -575,8 +557,6 @@ int imx_drm_add_crtc(struct drm_crtc *crtc,
imx_drm_crtc->crtc = crtc; imx_drm_crtc->crtc = crtc;
imx_drm_crtc->imxdrm = imxdrm; imx_drm_crtc->imxdrm = imxdrm;
imx_drm_crtc->owner = owner;
imxdrm->crtc[imx_drm_crtc->pipe] = imx_drm_crtc; imxdrm->crtc[imx_drm_crtc->pipe] = imx_drm_crtc;
*new_crtc = imx_drm_crtc; *new_crtc = imx_drm_crtc;
...@@ -588,11 +568,9 @@ int imx_drm_add_crtc(struct drm_crtc *crtc, ...@@ -588,11 +568,9 @@ int imx_drm_add_crtc(struct drm_crtc *crtc,
drm_crtc_helper_add(crtc, drm_crtc_helper_add(crtc,
imx_drm_crtc->imx_drm_helper_funcs.crtc_helper_funcs); imx_drm_crtc->imx_drm_helper_funcs.crtc_helper_funcs);
drm_crtc_init(imxdrm->drm, crtc, drm_crtc_init(drm, crtc,
imx_drm_crtc->imx_drm_helper_funcs.crtc_funcs); imx_drm_crtc->imx_drm_helper_funcs.crtc_funcs);
drm_mode_group_reinit(imxdrm->drm);
imx_drm_update_possible_crtcs(); imx_drm_update_possible_crtcs();
mutex_unlock(&imxdrm->mutex); mutex_unlock(&imxdrm->mutex);
...@@ -622,8 +600,6 @@ int imx_drm_remove_crtc(struct imx_drm_crtc *imx_drm_crtc) ...@@ -622,8 +600,6 @@ int imx_drm_remove_crtc(struct imx_drm_crtc *imx_drm_crtc)
imxdrm->crtc[imx_drm_crtc->pipe] = NULL; imxdrm->crtc[imx_drm_crtc->pipe] = NULL;
drm_mode_group_reinit(imxdrm->drm);
mutex_unlock(&imxdrm->mutex); mutex_unlock(&imxdrm->mutex);
kfree(imx_drm_crtc); kfree(imx_drm_crtc);
......
...@@ -25,10 +25,10 @@ struct imx_drm_crtc_helper_funcs { ...@@ -25,10 +25,10 @@ struct imx_drm_crtc_helper_funcs {
const struct drm_crtc_funcs *crtc_funcs; const struct drm_crtc_funcs *crtc_funcs;
}; };
int imx_drm_add_crtc(struct drm_crtc *crtc, int imx_drm_add_crtc(struct drm_device *drm, struct drm_crtc *crtc,
struct imx_drm_crtc **new_crtc, struct imx_drm_crtc **new_crtc,
const struct imx_drm_crtc_helper_funcs *imx_helper_funcs, const struct imx_drm_crtc_helper_funcs *imx_helper_funcs,
struct module *owner, void *cookie, int id); void *cookie, int id);
int imx_drm_remove_crtc(struct imx_drm_crtc *); int imx_drm_remove_crtc(struct imx_drm_crtc *);
int imx_drm_init_drm(struct platform_device *pdev, int imx_drm_init_drm(struct platform_device *pdev,
int preferred_bpp); int preferred_bpp);
......
...@@ -336,7 +336,7 @@ static int ipu_get_resources(struct ipu_crtc *ipu_crtc, ...@@ -336,7 +336,7 @@ static int ipu_get_resources(struct ipu_crtc *ipu_crtc,
} }
static int ipu_crtc_init(struct ipu_crtc *ipu_crtc, static int ipu_crtc_init(struct ipu_crtc *ipu_crtc,
struct ipu_client_platformdata *pdata) struct ipu_client_platformdata *pdata, struct drm_device *drm)
{ {
struct ipu_soc *ipu = dev_get_drvdata(ipu_crtc->dev->parent); struct ipu_soc *ipu = dev_get_drvdata(ipu_crtc->dev->parent);
int dp = -EINVAL; int dp = -EINVAL;
...@@ -350,9 +350,9 @@ static int ipu_crtc_init(struct ipu_crtc *ipu_crtc, ...@@ -350,9 +350,9 @@ static int ipu_crtc_init(struct ipu_crtc *ipu_crtc,
return ret; return ret;
} }
ret = imx_drm_add_crtc(&ipu_crtc->base, ret = imx_drm_add_crtc(drm, &ipu_crtc->base,
&ipu_crtc->imx_crtc, &ipu_crtc->imx_crtc,
&ipu_crtc_helper_funcs, THIS_MODULE, &ipu_crtc_helper_funcs,
ipu_crtc->dev->parent->of_node, pdata->di); ipu_crtc->dev->parent->of_node, pdata->di);
if (ret) { if (ret) {
dev_err(ipu_crtc->dev, "adding crtc failed with %d.\n", ret); dev_err(ipu_crtc->dev, "adding crtc failed with %d.\n", ret);
...@@ -404,6 +404,7 @@ static int ipu_crtc_init(struct ipu_crtc *ipu_crtc, ...@@ -404,6 +404,7 @@ static int ipu_crtc_init(struct ipu_crtc *ipu_crtc,
static int ipu_drm_bind(struct device *dev, struct device *master, void *data) static int ipu_drm_bind(struct device *dev, struct device *master, void *data)
{ {
struct ipu_client_platformdata *pdata = dev->platform_data; struct ipu_client_platformdata *pdata = dev->platform_data;
struct drm_device *drm = data;
struct ipu_crtc *ipu_crtc; struct ipu_crtc *ipu_crtc;
int ret; int ret;
...@@ -413,7 +414,7 @@ static int ipu_drm_bind(struct device *dev, struct device *master, void *data) ...@@ -413,7 +414,7 @@ static int ipu_drm_bind(struct device *dev, struct device *master, void *data)
ipu_crtc->dev = dev; ipu_crtc->dev = dev;
ret = ipu_crtc_init(ipu_crtc, pdata); ret = ipu_crtc_init(ipu_crtc, pdata, drm);
if (ret) if (ret)
return ret; return ret;
......
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