[v2] drm: Return -ENOTSUPP when called for KMS cap with a non-KMS driver
diff mbox

Message ID 20161201073731.5716-1-michel@daenzer.net
State New
Headers show

Commit Message

Michel Dänzer Dec. 1, 2016, 7:37 a.m. UTC
From: Michel Dänzer <michel.daenzer@amd.com>

This is an attempt to make the previous fix a bit more robust going
forward.

v2:
* Only allow DRM_CAP_TIMESTAMP_MONOTONIC with UMS drivers (Daniel
  Vetter, Alex Deucher)
* Different logic to keep DRM_CAP_TIMESTAMP_MONOTONIC separate from
  the other caps (Daniel Vetter)

Signed-off-by: Michel Dänzer <michel.daenzer@amd.com>
---
 drivers/gpu/drm/drm_ioctl.c | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)

Comments

Alex Deucher Dec. 1, 2016, 2:46 p.m. UTC | #1
On Thu, Dec 1, 2016 at 2:37 AM, Michel Dänzer <michel@daenzer.net> wrote:
> From: Michel Dänzer <michel.daenzer@amd.com>
>
> This is an attempt to make the previous fix a bit more robust going
> forward.
>
> v2:
> * Only allow DRM_CAP_TIMESTAMP_MONOTONIC with UMS drivers (Daniel
>   Vetter, Alex Deucher)
> * Different logic to keep DRM_CAP_TIMESTAMP_MONOTONIC separate from
>   the other caps (Daniel Vetter)
>
> Signed-off-by: Michel Dänzer <michel.daenzer@amd.com>

Reviewed-by: Alex Deucher <alexander.deucher@amd.com>

> ---
>  drivers/gpu/drm/drm_ioctl.c | 24 +++++++++++++++---------
>  1 file changed, 15 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
> index 71c3473..706d5aa 100644
> --- a/drivers/gpu/drm/drm_ioctl.c
> +++ b/drivers/gpu/drm/drm_ioctl.c
> @@ -229,6 +229,17 @@ static int drm_getcap(struct drm_device *dev, void *data, struct drm_file *file_
>         struct drm_crtc *crtc;
>
>         req->value = 0;
> +
> +       /* Only one cap makes sense with a UMS driver: */
> +       if (req->capability == DRM_CAP_TIMESTAMP_MONOTONIC) {
> +               req->value = drm_timestamp_monotonic;
> +               return 0;
> +       }
> +
> +       /* Other caps only work with KMS drivers */
> +       if (!drm_core_check_feature(dev, DRIVER_MODESET))
> +               return -ENOTSUPP;
> +
>         switch (req->capability) {
>         case DRM_CAP_DUMB_BUFFER:
>                 if (dev->driver->dumb_create)
> @@ -247,19 +258,14 @@ static int drm_getcap(struct drm_device *dev, void *data, struct drm_file *file_
>                 req->value |= dev->driver->prime_fd_to_handle ? DRM_PRIME_CAP_IMPORT : 0;
>                 req->value |= dev->driver->prime_handle_to_fd ? DRM_PRIME_CAP_EXPORT : 0;
>                 break;
> -       case DRM_CAP_TIMESTAMP_MONOTONIC:
> -               req->value = drm_timestamp_monotonic;
> -               break;
>         case DRM_CAP_ASYNC_PAGE_FLIP:
>                 req->value = dev->mode_config.async_page_flip;
>                 break;
>         case DRM_CAP_PAGE_FLIP_TARGET:
> -               if (drm_core_check_feature(dev, DRIVER_MODESET)) {
> -                       req->value = 1;
> -                       drm_for_each_crtc(crtc, dev) {
> -                               if (!crtc->funcs->page_flip_target)
> -                                       req->value = 0;
> -                       }
> +               req->value = 1;
> +               drm_for_each_crtc(crtc, dev) {
> +                       if (!crtc->funcs->page_flip_target)
> +                               req->value = 0;
>                 }
>                 break;
>         case DRM_CAP_CURSOR_WIDTH:
> --
> 2.10.2
>
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel
Sean Paul Dec. 1, 2016, 3:21 p.m. UTC | #2
On Thu, Dec 1, 2016 at 2:37 AM, Michel Dänzer <michel@daenzer.net> wrote:
> From: Michel Dänzer <michel.daenzer@amd.com>
>
> This is an attempt to make the previous fix a bit more robust going
> forward.

It takes a bit of work to locate the "previous fix" now that it's gone
through drm-misc-fixes. Can you update with a proper reference to the
first patch?

Additionally, it's probably easiest if we hold off on merging this
until your first patch finds its way into drm-misc-next.

Thanks,

Sean


>
> v2:
> * Only allow DRM_CAP_TIMESTAMP_MONOTONIC with UMS drivers (Daniel
>   Vetter, Alex Deucher)
> * Different logic to keep DRM_CAP_TIMESTAMP_MONOTONIC separate from
>   the other caps (Daniel Vetter)
>
> Signed-off-by: Michel Dänzer <michel.daenzer@amd.com>
> ---
>  drivers/gpu/drm/drm_ioctl.c | 24 +++++++++++++++---------
>  1 file changed, 15 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
> index 71c3473..706d5aa 100644
> --- a/drivers/gpu/drm/drm_ioctl.c
> +++ b/drivers/gpu/drm/drm_ioctl.c
> @@ -229,6 +229,17 @@ static int drm_getcap(struct drm_device *dev, void *data, struct drm_file *file_
>         struct drm_crtc *crtc;
>
>         req->value = 0;
> +
> +       /* Only one cap makes sense with a UMS driver: */
> +       if (req->capability == DRM_CAP_TIMESTAMP_MONOTONIC) {
> +               req->value = drm_timestamp_monotonic;
> +               return 0;
> +       }
> +
> +       /* Other caps only work with KMS drivers */
> +       if (!drm_core_check_feature(dev, DRIVER_MODESET))
> +               return -ENOTSUPP;
> +
>         switch (req->capability) {
>         case DRM_CAP_DUMB_BUFFER:
>                 if (dev->driver->dumb_create)
> @@ -247,19 +258,14 @@ static int drm_getcap(struct drm_device *dev, void *data, struct drm_file *file_
>                 req->value |= dev->driver->prime_fd_to_handle ? DRM_PRIME_CAP_IMPORT : 0;
>                 req->value |= dev->driver->prime_handle_to_fd ? DRM_PRIME_CAP_EXPORT : 0;
>                 break;
> -       case DRM_CAP_TIMESTAMP_MONOTONIC:
> -               req->value = drm_timestamp_monotonic;
> -               break;
>         case DRM_CAP_ASYNC_PAGE_FLIP:
>                 req->value = dev->mode_config.async_page_flip;
>                 break;
>         case DRM_CAP_PAGE_FLIP_TARGET:
> -               if (drm_core_check_feature(dev, DRIVER_MODESET)) {
> -                       req->value = 1;
> -                       drm_for_each_crtc(crtc, dev) {
> -                               if (!crtc->funcs->page_flip_target)
> -                                       req->value = 0;
> -                       }
> +               req->value = 1;
> +               drm_for_each_crtc(crtc, dev) {
> +                       if (!crtc->funcs->page_flip_target)
> +                               req->value = 0;
>                 }
>                 break;
>         case DRM_CAP_CURSOR_WIDTH:
> --
> 2.10.2
>
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel
Daniel Vetter Dec. 1, 2016, 3:23 p.m. UTC | #3
On Thu, Dec 01, 2016 at 10:21:28AM -0500, Sean Paul wrote:
> On Thu, Dec 1, 2016 at 2:37 AM, Michel Dänzer <michel@daenzer.net> wrote:
> > From: Michel Dänzer <michel.daenzer@amd.com>
> >
> > This is an attempt to make the previous fix a bit more robust going
> > forward.
> 
> It takes a bit of work to locate the "previous fix" now that it's gone
> through drm-misc-fixes. Can you update with a proper reference to the
> first patch?
> 
> Additionally, it's probably easiest if we hold off on merging this
> until your first patch finds its way into drm-misc-next.

I'll bother Dave for a backmerge as soon as 4.9/4.9-rc8 is out, and then
we can apply Michel's cleanup on top.
-Daniel
Daniel Vetter Dec. 5, 2016, 8:05 a.m. UTC | #4
On Thu, Dec 01, 2016 at 09:46:06AM -0500, Alex Deucher wrote:
> On Thu, Dec 1, 2016 at 2:37 AM, Michel Dänzer <michel@daenzer.net> wrote:
> > From: Michel Dänzer <michel.daenzer@amd.com>
> >
> > This is an attempt to make the previous fix a bit more robust going
> > forward.
> >
> > v2:
> > * Only allow DRM_CAP_TIMESTAMP_MONOTONIC with UMS drivers (Daniel
> >   Vetter, Alex Deucher)
> > * Different logic to keep DRM_CAP_TIMESTAMP_MONOTONIC separate from
> >   the other caps (Daniel Vetter)
> >
> > Signed-off-by: Michel Dänzer <michel.daenzer@amd.com>
> 
> Reviewed-by: Alex Deucher <alexander.deucher@amd.com>

Applied to drm-misc, thanks.
-Daniel

> 
> > ---
> >  drivers/gpu/drm/drm_ioctl.c | 24 +++++++++++++++---------
> >  1 file changed, 15 insertions(+), 9 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
> > index 71c3473..706d5aa 100644
> > --- a/drivers/gpu/drm/drm_ioctl.c
> > +++ b/drivers/gpu/drm/drm_ioctl.c
> > @@ -229,6 +229,17 @@ static int drm_getcap(struct drm_device *dev, void *data, struct drm_file *file_
> >         struct drm_crtc *crtc;
> >
> >         req->value = 0;
> > +
> > +       /* Only one cap makes sense with a UMS driver: */
> > +       if (req->capability == DRM_CAP_TIMESTAMP_MONOTONIC) {
> > +               req->value = drm_timestamp_monotonic;
> > +               return 0;
> > +       }
> > +
> > +       /* Other caps only work with KMS drivers */
> > +       if (!drm_core_check_feature(dev, DRIVER_MODESET))
> > +               return -ENOTSUPP;
> > +
> >         switch (req->capability) {
> >         case DRM_CAP_DUMB_BUFFER:
> >                 if (dev->driver->dumb_create)
> > @@ -247,19 +258,14 @@ static int drm_getcap(struct drm_device *dev, void *data, struct drm_file *file_
> >                 req->value |= dev->driver->prime_fd_to_handle ? DRM_PRIME_CAP_IMPORT : 0;
> >                 req->value |= dev->driver->prime_handle_to_fd ? DRM_PRIME_CAP_EXPORT : 0;
> >                 break;
> > -       case DRM_CAP_TIMESTAMP_MONOTONIC:
> > -               req->value = drm_timestamp_monotonic;
> > -               break;
> >         case DRM_CAP_ASYNC_PAGE_FLIP:
> >                 req->value = dev->mode_config.async_page_flip;
> >                 break;
> >         case DRM_CAP_PAGE_FLIP_TARGET:
> > -               if (drm_core_check_feature(dev, DRIVER_MODESET)) {
> > -                       req->value = 1;
> > -                       drm_for_each_crtc(crtc, dev) {
> > -                               if (!crtc->funcs->page_flip_target)
> > -                                       req->value = 0;
> > -                       }
> > +               req->value = 1;
> > +               drm_for_each_crtc(crtc, dev) {
> > +                       if (!crtc->funcs->page_flip_target)
> > +                               req->value = 0;
> >                 }
> >                 break;
> >         case DRM_CAP_CURSOR_WIDTH:
> > --
> > 2.10.2
> >
> > _______________________________________________
> > dri-devel mailing list
> > dri-devel@lists.freedesktop.org
> > https://lists.freedesktop.org/mailman/listinfo/dri-devel

Patch
diff mbox

diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
index 71c3473..706d5aa 100644
--- a/drivers/gpu/drm/drm_ioctl.c
+++ b/drivers/gpu/drm/drm_ioctl.c
@@ -229,6 +229,17 @@  static int drm_getcap(struct drm_device *dev, void *data, struct drm_file *file_
 	struct drm_crtc *crtc;
 
 	req->value = 0;
+
+	/* Only one cap makes sense with a UMS driver: */
+	if (req->capability == DRM_CAP_TIMESTAMP_MONOTONIC) {
+		req->value = drm_timestamp_monotonic;
+		return 0;
+	}
+
+	/* Other caps only work with KMS drivers */
+	if (!drm_core_check_feature(dev, DRIVER_MODESET))
+		return -ENOTSUPP;
+
 	switch (req->capability) {
 	case DRM_CAP_DUMB_BUFFER:
 		if (dev->driver->dumb_create)
@@ -247,19 +258,14 @@  static int drm_getcap(struct drm_device *dev, void *data, struct drm_file *file_
 		req->value |= dev->driver->prime_fd_to_handle ? DRM_PRIME_CAP_IMPORT : 0;
 		req->value |= dev->driver->prime_handle_to_fd ? DRM_PRIME_CAP_EXPORT : 0;
 		break;
-	case DRM_CAP_TIMESTAMP_MONOTONIC:
-		req->value = drm_timestamp_monotonic;
-		break;
 	case DRM_CAP_ASYNC_PAGE_FLIP:
 		req->value = dev->mode_config.async_page_flip;
 		break;
 	case DRM_CAP_PAGE_FLIP_TARGET:
-		if (drm_core_check_feature(dev, DRIVER_MODESET)) {
-			req->value = 1;
-			drm_for_each_crtc(crtc, dev) {
-				if (!crtc->funcs->page_flip_target)
-					req->value = 0;
-			}
+		req->value = 1;
+		drm_for_each_crtc(crtc, dev) {
+			if (!crtc->funcs->page_flip_target)
+				req->value = 0;
 		}
 		break;
 	case DRM_CAP_CURSOR_WIDTH: