Date: Wed, 20 Dec 2017 19:14:06 +0000 (UTC) From: Warner Losh <imp@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r327035 - head/sys/dev/pci Message-ID: <201712201914.vBKJE6kd087253@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: imp Date: Wed Dec 20 19:14:05 2017 New Revision: 327035 URL: https://svnweb.freebsd.org/changeset/base/327035 Log: Add device location wiring to the pci bus. This allows one to specify, for example, that if there's an igb card in bus 12, slot 0, function 0, it should be assigned igb5. If there isn't, or there's one in a different slot, normal numbering rules apply (hinted units are skipped). Adding 'hint.igb.5.at="pci12:0:0"' or 'hint.igb.5.at="pci0:12:0:0"' to /boot/device.hints will accomplish this. The double quotes are important. The kernel only accepts the strings (in shell notation): pci$d:$b:$s:$f and pci$b:$s:$f where $d is the pci domain, $b is the pci bus number, $s is the slot number and $f is the function number. A string compare is done with the current device to avoid another string parser in the kernel. All numbers are unsigned decimal without leading zeros. Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D13546 Modified: head/sys/dev/pci/pci.c Modified: head/sys/dev/pci/pci.c ============================================================================== --- head/sys/dev/pci/pci.c Wed Dec 20 19:13:55 2017 (r327034) +++ head/sys/dev/pci/pci.c Wed Dec 20 19:14:05 2017 (r327035) @@ -123,6 +123,8 @@ static void pci_resume_msi(device_t dev); static void pci_resume_msix(device_t dev); static int pci_remap_intr_method(device_t bus, device_t dev, u_int irq); +static void pci_hint_device_unit(device_t acdev, device_t child, + const char *name, int *unitp); static int pci_get_id_method(device_t dev, device_t child, enum pci_id_type type, uintptr_t *rid); @@ -162,6 +164,7 @@ static device_method_t pci_methods[] = { DEVMETHOD(bus_child_detached, pci_child_detached), DEVMETHOD(bus_child_pnpinfo_str, pci_child_pnpinfo_str_method), DEVMETHOD(bus_child_location_str, pci_child_location_str_method), + DEVMETHOD(bus_hint_device_unit, pci_hint_device_unit), DEVMETHOD(bus_remap_intr, pci_remap_intr_method), DEVMETHOD(bus_suspend_child, pci_suspend_child), DEVMETHOD(bus_resume_child, pci_resume_child), @@ -4218,6 +4221,31 @@ pci_detach(device_t dev) return (error); #endif return (device_delete_children(dev)); +} + +static void +pci_hint_device_unit(device_t dev, device_t child, const char *name, int *unitp) +{ + int line, unit; + const char *at; + char me1[24], me2[32]; + uint8_t b, s, f; + uint32_t d; + + d = pci_get_domain(child); + b = pci_get_bus(child); + s = pci_get_slot(child); + f = pci_get_function(child); + snprintf(me1, sizeof(me1), "pci%u:%u:%u", b, s, f); + snprintf(me2, sizeof(me2), "pci%u:%u:%u:%u", d, b, s, f); + line = 0; + while (resource_find_dev(&line, name, &unit, "at", NULL) == 0) { + resource_string_value(name, unit, "at", &at); + if (strcmp(at, me1) != 0 && strcmp(at, me2) != 0) + continue; /* No match, try next candidate */ + *unitp = unit; + return; + } } static void
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201712201914.vBKJE6kd087253>