Source-Changes-HG archive

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

[src/trunk]: src/sys/external/bsd/drm2/nouveau Improve nouveau pci attachment...



details:   https://anonhg.NetBSD.org/src/rev/33e74042c9e1
branches:  trunk
changeset: 457571:33e74042c9e1
user:      wiz <wiz%NetBSD.org@localhost>
date:      Wed Jul 03 20:47:22 2019 +0000

description:
Improve nouveau pci attachment code so it waits for the availability of /
before trying to load firmware.

Fixes my PR 54274.

LGTM mrg

diffstat:

 sys/external/bsd/drm2/nouveau/nouveau_pci.c |  43 +++++++++++++++++++++-------
 1 files changed, 32 insertions(+), 11 deletions(-)

diffs (100 lines):

diff -r 38e2968c69e5 -r 33e74042c9e1 sys/external/bsd/drm2/nouveau/nouveau_pci.c
--- a/sys/external/bsd/drm2/nouveau/nouveau_pci.c       Wed Jul 03 20:26:16 2019 +0000
+++ b/sys/external/bsd/drm2/nouveau/nouveau_pci.c       Wed Jul 03 20:47:22 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: nouveau_pci.c,v 1.23 2018/12/24 08:40:33 mrg Exp $     */
+/*     $NetBSD: nouveau_pci.c,v 1.24 2019/07/03 20:47:22 wiz Exp $     */
 
 /*-
  * Copyright (c) 2015 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: nouveau_pci.c,v 1.23 2018/12/24 08:40:33 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nouveau_pci.c,v 1.24 2019/07/03 20:47:22 wiz Exp $");
 
 #include <sys/types.h>
 #include <sys/device.h>
@@ -52,6 +52,7 @@
 
 struct nouveau_pci_softc {
        device_t                sc_dev;
+       struct pci_attach_args  sc_pa;
        enum {
                NOUVEAU_TASK_ATTACH,
                NOUVEAU_TASK_WORKQUEUE,
@@ -67,6 +68,7 @@
 
 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 *);
@@ -110,7 +112,7 @@
         *   0x1e80-0x1eff      TU104
         *   0x1f00-0x1f7f      TU106
         */
-       
+
        if (IS_BETWEEN(0x1580, 0x15ff) ||
            IS_BETWEEN(0x1b00, 0x1b7f) ||
            IS_BETWEEN(0x1b80, 0x1bff) ||
@@ -144,22 +146,37 @@
 {
        struct nouveau_pci_softc *const sc = device_private(self);
        const struct pci_attach_args *const pa = aux;
-       int error;
 
        pci_aprint_devinfo(pa, NULL);
 
+       if (!pmf_device_register(self, &nouveau_pci_suspend, &nouveau_pci_resume))
+               aprint_error_dev(self, "unable to establish power handler\n");
+
+       /*
+        * 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;
+       int error;
+
        sc->sc_dev = self;
+       sc->sc_task_state = NOUVEAU_TASK_ATTACH;
+       SIMPLEQ_INIT(&sc->sc_task_u.attach);
 
        /* Initialize the Linux PCI device descriptor.  */
        linux_pci_dev_init(&sc->sc_pci_dev, self, device_parent(self), pa, 0);
 
-       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);
-
        /* XXX errno Linux->NetBSD */
        error = -nvkm_device_pci_new(&sc->sc_pci_dev,
            nouveau_config, nouveau_debug,
@@ -204,6 +221,10 @@
        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)



Home | Main Index | Thread Index | Old Index