Message ID | 20161126004034.53376-3-jsg@jsg.id.au (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
On 26 November 2016 at 00:40, Jonathan Gray <jsg@jsg.id.au> wrote: > Implement drmParsePciDeviceInfo for OpenBSD by using the new > DRM_IOCTL_GET_PCIINFO ioctl. > > Signed-off-by: Jonathan Gray <jsg@jsg.id.au> > --- > xf86drm.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 51 insertions(+) > > diff --git a/xf86drm.c b/xf86drm.c > index b355c83..581527b 100644 > --- a/xf86drm.c > +++ b/xf86drm.c > @@ -102,6 +102,26 @@ > #define DRM_MAJOR 226 /* Linux */ > #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 > > #define memclear(s) memset(&s, 0, sizeof(s)) > @@ -2991,6 +3011,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 > + Since X_PRIVSEP is always set one can drop the ifndef case alongside the define X_PRIVSEP all together. At the same time, priv_open_device isn't defined thus one might well use drmOpenMinor() like in 4/5 ? Sidenote: In the future we might fold drmParsePciBusInfo and drmParsePciDeviceInfo, but for the moment we have to keep them separate :-( Thanks Emil
On Tue, Nov 29, 2016 at 07:55:13PM +0000, Emil Velikov wrote: > On 26 November 2016 at 00:40, Jonathan Gray <jsg@jsg.id.au> wrote: > > Implement drmParsePciDeviceInfo for OpenBSD by using the new > > DRM_IOCTL_GET_PCIINFO ioctl. > > > > Signed-off-by: Jonathan Gray <jsg@jsg.id.au> > > --- > > xf86drm.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ > > 1 file changed, 51 insertions(+) > > > > diff --git a/xf86drm.c b/xf86drm.c > > index b355c83..581527b 100644 > > --- a/xf86drm.c > > +++ b/xf86drm.c > > @@ -102,6 +102,26 @@ > > #define DRM_MAJOR 226 /* Linux */ > > #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 > > > > #define memclear(s) memset(&s, 0, sizeof(s)) > > @@ -2991,6 +3011,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 > > + > Since X_PRIVSEP is always set one can drop the ifndef case alongside > the define X_PRIVSEP all together. At the same time, priv_open_device > isn't defined thus one might well use drmOpenMinor() like in 4/5 ? Then we'd have to find a minor number and type based on the d_name string argument to drmParsePciDeviceInfo. The priv_open_device part is really a different patch. > > Sidenote: In the future we might fold drmParsePciBusInfo and > drmParsePciDeviceInfo, but for the moment we have to keep them > separate :-( Annoying that one takes a minor and one takes a string...
On 30 November 2016 at 00:38, Jonathan Gray <jsg@jsg.id.au> wrote: > On Tue, Nov 29, 2016 at 07:55:13PM +0000, Emil Velikov wrote: >> On 26 November 2016 at 00:40, Jonathan Gray <jsg@jsg.id.au> wrote: >> > Implement drmParsePciDeviceInfo for OpenBSD by using the new >> > DRM_IOCTL_GET_PCIINFO ioctl. >> > >> > Signed-off-by: Jonathan Gray <jsg@jsg.id.au> >> > --- >> > xf86drm.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ >> > 1 file changed, 51 insertions(+) >> > >> > diff --git a/xf86drm.c b/xf86drm.c >> > index b355c83..581527b 100644 >> > --- a/xf86drm.c >> > +++ b/xf86drm.c >> > @@ -102,6 +102,26 @@ >> > #define DRM_MAJOR 226 /* Linux */ >> > #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 >> > >> > #define memclear(s) memset(&s, 0, sizeof(s)) >> > @@ -2991,6 +3011,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 >> > + >> Since X_PRIVSEP is always set one can drop the ifndef case alongside >> the define X_PRIVSEP all together. At the same time, priv_open_device >> isn't defined thus one might well use drmOpenMinor() like in 4/5 ? > > Then we'd have to find a minor number and type based on the d_name > string argument to drmParsePciDeviceInfo. The priv_open_device part is > really a different patch. > >> >> Sidenote: In the future we might fold drmParsePciBusInfo and >> drmParsePciDeviceInfo, but for the moment we have to keep them >> separate :-( > > Annoying that one takes a minor and one takes a string... It's a po-tay-to po-tah-to case on our end :-) A maj/min pair seems better, patch coming in a bit. Thanks Emil
diff --git a/xf86drm.c b/xf86drm.c index b355c83..581527b 100644 --- a/xf86drm.c +++ b/xf86drm.c @@ -102,6 +102,26 @@ #define DRM_MAJOR 226 /* Linux */ #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 #define memclear(s) memset(&s, 0, sizeof(s)) @@ -2991,6 +3011,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;
Implement drmParsePciDeviceInfo for OpenBSD by using the new DRM_IOCTL_GET_PCIINFO ioctl. Signed-off-by: Jonathan Gray <jsg@jsg.id.au> --- xf86drm.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+)