Changeset View
Changeset View
Standalone View
Standalone View
head/graphics/libdrm/files/patch-xf86drm.c
--- xf86drm.c.orig 2017-01-15 13:16:10 UTC | --- xf86drm.c.orig 2017-01-30 19:04:05 UTC | ||||
+++ xf86drm.c | +++ xf86drm.c | ||||
@@ -62,6 +62,10 @@ | @@ -62,6 +62,10 @@ | ||||
#endif | #endif | ||||
#include <math.h> | #include <math.h> | ||||
+#ifdef HAVE_LIBDEVQ | +#ifdef HAVE_LIBDEVQ | ||||
+#include "libdevq.h" | +#include "libdevq.h" | ||||
+#endif | +#endif | ||||
Show All 11 Lines | |||||
+#define DRM_MAJOR 0 | +#define DRM_MAJOR 0 | ||||
+#endif | +#endif | ||||
+ | + | ||||
+#if defined(__DragonFly__) | +#if defined(__DragonFly__) | ||||
+#define DRM_MAJOR 65 /* was 145 XXX needs checking */ | +#define DRM_MAJOR 65 /* was 145 XXX needs checking */ | ||||
#endif | #endif | ||||
#ifdef __NetBSD__ | #ifdef __NetBSD__ | ||||
@@ -532,6 +540,7 @@ static int drmGetMinorType(int minor) | @@ -548,6 +556,7 @@ static int drmGetMinorType(int minor) | ||||
} | } | ||||
} | } | ||||
+#if !defined(__FreeBSD__) && !defined(__DragonFly__) | +#if !defined(__FreeBSD__) && !defined(__DragonFly__) | ||||
static const char *drmGetMinorName(int type) | static const char *drmGetMinorName(int type) | ||||
{ | { | ||||
switch (type) { | switch (type) { | ||||
@@ -545,6 +554,7 @@ static const char *drmGetMinorName(int t | @@ -561,6 +570,7 @@ static const char *drmGetMinorName(int t | ||||
return NULL; | return NULL; | ||||
} | } | ||||
} | } | ||||
+#endif | +#endif | ||||
/** | /** | ||||
* Open the device by bus ID. | * Open the device by bus ID. | ||||
@@ -2817,6 +2827,15 @@ static char *drmGetMinorNameForFD(int fd | @@ -2833,6 +2843,15 @@ static char *drmGetMinorNameForFD(int fd | ||||
out_close_dir: | out_close_dir: | ||||
closedir(sysdir); | closedir(sysdir); | ||||
+#elif defined(__FreeBSD__) || defined(__DragonFly__) | +#elif defined(__FreeBSD__) || defined(__DragonFly__) | ||||
+ struct stat buf; | + struct stat buf; | ||||
+ char name[64]; | + char name[64]; | ||||
+ | + | ||||
+ fstat(fd, &buf); | + fstat(fd, &buf); | ||||
+ snprintf(name, sizeof(name), "/dev/%s", | + snprintf(name, sizeof(name), "/dev/%s", | ||||
+ devname(buf.st_rdev, S_IFCHR)); | + devname(buf.st_rdev, S_IFCHR)); | ||||
+ | + | ||||
+ return strdup(name); | + return strdup(name); | ||||
#else | #else | ||||
#warning "Missing implementation of drmGetMinorNameForFD" | struct stat sbuf; | ||||
#endif | char buf[PATH_MAX + 1]; | ||||
@@ -2854,12 +2873,19 @@ static int drmParseSubsystemType(int maj | @@ -2960,7 +2979,7 @@ static int drmParseSubsystemType(int maj | ||||
return DRM_BUS_PCI; | return DRM_BUS_HOST1X; | ||||
return -EINVAL; | return -EINVAL; | ||||
+#elif defined(__FreeBSD__) || defined(__DragonFly__) | -#elif defined(__OpenBSD__) | ||||
+ /* XXX: Don't know how to get the subsystem type, hardcode for now. | +#elif defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__DragonFly__) | ||||
+ * The code following the call to this function needs depends on | return DRM_BUS_PCI; | ||||
+ * information provided by the /pci subsystem on linux. No replacement | |||||
+ * found yet for FreeBSD. */ | |||||
+ return DRM_BUS_PCI; | |||||
#else | #else | ||||
#warning "Missing implementation of drmParseSubsystemType" | #warning "Missing implementation of drmParseSubsystemType" | ||||
return -EINVAL; | @@ -3023,6 +3042,61 @@ static int drmParsePciBusInfo(int maj, i | ||||
#endif | #endif | ||||
} | } | ||||
+#if !defined(__FreeBSD__) && !defined(__DragonFly__) | +#if defined(__FreeBSD__) || defined(__DragonFly__) | ||||
static int drmParsePciBusInfo(int maj, int min, drmPciBusInfoPtr info) | |||||
{ | |||||
#ifdef __linux__ | |||||
@@ -2901,6 +2927,61 @@ static int drmParsePciBusInfo(int maj, i | |||||
return -EINVAL; | |||||
#endif | |||||
} | |||||
+#else | |||||
+ | |||||
+/* | +/* | ||||
+ * XXX temporary workaround, because FreeBSD doesn't provide | + * XXX temporary workaround, because FreeBSD doesn't provide | ||||
+ * pcibus device sysctl trees for renderD and controlD nodes (yet) | + * pcibus device sysctl trees for renderD and controlD nodes (yet) | ||||
+ */ | + */ | ||||
+static void | +static void | ||||
+drmBSDDeviceNameHack(const char *path, char *hacked_path, int length) | +drmBSDDeviceNameHack(const char *path, char *hacked_path, int length) | ||||
+{ | +{ | ||||
+ int start, number; | + int start, number; | ||||
+ const char *errstr; | + const char *errstr; | ||||
+ | + | ||||
+ if (strcmp(path, DRM_DIR_NAME "/controlD") > 0) { | + if (strcmp(path, DRM_DIR_NAME "/controlD") > 0) { | ||||
+ start = 17; | + start = 17; | ||||
+ number = strtonum(&path[start], 0, 256, &errstr) - 64; | + number = strtonum(&path[start], 0, 256, &errstr) - 64; | ||||
+ snprintf(hacked_path, length, DRM_DIR_NAME "/card%i", number); | + snprintf(hacked_path, length, "%s/card%i", DRM_DIR_NAME, number); | ||||
+ } else if (strcmp(path, DRM_DIR_NAME "/renderD") > 0) { | + } else if (strcmp(path, DRM_DIR_NAME "/renderD") > 0) { | ||||
+ start = 16; | + start = 16; | ||||
+ number = strtonum(&path[start], 0, 256, &errstr) - 128; | + number = strtonum(&path[start], 0, 256, &errstr) - 128; | ||||
+ snprintf(hacked_path, length, DRM_DIR_NAME "/card%i", number); | + snprintf(hacked_path, length, "%s/card%i", DRM_DIR_NAME, number); | ||||
+ } else | + } else | ||||
+ snprintf(hacked_path, length, "%s", path); | + snprintf(hacked_path, length, "%s", path); | ||||
+ | + | ||||
+ return; | + return; | ||||
+} | +} | ||||
+ | + | ||||
+static int | +static int | ||||
+drmParsePciBusInfoBSD(const char *path, drmPciBusInfoPtr info) | +drmParsePciBusInfoBSD(const char *path, drmPciBusInfoPtr info) | ||||
Show All 19 Lines | |||||
+ info->bus = (uint8_t) bus; | + info->bus = (uint8_t) bus; | ||||
+ info->dev = (uint8_t) slot; | + info->dev = (uint8_t) slot; | ||||
+ info->func = (uint8_t) function; | + info->func = (uint8_t) function; | ||||
+ | + | ||||
+ close(fd); | + close(fd); | ||||
+ return 0; | + return 0; | ||||
+} | +} | ||||
+#endif | +#endif | ||||
+ | |||||
static int drmCompareBusInfo(drmDevicePtr a, drmDevicePtr b) | static int drmCompareBusInfo(drmDevicePtr a, drmDevicePtr b) | ||||
{ | { | ||||
@@ -2971,6 +3052,31 @@ static int drmParsePciDeviceInfo(const c | if (a == NULL || b == NULL) | ||||
device->subdevice_id = config[46] | (config[47] << 8); | @@ -3188,6 +3262,36 @@ static int drmParsePciDeviceInfo(int maj | ||||
#endif | |||||
} | |||||
return 0; | +#if defined(__FreeBSD__) || defined(__DragonFly__) | ||||
+#elif defined(__FreeBSD__) || defined(__DragonFly__) | +static int drmParsePciDeviceInfoBSD(const char *path, | ||||
+ drmPciDeviceInfoPtr device, | |||||
+ uint32_t flags) | |||||
+{ | |||||
+ int fd, vendor_id = 0, device_id = 0, subvendor_id = 0, | + int fd, vendor_id = 0, device_id = 0, subvendor_id = 0, | ||||
+ subdevice_id = 0, revision_id = 0; | + subdevice_id = 0, revision_id = 0; | ||||
+ char path[PATH_MAX + 1]; | |||||
+ char hacked_path[PATH_MAX + 1]; | + char hacked_path[PATH_MAX + 1]; | ||||
+ | + | ||||
+ snprintf(path, PATH_MAX, DRM_DIR_NAME "/%s", d_name); | |||||
+ drmBSDDeviceNameHack(path, hacked_path, PATH_MAX); | + drmBSDDeviceNameHack(path, hacked_path, PATH_MAX); | ||||
+ | + | ||||
+ fd = open(hacked_path, O_RDONLY); | + fd = open(hacked_path, O_RDONLY); | ||||
+ | + | ||||
+ if (fd < 0) | + if (fd < 0) | ||||
+ return -errno; | + return -errno; | ||||
+ | + | ||||
+ devq_device_get_pciid_full_from_fd(fd, &vendor_id, &device_id, | + devq_device_get_pciid_full_from_fd(fd, &vendor_id, &device_id, | ||||
+ &subvendor_id, &subdevice_id, &revision_id); | + &subvendor_id, &subdevice_id, &revision_id); | ||||
+ | + | ||||
+ device->vendor_id = (uint16_t) vendor_id; | + device->vendor_id = (uint16_t) vendor_id; | ||||
+ device->device_id = (uint16_t) device_id; | + device->device_id = (uint16_t) device_id; | ||||
+ device->subvendor_id = (uint16_t) subvendor_id; | + device->subvendor_id = (uint16_t) subvendor_id; | ||||
+ device->subdevice_id = (uint16_t) subdevice_id; | + device->subdevice_id = (uint16_t) subdevice_id; | ||||
+ device->revision_id = (uint8_t) revision_id; | + device->revision_id = (uint8_t) revision_id; | ||||
+ | + | ||||
+ close(fd); | + close(fd); | ||||
+ return 0; | + return 0; | ||||
#else | +} | ||||
#warning "Missing implementation of drmParsePciDeviceInfo" | +#endif | ||||
return -EINVAL; | + | ||||
@@ -3030,7 +3136,12 @@ static int drmProcessPciDevice(drmDevice | static void drmFreePlatformDevice(drmDevicePtr device) | ||||
{ | |||||
if (device->deviceinfo.platform) { | |||||
@@ -3308,7 +3412,11 @@ static int drmProcessPciDevice(drmDevice | |||||
(*device)->businfo.pci = (drmPciBusInfoPtr)addr; | dev->businfo.pci = (drmPciBusInfoPtr)addr; | ||||
+#if defined(__FreeBSD__) || defined(__DragonFly__) | +#if defined(__FreeBSD__) || defined(__DragonFly__) | ||||
+ ret = drmParsePciBusInfoBSD(node, (*device)->businfo.pci); | + ret = drmParsePciBusInfoBSD(node, dev->businfo.pci); | ||||
+#else | +#else | ||||
ret = drmParsePciBusInfo(maj, min, (*device)->businfo.pci); | ret = drmParsePciBusInfo(maj, min, dev->businfo.pci); | ||||
+#endif | +#endif | ||||
+ | |||||
if (ret) | if (ret) | ||||
goto free_device; | goto free_device; | ||||
@@ -3316,8 +3424,11 @@ static int drmProcessPciDevice(drmDevice | |||||
if (fetch_deviceinfo) { | |||||
addr += sizeof(drmPciBusInfo); | |||||
dev->deviceinfo.pci = (drmPciDeviceInfoPtr)addr; | |||||
- | |||||
+#if defined(__FreeBSD__) || defined(__DragonFly__) | |||||
+ ret = drmParsePciDeviceInfoBSD(node, dev->deviceinfo.pci, flags); | |||||
+#else | |||||
ret = drmParsePciDeviceInfo(maj, min, dev->deviceinfo.pci, flags); | |||||
+#endif | |||||
if (ret) | |||||
goto free_device; | |||||
} |