public inbox for igt-dev@lists.freedesktop.org
 help / color / mirror / Atom feed
From: Daniele Ceraolo Spurio <daniele.ceraolospurio@intel.com>
To: Lukasz Kalamarz <lukasz.kalamarz@intel.com>,
	igt-dev@lists.freedesktop.org
Cc: Petri Latvala <Petri.latvala@intel.com>
Subject: Re: [igt-dev] [PATCH i-g-t v4 1/3] lib/ioctl_wrapper: Add i915_get_param helper
Date: Tue, 4 Dec 2018 16:39:06 -0800	[thread overview]
Message-ID: <1ffed44f-fd2b-868b-6593-198c04835af6@intel.com> (raw)
In-Reply-To: <20181204162526.26687-1-lukasz.kalamarz@intel.com>



On 04/12/2018 08:25, Lukasz Kalamarz wrote:
> 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@intel.com>
> 
> Cc: Michal Winiarski <michal.winiarski@intel.com>
> Cc: Katarzyna Dec <katarzyna.dec@intel.com>
> Cc: Daniele Ceraolo Spurio <daniele.ceraolospurio@intel.com>
> Cc: Petri Latvala <Petri.latvala@intel.com>
> Cc: Eric Anholt <eric@anholt.net>
> Cc: Antonio Argenziano <antonio.argenziano@intel.com>
> Cc: Ankit K Nautiyal <ankit.k.nautiyal@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)

This is only called in 1 place. Is it really worth having a separate 
fuction?

> +{
> +	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);

This assert breaks support for running on older kernels that don't have 
the param flag defined. Most of the current code assumes a default value 
if the flag is not defined (usually feature missing or version 0), but 
with this assert here we'd fail the test instead.
A good example is I915_PARAM_MMAP_GTT_COHERENT, which was only added 
recently and for which the test assumes a default of "true" if the flag 
is unsupported by the kernel.

> +
> +	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)

Just realized that there is already an has_param() wrapper that does 
more or less the same thing, so we can reuse that and/or adapt it to use 
i915_get_param.

Daniele

> +{
> +	return i915_get_param(fd, param) > 0;
> +}
>   
>   bool gem_create__has_stolen_support(int fd)
>   {
> diff --git a/lib/ioctl_wrappers.h b/lib/ioctl_wrappers.h
> index b22b36b0..c314a070 100644
> --- a/lib/ioctl_wrappers.h
> +++ b/lib/ioctl_wrappers.h
> @@ -74,6 +74,8 @@ int __gem_set_domain(int fd, uint32_t handle, uint32_t read, uint32_t write);
>   void gem_set_domain(int fd, uint32_t handle, uint32_t read, uint32_t write);
>   int gem_wait(int fd, uint32_t handle, int64_t *timeout_ns);
>   void gem_sync(int fd, uint32_t handle);
> +int i915_get_param(int fd, uint32_t param);
> +bool i915_has_feature(int fd, uint32_t param);
>   bool gem_create__has_stolen_support(int fd);
>   uint32_t __gem_create_stolen(int fd, uint64_t size);
>   uint32_t gem_create_stolen(int fd, uint64_t size);
> 
_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

  parent reply	other threads:[~2018-12-05  0:39 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-04 16:25 [igt-dev] [PATCH i-g-t v4 1/3] lib/ioctl_wrapper: Add i915_get_param helper Lukasz Kalamarz
2018-12-04 16:25 ` [igt-dev] [PATCH i-g-t v4 2/3] tests: Use i915_get_param where applicable Lukasz Kalamarz
2018-12-04 16:25 ` [igt-dev] [PATCH i-g-t v4 3/3] lib: Use i915_get_param where it is applicable Lukasz Kalamarz
2018-12-04 16:41   ` Chris Wilson
2018-12-04 16:39 ` [igt-dev] [PATCH i-g-t v4 1/3] lib/ioctl_wrapper: Add i915_get_param helper Chris Wilson
2018-12-04 16:40 ` Chris Wilson
2018-12-04 17:12 ` [igt-dev] ✓ Fi.CI.BAT: success for series starting with [i-g-t,v4,1/3] " Patchwork
2018-12-05  0:39 ` Daniele Ceraolo Spurio [this message]
2018-12-05  2:24 ` [igt-dev] ✗ Fi.CI.IGT: failure " Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1ffed44f-fd2b-868b-6593-198c04835af6@intel.com \
    --to=daniele.ceraolospurio@intel.com \
    --cc=Petri.latvala@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=lukasz.kalamarz@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox