From 25c093c86964a0cd317daf437445e5de65916e13 Mon Sep 17 00:00:00 2001 From: Russell King Date: Sun, 21 Oct 2012 16:28:28 +0100 Subject: Initial checkin Signed-off-by: Russell King --- .gitignore | 14 ++ Makefile.am | 17 +++ configure.ac | 34 +++++ debian/changelog | 5 + debian/compat | 1 + debian/control | 60 +++++++++ debian/libdrm-dove-dev.install | 5 + debian/libdrm-dove1.install | 1 + debian/libdrm-dove1.postinst.debhelper | 5 + debian/libdrm-dove1.postrm.debhelper | 5 + debian/rules | 23 ++++ dove_bufmgr.c | 228 +++++++++++++++++++++++++++++++++ dove_bufmgr.h | 31 +++++ dove_ioctl.h | 138 ++++++++++++++++++++ libdrm_dove.pc.in | 11 ++ 15 files changed, 578 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile.am create mode 100644 configure.ac create mode 100644 debian/changelog create mode 100644 debian/compat create mode 100644 debian/control create mode 100644 debian/libdrm-dove-dev.install create mode 100644 debian/libdrm-dove1.install create mode 100644 debian/libdrm-dove1.postinst.debhelper create mode 100644 debian/libdrm-dove1.postrm.debhelper create mode 100755 debian/rules create mode 100644 dove_bufmgr.c create mode 100644 dove_bufmgr.h create mode 100644 dove_ioctl.h create mode 100644 libdrm_dove.pc.in diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0dbcc56 --- /dev/null +++ b/.gitignore @@ -0,0 +1,14 @@ +Makefile.in +aclocal.m4 +autom4te.cache/ +build-aux/ +build/ +configure +debian/files +debian/*.log +debian/*.substvars +debian/tmp/ +debian/libdrm-dove-dev/ +debian/libdrm-dove1-dbg/ +debian/libdrm-dove1/ +m4/ diff --git a/Makefile.am b/Makefile.am new file mode 100644 index 0000000..b628087 --- /dev/null +++ b/Makefile.am @@ -0,0 +1,17 @@ +ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS} + +AM_CFLAGS = $(WARN_CFLAGS) @LIBDRM_CFLAGS@ + +libdrm_dove_la_LTLIBRARIES = libdrm_dove.la +libdrm_dove_ladir = $(libdir) +libdrm_dove_la_LDFLAGS = -version-number 1:0:0 -no-undefined +libdrm_dove_la_LIBADD = @LIBDRM_LIBS@ + +libdrm_dove_la_SOURCES = \ + dove_bufmgr.c + +libdrm_doveincludedir = ${includedir}/libdrm +libdrm_doveinclude_HEADERS = dove_bufmgr.h + +pkgconfigdir = @pkgconfigdir@ +pkgconfig_DATA = libdrm_dove.pc diff --git a/configure.ac b/configure.ac new file mode 100644 index 0000000..8553fc1 --- /dev/null +++ b/configure.ac @@ -0,0 +1,34 @@ +AC_PREREQ([2.63]) +AC_INIT([libdrm_dove], [1.0.0], [], [libdrm_dove]) + +AC_CONFIG_SRCDIR([Makefile.am]) +AC_CONFIG_MACRO_DIR([m4]) +AC_CONFIG_AUX_DIR([build-aux]) + +AM_INIT_AUTOMAKE([1.10 foreign dist-bzip2]) +AM_MAINTAINER_MODE([enable]) + +# Enable quiet compiles on automake 1.11. +m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) + +# Check for programs +AC_PROG_CC + +AC_USE_SYSTEM_EXTENSIONS + +# Initialize libtool +LT_PREREQ([2.2]) +LT_INIT([disable-static]) + +PKG_CHECK_MODULES(LIBDRM, libdrm) +AC_SUBST(LIBDRM_CFLAGS) +AC_SUBST(LIBDRM_LIBS) + +pkgconfigdir=${libdir}/pkgconfig +AC_SUBST(pkgconfigdir) + +AC_CONFIG_FILES([ + Makefile + libdrm_dove.pc +]) +AC_OUTPUT diff --git a/debian/changelog b/debian/changelog new file mode 100644 index 0000000..70a37d8 --- /dev/null +++ b/debian/changelog @@ -0,0 +1,5 @@ +libdrm-dove (1.0.0-1) unstable; urgency=low + + * Initial release. + + -- Russell King Tue, 9 Oct 2012 00:36:54 +0100 diff --git a/debian/compat b/debian/compat new file mode 100644 index 0000000..ec63514 --- /dev/null +++ b/debian/compat @@ -0,0 +1 @@ +9 diff --git a/debian/control b/debian/control new file mode 100644 index 0000000..6799de2 --- /dev/null +++ b/debian/control @@ -0,0 +1,60 @@ +Source: libdrm-dove +Priority: optional +Maintainer: Russell King +Build-Depends: + debhelper (>= 8.1.2ubuntu2), + dh-autoreconf, + pkg-config, + libdrm-dev, +Standards-Version: 3.9.2 +Section: libs + +Package: libdrm-dove-dev +Section: libdevel +Architecture: any +Depends: + libdrm-dove1 (= ${binary:Version}), + ${misc:Depends}, +Description: Userspace interface to kernel DRM services -- development files + This library implements the userspace interface to the kernel DRM + services. DRM stands for "Direct Rendering Manager", which is the + kernelspace portion of the "Direct Rendering Infrastructure" (DRI). + The DRI is currently used on Linux to provide hardware-accelerated + OpenGL drivers. + . + This package provides the development environment for libdrm-dove1. + +Package: libdrm-dove1 +Section: libs +Priority: extra +Architecture: linux-any +Depends: + ${shlibs:Depends}, + ${misc:Depends}, +Multi-Arch: same +Pre-Depends: ${misc:Pre-Depends} +Description: Userspace interface to kernel DRM services -- runtime + This library implements the userspace interface to the kernel DRM + services. DRM stands for "Direct Rendering Manager", which is the + kernelspace portion of the "Direct Rendering Infrastructure" (DRI). + The DRI is currently used on Linux to provide hardware-accelerated + OpenGL drivers. + . + This package provides the runtime environment for libdrm-dove1. + +Package: libdrm-dove1-dbg +Section: debug +Priority: extra +Architecture: linux-any +Depends: + libdrm2 (= ${binary:Version}), + ${misc:Depends}, +Multi-Arch: same +Description: Userspace interface to kernel DRM services -- debugging symbols + This library implements the userspace interface to the kernel DRM + services. DRM stands for "Direct Rendering Manager", which is the + kernelspace portion of the "Direct Rendering Infrastructure" (DRI). + The DRI is currently used on Linux to provide hardware-accelerated + OpenGL drivers. + . + This package provides debugging symbols for the libdrm-dove1 package. diff --git a/debian/libdrm-dove-dev.install b/debian/libdrm-dove-dev.install new file mode 100644 index 0000000..757f698 --- /dev/null +++ b/debian/libdrm-dove-dev.install @@ -0,0 +1,5 @@ +usr/include/* +usr/lib/*/lib*.a +usr/lib/*/lib*.so +usr/lib/*/pkgconfig/* + diff --git a/debian/libdrm-dove1.install b/debian/libdrm-dove1.install new file mode 100644 index 0000000..99c7f23 --- /dev/null +++ b/debian/libdrm-dove1.install @@ -0,0 +1 @@ +usr/lib/*/libdrm_dove.so.1* diff --git a/debian/libdrm-dove1.postinst.debhelper b/debian/libdrm-dove1.postinst.debhelper new file mode 100644 index 0000000..3d89d3e --- /dev/null +++ b/debian/libdrm-dove1.postinst.debhelper @@ -0,0 +1,5 @@ +# Automatically added by dh_makeshlibs +if [ "$1" = "configure" ]; then + ldconfig +fi +# End automatically added section diff --git a/debian/libdrm-dove1.postrm.debhelper b/debian/libdrm-dove1.postrm.debhelper new file mode 100644 index 0000000..7f44047 --- /dev/null +++ b/debian/libdrm-dove1.postrm.debhelper @@ -0,0 +1,5 @@ +# Automatically added by dh_makeshlibs +if [ "$1" = "remove" ]; then + ldconfig +fi +# End automatically added section diff --git a/debian/rules b/debian/rules new file mode 100755 index 0000000..00c9b22 --- /dev/null +++ b/debian/rules @@ -0,0 +1,23 @@ +#!/usr/bin/make -f + +### +### Actual build +### + +override_dh_auto_configure: + dh_auto_configure -- --enable-static=yes + +override_dh_auto_install: + dh_auto_install --destdir=debian/tmp + +override_dh_install: + find debian/tmp -name '*.la' -delete + dh_install --fail-missing + +override_dh_strip: + dh_strip -plibdrm-dove1 --dbg-package=libdrm-dove1-dbg + dh_strip -s --remaining-packages + +%: + dh $@ --with quilt,autoreconf --builddirectory=build/ + diff --git a/dove_bufmgr.c b/dove_bufmgr.c new file mode 100644 index 0000000..5737bf8 --- /dev/null +++ b/dove_bufmgr.c @@ -0,0 +1,228 @@ +#include +#include +#include +#include +#include + +#include + +#include "dove_bufmgr.h" + +#include "dove_ioctl.h" + +#ifndef DRM_IOCTL_MODE_CREATE_DUMB +/* create a dumb scanout buffer */ +struct drm_mode_create_dumb { + uint32_t height; + uint32_t width; + uint32_t bpp; + uint32_t flags; + /* handle, pitch, size will be returned */ + uint32_t handle; + uint32_t pitch; + uint64_t size; +}; +#define DRM_IOCTL_MODE_CREATE_DUMB DRM_IOWR(0xB2, struct drm_mode_create_dumb) +#endif + +#ifndef DRM_IOCTL_MODE_DESTROY_DUMB +struct drm_mode_destroy_dumb { + uint32_t handle; +}; +#define DRM_IOCTL_MODE_DESTROY_DUMB DRM_IOWR(0xB4, struct drm_mode_destroy_dumb) +#endif + +#ifndef DRM_IOCTL_MODE_MAP_DUMB +struct drm_mode_map_dumb { + uint32_t handle; + uint32_t pad; + uint64_t offset; +}; +#define DRM_IOCTL_MODE_MAP_DUMB DRM_IOWR(0xB3, struct drm_mode_map_dumb) +#endif + +struct drm_dove_bo *drm_dove_bo_create_phys(int fd, uint32_t phys, size_t size) +{ + struct drm_dove_bo *bo; + + bo = calloc(1, sizeof *bo); + if (bo) { + struct drm_dove_gem_create_phys arg; + int ret; + + memset(&arg, 0, sizeof(arg)); + arg.phys = phys; + arg.size = size; + + ret = drmIoctl(fd, DRM_IOCTL_DOVE_GEM_CREATE_PHYS, &arg); + if (ret) { + free(bo); + return NULL; + } + bo->ref = 1; + bo->handle = arg.handle; + bo->size = size; + bo->phys = phys; + bo->type = DRM_DOVE_BO_LINEAR; + } + return bo; +} + +struct drm_dove_bo *drm_dove_bo_create(int fd, unsigned w, unsigned h, unsigned bpp) +{ + struct drm_dove_bo *bo; + + bo = calloc(1, sizeof *bo); + if (bo) { + struct drm_dove_gem_create arg; + int ret; + + memset(&arg, 0, sizeof(arg)); + arg.width = w; + arg.height = h; + arg.bpp = bpp; + + ret = drmIoctl(fd, DRM_IOCTL_DOVE_GEM_CREATE, &arg); + if (ret) { + free(bo); + return NULL; + } + bo->ref = 1; + bo->handle = arg.handle; + bo->size = arg.size; + bo->pitch = arg.pitch; + bo->type = DRM_DOVE_BO_SHMEM; + } + return bo; +} + + + +struct drm_dove_bo *drm_dove_bo_dumb_create(int fd, unsigned w, unsigned h, + unsigned bpp) +{ + struct drm_dove_bo *bo; + + bo = calloc(1, sizeof *bo); + if (bo) { + struct drm_mode_create_dumb arg; + int ret; + + memset(&arg, 0, sizeof(arg)); + arg.width = w; + arg.height = h; + arg.bpp = bpp; + + ret = drmIoctl(fd, DRM_IOCTL_MODE_CREATE_DUMB, &arg); + if (ret) { + free(bo); + return NULL; + } + bo->ref = 1; + bo->handle = arg.handle; + bo->size = arg.size; + bo->pitch = arg.pitch; + bo->type = DRM_DOVE_BO_DUMB; + } + return bo; +} + +static void drm_dove_bo_dumb_destroy(int fd, struct drm_dove_bo *bo) +{ + struct drm_mode_destroy_dumb arg; + int ret; + + if (bo->ptr) { + munmap(bo->ptr, bo->size); + bo->ptr = NULL; + } + + memset(&arg, 0, sizeof(arg)); + arg.handle = bo->handle; + ret = drmIoctl(fd, DRM_IOCTL_MODE_DESTROY_DUMB, &arg); + if (ret == 0) { + free(bo); + } +} + +void drm_dove_bo_get(int fd, struct drm_dove_bo *bo) +{ + bo->ref++; +} + +void drm_dove_bo_put(int fd, struct drm_dove_bo *bo) +{ + if (bo->ref-- == 1) + drm_dove_bo_dumb_destroy(fd, bo); +} + +int drm_dove_bo_map(int fd, struct drm_dove_bo *bo) +{ + void *map; + int ret; + + if (bo->type == DRM_DOVE_BO_DUMB) { + struct drm_mode_map_dumb arg; + + memset(&arg, 0, sizeof(arg)); + arg.handle = bo->handle; + + ret = drmIoctl(fd, DRM_IOCTL_MODE_MAP_DUMB, &arg); + if (ret) + return ret; + + map = mmap(0, bo->size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, + arg.offset); + + if (map == MAP_FAILED) + return -1; + } else if (bo->type == DRM_DOVE_BO_SHMEM) { + struct drm_dove_gem_mmap arg; + + memset(&arg, 0, sizeof(arg)); + arg.handle = bo->handle; + arg.offset = 0; + arg.size = bo->size; + + ret = drmIoctl(fd, DRM_IOCTL_DOVE_GEM_MMAP, &arg); + if (ret) + return -1; + + map = (void *)(uintptr_t)arg.addr; + } else { + errno = EINVAL; + return -1; + } + + bo->ptr = map; + + return 0; +} + +uint32_t drm_dove_bo_phys(int fd, struct drm_dove_bo *bo) +{ + struct drm_dove_gem_prop arg; + int ret; + + memset(&arg, 0, sizeof(arg)); + arg.handle = bo->handle; + + ret = drmIoctl(fd, DRM_IOCTL_DOVE_GEM_PROP, &arg); + + return ret ? -1 : (uint32_t)arg.phys; +} + +int drm_dove_bo_subdata(int fd, struct drm_dove_bo *bo, unsigned long offset, + unsigned long size, const void *data) +{ + struct drm_dove_gem_pwrite arg; + + memset(&arg, 0, sizeof(arg)); + arg.handle = bo->handle; + arg.offset = offset; + arg.size = size; + arg.ptr = (uint64_t)(uintptr_t)data; + + return drmIoctl(fd, DRM_IOCTL_DOVE_GEM_PWRITE, &arg); +} + diff --git a/dove_bufmgr.h b/dove_bufmgr.h new file mode 100644 index 0000000..701e128 --- /dev/null +++ b/dove_bufmgr.h @@ -0,0 +1,31 @@ +#ifndef DRM_DOVE_GEM_H +#define DRM_DOVE_GEM_H + +enum drm_dove_bo_type { + DRM_DOVE_BO_DUMB, + DRM_DOVE_BO_LINEAR, + DRM_DOVE_BO_SHMEM +}; + +struct drm_dove_bo { + uint32_t ref; + uint32_t handle; + uint32_t size; + uint32_t pitch; + uint32_t phys; + void *ptr; + enum drm_dove_bo_type type; +}; + +struct drm_dove_bo *drm_dove_bo_create(int fd, unsigned w, unsigned h, unsigned bpp); +struct drm_dove_bo *drm_dove_bo_create_phys(int fd, uint32_t phys, size_t size); +struct drm_dove_bo *drm_dove_bo_dumb_create(int fd, unsigned w, unsigned h, + unsigned bpp); +int drm_dove_bo_map(int fd, struct drm_dove_bo *bo); +uint32_t drm_dove_bo_phys(int fd, struct drm_dove_bo *bo); +void drm_dove_bo_get(int fd, struct drm_dove_bo *bo); +void drm_dove_bo_put(int fd, struct drm_dove_bo *bo); +int drm_dove_bo_subdata(int fd, struct drm_dove_bo *bo, unsigned long offset, + unsigned long size, const void *data); + +#endif diff --git a/dove_ioctl.h b/dove_ioctl.h new file mode 100644 index 0000000..51997c2 --- /dev/null +++ b/dove_ioctl.h @@ -0,0 +1,138 @@ +/* + * Copyright (C) 2012 Russell King + * With inspiration from the i915 driver + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ +#ifndef DRM_DOVE_IOCTL_H +#define DRM_DOVE_IOCTL_H + +#define DRM_DOVE_GEM_CREATE 0x00 +#define DRM_DOVE_GEM_CREATE_PHYS 0x01 +#define DRM_DOVE_GEM_MMAP 0x02 +#define DRM_DOVE_GEM_PWRITE 0x03 +#define DRM_DOVE_GEM_PROP 0x04 +#define DRM_DOVE_GEM_CACHE 0x05 +#define DRM_DOVE_OVERLAY_PUT_IMAGE 0x06 +#define DRM_DOVE_OVERLAY_ATTRS 0x07 + +#define DOVE_IOCTL(dir,name,str) \ + DRM_##dir(DRM_COMMAND_BASE + DRM_DOVE_##name, struct drm_dove_##str) + +struct drm_dove_gem_create { + uint32_t height; + uint32_t width; + uint32_t bpp; + uint32_t handle; + uint32_t pitch; + uint32_t size; +}; +#define DRM_IOCTL_DOVE_GEM_CREATE \ + DOVE_IOCTL(IOWR, GEM_CREATE, gem_create) + +struct drm_dove_gem_create_phys { + uint32_t size; + uint32_t handle; + uint64_t phys; +}; +#define DRM_IOCTL_DOVE_GEM_CREATE_PHYS \ + DOVE_IOCTL(IOWR, GEM_CREATE_PHYS, gem_create_phys) + +struct drm_dove_gem_mmap { + uint32_t handle; + uint32_t pad; + uint64_t offset; + uint64_t size; + uint64_t addr; +}; +#define DRM_IOCTL_DOVE_GEM_MMAP \ + DOVE_IOCTL(IOWR, GEM_MMAP, gem_mmap) + +struct drm_dove_gem_pwrite { + uint32_t handle; + uint32_t offset; + uint32_t size; + uint64_t ptr; +}; +#define DRM_IOCTL_DOVE_GEM_PWRITE \ + DOVE_IOCTL(IOW, GEM_PWRITE, gem_pwrite) + +struct drm_dove_gem_prop { + uint64_t phys; + uint32_t handle; +}; +#define DRM_IOCTL_DOVE_GEM_PROP \ + DOVE_IOCTL(IOWR, GEM_PROP, gem_prop) + +struct drm_dove_gem_cache { + uint64_t ptr; + uint32_t handle; + uint32_t size; + uint32_t op; +}; +#define DRM_IOCTL_DOVE_GEM_CACHE \ + DOVE_IOCTL(IOW, GEM_CACHE, gem_cache) + +/* Same as Intel I915 */ +struct drm_dove_overlay_put_image { + uint32_t flags; +#define DOVE_OVERLAY_TYPE_MASK 0x000000ff +#define DOVE_OVERLAY_YUV_PLANAR 0x00000001 +#define DOVE_OVERLAY_YUV_PACKED 0x00000002 +#define DOVE_OVERLAY_RGB 0x00000003 +#define DOVE_OVERLAY_DEPTH_MASK 0x0000ff00 +#define DOVE_OVERLAY_RGB24 0x00001000 +#define DOVE_OVERLAY_RGB16 0x00002000 +#define DOVE_OVERLAY_RGB15 0x00003000 +#define DOVE_OVERLAY_YUV422 0x00000100 +#define DOVE_OVERLAY_YUV411 0x00000200 +#define DOVE_OVERLAY_YUV420 0x00000300 +#define DOVE_OVERLAY_YUV410 0x00000400 +#define DOVE_OVERLAY_SWAP_MASK 0x00ff0000 +#define DOVE_OVERLAY_NO_SWAP 0x00000000 +#define DOVE_OVERLAY_UV_SWAP 0x00010000 +#define DOVE_OVERLAY_Y_SWAP 0x00020000 +#define DOVE_OVERLAY_Y_AND_UV_SWAP 0x00030000 +#define DOVE_OVERLAY_FLAGS_MASK 0xff000000 +#define DOVE_OVERLAY_ENABLE 0x01000000 + uint32_t bo_handle; + uint16_t stride_Y; + uint16_t stride_UV; + uint32_t offset_Y; + uint32_t offset_U; + uint32_t offset_V; + uint16_t src_width; + uint16_t src_height; + uint16_t src_scan_width; + uint16_t src_scan_height; + uint32_t crtc_id; + uint16_t dst_x; + uint16_t dst_y; + uint16_t dst_width; + uint16_t dst_height; +}; +#define DRM_IOCTL_DOVE_OVERLAY_PUT_IMAGE \ + DOVE_IOCTL(IOW, OVERLAY_PUT_IMAGE, overlay_put_image) + +/* Same as Intel I915 */ +struct drm_dove_overlay_attrs { + uint32_t flags; +#define DOVE_OVERLAY_UPDATE_ATTRS (1<<0) +#define DOVE_OVERLAY_UPDATE_GAMMA (1<<1) + uint32_t color_key; + int32_t brightness; + uint32_t contrast; + uint32_t saturation; + uint32_t gamma0; + uint32_t gamma1; + uint32_t gamma2; + uint32_t gamma3; + uint32_t gamma4; + uint32_t gamma5; +}; +#define DRM_IOCTL_DOVE_OVERLAY_ATTRS \ + DOVE_IOCTL(IOWR, OVERLAY_ATTRS, overlay_attrs) + +#endif diff --git a/libdrm_dove.pc.in b/libdrm_dove.pc.in new file mode 100644 index 0000000..80ad07a --- /dev/null +++ b/libdrm_dove.pc.in @@ -0,0 +1,11 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +includedir=@includedir@ + +Name: libdrm_dove +Description: Userspace interface to kerenl DRM services +Version: @PACKAGE_VERSION@ +Requires: libdrm +Libs: -L${libdir} -ldrm_dove +Cflags: -I${includedir}/libdrm -- cgit