atomic: add atomic_add_unless()

Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: Damien Lespiau <damien.lespiau@intel.com>
Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
intel: make bufmgr_gem shareable from different API

When using Mesa and LibVA in the same process, one would like to be
able bind buffers from the output of the decoder to a GL texture
through an EGLImage.

LibVA can reuse buffers allocated by Gbm through a file descriptor. It
will then wrap it into a drm_intel_bo with
drm_intel_bo_gem_create_from_prime().

The problem at the moment is that both library get a different
drm_intel_bufmgr object when they call drm_intel_bufmgr_gem_init()
even though they're using the same drm file descriptor. As a result,
instead of manipulating the same buffer object for a given file
descriptor, they get 2 different drm_intel_bo objects and 2 different
refcounts, leading one of the library to get errors from the kernel on
invalid BO when one of the 2 library is done with a shared buffer.

This patch modifies drm_intel_bufmgr_gem_init() so, given a file
descriptor, it will look for an already existing drm_intel_bufmgr
using the same file descriptor and return that object.

Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: Damien Lespiau <damien.lespiau@intel.com>
Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
intel: make bo_unreference() thread safe

Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: Damien Lespiau <damien.lespiau@intel.com>
Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
intel: make drm_intel_gem_bo_get_reloc_count() thread safe

Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: Damien Lespiau <damien.lespiau@intel.com>
Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
intel: Add support for userptr objects

Allow userptr objects to be created and used via libdrm_intel.

At the moment tiling and mapping to GTT aperture is not supported
due hardware limitations across different generations and uncertainty
about its usefulness.

v2: Improved error handling in feature detection per review comments.

v3: Rebase on top of the drm_public addition, minor whitespace addition.

Reviewed-by: Damien Lespiau <damien.lespiau@intel.com>
Signed-off-by: Damien Lespiau <damien.lespiau@intel.com> (v3)
Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com> (v1,v2)
intel: Adding locks for drm objects synchronization.

The changes make sure that members of the bufmgr_gem and bo_gem
name lists are sychronized between threads
when using the create from prime and create from name methods.

Signed-off-by: Rafal Sapala <rafal.a.sapala@intel.com>
Testcase: igt/drm_import_export
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
intel: Don't leak the test page in an has_userptr() error path

When handling the error on GEM_CLOSE, we weren't freeing the allocated
page. Plug that.

Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Signed-off-by: Damien Lespiau <damien.lespiau@intel.com>
freedreno: add dmabuf import/export helpers

Signed-off-by: Rob Clark <robclark@freedesktop.org>
automake: remove obsolete makefiles

Rather than having two extra makefiles in order to ship ~10 headers
just fold its 5 lines of code into the top one makefile.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Jakob Bornecrantz <jakob@vmware.com>
Remove i810_drm.h and i830_drm.h from the distribution tarball

Both of these headers are not installed since they were imported.
They  are not even used internally. The latter no longer exist in the
kernel...

Note the * symbol in EXTRA_DIST causes 'make distcheck' to fail. When
was the last time we ran it ?

Cc: Ville Syrjälä <ville.syrjala@linux.intel.com>
Cc: Damien Lespiau <damien.lespiau@intel.com>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Jakob Bornecrantz <jakob@vmware.com>
Acked-by: Daniel Vetter <daniel.vetter@ffwll.ch>
automake: fix 'make commit-headers'

Not too long ago the in-kernel drm public headers were moved. Since then
we could no longer fetch/update the ones in libdrm using the command.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Jakob Bornecrantz <jakob@vmware.com>
configure: unconditionally check for atomic ops/primitives

Just have the check once, and let new drivers opt-in if they want
to use them. Move the block further up the script, to tie nicely
with the actual usage of $HW defines.

Move the final $HW users to be alongside their brethren.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Jakob Bornecrantz <jakob@vmware.com>
libkms: build the intel backend only when needed

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Jakob Bornecrantz <jakob@vmware.com>
libkms: move sources lists to makefile.sources

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Jakob Bornecrantz <jakob@vmware.com>
libkms: add Android build

Cc: Benjamin Gaignard <benjamin.gaignard@linaro.org>
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Jakob Bornecrantz <jakob@vmware.com>
modetest: move sources lists to makefiles.sources

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Jakob Bornecrantz <jakob@vmware.com>
modetest: add Android build

v2: include modetest rather than modeset.
Spotted by Mauro Rossi and Paulo Sergio.

Cc: Benjamin Gaignard <benjamin.gaignard@linaro.org>
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Jakob Bornecrantz <jakob@vmware.com> (v1)
modetest: Add support of STI driver

Reviewed-by: Jakob Bornecrantz <jakob@vmware.com>
automake: pick up all files for distribution.

Autotools is already smart enough to pick the *.pc.in files but it
needs some help with the Android.mk ones.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Jakob Bornecrantz <jakob@vmware.com>
Add private mmap/munmap wrappers

Unlike Linux, Android (bionic) has separate functions - mmap & mmap64.
Add a local wrapper (inspired by gallium) that will be used throughout
libdrm to combat this bionic feature.

v2:
 - Drop the undefined unlikely macro.
 - Use macro for munmap under Android.
 - Wrap long lines.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Jakob Bornecrantz <jakob@vmware.com> (v1)