drm/vgem: Fix vgem_init to get drm device available.
Subsystems (3)
PATCH 1/3 drm/vgem: Fix vgem_init to get drm device available.
From: Deepak Sharma <[email protected]>
Modify vgem_init to take platform dev as parent in drm_dev_init. This will make drm device available at "/sys/devices/platform/vgem" in x86 chromebook.
v2: rebase, address checkpatch typo and line over 80 characters
--- drivers/gpu/drm/vgem/vgem_drv.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/gpu/drm/vgem/vgem_drv.c +8 -8
@@ -471,31 +471,31 @@ static int __init vgem_init(void)if (!vgem_device)return -ENOMEM ; - ret =drm_dev_init (&vgem_device->drm, &vgem_driver,NULL ); -if (ret) - goto out_free; - vgem_device->platform =platform_device_register_simple ("vgem" ,-1 ,NULL ,0 );if (IS_ERR (vgem_device->platform)) { ret =PTR_ERR (vgem_device->platform); - goto out_fini; + goto out_free; }dma_coerce_mask_and_coherent (&vgem_device->platform->dev,DMA_BIT_MASK (64 )); + ret =drm_dev_init (&vgem_device->drm, &vgem_driver, + &vgem_device->platform->dev); +if (ret) + goto out_unregister;/* Final step: expose the device/driver to userspace */ ret =drm_dev_register (&vgem_device->drm,0 );if (ret) - goto out_unregister; + goto out_fini;return 0 ; -out_unregister: -platform_device_unregister (vgem_device->platform); out_fini:drm_dev_fini (&vgem_device->drm); +out_unregister: +platform_device_unregister (vgem_device->platform); out_free:kfree (vgem_device);return ret;
Signature · 6 lines
2.19.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 2/3 drm: BUG_ON if passing NULL parent to drm_dev_init
From: Emil Velikov <[email protected]>
Previous commit removed the only reason why we were allowing NULL as a parent device. With that resolved, we can enforce nobody else does that mistake.
With that we can drop the ugly drm_dev_set_unique workaround.
v2: rebase, silence checkpatch "== NULL" warning
--- drivers/gpu/drm/drm_drv.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/gpu/drm/drm_drv.c +3 -5
@@ -476,8 +476,6 @@ static void drm_fs_inode_free(struct inode *inode)* The initial ref-count of the object is 1. Use drm_dev_get() and * drm_dev_put() to take and drop further ref-counts. * -* Note that for purely virtual devices @parent can be NULL. -* * Drivers that do not want to allocate their own device struct * embedding &struct drm_device can call drm_dev_alloc() instead. For drivers * that do embed &struct drm_device it must be placed first in the overall
@@ -502,6 +500,8 @@ int drm_dev_init(struct drm_device *dev,return -ENODEV ; } +BUG_ON (!parent); +kref_init (&dev->ref); dev->dev = parent; dev->driver = driver;
@@ -556,9 +556,7 @@ int drm_dev_init(struct drm_device *dev, } } -/* Use the parent device name as DRM device unique identifier, but fall -* back to the driver name for virtual devices like vgem. */ - ret =drm_dev_set_unique (dev, parent ?dev_name (parent) : driver->name); + ret =drm_dev_set_unique (dev,dev_name (parent));if (ret) goto err_setunique;
Signature · 6 lines
2.19.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
RE: [PATCH 2/3] drm: BUG_ON if passing NULL parent to drm_dev_init
Patch is Acked-by: Deepak Sharma <[email protected]>
Thanks,
Deepak
-----Original Message-----
From: Emil Velikov <[email protected]>
Sent: Tuesday, October 23, 2018 9:36 AM
To: [email protected]
Cc: [email protected]; Daniel Vetter <[email protected]>; Sharma, Deepak <[email protected]>
Subject: [PATCH 2/3] drm: BUG_ON if passing NULL parent to drm_dev_init
From: Emil Velikov <[email protected]>
Previous commit removed the only reason why we were allowing NULL as a parent device. With that resolved, we can enforce nobody else does that mistake.
With that we can drop the ugly drm_dev_set_unique workaround.
v2: rebase, silence checkpatch "== NULL" warning
--- drivers/gpu/drm/drm_drv.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/gpu/drm/drm_drv.c +0 -2
@@ -476,8 +476,6 @@ static void drm_fs_inode_free(struct inode *inode)* The initial ref-count of the object is 1. Use drm_dev_get() and * drm_dev_put() to take and drop further ref-counts. * -* Note that for purely virtual devices @parent can be NULL. -* * Drivers that do not want to allocate their own device struct * embedding &struct drm_device can call drm_dev_alloc() instead. For drivers * that do embed &struct drm_device it must be placed first in the overall @@ -502,6 +500,8 @@ int drm_dev_init(struct drm_device *dev,
return -ENODEV;
}
+ BUG_ON(!parent);
+
kref_init(&dev->ref);
dev->dev = parent;
dev->driver = driver;
@@ -556,9 +556,7 @@ int drm_dev_init(struct drm_device *dev,
}
}
- /* Use the parent device name as DRM device unique identifier, but fall
- * back to the driver name for virtual devices like vgem. */
- ret = drm_dev_set_unique(dev, parent ? dev_name(parent) : driver->name);
+ ret = drm_dev_set_unique(dev, dev_name(parent));
if (ret)
goto err_setunique;
--
2.19.1
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 3/3 drm/virtio: document drm_dev_set_unique workaround
In reply to Emil VelikovFrom: Emil Velikov <[email protected]>
A while back we removed it, yet that lead to regressions. At some later point, I've attempted to remove it again without fully grasping the unique (pun intended) situation that virtio is in.
Add a bulky comment to document any the call should stay as-is, for the next person who's around.
As a Tl;Dr: virtio sits on top of struct virtio_device, which confuses dev_is_pci(), wrong info gets sent to userspace and X doesn't start. Driver needs to explicitly call drm_dev_set_unique() to keep it working.
--- drivers/gpu/drm/virtio/virtgpu_drm_bus.c | 31 ++++++++++++++++++++++++ 1 file changed, 31 insertions(+)
drivers/gpu/drm/virtio/virtgpu_drm_bus.c +31 -0
@@ -53,6 +53,37 @@ int drm_virtio_init(struct drm_driver *driver, struct virtio_device *vdev)0 , "virtiodrmfb"); +/* +* Normally the drm_dev_set_unique() call is done by core DRM. +* The following comment covers, why virtio cannot rely on it. +* +* Unlike the other virtual GPU drivers, virtio abstracts the +* underlying bus type by using struct virtio_device. +* +* Hence the dev_is_pci() check, used in core DRM, will fail +* and the unique returned will be the virtio_device "virtio0", +* while a "pci:..." one is required. +* +* A few other ideas were considered: +* - Extend dev_is_pci() check [in drm_set_busid] to consider +* virtio. +* Seems like a bigger hack than what we have already. +* +* - Point drm_device::dev to the parent of the virtio_device +* Semantic changes: +* * Using the wrong device for i2c, framebuffer_alloc and +* prime import. +* Visual changes: +* * Helpers such as DRM_DEV_ERROR, dev_info, drm_printer, +* will print the wrong information. +* +* We could address the latter issues, by introducing +* drm_device::bus_dev, ... which will be used solely for this. +* +* So for the moment keep things as-is, with a bulky comment +* for the next person who feels like removing this +* drm_dev_set_unique() quirk. +*/ snprintf (unique,sizeof (unique),"pci:%s" , pname); ret =drm_dev_set_unique (dev, unique);if (ret)
Signature · 6 lines
2.19.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 3/3] drm/virtio: document drm_dev_set_unique workaround
Quoted 5 lines · Emil Velikov
From: Emil Velikov <[email protected]>
A while back we removed it, yet that lead to regressions. At some later point, I've attempted to remove it again without fully grasping the unique (pun intended) situation that virtio is in.
pun appreciated :)
Quoted 3 lines
Add a bulky comment to document any the call should stay as-is, for the next person who's around.
s/any/why/?
Quoted 26 lines
As a Tl;Dr: virtio sits on top of struct
virtio_device, which confusesdev_is_pci(), wrong info gets sent to userspace and X doesn't start. Driver needs to explicitly calldrm_dev_set_unique()to keep it working.Cc Daniel Vetter <[email protected]>Cc Gerd Hoffmann <[email protected]>Cc Hans de Goede <[email protected]>Cc Laszlo Ersek <[email protected]>Signed-off-by Emil Velikov <[email protected]>--- drivers/gpu/drm/virtio/virtgpu_drm_bus.c | 31 ++++++++++++++++++++++++ 1 file changed, 31 insertions(+)drivers/gpu/drm/virtio/virtgpu_drm_bus.c +4
-0@@ -53,6 +53,37 @@ int drm_virtio_init(struct drm_driver *driver, struct virtio_device *vdev)0 , "virtiodrmfb"); +/* +* Normally the drm_dev_set_unique() call is done by core DRM. +* The following comment covers, why virtio cannot rely on it. +*
drivers/gpu/drm/virtio/virtgpu_drm_bus.c int drm_virtio_init(struct drm_driver *driver, struct virtio_device *vdev) · line 69
Quoted 10 lines
drivers/gpu/drm/virtio/virtgpu_drm_bus.c +10
-0+* Unlike the other virtual GPU drivers, virtio abstracts the +* underlying bus type by using struct virtio_device. +* +* Hence the dev_is_pci() check, used in core DRM, will fail +* and the unique returned will be the virtio_device "virtio0", +* while a "pci:..." one is required. +* +* A few other ideas were considered: +* - Extend dev_is_pci() check [in drm_set_busid] to consider +* virtio.
I suggest "Extend [the] dev_is_pci() check" for a more "fluent" reading experience. (I should note however that I'm not a native speaker.)
In addition, the word "virtio" doesn't appear correctly indented, within the comment.
drivers/gpu/drm/virtio/virtgpu_drm_bus.c int drm_virtio_init(struct drm_driver *driver, struct virtio_device *vdev) · line 81
Quoted 12 lines
drivers/gpu/drm/virtio/virtgpu_drm_bus.c +12
-0+* Seems like a bigger hack than what we have already. +* +* - Point drm_device::dev to the parent of the virtio_device +* Semantic changes: +* * Using the wrong device for i2c, framebuffer_alloc and +* prime import. +* Visual changes: +* * Helpers such as DRM_DEV_ERROR, dev_info, drm_printer, +* will print the wrong information. +* +* We could address the latter issues, by introducing +* drm_device::bus_dev, ... which will be used solely for this.
s/will/would/?
drivers/gpu/drm/virtio/virtgpu_drm_bus.c int drm_virtio_init(struct drm_driver *driver, struct virtio_device *vdev) · line 89
Quoted 9 lines
drivers/gpu/drm/virtio/virtgpu_drm_bus.c +5
-0+* +* So for the moment keep things as-is, with a bulky comment +* for the next person who feels like removing this +* drm_dev_set_unique() quirk. +*/ snprintf (unique,sizeof (unique),"pci:%s" , pname); ret =drm_dev_set_unique (dev, unique);if (ret)
Semantically: I've by now totally forgotten about these details, so if you wanted to, you could totally sell me on some "underhanded inaccuracies" in this comment.
That said, I feel the comment (and the commit message) are great. The comment makes me recall the details on the subject, and I think it'll be pretty effective as a warning, effective at preventing further regressions in the area.
With the typos fixed:
Thanks!
Laszlo
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v2 1/1 drm/virtio: document drm_dev_set_unique workaround
In reply to Emil VelikovFrom: Emil Velikov <[email protected]>
A while back we removed it, yet that lead to regressions. At some later point, I've attempted to remove it again without fully grasping the unique (pun intended) situation that virtio is in.
Add a bulky comment to document why the call should stay as-is, for the next person who's around.
As a Tl;Dr: virtio sits on top of struct virtio_device, which confuses dev_is_pci(), wrong info gets sent to userspace and X doesn't start. Driver needs to explicitly call drm_dev_set_unique() to keep it working.
v2: Fix handful of typos (Laszlo)
---
Thanks for the quick feedback and corrections Laszlo. They're spot-on and I've addressed them all here.
Sending it out for posterity-sake. Modulo any objections I'll merge this via drm-misc.
--- drivers/gpu/drm/virtio/virtgpu_drm_bus.c | 31 ++++++++++++++++++++++++ 1 file changed, 31 insertions(+)
drivers/gpu/drm/virtio/virtgpu_drm_bus.c +31 -0
@@ -53,6 +53,37 @@ int drm_virtio_init(struct drm_driver *driver, struct virtio_device *vdev)0 , "virtiodrmfb"); +/* +* Normally the drm_dev_set_unique() call is done by core DRM. +* The following comment covers, why virtio cannot rely on it. +* +* Unlike the other virtual GPU drivers, virtio abstracts the +* underlying bus type by using struct virtio_device. +* +* Hence the dev_is_pci() check, used in core DRM, will fail +* and the unique returned will be the virtio_device "virtio0", +* while a "pci:..." one is required. +* +* A few other ideas were considered: +* - Extend the dev_is_pci() check [in drm_set_busid] to +* consider virtio. +* Seems like a bigger hack than what we have already. +* +* - Point drm_device::dev to the parent of the virtio_device +* Semantic changes: +* * Using the wrong device for i2c, framebuffer_alloc and +* prime import. +* Visual changes: +* * Helpers such as DRM_DEV_ERROR, dev_info, drm_printer, +* will print the wrong information. +* +* We could address the latter issues, by introducing +* drm_device::bus_dev, ... which would be used solely for this. +* +* So for the moment keep things as-is, with a bulky comment +* for the next person who feels like removing this +* drm_dev_set_unique() quirk. +*/ snprintf (unique,sizeof (unique),"pci:%s" , pname); ret =drm_dev_set_unique (dev, unique);if (ret)
Signature · 6 lines
2.19.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH v2] drm/virtio: document drm_dev_set_unique workaround
Quoted 13 lines · Emil Velikov
From: Emil Velikov <[email protected]>
A while back we removed it, yet that lead to regressions. At some later point, I've attempted to remove it again without fully grasping the unique (pun intended) situation that virtio is in.
Add a bulky comment to document why the call should stay as-is, for the next person who's around.
As a Tl;Dr: virtio sits on top of struct
virtio_device, which confusesdev_is_pci(), wrong info gets sent to userspace and X doesn't start. Driver needs to explicitly calldrm_dev_set_unique()to keep it working.
Quoted 8 lines
v2: Fix handful of typos (Laszlo)
Cc Daniel Vetter <[email protected]>Cc Gerd Hoffmann <[email protected]>Cc Hans de Goede <[email protected]>Cc Laszlo Ersek <[email protected]>Signed-off-by Emil Velikov <[email protected]>Reviewed-by Laszlo Ersek <[email protected]>
Quoted 2 lines
Sending it out for posterity-sake. Modulo any objections I'll merge this via drm-misc.
Ah, good, leaving merging to you then ;)
cheers,
Gerd
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH v2] drm/virtio: document drm_dev_set_unique workaround
Quoted 17 lines · Gerd Hoffmann
Quoted 15 lines · Emil Velikov
From: Emil Velikov <[email protected]>
A while back we removed it, yet that lead to regressions. At some later point, I've attempted to remove it again without fully grasping the unique (pun intended) situation that virtio is in.
Add a bulky comment to document why the call should stay as-is, for the next person who's around.
As a Tl;Dr: virtio sits on top of struct
virtio_device, which confusesdev_is_pci(), wrong info gets sent to userspace and X doesn't start. Driver needs to explicitly calldrm_dev_set_unique()to keep it working.v2: Fix handful of typos (Laszlo)
Quoted 9 lines
Quoted 6 lines
Cc Daniel Vetter <[email protected]>Cc Gerd Hoffmann <[email protected]>Cc Hans de Goede <[email protected]>Cc Laszlo Ersek <[email protected]>Signed-off-by Emil Velikov <[email protected]>Reviewed-by Laszlo Ersek <[email protected]>Reviewed-by Gerd Hoffmann <[email protected]>
Thanks Gerd.
Quoted 5 lines
Quoted 2 lines
Sending it out for posterity-sake. Modulo any objections I'll merge this via drm-misc.
Ah, good, leaving merging to you then ;)
I've pushed the commit to drm-misc with Laszlo's RB a bit before your reply. Hope it's not a problem, but for the future I'll be more patient.
-Emil
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel