[v3,1/2] drm: add drm_core_check_all_features() to check for a mask of features
diff mbox series

Message ID 20200122155030.29304-1-jani.nikula@intel.com
State New
Headers show
Series
  • [v3,1/2] drm: add drm_core_check_all_features() to check for a mask of features
Related show

Commit Message

Jani Nikula Jan. 22, 2020, 3:50 p.m. UTC
Add new drm_core_check_all_features() function to check for a mask of
features. All features in the mask are required.

Redefine existing drm_core_check_feature() in terms of this function,
using the drm_driver_feature enum for the parameter.

v3:
- add drm_core_check_all_features() (Thomas)

v2:
- fix kernel-doc (Ville)
- add an extra variable for clarity (Ville)

Cc: Ville Syrjälä <ville.syrjala@linux.intel.com>
Cc: Thomas Zimmermann <tzimmermann@suse.de>
Signed-off-by: Jani Nikula <jani.nikula@intel.com>
---
 include/drm/drm_drv.h | 24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)

Comments

Thomas Zimmermann Jan. 22, 2020, 4:11 p.m. UTC | #1
Hi

Am 22.01.20 um 16:50 schrieb Jani Nikula:
> Add new drm_core_check_all_features() function to check for a mask of
> features. All features in the mask are required.
> 
> Redefine existing drm_core_check_feature() in terms of this function,
> using the drm_driver_feature enum for the parameter.
> 
> v3:
> - add drm_core_check_all_features() (Thomas)

Oh! Thank you.

> 
> v2:
> - fix kernel-doc (Ville)
> - add an extra variable for clarity (Ville)
> 
> Cc: Ville Syrjälä <ville.syrjala@linux.intel.com>
> Cc: Thomas Zimmermann <tzimmermann@suse.de>
> Signed-off-by: Jani Nikula <jani.nikula@intel.com>

Reviewed-by: Thomas Zimmermann <tzimmermann@suse.de>

> ---
>  include/drm/drm_drv.h | 24 ++++++++++++++++++++++--
>  1 file changed, 22 insertions(+), 2 deletions(-)
> 
> diff --git a/include/drm/drm_drv.h b/include/drm/drm_drv.h
> index cf13470810a5..23b636691fb4 100644
> --- a/include/drm/drm_drv.h
> +++ b/include/drm/drm_drv.h
> @@ -823,6 +823,25 @@ static inline bool drm_dev_is_unplugged(struct drm_device *dev)
>  	return true;
>  }
>  
> +/**
> + * drm_core_check_all_features - check driver feature flags mask
> + * @dev: DRM device to check
> + * @features: feature flag(s) mask
> + *
> + * This checks @dev for driver features, see &drm_driver.driver_features,
> + * &drm_device.driver_features, and the various &enum drm_driver_feature flags.
> + *
> + * Returns true if all features in the @features mask are supported, false
> + * otherwise.
> + */
> +static inline bool drm_core_check_all_features(const struct drm_device *dev,
> +					       u32 features)
> +{
> +	u32 supported = dev->driver->driver_features & dev->driver_features;
> +
> +	return features && (supported & features) == features;
> +}
> +
>  /**
>   * drm_core_check_feature - check driver feature flags
>   * @dev: DRM device to check
> @@ -833,9 +852,10 @@ static inline bool drm_dev_is_unplugged(struct drm_device *dev)
>   *
>   * Returns true if the @feature is supported, false otherwise.
>   */
> -static inline bool drm_core_check_feature(const struct drm_device *dev, u32 feature)
> +static inline bool drm_core_check_feature(const struct drm_device *dev,
> +					  enum drm_driver_feature feature)
>  {
> -	return dev->driver->driver_features & dev->driver_features & feature;
> +	return drm_core_check_all_features(dev, feature);
>  }
>  
>  /**
>

Patch
diff mbox series

diff --git a/include/drm/drm_drv.h b/include/drm/drm_drv.h
index cf13470810a5..23b636691fb4 100644
--- a/include/drm/drm_drv.h
+++ b/include/drm/drm_drv.h
@@ -823,6 +823,25 @@  static inline bool drm_dev_is_unplugged(struct drm_device *dev)
 	return true;
 }
 
+/**
+ * drm_core_check_all_features - check driver feature flags mask
+ * @dev: DRM device to check
+ * @features: feature flag(s) mask
+ *
+ * This checks @dev for driver features, see &drm_driver.driver_features,
+ * &drm_device.driver_features, and the various &enum drm_driver_feature flags.
+ *
+ * Returns true if all features in the @features mask are supported, false
+ * otherwise.
+ */
+static inline bool drm_core_check_all_features(const struct drm_device *dev,
+					       u32 features)
+{
+	u32 supported = dev->driver->driver_features & dev->driver_features;
+
+	return features && (supported & features) == features;
+}
+
 /**
  * drm_core_check_feature - check driver feature flags
  * @dev: DRM device to check
@@ -833,9 +852,10 @@  static inline bool drm_dev_is_unplugged(struct drm_device *dev)
  *
  * Returns true if the @feature is supported, false otherwise.
  */
-static inline bool drm_core_check_feature(const struct drm_device *dev, u32 feature)
+static inline bool drm_core_check_feature(const struct drm_device *dev,
+					  enum drm_driver_feature feature)
 {
-	return dev->driver->driver_features & dev->driver_features & feature;
+	return drm_core_check_all_features(dev, feature);
 }
 
 /**