Re: svn commit: r323692 - in head/sys/compat: linsysfs linux
On Sun, Sep 17, 2017 at 4:40 PM, Conrad Meyer wrote: > Author: cem > Date: Sun Sep 17 23:40:16 2017 > New Revision: 323692 > URL: https://svnweb.freebsd.org/changeset/base/323692 > > Log: > linsysfs(5): Add support for recent libdrm > > Expose more information about PCI devices (and GPUs in particular) via > linsysfs to libdrm. > > This allows unmodified modern 64-bit Linux libdrm to work, which allows > modern Linux Mesa to work. The submitter reports that he tested the change > with an Ubuntu 16.04 chroot + amdgpu from graphics/drm-next-kmod. > > PR: 222375 > Submitted by: Greg V > > Modified: > head/sys/compat/linsysfs/linsysfs.c > head/sys/compat/linux/linux_util.c > > Modified: head/sys/compat/linsysfs/linsysfs.c > == > --- head/sys/compat/linsysfs/linsysfs.c Sun Sep 17 22:58:13 2017 > (r323691) > +++ head/sys/compat/linsysfs/linsysfs.c Sun Sep 17 23:40:16 2017 > (r323692) > @@ -133,20 +133,135 @@ linsysfs_link_scsi_host(PFS_FILL_ARGS) > return (0); > } > > +static int > +linsysfs_fill_data(PFS_FILL_ARGS) > +{ > + sbuf_printf(sb, "%s", pn->pn_data); > + return (0); > +} This broke the gcc build with -Wformat [1]: /workspace/src/sys/compat/linsysfs/linsysfs.c: In function 'linsysfs_fill_data': /workspace/src/sys/compat/linsysfs/linsysfs.c:139:20: error: format '%s' expects argument of type 'char *', but argument 3 has type 'void *' [-Werror=format=] sbuf_printf(sb, "%s", pn->pn_data); It builds if a char * cast is added. Is that the right fix? [1] https://ci.freebsd.org/job/FreeBSD-head-amd64-gcc/2532/ ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
Re: svn commit: r323692 - in head/sys/compat: linsysfs linux
This was not introduced in this change. On Mon, Sep 18, 2017 at 8:05 AM, Hans Petter Selasky wrote: > On 09/18/17 01:40, Conrad Meyer wrote: >> >> device_get_children(dev, &children, &nchildren); >> for (i = 0; i < nchildren; i++) { >> if (children[i]) >> - linsysfs_run_bus(children[i], dir, scsi, new_path, >> prefix); >> + linsysfs_run_bus(children[i], dir, scsi, chardev, >> new_path, prefix); >> } >> if (new_path != path) >> free(new_path, M_TEMP); >> + free(chardevname, M_TEMP); >> return (1); > > > 1) Return code from device_get_children() should be checked. > > 2) children pointer should be freed else there is a memory leak. > > --HPS ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
Re: svn commit: r323692 - in head/sys/compat: linsysfs linux
On 09/18/17 17:09, Conrad Meyer wrote: Seems unhelpful here, as the maximum length of "226:%d" is shorter than the buffer. It makes code-review easier. --HPS ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
Re: svn commit: r323692 - in head/sys/compat: linsysfs linux
On 09/18/17 01:40, Conrad Meyer wrote: + + dinfo = device_get_ivars(parent); + if (dinfo != NULL && dinfo->cfg.baseclass == PCIC_DISPLAY) { + devclass = device_get_devclass(dev); + if (devclass != NULL) + name = devclass_get_name(devclass); + if (name != NULL && strcmp(name, DRMN_DEV) == 0 && + device_get_unit(dev) >= 0) { + sprintf(chardevname, "226:%d", Order of comparison should be switched. First check devclass and name. Then try to access ivars. Else the ivars might have an undefined type! --HPS ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
Re: svn commit: r323692 - in head/sys/compat: linsysfs linux
Seems unhelpful here, as the maximum length of "226:%d" is shorter than the buffer. On Mon, Sep 18, 2017 at 3:38 AM, Hans Petter Selasky wrote: > On 09/18/17 01:40, Conrad Meyer wrote: >> >> + sprintf(chardevname, "226:%d", >> + device_get_unit(dev)); > > > Hi, > > Try to use snprintf(). Define the chardevname size as a macro, or just > allocate it on the stack if it is < 32 bytes. > > --HPS ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
Re: svn commit: r323692 - in head/sys/compat: linsysfs linux
On 09/18/17 01:40, Conrad Meyer wrote: device_get_children(dev, &children, &nchildren); for (i = 0; i < nchildren; i++) { if (children[i]) - linsysfs_run_bus(children[i], dir, scsi, new_path, prefix); + linsysfs_run_bus(children[i], dir, scsi, chardev, new_path, prefix); } if (new_path != path) free(new_path, M_TEMP); + free(chardevname, M_TEMP); return (1); 1) Return code from device_get_children() should be checked. 2) children pointer should be freed else there is a memory leak. --HPS ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
Re: svn commit: r323692 - in head/sys/compat: linsysfs linux
On 09/18/17 01:40, Conrad Meyer wrote: + sprintf(chardevname, "226:%d", + device_get_unit(dev)); Hi, Try to use snprintf(). Define the chardevname size as a macro, or just allocate it on the stack if it is < 32 bytes. --HPS ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
svn commit: r323692 - in head/sys/compat: linsysfs linux
Author: cem Date: Sun Sep 17 23:40:16 2017 New Revision: 323692 URL: https://svnweb.freebsd.org/changeset/base/323692 Log: linsysfs(5): Add support for recent libdrm Expose more information about PCI devices (and GPUs in particular) via linsysfs to libdrm. This allows unmodified modern 64-bit Linux libdrm to work, which allows modern Linux Mesa to work. The submitter reports that he tested the change with an Ubuntu 16.04 chroot + amdgpu from graphics/drm-next-kmod. PR: 222375 Submitted by: Greg V Modified: head/sys/compat/linsysfs/linsysfs.c head/sys/compat/linux/linux_util.c Modified: head/sys/compat/linsysfs/linsysfs.c == --- head/sys/compat/linsysfs/linsysfs.c Sun Sep 17 22:58:13 2017 (r323691) +++ head/sys/compat/linsysfs/linsysfs.c Sun Sep 17 23:40:16 2017 (r323692) @@ -133,20 +133,135 @@ linsysfs_link_scsi_host(PFS_FILL_ARGS) return (0); } +static int +linsysfs_fill_data(PFS_FILL_ARGS) +{ + sbuf_printf(sb, "%s", pn->pn_data); + return (0); +} + +static int +linsysfs_fill_vendor(PFS_FILL_ARGS) +{ + sbuf_printf(sb, "0x%04x\n", pci_get_vendor((device_t)pn->pn_data)); + return (0); +} + +static int +linsysfs_fill_device(PFS_FILL_ARGS) +{ + sbuf_printf(sb, "0x%04x\n", pci_get_device((device_t)pn->pn_data)); + return (0); +} + +static int +linsysfs_fill_subvendor(PFS_FILL_ARGS) +{ + sbuf_printf(sb, "0x%04x\n", pci_get_subvendor((device_t)pn->pn_data)); + return (0); +} + +static int +linsysfs_fill_subdevice(PFS_FILL_ARGS) +{ + sbuf_printf(sb, "0x%04x\n", pci_get_subdevice((device_t)pn->pn_data)); + return (0); +} + +static int +linsysfs_fill_revid(PFS_FILL_ARGS) +{ + sbuf_printf(sb, "0x%x\n", pci_get_revid((device_t)pn->pn_data)); + return (0); +} + +/* + * Filler function for PCI uevent file + */ +static int +linsysfs_fill_uevent_pci(PFS_FILL_ARGS) +{ + device_t dev; + + dev = (device_t)pn->pn_data; + sbuf_printf(sb, "DRIVER=%s\nPCI_CLASS=%X\nPCI_ID=%04X:%04X\n" + "PCI_SUBSYS_ID=%04X:%04X\nPCI_SLOT_NAME=%04d:%02x:%02x.%x\n", + linux_driver_get_name_dev(dev), pci_get_class(dev), + pci_get_vendor(dev), pci_get_device(dev), pci_get_subvendor(dev), + pci_get_subdevice(dev), pci_get_domain(dev), pci_get_bus(dev), + pci_get_slot(dev), pci_get_function(dev)); + return (0); +} + +/* + * Filler function for drm uevent file + */ +static int +linsysfs_fill_uevent_drm(PFS_FILL_ARGS) +{ + device_t dev; + int unit; + + dev = (device_t)pn->pn_data; + unit = device_get_unit(dev); + sbuf_printf(sb, + "MAJOR=226\nMINOR=%d\nDEVNAME=drm/%d\nDEVTYPE=dri_minor\n", unit, + unit); + return (0); +} + +static char * +get_full_pfs_path(struct pfs_node *cur) +{ + char *temp, *path; + + temp = malloc(MAXPATHLEN, M_TEMP, M_WAITOK); + path = malloc(MAXPATHLEN, M_TEMP, M_WAITOK); + path[0] = '\0'; + + do { + snprintf(temp, MAXPATHLEN, "%s/%s", cur->pn_name, path); + strlcpy(path, temp, MAXPATHLEN); + cur = cur->pn_parent; + } while (cur->pn_parent != NULL); + + path[strlen(path) - 1] = '\0'; /* remove extra slash */ + free(temp, M_TEMP); + return (path); +} + +/* + * Filler function for symlink from drm char device to PCI device + */ +static int +linsysfs_fill_vgapci(PFS_FILL_ARGS) +{ + char *path; + + path = get_full_pfs_path((struct pfs_node*)pn->pn_data); + sbuf_printf(sb, "../../../%s", path); + free(path, M_TEMP); + return (0); +} + #define PCI_DEV "pci" +#define DRMN_DEV "drmn" static int -linsysfs_run_bus(device_t dev, struct pfs_node *dir, struct pfs_node *scsi, char *path, - char *prefix) +linsysfs_run_bus(device_t dev, struct pfs_node *dir, struct pfs_node *scsi, struct pfs_node *chardev, + char *path, char *prefix) { struct scsi_host_queue *scsi_host; - struct pfs_node *sub_dir; + struct pfs_node *sub_dir, *cur_file, *cur_chardev; int i, nchildren; device_t *children, parent; devclass_t devclass; const char *name = NULL; struct pci_devinfo *dinfo; - char *device, *host, *new_path = path; + char *device, *host, *new_path, *chardevname; + new_path = path; + chardevname = malloc(16, M_TEMP, M_WAITOK); + parent = device_get_parent(dev); if (parent) { devclass = device_get_devclass(parent); @@ -171,6 +286,36 @@ linsysfs_run_bus(device_t dev, struct pfs_node *dir, s strcat(new_path, device); dir = pfs_create_dir(dir, device, NULL, NULL, NULL, 0); + cur_file = pfs_create_file(dir, "vendor", +