Re: [PATCH v3 03/37] drm/nouveau: replace drm_device* with nouveau_drm* as dev drvdata

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]<

 



On Fri, 26 Jul 2024 14:37:54 +1000
Ben Skeggs <bskeggs@xxxxxxxxxx> wrote:

> We almost always want to cast the pointer from dev_get_drvdata() to
> 'struct nouveau_drm *', so just directly store that pointer instead,
> simplifying callers, and fixing some clumsy naming of dev/drm_dev
> variables at the same time.
> 
> Signed-off-by: Ben Skeggs <bskeggs@xxxxxxxxxx>
> ---
>  drivers/gpu/drm/nouveau/dispnv50/disp.c    | 17 ++---
>  drivers/gpu/drm/nouveau/nouveau_display.c  |  4 +-
>  drivers/gpu/drm/nouveau/nouveau_display.h  |  2 +-
>  drivers/gpu/drm/nouveau/nouveau_drm.c      | 78
> ++++++++++------------ drivers/gpu/drm/nouveau/nouveau_drv.h      |
> 2 +- drivers/gpu/drm/nouveau/nouveau_platform.c |  5 +-
>  drivers/gpu/drm/nouveau/nouveau_vga.c      | 14 ++--
>  7 files changed, 58 insertions(+), 64 deletions(-)
> 
> diff --git a/drivers/gpu/drm/nouveau/dispnv50/disp.c
> b/drivers/gpu/drm/nouveau/dispnv50/disp.c index
> 6d20d3c68fa7..58c986528ff6 100644 ---
> a/drivers/gpu/drm/nouveau/dispnv50/disp.c +++
> b/drivers/gpu/drm/nouveau/dispnv50/disp.c @@ -593,8 +593,7 @@ static
> int nv50_audio_component_get_eld(struct device *kdev, int port, int
> dev_id, bool *enabled, unsigned char *buf, int max_bytes)
>  {
> -	struct drm_device *drm_dev = dev_get_drvdata(kdev);
> -	struct nouveau_drm *drm = nouveau_drm(drm_dev);
> +	struct nouveau_drm *drm = dev_get_drvdata(kdev);
>  	struct drm_encoder *encoder;
>  	struct nouveau_encoder *nv_encoder;
>  	struct nouveau_crtc *nv_crtc;
> @@ -639,18 +638,17 @@ static int
>  nv50_audio_component_bind(struct device *kdev, struct device
> *hda_kdev, void *data)
>  {
> -	struct drm_device *drm_dev = dev_get_drvdata(kdev);
> -	struct nouveau_drm *drm = nouveau_drm(drm_dev);
> +	struct nouveau_drm *drm = dev_get_drvdata(kdev);
>  	struct drm_audio_component *acomp = data;
>  
>  	if (WARN_ON(!device_link_add(hda_kdev, kdev,
> DL_FLAG_STATELESS))) return -ENOMEM;
>  
> -	drm_modeset_lock_all(drm_dev);
> +	drm_modeset_lock_all(drm->dev);
>  	acomp->ops = &nv50_audio_component_ops;
>  	acomp->dev = kdev;
>  	drm->audio.component = acomp;
> -	drm_modeset_unlock_all(drm_dev);
> +	drm_modeset_unlock_all(drm->dev);
>  	return 0;
>  }
>  
> @@ -658,15 +656,14 @@ static void
>  nv50_audio_component_unbind(struct device *kdev, struct device
> *hda_kdev, void *data)
>  {
> -	struct drm_device *drm_dev = dev_get_drvdata(kdev);
> -	struct nouveau_drm *drm = nouveau_drm(drm_dev);
> +	struct nouveau_drm *drm = dev_get_drvdata(kdev);
>  	struct drm_audio_component *acomp = data;
>  
> -	drm_modeset_lock_all(drm_dev);
> +	drm_modeset_lock_all(drm->dev);
>  	drm->audio.component = NULL;
>  	acomp->ops = NULL;
>  	acomp->dev = NULL;
> -	drm_modeset_unlock_all(drm_dev);
> +	drm_modeset_unlock_all(drm->dev);
>  }
>  
>  static const struct component_ops nv50_audio_component_bind_ops = {
> diff --git a/drivers/gpu/drm/nouveau/nouveau_display.c
> b/drivers/gpu/drm/nouveau/nouveau_display.c index
> aed5d5b51b43..fa30c97bcf90 100644 ---
> a/drivers/gpu/drm/nouveau/nouveau_display.c +++
> b/drivers/gpu/drm/nouveau/nouveau_display.c @@ -446,10 +446,8 @@
> static struct nouveau_drm_prop_enum_list dither_depth[] = { } while(0)
>  
>  void
> -nouveau_display_hpd_resume(struct drm_device *dev)
> +nouveau_display_hpd_resume(struct nouveau_drm *drm)
>  {
> -	struct nouveau_drm *drm = nouveau_drm(dev);
> -
>  	spin_lock_irq(&drm->hpd_lock);
>  	drm->hpd_pending = ~0;
>  	spin_unlock_irq(&drm->hpd_lock);
> diff --git a/drivers/gpu/drm/nouveau/nouveau_display.h
> b/drivers/gpu/drm/nouveau/nouveau_display.h index
> 2ab2ddb1eadf..1f506f8b289c 100644 ---
> a/drivers/gpu/drm/nouveau/nouveau_display.h +++
> b/drivers/gpu/drm/nouveau/nouveau_display.h @@ -45,7 +45,7 @@
> nouveau_display(struct drm_device *dev) int
> nouveau_display_create(struct drm_device *dev); void
> nouveau_display_destroy(struct drm_device *dev); int
> nouveau_display_init(struct drm_device *dev, bool resume, bool
> runtime); -void nouveau_display_hpd_resume(struct drm_device *dev);
> +void nouveau_display_hpd_resume(struct nouveau_drm *); void
> nouveau_display_fini(struct drm_device *dev, bool suspend, bool
> runtime); int  nouveau_display_suspend(struct drm_device *dev, bool
> runtime); void nouveau_display_resume(struct drm_device *dev, bool
> runtime); diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.c
> b/drivers/gpu/drm/nouveau/nouveau_drm.c index
> 9beff8737617..0687bc59d486 100644 ---
> a/drivers/gpu/drm/nouveau/nouveau_drm.c +++
> b/drivers/gpu/drm/nouveau/nouveau_drm.c @@ -579,10 +579,10 @@
> nouveau_parent = { }; 
>  static void
> -nouveau_drm_device_fini(struct drm_device *dev)
> +nouveau_drm_device_fini(struct nouveau_drm *drm)
>  {
> +	struct drm_device *dev = drm->dev;
>  	struct nouveau_cli *cli, *temp_cli;
> -	struct nouveau_drm *drm = nouveau_drm(dev);
>  
>  	if (nouveau_pmops_runtime()) {
>  		pm_runtime_get_sync(dev->dev);
> @@ -707,7 +707,7 @@ nouveau_drm_device_init(struct nouveau_drm *drm)
>  
>  	ret = drm_dev_register(drm->dev, 0);
>  	if (ret) {
> -		nouveau_drm_device_fini(drm->dev);
> +		nouveau_drm_device_fini(drm);
>  		return ret;
>  	}
>  
> @@ -758,7 +758,7 @@ nouveau_drm_device_new(const struct drm_driver
> *drm_driver, struct device *paren }
>  
>  	drm->dev->dev_private = drm;
> -	dev_set_drvdata(parent, drm->dev);
> +	dev_set_drvdata(parent, drm);
>  
>  done:
>  	if (ret) {
> @@ -811,8 +811,7 @@ nouveau_drm_device_new(const struct drm_driver
> *drm_driver, struct device *paren 
>  static void quirk_broken_nv_runpm(struct pci_dev *pdev)
>  {
> -	struct drm_device *dev = pci_get_drvdata(pdev);
> -	struct nouveau_drm *drm = nouveau_drm(dev);
> +	struct nouveau_drm *drm = pci_get_drvdata(pdev);
>  	struct pci_dev *bridge = pci_upstream_bridge(pdev);
>  
>  	if (!bridge || bridge->vendor != PCI_VENDOR_ID_INTEL)
> @@ -894,18 +893,17 @@ static int nouveau_drm_probe(struct pci_dev
> *pdev, }
>  
>  void
> -nouveau_drm_device_remove(struct drm_device *dev)
> +nouveau_drm_device_remove(struct nouveau_drm *drm)
>  {
> -	struct nouveau_drm *drm = nouveau_drm(dev);
>  	struct nvkm_client *client;
>  	struct nvkm_device *device;
>  
> -	drm_dev_unplug(dev);
> +	drm_dev_unplug(drm->dev);
>  
>  	client = nvxx_client(&drm->client.base);
>  	device = nvkm_device_find(client->device);
>  
> -	nouveau_drm_device_fini(dev);
> +	nouveau_drm_device_fini(drm);
>  	nouveau_drm_device_del(drm);
>  	nvkm_device_del(&device);
>  }
> @@ -913,20 +911,19 @@ nouveau_drm_device_remove(struct drm_device
> *dev) static void
>  nouveau_drm_remove(struct pci_dev *pdev)
>  {
> -	struct drm_device *dev = pci_get_drvdata(pdev);
> -	struct nouveau_drm *drm = nouveau_drm(dev);
> +	struct nouveau_drm *drm = pci_get_drvdata(pdev);
>  
>  	/* revert our workaround */
>  	if (drm->old_pm_cap)
>  		pdev->pm_cap = drm->old_pm_cap;
> -	nouveau_drm_device_remove(dev);
> +	nouveau_drm_device_remove(drm);
>  	pci_disable_device(pdev);
>  }
>  
>  static int
> -nouveau_do_suspend(struct drm_device *dev, bool runtime)
> +nouveau_do_suspend(struct nouveau_drm *drm, bool runtime)
>  {
> -	struct nouveau_drm *drm = nouveau_drm(dev);
> +	struct drm_device *dev = drm->dev;
>  	struct ttm_resource_manager *man;
>  	int ret;
>  
> @@ -987,10 +984,10 @@ nouveau_do_suspend(struct drm_device *dev, bool
> runtime) }
>  
>  static int
> -nouveau_do_resume(struct drm_device *dev, bool runtime)
> +nouveau_do_resume(struct nouveau_drm *drm, bool runtime)
>  {
> +	struct drm_device *dev = drm->dev;
>  	int ret = 0;
> -	struct nouveau_drm *drm = nouveau_drm(dev);
>  
>  	NV_DEBUG(drm, "resuming object tree...\n");
>  	ret = nvif_client_resume(&drm->master.base);
> @@ -1020,14 +1017,14 @@ int
>  nouveau_pmops_suspend(struct device *dev)
>  {
>  	struct pci_dev *pdev = to_pci_dev(dev);
> -	struct drm_device *drm_dev = pci_get_drvdata(pdev);
> +	struct nouveau_drm *drm = pci_get_drvdata(pdev);
>  	int ret;
>  
> -	if (drm_dev->switch_power_state == DRM_SWITCH_POWER_OFF ||
> -	    drm_dev->switch_power_state ==
> DRM_SWITCH_POWER_DYNAMIC_OFF)
> +	if (drm->dev->switch_power_state == DRM_SWITCH_POWER_OFF ||
> +	    drm->dev->switch_power_state ==
> DRM_SWITCH_POWER_DYNAMIC_OFF) return 0;
>  
> -	ret = nouveau_do_suspend(drm_dev, false);
> +	ret = nouveau_do_suspend(drm, false);
>  	if (ret)
>  		return ret;
>  
> @@ -1042,11 +1039,11 @@ int
>  nouveau_pmops_resume(struct device *dev)
>  {
>  	struct pci_dev *pdev = to_pci_dev(dev);
> -	struct drm_device *drm_dev = pci_get_drvdata(pdev);
> +	struct nouveau_drm *drm = pci_get_drvdata(pdev);
>  	int ret;
>  
> -	if (drm_dev->switch_power_state == DRM_SWITCH_POWER_OFF ||
> -	    drm_dev->switch_power_state ==
> DRM_SWITCH_POWER_DYNAMIC_OFF)
> +	if (drm->dev->switch_power_state == DRM_SWITCH_POWER_OFF ||
> +	    drm->dev->switch_power_state ==
> DRM_SWITCH_POWER_DYNAMIC_OFF) return 0;
>  
>  	pci_set_power_state(pdev, PCI_D0);
> @@ -1056,10 +1053,10 @@ nouveau_pmops_resume(struct device *dev)
>  		return ret;
>  	pci_set_master(pdev);
>  
> -	ret = nouveau_do_resume(drm_dev, false);
> +	ret = nouveau_do_resume(drm, false);
>  
>  	/* Monitors may have been connected / disconnected during
> suspend */
> -	nouveau_display_hpd_resume(drm_dev);
> +	nouveau_display_hpd_resume(drm);
>  
>  	return ret;
>  }
> @@ -1067,17 +1064,17 @@ nouveau_pmops_resume(struct device *dev)
>  static int
>  nouveau_pmops_freeze(struct device *dev)
>  {
> -	struct pci_dev *pdev = to_pci_dev(dev);
> -	struct drm_device *drm_dev = pci_get_drvdata(pdev);
> -	return nouveau_do_suspend(drm_dev, false);
> +	struct nouveau_drm *drm = dev_get_drvdata(dev);
> +
> +	return nouveau_do_suspend(drm, false);
>  }
>  
>  static int
>  nouveau_pmops_thaw(struct device *dev)
>  {
> -	struct pci_dev *pdev = to_pci_dev(dev);
> -	struct drm_device *drm_dev = pci_get_drvdata(pdev);
> -	return nouveau_do_resume(drm_dev, false);
> +	struct nouveau_drm *drm = dev_get_drvdata(dev);
> +
> +	return nouveau_do_resume(drm, false);
>  }
>  
>  bool
> @@ -1092,7 +1089,7 @@ static int
>  nouveau_pmops_runtime_suspend(struct device *dev)
>  {
>  	struct pci_dev *pdev = to_pci_dev(dev);
> -	struct drm_device *drm_dev = pci_get_drvdata(pdev);
> +	struct nouveau_drm *drm = pci_get_drvdata(pdev);
>  	int ret;
>  
>  	if (!nouveau_pmops_runtime()) {
> @@ -1101,12 +1098,12 @@ nouveau_pmops_runtime_suspend(struct device
> *dev) }
>  
>  	nouveau_switcheroo_optimus_dsm();
> -	ret = nouveau_do_suspend(drm_dev, true);
> +	ret = nouveau_do_suspend(drm, true);
>  	pci_save_state(pdev);
>  	pci_disable_device(pdev);
>  	pci_ignore_hotplug(pdev);
>  	pci_set_power_state(pdev, PCI_D3cold);
> -	drm_dev->switch_power_state = DRM_SWITCH_POWER_DYNAMIC_OFF;
> +	drm->dev->switch_power_state = DRM_SWITCH_POWER_DYNAMIC_OFF;
>  	return ret;
>  }
>  
> @@ -1114,9 +1111,8 @@ static int
>  nouveau_pmops_runtime_resume(struct device *dev)
>  {
>  	struct pci_dev *pdev = to_pci_dev(dev);
> -	struct drm_device *drm_dev = pci_get_drvdata(pdev);
> -	struct nouveau_drm *drm = nouveau_drm(drm_dev);
> -	struct nvif_device *device =
> &nouveau_drm(drm_dev)->client.device;
> +	struct nouveau_drm *drm = pci_get_drvdata(pdev);
> +	struct nvif_device *device = &drm->client.device;
>  	int ret;
>  
>  	if (!nouveau_pmops_runtime()) {
> @@ -1131,7 +1127,7 @@ nouveau_pmops_runtime_resume(struct device *dev)
>  		return ret;
>  	pci_set_master(pdev);
>  
> -	ret = nouveau_do_resume(drm_dev, true);
> +	ret = nouveau_do_resume(drm, true);
>  	if (ret) {
>  		NV_ERROR(drm, "resume failed with: %d\n", ret);
>  		return ret;
> @@ -1139,10 +1135,10 @@ nouveau_pmops_runtime_resume(struct device
> *dev) 
>  	/* do magic */
>  	nvif_mask(&device->object, 0x088488, (1 << 25), (1 << 25));
> -	drm_dev->switch_power_state = DRM_SWITCH_POWER_ON;
> +	drm->dev->switch_power_state = DRM_SWITCH_POWER_ON;
>  
>  	/* Monitors may have been connected / disconnected during
> suspend */
> -	nouveau_display_hpd_resume(drm_dev);
> +	nouveau_display_hpd_resume(drm);
>  
>  	return ret;
>  }
> diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.h
> b/drivers/gpu/drm/nouveau/nouveau_drv.h index
> e239c6bf4afa..7e624c587fc0 100644 ---
> a/drivers/gpu/drm/nouveau/nouveau_drv.h +++
> b/drivers/gpu/drm/nouveau/nouveau_drv.h @@ -325,7 +325,7 @@ bool
> nouveau_pmops_runtime(void); struct drm_device *
>  nouveau_platform_device_create(const struct nvkm_device_tegra_func *,
>  			       struct platform_device *, struct
> nvkm_device **); -void nouveau_drm_device_remove(struct drm_device
> *dev); +void nouveau_drm_device_remove(struct nouveau_drm *);
>  
>  #define NV_PRINTK(l,c,f,a...) do {
>           \ struct nouveau_cli *_cli = (c);
>              \ diff --git
> a/drivers/gpu/drm/nouveau/nouveau_platform.c
> b/drivers/gpu/drm/nouveau/nouveau_platform.c index
> d0a63f0f54a2..3194b110eff8 100644 ---
> a/drivers/gpu/drm/nouveau/nouveau_platform.c +++
> b/drivers/gpu/drm/nouveau/nouveau_platform.c @@ -39,8 +39,9 @@ static
> int nouveau_platform_probe(struct platform_device *pdev) static void
> nouveau_platform_remove(struct platform_device *pdev) {
> -	struct drm_device *dev = platform_get_drvdata(pdev);
> -	nouveau_drm_device_remove(dev);
> +	struct nouveau_drm *drm = platform_get_drvdata(pdev);
> +
> +	nouveau_drm_device_remove(drm);
>  }
>  
>  #if IS_ENABLED(CONFIG_OF)
> diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c
> b/drivers/gpu/drm/nouveau/nouveau_vga.c index
> f8bf0ec26844..2525e08938b3 100644 ---
> a/drivers/gpu/drm/nouveau/nouveau_vga.c +++
> b/drivers/gpu/drm/nouveau/nouveau_vga.c @@ -11,7 +11,7 @@
>  static unsigned int
>  nouveau_vga_set_decode(struct pci_dev *pdev, bool state)
>  {
> -	struct nouveau_drm *drm = nouveau_drm(pci_get_drvdata(pdev));
> +	struct nouveau_drm *drm = pci_get_drvdata(pdev);
>  	struct nvif_object *device = &drm->client.device.object;
>  
>  	if (drm->client.device.info.family ==
> NV_DEVICE_INFO_V0_CURIE && @@ -34,7 +34,8 @@ static void
>  nouveau_switcheroo_set_state(struct pci_dev *pdev,
>  			     enum vga_switcheroo_state state)
>  {
> -	struct drm_device *dev = pci_get_drvdata(pdev);
> +	struct nouveau_drm *drm = pci_get_drvdata(pdev);
> +	struct drm_device *dev = drm->dev;
>  
>  	if ((nouveau_is_optimus() || nouveau_is_v1_dsm()) && state
> == VGA_SWITCHEROO_OFF) return;
> @@ -56,21 +57,22 @@ nouveau_switcheroo_set_state(struct pci_dev *pdev,
>  static void
>  nouveau_switcheroo_reprobe(struct pci_dev *pdev)
>  {
> -	struct drm_device *dev = pci_get_drvdata(pdev);
> -	drm_fb_helper_output_poll_changed(dev);
> +	struct nouveau_drm *drm = pci_get_drvdata(pdev);
> +
> +	drm_fb_helper_output_poll_changed(drm->dev);
>  }
>  
>  static bool
>  nouveau_switcheroo_can_switch(struct pci_dev *pdev)
>  {
> -	struct drm_device *dev = pci_get_drvdata(pdev);
> +	struct nouveau_drm *drm = pci_get_drvdata(pdev);
>  
>  	/*
>  	 * FIXME: open_count is protected by drm_global_mutex but
> that would lead to
>  	 * locking inversion with the driver load path. And the
> access here is
>  	 * completely racy anyway. So don't bother with locking for
> now. */
> -	return atomic_read(&dev->open_count) == 0;
> +	return atomic_read(&drm->dev->open_count) == 0;
>  }
>  
>  static const struct vga_switcheroo_client_ops

Reviewed-by: Zhi Wang <zhiw@xxxxxxxxxx>



[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux