Message ID | 1342311766-30930-1-git-send-email-airlied@gmail.com (mailing list archive) |
---|---|
State | Not Applicable |
Headers | show |
On Sun, 15 Jul 2012 10:22:46 +1000, Dave Airlie <airlied@gmail.com> wrote: > This adds interfaces for the X driver to use to create a > prime handle from a buffer, and create a bo from a handle. > > Signed-off-by: Dave Airlie <airlied@redhat.com> > --- > intel/intel_bufmgr.h | 4 ++++ > intel/intel_bufmgr_gem.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 50 insertions(+) > > diff --git a/intel/intel_bufmgr.h b/intel/intel_bufmgr.h > index 9b3a483..bf9ad5c 100644 > --- a/intel/intel_bufmgr.h > +++ b/intel/intel_bufmgr.h > @@ -192,6 +192,10 @@ void drm_intel_gem_context_destroy(drm_intel_context *ctx); > int drm_intel_gem_bo_context_exec(drm_intel_bo *bo, drm_intel_context *ctx, > int used, unsigned int flags); > > +int drm_intel_bufmgr_gem_set_bo_prime(drm_intel_bo *bo, int *prime_fd); > +drm_intel_bo *drm_intel_bufmgr_gem_get_bo_prime(drm_intel_bufmgr *bufmgr, > + int prime_fd, int size); I think drm_intel_bo_gem_create_for_prime(drm_intel_bufmgr *, int prime_fd, int size); drm_intel_bo_gem_export_to_prime(drm_intel_bo *, int *prime_fd); are more consistent names (with an alias for drm_intel_gem_bo_flink to drm_intel_bo_gem_export_to_name). Or possibly from_prime to be more in keeping with from_name, except the 'from' has the semantics of taking a copy and 'for' has the semantics of wrapping/proxying. At least in comparable API. However we are probably stuck with the existing semantics derived from drm_intel_bo_gem_create_from_name(). -Chris
diff --git a/intel/intel_bufmgr.h b/intel/intel_bufmgr.h index 9b3a483..bf9ad5c 100644 --- a/intel/intel_bufmgr.h +++ b/intel/intel_bufmgr.h @@ -192,6 +192,10 @@ void drm_intel_gem_context_destroy(drm_intel_context *ctx); int drm_intel_gem_bo_context_exec(drm_intel_bo *bo, drm_intel_context *ctx, int used, unsigned int flags); +int drm_intel_bufmgr_gem_set_bo_prime(drm_intel_bo *bo, int *prime_fd); +drm_intel_bo *drm_intel_bufmgr_gem_get_bo_prime(drm_intel_bufmgr *bufmgr, + int prime_fd, int size); + /* drm_intel_bufmgr_fake.c */ drm_intel_bufmgr *drm_intel_bufmgr_fake_init(int fd, unsigned long low_offset, diff --git a/intel/intel_bufmgr_gem.c b/intel/intel_bufmgr_gem.c index 12a3197..dfba4e4 100644 --- a/intel/intel_bufmgr_gem.c +++ b/intel/intel_bufmgr_gem.c @@ -2413,6 +2413,52 @@ drm_intel_gem_bo_get_tiling(drm_intel_bo *bo, uint32_t * tiling_mode, return 0; } +drm_intel_bo * +drm_intel_bufmgr_gem_get_bo_prime(drm_intel_bufmgr *bufmgr, int prime_fd, int size) +{ + drm_intel_bufmgr_gem *bufmgr_gem = (drm_intel_bufmgr_gem *) bufmgr; + int ret; + uint32_t handle; + drm_intel_bo_gem *bo_gem; + ret = drmPrimeFDToHandle(bufmgr_gem->fd, prime_fd, &handle); + if (ret) { + fprintf(stderr,"ret is %d %d\n", ret, errno); + return NULL; + } + + bo_gem = calloc(1, sizeof(*bo_gem)); + if (!bo_gem) + return NULL; + + bo_gem->bo.size = size; + bo_gem->name = "prime"; + atomic_set(&bo_gem->refcount, 1); + bo_gem->validate_index = -1; + bo_gem->reloc_tree_fences = 0; + bo_gem->used_as_reloc_target = false; + bo_gem->has_error = false; + bo_gem->reusable = false; + + bo_gem->bo.handle = handle; + bo_gem->bo.bufmgr = bufmgr; + + DRMINITLISTHEAD(&bo_gem->name_list); + DRMINITLISTHEAD(&bo_gem->vma_list); + + bo_gem->gem_handle = handle; + + return &bo_gem->bo; +} + +int +drm_intel_bufmgr_gem_set_bo_prime(drm_intel_bo *bo, int *prime_fd) +{ + drm_intel_bufmgr_gem *bufmgr_gem = (drm_intel_bufmgr_gem *) bo->bufmgr; + drm_intel_bo_gem *bo_gem = (drm_intel_bo_gem *) bo; + + return drmPrimeHandleToFD(bufmgr_gem->fd, bo_gem->gem_handle, DRM_CLOEXEC, prime_fd); +} + static int drm_intel_gem_bo_flink(drm_intel_bo *bo, uint32_t * name) {
This adds interfaces for the X driver to use to create a prime handle from a buffer, and create a bo from a handle. Signed-off-by: Dave Airlie <airlied@redhat.com> --- intel/intel_bufmgr.h | 4 ++++ intel/intel_bufmgr_gem.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+)