Module Name: src
Committed By: wiz
Date: Wed Jul 3 20:47:22 UTC 2019
Modified Files:
src/sys/external/bsd/drm2/nouveau: nouveau_pci.c
Log Message:
Improve nouveau pci attachment code so it waits for the availability of /
before trying to load firmware.
Fixes my PR 54274.
LGTM mrg
To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/sys/external/bsd/drm2/nouveau/nouveau_pci.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/external/bsd/drm2/nouveau/nouveau_pci.c
diff -u src/sys/external/bsd/drm2/nouveau/nouveau_pci.c:1.23 src/sys/external/bsd/drm2/nouveau/nouveau_pci.c:1.24
--- src/sys/external/bsd/drm2/nouveau/nouveau_pci.c:1.23 Mon Dec 24 08:40:33 2018
+++ src/sys/external/bsd/drm2/nouveau/nouveau_pci.c Wed Jul 3 20:47:22 2019
@@ -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 @@ 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,
@@ -67,6 +68,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 *);
@@ -110,7 +112,7 @@ nouveau_pci_match(device_t parent, cfdat
* 0x1e80-0x1eff TU104
* 0x1f00-0x1f7f TU106
*/
-
+
if (IS_BETWEEN(0x1580, 0x15ff) ||
IS_BETWEEN(0x1b00, 0x1b7f) ||
IS_BETWEEN(0x1b80, 0x1bff) ||
@@ -144,22 +146,37 @@ nouveau_pci_attach(device_t parent, devi
{
struct nouveau_pci_softc *const sc = device_private(self);
const struct pci_attach_args *const pa = aux;
- int error;
pci_aprint_devinfo(pa, NULL);
- sc->sc_dev = self;
+ if (!pmf_device_register(self, &nouveau_pci_suspend, &nouveau_pci_resume))
+ aprint_error_dev(self, "unable to establish power handler\n");
- /* Initialize the Linux PCI device descriptor. */
- linux_pci_dev_init(&sc->sc_pci_dev, self, device_parent(self), pa, 0);
+ /*
+ * 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;
- if (!pmf_device_register(self, &nouveau_pci_suspend,
- &nouveau_pci_resume))
- aprint_error_dev(self, "unable to establish power handler\n");
+ 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);
+
/* XXX errno Linux->NetBSD */
error = -nvkm_device_pci_new(&sc->sc_pci_dev,
nouveau_config, nouveau_debug,
@@ -204,6 +221,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)