#include <linux/stddef.h>
#include <errno.h>
#include <sys/mman.h>
+#include <fcntl.h>
+#include <unistd.h>
#include <xf86drm.h>
uint32_t handle;
uint32_t name; /* flink global handle (DRI2 name) */
uint64_t offset; /* offset to mmap() */
+ int fd; /* dmabuf handle */
};
struct omap_device * omap_device_new(int fd)
static struct omap_bo * omap_bo_new_impl(struct omap_device *dev,
union omap_gem_size size, uint32_t flags)
{
- struct omap_bo *bo;
+ struct omap_bo *bo = NULL;
struct drm_omap_gem_new req = {
.size = size,
.flags = flags,
munmap(bo->map, bo->size);
}
+ if (bo->fd) {
+ close(bo->fd);
+ }
+
if (bo->handle) {
struct drm_gem_close req = {
.handle = bo->handle,
return bo->handle;
}
+/* caller owns the dmabuf fd that is returned and is responsible
+ * to close() it when done
+ */
+int omap_bo_dmabuf(struct omap_bo *bo)
+{
+ if (!bo->fd) {
+ struct drm_prime_handle req = {
+ .handle = bo->handle,
+ .flags = DRM_CLOEXEC,
+ };
+ int ret;
+
+ ret = drmIoctl(bo->dev->fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &req);
+ if (ret) {
+ return ret;
+ }
+
+ bo->fd = req.fd;
+ }
+ return dup(bo->fd);
+}
+
uint32_t omap_bo_size(struct omap_bo *bo)
{
if (!bo->size) {