summaryrefslogtreecommitdiff
path: root/xf86drm.c
Commit message (Collapse)AuthorAgeFilesLines
* xf86drm: add support for printing AMD GFX11 modifiersSimon Ser2023-02-091-0/+6
| | | | | | | | See kernel commit 543036a2de71 ("drm/amd: Add GFX11 modifiers support to AMDGPU (v3)"). Signed-off-by: Simon Ser <contact@emersion.fr> Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
* xf86drm: fix warning in drmGetFormatModifierNameFromVivante()Simon Ser2022-12-211-1/+1
| | | | | | | | | | | | | | | | | | | | Fixes the following warning: ../xf86drm.c: In function ‘drmGetFormatModifierNameFromVivante’: ../xf86drm.c:614:14: warning: passing argument 1 of ‘asprintf’ from incompatible pointer type [-Wincompatible-pointer-types] 614 | asprintf(&mod_vivante, "%s%s%s", color_tiling, tile_status, compression); | ^~~~~~~~~~~~ | | | const char ** In file included from ../xf86drm.c:34: /usr/include/stdio.h:396:40: note: expected ‘char ** restrict’ but argument is of type ‘const char **’ 396 | extern int asprintf (char **__restrict __ptr, | ~~~~~~~~~~~~~~~~~~^~~~~ ../xf86drm.c:615:12: warning: return discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers] 615 | return mod_vivante; | ^~~~~~~~~~~ Signed-off-by: Simon Ser <contact@emersion.fr>
* xf86drm: Add support for decoding Vivante format modifiersPhilipp Zabel2022-11-301-0/+68
| | | | | | Allow applications to pretty-print Vivante format modifiers. Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
* xf86drm: handle DRM_FORMAT_BIG_ENDIAN in drmGetFormatName()Simon Ser2022-10-171-12/+17
| | | | | | | This bit can be added to a DRM format to indicate that it's big endian instead of little endian. Signed-off-by: Simon Ser <contact@emersion.fr>
* xf86drm: add drmGetFormatName()Simon Ser2022-08-311-0/+35
| | | | | | | | 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>
* Remove unused 3rd parameter to open(2)Matthieu Herrb2022-08-231-5/+5
| | | | | | The 3rd parameter is only used with the O_CREAT flag Signed-off-by: Matthieu Herrb <matthieu@herrb.eu>
* xf86drm.c: fix C99 warningEleni Maria Stea2022-05-091-1/+2
| | | | | | | Moved declaration to the top to resolve C99 compliance warning. Signed-off-by: Eleni Maria Stea <elene.mst@gmail.com> Reviewed-by: Simon Ser <contact@emersion.fr>
* xf86drm: fix compiler warningsEleni Maria Stea2021-11-251-10/+15
| | | | | | | | | | | Used casting to fix warnings about assigning different enum types to variables. Used error checks in places where snprintf is called and output might be truncated to fix gcc format-truncation warnings. v2: Removed a change in drm.h (Simon Ser) v3, v4: Removed unecessary braces in snprintf (Simon Ser) Signed-off-by: Eleni Maria Stea <elene.mst@gmail.com>
* xf86drm: add drmGetDeviceFromDevIdSimon Ser2021-11-191-24/+40
| | | | | | | | | | | | | 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>
* xf86drm: Update drmGetFormatModifierNameFromArm to handle AFRCDennis Tsiang2021-10-041-20/+84
| | | | | | | Update drmGetFormatModifierNameFromArm function to handle AFRC modifiers. Signed-off-by: Dennis Tsiang <dennis.tsiang@arm.com>
* xf86drm: add GEM_CLOSE ioctl wrapperSimon Ser2021-09-271-0/+9
| | | | | | | | | | 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>
* xf86drm: fix mem leak in drm_usb_dev_path()Eric Engestrom2021-08-141-2/+7
| | | | | | | | `sysfs_uevent_get()` returns a `strndup()`ed string, which must be `free()`d. Fixes: bf63f8acdc94164ad29d ("libdrm: Handle usb_interface devices for usb parsing") Reviewed-by: Simon Ser <contact@emersion.fr> Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
* xf86drm: Add support for decoding AMLOGIC format modifiersMarius Vlad2021-06-221-0/+35
| | | | Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
* xf86drm: Add support for decoding AMD format modifiersMarius Vlad2021-06-221-0/+167
| | | | Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
* xf86drm: Add support for decoding Nvidia format modifiersMarius Vlad2021-06-221-0/+30
| | | | Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
* xf86drm: Add a vendor function to decode the format modifierMarius Vlad2021-06-221-3/+112
| | | | | | | | | | | | | As format modifiers can be encoded in quite complex forms, the static table previously added is not sufficient to retrieve, extract and decode the token formats to a human-readable string. This patch introduces a vendor specific callback which could be used to perform an additional search to match up with vendor encoding scheme, which, will be used first, before resorting to searching the static table. With it, add support for decoding the ARM format modifiers. Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
* xf86drm: Add a human readable representation for format modifiersMarius Vlad2021-06-221-0/+80
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* xf86drm: fix null pointer deref in drmGetBufInfoAlistair Delva2021-03-021-1/+6
| | | | | | | | | | If info.count is large, drmMalloc() / alloca() may fail, and the resulting null pointer is not null checked before dereference. Issue: https://gitlab.freedesktop.org/mesa/drm/-/issues/62 Reviewed-by: Simon Ser <contact@emersion.fr> Signed-off-by: Alistair Delva <adelva@google.com>
* xf86drm: cap number of reported devices by drmGetDevice(2)Emil Velikov2021-02-261-0/+4
| | | | | | | | | | | | | | | | Do as the documentation says - when devices non NULL, cap the reported devices to max_devices. Otherwise we risk out-of-bound access for users of the API. v2: - Fix this w/o breaking the API v3: - Drop local variables, flip inverted conditional (Simon) Issue: https://gitlab.freedesktop.org/mesa/drm/-/issues/56 Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com> Reviewed-by: Simon Ser <contact@emersion.fr>
* Revert "xf86drm: cap number of reported devices by drmGetDevice(2)"Emil Velikov2021-02-261-4/+3
| | | | | | | | | This reverts commit 8cb12a2528d795c45bba5f03b3486b4040fb0f45. The commit fixed the OOB, yet it broke drmDevices2(0, NULL, 0) - aka we did not return the total devices list. Reviewed-by: Simon Ser <contact@emersion.fr>
* xf86drm: cap number of reported devices by drmGetDevice(2)Emil Velikov2021-02-101-3/+4
| | | | | | | | | | Do as the documentation says - cap the number of reported devices to the requested amount - aka max_devices. Otherwise we risk out-of-bound access for users of the API. Issue: https://gitlab.freedesktop.org/mesa/drm/-/issues/56 Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com> Reviewed-by: Simon Ser <contact@emersion.fr>
* xf86drm.c: Use integer logarithm.Paul Gofman2020-10-281-1/+17
| | | | | | | | | | log() is affected by FP control word and can provide inaccurate result. Fixes Killer Instinct under Wine not being able to find AMD vulkan device. Reviewed-by: Dave Airlie <airlied@redhat.com> Signed-off-by: Paul Gofman <pgofman@codeweavers.com>
* xf86drm.c: fix build failureHeiko Thiery2020-06-061-5/+5
| | | | | | | | | | | | | | | | | | | | | | | | | ./xf86drm.c: In function 'drmNodeIsDRM': ../xf86drm.c:2825:7: error: "__FreeBSD__" is not defined [-Werror=undef] #elif __FreeBSD__ ^ ../xf86drm.c: In function 'drmGetMinorNameForFD': ../xf86drm.c:2938:7: error: "__FreeBSD__" is not defined [-Werror=undef] #elif __FreeBSD__ ^ ../xf86drm.c: In function 'drmParsePciBusInfo': ../xf86drm.c:3258:7: error: "__FreeBSD__" is not defined [-Werror=undef] #elif __FreeBSD__ ^ ../xf86drm.c: In function 'drmParsePciDeviceInfo': ../xf86drm.c:3427:7: error: "__FreeBSD__" is not defined [-Werror=undef] #elif __FreeBSD__ ^ ../xf86drm.c: In function 'drmGetDeviceNameFromFd2': ../xf86drm.c:4305:7: error: "__FreeBSD__" is not defined [-Werror=undef] #elif __FreeBSD__ ^ Signed-off-by: Heiko Thiery <heiko.thiery@gmail.com>
* core: use `O_RDONLY` instead of ambiguous `0` flagEric Engestrom2020-05-281-1/+1
| | | | | Signed-off-by: Eric Engestrom <eric@engestrom.ch> Reviewed-by: Michel Dänzer <mdaenzer@redhat.com>
* libdrm: drmGetDeviceNameFromFd: Always return /dev/dri/ node for FreeBSDEmmanuel Vadot2020-05-041-11/+4
| | | | | | | | | Since we now always returns the /dev/dri/ node for drmGet<nodetype>DeviceNameFromFd, be consistant with the names returned in drmGetDeviceNameFromFd. Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com> Signed-off-by: Emmanuel Vadot <manu@FreeBSD.org>
* libdrm: drmGetMinorNameFromFd: Fix FreeBSD variantEmmanuel Vadot2020-05-041-8/+19
| | | | | | | | | | | Fix the FreeBSD variant by getting the node type represented by fd to deduce the target minor name. We then return the full /dev/dri/<minorname><id> version. Fix: #41 Fixes: 6818a50b12 Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com> Signed-off-by: Emmanuel Vadot <manu@FreeBSD.org>
* libdrm: Handle usb_interface devices for usb parsingScott Anderson2020-04-241-2/+46
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently the code expects that the device found at /sys/char/$maj:$min/device for USB devices is a "usb_device". However, at least for some devices, such as for the udl driver, they are instead a "usb_interface". A usb_interface is a child of the usb_device we're interested in, so we walk up one in the /sys path to get there. For example, with a USB device I have, trimmed to show the relevant information: ``` $ udevadm info /dev/dri/card1 P: /devices/pci0000:00/0000:00:01.3/0000:02:00.0/usb1/1-4/1-4:1.0/drm/card1 E: DEVTYPE=drm_minor $ udevadm info /sys/devices/pci0000:00/0000:00:01.3/0000:02:00.0/usb1/1-4/1-4:1.0 E: DEVTYPE=usb_interface E: DRIVER=udl $ udevadm info /sys/devices/pci0000:00/0000:00:01.3/0000:02:00.0/usb1/1-4 E: DEVTYPE=usb_device E: DRIVER=usb E: BUSNUM=001 E: DEVNUM=009 ``` Signed-off-by: Scott Anderson <scott@anderso.nz>
* xf86drm: Check non-absolute path only for virtio based devicesMikhail Golubev2020-04-241-4/+8
| | | | | | | | This fixes bug in drmParseSubsystemType() that cases situation when subsequent call to readlink() from get_subsystem_type() will result in EACCESS. Signed-off-by: Mikhail Golubev <mikhail.golubev@opensynergy.com>
* libdrm: Implement drmParsePciDeviceInfo for FreeBSDEmmanuel Vadot2020-04-211-0/+43
| | | | | | | | | | | The FreeBSD kernel expose a pseudo-device /dev/pci to obtain information about present PCI device. Uee the PCIOCGETCONF ioctl on this device to look up the desired device information. Signed-off-by: Emmanuel Vadot <manu@FreeBSD.org> Reviewed-by: Eric Engestrom <eric@engestrom.ch> Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
* libdrm: get_pci_path is Linux only so add an ifdefEmmanuel Vadot2020-04-211-0/+2
| | | | | Signed-off-by: Emmanuel Vadot <manu@FreeBSD.org> Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
* libdrm: Add get_sysctl_pci_bus_info for FreeBSDEmmanuel Vadot2020-04-211-0/+65
| | | | | | | | | | | The FreeBSD drm driver expose a sysctl hw.dri.%d.busid which contain the busid. Use this sysctl to parse the busid information based on the major/minor that allow us to implement FreeBSD support for drmParsePciBusInfo. Signed-off-by: Emmanuel Vadot <manu@FreeBSD.org> Reviewed-by: Eric Engestrom <eric@engestrom.ch> Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
* libdrm: drmGetDeviceNameFromFd2: Add FreeBSD variantEmmanuel Vadot2020-04-211-0/+2
| | | | | | | | | The FreeBSD variant of drmGetDeviceNameFromFd can already handle the different node type so just call it. Signed-off-by: Emmanuel Vadot <manu@FreeBSD.org> Reviewed-by: Eric Engestrom <eric@engestrom.ch> Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
* libdrm: Default to PCI for FreeBSDEmmanuel Vadot2020-04-211-1/+1
| | | | | | | | | FreeBSD have some support for DRM on !PCI device but no code is currently upstream. Default to PCI for now. Signed-off-by: Emmanuel Vadot <manu@FreeBSD.org> Reviewed-by: Eric Engestrom <eric@engestrom.ch> Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
* libdrm: drmGetMinorNameForFD: Add FreeBSD variantEmmanuel Vadot2020-04-211-0/+32
| | | | | | | | | | Use the FreeBSD variant function to obtain the minor name and the device node. Return the correct path based on where the node is (drm/ versus dri/). Signed-off-by: Emmanuel Vadot <manu@FreeBSD.org> Reviewed-by: Eric Engestrom <eric@engestrom.ch> Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
* libdrm: drmGetDeviceNameFromFd: Add FreeBSD variantEmmanuel Vadot2020-04-211-0/+24
| | | | | | | | | | | | Get the major/minor via fstat and after checking that this is a drm node construct the full device node name using devname. Note that we should be able to use fdevname to avoid calling fstat + devname but for some reason it doesn't work on drm node (probably due to how the device node are created in the linux compat code for drm on FreeBSD). Signed-off-by: Emmanuel Vadot <manu@FreeBSD.org> Reviewed-by: Eric Engestrom <eric@engestrom.ch> Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
* libdrm: drmGetMinorType: Add FreeBSD versionEmmanuel Vadot2020-04-211-6/+26
| | | | | | | | | | | | Resolve the minor type based on the device node path. The minor type is either in /dev/drm/X where X is the type or in a Linux-compatible device node in /dev/dri/ This means we need the major number on FreeBSD so add it to the function arguments. Signed-off-by: Emmanuel Vadot <manu@FreeBSD.org> Reviewed-by: Eric Engestrom <eric@engestrom.ch> Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
* xf86drm: Remove ifdef for FreeBSD and DRM_MAJOREmmanuel Vadot2020-04-211-1/+1
| | | | | | | | | FreeBSD devfs only provides on the fly generated major/minor. The major number is irrelevant for FreeBSD so remove the special case. Signed-off-by: Emmanuel Vadot <manu@FreeBSD.org> Reviewed-by: Eric Engestrom <eric@engestrom.ch> Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
* libdrm: drmNodeIsDRM: Add FreeBSD variantEmmanuel Vadot2020-04-211-0/+14
| | | | | | | | | | | | | FreeBSD devfs have on the gly generated major minor so we cannot use them to test if the device is a drm node. Instead get the devfs node name and test if it is in a subdirectory "drm/" or "dri/". Historycally DRM device on FreeBSD are created in /dev/drm/ and link are present in /dev/dri/ for compatibility reason. Signed-off-by: Emmanuel Vadot <manu@FreeBSD.org> Reviewed-by: Eric Engestrom <eric@engestrom.ch> Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
* xf86drm: fix subsystem type lookup for virtio mmio-based devicesVasyl Vavrychuk2020-02-241-3/+12
| | | | | | | | | | | | | | | | Currently the code assumes that a virtio based device is always located on the PCI bus. Modify the parser to make it check the device's parent directory to determine on which bus it is located. Output for virtio-pci is the PCI bus. Output for virtio-mmio is the Platform bus. Signed-off-by: Vasyl Vavrychuk <vasyl.vavrychuk@opensynergy.com> Signed-off-by: Mikhail Golubev <Mikhail.Golubev@opensynergy.com> Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org> Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
* xf86drm: generalize the device subsystem type parsing codeVasyl Vavrychuk2020-02-241-5/+16
| | | | | | | | | | Move the code, which used to get the device subsystem type from a device path in sysfs, to a separate function to be reusable. Signed-off-by: Vasyl Vavrychuk <vasyl.vavrychuk@opensynergy.com> Signed-off-by: Mikhail Golubev <Mikhail.Golubev@opensynergy.com> Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org> Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
* libdrm: wrap new flexible syncobj query interface v2Chunming Zhou2019-10-261-0/+15
| | | | | | | | | | 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>
* xf86drm: dedupe drmGetDeviceName() logicEric Engestrom2019-07-031-63/+23
| | | | Signed-off-by: Eric Engestrom <eric.engestrom@intel.com>
* xf86drm: use max size of drm node name instead of arbitrary sizeEric Engestrom2019-07-031-2/+2
| | | | Signed-off-by: Eric Engestrom <eric.engestrom@intel.com>
* xf86drm: dedupe `#define`sEric Engestrom2019-07-031-10/+0
| | | | | | | | | | Adapted from a local patch carried by DragonFlyBSD: https://github.com/DragonFlyBSD/DPorts/blob/bc056f88f7e4d468d8c9751f831a47b5ae1326e3/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>
* xf86drm: open correct render node on non-linuxJonathan Gray2019-07-031-18/+6
| | | | | | | | | | | drm render nodes have the same major as drm primary devices but offset the minor by a base of 128. I expected the name of the device to have numbering starting at 0 when these non-linux codepaths were added (before OpenBSD had render nodes). Signed-off-by: Jonathan Gray <jsg@jsg.id.au> Acked-by: Eric Engestrom <eric.engestrom@intel.com>
* xf86drm: test for render nodes before primary nodesJonathan Gray2019-07-031-4/+4
| | | | | | | | | | Unlike Linux the OpenBSD primary "drm" device name is substring of the "drmR" render node device name and strncmp() tests resulted in render nodes being flagged as primary nodes. Signed-off-by: Jonathan Gray <jsg@jsg.id.au> Reviewed-by: Eric Engestrom <eric.engestrom@intel.com> Acked-by: Eric Engestrom <eric.engestrom@intel.com>
* add timeline signal/transfer ioctls v2Chunming Zhou2019-05-161-0/+33
| | | | | | | v2: use one transfer ioctl Signed-off-by: Chunming Zhou <david1.zhou@amd.com> Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
* add timeline wait/query ioctl v2Chunming Zhou2019-05-161-0/+44
| | | | | | | v2: drop export/import Signed-off-by: Chunming Zhou <david1.zhou@amd.com> Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
* libdrm: Avoid additional drm open closePrabhanjan Kandula2019-04-251-2/+2
| | | | | | | | | | | Avoid additional drm device open and close. Cc: Sean Paul <seanpaul@chromium.org> Cc: Alistair Strachan <astrachan@google.com> Cc: Marissa Wall <marissaw@google.com> Reviewed-by: Alex Deucher <alexander.deucher@amd.com> Reviewed-by: Emil Velikov <emil.velikov@collabora.com> Signed-off-by: John Stultz <john.stultz@linaro.org>
* Revert "libdrm: Fix issue about differrent domainID but same BDF"Emil Velikov2019-04-171-23/+0
| | | | | | | This reverts commit 56c21f877bda7b8c62c3d7925b070b5113d807f2. There were issues pointed out during review that were not addressed. Would love to have this re-land, once those are addressed.