[v3,1/2] drm/file: Rehabilitate the firstopen hook for non-legacy drivers

Submitted by Paul Kocialkowski on March 28, 2019, 4:13 p.m.

Details

Message ID 20190328161306.22757-2-paul.kocialkowski@bootlin.com
State New
Headers show
Series "drm/vc4: Binner BO management improvements" ( rev: 2 ) in DRI devel

Not browsing as part of any series.

Commit Message

Paul Kocialkowski March 28, 2019, 4:13 p.m.
The firstopen DRM driver hook was initially used to perform hardware
initialization, which is now considered legacy. Only a single user of
firstopen remains at this point (savage).

In some specific cases, non-legacy drivers may also need to implement
these hooks. For instance on VC4, we need to allocate a 16 MiB buffer
for the GPU. Because it's not required for fbcon, it's a waste to
allocate it before userspace starts using the DRM device.

Using firstopen and lastclose for this allocation seems like the best
fit, so re-habilitate the hook to allow it to be called for non-legacy
drivers.

Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
---
 drivers/gpu/drm/drm_file.c | 3 +--
 include/drm/drm_drv.h      | 3 ---
 2 files changed, 1 insertion(+), 5 deletions(-)

Patch hide | download patch | download mbox

diff --git a/drivers/gpu/drm/drm_file.c b/drivers/gpu/drm/drm_file.c
index b1838a41ad43..c011b5cbfb6b 100644
--- a/drivers/gpu/drm/drm_file.c
+++ b/drivers/gpu/drm/drm_file.c
@@ -266,8 +266,7 @@  static int drm_setup(struct drm_device * dev)
 {
 	int ret;
 
-	if (dev->driver->firstopen &&
-	    drm_core_check_feature(dev, DRIVER_LEGACY)) {
+	if (dev->driver->firstopen) {
 		ret = dev->driver->firstopen(dev);
 		if (ret != 0)
 			return ret;
diff --git a/include/drm/drm_drv.h b/include/drm/drm_drv.h
index ca46a45a9cce..de5637494503 100644
--- a/include/drm/drm_drv.h
+++ b/include/drm/drm_drv.h
@@ -234,9 +234,6 @@  struct drm_driver {
 	 * kernel driver does not really own the hardware. Instead ownershipe is
 	 * handled with the help of userspace through an inheritedly racy dance
 	 * to set/unset the VT into raw mode.
-	 *
-	 * Legacy drivers initialize the hardware in the @firstopen callback,
-	 * which isn't even called for modern drivers.
 	 */
 	void (*lastclose) (struct drm_device *);
 

Comments

On Thu, Mar 28, 2019 at 05:13:05PM +0100, Paul Kocialkowski wrote:
> The firstopen DRM driver hook was initially used to perform hardware
> initialization, which is now considered legacy. Only a single user of
> firstopen remains at this point (savage).
> 
> In some specific cases, non-legacy drivers may also need to implement
> these hooks. For instance on VC4, we need to allocate a 16 MiB buffer
> for the GPU. Because it's not required for fbcon, it's a waste to
> allocate it before userspace starts using the DRM device.
> 
> Using firstopen and lastclose for this allocation seems like the best
> fit, so re-habilitate the hook to allow it to be called for non-legacy
> drivers.
> 
> Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
> Reviewed-by: Eric Anholt <eric@anholt.net>
> ---
>  drivers/gpu/drm/drm_file.c | 3 +--
>  include/drm/drm_drv.h      | 3 ---
>  2 files changed, 1 insertion(+), 5 deletions(-)
> 
> diff --git a/drivers/gpu/drm/drm_file.c b/drivers/gpu/drm/drm_file.c
> index b1838a41ad43..c011b5cbfb6b 100644
> --- a/drivers/gpu/drm/drm_file.c
> +++ b/drivers/gpu/drm/drm_file.c
> @@ -266,8 +266,7 @@ static int drm_setup(struct drm_device * dev)
>  {
>  	int ret;
>  
> -	if (dev->driver->firstopen &&
> -	    drm_core_check_feature(dev, DRIVER_LEGACY)) {
> +	if (dev->driver->firstopen) {

If you guys insist on this (still not a fan myself) pls pull it out of
drm_setup - that's all just legacy hw setup in there. I still think
tracking this a bit more accurately (if you want to bother with this)
would be better.
-Daniel

>  		ret = dev->driver->firstopen(dev);
>  		if (ret != 0)
>  			return ret;
> diff --git a/include/drm/drm_drv.h b/include/drm/drm_drv.h
> index ca46a45a9cce..de5637494503 100644
> --- a/include/drm/drm_drv.h
> +++ b/include/drm/drm_drv.h
> @@ -234,9 +234,6 @@ struct drm_driver {
>  	 * kernel driver does not really own the hardware. Instead ownershipe is
>  	 * handled with the help of userspace through an inheritedly racy dance
>  	 * to set/unset the VT into raw mode.
> -	 *
> -	 * Legacy drivers initialize the hardware in the @firstopen callback,
> -	 * which isn't even called for modern drivers.
>  	 */
>  	void (*lastclose) (struct drm_device *);
>  
> -- 
> 2.21.0
>
On Fri, Mar 29, 2019 at 09:35:34AM +0100, Daniel Vetter wrote:
> On Thu, Mar 28, 2019 at 05:13:05PM +0100, Paul Kocialkowski wrote:
> > The firstopen DRM driver hook was initially used to perform hardware
> > initialization, which is now considered legacy. Only a single user of
> > firstopen remains at this point (savage).
> > 
> > In some specific cases, non-legacy drivers may also need to implement
> > these hooks. For instance on VC4, we need to allocate a 16 MiB buffer
> > for the GPU. Because it's not required for fbcon, it's a waste to
> > allocate it before userspace starts using the DRM device.
> > 
> > Using firstopen and lastclose for this allocation seems like the best
> > fit, so re-habilitate the hook to allow it to be called for non-legacy
> > drivers.
> > 
> > Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
> > Reviewed-by: Eric Anholt <eric@anholt.net>
> > ---
> >  drivers/gpu/drm/drm_file.c | 3 +--
> >  include/drm/drm_drv.h      | 3 ---
> >  2 files changed, 1 insertion(+), 5 deletions(-)
> > 
> > diff --git a/drivers/gpu/drm/drm_file.c b/drivers/gpu/drm/drm_file.c
> > index b1838a41ad43..c011b5cbfb6b 100644
> > --- a/drivers/gpu/drm/drm_file.c
> > +++ b/drivers/gpu/drm/drm_file.c
> > @@ -266,8 +266,7 @@ static int drm_setup(struct drm_device * dev)
> >  {
> >  	int ret;
> >  
> > -	if (dev->driver->firstopen &&
> > -	    drm_core_check_feature(dev, DRIVER_LEGACY)) {
> > +	if (dev->driver->firstopen) {
> 
> If you guys insist on this (still not a fan myself) pls pull it out of
> drm_setup - that's all just legacy hw setup in there. I still think
> tracking this a bit more accurately (if you want to bother with this)
> would be better.

Maybe another one: Firstopen is called after ->open, which might be
confusing. But we can't change that ever because legacy drivers surely
rely on that somewhere (like the backwards load/unload calling sequence).
-Daniel
Hi Daniel,

On Fri, 2019-03-29 at 09:35 +0100, Daniel Vetter wrote:
> On Thu, Mar 28, 2019 at 05:13:05PM +0100, Paul Kocialkowski wrote:
> > The firstopen DRM driver hook was initially used to perform hardware
> > initialization, which is now considered legacy. Only a single user of
> > firstopen remains at this point (savage).
> > 
> > In some specific cases, non-legacy drivers may also need to implement
> > these hooks. For instance on VC4, we need to allocate a 16 MiB buffer
> > for the GPU. Because it's not required for fbcon, it's a waste to
> > allocate it before userspace starts using the DRM device.
> > 
> > Using firstopen and lastclose for this allocation seems like the best
> > fit, so re-habilitate the hook to allow it to be called for non-legacy
> > drivers.
> > 
> > Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
> > Reviewed-by: Eric Anholt <eric@anholt.net>
> > ---
> >  drivers/gpu/drm/drm_file.c | 3 +--
> >  include/drm/drm_drv.h      | 3 ---
> >  2 files changed, 1 insertion(+), 5 deletions(-)
> > 
> > diff --git a/drivers/gpu/drm/drm_file.c b/drivers/gpu/drm/drm_file.c
> > index b1838a41ad43..c011b5cbfb6b 100644
> > --- a/drivers/gpu/drm/drm_file.c
> > +++ b/drivers/gpu/drm/drm_file.c
> > @@ -266,8 +266,7 @@ static int drm_setup(struct drm_device * dev)
> >  {
> >  	int ret;
> >  
> > -	if (dev->driver->firstopen &&
> > -	    drm_core_check_feature(dev, DRIVER_LEGACY)) {
> > +	if (dev->driver->firstopen) {
> 
> If you guys insist on this (still not a fan myself) pls pull it out of
> drm_setup - that's all just legacy hw setup in there. I still think
> tracking this a bit more accurately (if you want to bother with this)
> would be better.

I sent out this v3 right before receiving your comments on v2, so this
new iteration only takes Eric's comments into account.

I think the points you made on v2 are very legitimate and I'll be
working to prepare a new series that takes them into consideration :)

Cheers,

Paul

> -Daniel
> 
> >  		ret = dev->driver->firstopen(dev);
> >  		if (ret != 0)
> >  			return ret;
> > diff --git a/include/drm/drm_drv.h b/include/drm/drm_drv.h
> > index ca46a45a9cce..de5637494503 100644
> > --- a/include/drm/drm_drv.h
> > +++ b/include/drm/drm_drv.h
> > @@ -234,9 +234,6 @@ struct drm_driver {
> >  	 * kernel driver does not really own the hardware. Instead ownershipe is
> >  	 * handled with the help of userspace through an inheritedly racy dance
> >  	 * to set/unset the VT into raw mode.
> > -	 *
> > -	 * Legacy drivers initialize the hardware in the @firstopen callback,
> > -	 * which isn't even called for modern drivers.
> >  	 */
> >  	void (*lastclose) (struct drm_device *);
> >  
> > -- 
> > 2.21.0
> >