Module Name:    src
Committed By:   riastradh
Date:           Mon May 20 19:15:49 UTC 2024

Modified Files:
        src/sys/arch/sparc64/dev: pci_machdep.c
        src/sys/arch/sparc64/include: pci_machdep.h
        src/sys/arch/xen/include: pci_machdep.h
        src/sys/arch/xen/xen: xpci_xenbus.c
        src/sys/dev/acpi: acpi_mcfg.c
        src/sys/dev/pci: pci.c pcivar.h

Log Message:
Revert "pci: Pass cookie through pci_find_device, pci_enumerate_bus."

Evidently something is wrong with this, to be diagnosed and redone
once the builds and tests are in better shape.


To generate a diff of this commit:
cvs rdiff -u -r1.81 -r1.82 src/sys/arch/sparc64/dev/pci_machdep.c
cvs rdiff -u -r1.29 -r1.30 src/sys/arch/sparc64/include/pci_machdep.h
cvs rdiff -u -r1.22 -r1.23 src/sys/arch/xen/include/pci_machdep.h
cvs rdiff -u -r1.27 -r1.28 src/sys/arch/xen/xen/xpci_xenbus.c
cvs rdiff -u -r1.27 -r1.28 src/sys/dev/acpi/acpi_mcfg.c
cvs rdiff -u -r1.166 -r1.167 src/sys/dev/pci/pci.c
cvs rdiff -u -r1.118 -r1.119 src/sys/dev/pci/pcivar.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/sparc64/dev/pci_machdep.c
diff -u src/sys/arch/sparc64/dev/pci_machdep.c:1.81 src/sys/arch/sparc64/dev/pci_machdep.c:1.82
--- src/sys/arch/sparc64/dev/pci_machdep.c:1.81	Mon May 20 11:34:18 2024
+++ src/sys/arch/sparc64/dev/pci_machdep.c	Mon May 20 19:15:48 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: pci_machdep.c,v 1.81 2024/05/20 11:34:18 riastradh Exp $	*/
+/*	$NetBSD: pci_machdep.c,v 1.82 2024/05/20 19:15:48 riastradh Exp $	*/
 
 /*
  * Copyright (c) 1999, 2000 Matthew R. Green
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pci_machdep.c,v 1.81 2024/05/20 11:34:18 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pci_machdep.c,v 1.82 2024/05/20 19:15:48 riastradh Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -244,9 +244,8 @@ pci_decompose_tag(pci_chipset_tag_t pc, 
 }
 
 int
-sparc64_pci_enumerate_bus1(struct pci_softc *sc, const int *locators,
-    int (*match)(void *, const struct pci_attach_args *), void *cookie,
-    struct pci_attach_args *pap)
+sparc64_pci_enumerate_bus(struct pci_softc *sc, const int *locators,
+    int (*match)(const struct pci_attach_args *), struct pci_attach_args *pap)
 {
 	struct ofw_pci_register reg;
 	pci_chipset_tag_t pc = sc->sc_pc;
@@ -308,10 +307,8 @@ sparc64_pci_enumerate_bus1(struct pci_so
 		if (OF_getprop(node, "class-code", &class, sizeof(class)) != 
 		    sizeof(class))
 			continue;
-		if (OF_getprop(node, "reg", &reg, sizeof(reg)) < sizeof(reg)) {
-			panic("pci_enumerate_bus1: \"%s\" regs too small",
-			    name);
-		}
+		if (OF_getprop(node, "reg", &reg, sizeof(reg)) < sizeof(reg))
+			panic("pci_enumerate_bus: \"%s\" regs too small", name);
 
 		b = OFW_PCI_PHYS_HI_BUS(reg.phys_hi);
 		d = OFW_PCI_PHYS_HI_DEVICE(reg.phys_hi);
@@ -364,7 +361,7 @@ sparc64_pci_enumerate_bus1(struct pci_so
 			(cl << PCI_CACHELINE_SHIFT);
 		pci_conf_write(pc, tag, PCI_BHLC_REG, bhlc);
 
-		ret = pci_probe_device1(sc, tag, match, cookie, pap);
+		ret = pci_probe_device(sc, tag, match, pap);
 		if (match != NULL && ret != 0)
 			return (ret);
 	}

Index: src/sys/arch/sparc64/include/pci_machdep.h
diff -u src/sys/arch/sparc64/include/pci_machdep.h:1.29 src/sys/arch/sparc64/include/pci_machdep.h:1.30
--- src/sys/arch/sparc64/include/pci_machdep.h:1.29	Mon May 20 11:34:18 2024
+++ src/sys/arch/sparc64/include/pci_machdep.h	Mon May 20 19:15:48 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: pci_machdep.h,v 1.29 2024/05/20 11:34:18 riastradh Exp $ */
+/* $NetBSD: pci_machdep.h,v 1.30 2024/05/20 19:15:48 riastradh Exp $ */
 
 /*
  * Copyright (c) 1999 Matthew R. Green
@@ -95,10 +95,10 @@ int		pci_intr_map(const struct pci_attac
 		    pci_intr_handle_t *);
 void		pci_intr_disestablish(pci_chipset_tag_t, void *);
 
-int		sparc64_pci_enumerate_bus1(struct pci_softc *, const int *,
-		    int (*)(void *, const struct pci_attach_args *), void *,
+int		sparc64_pci_enumerate_bus(struct pci_softc *, const int *,
+		    int (*)(const struct pci_attach_args *),
 		    struct pci_attach_args *);
-#define PCI_MACHDEP_ENUMERATE_BUS1 sparc64_pci_enumerate_bus1
+#define PCI_MACHDEP_ENUMERATE_BUS sparc64_pci_enumerate_bus
 
 #define	pci_conf_read(pc, tag, reg) \
 		((pc)->spc_conf_read(pc, tag, reg))

Index: src/sys/arch/xen/include/pci_machdep.h
diff -u src/sys/arch/xen/include/pci_machdep.h:1.22 src/sys/arch/xen/include/pci_machdep.h:1.23
--- src/sys/arch/xen/include/pci_machdep.h:1.22	Mon May 20 11:34:18 2024
+++ src/sys/arch/xen/include/pci_machdep.h	Mon May 20 19:15:49 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: pci_machdep.h,v 1.22 2024/05/20 11:34:18 riastradh Exp $ */
+/* $NetBSD: pci_machdep.h,v 1.23 2024/05/20 19:15:49 riastradh Exp $ */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -67,14 +67,20 @@ typedef intr_handle_t pci_intr_handle_t;
 #include "opt_xen.h"
 
 #if !defined(DOM0OPS) && defined(XENPV)
-int		xpci_enumerate_bus1(struct pci_softc *, const int *,
-		   int (*)(void *, const struct pci_attach_args *), void *,
+int		xpci_enumerate_bus(struct pci_softc *, const int *,
+		   int (*)(const struct pci_attach_args *),
 		   struct pci_attach_args *);
-#define PCI_MACHDEP_ENUMERATE_BUS1 xpci_enumerate_bus1
+#define PCI_MACHDEP_ENUMERATE_BUS xpci_enumerate_bus
 #endif
 
 #ifdef XENPV
 void pci_conf_write16(pci_chipset_tag_t, pcitag_t, int, uint16_t);
 #endif
 
+/* functions provided to MI PCI */
+
+int		xen_pci_enumerate_bus(struct pci_softc *, const int *,
+		   int (*)(const struct pci_attach_args *),
+		   struct pci_attach_args *);
+
 #endif /* _XEN_PCI_MACHDEP_H_ */

Index: src/sys/arch/xen/xen/xpci_xenbus.c
diff -u src/sys/arch/xen/xen/xpci_xenbus.c:1.27 src/sys/arch/xen/xen/xpci_xenbus.c:1.28
--- src/sys/arch/xen/xen/xpci_xenbus.c:1.27	Mon May 20 11:34:18 2024
+++ src/sys/arch/xen/xen/xpci_xenbus.c	Mon May 20 19:15:49 2024
@@ -1,4 +1,4 @@
-/*      $NetBSD: xpci_xenbus.c,v 1.27 2024/05/20 11:34:18 riastradh Exp $      */
+/*      $NetBSD: xpci_xenbus.c,v 1.28 2024/05/20 19:15:49 riastradh Exp $      */
 
 /*
  * Copyright (c) 2009 Manuel Bouyer.
@@ -25,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: xpci_xenbus.c,v 1.27 2024/05/20 11:34:18 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xpci_xenbus.c,v 1.28 2024/05/20 19:15:49 riastradh Exp $");
 
 #include "opt_xen.h"
 
@@ -491,9 +491,8 @@ pci_conf_write(pci_chipset_tag_t pc, pci
 }
 
 int
-xpci_enumerate_bus1(struct pci_softc *sc, const int *locators,
-    int (*match)(void *, const struct pci_attach_args *), void *cookie,
-    struct pci_attach_args *pap)
+xpci_enumerate_bus(struct pci_softc *sc, const int *locators,
+    int (*match)(const struct pci_attach_args *), struct pci_attach_args *pap)
 {
 #if 0
 	char *string;
@@ -551,7 +550,7 @@ xpci_enumerate_bus1(struct pci_softc *sc
 			if (busn != sc->sc_bus)
 				goto endfor;
 			tag = pci_make_tag(pc, busn, devn, funcn);
-			err = pci_probe_device1(sc, tag, match, pap);
+			err = pci_probe_device(sc, tag, match, pap);
 			if (match != NULL && err != 0)
 				return (err);
 		}
@@ -620,7 +619,7 @@ endfor:
 					goto next;
 				}
 			}
-			err = pci_probe_device1(sc, tag, match, pap);
+			err = pci_probe_device(sc, tag, match, pap);
 			if (match != NULL && err != 0)
 				return (err);
 next:

Index: src/sys/dev/acpi/acpi_mcfg.c
diff -u src/sys/dev/acpi/acpi_mcfg.c:1.27 src/sys/dev/acpi/acpi_mcfg.c:1.28
--- src/sys/dev/acpi/acpi_mcfg.c:1.27	Mon May 20 11:34:19 2024
+++ src/sys/dev/acpi/acpi_mcfg.c	Mon May 20 19:15:49 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_mcfg.c,v 1.27 2024/05/20 11:34:19 riastradh Exp $	*/
+/*	$NetBSD: acpi_mcfg.c,v 1.28 2024/05/20 19:15:49 riastradh Exp $	*/
 
 /*-
  * Copyright (C) 2015 NONAKA Kimihiro <non...@netbsd.org>
@@ -28,7 +28,7 @@
 #include "opt_pci.h"
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi_mcfg.c,v 1.27 2024/05/20 11:34:19 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_mcfg.c,v 1.28 2024/05/20 19:15:49 riastradh Exp $");
 
 #include <sys/param.h>
 #include <sys/device.h>
@@ -524,6 +524,10 @@ acpimcfg_device_probe(const struct pci_a
 	return 0;
 }
 
+#ifdef PCI_MACHDEP_ENUMERATE_BUS
+#define pci_enumerate_bus PCI_MACHDEP_ENUMERATE_BUS
+#endif
+
 static void
 acpimcfg_scan_bus(struct pci_softc *sc, pci_chipset_tag_t pc, int bus)
 {

Index: src/sys/dev/pci/pci.c
diff -u src/sys/dev/pci/pci.c:1.166 src/sys/dev/pci/pci.c:1.167
--- src/sys/dev/pci/pci.c:1.166	Mon May 20 11:34:19 2024
+++ src/sys/dev/pci/pci.c	Mon May 20 19:15:49 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: pci.c,v 1.166 2024/05/20 11:34:19 riastradh Exp $	*/
+/*	$NetBSD: pci.c,v 1.167 2024/05/20 19:15:49 riastradh Exp $	*/
 
 /*
  * Copyright (c) 1995, 1996, 1997, 1998
@@ -36,7 +36,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pci.c,v 1.166 2024/05/20 11:34:19 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pci.c,v 1.167 2024/05/20 19:15:49 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_pci.h"
@@ -69,8 +69,8 @@ int pci_config_dump = 0;
 
 int	pciprint(void *, const char *);
 
-#ifdef PCI_MACHDEP_ENUMERATE_BUS1
-#define pci_enumerate_bus1 PCI_MACHDEP_ENUMERATE_BUS1
+#ifdef PCI_MACHDEP_ENUMERATE_BUS
+#define pci_enumerate_bus PCI_MACHDEP_ENUMERATE_BUS
 #endif
 
 /*
@@ -290,8 +290,8 @@ pci_bus_get_child_devhandle(struct pci_s
 }
 
 int
-pci_probe_device1(struct pci_softc *sc, pcitag_t tag,
-    int (*match)(void *, const struct pci_attach_args *), void *cookie,
+pci_probe_device(struct pci_softc *sc, pcitag_t tag,
+    int (*match)(const struct pci_attach_args *),
     struct pci_attach_args *pap)
 {
 	pci_chipset_tag_t pc = sc->sc_pc;
@@ -470,7 +470,7 @@ pci_probe_device1(struct pci_softc *sc, 
 #endif
 
 	if (match != NULL) {
-		ret = (*match)(cookie, &pa);
+		ret = (*match)(&pa);
 		if (ret != 0 && pap != NULL)
 			*pap = pa;
 	} else {
@@ -681,26 +681,9 @@ pci_get_ext_capability(pci_chipset_tag_t
 	return 0;
 }
 
-static int
-pci_match_cookieless(void *cookie, const struct pci_attach_args *pa)
-{
-	int (*match)(const struct pci_attach_args *) = cookie;
-
-	return (*match)(pa);
-}
-
 int
 pci_find_device(struct pci_attach_args *pa,
-    int (*match)(const struct pci_attach_args *))
-{
-	void *cookie = match;
-
-	return pci_find_device1(pa, &pci_match_cookieless, cookie);
-}
-
-int
-pci_find_device1(struct pci_attach_args *pa,
-    int (*match)(void *, const struct pci_attach_args *), void *cookie)
+		int (*match)(const struct pci_attach_args *))
 {
 	extern struct cfdriver pci_cd;
 	device_t pcidev;
@@ -713,32 +696,21 @@ pci_find_device1(struct pci_attach_args 
 	for (i = 0; i < pci_cd.cd_ndevs; i++) {
 		pcidev = device_lookup(&pci_cd, i);
 		if (pcidev != NULL &&
-		    pci_enumerate_bus1(device_private(pcidev), wildcard,
-			match, cookie, pa) != 0)
+		    pci_enumerate_bus(device_private(pcidev), wildcard,
+		    		      match, pa) != 0)
 			return 1;
 	}
 	return 0;
 }
 
-int
-pci_enumerate_bus(struct pci_softc *sc, const int *locators,
-    int (*match)(const struct pci_attach_args *), struct pci_attach_args *pap)
-{
-	void *cookie = match;
-
-	return pci_enumerate_bus1(sc, locators, &pci_match_cookieless, cookie,
-	    pap);
-}
-
-#ifndef PCI_MACHDEP_ENUMERATE_BUS1
+#ifndef PCI_MACHDEP_ENUMERATE_BUS
 /*
  * Generic PCI bus enumeration routine.  Used unless machine-dependent
  * code needs to provide something else.
  */
 int
-pci_enumerate_bus1(struct pci_softc *sc, const int *locators,
-    int (*match)(void *, const struct pci_attach_args *), void *cookie,
-    struct pci_attach_args *pap)
+pci_enumerate_bus(struct pci_softc *sc, const int *locators,
+    int (*match)(const struct pci_attach_args *), struct pci_attach_args *pap)
 {
 	pci_chipset_tag_t pc = sc->sc_pc;
 	int device, function, nfunctions, ret;
@@ -844,14 +816,14 @@ pci_enumerate_bus1(struct pci_softc *sc,
 			    (qd->quirks & PCI_QUIRK_SKIP_FUNC(function)) != 0)
 				continue;
 			tag = pci_make_tag(pc, sc->sc_bus, device, function);
-			ret = pci_probe_device1(sc, tag, match, cookie, pap);
+			ret = pci_probe_device(sc, tag, match, pap);
 			if (match != NULL && ret != 0)
 				return ret;
 		}
 	}
 	return 0;
 }
-#endif /* PCI_MACHDEP_ENUMERATE_BUS1 */
+#endif /* PCI_MACHDEP_ENUMERATE_BUS */
 
 
 /*

Index: src/sys/dev/pci/pcivar.h
diff -u src/sys/dev/pci/pcivar.h:1.118 src/sys/dev/pci/pcivar.h:1.119
--- src/sys/dev/pci/pcivar.h:1.118	Mon May 20 11:34:19 2024
+++ src/sys/dev/pci/pcivar.h	Mon May 20 19:15:49 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: pcivar.h,v 1.118 2024/05/20 11:34:19 riastradh Exp $	*/
+/*	$NetBSD: pcivar.h,v 1.119 2024/05/20 19:15:49 riastradh Exp $	*/
 
 /*
  * Copyright (c) 1996, 1997 Christopher G. Demetriou.  All rights reserved.
@@ -339,15 +339,12 @@ const struct device_compatible_entry *
 	    const struct device_compatible_entry *);
 int	pci_compatible_match_subsys(const struct pci_attach_args *,
 	    const struct device_compatible_entry *);
+#ifndef PCI_MACHDEP_ENUMERATE_BUS
 int	pci_enumerate_bus(struct pci_softc *, const int *,
 	    int (*)(const struct pci_attach_args *), struct pci_attach_args *);
-#ifndef PCI_MACHDEP_ENUMERATE_BUS1
-int	pci_enumerate_bus1(struct pci_softc *, const int *,
-	    int (*)(void *, const struct pci_attach_args *), void *,
-	    struct pci_attach_args *);
 #endif
-int	pci_probe_device1(struct pci_softc *, pcitag_t tag,
-	    int (*)(void *, const struct pci_attach_args *), void *,
+int	pci_probe_device(struct pci_softc *, pcitag_t tag,
+	    int (*)(const struct pci_attach_args *),
 	    struct pci_attach_args *);
 void	pci_devinfo(pcireg_t, pcireg_t, int, char *, size_t);
 void	pci_aprint_devinfo_fancy(const struct pci_attach_args *,
@@ -385,10 +382,8 @@ int	pci_vpd_write(pci_chipset_tag_t, pci
 /*
  * Misc.
  */
-int	pci_find_device(struct pci_attach_args *,
-	    int (*match)(const struct pci_attach_args *));
-int	pci_find_device1(struct pci_attach_args *,
-	    int (*match)(void *, const struct pci_attach_args *), void *);
+int	pci_find_device(struct pci_attach_args *pa,
+			int (*match)(const struct pci_attach_args *));
 int	pci_dma64_available(const struct pci_attach_args *);
 void	pci_conf_capture(pci_chipset_tag_t, pcitag_t, struct pci_conf_state *);
 void	pci_conf_restore(pci_chipset_tag_t, pcitag_t, struct pci_conf_state *);

Reply via email to