Commit Graph

69 Commits (f803a45e744272190aaaab1ad7c702641190d002)

Author SHA1 Message Date
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
Jan Vesely 50d3c85bdb xf86drm.c: Fix mix of tabs and spaces
Remove whitespace at the end of line.
2016-07-06 16:58:38 +01:00
Nicolai Hähnle 9bdec97a19 xf86drm: ensure proper alignment of pointers in drmProcessPciDevice
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>
2016-06-10 20:15:15 +02:00
Qiang Yu 70b64073f7 drm: fix multi GPU drmGetDevices only return one device
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>
2016-06-06 12:29:16 -04:00
Eric Engestrom ce97507cfc xf86drm: Fix spelling mistakes
Signed-off-by: Eric Engestrom <eric@engestrom.ch>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
2016-04-07 18:16:01 +01:00
Damien Lespiau 3627f38da9 xf86drm: Bound strstr() to the allocated data
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>
2016-01-22 15:50:17 +00:00
Matt Roper ba5a6ecf81 xf86drm: Handle unrecognized subsystems safely in drmGetDevice[s]()
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>
2015-10-20 18:45:23 +01:00
Matt Roper cf0f036e3d xf86drm: Fix error handling for drmGetDevice()
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>
2015-10-20 18:44:58 +01:00
Michel Dänzer 3045523de2 Fix void pointer arithmetic in drmProcessPciDevice
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>
2015-10-14 12:48:52 +09:00
Matt Roper 8c4a1cbd98 xf86drm: Fix error handling for drmGetDevices()
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>
2015-10-02 13:17:03 +01:00
Felix Janda 4031dc17bb xf86drm: include <limits.h> for PATH_MAX
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>
2015-09-28 17:59:55 +01:00
Emil Velikov f3c6740f0c xf86drm: remove makedev() hack/workaround
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>
2015-09-21 17:59:45 +01: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 fae59d7234 xf86drm: split out drmProcessPciDevice and drmFoldDuplicatedDevices
Will be reused in the next commit.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Acked-by: Alex Deucher <alexander.deucher@amd.com>
2015-09-21 17:43:06 +01:00
Emil Velikov 8415a00a3f xf86drm: warn on missing drmGetMinorNameForFD implementation
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Acked-by: Alex Deucher <alexander.deucher@amd.com>
2015-09-21 17:43:03 +01:00
Emil Velikov 291b2bb92c xf86drm: move ifdef __linux__ guards where needed
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Acked-by: Alex Deucher <alexander.deucher@amd.com>
2015-09-21 17:42:57 +01:00
Emil Velikov 5f68d31820 xf86drm: rework drmGetDevices()
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>
2015-09-21 17:42:53 +01:00
Emil Velikov bc2aca9e22 xf86drm: rename drmSameDevice to drmCompareBusInfo
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>
2015-09-21 17:42:48 +01:00
Emil Velikov a250fceaaa xf86drm: move the final linux specific bits out of drmGetDevices
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>
2015-09-21 17:42:46 +01:00
Emil Velikov ef5192e9c7 xf86drm: move platform details to drmParsePciDeviceInfo()
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>
2015-09-21 17:42:43 +01:00
Emil Velikov 536e0deba3 xf86drm: flex platform specifics into drmParsePciBusInfo
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>
2015-09-21 17:42:40 +01:00
Rob Clark eb7c2d5e63 drm: make individual drm_server_info fxns optional
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>
2015-09-04 08:40:57 -04: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
Mathias Tillman 5c42b5e36a drm: fix the usage after free
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>
2015-08-24 11:11:20 +02: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
Jonathan Gray 66c3afb75f xf86drm: correct the OpenBSD DRM_MAJOR define
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>
2015-07-29 18:04:15 +01:00
Emil Velikov c1cd3d9388 xf86drm: fix incorrect fd comparison in drmOpenOnce{,WithType}
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>
2015-07-16 16:41:49 +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
Guillaume Desmottes 4bca42fc50 drmPrime*: initialize output args to 0
Fix Valgrind errors because those memory was uninitialized.

https://bugs.freedesktop.org/show_bug.cgi?id=90194
Signed-off-by: Guillaume Desmottes <guillaume.desmottes@collabora.co.uk>

v2: Explicitly zero the whole struct using memclear.
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
2015-05-28 15:58:34 +01:00
Jammy Zhou 454b149494 Fix one warning (v2)
xf86drm.c:356:2: warning: comparison of unsigned expression >= 0 is always true [-Wtype-limits]
  group = (serv_group >= 0) ? serv_group : DRM_DEV_GID;
  ^

v2: do 'int' cast to fix the warning

Signed-off-by: Jammy Zhou <Jammy.Zhou@amd.com>
Reviewed-by: Jan Vesely <jan.vesely@rutgers.edu>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
2015-05-28 15:49:18 +01:00
Emil Velikov d0e592d4e9 xf86drm: simplify drmMalloc/drmFree
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
2015-05-28 15:40:18 +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 42465feb97 drm: rename libdrm{,_macros}.h
Provide a more meaningful name, considering what it does.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
2015-04-28 11:19:15 +01:00
Connor Behan 1490055bc0 xf86drm: Fix ioctl struct clearing in drmAgpEnable
This one is a bit harder to notice.

Signed-off-by: Connor Behan <connor.behan@gmail.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
2015-04-05 15:33:33 +01:00
Jan Vesely cfbe9c9807 Remove drmSetDebugMsgFunction and related infrastructure
Not used anywhere

Signed-off-by: Jan Vesely <jan.vesely@rutgers.edu>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
2015-03-20 17:36:04 -04:00
Jan Vesely 6fc0e4ba1e Fix unused function warnings
v2: Remove the handler function instead of commenting out
    split debugmsg function removal to a separate patch

Signed-off-by: Jan Vesely <jan.vesely@rutgers.edu>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
2015-03-20 13:36:53 -04:00
Jan Vesely 0706c14e7c Fix unused, and unused-but-set variables warnings
Signed-off-by: Jan Vesely <jan.vesely@rutgers.edu>
Reviewed-by: Emil Velikov <eil.l.velikov@gmail.com>
2015-03-14 17:02:06 -04:00
Alan Coopersmith 0e1135de5c On Solaris, #include <sys/mkdev.h> in xf86drm.c
Needed on Solaris for the definitions of major() & minor() used in
drmGetNodeTypeFromFd() and makedev() used in drmOpenMinor()

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
2015-03-14 08:37:36 -07: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
Daniel Vetter 95f23cf894 xf86drm: Fix ioctl struct clearing in drmGetVersion
Oops, fumbled that one.

Reported-by: Jan Vesely <jan.vesely@rutgers.edu>
Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
2015-02-11 17:25:30 +01:00
Daniel Vetter fd38794344 xf86drm: Unconditionally clear ioctl structs
We really have to do this to avoid surprises when extending the ABI
later on. Especially when growing the structures.

A bit overkill to update all the old legacy ioctl wrappers, but can't
hurt really either.

Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Rob Clark <robdclark@gmail.com>
Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
2015-02-11 15:37:17 +01:00
Daniel Vetter 80834b377e drm: use drmIoctl everywhere
Well just core drm. All the other callers in there that still use
direct calls to ioctl have some custom retry logic already, so should
be good already.

All the other offenders (tests, freedreno/kgsl, ...) don't really
matter (e.g. kgsl is the blob library and so not a drm thing) or are
again special exceptions with their own retry loops.

Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Rob Clark <robdclark@gmail.com>
Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
2015-02-11 15:36:43 +01:00
Jan Vesely de8532dd83 Fix gcc -Wextra warnings
Signed-off-by: Jan Vesely <jan.vesely@rutgers.edu>
Reviewed-by: Ian Romanick <idr@freedesktop.org>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
2015-02-10 15:25:28 -05:00