diff options
author | Jonathan Gray <jsg@cvs.openbsd.org> | 2016-11-25 23:48:51 +0000 |
---|---|---|
committer | Jonathan Gray <jsg@cvs.openbsd.org> | 2016-11-25 23:48:51 +0000 |
commit | 03775343380e5ccbc139941cafac686431cd8c2e (patch) | |
tree | 5317df7da01d6710e5ff0404cf9f57be8cdc357d /lib/libdrm | |
parent | dff93a967ac9eae54939561a353f99ca635dcdef (diff) |
Implement drmParsePciDeviceInfo for OpenBSD by using the new
DRM_IOCTL_GET_PCIINFO ioctl.
ok kettenis@
Diffstat (limited to 'lib/libdrm')
-rw-r--r-- | lib/libdrm/xf86drm.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/lib/libdrm/xf86drm.c b/lib/libdrm/xf86drm.c index 0ac724bd1..90781e0a1 100644 --- a/lib/libdrm/xf86drm.c +++ b/lib/libdrm/xf86drm.c @@ -103,7 +103,23 @@ #endif #ifdef __OpenBSD__ + #define X_PRIVSEP + +struct drm_pciinfo { + uint16_t domain; + uint8_t bus; + uint8_t dev; + uint8_t func; + uint16_t vendor_id; + uint16_t device_id; + uint16_t subvendor_id; + uint16_t subdevice_id; + uint8_t revision_id; +}; + +#define DRM_IOCTL_GET_PCIINFO DRM_IOR(0x15, struct drm_pciinfo) + #endif #define DRM_MSG_VERBOSITY 3 @@ -3024,6 +3040,37 @@ static int drmParsePciDeviceInfo(const char *d_name, device->subdevice_id = config[46] | (config[47] << 8); return 0; +#elif defined(__OpenBSD__) + struct drm_pciinfo pinfo; + char buf[PATH_MAX + 1]; + int fd, n; + + n = snprintf(buf, sizeof(buf), "%s/%s", DRM_DIR_NAME, d_name); + if (n == -1 || n >= sizeof(buf)) + return -errno; + +#ifndef X_PRIVSEP + fd = open(buf, O_RDWR, 0); +#else + fd = priv_open_device(buf); +#endif + + if (fd < 0) + return -errno; + + if (drmIoctl(fd, DRM_IOCTL_GET_PCIINFO, &pinfo)) { + close(fd); + return -errno; + } + close(fd); + + device->vendor_id = pinfo.vendor_id; + device->device_id = pinfo.device_id; + device->revision_id = pinfo.revision_id; + device->subvendor_id = pinfo.subvendor_id; + device->subdevice_id = pinfo.subdevice_id; + + return 0; #else #warning "Missing implementation of drmParsePciDeviceInfo" return -EINVAL; |