[igt-dev] [PATCH i-g-t v4 1/3] lib/ioctl_wrapper: Add i915_get_param helper
Chris Wilson
chris at chris-wilson.co.uk
Tue Dec 4 16:40:19 UTC 2018
Quoting Lukasz Kalamarz (2018-12-04 16:25:24)
> getparam is used in few places across IGT, but no helper function
> is used to reduce code duplication.
>
> v2: Added doc part and changed return value in case of error
> v3: Renamed function to i915_get_param, created internal error
> checking function and helper function to check if given feature
> is enabled.
>
> Signed-off-by: Lukasz Kalamarz <lukasz.kalamarz at intel.com>
>
> Cc: Michal Winiarski <michal.winiarski at intel.com>
> Cc: Katarzyna Dec <katarzyna.dec at intel.com>
> Cc: Daniele Ceraolo Spurio <daniele.ceraolospurio at intel.com>
> Cc: Petri Latvala <Petri.latvala at intel.com>
> Cc: Eric Anholt <eric at anholt.net>
> Cc: Antonio Argenziano <antonio.argenziano at intel.com>
> Cc: Ankit K Nautiyal <ankit.k.nautiyal at intel.com>
> ---
> lib/ioctl_wrappers.c | 50 ++++++++++++++++++++++++++++++++++++++++++++
> lib/ioctl_wrappers.h | 2 ++
> 2 files changed, 52 insertions(+)
>
> diff --git a/lib/ioctl_wrappers.c b/lib/ioctl_wrappers.c
> index 9f255508..b48dad5b 100644
> --- a/lib/ioctl_wrappers.c
> +++ b/lib/ioctl_wrappers.c
> @@ -468,6 +468,56 @@ void gem_sync(int fd, uint32_t handle)
> errno = 0;
> }
>
> +static int
> +__i915_get_param(int fd, struct drm_i915_getparam *gp)
> +{
> + int err;
> +
> + err = 0;
> + if (igt_ioctl(fd, DRM_IOCTL_I915_GETPARAM, gp))
> + err = -errno;
> +
> + errno = 0;
> + return err;
> +}
> +
> +/**
> + * i915_get_param:
> + * @fd: open i915 drm file descriptor
> + * @param: drm parameter we want to read
> + *
> + * Helper function that execute GETPARAM ioctl for a given parameter.
> + *
> + * Return: Read value from GETPARAM
> + */
> +int i915_get_param(int fd, uint32_t param)
> +{
> + int value;
> + drm_i915_getparam_t gp = {
> + .param = param,
> + .value = &value
> + };
> +
> + igt_assert_eq(__i915_get_param(fd, &gp), 0);
> +
> + return value;
> +}
> +
> +/**
> + * i915_has_feature:
> + * @fd: open i915 drm file descriptor
> + * @param: drm parameter we want to read
> + *
> + * Helper function that check if given functionality is enabled.
> + * Check is done via getparam IOCTL.
> + *
> + * Return: Value whether feature is enabled or not
> + */
> +
> +bool i915_has_feature(int fd, uint32_t param)
> +{
> + return i915_get_param(fd, param) > 0;
Nope, this should return false not assert if the kernel doesn't
recognise said feature.
-Chris
More information about the igt-dev
mailing list