Commit Graph

114 Commits (9c979e0ec4052acc93da94f477c3d3d6139ebd31)

Author SHA1 Message Date
Emil Velikov 3988580e4c xf86drm: Add drmDevice support for virtio_gpu
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>
2018-07-24 16:25:05 +01:00
Emil Velikov a02900133b xf86drm: introduce a get_real_pci_path() helper
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)
2018-07-24 16:24:45 +01:00
Emil Velikov 95b262f019 xf86drm: Allocate drmDevicePtr's on stack
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)
2018-07-24 16:24:31 +01:00
Emil Velikov f808fee90d xf86drm: Fold drmDevice processing into process_device() helper
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>
2018-07-24 16:24:26 +01:00
Emil Velikov 56e72d3f2e xf86drm: introduce drm_device_has_rdev() helper
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>
2018-07-24 16:24:14 +01:00
Emil Velikov 7f52a0ebf7 xf86drm: drmGetDevice2: error out if the fd has unknown subsys
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>
2018-07-24 16:24:04 +01:00
Michel Dänzer 35615697f7 Always pass O_CLOEXEC when opening DRM file descriptors
Reviewed-by: Christian König <christian.koenig@amd.com>
2018-05-22 18:05:19 +02:00
Kevin Strasser f34b6942ec xf86drm: Be sure to closedir before return
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>
2018-05-21 15:06:48 +01:00
John Stultz bb45ce4e3a libdrm: Use readdir instead of readdir_r to avoid build warnings
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>
2018-03-22 16:47:47 +00:00
Eric Engestrom 0926f0af54 meson,configure: include config.h automatically
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>
2018-03-20 18:19:26 +00:00
Eric Engestrom 07585200e9 meson,configure: always define UDEV
Signed-off-by: Eric Engestrom <eric.engestrom@imgtec.com>
Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
Reviewed-by: Dylan Baker <dylan@pnwbakers.com>
2018-03-20 14:31:14 +00:00
Chunming Zhou bde3b9b689 fix return value for syncobj wait
otherwise -ETIME is missed.

Signed-off-by: Chunming Zhou <david1.zhou@amd.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
2018-02-07 11:23:01 +08:00
Bas Nieuwenhuizen b1e63d9ee6 drm: Fix 32-bit drmSyncobjWait.
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>
2018-02-06 18:15:32 +01: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
Dave Airlie 61ff9779e3 drm/syncobj: fix some whitespace issues
These had tabs, just remove them.

Signed-off-by: Dave Airlie <airlied@redhat.com>
2017-10-25 07:44:31 +01: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
Emil Velikov 3876bc246a xf86drm: continue with next device if drmProcessUsbDevice fails
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>
2017-07-20 12:25:27 +01:00
Gurchetan Singh 5226b52773 xf86drm: continue after drmProcessPlatformDevice failure
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>
2017-07-20 12:23:58 +01:00
coypu ac21401790 Remove redundant memclear
drmMalloc will zero out the memory for us

Reviewed-by: Eric Engestrom <eric.engestrom@imgtec.com>
2017-07-07 10:49:40 +01: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 a2fa2e0869 Fix stray caller of drmCompareDevices
Signed-off-by: Adam Jackson <ajax@redhat.com>
2017-05-04 15:57:14 -04: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
Seung-Woo Kim 7b806e8789 xf86drm: remove memory leaks in drmGetBusid/drmGetReservedContextList
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>
2017-04-03 17:46:06 +01:00
Thierry Reding 5403cb39c1 xf86drm: Reuse sysfs_uevent_get()
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>
2017-01-20 16:27:33 +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
Thierry Reding 2e57bba870 xf86drm: Factor out drmDeviceAlloc()
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>
2017-01-20 16:25:35 +01:00
Taro Yamada 4ecd1ef010 xf86drm: fix null termination of string buffer
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>
2017-01-16 14:41:36 +00:00
Thierry Reding e17cad1994 xf86drm: Fix indentation
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>
2017-01-12 22:40:41 +01:00
Jonathan Gray eebefaf72c xf86drm: don't fatal on per device error in drmGetDevice[s]2
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>
2016-12-24 17:06:58 +00:00
Jonathan Gray e2e766d5ac xf86drm: add a non-sysfs version of drmGetDeviceNameFromFd2
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>
2016-12-24 17:06:53 +00:00
Jonathan Gray d5cf3f9831 xf86drm: adjust device node path for minor base
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>
2016-12-24 17:06:49 +00:00
Grazvydas Ignotas 3bc14c8cb9 xf86drm: fix sign-compare warning
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>
2016-12-12 14:01:19 +00:00
Jonathan Gray 0825792723 xf86drm: implement an OpenBSD specific drmGetDevice2
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>
2016-12-05 17:53:11 +00:00
Jonathan Gray fd190564da xf86drm: implement drmParsePciBusInfo for OpenBSD
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>
2016-12-05 17:53:05 +00:00
Jonathan Gray c0ef1d0788 xf86drm: implement drmParsePciDeviceInfo for OpenBSD
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>
2016-12-05 17:53:00 +00:00
Jonathan Gray d05b9f2dde xf86drm: implement drmParseSubsystemType for OpenBSD
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>
2016-12-05 17:52:53 +00:00
Jonathan Gray f189011b36 xf86drm: implement drmGetMinorNameForFD for non-sysfs
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>
2016-12-05 17:52:46 +00: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 aae3f318d5 xf86drm: parse the separate sysfs files for vendor... info
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>
2016-12-05 17:21:23 +00:00
Emil Velikov 138d23117c xf86drm: add plumbing to not retrieve PCI device revision
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>
2016-12-05 17:17:35 +00:00
Emil Velikov b40a65d448 xf86drm: use maj/min in drmParsePciDeviceInfo()
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>
2016-12-05 17:17:22 +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 f53d3542c1 xd86drm: read more than 128 bytes of uevent in drmParsePciBusInfo
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>
2016-11-14 19:53:04 +00:00
Eric Anholt 2d8c01f256 Silence runtime complaints on platform devices
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>
2016-10-21 12:50:56 -07:00
Rob Herring 677cd97dc4 Return an -ENODEV from drmGetDevice() when no device was found.
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>
2016-10-21 12:50:50 -07:00
Qiang Yu 6c056eecd5 drm: fix drmFreeDevices memory leak on multi GPU setups
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>
2016-07-20 23:44:40 +01:00
Qiang Yu 3c20893daa drm: drmGetDevice return correct device on multi GPU setups
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>
2016-07-20 23:38:35 +01:00
Mike Frysinger 8c8d5dd76f pull in sys/sysmacros.h when available
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>
2016-07-06 16:58:38 +01:00