dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel Vetter <daniel@ffwll.ch>
To: "Kristian Høgsberg" <krh@bitplanet.net>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH] intel: Set bo size from lseek if kernel supports it
Date: Fri, 11 Oct 2013 01:10:15 +0200	[thread overview]
Message-ID: <20131010231015.GE8303@phenom.ffwll.local> (raw)
In-Reply-To: <1381442821-9033-1-git-send-email-krh@bitplanet.net>

On Thu, Oct 10, 2013 at 03:07:01PM -0700, Kristian Høgsberg wrote:
> The various create and open functions set the buffer size, but
> drm_intel_bo_gem_create_from_prime() is an exception.  In the 3.12 kernel
> we can now use lseek on the prime fd to determine the size of the bo.
> Use that and override the userprovided size.  If the kernel doesn't
> support this, we get an error and fall back to the user provided size.
> 
> Signed-off-by: Kristian Høgsberg <krh@bitplanet.net>

Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
> ---
>  intel/intel_bufmgr_gem.c | 12 +++++++++++-
>  1 file changed, 11 insertions(+), 1 deletion(-)
> 
> diff --git a/intel/intel_bufmgr_gem.c b/intel/intel_bufmgr_gem.c
> index f98f7a7..278f5c8 100644
> --- a/intel/intel_bufmgr_gem.c
> +++ b/intel/intel_bufmgr_gem.c
> @@ -2452,7 +2452,17 @@ drm_intel_bo_gem_create_from_prime(drm_intel_bufmgr *bufmgr, int prime_fd, int s
>  	if (!bo_gem)
>  		return NULL;
>  
> -	bo_gem->bo.size = size;
> +	/* Determine size of bo.  The fd-to-handle ioctl really should
> +	 * return the size, but it doesn't.  If we have kernel 3.12 or
> +	 * later, we can lseek on the prime fd to get the size.  Older
> +	 * kernels will just fail, in which case we fall back to the
> +	 * provided (estimated or guess size). */
> +	ret = lseek(prime_fd, 0, SEEK_END);
> +	if (ret != -1)
> +		bo_gem->bo.size = ret;
> +	else
> +		bo_gem->bo.size = size;
> +
>  	bo_gem->bo.handle = handle;
>  	bo_gem->bo.bufmgr = bufmgr;
>  
> -- 
> 1.8.3.1
> 
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/dri-devel

-- 
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch

      reply	other threads:[~2013-10-10 23:09 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-10 22:07 [PATCH] intel: Set bo size from lseek if kernel supports it Kristian Høgsberg
2013-10-10 23:10 ` Daniel Vetter [this message]

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=20131010231015.GE8303@phenom.ffwll.local \
    --to=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=krh@bitplanet.net \
    /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