Module Name: src Committed By: riastradh Date: Mon May 20 11:34:19 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. 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 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. To generate a diff of this commit: cvs rdiff -u -r1.80 -r1.81 src/sys/arch/sparc64/dev/pci_machdep.c cvs rdiff -u -r1.28 -r1.29 src/sys/arch/sparc64/include/pci_machdep.h cvs rdiff -u -r1.21 -r1.22 src/sys/arch/xen/include/pci_machdep.h cvs rdiff -u -r1.26 -r1.27 src/sys/arch/xen/xen/xpci_xenbus.c cvs rdiff -u -r1.26 -r1.27 src/sys/dev/acpi/acpi_mcfg.c cvs rdiff -u -r1.165 -r1.166 src/sys/dev/pci/pci.c cvs rdiff -u -r1.117 -r1.118 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.80 src/sys/arch/sparc64/dev/pci_machdep.c:1.81 --- src/sys/arch/sparc64/dev/pci_machdep.c:1.80 Wed Dec 20 05:33:58 2023 +++ src/sys/arch/sparc64/dev/pci_machdep.c Mon May 20 11:34:18 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: pci_machdep.c,v 1.80 2023/12/20 05:33:58 thorpej Exp $ */ +/* $NetBSD: pci_machdep.c,v 1.81 2024/05/20 11:34:18 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.80 2023/12/20 05:33:58 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pci_machdep.c,v 1.81 2024/05/20 11:34:18 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.28 src/sys/arch/sparc64/include/pci_machdep.h:1.29 --- src/sys/arch/sparc64/include/pci_machdep.h:1.28 Thu Jul 7 06:55:38 2016 +++ src/sys/arch/sparc64/include/pci_machdep.h Mon May 20 11:34:18 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: pci_machdep.h,v 1.28 2016/07/07 06:55:38 msaitoh Exp $ */ +/* $NetBSD: pci_machdep.h,v 1.29 2024/05/20 11:34:18 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.21 src/sys/arch/xen/include/pci_machdep.h:1.22 --- src/sys/arch/xen/include/pci_machdep.h:1.21 Mon May 23 15:03:05 2022 +++ src/sys/arch/xen/include/pci_machdep.h Mon May 20 11:34:18 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: pci_machdep.h,v 1.21 2022/05/23 15:03:05 bouyer Exp $ */ +/* $NetBSD: pci_machdep.h,v 1.22 2024/05/20 11:34:18 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.26 src/sys/arch/xen/xen/xpci_xenbus.c:1.27 --- src/sys/arch/xen/xen/xpci_xenbus.c:1.26 Fri Feb 9 22:08:33 2024 +++ src/sys/arch/xen/xen/xpci_xenbus.c Mon May 20 11:34:18 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: xpci_xenbus.c,v 1.26 2024/02/09 22:08:33 andvar Exp $ */ +/* $NetBSD: xpci_xenbus.c,v 1.27 2024/05/20 11:34:18 riastradh Exp $ */ /* * Copyright (c) 2009 Manuel Bouyer. @@ -25,7 +25,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: xpci_xenbus.c,v 1.26 2024/02/09 22:08:33 andvar Exp $"); +__KERNEL_RCSID(0, "$NetBSD: xpci_xenbus.c,v 1.27 2024/05/20 11:34:18 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.26 src/sys/dev/acpi/acpi_mcfg.c:1.27 --- src/sys/dev/acpi/acpi_mcfg.c:1.26 Fri Oct 14 22:10:15 2022 +++ src/sys/dev/acpi/acpi_mcfg.c Mon May 20 11:34:19 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: acpi_mcfg.c,v 1.26 2022/10/14 22:10:15 jmcneill Exp $ */ +/* $NetBSD: acpi_mcfg.c,v 1.27 2024/05/20 11:34:19 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.26 2022/10/14 22:10:15 jmcneill Exp $"); +__KERNEL_RCSID(0, "$NetBSD: acpi_mcfg.c,v 1.27 2024/05/20 11:34:19 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.165 src/sys/dev/pci/pci.c:1.166 --- src/sys/dev/pci/pci.c:1.165 Wed Aug 24 11:19:25 2022 +++ src/sys/dev/pci/pci.c Mon May 20 11:34:19 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: pci.c,v 1.165 2022/08/24 11:19:25 riastradh Exp $ */ +/* $NetBSD: pci.c,v 1.166 2024/05/20 11:34:19 riastradh Exp $ */ /* * Copyright (c) 1995, 1996, 1997, 1998 @@ -36,7 +36,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: pci.c,v 1.165 2022/08/24 11:19:25 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pci.c,v 1.166 2024/05/20 11:34:19 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,26 @@ 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 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 +713,32 @@ 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 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 +844,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.117 src/sys/dev/pci/pcivar.h:1.118 --- src/sys/dev/pci/pcivar.h:1.117 Sun Feb 27 14:18:52 2022 +++ src/sys/dev/pci/pcivar.h Mon May 20 11:34:19 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: pcivar.h,v 1.117 2022/02/27 14:18:52 riastradh Exp $ */ +/* $NetBSD: pcivar.h,v 1.118 2024/05/20 11:34:19 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 *);