radeon: add prime import/export support

this adds radeon version of the prime import/export support.

Signed-off-by: Dave Airlie <airlied@redhat.com>
main
Dave Airlie 2012-06-12 17:31:12 +01:00
parent a9412fa9de
commit 3163cfe4db
3 changed files with 52 additions and 2 deletions

View File

@ -31,7 +31,7 @@ AM_CFLAGS = \
libdrm_radeon_la_LTLIBRARIES = libdrm_radeon.la libdrm_radeon_la_LTLIBRARIES = libdrm_radeon.la
libdrm_radeon_ladir = $(libdir) libdrm_radeon_ladir = $(libdir)
libdrm_radeon_la_LDFLAGS = -version-number 1:0:0 -no-undefined libdrm_radeon_la_LDFLAGS = -version-number 1:0:1 -no-undefined
libdrm_radeon_la_LIBADD = ../libdrm.la @PTHREADSTUBS_LIBS@ libdrm_radeon_la_LIBADD = ../libdrm.la @PTHREADSTUBS_LIBS@
libdrm_radeon_la_SOURCES = \ libdrm_radeon_la_SOURCES = \

View File

@ -45,7 +45,7 @@
#include "radeon_bo.h" #include "radeon_bo.h"
#include "radeon_bo_int.h" #include "radeon_bo_int.h"
#include "radeon_bo_gem.h" #include "radeon_bo_gem.h"
#include <fcntl.h>
struct radeon_bo_gem { struct radeon_bo_gem {
struct radeon_bo_int base; struct radeon_bo_int base;
uint32_t name; uint32_t name;
@ -349,3 +349,49 @@ int radeon_gem_set_domain(struct radeon_bo *bo, uint32_t read_domains, uint32_t
sizeof(args)); sizeof(args));
return r; return r;
} }
int radeon_gem_prime_share_bo(struct radeon_bo *bo, int *handle)
{
struct radeon_bo_gem *bo_gem = (struct radeon_bo_gem*)bo;
int ret;
ret = drmPrimeHandleToFD(bo_gem->base.bom->fd, bo->handle, DRM_CLOEXEC, handle);
return ret;
}
struct radeon_bo *radeon_gem_bo_open_prime(struct radeon_bo_manager *bom,
int fd_handle,
uint32_t size)
{
struct radeon_bo_gem *bo;
int r;
uint32_t handle;
bo = (struct radeon_bo_gem*)calloc(1, sizeof(struct radeon_bo_gem));
if (bo == NULL) {
return NULL;
}
bo->base.bom = bom;
bo->base.handle = 0;
bo->base.size = size;
bo->base.alignment = 0;
bo->base.domains = RADEON_GEM_DOMAIN_GTT;
bo->base.flags = 0;
bo->base.ptr = NULL;
atomic_set(&bo->reloc_in_cs, 0);
bo->map_count = 0;
r = drmPrimeFDToHandle(bom->fd, fd_handle, &handle);
if (r != 0) {
free(bo);
return NULL;
}
bo->base.handle = handle;
bo->name = handle;
radeon_bo_ref((struct radeon_bo *)bo);
return (struct radeon_bo *)bo;
}

View File

@ -41,4 +41,8 @@ uint32_t radeon_gem_name_bo(struct radeon_bo *bo);
void *radeon_gem_get_reloc_in_cs(struct radeon_bo *bo); void *radeon_gem_get_reloc_in_cs(struct radeon_bo *bo);
int radeon_gem_set_domain(struct radeon_bo *bo, uint32_t read_domains, uint32_t write_domain); int radeon_gem_set_domain(struct radeon_bo *bo, uint32_t read_domains, uint32_t write_domain);
int radeon_gem_get_kernel_name(struct radeon_bo *bo, uint32_t *name); int radeon_gem_get_kernel_name(struct radeon_bo *bo, uint32_t *name);
int radeon_gem_prime_share_bo(struct radeon_bo *bo, int *handle);
struct radeon_bo *radeon_gem_bo_open_prime(struct radeon_bo_manager *bom,
int fd_handle,
uint32_t size);
#endif #endif