patch #1 is code refactorings to use devm_drm_irq_install.
patch #2 add the new api to install irq, patch #3 is hibmc driver uses
the newly added api to register interrupts.
Changes since v1:
Splits the original patch #1 into two patches,rewrite
to_hibmc_drm_private() function in patch #2.Fix the
comment error in patch #3, and use
devm_add_action_or_reset instead of devm_add_action.
Tian Tao (4):
drm/hisilicon: Assgin local variable to drm_device
drm/hisilicon: Code refactoring for hibmc_drm_drv
drm/irq: Add the new api to install irq
drm/hisilicon: Use the new api devm_drm_irq_install
drivers/gpu/drm/drm_irq.c | 35 ++++++++++++++++
drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c | 2 +-
drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c | 51 ++++++++++--------------
drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h | 4 +-
drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c | 2 +-
drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c | 8 ++--
include/drm/drm_irq.h | 2 +-
7 files changed, 67 insertions(+), 37 deletions(-)
--
2.7.4
Assign local variable to struct drm_device *dev because they are
used multiple times within a function.
Signed-off-by: Tian Tao <[email protected]>
---
drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c | 2 +-
drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c | 30 ++++++++++++------------
drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h | 2 +-
drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c | 2 +-
drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c | 8 ++++---
5 files changed, 23 insertions(+), 21 deletions(-)
diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c
index ea962ac..096eea9 100644
--- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c
+++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c
@@ -499,7 +499,7 @@ static const struct drm_crtc_helper_funcs hibmc_crtc_helper_funcs = {
int hibmc_de_init(struct hibmc_drm_private *priv)
{
- struct drm_device *dev = priv->dev;
+ struct drm_device *dev = &priv->dev;
struct drm_crtc *crtc = &priv->crtc;
struct drm_plane *plane = &priv->primary_plane;
int ret;
diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
index d845657..dd9fadc 100644
--- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
+++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
@@ -79,31 +79,32 @@ static const struct dev_pm_ops hibmc_pm_ops = {
static int hibmc_kms_init(struct hibmc_drm_private *priv)
{
+ struct drm_device *dev = &priv->dev;
int ret;
- drm_mode_config_init(priv->dev);
+ drm_mode_config_init(dev);
priv->mode_config_initialized = true;
- priv->dev->mode_config.min_width = 0;
- priv->dev->mode_config.min_height = 0;
- priv->dev->mode_config.max_width = 1920;
- priv->dev->mode_config.max_height = 1200;
+ dev->mode_config.min_width = 0;
+ dev->mode_config.min_height = 0;
+ dev->mode_config.max_width = 1920;
+ dev->mode_config.max_height = 1200;
- priv->dev->mode_config.fb_base = priv->fb_base;
- priv->dev->mode_config.preferred_depth = 32;
- priv->dev->mode_config.prefer_shadow = 1;
+ dev->mode_config.fb_base = priv->fb_base;
+ dev->mode_config.preferred_depth = 32;
+ dev->mode_config.prefer_shadow = 1;
- priv->dev->mode_config.funcs = (void *)&hibmc_mode_funcs;
+ dev->mode_config.funcs = (void *)&hibmc_mode_funcs;
ret = hibmc_de_init(priv);
if (ret) {
- drm_err(priv->dev, "failed to init de: %d\n", ret);
+ drm_err(dev, "failed to init de: %d\n", ret);
return ret;
}
ret = hibmc_vdac_init(priv);
if (ret) {
- drm_err(priv->dev, "failed to init vdac: %d\n", ret);
+ drm_err(dev, "failed to init vdac: %d\n", ret);
return ret;
}
@@ -113,7 +114,7 @@ static int hibmc_kms_init(struct hibmc_drm_private *priv)
static void hibmc_kms_fini(struct hibmc_drm_private *priv)
{
if (priv->mode_config_initialized) {
- drm_mode_config_cleanup(priv->dev);
+ drm_mode_config_cleanup(&priv->dev);
priv->mode_config_initialized = false;
}
}
@@ -202,7 +203,7 @@ static void hibmc_hw_config(struct hibmc_drm_private *priv)
static int hibmc_hw_map(struct hibmc_drm_private *priv)
{
- struct drm_device *dev = priv->dev;
+ struct drm_device *dev = &priv->dev;
struct pci_dev *pdev = dev->pdev;
resource_size_t addr, size, ioaddr, iosize;
@@ -258,7 +259,7 @@ static int hibmc_unload(struct drm_device *dev)
static int hibmc_load(struct drm_device *dev)
{
- struct hibmc_drm_private *priv;
+ struct hibmc_drm_private *priv = to_hibmc_drm_private(dev);
int ret;
priv = drmm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
@@ -267,7 +268,6 @@ static int hibmc_load(struct drm_device *dev)
return -ENOMEM;
}
dev->dev_private = priv;
- priv->dev = dev;
ret = hibmc_hw_init(priv);
if (ret)
diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
index f310a83..e35353a 100644
--- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
+++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
@@ -37,7 +37,7 @@ struct hibmc_drm_private {
resource_size_t fb_size;
/* drm */
- struct drm_device *dev;
+ struct drm_device dev;
struct drm_plane primary_plane;
struct drm_crtc crtc;
struct drm_encoder encoder;
diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c
index 74e26c2..d35548d 100644
--- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c
+++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c
@@ -96,7 +96,7 @@ static const struct drm_encoder_funcs hibmc_encoder_funcs = {
int hibmc_vdac_init(struct hibmc_drm_private *priv)
{
- struct drm_device *dev = priv->dev;
+ struct drm_device *dev = &priv->dev;
struct hibmc_connector *hibmc_connector = &priv->connector;
struct drm_encoder *encoder = &priv->encoder;
struct drm_connector *connector = &hibmc_connector->base;
diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c b/drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c
index 602ece1..e84fb81 100644
--- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c
+++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c
@@ -25,7 +25,7 @@ int hibmc_mm_init(struct hibmc_drm_private *hibmc)
{
struct drm_vram_mm *vmm;
int ret;
- struct drm_device *dev = hibmc->dev;
+ struct drm_device *dev = &hibmc->dev;
vmm = drm_vram_helper_alloc_mm(dev,
pci_resource_start(dev->pdev, 0),
@@ -41,10 +41,12 @@ int hibmc_mm_init(struct hibmc_drm_private *hibmc)
void hibmc_mm_fini(struct hibmc_drm_private *hibmc)
{
- if (!hibmc->dev->vram_mm)
+ struct drm_device *dev = &hibmc->dev;
+
+ if (!dev->vram_mm)
return;
- drm_vram_helper_release_mm(hibmc->dev);
+ drm_vram_helper_release_mm(dev);
}
int hibmc_dumb_create(struct drm_file *file, struct drm_device *dev,
--
2.7.4
Use the devm_drm_dev_alloc provided by the drm framework to alloc
a struct hibmc_drm_private.
Signed-off-by: Tian Tao <[email protected]>
---
drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c | 16 ++++++----------
drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h | 2 +-
2 files changed, 7 insertions(+), 11 deletions(-)
diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
index dd9fadc..c5b0b57 100644
--- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
+++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
@@ -262,13 +262,6 @@ static int hibmc_load(struct drm_device *dev)
struct hibmc_drm_private *priv = to_hibmc_drm_private(dev);
int ret;
- priv = drmm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
- if (!priv) {
- drm_err(dev, "no memory to allocate for hibmc_drm_private\n");
- return -ENOMEM;
- }
- dev->dev_private = priv;
-
ret = hibmc_hw_init(priv);
if (ret)
goto err;
@@ -311,6 +304,7 @@ static int hibmc_pci_probe(struct pci_dev *pdev,
const struct pci_device_id *ent)
{
struct drm_device *dev;
+ struct hibmc_drm_private *priv;
int ret;
ret = drm_fb_helper_remove_conflicting_pci_framebuffers(pdev,
@@ -318,12 +312,14 @@ static int hibmc_pci_probe(struct pci_dev *pdev,
if (ret)
return ret;
- dev = drm_dev_alloc(&hibmc_driver, &pdev->dev);
- if (IS_ERR(dev)) {
+ priv = devm_drm_dev_alloc(&pdev->dev, &hibmc_driver,
+ struct hibmc_drm_private, dev);
+ if (IS_ERR(priv)) {
DRM_ERROR("failed to allocate drm_device\n");
- return PTR_ERR(dev);
+ return PTR_ERR(priv);
}
+ dev = &priv->dev;
dev->pdev = pdev;
pci_set_drvdata(pdev, dev);
diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
index e35353a..7e0c756 100644
--- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
+++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
@@ -52,7 +52,7 @@ static inline struct hibmc_connector *to_hibmc_connector(struct drm_connector *c
static inline struct hibmc_drm_private *to_hibmc_drm_private(struct drm_device *dev)
{
- return dev->dev_private;
+ return container_of(dev, struct hibmc_drm_private, dev);
}
void hibmc_set_power_mode(struct hibmc_drm_private *priv,
--
2.7.4
Use devm_drm_irq_install to register interrupts so that
drm_irq_uninstall is not called when hibmc is removed.
Signed-off-by: Tian Tao <[email protected]>
Reviewed-by: Thomas Zimmermann <[email protected]>
---
drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
index c5b0b57..c918b6a 100644
--- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
+++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
@@ -247,9 +247,6 @@ static int hibmc_unload(struct drm_device *dev)
drm_atomic_helper_shutdown(dev);
- if (dev->irq_enabled)
- drm_irq_uninstall(dev);
-
pci_disable_msi(dev->pdev);
hibmc_kms_fini(priv);
hibmc_mm_fini(priv);
@@ -284,7 +281,7 @@ static int hibmc_load(struct drm_device *dev)
if (ret) {
drm_warn(dev, "enabling MSI failed: %d\n", ret);
} else {
- ret = drm_irq_install(dev, dev->pdev->irq);
+ ret = devm_drm_irq_install(dev, dev->pdev->irq);
if (ret)
drm_warn(dev, "install irq failed: %d\n", ret);
}
--
2.7.4
Hi
Am 01.12.20 um 12:55 schrieb Tian Tao:
> Assign local variable to struct drm_device *dev because they are
> used multiple times within a function.
>
> Signed-off-by: Tian Tao <[email protected]>
> ---
> drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c | 2 +-
> drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c | 30 ++++++++++++------------
> drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h | 2 +-
> drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c | 2 +-
> drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c | 8 ++++---
> 5 files changed, 23 insertions(+), 21 deletions(-)
>
> diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c
> index ea962ac..096eea9 100644
> --- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c
> +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c
> @@ -499,7 +499,7 @@ static const struct drm_crtc_helper_funcs hibmc_crtc_helper_funcs = {
>
> int hibmc_de_init(struct hibmc_drm_private *priv)
> {
> - struct drm_device *dev = priv->dev;
> + struct drm_device *dev = &priv->dev;
> struct drm_crtc *crtc = &priv->crtc;
> struct drm_plane *plane = &priv->primary_plane;
> int ret;
> diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
> index d845657..dd9fadc 100644
> --- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
> +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
> @@ -79,31 +79,32 @@ static const struct dev_pm_ops hibmc_pm_ops = {
>
> static int hibmc_kms_init(struct hibmc_drm_private *priv)
> {
> + struct drm_device *dev = &priv->dev;
> int ret;
>
> - drm_mode_config_init(priv->dev);
> + drm_mode_config_init(dev);
> priv->mode_config_initialized = true;
>
> - priv->dev->mode_config.min_width = 0;
> - priv->dev->mode_config.min_height = 0;
> - priv->dev->mode_config.max_width = 1920;
> - priv->dev->mode_config.max_height = 1200;
> + dev->mode_config.min_width = 0;
> + dev->mode_config.min_height = 0;
> + dev->mode_config.max_width = 1920;
> + dev->mode_config.max_height = 1200;
>
> - priv->dev->mode_config.fb_base = priv->fb_base;
> - priv->dev->mode_config.preferred_depth = 32;
> - priv->dev->mode_config.prefer_shadow = 1;
> + dev->mode_config.fb_base = priv->fb_base;
> + dev->mode_config.preferred_depth = 32;
> + dev->mode_config.prefer_shadow = 1;
>
> - priv->dev->mode_config.funcs = (void *)&hibmc_mode_funcs;
> + dev->mode_config.funcs = (void *)&hibmc_mode_funcs;
>
> ret = hibmc_de_init(priv);
> if (ret) {
> - drm_err(priv->dev, "failed to init de: %d\n", ret);
> + drm_err(dev, "failed to init de: %d\n", ret);
> return ret;
> }
>
> ret = hibmc_vdac_init(priv);
> if (ret) {
> - drm_err(priv->dev, "failed to init vdac: %d\n", ret);
> + drm_err(dev, "failed to init vdac: %d\n", ret);
> return ret;
> }
>
> @@ -113,7 +114,7 @@ static int hibmc_kms_init(struct hibmc_drm_private *priv)
> static void hibmc_kms_fini(struct hibmc_drm_private *priv)
> {
> if (priv->mode_config_initialized) {
> - drm_mode_config_cleanup(priv->dev);
> + drm_mode_config_cleanup(&priv->dev);
> priv->mode_config_initialized = false;
> }
> }
> @@ -202,7 +203,7 @@ static void hibmc_hw_config(struct hibmc_drm_private *priv)
>
> static int hibmc_hw_map(struct hibmc_drm_private *priv)
> {
> - struct drm_device *dev = priv->dev;
> + struct drm_device *dev = &priv->dev;
> struct pci_dev *pdev = dev->pdev;
> resource_size_t addr, size, ioaddr, iosize;
>
> @@ -258,7 +259,7 @@ static int hibmc_unload(struct drm_device *dev)
>
> static int hibmc_load(struct drm_device *dev)
> {
> - struct hibmc_drm_private *priv;
> + struct hibmc_drm_private *priv = to_hibmc_drm_private(dev);
> int ret;
>
> priv = drmm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
> @@ -267,7 +268,6 @@ static int hibmc_load(struct drm_device *dev)
> return -ENOMEM;
> }
> dev->dev_private = priv;
> - priv->dev = dev;
I'm sure this either does not build or does not work. There's a call to
drm_dev_alloc(), which initialized the DRM device. You need to assign
the returned device here. The embedding of dev only work after you
switched to devm_drm_dev_alloc() in the next patch.
For the patch at hand, just keep struct hibmc_drm_private.dev as a
pointer and you should be fine.
Best regards
Thomas
>
> ret = hibmc_hw_init(priv);
> if (ret)
> diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
> index f310a83..e35353a 100644
> --- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
> +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
> @@ -37,7 +37,7 @@ struct hibmc_drm_private {
> resource_size_t fb_size;
>
> /* drm */
> - struct drm_device *dev;
> + struct drm_device dev;
> struct drm_plane primary_plane;
> struct drm_crtc crtc;
> struct drm_encoder encoder;
> diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c
> index 74e26c2..d35548d 100644
> --- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c
> +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c
> @@ -96,7 +96,7 @@ static const struct drm_encoder_funcs hibmc_encoder_funcs = {
>
> int hibmc_vdac_init(struct hibmc_drm_private *priv)
> {
> - struct drm_device *dev = priv->dev;
> + struct drm_device *dev = &priv->dev;
> struct hibmc_connector *hibmc_connector = &priv->connector;
> struct drm_encoder *encoder = &priv->encoder;
> struct drm_connector *connector = &hibmc_connector->base;
> diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c b/drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c
> index 602ece1..e84fb81 100644
> --- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c
> +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c
> @@ -25,7 +25,7 @@ int hibmc_mm_init(struct hibmc_drm_private *hibmc)
> {
> struct drm_vram_mm *vmm;
> int ret;
> - struct drm_device *dev = hibmc->dev;
> + struct drm_device *dev = &hibmc->dev;
>
> vmm = drm_vram_helper_alloc_mm(dev,
> pci_resource_start(dev->pdev, 0),
> @@ -41,10 +41,12 @@ int hibmc_mm_init(struct hibmc_drm_private *hibmc)
>
> void hibmc_mm_fini(struct hibmc_drm_private *hibmc)
> {
> - if (!hibmc->dev->vram_mm)
> + struct drm_device *dev = &hibmc->dev;
> +
> + if (!dev->vram_mm)
> return;
>
> - drm_vram_helper_release_mm(hibmc->dev);
> + drm_vram_helper_release_mm(dev);
> }
>
> int hibmc_dumb_create(struct drm_file *file, struct drm_device *dev,
>
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Felix Imendörffer
在 2020/12/1 20:17, Thomas Zimmermann 写道:
> Hi
>
> Am 01.12.20 um 12:55 schrieb Tian Tao:
>> Assign local variable to struct drm_device *dev because they are
>> used multiple times within a function.
>>
>> Signed-off-by: Tian Tao <[email protected]>
>> ---
>> drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c | 2 +-
>> drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c | 30
>> ++++++++++++------------
>> drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h | 2 +-
>> drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c | 2 +-
>> drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c | 8 ++++---
>> 5 files changed, 23 insertions(+), 21 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c
>> b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c
>> index ea962ac..096eea9 100644
>> --- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c
>> +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c
>> @@ -499,7 +499,7 @@ static const struct drm_crtc_helper_funcs
>> hibmc_crtc_helper_funcs = {
>> int hibmc_de_init(struct hibmc_drm_private *priv)
>> {
>> - struct drm_device *dev = priv->dev;
>> + struct drm_device *dev = &priv->dev;
>> struct drm_crtc *crtc = &priv->crtc;
>> struct drm_plane *plane = &priv->primary_plane;
>> int ret;
>> diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
>> b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
>> index d845657..dd9fadc 100644
>> --- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
>> +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
>> @@ -79,31 +79,32 @@ static const struct dev_pm_ops hibmc_pm_ops = {
>> static int hibmc_kms_init(struct hibmc_drm_private *priv)
>> {
>> + struct drm_device *dev = &priv->dev;
>> int ret;
>> - drm_mode_config_init(priv->dev);
>> + drm_mode_config_init(dev);
>> priv->mode_config_initialized = true;
>> - priv->dev->mode_config.min_width = 0;
>> - priv->dev->mode_config.min_height = 0;
>> - priv->dev->mode_config.max_width = 1920;
>> - priv->dev->mode_config.max_height = 1200;
>> + dev->mode_config.min_width = 0;
>> + dev->mode_config.min_height = 0;
>> + dev->mode_config.max_width = 1920;
>> + dev->mode_config.max_height = 1200;
>> - priv->dev->mode_config.fb_base = priv->fb_base;
>> - priv->dev->mode_config.preferred_depth = 32;
>> - priv->dev->mode_config.prefer_shadow = 1;
>> + dev->mode_config.fb_base = priv->fb_base;
>> + dev->mode_config.preferred_depth = 32;
>> + dev->mode_config.prefer_shadow = 1;
>> - priv->dev->mode_config.funcs = (void *)&hibmc_mode_funcs;
>> + dev->mode_config.funcs = (void *)&hibmc_mode_funcs;
>> ret = hibmc_de_init(priv);
>> if (ret) {
>> - drm_err(priv->dev, "failed to init de: %d\n", ret);
>> + drm_err(dev, "failed to init de: %d\n", ret);
>> return ret;
>> }
>> ret = hibmc_vdac_init(priv);
>> if (ret) {
>> - drm_err(priv->dev, "failed to init vdac: %d\n", ret);
>> + drm_err(dev, "failed to init vdac: %d\n", ret);
>> return ret;
>> }
>> @@ -113,7 +114,7 @@ static int hibmc_kms_init(struct hibmc_drm_private
>> *priv)
>> static void hibmc_kms_fini(struct hibmc_drm_private *priv)
>> {
>> if (priv->mode_config_initialized) {
>> - drm_mode_config_cleanup(priv->dev);
>> + drm_mode_config_cleanup(&priv->dev);
>> priv->mode_config_initialized = false;
>> }
>> }
>> @@ -202,7 +203,7 @@ static void hibmc_hw_config(struct
>> hibmc_drm_private *priv)
>> static int hibmc_hw_map(struct hibmc_drm_private *priv)
>> {
>> - struct drm_device *dev = priv->dev;
>> + struct drm_device *dev = &priv->dev;
>> struct pci_dev *pdev = dev->pdev;
>> resource_size_t addr, size, ioaddr, iosize;
>> @@ -258,7 +259,7 @@ static int hibmc_unload(struct drm_device *dev)
>> static int hibmc_load(struct drm_device *dev)
>> {
>> - struct hibmc_drm_private *priv;
>> + struct hibmc_drm_private *priv = to_hibmc_drm_private(dev);
>> int ret;
>> priv = drmm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
>> @@ -267,7 +268,6 @@ static int hibmc_load(struct drm_device *dev)
>> return -ENOMEM;
>> }
>> dev->dev_private = priv;
>> - priv->dev = dev;
>
> I'm sure this either does not build or does not work. There's a call to
> drm_dev_alloc(), which initialized the DRM device. You need to assign
> the returned device here. The embedding of dev only work after you
> switched to devm_drm_dev_alloc() in the next patch.
>
> For the patch at hand, just keep struct hibmc_drm_private.dev as a
> pointer and you should be fine.
>
Changing drm_device *dev to drm_device dev and using devm_drm_dev_alloc
does not easily split into two patches.
The patch does not compile well on its own, but it will compile fine
with patch #2.
Can patch #1 and patch #2 be combined into a single patch,just like V1.
> Best regards
> Thomas
>
>> ret = hibmc_hw_init(priv);
>> if (ret)
>> diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
>> b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
>> index f310a83..e35353a 100644
>> --- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
>> +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
>> @@ -37,7 +37,7 @@ struct hibmc_drm_private {
>> resource_size_t fb_size;
>> /* drm */
>> - struct drm_device *dev;
>> + struct drm_device dev;
>> struct drm_plane primary_plane;
>> struct drm_crtc crtc;
>> struct drm_encoder encoder;
>> diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c
>> b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c
>> index 74e26c2..d35548d 100644
>> --- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c
>> +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c
>> @@ -96,7 +96,7 @@ static const struct drm_encoder_funcs
>> hibmc_encoder_funcs = {
>> int hibmc_vdac_init(struct hibmc_drm_private *priv)
>> {
>> - struct drm_device *dev = priv->dev;
>> + struct drm_device *dev = &priv->dev;
>> struct hibmc_connector *hibmc_connector = &priv->connector;
>> struct drm_encoder *encoder = &priv->encoder;
>> struct drm_connector *connector = &hibmc_connector->base;
>> diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c
>> b/drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c
>> index 602ece1..e84fb81 100644
>> --- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c
>> +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c
>> @@ -25,7 +25,7 @@ int hibmc_mm_init(struct hibmc_drm_private *hibmc)
>> {
>> struct drm_vram_mm *vmm;
>> int ret;
>> - struct drm_device *dev = hibmc->dev;
>> + struct drm_device *dev = &hibmc->dev;
>> vmm = drm_vram_helper_alloc_mm(dev,
>> pci_resource_start(dev->pdev, 0),
>> @@ -41,10 +41,12 @@ int hibmc_mm_init(struct hibmc_drm_private *hibmc)
>> void hibmc_mm_fini(struct hibmc_drm_private *hibmc)
>> {
>> - if (!hibmc->dev->vram_mm)
>> + struct drm_device *dev = &hibmc->dev;
>> +
>> + if (!dev->vram_mm)
>> return;
>> - drm_vram_helper_release_mm(hibmc->dev);
>> + drm_vram_helper_release_mm(dev);
>> }
>> int hibmc_dumb_create(struct drm_file *file, struct drm_device *dev,
>>
>
Hi
Am 01.12.20 um 14:05 schrieb tiantao (H):
>
>
> 在 2020/12/1 20:36, Thomas Zimmermann 写道:
>> Hi
>>
>> Am 01.12.20 um 13:26 schrieb tiantao (H):
>>>
>>>
>>> 在 2020/12/1 20:17, Thomas Zimmermann 写道:
>>>> Hi
>>>>
>>>> Am 01.12.20 um 12:55 schrieb Tian Tao:
>>>>> Assign local variable to struct drm_device *dev because they are
>>>>> used multiple times within a function.
>>>>>
>>>>> Signed-off-by: Tian Tao <[email protected]>
>>>>> ---
>>>>> drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c | 2 +-
>>>>> drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c | 30
>>>>> ++++++++++++------------
>>>>> drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h | 2 +-
>>>>> drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c | 2 +-
>>>>> drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c | 8 ++++---
>>>>> 5 files changed, 23 insertions(+), 21 deletions(-)
>>>>>
>>>>> diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c
>>>>> b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c
>>>>> index ea962ac..096eea9 100644
>>>>> --- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c
>>>>> +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c
>>>>> @@ -499,7 +499,7 @@ static const struct drm_crtc_helper_funcs
>>>>> hibmc_crtc_helper_funcs = {
>>>>> int hibmc_de_init(struct hibmc_drm_private *priv)
>>>>> {
>>>>> - struct drm_device *dev = priv->dev;
>>>>> + struct drm_device *dev = &priv->dev;
>>>>> struct drm_crtc *crtc = &priv->crtc;
>>>>> struct drm_plane *plane = &priv->primary_plane;
>>>>> int ret;
>>>>> diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
>>>>> b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
>>>>> index d845657..dd9fadc 100644
>>>>> --- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
>>>>> +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
>>>>> @@ -79,31 +79,32 @@ static const struct dev_pm_ops hibmc_pm_ops = {
>>>>> static int hibmc_kms_init(struct hibmc_drm_private *priv)
>>>>> {
>>>>> + struct drm_device *dev = &priv->dev;
>>>>> int ret;
>>>>> - drm_mode_config_init(priv->dev);
>>>>> + drm_mode_config_init(dev);
>>>>> priv->mode_config_initialized = true;
>>>>> - priv->dev->mode_config.min_width = 0;
>>>>> - priv->dev->mode_config.min_height = 0;
>>>>> - priv->dev->mode_config.max_width = 1920;
>>>>> - priv->dev->mode_config.max_height = 1200;
>>>>> + dev->mode_config.min_width = 0;
>>>>> + dev->mode_config.min_height = 0;
>>>>> + dev->mode_config.max_width = 1920;
>>>>> + dev->mode_config.max_height = 1200;
>>>>> - priv->dev->mode_config.fb_base = priv->fb_base;
>>>>> - priv->dev->mode_config.preferred_depth = 32;
>>>>> - priv->dev->mode_config.prefer_shadow = 1;
>>>>> + dev->mode_config.fb_base = priv->fb_base;
>>>>> + dev->mode_config.preferred_depth = 32;
>>>>> + dev->mode_config.prefer_shadow = 1;
>>>>> - priv->dev->mode_config.funcs = (void *)&hibmc_mode_funcs;
>>>>> + dev->mode_config.funcs = (void *)&hibmc_mode_funcs;
>>>>> ret = hibmc_de_init(priv);
>>>>> if (ret) {
>>>>> - drm_err(priv->dev, "failed to init de: %d\n", ret);
>>>>> + drm_err(dev, "failed to init de: %d\n", ret);
>>>>> return ret;
>>>>> }
>>>>> ret = hibmc_vdac_init(priv);
>>>>> if (ret) {
>>>>> - drm_err(priv->dev, "failed to init vdac: %d\n", ret);
>>>>> + drm_err(dev, "failed to init vdac: %d\n", ret);
>>>>> return ret;
>>>>> }
>>>>> @@ -113,7 +114,7 @@ static int hibmc_kms_init(struct
>>>>> hibmc_drm_private *priv)
>>>>> static void hibmc_kms_fini(struct hibmc_drm_private *priv)
>>>>> {
>>>>> if (priv->mode_config_initialized) {
>>>>> - drm_mode_config_cleanup(priv->dev);
>>>>> + drm_mode_config_cleanup(&priv->dev);
>>>>> priv->mode_config_initialized = false;
>>>>> }
>>>>> }
>>>>> @@ -202,7 +203,7 @@ static void hibmc_hw_config(struct
>>>>> hibmc_drm_private *priv)
>>>>> static int hibmc_hw_map(struct hibmc_drm_private *priv)
>>>>> {
>>>>> - struct drm_device *dev = priv->dev;
>>>>> + struct drm_device *dev = &priv->dev;
>>>>> struct pci_dev *pdev = dev->pdev;
>>>>> resource_size_t addr, size, ioaddr, iosize;
>>>>> @@ -258,7 +259,7 @@ static int hibmc_unload(struct drm_device *dev)
>>>>> static int hibmc_load(struct drm_device *dev)
>>>>> {
>>>>> - struct hibmc_drm_private *priv;
>>>>> + struct hibmc_drm_private *priv = to_hibmc_drm_private(dev);
>>>>> int ret;
>>>>> priv = drmm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
>>>>> @@ -267,7 +268,6 @@ static int hibmc_load(struct drm_device *dev)
>>>>> return -ENOMEM;
>>>>> }
>>>>> dev->dev_private = priv;
>>>>> - priv->dev = dev;
>>>>
>>>> I'm sure this either does not build or does not work. There's a call
>>>> to drm_dev_alloc(), which initialized the DRM device. You need to
>>>> assign the returned device here. The embedding of dev only work
>>>> after you switched to devm_drm_dev_alloc() in the next patch.
>>>>
>>>> For the patch at hand, just keep struct hibmc_drm_private.dev as a
>>>> pointer and you should be fine.
>>>>
>>> Changing drm_device *dev to drm_device dev and using
>>> devm_drm_dev_alloc does not easily split into two patches.
>>> The patch does not compile well on its own, but it will compile fine
>>> with patch #2.
>>> Can patch #1 and patch #2 be combined into a single patch,just like V1.
>>
>> Most of the code in this patch does
>>
>> struct drm_device *dev = &priv->dev;
>>
>> to get dev as a local variable. Why don't you do
>>
>> struct drm_device *dev = priv->dev;
>>
>> ?
>>
>> That's all that's really needed.
>
> + priv = devm_drm_dev_alloc(&pdev->dev, &hibmc_driver,
> + struct hibmc_drm_private, dev);
> devm_drm_dev_alloc function requires parameter 4, dev must be a
> non-pointer for it to work. so had to change dev in the
> hibmc_drm_private to non-pointer.
> This is also the reason to change drm_device *dev to drm_device dev.
Yes, but that's what patch 2 is about. Patch 1 is about simplifying
these pointer dereferences into local variables. For this, all you need is
struct drm_device *dev = priv->dev;
In patch 2, these lines are then changed to
struct drm_device *dev = &priv->dev;
That makes 2 self-contained patches.
Best regards
Thomas
>>
>> Best regards
>> Thomas
>>
>>>> Best regards
>>>> Thomas
>>>>
>>>>> ret = hibmc_hw_init(priv);
>>>>> if (ret)
>>>>> diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
>>>>> b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
>>>>> index f310a83..e35353a 100644
>>>>> --- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
>>>>> +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
>>>>> @@ -37,7 +37,7 @@ struct hibmc_drm_private {
>>>>> resource_size_t fb_size;
>>>>> /* drm */
>>>>> - struct drm_device *dev;
>>>>> + struct drm_device dev;
>>>>> struct drm_plane primary_plane;
>>>>> struct drm_crtc crtc;
>>>>> struct drm_encoder encoder;
>>>>> diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c
>>>>> b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c
>>>>> index 74e26c2..d35548d 100644
>>>>> --- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c
>>>>> +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c
>>>>> @@ -96,7 +96,7 @@ static const struct drm_encoder_funcs
>>>>> hibmc_encoder_funcs = {
>>>>> int hibmc_vdac_init(struct hibmc_drm_private *priv)
>>>>> {
>>>>> - struct drm_device *dev = priv->dev;
>>>>> + struct drm_device *dev = &priv->dev;
>>>>> struct hibmc_connector *hibmc_connector = &priv->connector;
>>>>> struct drm_encoder *encoder = &priv->encoder;
>>>>> struct drm_connector *connector = &hibmc_connector->base;
>>>>> diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c
>>>>> b/drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c
>>>>> index 602ece1..e84fb81 100644
>>>>> --- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c
>>>>> +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c
>>>>> @@ -25,7 +25,7 @@ int hibmc_mm_init(struct hibmc_drm_private *hibmc)
>>>>> {
>>>>> struct drm_vram_mm *vmm;
>>>>> int ret;
>>>>> - struct drm_device *dev = hibmc->dev;
>>>>> + struct drm_device *dev = &hibmc->dev;
>>>>> vmm = drm_vram_helper_alloc_mm(dev,
>>>>> pci_resource_start(dev->pdev, 0),
>>>>> @@ -41,10 +41,12 @@ int hibmc_mm_init(struct hibmc_drm_private *hibmc)
>>>>> void hibmc_mm_fini(struct hibmc_drm_private *hibmc)
>>>>> {
>>>>> - if (!hibmc->dev->vram_mm)
>>>>> + struct drm_device *dev = &hibmc->dev;
>>>>> +
>>>>> + if (!dev->vram_mm)
>>>>> return;
>>>>> - drm_vram_helper_release_mm(hibmc->dev);
>>>>> + drm_vram_helper_release_mm(dev);
>>>>> }
>>>>> int hibmc_dumb_create(struct drm_file *file, struct drm_device *dev,
>>>>>
>>>>
>>>
>>
>
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Felix Imendörffer
Add new api devm_drm_irq_install() to register interrupts,
no need to call drm_irq_uninstall() when the drm module is removed.
Signed-off-by: Tian Tao <[email protected]>
---
drivers/gpu/drm/drm_irq.c | 35 +++++++++++++++++++++++++++++++++++
include/drm/drm_irq.h | 2 +-
2 files changed, 36 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/drm_irq.c b/drivers/gpu/drm/drm_irq.c
index 09d6e9e..b363dec 100644
--- a/drivers/gpu/drm/drm_irq.c
+++ b/drivers/gpu/drm/drm_irq.c
@@ -214,6 +214,41 @@ int drm_irq_uninstall(struct drm_device *dev)
}
EXPORT_SYMBOL(drm_irq_uninstall);
+static void devm_drm_irq_uninstall(void *data)
+{
+ drm_irq_uninstall(data);
+}
+
+/**
+ * devm_drm_irq_install - install IRQ handler
+ * @dev: DRM device
+ * @irq: IRQ number to install the handler for
+ *
+ * devm_drm_irq_install is a help function of drm_irq_install.
+ *
+ * if the driver uses devm_drm_irq_install, there is no need
+ * to call drm_irq_uninstall when the drm module get unloaded,
+ * as this will done automagically.
+ *
+ * Returns:
+ * Zero on success or a negative error code on failure.
+ */
+int devm_drm_irq_install(struct drm_device *dev, int irq)
+{
+ int ret;
+
+ ret = drm_irq_install(dev, irq);
+ if (ret)
+ return ret;
+
+ ret = devm_add_action_or_reset(dev->dev, devm_drm_irq_uninstall, dev);
+ if (ret)
+ devm_drm_irq_uninstall(dev);
+
+ return ret;
+}
+EXPORT_SYMBOL(devm_drm_irq_install);
+
#if IS_ENABLED(CONFIG_DRM_LEGACY)
int drm_legacy_irq_control(struct drm_device *dev, void *data,
struct drm_file *file_priv)
diff --git a/include/drm/drm_irq.h b/include/drm/drm_irq.h
index d77f6e6..631b22f 100644
--- a/include/drm/drm_irq.h
+++ b/include/drm/drm_irq.h
@@ -28,5 +28,5 @@ struct drm_device;
int drm_irq_install(struct drm_device *dev, int irq);
int drm_irq_uninstall(struct drm_device *dev);
-
+int devm_drm_irq_install(struct drm_device *dev, int irq);
#endif
--
2.7.4
Hi
Am 01.12.20 um 13:26 schrieb tiantao (H):
>
>
> 在 2020/12/1 20:17, Thomas Zimmermann 写道:
>> Hi
>>
>> Am 01.12.20 um 12:55 schrieb Tian Tao:
>>> Assign local variable to struct drm_device *dev because they are
>>> used multiple times within a function.
>>>
>>> Signed-off-by: Tian Tao <[email protected]>
>>> ---
>>> drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c | 2 +-
>>> drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c | 30
>>> ++++++++++++------------
>>> drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h | 2 +-
>>> drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c | 2 +-
>>> drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c | 8 ++++---
>>> 5 files changed, 23 insertions(+), 21 deletions(-)
>>>
>>> diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c
>>> b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c
>>> index ea962ac..096eea9 100644
>>> --- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c
>>> +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c
>>> @@ -499,7 +499,7 @@ static const struct drm_crtc_helper_funcs
>>> hibmc_crtc_helper_funcs = {
>>> int hibmc_de_init(struct hibmc_drm_private *priv)
>>> {
>>> - struct drm_device *dev = priv->dev;
>>> + struct drm_device *dev = &priv->dev;
>>> struct drm_crtc *crtc = &priv->crtc;
>>> struct drm_plane *plane = &priv->primary_plane;
>>> int ret;
>>> diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
>>> b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
>>> index d845657..dd9fadc 100644
>>> --- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
>>> +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
>>> @@ -79,31 +79,32 @@ static const struct dev_pm_ops hibmc_pm_ops = {
>>> static int hibmc_kms_init(struct hibmc_drm_private *priv)
>>> {
>>> + struct drm_device *dev = &priv->dev;
>>> int ret;
>>> - drm_mode_config_init(priv->dev);
>>> + drm_mode_config_init(dev);
>>> priv->mode_config_initialized = true;
>>> - priv->dev->mode_config.min_width = 0;
>>> - priv->dev->mode_config.min_height = 0;
>>> - priv->dev->mode_config.max_width = 1920;
>>> - priv->dev->mode_config.max_height = 1200;
>>> + dev->mode_config.min_width = 0;
>>> + dev->mode_config.min_height = 0;
>>> + dev->mode_config.max_width = 1920;
>>> + dev->mode_config.max_height = 1200;
>>> - priv->dev->mode_config.fb_base = priv->fb_base;
>>> - priv->dev->mode_config.preferred_depth = 32;
>>> - priv->dev->mode_config.prefer_shadow = 1;
>>> + dev->mode_config.fb_base = priv->fb_base;
>>> + dev->mode_config.preferred_depth = 32;
>>> + dev->mode_config.prefer_shadow = 1;
>>> - priv->dev->mode_config.funcs = (void *)&hibmc_mode_funcs;
>>> + dev->mode_config.funcs = (void *)&hibmc_mode_funcs;
>>> ret = hibmc_de_init(priv);
>>> if (ret) {
>>> - drm_err(priv->dev, "failed to init de: %d\n", ret);
>>> + drm_err(dev, "failed to init de: %d\n", ret);
>>> return ret;
>>> }
>>> ret = hibmc_vdac_init(priv);
>>> if (ret) {
>>> - drm_err(priv->dev, "failed to init vdac: %d\n", ret);
>>> + drm_err(dev, "failed to init vdac: %d\n", ret);
>>> return ret;
>>> }
>>> @@ -113,7 +114,7 @@ static int hibmc_kms_init(struct
>>> hibmc_drm_private *priv)
>>> static void hibmc_kms_fini(struct hibmc_drm_private *priv)
>>> {
>>> if (priv->mode_config_initialized) {
>>> - drm_mode_config_cleanup(priv->dev);
>>> + drm_mode_config_cleanup(&priv->dev);
>>> priv->mode_config_initialized = false;
>>> }
>>> }
>>> @@ -202,7 +203,7 @@ static void hibmc_hw_config(struct
>>> hibmc_drm_private *priv)
>>> static int hibmc_hw_map(struct hibmc_drm_private *priv)
>>> {
>>> - struct drm_device *dev = priv->dev;
>>> + struct drm_device *dev = &priv->dev;
>>> struct pci_dev *pdev = dev->pdev;
>>> resource_size_t addr, size, ioaddr, iosize;
>>> @@ -258,7 +259,7 @@ static int hibmc_unload(struct drm_device *dev)
>>> static int hibmc_load(struct drm_device *dev)
>>> {
>>> - struct hibmc_drm_private *priv;
>>> + struct hibmc_drm_private *priv = to_hibmc_drm_private(dev);
>>> int ret;
>>> priv = drmm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
>>> @@ -267,7 +268,6 @@ static int hibmc_load(struct drm_device *dev)
>>> return -ENOMEM;
>>> }
>>> dev->dev_private = priv;
>>> - priv->dev = dev;
>>
>> I'm sure this either does not build or does not work. There's a call
>> to drm_dev_alloc(), which initialized the DRM device. You need to
>> assign the returned device here. The embedding of dev only work after
>> you switched to devm_drm_dev_alloc() in the next patch.
>>
>> For the patch at hand, just keep struct hibmc_drm_private.dev as a
>> pointer and you should be fine.
>>
> Changing drm_device *dev to drm_device dev and using devm_drm_dev_alloc
> does not easily split into two patches.
> The patch does not compile well on its own, but it will compile fine
> with patch #2.
> Can patch #1 and patch #2 be combined into a single patch,just like V1.
Most of the code in this patch does
struct drm_device *dev = &priv->dev;
to get dev as a local variable. Why don't you do
struct drm_device *dev = priv->dev;
?
That's all that's really needed.
Best regards
Thomas
>> Best regards
>> Thomas
>>
>>> ret = hibmc_hw_init(priv);
>>> if (ret)
>>> diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
>>> b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
>>> index f310a83..e35353a 100644
>>> --- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
>>> +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
>>> @@ -37,7 +37,7 @@ struct hibmc_drm_private {
>>> resource_size_t fb_size;
>>> /* drm */
>>> - struct drm_device *dev;
>>> + struct drm_device dev;
>>> struct drm_plane primary_plane;
>>> struct drm_crtc crtc;
>>> struct drm_encoder encoder;
>>> diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c
>>> b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c
>>> index 74e26c2..d35548d 100644
>>> --- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c
>>> +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c
>>> @@ -96,7 +96,7 @@ static const struct drm_encoder_funcs
>>> hibmc_encoder_funcs = {
>>> int hibmc_vdac_init(struct hibmc_drm_private *priv)
>>> {
>>> - struct drm_device *dev = priv->dev;
>>> + struct drm_device *dev = &priv->dev;
>>> struct hibmc_connector *hibmc_connector = &priv->connector;
>>> struct drm_encoder *encoder = &priv->encoder;
>>> struct drm_connector *connector = &hibmc_connector->base;
>>> diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c
>>> b/drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c
>>> index 602ece1..e84fb81 100644
>>> --- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c
>>> +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c
>>> @@ -25,7 +25,7 @@ int hibmc_mm_init(struct hibmc_drm_private *hibmc)
>>> {
>>> struct drm_vram_mm *vmm;
>>> int ret;
>>> - struct drm_device *dev = hibmc->dev;
>>> + struct drm_device *dev = &hibmc->dev;
>>> vmm = drm_vram_helper_alloc_mm(dev,
>>> pci_resource_start(dev->pdev, 0),
>>> @@ -41,10 +41,12 @@ int hibmc_mm_init(struct hibmc_drm_private *hibmc)
>>> void hibmc_mm_fini(struct hibmc_drm_private *hibmc)
>>> {
>>> - if (!hibmc->dev->vram_mm)
>>> + struct drm_device *dev = &hibmc->dev;
>>> +
>>> + if (!dev->vram_mm)
>>> return;
>>> - drm_vram_helper_release_mm(hibmc->dev);
>>> + drm_vram_helper_release_mm(dev);
>>> }
>>> int hibmc_dumb_create(struct drm_file *file, struct drm_device *dev,
>>>
>>
>
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Felix Imendörffer
在 2020/12/1 20:36, Thomas Zimmermann 写道:
> Hi
>
> Am 01.12.20 um 13:26 schrieb tiantao (H):
>>
>>
>> 在 2020/12/1 20:17, Thomas Zimmermann 写道:
>>> Hi
>>>
>>> Am 01.12.20 um 12:55 schrieb Tian Tao:
>>>> Assign local variable to struct drm_device *dev because they are
>>>> used multiple times within a function.
>>>>
>>>> Signed-off-by: Tian Tao <[email protected]>
>>>> ---
>>>> drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c | 2 +-
>>>> drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c | 30
>>>> ++++++++++++------------
>>>> drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h | 2 +-
>>>> drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c | 2 +-
>>>> drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c | 8 ++++---
>>>> 5 files changed, 23 insertions(+), 21 deletions(-)
>>>>
>>>> diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c
>>>> b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c
>>>> index ea962ac..096eea9 100644
>>>> --- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c
>>>> +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c
>>>> @@ -499,7 +499,7 @@ static const struct drm_crtc_helper_funcs
>>>> hibmc_crtc_helper_funcs = {
>>>> int hibmc_de_init(struct hibmc_drm_private *priv)
>>>> {
>>>> - struct drm_device *dev = priv->dev;
>>>> + struct drm_device *dev = &priv->dev;
>>>> struct drm_crtc *crtc = &priv->crtc;
>>>> struct drm_plane *plane = &priv->primary_plane;
>>>> int ret;
>>>> diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
>>>> b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
>>>> index d845657..dd9fadc 100644
>>>> --- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
>>>> +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
>>>> @@ -79,31 +79,32 @@ static const struct dev_pm_ops hibmc_pm_ops = {
>>>> static int hibmc_kms_init(struct hibmc_drm_private *priv)
>>>> {
>>>> + struct drm_device *dev = &priv->dev;
>>>> int ret;
>>>> - drm_mode_config_init(priv->dev);
>>>> + drm_mode_config_init(dev);
>>>> priv->mode_config_initialized = true;
>>>> - priv->dev->mode_config.min_width = 0;
>>>> - priv->dev->mode_config.min_height = 0;
>>>> - priv->dev->mode_config.max_width = 1920;
>>>> - priv->dev->mode_config.max_height = 1200;
>>>> + dev->mode_config.min_width = 0;
>>>> + dev->mode_config.min_height = 0;
>>>> + dev->mode_config.max_width = 1920;
>>>> + dev->mode_config.max_height = 1200;
>>>> - priv->dev->mode_config.fb_base = priv->fb_base;
>>>> - priv->dev->mode_config.preferred_depth = 32;
>>>> - priv->dev->mode_config.prefer_shadow = 1;
>>>> + dev->mode_config.fb_base = priv->fb_base;
>>>> + dev->mode_config.preferred_depth = 32;
>>>> + dev->mode_config.prefer_shadow = 1;
>>>> - priv->dev->mode_config.funcs = (void *)&hibmc_mode_funcs;
>>>> + dev->mode_config.funcs = (void *)&hibmc_mode_funcs;
>>>> ret = hibmc_de_init(priv);
>>>> if (ret) {
>>>> - drm_err(priv->dev, "failed to init de: %d\n", ret);
>>>> + drm_err(dev, "failed to init de: %d\n", ret);
>>>> return ret;
>>>> }
>>>> ret = hibmc_vdac_init(priv);
>>>> if (ret) {
>>>> - drm_err(priv->dev, "failed to init vdac: %d\n", ret);
>>>> + drm_err(dev, "failed to init vdac: %d\n", ret);
>>>> return ret;
>>>> }
>>>> @@ -113,7 +114,7 @@ static int hibmc_kms_init(struct
>>>> hibmc_drm_private *priv)
>>>> static void hibmc_kms_fini(struct hibmc_drm_private *priv)
>>>> {
>>>> if (priv->mode_config_initialized) {
>>>> - drm_mode_config_cleanup(priv->dev);
>>>> + drm_mode_config_cleanup(&priv->dev);
>>>> priv->mode_config_initialized = false;
>>>> }
>>>> }
>>>> @@ -202,7 +203,7 @@ static void hibmc_hw_config(struct
>>>> hibmc_drm_private *priv)
>>>> static int hibmc_hw_map(struct hibmc_drm_private *priv)
>>>> {
>>>> - struct drm_device *dev = priv->dev;
>>>> + struct drm_device *dev = &priv->dev;
>>>> struct pci_dev *pdev = dev->pdev;
>>>> resource_size_t addr, size, ioaddr, iosize;
>>>> @@ -258,7 +259,7 @@ static int hibmc_unload(struct drm_device *dev)
>>>> static int hibmc_load(struct drm_device *dev)
>>>> {
>>>> - struct hibmc_drm_private *priv;
>>>> + struct hibmc_drm_private *priv = to_hibmc_drm_private(dev);
>>>> int ret;
>>>> priv = drmm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
>>>> @@ -267,7 +268,6 @@ static int hibmc_load(struct drm_device *dev)
>>>> return -ENOMEM;
>>>> }
>>>> dev->dev_private = priv;
>>>> - priv->dev = dev;
>>>
>>> I'm sure this either does not build or does not work. There's a call
>>> to drm_dev_alloc(), which initialized the DRM device. You need to
>>> assign the returned device here. The embedding of dev only work after
>>> you switched to devm_drm_dev_alloc() in the next patch.
>>>
>>> For the patch at hand, just keep struct hibmc_drm_private.dev as a
>>> pointer and you should be fine.
>>>
>> Changing drm_device *dev to drm_device dev and using
>> devm_drm_dev_alloc does not easily split into two patches.
>> The patch does not compile well on its own, but it will compile fine
>> with patch #2.
>> Can patch #1 and patch #2 be combined into a single patch,just like V1.
>
> Most of the code in this patch does
>
> struct drm_device *dev = &priv->dev;
>
> to get dev as a local variable. Why don't you do
>
> struct drm_device *dev = priv->dev;
>
> ?
>
> That's all that's really needed.
+ priv = devm_drm_dev_alloc(&pdev->dev, &hibmc_driver,
+ struct hibmc_drm_private, dev);
devm_drm_dev_alloc function requires parameter 4, dev must be a
non-pointer for it to work. so had to change dev in the
hibmc_drm_private to non-pointer.
This is also the reason to change drm_device *dev to drm_device dev.
>
> Best regards
> Thomas
>
>>> Best regards
>>> Thomas
>>>
>>>> ret = hibmc_hw_init(priv);
>>>> if (ret)
>>>> diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
>>>> b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
>>>> index f310a83..e35353a 100644
>>>> --- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
>>>> +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
>>>> @@ -37,7 +37,7 @@ struct hibmc_drm_private {
>>>> resource_size_t fb_size;
>>>> /* drm */
>>>> - struct drm_device *dev;
>>>> + struct drm_device dev;
>>>> struct drm_plane primary_plane;
>>>> struct drm_crtc crtc;
>>>> struct drm_encoder encoder;
>>>> diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c
>>>> b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c
>>>> index 74e26c2..d35548d 100644
>>>> --- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c
>>>> +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c
>>>> @@ -96,7 +96,7 @@ static const struct drm_encoder_funcs
>>>> hibmc_encoder_funcs = {
>>>> int hibmc_vdac_init(struct hibmc_drm_private *priv)
>>>> {
>>>> - struct drm_device *dev = priv->dev;
>>>> + struct drm_device *dev = &priv->dev;
>>>> struct hibmc_connector *hibmc_connector = &priv->connector;
>>>> struct drm_encoder *encoder = &priv->encoder;
>>>> struct drm_connector *connector = &hibmc_connector->base;
>>>> diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c
>>>> b/drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c
>>>> index 602ece1..e84fb81 100644
>>>> --- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c
>>>> +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c
>>>> @@ -25,7 +25,7 @@ int hibmc_mm_init(struct hibmc_drm_private *hibmc)
>>>> {
>>>> struct drm_vram_mm *vmm;
>>>> int ret;
>>>> - struct drm_device *dev = hibmc->dev;
>>>> + struct drm_device *dev = &hibmc->dev;
>>>> vmm = drm_vram_helper_alloc_mm(dev,
>>>> pci_resource_start(dev->pdev, 0),
>>>> @@ -41,10 +41,12 @@ int hibmc_mm_init(struct hibmc_drm_private *hibmc)
>>>> void hibmc_mm_fini(struct hibmc_drm_private *hibmc)
>>>> {
>>>> - if (!hibmc->dev->vram_mm)
>>>> + struct drm_device *dev = &hibmc->dev;
>>>> +
>>>> + if (!dev->vram_mm)
>>>> return;
>>>> - drm_vram_helper_release_mm(hibmc->dev);
>>>> + drm_vram_helper_release_mm(dev);
>>>> }
>>>> int hibmc_dumb_create(struct drm_file *file, struct drm_device *dev,
>>>>
>>>
>>
>
在 2020/12/1 21:44, Thomas Zimmermann 写道:
> Hi
>
> Am 01.12.20 um 14:05 schrieb tiantao (H):
>>
>>
>> 在 2020/12/1 20:36, Thomas Zimmermann 写道:
>>> Hi
>>>
>>> Am 01.12.20 um 13:26 schrieb tiantao (H):
>>>>
>>>>
>>>> 在 2020/12/1 20:17, Thomas Zimmermann 写道:
>>>>> Hi
>>>>>
>>>>> Am 01.12.20 um 12:55 schrieb Tian Tao:
>>>>>> Assign local variable to struct drm_device *dev because they are
>>>>>> used multiple times within a function.
>>>>>>
>>>>>> Signed-off-by: Tian Tao <[email protected]>
>>>>>> ---
>>>>>> drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c | 2 +-
>>>>>> drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c | 30
>>>>>> ++++++++++++------------
>>>>>> drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h | 2 +-
>>>>>> drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c | 2 +-
>>>>>> drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c | 8 ++++---
>>>>>> 5 files changed, 23 insertions(+), 21 deletions(-)
>>>>>>
>>>>>> diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c
>>>>>> b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c
>>>>>> index ea962ac..096eea9 100644
>>>>>> --- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c
>>>>>> +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c
>>>>>> @@ -499,7 +499,7 @@ static const struct drm_crtc_helper_funcs
>>>>>> hibmc_crtc_helper_funcs = {
>>>>>> int hibmc_de_init(struct hibmc_drm_private *priv)
>>>>>> {
>>>>>> - struct drm_device *dev = priv->dev;
>>>>>> + struct drm_device *dev = &priv->dev;
>>>>>> struct drm_crtc *crtc = &priv->crtc;
>>>>>> struct drm_plane *plane = &priv->primary_plane;
>>>>>> int ret;
>>>>>> diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
>>>>>> b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
>>>>>> index d845657..dd9fadc 100644
>>>>>> --- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
>>>>>> +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
>>>>>> @@ -79,31 +79,32 @@ static const struct dev_pm_ops hibmc_pm_ops = {
>>>>>> static int hibmc_kms_init(struct hibmc_drm_private *priv)
>>>>>> {
>>>>>> + struct drm_device *dev = &priv->dev;
>>>>>> int ret;
>>>>>> - drm_mode_config_init(priv->dev);
>>>>>> + drm_mode_config_init(dev);
>>>>>> priv->mode_config_initialized = true;
>>>>>> - priv->dev->mode_config.min_width = 0;
>>>>>> - priv->dev->mode_config.min_height = 0;
>>>>>> - priv->dev->mode_config.max_width = 1920;
>>>>>> - priv->dev->mode_config.max_height = 1200;
>>>>>> + dev->mode_config.min_width = 0;
>>>>>> + dev->mode_config.min_height = 0;
>>>>>> + dev->mode_config.max_width = 1920;
>>>>>> + dev->mode_config.max_height = 1200;
>>>>>> - priv->dev->mode_config.fb_base = priv->fb_base;
>>>>>> - priv->dev->mode_config.preferred_depth = 32;
>>>>>> - priv->dev->mode_config.prefer_shadow = 1;
>>>>>> + dev->mode_config.fb_base = priv->fb_base;
>>>>>> + dev->mode_config.preferred_depth = 32;
>>>>>> + dev->mode_config.prefer_shadow = 1;
>>>>>> - priv->dev->mode_config.funcs = (void *)&hibmc_mode_funcs;
>>>>>> + dev->mode_config.funcs = (void *)&hibmc_mode_funcs;
>>>>>> ret = hibmc_de_init(priv);
>>>>>> if (ret) {
>>>>>> - drm_err(priv->dev, "failed to init de: %d\n", ret);
>>>>>> + drm_err(dev, "failed to init de: %d\n", ret);
>>>>>> return ret;
>>>>>> }
>>>>>> ret = hibmc_vdac_init(priv);
>>>>>> if (ret) {
>>>>>> - drm_err(priv->dev, "failed to init vdac: %d\n", ret);
>>>>>> + drm_err(dev, "failed to init vdac: %d\n", ret);
>>>>>> return ret;
>>>>>> }
>>>>>> @@ -113,7 +114,7 @@ static int hibmc_kms_init(struct
>>>>>> hibmc_drm_private *priv)
>>>>>> static void hibmc_kms_fini(struct hibmc_drm_private *priv)
>>>>>> {
>>>>>> if (priv->mode_config_initialized) {
>>>>>> - drm_mode_config_cleanup(priv->dev);
>>>>>> + drm_mode_config_cleanup(&priv->dev);
>>>>>> priv->mode_config_initialized = false;
>>>>>> }
>>>>>> }
>>>>>> @@ -202,7 +203,7 @@ static void hibmc_hw_config(struct
>>>>>> hibmc_drm_private *priv)
>>>>>> static int hibmc_hw_map(struct hibmc_drm_private *priv)
>>>>>> {
>>>>>> - struct drm_device *dev = priv->dev;
>>>>>> + struct drm_device *dev = &priv->dev;
>>>>>> struct pci_dev *pdev = dev->pdev;
>>>>>> resource_size_t addr, size, ioaddr, iosize;
>>>>>> @@ -258,7 +259,7 @@ static int hibmc_unload(struct drm_device *dev)
>>>>>> static int hibmc_load(struct drm_device *dev)
>>>>>> {
>>>>>> - struct hibmc_drm_private *priv;
>>>>>> + struct hibmc_drm_private *priv = to_hibmc_drm_private(dev);
>>>>>> int ret;
>>>>>> priv = drmm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
>>>>>> @@ -267,7 +268,6 @@ static int hibmc_load(struct drm_device *dev)
>>>>>> return -ENOMEM;
>>>>>> }
>>>>>> dev->dev_private = priv;
>>>>>> - priv->dev = dev;
>>>>>
>>>>> I'm sure this either does not build or does not work. There's a
>>>>> call to drm_dev_alloc(), which initialized the DRM device. You need
>>>>> to assign the returned device here. The embedding of dev only work
>>>>> after you switched to devm_drm_dev_alloc() in the next patch.
>>>>>
>>>>> For the patch at hand, just keep struct hibmc_drm_private.dev as a
>>>>> pointer and you should be fine.
>>>>>
>>>> Changing drm_device *dev to drm_device dev and using
>>>> devm_drm_dev_alloc does not easily split into two patches.
>>>> The patch does not compile well on its own, but it will compile fine
>>>> with patch #2.
>>>> Can patch #1 and patch #2 be combined into a single patch,just like V1.
>>>
>>> Most of the code in this patch does
>>>
>>> struct drm_device *dev = &priv->dev;
>>>
>>> to get dev as a local variable. Why don't you do
>>>
>>> struct drm_device *dev = priv->dev;
>>>
>>> ?
>>>
>>> That's all that's really needed.
>>
>> + priv = devm_drm_dev_alloc(&pdev->dev, &hibmc_driver,
>> + struct hibmc_drm_private, dev);
>> devm_drm_dev_alloc function requires parameter 4, dev must be a
>> non-pointer for it to work. so had to change dev in the
>> hibmc_drm_private to non-pointer.
>> This is also the reason to change drm_device *dev to drm_device dev.
>
> Yes, but that's what patch 2 is about. Patch 1 is about simplifying
> these pointer dereferences into local variables. For this, all you need is
>
> struct drm_device *dev = priv->dev;
I'm sorry, I still don't understand what you mean.The latest code on the
drm branch looks like this "struct drm_device *dev = priv->dev;"
If I change the dev of hibmc_drm_private to local variables, I won't be
able to assign it like this "struct drm_device *dev = priv->dev;", right?
>
> In patch 2, these lines are then changed to
>
> struct drm_device *dev = &priv->dev;
>
> That makes 2 self-contained patches.
>
> Best regards
> Thomas
>
>>>
>>> Best regards
>>> Thomas
>>>
>>>>> Best regards
>>>>> Thomas
>>>>>
>>>>>> ret = hibmc_hw_init(priv);
>>>>>> if (ret)
>>>>>> diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
>>>>>> b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
>>>>>> index f310a83..e35353a 100644
>>>>>> --- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
>>>>>> +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
>>>>>> @@ -37,7 +37,7 @@ struct hibmc_drm_private {
>>>>>> resource_size_t fb_size;
>>>>>> /* drm */
>>>>>> - struct drm_device *dev;
>>>>>> + struct drm_device dev;
>>>>>> struct drm_plane primary_plane;
>>>>>> struct drm_crtc crtc;
>>>>>> struct drm_encoder encoder;
>>>>>> diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c
>>>>>> b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c
>>>>>> index 74e26c2..d35548d 100644
>>>>>> --- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c
>>>>>> +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c
>>>>>> @@ -96,7 +96,7 @@ static const struct drm_encoder_funcs
>>>>>> hibmc_encoder_funcs = {
>>>>>> int hibmc_vdac_init(struct hibmc_drm_private *priv)
>>>>>> {
>>>>>> - struct drm_device *dev = priv->dev;
>>>>>> + struct drm_device *dev = &priv->dev;
>>>>>> struct hibmc_connector *hibmc_connector = &priv->connector;
>>>>>> struct drm_encoder *encoder = &priv->encoder;
>>>>>> struct drm_connector *connector = &hibmc_connector->base;
>>>>>> diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c
>>>>>> b/drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c
>>>>>> index 602ece1..e84fb81 100644
>>>>>> --- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c
>>>>>> +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c
>>>>>> @@ -25,7 +25,7 @@ int hibmc_mm_init(struct hibmc_drm_private *hibmc)
>>>>>> {
>>>>>> struct drm_vram_mm *vmm;
>>>>>> int ret;
>>>>>> - struct drm_device *dev = hibmc->dev;
>>>>>> + struct drm_device *dev = &hibmc->dev;
>>>>>> vmm = drm_vram_helper_alloc_mm(dev,
>>>>>> pci_resource_start(dev->pdev, 0),
>>>>>> @@ -41,10 +41,12 @@ int hibmc_mm_init(struct hibmc_drm_private
>>>>>> *hibmc)
>>>>>> void hibmc_mm_fini(struct hibmc_drm_private *hibmc)
>>>>>> {
>>>>>> - if (!hibmc->dev->vram_mm)
>>>>>> + struct drm_device *dev = &hibmc->dev;
>>>>>> +
>>>>>> + if (!dev->vram_mm)
>>>>>> return;
>>>>>> - drm_vram_helper_release_mm(hibmc->dev);
>>>>>> + drm_vram_helper_release_mm(dev);
>>>>>> }
>>>>>> int hibmc_dumb_create(struct drm_file *file, struct drm_device
>>>>>> *dev,
>>>>>>
>>>>>
>>>>
>>>
>>
>
在 2020/12/2 10:06, tiantao (H) 写道:
>
>
> 在 2020/12/1 21:44, Thomas Zimmermann 写道:
>> Hi
>>
>> Am 01.12.20 um 14:05 schrieb tiantao (H):
>>>
>>>
>>> 在 2020/12/1 20:36, Thomas Zimmermann 写道:
>>>> Hi
>>>>
>>>> Am 01.12.20 um 13:26 schrieb tiantao (H):
>>>>>
>>>>>
>>>>> 在 2020/12/1 20:17, Thomas Zimmermann 写道:
>>>>>> Hi
>>>>>>
>>>>>> Am 01.12.20 um 12:55 schrieb Tian Tao:
>>>>>>> Assign local variable to struct drm_device *dev because they are
>>>>>>> used multiple times within a function.
>>>>>>>
>>>>>>> Signed-off-by: Tian Tao <[email protected]>
>>>>>>> ---
>>>>>>> drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c | 2 +-
>>>>>>> drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c | 30
>>>>>>> ++++++++++++------------
>>>>>>> drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h | 2 +-
>>>>>>> drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c | 2 +-
>>>>>>> drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c | 8 ++++---
>>>>>>> 5 files changed, 23 insertions(+), 21 deletions(-)
>>>>>>>
>>>>>>> diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c
>>>>>>> b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c
>>>>>>> index ea962ac..096eea9 100644
>>>>>>> --- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c
>>>>>>> +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c
>>>>>>> @@ -499,7 +499,7 @@ static const struct drm_crtc_helper_funcs
>>>>>>> hibmc_crtc_helper_funcs = {
>>>>>>> int hibmc_de_init(struct hibmc_drm_private *priv)
>>>>>>> {
>>>>>>> - struct drm_device *dev = priv->dev;
>>>>>>> + struct drm_device *dev = &priv->dev;
>>>>>>> struct drm_crtc *crtc = &priv->crtc;
>>>>>>> struct drm_plane *plane = &priv->primary_plane;
>>>>>>> int ret;
>>>>>>> diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
>>>>>>> b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
>>>>>>> index d845657..dd9fadc 100644
>>>>>>> --- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
>>>>>>> +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
>>>>>>> @@ -79,31 +79,32 @@ static const struct dev_pm_ops hibmc_pm_ops = {
>>>>>>> static int hibmc_kms_init(struct hibmc_drm_private *priv)
>>>>>>> {
>>>>>>> + struct drm_device *dev = &priv->dev;
>>>>>>> int ret;
>>>>>>> - drm_mode_config_init(priv->dev);
>>>>>>> + drm_mode_config_init(dev);
>>>>>>> priv->mode_config_initialized = true;
>>>>>>> - priv->dev->mode_config.min_width = 0;
>>>>>>> - priv->dev->mode_config.min_height = 0;
>>>>>>> - priv->dev->mode_config.max_width = 1920;
>>>>>>> - priv->dev->mode_config.max_height = 1200;
>>>>>>> + dev->mode_config.min_width = 0;
>>>>>>> + dev->mode_config.min_height = 0;
>>>>>>> + dev->mode_config.max_width = 1920;
>>>>>>> + dev->mode_config.max_height = 1200;
>>>>>>> - priv->dev->mode_config.fb_base = priv->fb_base;
>>>>>>> - priv->dev->mode_config.preferred_depth = 32;
>>>>>>> - priv->dev->mode_config.prefer_shadow = 1;
>>>>>>> + dev->mode_config.fb_base = priv->fb_base;
>>>>>>> + dev->mode_config.preferred_depth = 32;
>>>>>>> + dev->mode_config.prefer_shadow = 1;
>>>>>>> - priv->dev->mode_config.funcs = (void *)&hibmc_mode_funcs;
>>>>>>> + dev->mode_config.funcs = (void *)&hibmc_mode_funcs;
>>>>>>> ret = hibmc_de_init(priv);
>>>>>>> if (ret) {
>>>>>>> - drm_err(priv->dev, "failed to init de: %d\n", ret);
>>>>>>> + drm_err(dev, "failed to init de: %d\n", ret);
>>>>>>> return ret;
>>>>>>> }
>>>>>>> ret = hibmc_vdac_init(priv);
>>>>>>> if (ret) {
>>>>>>> - drm_err(priv->dev, "failed to init vdac: %d\n", ret);
>>>>>>> + drm_err(dev, "failed to init vdac: %d\n", ret);
>>>>>>> return ret;
>>>>>>> }
>>>>>>> @@ -113,7 +114,7 @@ static int hibmc_kms_init(struct
>>>>>>> hibmc_drm_private *priv)
>>>>>>> static void hibmc_kms_fini(struct hibmc_drm_private *priv)
>>>>>>> {
>>>>>>> if (priv->mode_config_initialized) {
>>>>>>> - drm_mode_config_cleanup(priv->dev);
>>>>>>> + drm_mode_config_cleanup(&priv->dev);
>>>>>>> priv->mode_config_initialized = false;
>>>>>>> }
>>>>>>> }
>>>>>>> @@ -202,7 +203,7 @@ static void hibmc_hw_config(struct
>>>>>>> hibmc_drm_private *priv)
>>>>>>> static int hibmc_hw_map(struct hibmc_drm_private *priv)
>>>>>>> {
>>>>>>> - struct drm_device *dev = priv->dev;
>>>>>>> + struct drm_device *dev = &priv->dev;
>>>>>>> struct pci_dev *pdev = dev->pdev;
>>>>>>> resource_size_t addr, size, ioaddr, iosize;
>>>>>>> @@ -258,7 +259,7 @@ static int hibmc_unload(struct drm_device *dev)
>>>>>>> static int hibmc_load(struct drm_device *dev)
>>>>>>> {
>>>>>>> - struct hibmc_drm_private *priv;
>>>>>>> + struct hibmc_drm_private *priv = to_hibmc_drm_private(dev);
>>>>>>> int ret;
>>>>>>> priv = drmm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
>>>>>>> @@ -267,7 +268,6 @@ static int hibmc_load(struct drm_device *dev)
>>>>>>> return -ENOMEM;
>>>>>>> }
>>>>>>> dev->dev_private = priv;
>>>>>>> - priv->dev = dev;
>>>>>>
>>>>>> I'm sure this either does not build or does not work. There's a
>>>>>> call to drm_dev_alloc(), which initialized the DRM device. You
>>>>>> need to assign the returned device here. The embedding of dev only
>>>>>> work after you switched to devm_drm_dev_alloc() in the next patch.
>>>>>>
>>>>>> For the patch at hand, just keep struct hibmc_drm_private.dev as a
>>>>>> pointer and you should be fine.
>>>>>>
>>>>> Changing drm_device *dev to drm_device dev and using
>>>>> devm_drm_dev_alloc does not easily split into two patches.
>>>>> The patch does not compile well on its own, but it will compile
>>>>> fine with patch #2.
>>>>> Can patch #1 and patch #2 be combined into a single patch,just like
>>>>> V1.
>>>>
>>>> Most of the code in this patch does
>>>>
>>>> struct drm_device *dev = &priv->dev;
>>>>
>>>> to get dev as a local variable. Why don't you do
>>>>
>>>> struct drm_device *dev = priv->dev;
>>>>
>>>> ?
>>>>
>>>> That's all that's really needed.
>>>
>>> + priv = devm_drm_dev_alloc(&pdev->dev, &hibmc_driver,
>>> + struct hibmc_drm_private, dev);
>>> devm_drm_dev_alloc function requires parameter 4, dev must be a
>>> non-pointer for it to work. so had to change dev in the
>>> hibmc_drm_private to non-pointer.
>>> This is also the reason to change drm_device *dev to drm_device dev.
>>
>> Yes, but that's what patch 2 is about. Patch 1 is about simplifying
>> these pointer dereferences into local variables. For this, all you
>> need is
>>
>> struct drm_device *dev = priv->dev;
> I'm sorry, I still don't understand what you mean.The latest code on the
> drm branch looks like this "struct drm_device *dev = priv->dev;"
> If I change the dev of hibmc_drm_private to local variables, I won't be
> able to assign it like this "struct drm_device *dev = priv->dev;", right?
>>
>> In patch 2, these lines are then changed to
>>
>> struct drm_device *dev = &priv->dev;
>>
>> That makes 2 self-contained patches.
patch #1
first changed drm_device *dev to drm_device dev
then
drm = &priv->dev;
err = drm_dev_init(drm, &hibmc_drm_private , &pdev->dev);
patch #2
using devm_drm_dev_alloc()
Is this right ?
>>
>> Best regards
>> Thomas
>>
>>>>
>>>> Best regards
>>>> Thomas
>>>>
>>>>>> Best regards
>>>>>> Thomas
>>>>>>
>>>>>>> ret = hibmc_hw_init(priv);
>>>>>>> if (ret)
>>>>>>> diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
>>>>>>> b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
>>>>>>> index f310a83..e35353a 100644
>>>>>>> --- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
>>>>>>> +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
>>>>>>> @@ -37,7 +37,7 @@ struct hibmc_drm_private {
>>>>>>> resource_size_t fb_size;
>>>>>>> /* drm */
>>>>>>> - struct drm_device *dev;
>>>>>>> + struct drm_device dev;
>>>>>>> struct drm_plane primary_plane;
>>>>>>> struct drm_crtc crtc;
>>>>>>> struct drm_encoder encoder;
>>>>>>> diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c
>>>>>>> b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c
>>>>>>> index 74e26c2..d35548d 100644
>>>>>>> --- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c
>>>>>>> +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c
>>>>>>> @@ -96,7 +96,7 @@ static const struct drm_encoder_funcs
>>>>>>> hibmc_encoder_funcs = {
>>>>>>> int hibmc_vdac_init(struct hibmc_drm_private *priv)
>>>>>>> {
>>>>>>> - struct drm_device *dev = priv->dev;
>>>>>>> + struct drm_device *dev = &priv->dev;
>>>>>>> struct hibmc_connector *hibmc_connector = &priv->connector;
>>>>>>> struct drm_encoder *encoder = &priv->encoder;
>>>>>>> struct drm_connector *connector = &hibmc_connector->base;
>>>>>>> diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c
>>>>>>> b/drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c
>>>>>>> index 602ece1..e84fb81 100644
>>>>>>> --- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c
>>>>>>> +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c
>>>>>>> @@ -25,7 +25,7 @@ int hibmc_mm_init(struct hibmc_drm_private *hibmc)
>>>>>>> {
>>>>>>> struct drm_vram_mm *vmm;
>>>>>>> int ret;
>>>>>>> - struct drm_device *dev = hibmc->dev;
>>>>>>> + struct drm_device *dev = &hibmc->dev;
>>>>>>> vmm = drm_vram_helper_alloc_mm(dev,
>>>>>>> pci_resource_start(dev->pdev, 0),
>>>>>>> @@ -41,10 +41,12 @@ int hibmc_mm_init(struct hibmc_drm_private
>>>>>>> *hibmc)
>>>>>>> void hibmc_mm_fini(struct hibmc_drm_private *hibmc)
>>>>>>> {
>>>>>>> - if (!hibmc->dev->vram_mm)
>>>>>>> + struct drm_device *dev = &hibmc->dev;
>>>>>>> +
>>>>>>> + if (!dev->vram_mm)
>>>>>>> return;
>>>>>>> - drm_vram_helper_release_mm(hibmc->dev);
>>>>>>> + drm_vram_helper_release_mm(dev);
>>>>>>> }
>>>>>>> int hibmc_dumb_create(struct drm_file *file, struct drm_device
>>>>>>> *dev,
>>>>>>>
>>>>>>
>>>>>
>>>>
>>>
>>
>
>
> .
>
Hi
Am 02.12.20 um 03:54 schrieb tiantao (H):
>
>
> 在 2020/12/2 10:06, tiantao (H) 写道:
>>
>>
>> 在 2020/12/1 21:44, Thomas Zimmermann 写道:
>>> Hi
>>>
>>> Am 01.12.20 um 14:05 schrieb tiantao (H):
>>>>
>>>>
>>>> 在 2020/12/1 20:36, Thomas Zimmermann 写道:
>>>>> Hi
>>>>>
>>>>> Am 01.12.20 um 13:26 schrieb tiantao (H):
>>>>>>
>>>>>>
>>>>>> 在 2020/12/1 20:17, Thomas Zimmermann 写道:
>>>>>>> Hi
>>>>>>>
>>>>>>> Am 01.12.20 um 12:55 schrieb Tian Tao:
>>>>>>>> Assign local variable to struct drm_device *dev because they are
>>>>>>>> used multiple times within a function.
>>>>>>>>
>>>>>>>> Signed-off-by: Tian Tao <[email protected]>
>>>>>>>> ---
>>>>>>>> drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c | 2 +-
>>>>>>>> drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c | 30
>>>>>>>> ++++++++++++------------
>>>>>>>> drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h | 2 +-
>>>>>>>> drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c | 2 +-
>>>>>>>> drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c | 8 ++++---
>>>>>>>> 5 files changed, 23 insertions(+), 21 deletions(-)
>>>>>>>>
>>>>>>>> diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c
>>>>>>>> b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c
>>>>>>>> index ea962ac..096eea9 100644
>>>>>>>> --- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c
>>>>>>>> +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c
>>>>>>>> @@ -499,7 +499,7 @@ static const struct drm_crtc_helper_funcs
>>>>>>>> hibmc_crtc_helper_funcs = {
>>>>>>>> int hibmc_de_init(struct hibmc_drm_private *priv)
>>>>>>>> {
>>>>>>>> - struct drm_device *dev = priv->dev;
>>>>>>>> + struct drm_device *dev = &priv->dev;
>>>>>>>> struct drm_crtc *crtc = &priv->crtc;
>>>>>>>> struct drm_plane *plane = &priv->primary_plane;
>>>>>>>> int ret;
>>>>>>>> diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
>>>>>>>> b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
>>>>>>>> index d845657..dd9fadc 100644
>>>>>>>> --- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
>>>>>>>> +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
>>>>>>>> @@ -79,31 +79,32 @@ static const struct dev_pm_ops hibmc_pm_ops = {
>>>>>>>> static int hibmc_kms_init(struct hibmc_drm_private *priv)
>>>>>>>> {
>>>>>>>> + struct drm_device *dev = &priv->dev;
>>>>>>>> int ret;
>>>>>>>> - drm_mode_config_init(priv->dev);
>>>>>>>> + drm_mode_config_init(dev);
>>>>>>>> priv->mode_config_initialized = true;
>>>>>>>> - priv->dev->mode_config.min_width = 0;
>>>>>>>> - priv->dev->mode_config.min_height = 0;
>>>>>>>> - priv->dev->mode_config.max_width = 1920;
>>>>>>>> - priv->dev->mode_config.max_height = 1200;
>>>>>>>> + dev->mode_config.min_width = 0;
>>>>>>>> + dev->mode_config.min_height = 0;
>>>>>>>> + dev->mode_config.max_width = 1920;
>>>>>>>> + dev->mode_config.max_height = 1200;
>>>>>>>> - priv->dev->mode_config.fb_base = priv->fb_base;
>>>>>>>> - priv->dev->mode_config.preferred_depth = 32;
>>>>>>>> - priv->dev->mode_config.prefer_shadow = 1;
>>>>>>>> + dev->mode_config.fb_base = priv->fb_base;
>>>>>>>> + dev->mode_config.preferred_depth = 32;
>>>>>>>> + dev->mode_config.prefer_shadow = 1;
>>>>>>>> - priv->dev->mode_config.funcs = (void *)&hibmc_mode_funcs;
>>>>>>>> + dev->mode_config.funcs = (void *)&hibmc_mode_funcs;
>>>>>>>> ret = hibmc_de_init(priv);
>>>>>>>> if (ret) {
>>>>>>>> - drm_err(priv->dev, "failed to init de: %d\n", ret);
>>>>>>>> + drm_err(dev, "failed to init de: %d\n", ret);
>>>>>>>> return ret;
>>>>>>>> }
>>>>>>>> ret = hibmc_vdac_init(priv);
>>>>>>>> if (ret) {
>>>>>>>> - drm_err(priv->dev, "failed to init vdac: %d\n", ret);
>>>>>>>> + drm_err(dev, "failed to init vdac: %d\n", ret);
>>>>>>>> return ret;
>>>>>>>> }
>>>>>>>> @@ -113,7 +114,7 @@ static int hibmc_kms_init(struct
>>>>>>>> hibmc_drm_private *priv)
>>>>>>>> static void hibmc_kms_fini(struct hibmc_drm_private *priv)
>>>>>>>> {
>>>>>>>> if (priv->mode_config_initialized) {
>>>>>>>> - drm_mode_config_cleanup(priv->dev);
>>>>>>>> + drm_mode_config_cleanup(&priv->dev);
>>>>>>>> priv->mode_config_initialized = false;
>>>>>>>> }
>>>>>>>> }
>>>>>>>> @@ -202,7 +203,7 @@ static void hibmc_hw_config(struct
>>>>>>>> hibmc_drm_private *priv)
>>>>>>>> static int hibmc_hw_map(struct hibmc_drm_private *priv)
>>>>>>>> {
>>>>>>>> - struct drm_device *dev = priv->dev;
>>>>>>>> + struct drm_device *dev = &priv->dev;
>>>>>>>> struct pci_dev *pdev = dev->pdev;
>>>>>>>> resource_size_t addr, size, ioaddr, iosize;
>>>>>>>> @@ -258,7 +259,7 @@ static int hibmc_unload(struct drm_device *dev)
>>>>>>>> static int hibmc_load(struct drm_device *dev)
>>>>>>>> {
>>>>>>>> - struct hibmc_drm_private *priv;
>>>>>>>> + struct hibmc_drm_private *priv = to_hibmc_drm_private(dev);
>>>>>>>> int ret;
>>>>>>>> priv = drmm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
>>>>>>>> @@ -267,7 +268,6 @@ static int hibmc_load(struct drm_device *dev)
>>>>>>>> return -ENOMEM;
>>>>>>>> }
>>>>>>>> dev->dev_private = priv;
>>>>>>>> - priv->dev = dev;
>>>>>>>
>>>>>>> I'm sure this either does not build or does not work. There's a
>>>>>>> call to drm_dev_alloc(), which initialized the DRM device. You
>>>>>>> need to assign the returned device here. The embedding of dev
>>>>>>> only work after you switched to devm_drm_dev_alloc() in the next
>>>>>>> patch.
>>>>>>>
>>>>>>> For the patch at hand, just keep struct hibmc_drm_private.dev as
>>>>>>> a pointer and you should be fine.
>>>>>>>
>>>>>> Changing drm_device *dev to drm_device dev and using
>>>>>> devm_drm_dev_alloc does not easily split into two patches.
>>>>>> The patch does not compile well on its own, but it will compile
>>>>>> fine with patch #2.
>>>>>> Can patch #1 and patch #2 be combined into a single patch,just
>>>>>> like V1.
>>>>>
>>>>> Most of the code in this patch does
>>>>>
>>>>> struct drm_device *dev = &priv->dev;
>>>>>
>>>>> to get dev as a local variable. Why don't you do
>>>>>
>>>>> struct drm_device *dev = priv->dev;
>>>>>
>>>>> ?
>>>>>
>>>>> That's all that's really needed.
>>>>
>>>> + priv = devm_drm_dev_alloc(&pdev->dev, &hibmc_driver,
>>>> + struct hibmc_drm_private, dev);
>>>> devm_drm_dev_alloc function requires parameter 4, dev must be a
>>>> non-pointer for it to work. so had to change dev in the
>>>> hibmc_drm_private to non-pointer.
>>>> This is also the reason to change drm_device *dev to drm_device dev.
>>>
>>> Yes, but that's what patch 2 is about. Patch 1 is about simplifying
>>> these pointer dereferences into local variables. For this, all you
>>> need is
>>>
>>> struct drm_device *dev = priv->dev;
>> I'm sorry, I still don't understand what you mean.The latest code on
>> the drm branch looks like this "struct drm_device *dev = priv->dev;"
>> If I change the dev of hibmc_drm_private to local variables, I won't
>> be able to assign it like this "struct drm_device *dev = priv->dev;",
>> right?
>>>
>>> In patch 2, these lines are then changed to
>>>
>>> struct drm_device *dev = &priv->dev;
>>>
>>> That makes 2 self-contained patches.
> patch #1
> first changed drm_device *dev to drm_device dev
> then
> drm = &priv->dev;
> err = drm_dev_init(drm, &hibmc_drm_private , &pdev->dev);
> patch #2
>
> using devm_drm_dev_alloc()
>
> Is this right ?
Oh, I guess I now see why we're misunderstanding each other. By local
variable, I mean that dev is a local pointer in a function. I didn't
mean that the actual instance of dev is stored in struct
hibmc_drm_private. In patch 1 it's still supposed to be a pointer in
struct hibmc_drm_private. Only patch 2 will make dev an instance.
Anyway, before this goes on forever, maybe just merge patches 1 and 2
and resubmit.
Best regards
Thomas
>
>>>
>>> Best regards
>>> Thomas
>>>
>>>>>
>>>>> Best regards
>>>>> Thomas
>>>>>
>>>>>>> Best regards
>>>>>>> Thomas
>>>>>>>
>>>>>>>> ret = hibmc_hw_init(priv);
>>>>>>>> if (ret)
>>>>>>>> diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
>>>>>>>> b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
>>>>>>>> index f310a83..e35353a 100644
>>>>>>>> --- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
>>>>>>>> +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
>>>>>>>> @@ -37,7 +37,7 @@ struct hibmc_drm_private {
>>>>>>>> resource_size_t fb_size;
>>>>>>>> /* drm */
>>>>>>>> - struct drm_device *dev;
>>>>>>>> + struct drm_device dev;
>>>>>>>> struct drm_plane primary_plane;
>>>>>>>> struct drm_crtc crtc;
>>>>>>>> struct drm_encoder encoder;
>>>>>>>> diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c
>>>>>>>> b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c
>>>>>>>> index 74e26c2..d35548d 100644
>>>>>>>> --- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c
>>>>>>>> +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c
>>>>>>>> @@ -96,7 +96,7 @@ static const struct drm_encoder_funcs
>>>>>>>> hibmc_encoder_funcs = {
>>>>>>>> int hibmc_vdac_init(struct hibmc_drm_private *priv)
>>>>>>>> {
>>>>>>>> - struct drm_device *dev = priv->dev;
>>>>>>>> + struct drm_device *dev = &priv->dev;
>>>>>>>> struct hibmc_connector *hibmc_connector = &priv->connector;
>>>>>>>> struct drm_encoder *encoder = &priv->encoder;
>>>>>>>> struct drm_connector *connector = &hibmc_connector->base;
>>>>>>>> diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c
>>>>>>>> b/drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c
>>>>>>>> index 602ece1..e84fb81 100644
>>>>>>>> --- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c
>>>>>>>> +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c
>>>>>>>> @@ -25,7 +25,7 @@ int hibmc_mm_init(struct hibmc_drm_private
>>>>>>>> *hibmc)
>>>>>>>> {
>>>>>>>> struct drm_vram_mm *vmm;
>>>>>>>> int ret;
>>>>>>>> - struct drm_device *dev = hibmc->dev;
>>>>>>>> + struct drm_device *dev = &hibmc->dev;
>>>>>>>> vmm = drm_vram_helper_alloc_mm(dev,
>>>>>>>> pci_resource_start(dev->pdev, 0),
>>>>>>>> @@ -41,10 +41,12 @@ int hibmc_mm_init(struct hibmc_drm_private
>>>>>>>> *hibmc)
>>>>>>>> void hibmc_mm_fini(struct hibmc_drm_private *hibmc)
>>>>>>>> {
>>>>>>>> - if (!hibmc->dev->vram_mm)
>>>>>>>> + struct drm_device *dev = &hibmc->dev;
>>>>>>>> +
>>>>>>>> + if (!dev->vram_mm)
>>>>>>>> return;
>>>>>>>> - drm_vram_helper_release_mm(hibmc->dev);
>>>>>>>> + drm_vram_helper_release_mm(dev);
>>>>>>>> }
>>>>>>>> int hibmc_dumb_create(struct drm_file *file, struct drm_device
>>>>>>>> *dev,
>>>>>>>>
>>>>>>>
>>>>>>
>>>>>
>>>>
>>>
>>
>>
>> .
>>
>
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Felix Imendörffer