Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[xsrc/trunk]: xsrc/external/mit/libdrm/dist Implement drmParsePciBusInfo and ...



details:   https://anonhg.NetBSD.org/xsrc/rev/b5aa54fc103c
branches:  trunk
changeset: 9986:b5aa54fc103c
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Sun Sep 09 02:00:29 2018 +0000

description:
Implement drmParsePciBusInfo and drmParsePciDeviceInfo.

Uses drmGetBusid for bus info, and pciN with libpci for device info.

Aims to address PR pkg/51795 without needing the kernel changes
suggested in PR kern/51786.  Compile-tested only sofar -- should
confirm before closing any PRs.

(Sorry it took so long for me to find a round tuit!)

XXX pullup-7
XXX pullup-8

...along with src/external/mit/xorg/lib/libdrm/Makefile r1.16 for
libpci.

diffstat:

 external/mit/libdrm/dist/xf86drm.c |  159 +++++++++++++++++++++++++++++++++++++
 1 files changed, 159 insertions(+), 0 deletions(-)

diffs (190 lines):

diff -r 627ff351bf71 -r b5aa54fc103c external/mit/libdrm/dist/xf86drm.c
--- a/external/mit/libdrm/dist/xf86drm.c        Tue Aug 28 08:45:20 2018 +0000
+++ b/external/mit/libdrm/dist/xf86drm.c        Sun Sep 09 02:00:29 2018 +0000
@@ -89,6 +89,8 @@
 #ifdef __NetBSD__
 #undef DRM_MAJOR
 #define DRM_MAJOR 180
+#include <dev/pci/pcireg.h>
+#include <pci.h>
 #endif
 
 #ifdef __OpenBSD__
@@ -3002,6 +3004,63 @@
         return DRM_BUS_HOST1X;
 
     return -EINVAL;
+#elif defined(__NetBSD__)
+    int type, fd;
+    drmSetVersion sv;
+    char *buf;
+    unsigned domain, bus, dev;
+    int func;
+    int ret;
+
+    /* Get the type of device we're looking for to pick the right pathname.  */
+    type = drmGetMinorType(min);
+    if (type == -1)
+       return -ENODEV;
+
+    /* Open the device.  Don't try to create it if it's not there.  */
+    fd = drmOpenMinor(min, 0, type);
+    if (fd < 0)
+       return -errno;
+
+    /*
+     * Set the interface version to 1.4 or 1.1, which has the effect of
+     * populating the bus id for us.
+     */
+    sv.drm_di_major = 1;
+    sv.drm_di_minor = 4;
+    sv.drm_dd_major = -1;
+    sv.drm_dd_minor = -1;
+    if (drmSetInterfaceVersion(fd, &sv)) {
+       sv.drm_di_major = 1;
+       sv.drm_di_minor = 1;
+       sv.drm_dd_major = -1;
+       sv.drm_dd_minor = -1;
+       if (drmSetInterfaceVersion(fd, &sv)) {
+           (void)close(fd);
+           return -ENODEV;
+       }
+    }
+
+    /* Get the bus id.  */
+    buf = drmGetBusid(fd);
+
+    /* We're done with the device now.  */
+    (void)close(fd);
+
+    /* If there is no bus id, fail.  */
+    if (buf == NULL)
+       return -ENODEV;
+
+    /* Find a string we know about; otherwise -EINVAL.  */
+    ret = -EINVAL;
+    if (strncmp(buf, "pci:", 4) != 0)
+       ret = DRM_BUS_PCI;
+
+    /* We're done with the bus id.  */
+    free(buf);
+
+    /* Success or not, we're done.  */
+    return ret;
 #elif defined(__OpenBSD__)
     return DRM_BUS_PCI;
 #else
@@ -3035,6 +3094,71 @@
     info->func = func;
 
     return 0;
+#elif defined(__NetBSD__)
+    int type, fd;
+    drmSetVersion sv;
+    char *buf;
+    unsigned domain, bus, dev;
+    int func;
+    int ret;
+
+    /* Get the type of device we're looking for to pick the right pathname.  */
+    type = drmGetMinorType(min);
+    if (type == -1)
+       return -ENODEV;
+
+    /* Open the device.  Don't try to create it if it's not there.  */
+    fd = drmOpenMinor(min, 0, type);
+    if (fd < 0)
+       return -errno;
+
+    /*
+     * Set the interface version to 1.4 or 1.1, which has the effect of
+     * populating the bus id for us.
+     */
+    sv.drm_di_major = 1;
+    sv.drm_di_minor = 4;
+    sv.drm_dd_major = -1;
+    sv.drm_dd_minor = -1;
+    if (drmSetInterfaceVersion(fd, &sv)) {
+       sv.drm_di_major = 1;
+       sv.drm_di_minor = 1;
+       sv.drm_dd_major = -1;
+       sv.drm_dd_minor = -1;
+       if (drmSetInterfaceVersion(fd, &sv)) {
+           (void)close(fd);
+           return -ENODEV;
+       }
+    }
+
+    /* Get the bus id.  */
+    buf = drmGetBusid(fd);
+
+    /* We're done with the device now.  */
+    (void)close(fd);
+
+    /* If there is no bus id, fail.  */
+    if (buf == NULL)
+       return -ENODEV;
+
+    /* Parse the bus id.  */
+    ret = sscanf(buf, "pci:%04x:%02x:%02x.%d", &domain, &bus, &dev, &func);
+
+    /* We're done with the bus id.  */
+    free(buf);
+
+    /* If scanf didn't return 4 -- domain, bus, dev, func -- then fail.  */
+    if (ret != 4)
+       return -ENODEV;
+
+    /* Populate the results.  */
+    info->domain = domain;
+    info->bus = bus;
+    info->dev = dev;
+    info->func = func;
+
+    /* Success!  */
+    return 0;
 #elif defined(__OpenBSD__)
     struct drm_pciinfo pinfo;
     int fd, type;
@@ -3199,6 +3323,41 @@
         return parse_config_sysfs_file(maj, min, device);
 
     return 0;
+#elif defined(__NetBSD__)
+    drmPciBusInfo businfo;
+    char fname[PATH_MAX];
+    int pcifd;
+    pcireg_t id, class, subsys;
+    int ret;
+
+    /* Find where on the bus the device lives.  */
+    ret = drmParsePciBusInfo(maj, min, &businfo);
+    if (ret)
+       return ret;
+
+    /* Open the pciN device node to get at its config registers.  */
+    if (snprintf(fname, sizeof fname, "/dev/pci%u", businfo.domain)
+       >= sizeof fname)
+       return -ENODEV;
+    if ((pcifd = open(fname, O_RDONLY)) == -1)
+       return -errno;
+
+    /* Read the id and class pci config registers.  */
+    if (pcibus_conf_read(pcifd, businfo.bus, businfo.dev, businfo.func,
+           PCI_ID_REG, &id) == -1)
+       return -errno;
+    if (pcibus_conf_read(pcifd, businfo.bus, businfo.dev, businfo.func,
+           PCI_CLASS_REG, &class) == -1)
+       return -errno;
+    if (pcibus_conf_read(pcifd, businfo.bus, businfo.dev, businfo.func,
+           PCI_SUBSYS_ID_REG, &subsys) == -1)
+       return -errno;
+
+    device->vendor_id = PCI_VENDOR(id);
+    device->device_id = PCI_PRODUCT(id);
+    device->subvendor_id = PCI_SUBSYS_VENDOR(subsys);
+    device->subdevice_id = PCI_SUBSYS_ID(subsys);
+    device->revision_id = PCI_REVISION(class);
 #elif defined(__OpenBSD__)
     struct drm_pciinfo pinfo;
     int fd, type;



Home | Main Index | Thread Index | Old Index