Commit Graph

48 Commits (ffb9375a505700addcea637ddb8aa308bb73ec36)

Author SHA1 Message Date
Simon Ser baa4b8cafc xf86drm: add drmGetFormatName()
Same as drmGetFormatModifierName() but for formats.

Signed-off-by: Simon Ser <contact@emersion.fr>
Reviewed-by: Marius Vlad <marius.vlad@collabora.com>
Reviewed-by: Eric Engestrom <eric@igalia.com>
2022-08-31 06:40:49 +00:00
Simon Ser 57e0b0552e xf86drm: add drmGetDeviceFromDevId
This adds a function to get a drmDevicePtr from a dev_t identifier
of a device. This is useful for Wayland that uses these to identify
devices over the protocol.

This is done by taking the implementation of drmGetDevice2, and removing
the call to fstat to find the dev_t.

Signed-off-by: Scott Anderson <scott.anderson@collabora.com>
Signed-off-by: Simon Ser <contact@emersion.fr>
Reviewed-by: Daniel Stone <daniels@collabora.com>
2021-11-19 15:30:30 +01:00
Simon Ser 264e66b5e9 xf86drm: add GEM_CLOSE ioctl wrapper
We have wrappers for PRIME_HANDLE_TO_FD and PRIME_FD_TO_HANDLE,
but not for GEM_CLOSE. Add it so that callers don't need to
manually call drmIoctl.

Signed-off-by: Simon Ser <contact@emersion.fr>
Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
Acked-by: Daniel Stone <daniels@collabora.com>
2021-09-27 12:57:02 +02:00
Marius Vlad 67e911977f xf86drm: Add a human readable representation for format modifiers
Introduces two new methods to retrieve a human readable representation of a
format modifier:

drmGetFormatModifierName() - returns a format modifier as a string,
from a token modifier
drmGetFormatModifierVendor() - returns the vendor as a string, from a
token modifier

and the fourcc_mod_get_vendor macro that returns the vendor.

New format modifiers added in drm_fourcc.h uapi kernel header should be
sync'ed up with libdrm and should include a human readable
representation for that format modifier, in order to display it
correctly as a string.

That happens with the help of a python script that reads up drm_fourcc
header file and outputs a static table comprised of token modifiers
alongside a vendor table (Suggested-by Simon Ser <contact@emersion.fr>).

The reason for doing it in libdrm is to have a unified place instead of each
user of libdrm having a way to keep track of the format modifiers.

With this patch, modetest has also been modified to make use of it.

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
2021-06-22 11:16:04 +00:00
Simon Ser 632f59fcbf xf86drm: warn about GEM handle reference counting
Users need to be careful when using drmPrimeHandleToFD or
drmPrimeFDToHandle directly. Mention GBM as a solution.

See [1] for an example mistake.

[1]: https://gitlab.freedesktop.org/drm/nouveau/-/issues/43#note_772661

Signed-off-by: Simon Ser <contact@emersion.fr>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
2021-02-26 13:01:04 +00:00
Lauren Post 8c1185d22c Add ARM support into xf86drm.h
This provides support for Xorg interface.  Without this the vivante
samples will hang during close requiring a reboot

[Adapted from yocto project]
Upstream-Status: Pending
Signed-off-by: Lauren Post <lauren.post@freescale.com>
Signed-off-by: Evan Kotara <evan.kotara@freescale.com>
[Thomas: change CAS code to only be used on ARMv6/ARMv7, and not
ARMv4/ARMv5, which don't support ldrex/strex. If no CAS implementation
is provided libdrm falls back to a system call for locking/unlocking.]
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
Signed-off-by: Peter Seiderer <ps.report@gmx.net>
Acked-by: Eric Engestrom <eric.engestrom@intel.com>
---
Changes v1 -> v2:
  - add comment explaining exclusion of ARMv4/ARMv5 and lower
2019-12-05 22:35:58 +01:00
Chunming Zhou 0a7ad7df14 libdrm: wrap new flexible syncobj query interface v2
v2: nit-picks fix

Signed-off-by: Chunming Zhou <david1.zhou@amd.com>
Cc: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Cc: Christian König <Christian.Koenig@amd.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
For the xf86drm.[ch] part : Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
2019-10-26 03:11:14 +00:00
Eric Engestrom 6869e4cea7 xf86drm: use max size of drm node name instead of arbitrary size
Signed-off-by: Eric Engestrom <eric.engestrom@intel.com>
2019-07-03 13:06:21 +01:00
Eric Engestrom 0d5ea07736 xf86drm: dedupe `#define`s
Adapted from a local patch carried by DragonFlyBSD:
bc056f88f7/graphics/libdrm/files/patch-xf86drm.h

Patch is sadly uncredited (a bot authored the commit), so I can't credit
the author here either.

Signed-off-by: Eric Engestrom <eric.engestrom@intel.com>
2019-07-03 13:06:21 +01:00
Chunming Zhou 12712eb6e3 add timeline signal/transfer ioctls v2
v2: use one transfer ioctl

Signed-off-by: Chunming Zhou <david1.zhou@amd.com>
Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
2019-05-16 12:07:18 +02:00
Chunming Zhou ec6ae51e80 add timeline wait/query ioctl v2
v2: drop export/import

Signed-off-by: Chunming Zhou <david1.zhou@amd.com>
Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
2019-05-16 12:07:18 +02:00
Eric Engestrom eba6609b7b xf86drm: fix return type for drmIsMaster()
Xserver has struct members named `bool`, which means the last commit
breaks its build with errors like this:

  error: two or more data types in declaration specifiers
  Bool bool;
       ^

Fix this by making it return a 0/1 integer, with the same semantic as
the boolean it was before.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=109587
Fixes: 17dfe3ac93 "xf86drm: Add drmIsMaster()"
Cc: Christopher James Halse Rogers <christopher.halse.rogers@canonical.com>
Signed-off-by: Eric Engestrom <eric.engestrom@intel.com>
Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
2019-02-08 18:52:36 +00:00
Christopher James Halse Rogers 17dfe3ac93 xf86drm: Add drmIsMaster()
We can't use drmSetMaster to query whether or not a drm fd is master
because it requires CAP_SYS_ADMIN, even if the fd *is* a master fd.

Pick DRM_IOCTL_MODE_ATTACHMODE as a long-deprecated ioctl that is
DRM_MASTER but not DRM_ROOT_ONLY as the probe by which we can detect
whether or not the fd is master.

This is useful for code that might get master by open()ing the drm device
while no other master exists, but can't call drmSetMaster itself because
it's not running as root or is in a container, where container-root isn't
real-root.

v2: Use the AUTH_MAGIC request rather than MODE_ATTACHMODE, as it's more
    clearly related to master status.

v3: [Emil] Don't expose internals, check for -EACCES.

Signed-off-by: Christopher James Halse Rogers <christopher.halse.rogers@canonical.com>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch> (v2)
Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
2019-02-07 17:43:01 +00:00
Keith Packard d4331dda5b drm: Add CrtcGetSequence and CrtcQueueSequence IOCTLs [v2]
These provide a crtc-id based interface to get the current sequence
(frame) number and to queue an event to be delivered at a specific sequence.

v2: Remove FIRST_PIXEL_OUT flag. This has been removed from the
    proposed kernel API

Signed-off-by: Keith Packard <keithp@keithp.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
2017-12-18 10:04:02 +10:00
Bas Nieuwenhuizen 1abccedc4d drm: Add drmSyncobjReset & drmSyncobjSignal wrappers.
anv already uses the ioctls but does not use libdrm, so these were
not wrapped yet.

Signed-off-by: Dave Airlie <airlied@redhat.com>
2017-12-18 09:51:50 +10:00
Marek Olšák 2048a9e727 drm: add drmSyncobjWait wrapper
Reviewed-by: Chunming Zhou <david1.zhou@amd.com>
2017-10-12 20:35:57 +02:00
Dave Airlie fc4922793f libdrm: add drm syncobj create/destroy/import/export
These ioctls are now in drm next so add the first set of libdrm APIs.

Reviewed-by: Eric Anholt <eric@anholt.net>
Signed-off-by: Dave Airlie <airlied@redhat.com>
2017-06-29 05:32:34 +10:00
Adam Jackson 7c27cd7c5d Export drmDevicesEqual
drmCompareBusInfo was almost this already, but it wasn't exported, its
name didn't match its functionality, and while it almost looks like it
was usable for sorting due to memcmp it wouldn't work if you had
multiple bus types. I don't really want to think about defining a
sensible sort order for bus types, so let's at least make it less of a
trap for the caller.

Invert its boolean sense to be 'true if equal', rename it to describe
the types it actually operates on, and export.

Reviewed-by: Eric Anholt <eric@anholt.net>
Reviewed-by: Emil Velikov <emil.velilkov@collabora.com>
Signed-off-by: Adam Jackson <ajax@redhat.com>
2017-05-04 14:36:25 -04:00
Ander Conselvan de Oliveira 890d43a6a8 Add CRTC ID to vblank event
When using the atomic API, one request can span multiple CRTCs, however
one event is generated per CRTC. As we cannot disambiguate the CRTC with
user data (since we only have one piece of user data to pass in), newer
kernels can include the CRTC ID in the page flip event.

Add a new vfunc to dispatch vblank events carrying a CRTC ID to clients
who negotiate a higher interface version.

[daniels: Rebased, include new cap, call page_flip_handler if it is set
          but page_flip_handler2 isn't even on newer contexts, write a
	  commit message.]

v2: Split into separate commit.

Signed-off-by: Ander Conselvan de Oliveira <ander.conselvan.de.oliveira@intel.com>
Signed-off-by: Daniel Stone <daniels@collabora.com>
Reviewed-by: Maarten Lankhorst <maarten.lankhorst@intel.com>
2017-04-06 20:32:43 +01:00
Thierry Reding 7b1f37f474 xf86drm: Add platform and host1x bus support
ARM SoCs usually have their DRM/KMS devices on the platform bus, so add
support for that to enable these devices to be used with the drmDevice
infrastructure.

NVIDIA Tegra SoCs have an additional level in the hierarchy and DRM/KMS
devices can also be on the host1x bus. This is mostly equivalent to the
platform bus.

v4:
- continue on error to process platform or host1x device

v3:
- guard Linux-specific sysfs parsing code with #ifdef __linux__

v2:
- be careful not to overflow the full name
- read compatible strings into device info

Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Signed-off-by: Thierry Reding <treding@nvidia.com>
2017-01-20 16:27:20 +01:00
Thierry Reding f8484ccbd1 xf86drm: Add USB support
Allow DRM/KMS devices hosted on USB to be detected by the drmDevice
infrastructure.

v4:
- continue on error to process USB devices

v3:
- guard Linux-specific sysfs parsing code with #ifdef __linux__

v2:
- make sysfs_uevent_get() more flexible using a format string

Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
2017-01-20 16:25:53 +01:00
Emil Velikov 11687bf418 xf86drm: introduce drmGetDevice[s]2
Relative to the original version, here one can provide a flags bitmask.
Currently only DRM_DEVICE_IGNORE_PCI_REVISION is supported.

Implementation detail:
If it's set, we will only parse the separate sysfs files and we won't
touch the config one. The latter awakes the device (causing delays)
which is the core reason why this API was introduced.

v2:
 - Initialize revision to 0xff if it's unread.
 - Change DRM_DEVICE_IGNORE_PCI_REVISION to DRM_DEVICE_GET_PCI_REVISION
 - Add explicit note that drmGetDevice[s]2 does not retrieve the
revision by default.

v3:
 - Correctly fold drmParsePciDeviceInfo() hunk in this patch.

Cc: Michel Dänzer <michel@daenzer.net>
Cc: Nicolai Hähnle <nhaehnle@gmail.com>
Cc: Mauro Santos <registo.mailling@gmail.com>
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=98502
Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>
2016-12-05 17:21:56 +00:00
Emil Velikov 37d790f7d4 xf86drm: introduce drmGetDeviceNameFromFd2
The original version considered only card devices, while this will pick
the device/node name regardless - card, control, renderD, other...

Current implementation is "linux" specific, in such that it relies on
sysfs/uevent file. At the same time this gives us the flexibility to
support any nodes even future ones, as long as they're within DRM_MAJOR.

Shamelessly copied from mesa, latter by: Gary Wong <gtw@gnu.org>
Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
Reviewed-by: Nicolai Hähnle <nicolai.haehnle@amd.com>
2016-11-22 13:54:23 +00:00
Emil Velikov ccedf66b65 xf86drm: add drm{Get,Free}Device
Similar interface to the *Devices() ones but they obtain/free the
information of the opened device (as given by its fd).

Note there is a fair bit of duplication between the two Get functions,
and anyone interested is more than welcome to consolidate it.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Acked-by: Alex Deucher <alexander.deucher@amd.com>
2015-09-21 17:43:08 +01:00
Emil Velikov b556ea127e drm: add interface to get drm devices on the system v3
For mutiple GPU support, the devices on the system should be enumerated
to get necessary information about each device, and the drmGetDevices
interface is added for this. Currently only PCI devices are supported for
the enumeration.

Typical usage:
int count;
drmDevicePtr *foo;
count = drmGetDevices(NULL, 0);
foo = calloc(count, sizeof(drmDevicePtr));
count = drmGetDevices(foo, count);
/* find proper device, open correct device node, etc */
drmFreeDevices(foo, count);
free(foo);

v2: [Jammy Zhou]
 - return a list of devices, rather than nodes
v3: [Jammy Zhou]
 - fix the signed extension for PCI device info

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Signed-off-by: Jammy Zhou <Jammy.Zhou@amd.com>
2015-08-24 17:36:28 +01:00
Tapani Pälli 1c205749fe remove usage of 'c_plusplus' preprocessor macro
Use only __cplusplus which is supported by the C++ standard.

Signed-off-by: Tapani Pälli <tapani.palli@intel.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
2015-08-10 11:25:39 +03:00
Jonathan Gray fc083322b0 xf86drm: use the correct device minor names on OpenBSD
Add defines for the device minor names and make use of them
in drmGetMinorName() so the correct paths will be used on OpenBSD.

v2: don't add new defines to xf86drm.h to keep them out of the API
    as requested by Emil.

Signed-off-by: Jonathan Gray <jsg@jsg.id.au>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
2015-07-29 18:04:15 +01:00
Emil Velikov 5b0e76f143 Revert "Add device enumeration interface (v4)"
This reverts commit fde4969176.

The commit adds an API that does not seem flexible enough to be used in
current open-source projects. Additionally it adds a hidden dependency
of libudev, which when used in mesa caused grief when combined with
Steam('s runtime).

Let's revert this for now and add a tweaked API later on that can be
used in mesa/xserver.

Cc: Frank Min <frank.min@amd.com>
Cc: Christian König <christian.koenig@amd.com>
Cc: Alex Deucher <alexander.deucher@amd.com>
Cc: Jammy Zhou <Jammy.Zhou@amd.com>
2015-06-29 11:12:21 +01:00
frank fde4969176 Add device enumeration interface (v4)
Add an interface for enumerating PCI devices on
a system.

v3: switch to udev/sysfs for the enumeration
v4: fix warnings

Signed-off-by: Frank Min <frank.min@amd.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Reviewed-by: Jammy Zhou <Jammy.Zhou@amd.com>
2015-05-26 12:34:38 -04:00
Emil Velikov 0ca03a4087 drm: add drmGet(Primary|Render)DeviceNameFromFd functions
Currently most places assume reliable primary(master) <> render node
mapping. Although this may work in some cases, it is not correct.

Add a couple of helpers that hide the details and provide the name of
the master or render device name, given an fd. The latter may belong to
either the master, control or render node device.

v2:
 - Rename Device and Primary to Master (aka the /dev/dri/cardX device).
 - Check for the file via readdir_r() rather than stat().
 - Wrap the check into a single function.
 - Return NULL for non-linux platforms.

v3:
 - Don't segfault if name is NULL.
 - Update function names, as suggested by Frank Binns.

v4:
 - Update commit message to reflect the function name changes.

Cc: Frank Binns <frank.binns@imgtec.com>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: David Herrmann <dh.herrmann@googlemail.com>
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Frank Binns <frank.binns@imgtec.com>
2015-03-10 18:14:40 +00:00
Frank Binns 1f73578df3 Add new drmGetNodeTypeFromFd function
Add a helper function that returns the type of device node from an fd.

Signed-off-by: Frank Binns <frank.binns@imgtec.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
2015-02-23 09:29:19 +00:00
Jammy Zhou dbc8b11db6 Add new drmOpenOnceWithType function (v2)
v2: call drmOpenOnceWithType in drmOpenOnce, and drop unused param
for drmOpenOnceWithType

Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Jammy Zhou <Jammy.Zhou@amd.com>
2015-02-12 18:36:52 -05:00
Jammy Zhou f1adc4b375 Add new drmOpenWithType function (v4)
v2: Add drmGetMinorBase, and call drmOpenWithType in drmOpen
v3: Pass 'type' to drmOpenByBusid and drmOpenDevice in drmOpenByName
v4: Renumber node type definitions, and return -1 for unsupported type

Signed-off-by: Jammy Zhou <Jammy.Zhou@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com> (v3)
Reviewed-by: Frank Binns <frank.binns@imgtec.com>
2015-02-12 18:34:57 -05:00
Frank Binns 0c5aaeef51 Add new drmOpenRender function
Add a new function, drmOpenRender, that can be used to open render nodes. This
can be used in the same way that drmOpenControl is used to open control nodes.

Signed-off-by: Frank Binns <frank.binns@imgtec.com>
Reviewed-by: Rob Clark <robdclark@gmail.com>
2015-01-23 23:02:27 +00:00
Thierry Reding 44b08c0ddf Mark functions printf-like where possible
These functions all take a format string and either a list of variable
arguments or a va_list. Use the new DRM_PRINTFLIKE macro to tell the
compiler about it so that the arguments can be checked against the
format string.

Reviewed-by: Eric Anholt <eric@anholt.net>
Signed-off-by: Thierry Reding <treding@nvidia.com>
2014-04-17 16:21:40 +02:00
Keith Packard cb4bc8ead6 Mark debug_print with __attribute__ ((format(__printf__, 1, 0)))
the drmServerInfo member, debug_print, takes a printf format string
and varargs list. Tell the compiler about it.

Signed-off-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
2014-01-13 10:13:42 -08:00
Damien Lespiau ddbbdb13d8 drm: Introduce a drmSetClientCap() wrapper
That wraps around the new DRM_SET_CLIENT_CAP ioctl.

v2: SET_CAP -> SET_CLIENT_CAP renaming

Signed-off-by: Damien Lespiau <damien.lespiau@intel.com>
2013-09-30 13:35:49 +01:00
Dave Airlie cc0a14575d libdrm: add prime fd->handle and handle->fd interfaces
These are just basic ioctl wrappers around the prime ioctls,
along with the capability reporting.

Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
2012-07-16 02:39:56 +01:00
Tapani Pälli cfee5218b1 xf86drm.h : wrap C code for C++ compilation/linking
To enable usage of xf86drm.h from C++ programs/frameworks.

Signed-off-by: Tapani Pälli <tapani.palli@intel.com>
[ickle: also wrap xf86drmMode.h]
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2011-09-23 12:58:56 +01:00
Ilija Hadzic be8802a941 libdrm: (revised) vblank wait on crtc > 1
Hi Alex,

Enclosed is a revised version of the patch sent on Mar 18, against
the master branch of the drm userspace (i.e. libdrm). Details
summarised in this thread:
http://lists.freedesktop.org/archives/dri-devel/2011-March/009499.html

This patch reconciles libdrm with the the kernel change that Dave
pushed this morning. It *supersedes* the previously sent patch (i.e.
apply it to the master branch as it exists at the time of this writing,
not as an incremental patch to the one sent previously).

Regards,

Ilija

Signed-off-by: Ilija Hadzic <ihadzic@research.bell-labs.com>
Signed-off-by: Alex Deucher <alexdeucher@gmail.com>
2011-04-04 11:04:03 -04:00
Ben Skeggs 5c6c6913d1 Implement drmGetCap() to query device/driver capabilities
Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
2011-03-04 15:25:51 +10:00
Jesse Barnes 14f5958f7f Bump event context structure version for page flipping 2009-12-03 14:27:08 -08:00
Jesse Barnes 53addc5d6e Merge branch 'pageflip' of git://people.freedesktop.org/~jbarnes/drm
Conflicts:
	include/drm/drm.h - RMFB had its signature changed to avoid uint32_t
2009-12-03 14:17:26 -08:00
Robert Noland 6f66de982a Correctly set DRM_MAX_MINOR for all platforms.
DRM_MAJOR is platform specific, but not used outside of xf86drm.c
that I can find.
2009-11-25 15:09:24 -06:00
Alex Deucher 9558f6377f Add missing DRM_MAX_MINOR define
lost in 500f5b5240

Signed-off-by: Alex Deucher <alexdeucher@gmail.com>
2009-11-24 15:03:32 -05:00
Kristian Høgsberg 22d4666904 Add drmGetDeviceNameFromFd function
Determines the /dev filename of the drm fd argument.
2009-11-23 20:51:34 -05:00
Kristian Høgsberg 500f5b5240 Fix build on *BSD
This adds a minimal #ifdef clause to drm.h that we'll push upstream.
Once that goes in we can share drm.h between linux, libdrm, and
the bsd's.
2009-11-23 18:25:11 -05:00
Kristian Høgsberg 4f57abfe66 Move libdrm/ up one level 2009-11-17 11:15:06 -05:00