Module Name:    src
Committed By:   martin
Date:           Sun Mar  8 09:28:04 UTC 2020

Modified Files:
        src/sys/external/bsd/drm2/nouveau [netbsd-8]: nouveau_pci.c

Log Message:
Pull up following revision(s) (requested by mrg in ticket #1512):

        sys/external/bsd/drm2/nouveau/nouveau_pci.c: revision 1.24,1.25
        (via patch)

Improve nouveau pci attachment code so it waits for the availability of /
before trying to load firmware.
Fixes my PR 54274.

LGTM mrg

list the PCI ID range for new nvidia TU117 and TU116.

adjust the check to simply be >= 0x1580, which is the
first pciid not support.

should fix PR#54600.


To generate a diff of this commit:
cvs rdiff -u -r1.8.10.2 -r1.8.10.3 \
    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.8.10.2 src/sys/external/bsd/drm2/nouveau/nouveau_pci.c:1.8.10.3
--- src/sys/external/bsd/drm2/nouveau/nouveau_pci.c:1.8.10.2	Tue Dec 25 11:25:00 2018
+++ src/sys/external/bsd/drm2/nouveau/nouveau_pci.c	Sun Mar  8 09:28:04 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: nouveau_pci.c,v 1.8.10.2 2018/12/25 11:25:00 martin Exp $	*/
+/*	$NetBSD: nouveau_pci.c,v 1.8.10.3 2020/03/08 09:28:04 martin 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.8.10.2 2018/12/25 11:25:00 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nouveau_pci.c,v 1.8.10.3 2020/03/08 09:28:04 martin Exp $");
 
 #include <sys/types.h>
 #include <sys/device.h>
@@ -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)

Reply via email to