Module Name:    src
Committed By:   jdolecek
Date:           Wed Feb 12 22:34:51 UTC 2020

Modified Files:
        src/sys/external/bsd/drm2/dist/drm/nouveau/nvkm/subdev/pci:
            nouveau_nvkm_subdev_pci_base.c

Log Message:
adjust the PCI interrupt allocation code to work the same as
drm_pci_request_irq(), now the driver successfully allocates MSI interrupt

[   3.6619808] nouveau0: info: NVIDIA GK208B (b06070b1)
[   3.7685336] nouveau0: info: bios: version 80.28.78.00.4b
[   3.7785491] nouveau0: interrupting at msi8 vec 0 (nouveau0)

related to PR kern/52440 by John D. Baker


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 \
    
src/sys/external/bsd/drm2/dist/drm/nouveau/nvkm/subdev/pci/nouveau_nvkm_subdev_pci_base.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/dist/drm/nouveau/nvkm/subdev/pci/nouveau_nvkm_subdev_pci_base.c
diff -u src/sys/external/bsd/drm2/dist/drm/nouveau/nvkm/subdev/pci/nouveau_nvkm_subdev_pci_base.c:1.6 src/sys/external/bsd/drm2/dist/drm/nouveau/nvkm/subdev/pci/nouveau_nvkm_subdev_pci_base.c:1.7
--- src/sys/external/bsd/drm2/dist/drm/nouveau/nvkm/subdev/pci/nouveau_nvkm_subdev_pci_base.c:1.6	Fri Feb  7 18:13:33 2020
+++ src/sys/external/bsd/drm2/dist/drm/nouveau/nvkm/subdev/pci/nouveau_nvkm_subdev_pci_base.c	Wed Feb 12 22:34:51 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: nouveau_nvkm_subdev_pci_base.c,v 1.6 2020/02/07 18:13:33 jmcneill Exp $	*/
+/*	$NetBSD: nouveau_nvkm_subdev_pci_base.c,v 1.7 2020/02/12 22:34:51 jdolecek Exp $	*/
 
 /*
  * Copyright 2015 Red Hat Inc.
@@ -24,7 +24,7 @@
  * Authors: Ben Skeggs <[email protected]>
  */
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: nouveau_nvkm_subdev_pci_base.c,v 1.6 2020/02/07 18:13:33 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nouveau_nvkm_subdev_pci_base.c,v 1.7 2020/02/12 22:34:51 jdolecek Exp $");
 
 #include "priv.h"
 #include "agp.h"
@@ -141,22 +141,51 @@ nvkm_pci_init(struct nvkm_subdev *subdev
 
 #ifdef __NetBSD__
     {
+	const char *const name = device_xname(pci_dev_dev(pdev));
 	const struct pci_attach_args *pa = &pdev->pd_pa;
-	int counts[PCI_INTR_TYPE_SIZE] =  {
-			[PCI_INTR_TYPE_INTX] = 1,
-			[PCI_INTR_TYPE_MSI] = 0,
-			[PCI_INTR_TYPE_MSIX] = 0,
-	};
+	const char *intrstr;
+	char intrbuf[PCI_INTRSTR_LEN];
 
-	/* XXX errno NetBSD->Linux */
-	ret = -pci_intr_alloc(pa, &pci->pci_ihp, counts, PCI_INTR_TYPE_INTX);
-	if (ret)
-		return ret;
+	/* XXX convert to use drm_pci_request_irq() */
+	if (pdev->msi_enabled) {
+		if (pdev->pd_intr_handles == NULL) {
+			if ((ret = pci_msi_alloc_exact(pa, &pci->pci_ihp,
+			    1))) {
+				aprint_error_dev(pci_dev_dev(pdev),
+				    "couldn't allocate MSI (%s)\n", name);
+				/* XXX errno NetBSD->Linux */
+				return -ret;
+			}
+		} else {
+			pci->pci_ihp = pdev->pd_intr_handles;
+			pdev->pd_intr_handles = NULL;
+		}
+	} else {
+		if ((ret = pci_intx_alloc(pa, &pci->pci_ihp))) {
+			aprint_error_dev(pci_dev_dev(pdev),
+			    "couldn't allocate INTx interrupt (%s)\n",
+			    name);
+
+			/* XXX errno NetBSD->Linux */
+			return -ret;
+		}
+	}
+
+	intrstr = pci_intr_string(pa->pa_pc, pci->pci_ihp[0],
+	    intrbuf, sizeof(intrbuf));
 	pci->pci_intrcookie = pci_intr_establish_xname(pa->pa_pc,
 	    pci->pci_ihp[0], IPL_DRM, nvkm_pci_intr, pci,
-	    device_xname(pci_dev_dev(pdev)));
-	if (pci->pci_intrcookie == NULL)
+	    name);
+	if (pci->pci_intrcookie == NULL) {
+		aprint_error_dev(pci_dev_dev(pdev),
+		    "couldn't establish interrupt at %s (%s)\n", intrstr, name);
+		pci_intr_release(pa->pa_pc, pci->pci_ihp, 1);
+		pci->pci_ihp = NULL;
 		return -EIO;	/* XXX er? */
+	}
+
+	aprint_normal_dev(pci_dev_dev(pdev), "interrupting at %s (%s)\n",
+	    intrstr, name);
     }
 #else
 	ret = request_irq(pdev->irq, nvkm_pci_intr, IRQF_SHARED, "nvkm", pci);

Reply via email to