Module Name: src
Committed By: riastradh
Date: Sun Jun 23 00:53:34 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:
pci: Pass cookie through pci_find_device, pci_enumerate_bus, take 2.
New functions pci_find_device1 and pci_enumerate_bus1 have the cookie
argument. Existing symbols pci_find_device and pci_enumerate_bus are
now wrappers for the cookieless version.
This will allow pci_find_device callers to pass a cookie through to
the match function so they can keep state or pass in extra parameters
like b/d/f numbers, which will allow us to nix some horrible kludges
in the Linux PCI API emulation for drm (and, perhaps, Intel wifi).
This change drops the symbol pci_probe_device, in favour of a new
pci_probe_device1 with the cookie argument. But I don't think that
requires a revbump because it's only called by MD pci_enumerate_bus1
implementations, which don't live in modules anyway.
Take 2: Make sure to handle NULL match function.
To generate a diff of this commit:
cvs rdiff -u -r1.82 -r1.83 src/sys/arch/sparc64/dev/pci_machdep.c
cvs rdiff -u -r1.30 -r1.31 src/sys/arch/sparc64/include/pci_machdep.h
cvs rdiff -u -r1.23 -r1.24 src/sys/arch/xen/include/pci_machdep.h
cvs rdiff -u -r1.28 -r1.29 src/sys/arch/xen/xen/xpci_xenbus.c
cvs rdiff -u -r1.28 -r1.29 src/sys/dev/acpi/acpi_mcfg.c
cvs rdiff -u -r1.167 -r1.168 src/sys/dev/pci/pci.c
cvs rdiff -u -r1.119 -r1.120 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.82 src/sys/arch/sparc64/dev/pci_machdep.c:1.83
--- src/sys/arch/sparc64/dev/pci_machdep.c:1.82 Mon May 20 19:15:48 2024
+++ src/sys/arch/sparc64/dev/pci_machdep.c Sun Jun 23 00:53:34 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: pci_machdep.c,v 1.82 2024/05/20 19:15:48 riastradh Exp $ */
+/* $NetBSD: pci_machdep.c,v 1.83 2024/06/23 00:53:34 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.82 2024/05/20 19:15:48 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pci_machdep.c,v 1.83 2024/06/23 00:53:34 riastradh Exp $");
#include <sys/types.h>
#include <sys/param.h>
@@ -244,8 +244,9 @@ pci_decompose_tag(pci_chipset_tag_t pc,
}
int
-sparc64_pci_enumerate_bus(struct pci_softc *sc, const int *locators,
- int (*match)(const struct pci_attach_args *), struct pci_attach_args *pap)
+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)
{
struct ofw_pci_register reg;
pci_chipset_tag_t pc = sc->sc_pc;
@@ -307,8 +308,10 @@ sparc64_pci_enumerate_bus(struct pci_sof
if (OF_getprop(node, "class-code", &class, sizeof(class)) !=
sizeof(class))
continue;
- if (OF_getprop(node, "reg", ®, sizeof(reg)) < sizeof(reg))
- panic("pci_enumerate_bus: \"%s\" regs too small", name);
+ if (OF_getprop(node, "reg", ®, sizeof(reg)) < sizeof(reg)) {
+ panic("pci_enumerate_bus1: \"%s\" regs too small",
+ name);
+ }
b = OFW_PCI_PHYS_HI_BUS(reg.phys_hi);
d = OFW_PCI_PHYS_HI_DEVICE(reg.phys_hi);
@@ -361,7 +364,7 @@ sparc64_pci_enumerate_bus(struct pci_sof
(cl << PCI_CACHELINE_SHIFT);
pci_conf_write(pc, tag, PCI_BHLC_REG, bhlc);
- ret = pci_probe_device(sc, tag, match, pap);
+ ret = pci_probe_device1(sc, tag, match, cookie, 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.30 src/sys/arch/sparc64/include/pci_machdep.h:1.31
--- src/sys/arch/sparc64/include/pci_machdep.h:1.30 Mon May 20 19:15:48 2024
+++ src/sys/arch/sparc64/include/pci_machdep.h Sun Jun 23 00:53:34 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: pci_machdep.h,v 1.30 2024/05/20 19:15:48 riastradh Exp $ */
+/* $NetBSD: pci_machdep.h,v 1.31 2024/06/23 00:53:34 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_bus(struct pci_softc *, const int *,
- int (*)(const struct pci_attach_args *),
+int sparc64_pci_enumerate_bus1(struct pci_softc *, const int *,
+ int (*)(void *, const struct pci_attach_args *), void *,
struct pci_attach_args *);
-#define PCI_MACHDEP_ENUMERATE_BUS sparc64_pci_enumerate_bus
+#define PCI_MACHDEP_ENUMERATE_BUS1 sparc64_pci_enumerate_bus1
#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.23 src/sys/arch/xen/include/pci_machdep.h:1.24
--- src/sys/arch/xen/include/pci_machdep.h:1.23 Mon May 20 19:15:49 2024
+++ src/sys/arch/xen/include/pci_machdep.h Sun Jun 23 00:53:34 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: pci_machdep.h,v 1.23 2024/05/20 19:15:49 riastradh Exp $ */
+/* $NetBSD: pci_machdep.h,v 1.24 2024/06/23 00:53:34 riastradh Exp $ */
/*
* Copyright (c) 2006 Manuel Bouyer.
@@ -67,20 +67,14 @@ typedef intr_handle_t pci_intr_handle_t;
#include "opt_xen.h"
#if !defined(DOM0OPS) && defined(XENPV)
-int xpci_enumerate_bus(struct pci_softc *, const int *,
- int (*)(const struct pci_attach_args *),
+int xpci_enumerate_bus1(struct pci_softc *, const int *,
+ int (*)(void *, const struct pci_attach_args *), void *,
struct pci_attach_args *);
-#define PCI_MACHDEP_ENUMERATE_BUS xpci_enumerate_bus
+#define PCI_MACHDEP_ENUMERATE_BUS1 xpci_enumerate_bus1
#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.28 src/sys/arch/xen/xen/xpci_xenbus.c:1.29
--- src/sys/arch/xen/xen/xpci_xenbus.c:1.28 Mon May 20 19:15:49 2024
+++ src/sys/arch/xen/xen/xpci_xenbus.c Sun Jun 23 00:53:34 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: xpci_xenbus.c,v 1.28 2024/05/20 19:15:49 riastradh Exp $ */
+/* $NetBSD: xpci_xenbus.c,v 1.29 2024/06/23 00:53:34 riastradh Exp $ */
/*
* Copyright (c) 2009 Manuel Bouyer.
@@ -25,7 +25,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: xpci_xenbus.c,v 1.28 2024/05/20 19:15:49 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xpci_xenbus.c,v 1.29 2024/06/23 00:53:34 riastradh Exp $");
#include "opt_xen.h"
@@ -491,8 +491,9 @@ pci_conf_write(pci_chipset_tag_t pc, pci
}
int
-xpci_enumerate_bus(struct pci_softc *sc, const int *locators,
- int (*match)(const struct pci_attach_args *), struct pci_attach_args *pap)
+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)
{
#if 0
char *string;
@@ -550,7 +551,7 @@ xpci_enumerate_bus(struct pci_softc *sc,
if (busn != sc->sc_bus)
goto endfor;
tag = pci_make_tag(pc, busn, devn, funcn);
- err = pci_probe_device(sc, tag, match, pap);
+ err = pci_probe_device1(sc, tag, match, pap);
if (match != NULL && err != 0)
return (err);
}
@@ -619,7 +620,7 @@ endfor:
goto next;
}
}
- err = pci_probe_device(sc, tag, match, pap);
+ err = pci_probe_device1(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.28 src/sys/dev/acpi/acpi_mcfg.c:1.29
--- src/sys/dev/acpi/acpi_mcfg.c:1.28 Mon May 20 19:15:49 2024
+++ src/sys/dev/acpi/acpi_mcfg.c Sun Jun 23 00:53:34 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_mcfg.c,v 1.28 2024/05/20 19:15:49 riastradh Exp $ */
+/* $NetBSD: acpi_mcfg.c,v 1.29 2024/06/23 00:53:34 riastradh Exp $ */
/*-
* Copyright (C) 2015 NONAKA Kimihiro <[email protected]>
@@ -28,7 +28,7 @@
#include "opt_pci.h"
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi_mcfg.c,v 1.28 2024/05/20 19:15:49 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_mcfg.c,v 1.29 2024/06/23 00:53:34 riastradh Exp $");
#include <sys/param.h>
#include <sys/device.h>
@@ -524,10 +524,6 @@ 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.167 src/sys/dev/pci/pci.c:1.168
--- src/sys/dev/pci/pci.c:1.167 Mon May 20 19:15:49 2024
+++ src/sys/dev/pci/pci.c Sun Jun 23 00:53:34 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: pci.c,v 1.167 2024/05/20 19:15:49 riastradh Exp $ */
+/* $NetBSD: pci.c,v 1.168 2024/06/23 00:53:34 riastradh Exp $ */
/*
* Copyright (c) 1995, 1996, 1997, 1998
@@ -36,7 +36,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pci.c,v 1.167 2024/05/20 19:15:49 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pci.c,v 1.168 2024/06/23 00:53:34 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_BUS
-#define pci_enumerate_bus PCI_MACHDEP_ENUMERATE_BUS
+#ifdef PCI_MACHDEP_ENUMERATE_BUS1
+#define pci_enumerate_bus1 PCI_MACHDEP_ENUMERATE_BUS1
#endif
/*
@@ -290,8 +290,8 @@ pci_bus_get_child_devhandle(struct pci_s
}
int
-pci_probe_device(struct pci_softc *sc, pcitag_t tag,
- int (*match)(const struct pci_attach_args *),
+pci_probe_device1(struct pci_softc *sc, pcitag_t tag,
+ int (*match)(void *, const struct pci_attach_args *), void *cookie,
struct pci_attach_args *pap)
{
pci_chipset_tag_t pc = sc->sc_pc;
@@ -470,7 +470,7 @@ pci_probe_device(struct pci_softc *sc, p
#endif
if (match != NULL) {
- ret = (*match)(&pa);
+ ret = (*match)(cookie, &pa);
if (ret != 0 && pap != NULL)
*pap = pa;
} else {
@@ -681,9 +681,28 @@ 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 *))
+ int (*match)(const struct pci_attach_args *))
+{
+ void *cookie = match;
+
+ return (match == NULL
+ ? pci_find_device1(pa, NULL, NULL)
+ : 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)
{
extern struct cfdriver pci_cd;
device_t pcidev;
@@ -696,21 +715,34 @@ pci_find_device(struct pci_attach_args *
for (i = 0; i < pci_cd.cd_ndevs; i++) {
pcidev = device_lookup(&pci_cd, i);
if (pcidev != NULL &&
- pci_enumerate_bus(device_private(pcidev), wildcard,
- match, pa) != 0)
+ pci_enumerate_bus1(device_private(pcidev), wildcard,
+ match, cookie, pa) != 0)
return 1;
}
return 0;
}
-#ifndef PCI_MACHDEP_ENUMERATE_BUS
+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 (match == NULL
+ ? pci_enumerate_bus1(sc, locators, NULL, NULL, pap)
+ : pci_enumerate_bus1(sc, locators, &pci_match_cookieless, cookie,
+ pap));
+}
+
+#ifndef PCI_MACHDEP_ENUMERATE_BUS1
/*
* Generic PCI bus enumeration routine. Used unless machine-dependent
* code needs to provide something else.
*/
int
-pci_enumerate_bus(struct pci_softc *sc, const int *locators,
- int (*match)(const struct pci_attach_args *), struct pci_attach_args *pap)
+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_chipset_tag_t pc = sc->sc_pc;
int device, function, nfunctions, ret;
@@ -816,14 +848,14 @@ pci_enumerate_bus(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_device(sc, tag, match, pap);
+ ret = pci_probe_device1(sc, tag, match, cookie, pap);
if (match != NULL && ret != 0)
return ret;
}
}
return 0;
}
-#endif /* PCI_MACHDEP_ENUMERATE_BUS */
+#endif /* PCI_MACHDEP_ENUMERATE_BUS1 */
/*
Index: src/sys/dev/pci/pcivar.h
diff -u src/sys/dev/pci/pcivar.h:1.119 src/sys/dev/pci/pcivar.h:1.120
--- src/sys/dev/pci/pcivar.h:1.119 Mon May 20 19:15:49 2024
+++ src/sys/dev/pci/pcivar.h Sun Jun 23 00:53:34 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: pcivar.h,v 1.119 2024/05/20 19:15:49 riastradh Exp $ */
+/* $NetBSD: pcivar.h,v 1.120 2024/06/23 00:53:34 riastradh Exp $ */
/*
* Copyright (c) 1996, 1997 Christopher G. Demetriou. All rights reserved.
@@ -339,12 +339,15 @@ 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_device(struct pci_softc *, pcitag_t tag,
- int (*)(const struct pci_attach_args *),
+int pci_probe_device1(struct pci_softc *, pcitag_t tag,
+ int (*)(void *, const struct pci_attach_args *), void *,
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 *,
@@ -382,8 +385,10 @@ int pci_vpd_write(pci_chipset_tag_t, pci
/*
* Misc.
*/
-int pci_find_device(struct pci_attach_args *pa,
- int (*match)(const struct pci_attach_args *));
+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_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 *);