From: Zhi Wang <zhiw@nvidia.com>
To: Ben Skeggs <bskeggs@nvidia.com>
Cc: <nouveau@lists.freedesktop.org>
Subject: Re: [PATCH v3 02/37] drm/nouveau: handle pci/tegra drm_dev_{alloc, register} from common code
Date: Wed, 31 Jul 2024 13:08:45 +0300 [thread overview]
Message-ID: <20240731130845.0000723b.zhiw@nvidia.com> (raw)
In-Reply-To: <20240726043828.58966-3-bskeggs@nvidia.com>
On Fri, 26 Jul 2024 14:37:53 +1000
Ben Skeggs <bskeggs@nvidia.com> wrote:
> Unify some more of the PCI/Tegra DRM driver init, both as a general
> cleanup, and because a subsequent commit changes the pointer stored
> via dev_set_drvdata(), and this allows the change to be made in one
> place.
>
> Signed-off-by: Ben Skeggs <bskeggs@nvidia.com>
> ---
> drivers/gpu/drm/nouveau/nouveau_drm.c | 93
> ++++++++++++++-------- drivers/gpu/drm/nouveau/nouveau_platform.c |
> 6 -- 2 files changed, 60 insertions(+), 39 deletions(-)
>
> diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.c
> b/drivers/gpu/drm/nouveau/nouveau_drm.c index
> eae48c87e3d5..9beff8737617 100644 ---
> a/drivers/gpu/drm/nouveau/nouveau_drm.c +++
> b/drivers/gpu/drm/nouveau/nouveau_drm.c @@ -628,20 +628,14 @@
> nouveau_drm_device_fini(struct drm_device *dev)
> destroy_workqueue(drm->sched_wq); nvif_parent_dtor(&drm->parent);
> mutex_destroy(&drm->clients_lock);
> - kfree(drm);
> }
>
> static int
> -nouveau_drm_device_init(struct drm_device *dev)
> +nouveau_drm_device_init(struct nouveau_drm *drm)
> {
> - struct nouveau_drm *drm;
> + struct drm_device *dev = drm->dev;
> int ret;
>
> - if (!(drm = kzalloc(sizeof(*drm), GFP_KERNEL)))
> - return -ENOMEM;
> - dev->dev_private = drm;
> - drm->dev = dev;
> -
> nvif_parent_ctor(&nouveau_parent, &drm->parent);
> drm->master.base.object.parent = &drm->parent;
>
> @@ -711,6 +705,12 @@ nouveau_drm_device_init(struct drm_device *dev)
> pm_runtime_put(dev->dev);
> }
>
> + ret = drm_dev_register(drm->dev, 0);
> + if (ret) {
> + nouveau_drm_device_fini(drm->dev);
> + return ret;
> + }
> +
> return 0;
> fail_dispinit:
> nouveau_display_destroy(dev);
> @@ -728,10 +728,47 @@ nouveau_drm_device_init(struct drm_device *dev)
> destroy_workqueue(drm->sched_wq);
> fail_alloc:
> nvif_parent_dtor(&drm->parent);
> - kfree(drm);
> return ret;
> }
>
> +static void
> +nouveau_drm_device_del(struct nouveau_drm *drm)
> +{
> + if (drm->dev)
> + drm_dev_put(drm->dev);
> +
> + kfree(drm);
> +}
> +
> +static struct nouveau_drm *
> +nouveau_drm_device_new(const struct drm_driver *drm_driver, struct
> device *parent,
> + struct nvkm_device *device)
> +{
> + struct nouveau_drm *drm;
> + int ret;
> +
> + drm = kzalloc(sizeof(*drm), GFP_KERNEL);
> + if (!drm)
> + return ERR_PTR(-ENOMEM);
> +
> + drm->dev = drm_dev_alloc(drm_driver, parent);
> + if (IS_ERR(drm->dev)) {
> + ret = PTR_ERR(drm->dev);
> + goto done;
> + }
> +
> + drm->dev->dev_private = drm;
> + dev_set_drvdata(parent, drm->dev);
> +
> +done:
> + if (ret) {
> + nouveau_drm_device_del(drm);
> + drm = NULL;
> + }
> +
> + return ret ? ERR_PTR(ret) : drm;
> +}
> +
> /*
> * On some Intel PCIe bridge controllers doing a
> * D0 -> D3hot -> D3cold -> D0 sequence causes Nvidia GPUs to not
> reappear. @@ -794,7 +831,7 @@ static int nouveau_drm_probe(struct
> pci_dev *pdev, const struct pci_device_id *pent)
> {
> struct nvkm_device *device;
> - struct drm_device *drm_dev;
> + struct nouveau_drm *drm;
> int ret;
>
> if (vga_switcheroo_client_probe_defer(pdev))
> @@ -825,9 +862,9 @@ static int nouveau_drm_probe(struct pci_dev *pdev,
> if (nouveau_atomic)
> driver_pci.driver_features |= DRIVER_ATOMIC;
>
> - drm_dev = drm_dev_alloc(&driver_pci, &pdev->dev);
> - if (IS_ERR(drm_dev)) {
> - ret = PTR_ERR(drm_dev);
> + drm = nouveau_drm_device_new(&driver_pci, &pdev->dev,
> device);
> + if (IS_ERR(drm)) {
> + ret = PTR_ERR(drm);
> goto fail_nvkm;
> }
>
> @@ -835,30 +872,22 @@ static int nouveau_drm_probe(struct pci_dev
> *pdev, if (ret)
> goto fail_drm;
>
> - pci_set_drvdata(pdev, drm_dev);
> -
> - ret = nouveau_drm_device_init(drm_dev);
> + ret = nouveau_drm_device_init(drm);
> if (ret)
> goto fail_pci;
>
> - ret = drm_dev_register(drm_dev, pent->driver_data);
> - if (ret)
> - goto fail_drm_dev_init;
> -
> - if (nouveau_drm(drm_dev)->client.device.info.ram_size <= 32
> * 1024 * 1024)
> - drm_fbdev_ttm_setup(drm_dev, 8);
> + if (drm->client.device.info.ram_size <= 32 * 1024 * 1024)
> + drm_fbdev_ttm_setup(drm->dev, 8);
> else
> - drm_fbdev_ttm_setup(drm_dev, 32);
> + drm_fbdev_ttm_setup(drm->dev, 32);
>
> quirk_broken_nv_runpm(pdev);
> return 0;
>
> -fail_drm_dev_init:
> - nouveau_drm_device_fini(drm_dev);
> fail_pci:
> pci_disable_device(pdev);
> fail_drm:
> - drm_dev_put(drm_dev);
> + nouveau_drm_device_del(drm);
> fail_nvkm:
> nvkm_device_del(&device);
> return ret;
> @@ -877,7 +906,7 @@ nouveau_drm_device_remove(struct drm_device *dev)
> device = nvkm_device_find(client->device);
>
> nouveau_drm_device_fini(dev);
> - drm_dev_put(dev);
> + nouveau_drm_device_del(drm);
> nvkm_device_del(&device);
> }
>
> @@ -1369,7 +1398,7 @@ nouveau_platform_device_create(const struct
> nvkm_device_tegra_func *func, struct platform_device *pdev,
> struct nvkm_device **pdevice)
> {
> - struct drm_device *drm;
> + struct nouveau_drm *drm;
> int err;
>
> err = nvkm_device_tegra_new(func, pdev, nouveau_config,
> nouveau_debug, @@ -1377,7 +1406,7 @@
> nouveau_platform_device_create(const struct nvkm_device_tegra_func
> *func, if (err) goto err_free;
>
> - drm = drm_dev_alloc(&driver_platform, &pdev->dev);
> + drm = nouveau_drm_device_new(&driver_platform, &pdev->dev,
> *pdevice); if (IS_ERR(drm)) {
> err = PTR_ERR(drm);
> goto err_free;
> @@ -1387,12 +1416,10 @@ nouveau_platform_device_create(const struct
> nvkm_device_tegra_func *func, if (err)
> goto err_put;
>
> - platform_set_drvdata(pdev, drm);
> -
> - return drm;
> + return drm->dev;
>
> err_put:
> - drm_dev_put(drm);
> + nouveau_drm_device_del(drm);
> err_free:
> nvkm_device_del(pdevice);
>
> diff --git a/drivers/gpu/drm/nouveau/nouveau_platform.c
> b/drivers/gpu/drm/nouveau/nouveau_platform.c index
> bf2dc7567ea4..d0a63f0f54a2 100644 ---
> a/drivers/gpu/drm/nouveau/nouveau_platform.c +++
> b/drivers/gpu/drm/nouveau/nouveau_platform.c @@ -34,12 +34,6 @@
> static int nouveau_platform_probe(struct platform_device *pdev) if
> (IS_ERR(drm)) return PTR_ERR(drm);
>
> - ret = drm_dev_register(drm, 0);
> - if (ret < 0) {
> - drm_dev_put(drm);
> - return ret;
> - }
> -
> return 0;
> }
>
Reviewed-by: Zhi Wang <zhiw@nvidia.com>
next prev parent reply other threads:[~2024-09-29 21:29 UTC|newest]
Thread overview: 70+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-26 4:37 [PATCH v3 00/37] drm/nouveau: misc. cleanups and removal of unused apis Ben Skeggs
2024-07-26 4:37 ` [PATCH v3 01/37] drm/nouveau: move nouveau_drm_device_fini() above init() Ben Skeggs
2024-07-31 10:10 ` Zhi Wang
2024-07-26 4:37 ` [PATCH v3 02/37] drm/nouveau: handle pci/tegra drm_dev_{alloc, register} from common code Ben Skeggs
2024-07-31 10:08 ` Zhi Wang [this message]
2024-07-31 10:09 ` Zhi Wang
2024-07-26 4:37 ` [PATCH v3 03/37] drm/nouveau: replace drm_device* with nouveau_drm* as dev drvdata Ben Skeggs
2024-07-31 10:13 ` Zhi Wang
2024-07-26 4:37 ` [PATCH v3 04/37] drm/nouveau: create pci device once Ben Skeggs
2024-07-31 10:20 ` Zhi Wang
2024-07-26 4:37 ` [PATCH v3 05/37] drm/nouveau: store nvkm_device pointer in nouveau_drm Ben Skeggs
2024-07-31 10:33 ` Zhi Wang
2024-07-26 4:37 ` [PATCH v3 06/37] drm/nouveau: move allocation of root client out of nouveau_cli_init() Ben Skeggs
2024-07-31 16:53 ` Zhi Wang
2024-07-26 4:37 ` [PATCH v3 07/37] drm/nouveau: add nouveau_cli to nouveau_abi16 Ben Skeggs
2024-07-31 11:05 ` Zhi Wang
2024-07-26 4:37 ` [PATCH v3 08/37] drm/nouveau: handle limited nvif ioctl in abi16 Ben Skeggs
2024-07-26 4:38 ` [PATCH v3 09/37] drm/nouveau: remove abi16->device Ben Skeggs
2024-07-31 11:19 ` Zhi Wang
2024-07-26 4:38 ` [PATCH v3 10/37] drm/nouveau: remove abi16->handles Ben Skeggs
2024-07-31 11:20 ` Zhi Wang
2024-07-26 4:38 ` [PATCH v3 11/37] drm/nouveau/nvkm: remove detect/mmio/subdev_mask from device args Ben Skeggs
2024-07-31 11:25 ` Zhi Wang
2024-07-26 4:38 ` [PATCH v3 12/37] drm/nouveau/nvkm: remove perfmon Ben Skeggs
2024-07-26 4:38 ` [PATCH v3 13/37] drm/nouveau/nvkm: remove nvkm_client_search() Ben Skeggs
2024-07-31 11:27 ` Zhi Wang
2024-07-26 4:38 ` [PATCH v3 14/37] drm/nouveau/nvif: remove support for userspace backends Ben Skeggs
2024-07-26 4:38 ` [PATCH v3 15/37] drm/nouveau/nvif: remove route/token Ben Skeggs
2024-07-26 4:38 ` [PATCH v3 16/37] drm/nouveau/nvif: remove nvxx_object() Ben Skeggs
2024-07-31 11:42 ` Zhi Wang
2024-07-26 4:38 ` [PATCH v3 17/37] drm/nouveau/nvif: remove nvxx_client() Ben Skeggs
2024-07-31 11:43 ` Zhi Wang
2024-07-26 4:38 ` [PATCH v3 18/37] drm/nouveau/nvif: remove driver keep/fini Ben Skeggs
2024-07-31 17:04 ` Zhi Wang
2024-07-26 4:38 ` [PATCH v3 19/37] drm/nouveau/nvif: remove client device arg Ben Skeggs
2024-07-26 4:38 ` [PATCH v3 20/37] drm/nouveau/nvif: remove client version Ben Skeggs
2024-07-31 17:08 ` Zhi Wang
2024-07-26 4:38 ` [PATCH v3 21/37] drm/nouveau/nvif: remove client devlist Ben Skeggs
2024-07-26 4:38 ` [PATCH v3 22/37] drm/nouveau/nvif: remove client fini Ben Skeggs
2024-07-31 11:49 ` Zhi Wang
2024-07-26 4:38 ` [PATCH v3 23/37] drm/nouveau/nvif: remove device args Ben Skeggs
2024-07-26 4:38 ` [PATCH v3 24/37] drm/nouveau: always map device Ben Skeggs
2024-07-31 17:21 ` Zhi Wang
2024-07-26 4:38 ` [PATCH v3 25/37] drm/nouveau/nvif: remove device rd/wr Ben Skeggs
2024-07-31 17:38 ` Zhi Wang
2024-07-26 4:38 ` [PATCH v3 26/37] drm/nouveau/nvif: remove disp chan rd/wr Ben Skeggs
2024-07-26 4:38 ` [PATCH v3 27/37] drm/nouveau: move nvxx_* definitions to nouveau_drv.h Ben Skeggs
2024-07-31 17:46 ` Zhi Wang
2024-07-26 4:38 ` [PATCH v3 28/37] drm/nouveau: add nvif_mmu to nouveau_drm Ben Skeggs
2024-07-31 17:55 ` Zhi Wang
2024-07-26 4:38 ` [PATCH v3 29/37] drm/nouveau: pass drm to nouveau_mem_new(), instead of cli Ben Skeggs
2024-07-31 17:58 ` Zhi Wang
2024-07-26 4:38 ` [PATCH v3 30/37] drm/nouveau: pass drm to nv50_dmac_create(), rather than device+disp Ben Skeggs
2024-07-31 18:00 ` Zhi Wang
2024-07-26 4:38 ` [PATCH v3 31/37] drm/nouveau: pass cli to nouveau_channel_new() instead of drm+device Ben Skeggs
2024-07-31 18:06 ` Zhi Wang
2024-07-26 4:38 ` [PATCH v3 32/37] drm/nouveau: remove nouveau_chan.device Ben Skeggs
2024-07-31 18:08 ` Zhi Wang
2024-07-26 4:38 ` [PATCH v3 33/37] drm/nouveau: remove chan->drm Ben Skeggs
2024-07-31 18:13 ` Zhi Wang
2024-07-26 4:38 ` [PATCH v3 34/37] drm/nouveau: remove master Ben Skeggs
2024-07-31 18:16 ` Zhi Wang
2024-07-26 4:38 ` [PATCH v3 35/37] drm/nouveau: remove push pointer from nouveau_channel Ben Skeggs
2024-07-31 18:21 ` Zhi Wang
2024-07-26 4:38 ` [PATCH v3 36/37] drm/nouveau/kms: remove a few unused struct members and fn decls Ben Skeggs
2024-07-31 18:23 ` Zhi Wang
2024-07-26 4:38 ` [PATCH v3 37/37] drm/nouveau/kms: remove push pointer from nv50_dmac Ben Skeggs
2024-07-31 18:24 ` Zhi Wang
2024-07-27 1:58 ` [PATCH v3 00/37] drm/nouveau: misc. cleanups and removal of unused apis Danilo Krummrich
2024-07-31 18:33 ` Zhi Wang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240731130845.0000723b.zhiw@nvidia.com \
--to=zhiw@nvidia.com \
--cc=bskeggs@nvidia.com \
--cc=nouveau@lists.freedesktop.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.