[PATCH 3/5] drm/amdgpu: Paper over the drm_driver mangling for virt

Daniel Vetter daniel.vetter at ffwll.ch
Sat Oct 31 13:57:32 UTC 2020


On Fri, Oct 30, 2020 at 7:47 PM Alex Deucher <alexdeucher at gmail.com> wrote:
>
> On Fri, Oct 30, 2020 at 6:11 AM Daniel Vetter <daniel.vetter at ffwll.ch> wrote:
> >
> > Prep work to make drm_device->driver const.
> >
> > Signed-off-by: Daniel Vetter <daniel.vetter at ffwll.ch>
> > Cc: Alex Deucher <alexander.deucher at amd.com>
> > Cc: "Christian König" <christian.koenig at amd.com>
> > Cc: Evan Quan <evan.quan at amd.com>
> > Cc: Felix Kuehling <Felix.Kuehling at amd.com>
> > Cc: Hawking Zhang <Hawking.Zhang at amd.com>
> > Cc: Andrey Grodzovsky <andrey.grodzovsky at amd.com>
> > Cc: Luben Tuikov <luben.tuikov at amd.com>
> > Cc: Thomas Zimmermann <tzimmermann at suse.de>
> > Cc: Monk Liu <Monk.Liu at amd.com>
> > Cc: Yintian Tao <yttao at amd.com>
> > Cc: Dennis Li <Dennis.Li at amd.com>
> > Cc: shaoyunl <shaoyun.liu at amd.com>
> > Cc: Bokun Zhang <Bokun.Zhang at amd.com>
> > Cc: "Stanley.Yang" <Stanley.Yang at amd.com>
> > Cc: Wenhui Sheng <Wenhui.Sheng at amd.com>
> > Cc: chen gong <curry.gong at amd.com>
> > Signed-off-by: Daniel Vetter <daniel.vetter at intel.com>
> > ---
> >  drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c  |  8 ++++----
> >  drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c | 12 +++++++++++-
> >  2 files changed, 15 insertions(+), 5 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
> > index 024c3b70b1aa..3d337f13ae4e 100644
> > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
> > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
> > @@ -1093,7 +1093,7 @@ static const struct pci_device_id pciidlist[] = {
> >
> >  MODULE_DEVICE_TABLE(pci, pciidlist);
> >
> > -static struct drm_driver kms_driver;
> > +struct drm_driver amdgpu_kms_driver;
> >
> >  static int amdgpu_pci_probe(struct pci_dev *pdev,
> >                             const struct pci_device_id *ent)
> > @@ -1164,7 +1164,7 @@ static int amdgpu_pci_probe(struct pci_dev *pdev,
> >         if (ret)
> >                 return ret;
> >
> > -       adev = devm_drm_dev_alloc(&pdev->dev, &kms_driver, typeof(*adev), ddev);
> > +       adev = devm_drm_dev_alloc(&pdev->dev, &amdgpu_kms_driver, typeof(*adev), ddev);
> >         if (IS_ERR(adev))
> >                 return PTR_ERR(adev);
> >
> > @@ -1508,7 +1508,7 @@ int amdgpu_file_to_fpriv(struct file *filp, struct amdgpu_fpriv **fpriv)
> >         return 0;
> >  }
> >
> > -static struct drm_driver kms_driver = {
> > +struct drm_driver amdgpu_kms_driver = {
> >         .driver_features =
> >             DRIVER_ATOMIC |
> >             DRIVER_GEM |
> > @@ -1571,7 +1571,7 @@ static int __init amdgpu_init(void)
> >                 goto error_fence;
> >
> >         DRM_INFO("amdgpu kernel modesetting enabled.\n");
> > -       kms_driver.num_ioctls = amdgpu_max_kms_ioctl;
> > +       amdgpu_kms_driver.num_ioctls = amdgpu_max_kms_ioctl;
> >         amdgpu_register_atpx_handler();
> >
> >         /* Ignore KFD init failures. Normal when CONFIG_HSA_AMD is not set. */
> > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
> > index d0aea5e39531..dde4c449c284 100644
> > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
> > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
> > @@ -45,13 +45,23 @@ bool amdgpu_virt_mmio_blocked(struct amdgpu_device *adev)
> >         return RREG32_NO_KIQ(0xc040) == 0xffffffff;
> >  }
> >
> > +extern struct drm_driver amdgpu_kms_driver;
> > +
> >  void amdgpu_virt_init_setting(struct amdgpu_device *adev)
> >  {
> >         /* enable virtual display */
> >         if (adev->mode_info.num_crtc == 0)
> >                 adev->mode_info.num_crtc = 1;
> >         adev->enable_virtual_display = true;
> > -       adev_to_drm(adev)->driver->driver_features &= ~DRIVER_ATOMIC;
> > +
> > +       /*
> > +        * FIXME: Either make virt support atomic or make sure you have two
> > +        * drm_driver structs, these kind of tricks are only ok when there's
> > +        * guaranteed only a single device per system. This should also be done
> > +        * before struct drm_device is initialized.
> > +        */
> > +       amdgpu_kms_driver.driver_features &= ~DRIVER_ATOMIC;
>
> There is additional DRIVER_ATOMIC in amdgpu_pci_probe() for older
> chips without atomic support.

That would need to be fixed for making the amdgpu drm_driver
structures constant, but that's not what I'm doing here. I'm only
removing the usage of the drm_device->driver pointer, to allow that to
become constant. Untangling the flow to make the amdgpu_kms_driver
const looked a bit more involved than just a  simple patch.
-Daniel

> Alex
>
> > +
> >         adev->cg_flags = 0;
> >         adev->pg_flags = 0;
> >  }
> > --
> > 2.28.0
> >
> > _______________________________________________
> > dri-devel mailing list
> > dri-devel at lists.freedesktop.org
> > https://lists.freedesktop.org/mailman/listinfo/dri-devel



-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch


More information about the dri-devel mailing list