Skip to content

Commit 18ace11

Browse files
committed
drm: Introduce per-device driver_features
We wish to control certain driver_features flags on a per-device basis while still sharing a single drm_driver instance across all the devices. To that end introduce device.driver_features. By default it will be set to ~0 to not impose any limits beyond driver.driver_features. Drivers can then clear specific flags in the per-device bitmask to limit the capabilities of the device. An alternative approach would be to copy the driver_features from the driver into the device in drm_dev_init(), however that would require verifying that no driver is currently changing driver.driver_features after drm_dev_init(). Hence the ~0 apporach was easier. Ideally we'd also make drm_driver const but there is plenty of code left that wants to mutate it (eg. various vfunc assignments). We'll need to fix all that up before we can make it const. And while at it fix up the type of the feature flag passed to drm_core_check_feature(). v2: Streamline the && vs. & (Chris) s/int/u32/ in drm_core_check_feature() args Cc: Chris Wilson <chris@chris-wilson.co.uk> Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com> Link: https://patchwork.freedesktop.org/patch/msgid/20180913131622.17690-1-ville.syrjala@linux.intel.com Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk> Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch> Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>
1 parent 169cc4c commit 18ace11

3 files changed

Lines changed: 17 additions & 4 deletions

File tree

‎drivers/gpu/drm/drm_drv.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,9 @@ int drm_dev_init(struct drm_device *dev,
506506
dev->dev = parent;
507507
dev->driver = driver;
508508

509+
/* no per-device feature limits by default */
510+
dev->driver_features = ~0u;
511+
509512
INIT_LIST_HEAD(&dev->filelist);
510513
INIT_LIST_HEAD(&dev->filelist_internal);
511514
INIT_LIST_HEAD(&dev->clientlist);

‎include/drm/drm_device.h‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@ struct drm_device {
4545
/* currently active master for this device. Protected by master_mutex */
4646
struct drm_master *master;
4747

48+
/**
49+
* @driver_features: per-device driver features
50+
*
51+
* Drivers can clear specific flags here to disallow
52+
* certain features on a per-device basis while still
53+
* sharing a single &struct drm_driver instance across
54+
* all devices.
55+
*/
56+
u32 driver_features;
57+
4858
/**
4959
* @unplugged:
5060
*

‎include/drm/drm_drv.h‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -653,14 +653,14 @@ static inline bool drm_dev_is_unplugged(struct drm_device *dev)
653653
* @dev: DRM device to check
654654
* @feature: feature flag
655655
*
656-
* This checks @dev for driver features, see &drm_driver.driver_features and the
657-
* various DRIVER_\* flags.
656+
* This checks @dev for driver features, see &drm_driver.driver_features,
657+
* &drm_device.driver_features, and the various DRIVER_\* flags.
658658
*
659659
* Returns true if the @feature is supported, false otherwise.
660660
*/
661-
static inline bool drm_core_check_feature(struct drm_device *dev, int feature)
661+
static inline bool drm_core_check_feature(struct drm_device *dev, u32 feature)
662662
{
663-
return dev->driver->driver_features & feature;
663+
return dev->driver->driver_features & dev->driver_features & feature;
664664
}
665665

666666
/**

0 commit comments

Comments
 (0)