2013-06-07 11:28:45 -06:00
|
|
|
#ifdef HAVE_XORG_CONFIG_H
|
|
|
|
#include <xorg-config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef XSERVER_PLATFORM_BUS
|
|
|
|
|
|
|
|
#include <xf86drm.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
2014-05-02 13:27:46 -06:00
|
|
|
#include <errno.h>
|
|
|
|
#include <string.h>
|
2013-06-07 11:28:45 -06:00
|
|
|
|
|
|
|
/* Linux platform device support */
|
|
|
|
#include "xf86_OSproc.h"
|
|
|
|
|
|
|
|
#include "xf86.h"
|
|
|
|
#include "xf86platformBus.h"
|
|
|
|
#include "xf86Bus.h"
|
|
|
|
|
|
|
|
#include "hotplug.h"
|
2014-09-27 11:52:59 -06:00
|
|
|
#include "systemd-logind.h"
|
2013-06-07 11:28:45 -06:00
|
|
|
|
|
|
|
static Bool
|
2013-08-24 13:44:25 -06:00
|
|
|
get_drm_info(struct OdevAttributes *attribs, char *path, int delayed_index)
|
2013-06-07 11:28:45 -06:00
|
|
|
{
|
|
|
|
drmSetVersion sv;
|
2014-09-27 11:52:59 -06:00
|
|
|
drmVersionPtr v;
|
2013-06-07 11:28:45 -06:00
|
|
|
char *buf;
|
2014-09-27 11:52:59 -06:00
|
|
|
int major, minor, fd;
|
2014-05-02 13:27:46 -06:00
|
|
|
int err = 0;
|
2014-09-27 11:52:59 -06:00
|
|
|
Bool paused, server_fd = FALSE;
|
|
|
|
|
|
|
|
major = config_odev_get_int_attribute(attribs, ODEV_ATTRIB_MAJOR, 0);
|
|
|
|
minor = config_odev_get_int_attribute(attribs, ODEV_ATTRIB_MINOR, 0);
|
|
|
|
|
|
|
|
fd = systemd_logind_take_fd(major, minor, path, &paused);
|
|
|
|
if (fd != -1) {
|
|
|
|
if (paused) {
|
|
|
|
LogMessage(X_ERROR,
|
|
|
|
"Error systemd-logind returned paused fd for drm node\n");
|
|
|
|
systemd_logind_release_fd(major, minor, -1);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
config_odev_add_int_attribute(attribs, ODEV_ATTRIB_FD, fd);
|
|
|
|
server_fd = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fd == -1)
|
|
|
|
fd = open(path, O_RDWR, O_CLOEXEC);
|
2013-06-07 11:28:45 -06:00
|
|
|
|
|
|
|
if (fd == -1)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
sv.drm_di_major = 1;
|
|
|
|
sv.drm_di_minor = 4;
|
|
|
|
sv.drm_dd_major = -1; /* Don't care */
|
|
|
|
sv.drm_dd_minor = -1; /* Don't care */
|
2014-05-02 13:27:46 -06:00
|
|
|
|
|
|
|
err = drmSetInterfaceVersion(fd, &sv);
|
|
|
|
if (err) {
|
2014-09-27 11:52:59 -06:00
|
|
|
xf86Msg(X_ERROR, "%s: failed to set DRM interface version 1.4: %s\n",
|
|
|
|
path, strerror(-err));
|
|
|
|
goto out;
|
2013-06-07 11:28:45 -06:00
|
|
|
}
|
|
|
|
|
2013-08-24 13:44:25 -06:00
|
|
|
/* for a delayed probe we've already added the device */
|
|
|
|
if (delayed_index == -1) {
|
2014-09-27 11:52:59 -06:00
|
|
|
xf86_add_platform_device(attribs, FALSE);
|
2013-08-24 13:44:25 -06:00
|
|
|
delayed_index = xf86_num_platform_devices - 1;
|
|
|
|
}
|
2013-06-07 11:28:45 -06:00
|
|
|
|
2014-09-27 11:52:59 -06:00
|
|
|
if (server_fd)
|
|
|
|
xf86_platform_devices[delayed_index].flags |= XF86_PDEV_SERVER_FD;
|
|
|
|
|
2013-06-07 11:28:45 -06:00
|
|
|
buf = drmGetBusid(fd);
|
2013-08-24 13:44:25 -06:00
|
|
|
xf86_add_platform_device_attrib(delayed_index,
|
2013-06-07 11:28:45 -06:00
|
|
|
ODEV_ATTRIB_BUSID, buf);
|
|
|
|
drmFreeBusid(buf);
|
2014-09-27 11:52:59 -06:00
|
|
|
|
|
|
|
v = drmGetVersion(fd);
|
|
|
|
if (!v) {
|
|
|
|
xf86Msg(X_ERROR, "%s: failed to query DRM version\n", path);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
xf86_add_platform_device_attrib(delayed_index, ODEV_ATTRIB_DRIVER,
|
|
|
|
v->name);
|
|
|
|
drmFreeVersion(v);
|
|
|
|
|
2014-05-02 13:27:46 -06:00
|
|
|
out:
|
2014-09-27 11:52:59 -06:00
|
|
|
if (!server_fd)
|
|
|
|
close(fd);
|
2014-05-02 13:27:46 -06:00
|
|
|
return (err == 0);
|
2013-06-07 11:28:45 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
Bool
|
|
|
|
xf86PlatformDeviceCheckBusID(struct xf86_platform_device *device, const char *busid)
|
|
|
|
{
|
|
|
|
struct OdevAttribute *attrib;
|
|
|
|
const char *syspath = NULL;
|
|
|
|
BusType bustype;
|
|
|
|
const char *id;
|
|
|
|
xorg_list_for_each_entry(attrib, &device->attribs->list, member) {
|
|
|
|
if (attrib->attrib_id == ODEV_ATTRIB_SYSPATH) {
|
|
|
|
syspath = attrib->attrib_name;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!syspath)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
bustype = StringToBusType(busid, &id);
|
|
|
|
if (bustype == BUS_PCI) {
|
|
|
|
struct pci_device *pPci = device->pdev;
|
|
|
|
if (xf86ComparePciBusString(busid,
|
|
|
|
((pPci->domain << 8)
|
|
|
|
| pPci->bus),
|
|
|
|
pPci->dev, pPci->func)) {
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (bustype == BUS_PLATFORM) {
|
|
|
|
/* match on the minimum string */
|
|
|
|
int len = strlen(id);
|
|
|
|
|
|
|
|
if (strlen(syspath) < strlen(id))
|
|
|
|
len = strlen(syspath);
|
|
|
|
|
|
|
|
if (strncmp(id, syspath, len))
|
|
|
|
return FALSE;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2013-08-24 13:44:25 -06:00
|
|
|
void
|
|
|
|
xf86PlatformReprobeDevice(int index, struct OdevAttributes *attribs)
|
|
|
|
{
|
|
|
|
Bool ret;
|
|
|
|
char *dpath;
|
|
|
|
dpath = xf86_get_platform_attrib(index, ODEV_ATTRIB_PATH);
|
|
|
|
|
|
|
|
ret = get_drm_info(attribs, dpath, index);
|
|
|
|
if (ret == FALSE) {
|
|
|
|
xf86_remove_platform_device(index);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ret = xf86platformAddDevice(index);
|
|
|
|
if (ret == -1)
|
|
|
|
xf86_remove_platform_device(index);
|
|
|
|
}
|
|
|
|
|
2013-06-07 11:28:45 -06:00
|
|
|
void
|
|
|
|
xf86PlatformDeviceProbe(struct OdevAttributes *attribs)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
char *path = NULL;
|
|
|
|
Bool ret;
|
|
|
|
|
2014-09-27 11:52:59 -06:00
|
|
|
path = config_odev_get_attribute(attribs, ODEV_ATTRIB_PATH);
|
2013-06-07 11:28:45 -06:00
|
|
|
if (!path)
|
|
|
|
goto out_free;
|
|
|
|
|
|
|
|
for (i = 0; i < xf86_num_platform_devices; i++) {
|
|
|
|
char *dpath;
|
|
|
|
dpath = xf86_get_platform_attrib(i, ODEV_ATTRIB_PATH);
|
|
|
|
|
|
|
|
if (!strcmp(path, dpath))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i != xf86_num_platform_devices)
|
|
|
|
goto out_free;
|
|
|
|
|
2013-08-24 13:44:25 -06:00
|
|
|
LogMessage(X_INFO, "xfree86: Adding drm device (%s)\n", path);
|
2013-06-07 11:28:45 -06:00
|
|
|
|
2013-08-24 13:44:25 -06:00
|
|
|
if (!xf86VTOwner()) {
|
|
|
|
/* if we don't currently own the VT then don't probe the device,
|
|
|
|
just mark it as unowned for later use */
|
2014-09-27 11:52:59 -06:00
|
|
|
xf86_add_platform_device(attribs, TRUE);
|
2013-08-24 13:44:25 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = get_drm_info(attribs, path, -1);
|
2013-06-07 11:28:45 -06:00
|
|
|
if (ret == FALSE)
|
|
|
|
goto out_free;
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
out_free:
|
|
|
|
config_odev_free_attribute_list(attribs);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NewGPUDeviceRequest(struct OdevAttributes *attribs)
|
|
|
|
{
|
|
|
|
int old_num = xf86_num_platform_devices;
|
|
|
|
int ret;
|
|
|
|
xf86PlatformDeviceProbe(attribs);
|
|
|
|
|
|
|
|
if (old_num == xf86_num_platform_devices)
|
|
|
|
return;
|
|
|
|
|
2013-08-24 13:44:25 -06:00
|
|
|
if (xf86_get_platform_device_unowned(xf86_num_platform_devices - 1) == TRUE)
|
|
|
|
return;
|
|
|
|
|
2013-06-07 11:28:45 -06:00
|
|
|
ret = xf86platformAddDevice(xf86_num_platform_devices-1);
|
|
|
|
if (ret == -1)
|
|
|
|
xf86_remove_platform_device(xf86_num_platform_devices-1);
|
|
|
|
|
|
|
|
ErrorF("xf86: found device %d\n", xf86_num_platform_devices);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DeleteGPUDeviceRequest(struct OdevAttributes *attribs)
|
|
|
|
{
|
|
|
|
struct OdevAttribute *attrib;
|
|
|
|
int index;
|
|
|
|
char *syspath = NULL;
|
|
|
|
|
|
|
|
xorg_list_for_each_entry(attrib, &attribs->list, member) {
|
|
|
|
if (attrib->attrib_id == ODEV_ATTRIB_SYSPATH) {
|
|
|
|
syspath = attrib->attrib_name;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (index = 0; index < xf86_num_platform_devices; index++) {
|
|
|
|
char *dspath;
|
|
|
|
dspath = xf86_get_platform_attrib(index, ODEV_ATTRIB_SYSPATH);
|
|
|
|
if (!strcmp(syspath, dspath))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (index == xf86_num_platform_devices)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
ErrorF("xf86: remove device %d %s\n", index, syspath);
|
|
|
|
|
2013-08-24 13:44:25 -06:00
|
|
|
if (xf86_get_platform_device_unowned(index) == TRUE)
|
|
|
|
xf86_remove_platform_device(index);
|
|
|
|
else
|
|
|
|
xf86platformRemoveDevice(index);
|
2013-06-07 11:28:45 -06:00
|
|
|
out:
|
|
|
|
config_odev_free_attribute_list(attribs);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|