Index: nouveau/nouveau_pci.c =================================================================== RCS file: /cvsroot/src/sys/external/bsd/drm2/nouveau/nouveau_pci.c,v retrieving revision 1.8.10.2 diff -p -u -u -r1.8.10.2 nouveau_pci.c --- nouveau/nouveau_pci.c 25 Dec 2018 11:25:00 -0000 1.8.10.2 +++ nouveau/nouveau_pci.c 6 Mar 2020 00:33:11 -0000 @@ -51,6 +51,7 @@ SIMPLEQ_HEAD(nouveau_pci_task_head, nouv struct nouveau_pci_softc { device_t sc_dev; + struct pci_attach_args sc_pa; enum { NOUVEAU_TASK_ATTACH, NOUVEAU_TASK_WORKQUEUE, @@ -66,6 +67,7 @@ struct nouveau_pci_softc { static int nouveau_pci_match(device_t, cfdata_t, void *); static void nouveau_pci_attach(device_t, device_t, void *); +static void nouveau_pci_attach_real(device_t); static int nouveau_pci_detach(device_t, int); static bool nouveau_pci_suspend(device_t, const pmf_qual_t *); @@ -91,17 +93,13 @@ nouveau_pci_match(device_t parent, cfdat if (PCI_CLASS(pa->pa_class) != PCI_CLASS_DISPLAY) return 0; -#define IS_BETWEEN(x,y) \ - (PCI_PRODUCT(pa->pa_id) >= (x) && PCI_PRODUCT(pa->pa_id) <= (y)) /* - * NetBSD drm2 needs missing-so-far firmware for Maxwell-based cards: - * 0x1380-0x13bf GM107 - */ - if (IS_BETWEEN(0x1380, 0x13bf)) - return 0; - - /* - * NetBSD drm2 doesn't support Pascal, Volta or Turing based cards: + * NetBSD 8.x drm2 doesn't support Maxwell, Pascal, Volta or Turing + * based cards: + * 0x1340-0x137f GM108 [1] + * 0x1380-0x13bf GM107 [1] + * 0x13c0-0x13ff GM204 + * 0x1400-0x147f GM206 * 0x1580-0x15ff GP100 * 0x1b00-0x1b7f GP102 * 0x1b80-0x1bff GP104 @@ -112,20 +110,20 @@ nouveau_pci_match(device_t parent, cfdat * 0x1e00-0x1e7f TU102 * 0x1e80-0x1eff TU104 * 0x1f00-0x1f7f TU106 + * 0x1f80-0x1fff TU117 + * 0x2180-0x21ff TU116 + * + * [1] GM107/GM108 may work if firmware files are provided. + * There are Windows and Linux methods to extract them, but they + * are not readily available. NetBSD-9 drm works. + * + * reduce this to >= 1300, so that new chipsets not explictly + * listed above will be picked up. + * + * XXX perhaps switch this to explicitly match known list. */ - - if (IS_BETWEEN(0x1580, 0x15ff) || - IS_BETWEEN(0x1b00, 0x1b7f) || - IS_BETWEEN(0x1b80, 0x1bff) || - IS_BETWEEN(0x1c00, 0x1c7f) || - IS_BETWEEN(0x1c80, 0x1cff) || - IS_BETWEEN(0x1d00, 0x1d7f) || - IS_BETWEEN(0x1d80, 0x1dff) || - IS_BETWEEN(0x1e00, 0x1e7f) || - IS_BETWEEN(0x1e80, 0x1eff) || - IS_BETWEEN(0x1f00, 0x1f7f)) + if (PCI_PRODUCT(pa->pa_id) >= 0x1300) return 0; -#undef IS_BETWEEN return 6; /* XXX Beat genfb_pci... */ } @@ -138,19 +136,34 @@ nouveau_pci_attach(device_t parent, devi { struct nouveau_pci_softc *const sc = device_private(self); const struct pci_attach_args *const pa = aux; - uint64_t devname; - int error; pci_aprint_devinfo(pa, NULL); - sc->sc_dev = self; - - if (!pmf_device_register(self, &nouveau_pci_suspend, - &nouveau_pci_resume)) + if (!pmf_device_register(self, &nouveau_pci_suspend, &nouveau_pci_resume)) aprint_error_dev(self, "unable to establish power handler\n"); - sc->sc_task_state = NOUVEAU_TASK_ATTACH; - SIMPLEQ_INIT(&sc->sc_task_u.attach); + /* + * Trivial initialization first; the rest will come after we + * have mounted the root file system and can load firmware + * images. + */ + sc->sc_dev = NULL; + sc->sc_pa = *pa; + + config_mountroot(self, &nouveau_pci_attach_real); +} + +static void +nouveau_pci_attach_real(device_t self) +{ + struct nouveau_pci_softc *const sc = device_private(self); + const struct pci_attach_args *const pa = &sc->sc_pa; + uint64_t devname; + int error; + + sc->sc_dev = self; + sc->sc_task_state = NOUVEAU_TASK_ATTACH; + SIMPLEQ_INIT(&sc->sc_task_u.attach); devname = (uint64_t)device_unit(device_parent(self)) << 32; devname |= pa->pa_bus << 16; @@ -197,6 +210,10 @@ nouveau_pci_detach(device_t self, int fl struct nouveau_pci_softc *const sc = device_private(self); int error; + if (sc->sc_dev == NULL) + /* Not done attaching. */ + return EBUSY; + /* XXX Check for in-use before tearing it all down... */ error = config_detach_children(self, flags); if (error)