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>
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>
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>
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>
This reverts commit 56c21f877b.
There were issues pointed out during review that were not addressed.
Would love to have this re-land, once those are addressed.
Saw a couple of typos fixes in the patch DragonFlyBSD carries [1], so
I ran codespell (a spell checker for code) on the whole repo.
[1] https://github.com/DragonFlyBSD/DPorts/blob/master/graphics/libdrm/files/patch-xf86drm.c
Signed-off-by: Eric Engestrom <eric.engestrom@intel.com>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
This fixes a bug, which was introduced with commit ee798b98
"xf85drm: de-duplicate drmParse{Platform.Host1x}{Bus,Device}Info".
where accessing *compatible[i] with i>0 results in a segfault.
Signed-off-by: Andreas Baierl <ichgeh@imkreisrum.de>
Fixes: ee798b9847 "xf85drm: de-duplicate drmParse{Platform.Host1x}{Bus,Device}Info"
Reviewed-by: Eric Engestrom <eric.engestrom@intel.com>
[Eric: add the same fix to the free() below]
Signed-off-by: Eric Engestrom <eric.engestrom@intel.com>
For multiple GPUs which has the same BDF, but has different domain ID,
the drmOpenByBusid will return the wrong fd when startx.
The reproduce sequence as below:
1. Call drmOpenByBusid to open Card0, then will return the right fd0, and the
fd0 is master privilege;
2. Call drmOpenByBusid to open Card1. In function drmOpenByBusid, it will
open Card0 first, this time, the fd1 for opening Card0 is not master
privilege, and will call drmSetInterfaceVersion to identify the
domain ID feature, as the fd1 is not master privilege, then drmSetInterfaceVersion
will fail, and then won't compare domain ID, then return the wrong fd for Card1.
Solution:
First loop search the best match fd about drm 1.4.
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Emily Deng <Emily.Deng@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
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>
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>
The functions are virtually identical, fold them up.
v2: foo -> tmp_name (Eric)
Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
Reviewed-by: Eric Engestrom <eric.engestrom@intel.com>
Some devices can lack OF data or it may not be available in the uevent
file. Fallback to the MODALIAS data in those cases.
We strip any leading "MODALIAS=.*:" thus the resulting information is
compatible with existing code in Mesa.
v2: foo -> tmp_name
Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
Tested-by: Lucas Stach <l.stach@pengutronix.de> (v1)
It is a cleaner and less fragile way to get PCI IDs than the one
currently used by local DPorts patches.
Signed-off-by: François Tigeot <ftigeot@wolfpond.org>
For ARM systems with tinydrm displays attached to SPI, the bus name is
/spi but we have platform device info for the rest. Fixes
eglInitialize() failures on hx8357d since the EGL_EXT_device_drm
changes.
Acked-by: Eric Engestrom <eric.engestrom@intel.com>
To determine whether a device node is a drm device node or not, the code
currently compares the node's major number to the static drm major device
number.
This breaks the standalone vmwgfx driver on XWayland dri clients,
https://cgit.freedesktop.org/mesa/vmwgfx
and any future attempt to introduce dynamic device numbers for drm.
So instead of checking for the device major, instead check for the presence
of the /sys/dev/char/<major>:<minor>/device/drm directory.
Signed-off-by: Thomas Hellstrom <thellstrom@vmware.com>
Reviewed-by: Eric Engestrom <eric.engestrom@intel.com>
Acked-by: Dave Airlie <airlied@redhat.com>
This was done with:
nm --dynamic --defined-only build/libdrm.so | \
grep " T " | \
grep -v _fini | grep -v _init | \
cut -d' ' -f3 > /tmp/a.txt
while read sym; do
read f func line _ <<<$(cscope -d -L -1 $sym)
if [ ! -z "$f" ]; then
sed -i "${line}s/^/drm_public /" $f
fi
done < /tmp/a.txt
Then the alignment of function arguments were manually fixed all over.
The idea here will be to switch the default visibility to hidden so we
don't export symbols we shouldn't.
Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
Reviewed-by: Eric Engestrom <eric.engestrom@intel.com>
"real_path" was getting confusing when there are other *paths in the
same functions.
Signed-off-by: Eric Engestrom <eric.engestrom@intel.com>
Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
Earlier commit reworked our sysfs handling to use realpath.
Sadly that backfired since the Firefox sandboxing mechanism rejects
that. Despite the files/folders being in the allowed list, of the
sandboxing mechanism.
Oddly enough, the Chromium sandboxing doesn't complain about any of
this.
Since there are no Firefox releases with the fix, add a temporary
solution which falls back to the original handling.
Sadly, this won't work for virgl.
v2: drop return type - function cannot return NULL (Eric)
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=107516
Fixes: a02900133b ("xf86drm: introduce a get_real_pci_path() helper")
Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>
Tested-by: Michel Dänzer <michel.daenzer@amd.com>
Reviewed-by: Eric Engestrom <eric.engestrom@intel.com>
In drmGetDevice2 when no local device is found or when
drm_device_has_rdev filters out all devices, *device might be left
uninitialized causing drmGetDevice2 to not return error - since
it's only returned when *device == NULL.
Above leads to crash in the firefox in system with amdgpu.
With this change firefox displays:
libGL error: MESA-LOADER: failed to retrieve device information
libGL error: unable to load driver: amdgpu_dri.so
libGL error: driver pointer missing
libGL error: failed to load driver: amdgpu
libGL error: MESA-LOADER: failed to retrieve device information
libGL error: unable to load driver: amdgpu_dri.so
libGL error: driver pointer missing
libGL error: failed to load driver: amdgpu
and doesn't crash.
Bugzilla: https://bugs.freedesktop.org/107384
Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>
Signed-off-by: Mariusz Ceier <mceier+mesa-dev@gmail.com>
The GPU almost exclusively lives on the PCI bus, so we expose it as a
normal PCI one.
This allows all existing drmDevice users to work without any changes.
One could wonder why a separate typeset is not introduced, alike say
host1x. Unlike host1x the PCI/platform distinction for virtio provides
no extra information. Plus if needed we can add the separate set at a
later stage.
Here are a few 'features' that virtio seems to be missing:
- provides extra information on top the plaform devices
- supports a range of GPU devices
- is considered hardware description (DT)
Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
Tested-by: Robert Foss <robert.foss@collabora.com>
Reviewed-by: Robert Foss <robert.foss@collabora.com>
Reviewed-by: Eric Engestrom <eric@engestrom.ch>
Introduce a helper which gets the real sysfs path for the given pci
device.
In other words, instead opening the /sys/dev/char/*/device symlink, we
opt for the actual /sys/devices/pci*/*/
It folds three (nearly identical) snprintf's and paves the way of adding
extra devices (see next patch) a piece of pie.
v2: use a caller (on stack) provided real_path (Eric)
Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
Tested-by: Robert Foss <robert.foss@collabora.com> (v1)
Reviewed-by: Robert Foss <robert.foss@collabora.com> (v1)
Reviewed-by: Eric Engestrom <eric@engestrom.ch> (v1)
Currently we dynamically allocate 16 pointers and reallocate more as
needed.
Instead, allocate the maximum number (256) on stack - the number is
small enough and is unlikely to change in the foreseeable future.
This allows us to simplify the error handling and even shed a few bytes
off the final binary.
v2:
- add a define & description behind the magic 256
- report error to strerr and skip when over 256 device nodes
Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
Tested-by: Robert Foss <robert.foss@collabora.com> (v1)
Reviewed-by: Robert Foss <robert.foss@collabora.com>
Reviewed-by: Eric Engestrom <eric@engestrom.ch> (v1)
Don't duplicate the nearly identical code across the two call sites.
It improves legibility and the diff stat seems nice.
Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
Tested-by: Robert Foss <robert.foss@collabora.com>
Reviewed-by: Robert Foss <robert.foss@collabora.com>
Reviewed-by: Eric Engestrom <eric@engestrom.ch>
Currently we match the opened drmDevice fd with each drmDevice we
process.
Move that after all the devices are processed and folded, via the
drm_device_has_rdev(). This makes the code easier to follow and allows
us to unify the massive process loop across drmGetDevice2 and
drmGetDevices2. That in itself is coming with a later commit.
Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
Tested-by: Robert Foss <robert.foss@collabora.com>
Reviewed-by: Robert Foss <robert.foss@collabora.com>
Reviewed-by: Eric Engestrom <eric@engestrom.ch>
Currently one can open() any /dev node. If it's unknown
drmParseSubsystemType() will return an error.
Track that and bail as needed.
Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
Tested-by: Robert Foss <robert.foss@collabora.com>
Reviewed-by: Robert Foss <robert.foss@collabora.com>
Reviewed-by: Eric Engestrom <eric@engestrom.ch>
removed in commit bb45ce4e3a
Adding it back as it is still needed in the case where we don't find a
match.
Signed-off-by: Kevin Strasser <kevin.strasser@intel.com>
Fixes: bb45ce4e3a "libdrm: Use readdir instead of readdir_r to
avoid build warnings"$
Reviewed-by: Eric Engestrom <eric.engestrom@intel.com>
Building libdrm under AOSP, we see the following build warning:
external/libdrm/xf86drm.c:2861:12: warning: 'readdir_r' is deprecated: readdir_r is deprecated; use readdir instead [-Wdeprecated-declarations]
while (readdir_r(sysdir, pent, &ent) == 0 && ent != NULL) {
^
Building on Linux with glibc produces the same warning.
Thus, this patch replaces readdir_r with readdir.
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=102031
Cc: Robert Foss <robert.foss@collabora.com>
Cc: Rob Herring <robh@kernel.org>
Cc: Stefan Schake <stschake@gmail.com>
Cc: John Stultz <john.stultz@linaro.org>
Signed-off-by: John Stultz <john.stultz@linaro.org>
Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
[Emil Velikov: remove unused variables, Eric]
Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
Reviewed-by: Eric Engestrom <eric.engestrom@imgtec.com>
This will prevent any more missing `#include "config.h"` bug, at the
cost of having to recompile some files that didn't need to be when
changing build options.
Signed-off-by: Eric Engestrom <eric.engestrom@imgtec.com>
Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
Otherwise we get an EFAULT, at least on a 64-bit kernel.
Fixes: 2048a9e7 "drm: add drmSyncobjWait wrapper"
Reviewed-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Dave Airlie <airlied@redhat.com>
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>
Analogous to previous commit (and the rest of the codebase), simply
discard the device if we cannot parse it.
Fixes: f8484ccbd1 ("xf86drm: Add USB support")
Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
On ChromeOS devices, readdir() processes the directory in
the following order:
-NAME- -TYPE-
. n/a
.. n/a
vgem n/a
card1 DRM_BUS_PLATFORM
renderD129 DRM_BUS_PLATFORM
card0 DRM_BUS_PCI
renderD128 DRM_BUS_PCI
controlD64 DRM_BUS_PCI
In drmGetDevices2, after drmProcessPlatformDevice fails for
/dev/dri/card1, we don't process the remaining directory entries.
As such, Vulkan fails to initialize since Mesa uses drmGetDevices2.
To fix this, continue if drmProcessPlatformDevice fails.
Fixes: 7b1f37f474 ("xf86drm: Add platform and host1x bus support")
Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
[Emil: correct the host1x platforms as well]
Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
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>
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>
In error path of drmGetBusid() and drmGetReservedContextList(),
there are memory leaks for error path. So this removes them.
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Reviewed-by: Nicolai Hähnle <nicolai.haehnle@amd.com>
Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
Recent patches for USB, platform and host1x bus support introduced the
sysfs_uevent_get() function that provides a generic way of parsing the
sysfs uevent file that is associated with each device in Linux.
Open-coded variants of this still exist in other places, so make those
reuse the new function to remove some code duplication.
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Signed-off-by: Thierry Reding <treding@nvidia.com>
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>
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>
Subsequent patches will add support for other bus types to drmDevice and
they will duplicate a lot of the code to allocate a drmDevice. Factor
out the common code so it can be reused.
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Signed-off-by: Thierry Reding <treding@nvidia.com>
The string written to the buffer by read() is not null-terminated,
but currently drmParsePciBusInfo() places null character only at the end of the buffer, not at the end of the
string.
As a result, the string passed to sscanf() contains an uninitialized value.
This patch changes to places null character at the end of the string.
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=99045
Signed-off-by: Taro Yamada <archer_ame@yahoo.co.jp>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
libdrm uses spaces for indentation. Fix the two inconsistent lines in
this file.
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Signed-off-by: Thierry Reding <treding@nvidia.com>
When iterating over all the device nodes if drmProcessPciDevice()
returned an error for any node the function would return an error,
ignoring any valid nodes.
The result of this on OpenBSD where drmProcessPciDevice() results in
device nodes being opened to issue ioctls to get pci data
was that data obtained from /dev/drm0 would be ignored if /dev/drm1
could not be opened.
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Signed-off-by: Jonathan Gray <jsg@jsg.id.au>
Implement a generic drmGetDeviceNameFromFd2() to use on non-linux
systems without sysfs.
v2: remove min < base test as requested by Emil
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Signed-off-by: Jonathan Gray <jsg@jsg.id.au>
When constructing a path to a device node the minor number retrieved
from fstat needs to have the offset of the node type subtracted from it.
Control and render node types have the same major as the primary node
but each has their own block of minor types at fixed offsets.
v2: remove min < base test as requested by Emil
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Signed-off-by: Jonathan Gray <jsg@jsg.id.au>
xf86drm.c:3601:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while (expected < sizeof(match)) {
^
Signed-off-by: Grazvydas Ignotas <notasas@gmail.com>
Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
DRI devices on OpenBSD are not in their own directory. They reside in
/dev with a large number of statically generated /dev nodes.
Avoid stat'ing all of /dev on OpenBSD by implementing this custom path.
v2:
- use drmGetMinorType to get node type
- adapt to drmProcessPciDevice changes
- verify drmParseSubsystemType type is PCI
- add a comment describing why this was added
Signed-off-by: Jonathan Gray <jsg@jsg.id.au>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Implement drmParsePciBusInfo for OpenBSD by using the new
DRM_IOCTL_GET_PCIINFO ioctl.
v2: use drmGetMinorType to get node type instead of always
using DRM_NODE_PRIMARY.
Signed-off-by: Jonathan Gray <jsg@jsg.id.au>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Implement drmParsePciDeviceInfo for OpenBSD by using the new
DRM_IOCTL_GET_PCIINFO ioctl.
v2: adapt to drmParsePciDeviceInfo changes and use drmOpenMinor
Signed-off-by: Jonathan Gray <jsg@jsg.id.au>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Implement drmParseSubsystemType for OpenBSD by always returning
DRM_BUS_PCI. No non-pci drm drivers are in the kernel and this is
unlikely to change anytime soon as the existing ones aren't permissively
licensed.
Signed-off-by: Jonathan Gray <jsg@jsg.id.au>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Implement drmGetMinorNameForFD for systems without sysfs by
adapting drm_get_device_name_for_fd() from the Mesa loader.
v2: use type parameter to select dev name instead of always
using DRM_DEV_NAME
Signed-off-by: Jonathan Gray <jsg@jsg.id.au>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
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>
Up-to recently (patch should land in 4.10) the kernel did not expose the
PCI device revision field as a separate sysfs file.
Thus one needed too parse the config file to retrieve it. This in
itself wakes up the device, which in some cases can be quite slow.
To avoid that, just check for the separate files and fall-back to the
original if kernel is not new enough.
v3: rework alongside drmGetDevice[s]2
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>
Will be used with the drmGetDevice[s]2 API.
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>
Be consistent with drmParsePciBusInfo() and use solely the device
major/minor pair.
Cc: Jonathan Gray <jsg@jsg.id.au>
Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
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>
Some platforms (such as Macs using OF) can have more information in the
uevent file thus reading only the first 128 might not be sufficient.
Bump it to 512, which "should be enough for everybody" ;-)
v2: Use sizeof(data)-1 over hardcoded number (Eric).
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=98629
Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
Reported-by: Mingcong Bai <jeffbai@aosc.xyz>
Tested-by: Mingcong Bai <jeffbai@aosc.xyz> (v1)
Reviewed-by: Eric Engestrom <eric.engestrom@imgtec.com>
glxgears was spamming this 12 times at startup because of Mesa's
probing of the DRM device code, which doesn't support platform
devices.
Signed-off-by: Eric Anholt <eric@anholt.net>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Fixes crashes in Mesa on platform devices, which expected *device to
have a device when 0 was returned.
(code from a paste by Rob, commit message by anholt)
Signed-off-by: Eric Anholt <eric@anholt.net>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
When in multi GPU case, devices array may have some
NULL "hole" in between two devices. So check all
array elements and free non-NULL device.
Signed-off-by: Qiang Yu <Qiang.Yu@amd.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Currently drmGetDevice always returns the first device it finds under
/dev/dri/.
Move the target device to the start of the list during iteration. This
way during deduplication it'll preserve its place and will be returned
to the user.
v2: Keep the memory leak separate.
v3: Move the drmFoldDuplicatedDevices description
Signed-off-by: Qiang Yu <Qiang.Yu@amd.com>
[Emil Velikov: move drmFoldDuplicatedDevices description, add
changelog, reword commit message]
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
This header provides major/minor/makedev funcs under most Linux C
libs. Pull it in to fix building with newer versions that drop the
implicit include via sys/types.h.
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=94231
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Previously, (*device)->businfo.pci would end up misaligned, which results
in undefined behavior.
Signed-off-by: Nicolai Hähnle <nicolai.haehnle@amd.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
When multi GPU present, after drmFoldDuplicatedDevices
merge same busid deveces, two different devices may be
seperated by zero in local_devices[]. The for loop
should check all local_devices instead of exit when
meet a zero.
Reviewed-by: Jim Qu <Jim.Qu@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Qiang Yu <Qiang.Yu@amd.com>
We are reading at most sizeof(data) bytes, but then data may not contain
a terminating '\0', at least in theory, so strstr() may overflow the
stack allocated array.
Make sure that data always contains at least one '\0'.
Signed-off-by: Damien Lespiau <damien.lespiau@intel.com>
Reviewed-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Both drmGetDevice() and drmGetDevices() currently print a warning when
they encounter an unknown (non-PCI) subsystem type for a device node,
but they still proceed to assume that the drmDevicePtr was initialized
and try to add it to the local device array. Add a 'continue' to the
error case handling to bypass the rest of the processing for devices we
can't handle.
Signed-off-by: Matt Roper <matthew.d.roper@intel.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Some of the error conditions in drmGetDevice() can lead to us calling
closedir(NULL) or leaking memory. Fix these conditions the same way we
did for drmGetDevices() in commit:
commit 8c4a1cbd98
Author: Matt Roper <matthew.d.roper@intel.com>
Date: Wed Sep 30 09:30:51 2015 -0700
xf86drm: Fix error handling for drmGetDevices()
Signed-off-by: Matt Roper <matthew.d.roper@intel.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Arithmetic on void pointers is a GCC extension.
CC libdrm_la-xf86drm.lo
../xf86drm.c: In function 'drmProcessPciDevice':
../xf86drm.c:3017:10: warning: pointer of type 'void *' used in arithmetic [-Wpointer-arith]
addr += sizeof(drmDevice);
^
../xf86drm.c:3020:10: warning: pointer of type 'void *' used in arithmetic [-Wpointer-arith]
addr += DRM_NODE_MAX * sizeof(void *);
^
../xf86drm.c:3023:14: warning: pointer of type 'void *' used in arithmetic [-Wpointer-arith]
addr += max_node_str;
^
../xf86drm.c:3035:14: warning: pointer of type 'void *' used in arithmetic [-Wpointer-arith]
addr += sizeof(drmPciBusInfo);
^
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
If the opendir() call in drmGetDevices() returns failure, we jump to an
error label that calls closedir() and then returns. However this means
that we're calling closedir(NULL) which may not be safe on all
implementations. We are also leaking the local_devices array that was
allocated before the opendir() call.
Fix both of these issues by jumping to an earlier error label (to free
local_devices) and guarding the closedir() call with a NULL test.
Signed-off-by: Matt Roper <matthew.d.roper@intel.com>
[Emil Velikov: make the teardown symmetrical, remove the NULL check]
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
fixes compilation error with musl libc and Solaris based platforms.
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=92082
Signed-off-by: Felix Janda <felix.janda@posteo.de>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Back when this was introduced commit 569da5a42eb(Merged glxmisc-3-0-0)
sys/sysmacros.h was used instead of the respecive headers (as per the
manual).
We've been handling it correctly for a little while now - in Linux, BSD
and Solaris. Thus we can drop this workaround.
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
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>
Do a once off memory allocation for each drmDevice.
This allows us to ease the error handling and simplify the
de-duplication loop. As part of this we need to rework drmFreeDevice()
such so that it frees the relevant hunks, rather than leaving that to
the caller.
Some memory stats from the drmdevice test
before: 22 allocs, 22 frees, 66,922 bytes allocated
after: 9 allocs, 9 frees, 66,436 bytes allocated
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Acked-by: Alex Deucher <alexander.deucher@amd.com>
Move away form the boolean name, change the return value
appropriately and check if either argument is NULL.
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Acked-by: Alex Deucher <alexander.deucher@amd.com>
Third and final piece of making drmGetDevices less crazy/ugly.
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Acked-by: Alex Deucher <alexander.deucher@amd.com>
As with previous commit let's try to keep drmGetDevices clean of linux
specifics.
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Acked-by: Alex Deucher <alexander.deucher@amd.com>
This will allow one to reuse the core drmGetDevices implementation on
other platforms. Keeping all the platform specifics in ParseFoo.
On the plus side this saves a bit of code :)
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Acked-by: Alex Deucher <alexander.deucher@amd.com>
For android / drm_gralloc, we want to hook up our own debug_print()
without bothering with the reset of it.
Signed-off-by: Rob Clark <robdclark@gmail.com>
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>
For readdir_r(), the next directory entry is returned in caller-allocted
buffer (pointered by pent here).
https://bugs.freedesktop.org/show_bug.cgi?id=91704
Signed-off-by: Mathias Tillman <master.homer@gmail.com>
Signed-off-by: Jammy Zhou <Jammy.Zhou@amd.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
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>
As far as I can tell no OpenBSD platform ever used 81
for a drm major. While the value was added to libdrm in 2003
or earlier drm didn't appear in OpenBSD till 2007.
Of the OpenBSD platforms that support drm amd64/macppc/sparc64
use a major of 87, i386 uses 88.
v2: rearrange ifdefs as suggested by Emil.
Signed-off-by: Jonathan Gray <jsg@jsg.id.au>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Spotted by looking for similar "let's assume fd == 0 is invalid" bugs.
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Thierry Reding <treding@nvidia.com>