From: Danilo Krummrich <dakr@redhat.com>
To: Ben Skeggs <bskeggs@nvidia.com>
Cc: nouveau@lists.freedesktop.org
Subject: Re: [PATCH v2 02/37] drm/nouveau: handle pci/tegra drm_dev_{alloc, register} from common code
Date: Fri, 19 Jul 2024 13:10:50 +0200 [thread overview]
Message-ID: <ZppJuiWfgfkEKeCH@pollux> (raw)
In-Reply-To: <e67e0c36-5c21-4f37-b489-78ec45298c4e@nvidia.com>
On Thu, Jul 18, 2024 at 05:14:15PM +1000, Ben Skeggs wrote:
> On 10/7/24 01:16, Danilo Krummrich wrote:
>
> > On Fri, Jul 05, 2024 at 04:36:46AM +1000, Ben Skeggs wrote:
> > > The next commit will change the pointer we store via dev_set_drvdata()
> > > to allow simplifying the code using it.
> > Please don't use future tense, e.g "In subsequent commits, the pointer we store
> > [...]". Also, when you mention that something is changes (such as the pointer
> > type here), it probably makes sense to mention what it is changed to instead.
> >
> > > Here we want to unify some more of the PCI/Tegra DRM driver init, both
> > > as a general cleanup, and to enable the dev_set_drvdata() change to be
> > > made in a single place.
> > In this case I think it makes sense to switch things up. First mention what the
> > commit does and why, i.e. "Unify some more of the PCI/Tegra DRM driver init
> > [...]" and then mention that the actual change to the pointer stored in a
> > device' drvdata in done in a subsequent commit.
>
> I've reworded the commit message.
>
>
> >
> > > 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);
> > Since you're reworking this anyways, can we switch to devm_drm_dev_alloc()?
> >
> > This also gets us rid of nouveau_drm_device_del().
>
> No, we can't. I originally had this change as a cleanup patch in the series
> I posted implementing aux bus support. However it turns out that in order
> to avoid breaking udev etc, we can't use the aux device as parent of the drm
Can you please expand a bit on what was breaking?
> device and instead have to continue passing the pci/platform device as we do
> now.
>
> Using devm_drm_dev_alloc() with the pci device as parent would tie the
> lifetime of the drm device to the pci device, which is owned by nvkm (after
How does this tie the lifetime of the drm device to the pci device? It's the
other way around, the drm device takes a reference of its parent (i.e. the pci
device).
I don't think there's anything wrong with that.
> the auxdev series). We could look at changing devm_drm_dev_alloc() of
> course, but I think that's best left until later.
I don't think that this is necessary.
>
> >
> > > + 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;
> > > }
> > > --
> > > 2.45.1
> > >
>
next prev parent reply other threads:[~2024-07-19 11:10 UTC|newest]
Thread overview: 77+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-04 18:36 [PATCH v2 00/37] drm/nouveau: misc. cleanups and removal of unused apis Ben Skeggs
2024-07-04 18:36 ` [PATCH v2 01/37] drm/nouveau: move nouveau_drm_device_fini() above init() Ben Skeggs
2024-07-09 14:48 ` Danilo Krummrich
2024-07-04 18:36 ` [PATCH v2 02/37] drm/nouveau: handle pci/tegra drm_dev_{alloc, register} from common code Ben Skeggs
2024-07-09 15:16 ` Danilo Krummrich
2024-07-18 7:14 ` Ben Skeggs
2024-07-19 11:10 ` Danilo Krummrich [this message]
2024-07-26 4:27 ` Ben Skeggs
2024-07-26 15:41 ` Danilo Krummrich
2024-07-26 13:07 ` Ben Skeggs
2024-07-27 1:54 ` Danilo Krummrich
2024-07-28 18:13 ` Jason Gunthorpe
2024-07-28 21:34 ` Danilo Krummrich
2024-07-28 23:04 ` Jason Gunthorpe
2024-07-29 0:55 ` Danilo Krummrich
2024-07-04 18:36 ` [PATCH v2 03/37] drm/nouveau: replace drm_device* with nouveau_drm* as dev drvdata Ben Skeggs
2024-07-04 18:36 ` [PATCH v2 04/37] drm/nouveau: create pci device once Ben Skeggs
2024-07-04 18:36 ` [PATCH v2 05/37] drm/nouveau: store nvkm_device pointer in nouveau_drm Ben Skeggs
2024-07-04 18:36 ` [PATCH v2 06/37] drm/nouveau: move allocation of root client out of nouveau_cli_init() Ben Skeggs
2024-07-09 15:33 ` Danilo Krummrich
2024-07-18 7:29 ` Ben Skeggs
2024-07-19 11:37 ` Danilo Krummrich
2024-07-26 4:29 ` Ben Skeggs
2024-07-04 18:36 ` [PATCH v2 07/37] drm/nouveau: add nouveau_cli to nouveau_abi16 Ben Skeggs
2024-07-09 15:36 ` Danilo Krummrich
2024-07-04 18:36 ` [PATCH v2 08/37] drm/nouveau: handle limited nvif ioctl in abi16 Ben Skeggs
2024-07-09 16:03 ` Danilo Krummrich
2024-07-18 7:43 ` Ben Skeggs
2024-07-19 12:06 ` Danilo Krummrich
2024-07-04 18:36 ` [PATCH v2 09/37] drm/nouveau: remove abi16->device Ben Skeggs
2024-07-04 18:36 ` [PATCH v2 10/37] drm/nouveau: remove abi16->handles Ben Skeggs
2024-07-04 18:36 ` [PATCH v2 11/37] drm/nouveau/nvkm: remove detect/mmio/subdev_mask from device args Ben Skeggs
2024-07-04 18:36 ` [PATCH v2 12/37] drm/nouveau/nvkm: remove perfmon Ben Skeggs
2024-07-04 18:36 ` [PATCH v2 13/37] drm/nouveau/nvkm: remove nvkm_client_search() Ben Skeggs
2024-07-04 18:36 ` [PATCH v2 14/37] drm/nouveau/nvif: remove support for userspace backends Ben Skeggs
2024-07-04 18:36 ` [PATCH v2 15/37] drm/nouveau/nvif: remove route/token Ben Skeggs
2024-07-09 16:11 ` Danilo Krummrich
2024-07-18 7:52 ` Ben Skeggs
2024-07-19 12:12 ` Danilo Krummrich
2024-07-04 18:37 ` [PATCH v2 16/37] drm/nouveau/nvif: remove nvxx_object() Ben Skeggs
2024-07-09 16:14 ` Danilo Krummrich
2024-07-04 18:37 ` [PATCH v2 17/37] drm/nouveau/nvif: remove nvxx_client() Ben Skeggs
2024-07-04 18:37 ` [PATCH v2 18/37] drm/nouveau/nvif: remove driver keep/fini Ben Skeggs
2024-07-04 18:37 ` [PATCH v2 19/37] drm/nouveau/nvif: remove client device arg Ben Skeggs
2024-07-09 16:16 ` Danilo Krummrich
2024-07-04 18:37 ` [PATCH v2 20/37] drm/nouveau/nvif: remove client version Ben Skeggs
2024-07-04 18:37 ` [PATCH v2 21/37] drm/nouveau/nvif: remove client devlist Ben Skeggs
2024-07-04 18:37 ` [PATCH v2 22/37] drm/nouveau/nvif: remove client fini Ben Skeggs
2024-07-04 18:37 ` [PATCH v2 23/37] drm/nouveau/nvif: remove device args Ben Skeggs
2024-07-09 16:18 ` Danilo Krummrich
2024-07-04 18:37 ` [PATCH v2 24/37] drm/nouveau: always map device Ben Skeggs
2024-07-04 18:37 ` [PATCH v2 25/37] drm/nouveau/nvif: remove device rd/wr Ben Skeggs
2024-07-09 16:22 ` Danilo Krummrich
2024-07-04 18:37 ` [PATCH v2 26/37] drm/nouveau/nvif: remove disp chan rd/wr Ben Skeggs
2024-07-04 18:37 ` [PATCH v2 27/37] drm/nouveau: move nvxx_* definitions to nouveau_drv.h Ben Skeggs
2024-07-09 16:31 ` Danilo Krummrich
2024-07-18 7:58 ` Ben Skeggs
2024-07-19 12:28 ` Danilo Krummrich
2024-07-26 4:35 ` Ben Skeggs
2024-07-04 18:37 ` [PATCH v2 28/37] drm/nouveau: add nvif_mmu to nouveau_drm Ben Skeggs
2024-07-09 16:34 ` Danilo Krummrich
2024-07-18 8:10 ` Ben Skeggs
2024-07-19 12:47 ` Danilo Krummrich
2024-07-04 18:37 ` [PATCH v2 29/37] drm/nouveau: pass drm to nouveau_mem_new(), instead of cli Ben Skeggs
2024-07-04 18:37 ` [PATCH v2 30/37] drm/nouveau: pass drm to nv50_dmac_create(), rather than device+disp Ben Skeggs
2024-07-04 18:37 ` [PATCH v2 31/37] drm/nouveau: pass cli to nouveau_channel_new() instead of drm+device Ben Skeggs
2024-07-04 18:37 ` [PATCH v2 32/37] drm/nouveau: remove nouveau_chan.device Ben Skeggs
2024-07-04 18:37 ` [PATCH v2 33/37] drm/nouveau: remove chan->drm Ben Skeggs
2024-07-04 18:37 ` [PATCH v2 34/37] drm/nouveau: remove master Ben Skeggs
2024-07-09 16:38 ` Danilo Krummrich
2024-07-18 8:12 ` Ben Skeggs
2024-07-19 12:49 ` Danilo Krummrich
2024-07-04 18:37 ` [PATCH v2 35/37] drm/nouveau: remove push pointer from nouveau_channel Ben Skeggs
2024-07-04 18:37 ` [PATCH v2 36/37] drm/nouveau/kms: remove a few unused struct members and fn decls Ben Skeggs
2024-07-04 18:37 ` [PATCH v2 37/37] drm/nouveau/kms: remove push pointer from nv50_dmac Ben Skeggs
2024-07-09 14:44 ` [PATCH v2 00/37] drm/nouveau: misc. cleanups and removal of unused apis Danilo Krummrich
2024-07-18 7:00 ` Ben Skeggs
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=ZppJuiWfgfkEKeCH@pollux \
--to=dakr@redhat.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.