Module Name:    src
Committed By:   thorpej
Date:           Wed Sep 15 17:33:08 UTC 2021

Modified Files:
        src/sys/arch/sparc/sparc: promlib.c
        src/sys/dev/acpi: acpi_pci.c acpi_util.c
        src/sys/dev/ofw: ofw_pci_subr.c ofw_subr.c
        src/sys/dev/pci: Makefile pci.c pcivar.h
        src/sys/kern: subr_device.c
        src/sys/sys: Makefile device.h
Added Files:
        src/sys/dev/pci: pci_calls.h
        src/sys/sys: device_calls.h

Log Message:
Adjust the device_call() calling convention so as to provide type checking
of the arguments passed to the call, using auto-generated argument
structures and binding macros.


To generate a diff of this commit:
cvs rdiff -u -r1.48 -r1.49 src/sys/arch/sparc/sparc/promlib.c
cvs rdiff -u -r1.31 -r1.32 src/sys/dev/acpi/acpi_pci.c
cvs rdiff -u -r1.25 -r1.26 src/sys/dev/acpi/acpi_util.c
cvs rdiff -u -r1.1 -r1.2 src/sys/dev/ofw/ofw_pci_subr.c
cvs rdiff -u -r1.58 -r1.59 src/sys/dev/ofw/ofw_subr.c
cvs rdiff -u -r1.15 -r1.16 src/sys/dev/pci/Makefile
cvs rdiff -u -r1.161 -r1.162 src/sys/dev/pci/pci.c
cvs rdiff -u -r0 -r1.1 src/sys/dev/pci/pci_calls.h
cvs rdiff -u -r1.115 -r1.116 src/sys/dev/pci/pcivar.h
cvs rdiff -u -r1.8 -r1.9 src/sys/kern/subr_device.c
cvs rdiff -u -r1.176 -r1.177 src/sys/sys/Makefile
cvs rdiff -u -r1.174 -r1.175 src/sys/sys/device.h
cvs rdiff -u -r0 -r1.1 src/sys/sys/device_calls.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/sparc/sparc/promlib.c
diff -u src/sys/arch/sparc/sparc/promlib.c:1.48 src/sys/arch/sparc/sparc/promlib.c:1.49
--- src/sys/arch/sparc/sparc/promlib.c:1.48	Mon May 10 13:59:30 2021
+++ src/sys/arch/sparc/sparc/promlib.c	Wed Sep 15 17:33:08 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: promlib.c,v 1.48 2021/05/10 13:59:30 thorpej Exp $ */
+/*	$NetBSD: promlib.c,v 1.49 2021/09/15 17:33:08 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: promlib.c,v 1.48 2021/05/10 13:59:30 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: promlib.c,v 1.49 2021/09/15 17:33:08 thorpej Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_sparc_arch.h"
@@ -45,6 +45,8 @@ __KERNEL_RCSID(0, "$NetBSD: promlib.c,v 
 #include <sys/kernel.h>
 #include <sys/device.h>
 
+#include <sys/device_calls.h>
+
 #ifdef _STANDALONE
 #include <lib/libsa/stand.h>
 #define malloc(s,t,f)	alloc(s)
@@ -276,7 +278,7 @@ obp_device_enumerate_children(device_t d
 
 	return 0;
 }
-OBP_DEVICE_CALL_REGISTER("device-enumerate-children",
+OBP_DEVICE_CALL_REGISTER(DEVICE_ENUMERATE_CHILDREN_STR,
 			 obp_device_enumerate_children)
 #endif /* ! _STANDALONE */
 

Index: src/sys/dev/acpi/acpi_pci.c
diff -u src/sys/dev/acpi/acpi_pci.c:1.31 src/sys/dev/acpi/acpi_pci.c:1.32
--- src/sys/dev/acpi/acpi_pci.c:1.31	Wed May 12 23:22:33 2021
+++ src/sys/dev/acpi/acpi_pci.c	Wed Sep 15 17:33:08 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_pci.c,v 1.31 2021/05/12 23:22:33 thorpej Exp $ */
+/* $NetBSD: acpi_pci.c,v 1.32 2021/09/15 17:33:08 thorpej Exp $ */
 
 /*
  * Copyright (c) 2009, 2010 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi_pci.c,v 1.31 2021/05/12 23:22:33 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_pci.c,v 1.32 2021/09/15 17:33:08 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/device.h>
@@ -41,6 +41,8 @@ __KERNEL_RCSID(0, "$NetBSD: acpi_pci.c,v
 #include <dev/pci/pcidevs.h>
 #include <dev/pci/ppbreg.h>
 
+#include <dev/pci/pci_calls.h>
+
 #include <dev/acpi/acpireg.h>
 #include <dev/acpi/acpivar.h>
 #include <dev/acpi/acpi_pci.h>
@@ -576,5 +578,5 @@ acpi_pci_bus_get_child_devhandle(device_
 
 	return ENODEV;
 }
-ACPI_DEVICE_CALL_REGISTER("pci-bus-get-child-devhandle",
+ACPI_DEVICE_CALL_REGISTER(PCI_BUS_GET_CHILD_DEVHANDLE_STR,
 			  acpi_pci_bus_get_child_devhandle)

Index: src/sys/dev/acpi/acpi_util.c
diff -u src/sys/dev/acpi/acpi_util.c:1.25 src/sys/dev/acpi/acpi_util.c:1.26
--- src/sys/dev/acpi/acpi_util.c:1.25	Mon Aug  9 20:49:09 2021
+++ src/sys/dev/acpi/acpi_util.c	Wed Sep 15 17:33:08 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_util.c,v 1.25 2021/08/09 20:49:09 andvar Exp $ */
+/*	$NetBSD: acpi_util.c,v 1.26 2021/09/15 17:33:08 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2003, 2007, 2021 The NetBSD Foundation, Inc.
@@ -65,7 +65,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi_util.c,v 1.25 2021/08/09 20:49:09 andvar Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_util.c,v 1.26 2021/09/15 17:33:08 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/kmem.h>
@@ -75,6 +75,8 @@ __KERNEL_RCSID(0, "$NetBSD: acpi_util.c,
 #include <dev/acpi/acpivar.h>
 #include <dev/acpi/acpi_intr.h>
 
+#include <sys/device_calls.h>
+
 #include <machine/acpi_machdep.h>
 
 #define _COMPONENT	ACPI_BUS_COMPONENT
@@ -153,7 +155,7 @@ acpi_device_enumerate_children(device_t 
 
 	return 0;
 }
-ACPI_DEVICE_CALL_REGISTER("device-enumerate-children",
+ACPI_DEVICE_CALL_REGISTER(DEVICE_ENUMERATE_CHILDREN_STR,
 			  acpi_device_enumerate_children)
 
 /*

Index: src/sys/dev/ofw/ofw_pci_subr.c
diff -u src/sys/dev/ofw/ofw_pci_subr.c:1.1 src/sys/dev/ofw/ofw_pci_subr.c:1.2
--- src/sys/dev/ofw/ofw_pci_subr.c:1.1	Wed May 12 23:22:33 2021
+++ src/sys/dev/ofw/ofw_pci_subr.c	Wed Sep 15 17:33:08 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ofw_pci_subr.c,v 1.1 2021/05/12 23:22:33 thorpej Exp $	*/
+/*	$NetBSD: ofw_pci_subr.c,v 1.2 2021/09/15 17:33:08 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ofw_pci_subr.c,v 1.1 2021/05/12 23:22:33 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ofw_pci_subr.c,v 1.2 2021/09/15 17:33:08 thorpej Exp $");
 
 #include <sys/types.h>
 #include <sys/device.h>
@@ -38,6 +38,7 @@ __KERNEL_RCSID(0, "$NetBSD: ofw_pci_subr
 #include <sys/errno.h>
 
 #include <dev/pci/pcivar.h>
+#include <dev/pci/pci_calls.h>
 
 #include <dev/ofw/openfirm.h>
 #include <dev/ofw/ofw_pci.h>
@@ -82,5 +83,5 @@ ofw_pci_bus_get_child_devhandle(device_t
 
 	return ENODEV;
 }
-OF_DEVICE_CALL_REGISTER("pci-bus-get-child-devhandle",
+OF_DEVICE_CALL_REGISTER(PCI_BUS_GET_CHILD_DEVHANDLE_STR,
 			ofw_pci_bus_get_child_devhandle)

Index: src/sys/dev/ofw/ofw_subr.c
diff -u src/sys/dev/ofw/ofw_subr.c:1.58 src/sys/dev/ofw/ofw_subr.c:1.59
--- src/sys/dev/ofw/ofw_subr.c:1.58	Sat Apr 24 23:36:57 2021
+++ src/sys/dev/ofw/ofw_subr.c	Wed Sep 15 17:33:08 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ofw_subr.c,v 1.58 2021/04/24 23:36:57 thorpej Exp $	*/
+/*	$NetBSD: ofw_subr.c,v 1.59 2021/09/15 17:33:08 thorpej Exp $	*/
 
 /*
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -60,12 +60,15 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ofw_subr.c,v 1.58 2021/04/24 23:36:57 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ofw_subr.c,v 1.59 2021/09/15 17:33:08 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/device.h>
 #include <sys/kmem.h>
 #include <sys/systm.h>
+
+#include <sys/device_calls.h>
+
 #include <dev/ofw/openfirm.h>
 
 #define	OFW_MAX_STACK_BUF_SIZE	256
@@ -130,7 +133,7 @@ of_device_enumerate_children(device_t de
 
 	return 0;
 }
-OF_DEVICE_CALL_REGISTER("device-enumerate-children",
+OF_DEVICE_CALL_REGISTER(DEVICE_ENUMERATE_CHILDREN_STR,
 			of_device_enumerate_children)
 
 /*

Index: src/sys/dev/pci/Makefile
diff -u src/sys/dev/pci/Makefile:1.15 src/sys/dev/pci/Makefile:1.16
--- src/sys/dev/pci/Makefile:1.15	Wed Dec 12 07:04:05 2018
+++ src/sys/dev/pci/Makefile	Wed Sep 15 17:33:08 2021
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.15 2018/12/12 07:04:05 maxv Exp $
+#	$NetBSD: Makefile,v 1.16 2021/09/15 17:33:08 thorpej Exp $
 
 # use 'make -f Makefile.pcidevs' to make pcidevs.h and pcidevs_data.h
 
@@ -9,4 +9,10 @@ INCS=	amrreg.h amrio.h mlyio.h mlyreg.h 
 	pcidevs.h pcidevs_data.h pciio.h pcireg.h \
 	tgareg.h twereg.h tweio.h
 
+pci_calls.h: ${.CURDIR}/pci_calls
+	echo "${TOOL_AWK} -f ${.CURDIR}/../../kern/gendevcalls.awk \
+	    ${.CURDIR}/pci_calls > ${.CURDIR}/pci_calls.h"
+	${TOOL_AWK} -f ${.CURDIR}/../../kern/gendevcalls.awk \
+	    ${.CURDIR}/pci_calls > ${.CURDIR}/pci_calls.h
+
 .include <bsd.kinc.mk>

Index: src/sys/dev/pci/pci.c
diff -u src/sys/dev/pci/pci.c:1.161 src/sys/dev/pci/pci.c:1.162
--- src/sys/dev/pci/pci.c:1.161	Sat Aug  7 16:19:14 2021
+++ src/sys/dev/pci/pci.c	Wed Sep 15 17:33:08 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: pci.c,v 1.161 2021/08/07 16:19:14 thorpej Exp $	*/
+/*	$NetBSD: pci.c,v 1.162 2021/09/15 17:33:08 thorpej Exp $	*/
 
 /*
  * Copyright (c) 1995, 1996, 1997, 1998
@@ -36,7 +36,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pci.c,v 1.161 2021/08/07 16:19:14 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pci.c,v 1.162 2021/09/15 17:33:08 thorpej Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_pci.h"
@@ -53,6 +53,8 @@ __KERNEL_RCSID(0, "$NetBSD: pci.c,v 1.16
 #include <dev/pci/pcidevs.h>
 #include <dev/pci/ppbvar.h>
 
+#include <dev/pci/pci_calls.h>
+
 #include <net/if.h>
 
 #include "locators.h"
@@ -275,8 +277,7 @@ pci_bus_get_child_devhandle(struct pci_s
 		.tag = tag,
 	};
 
-	if (device_call(sc->sc_dev, "pci-bus-get-child-devhandle",
-			&args) != 0) {
+	if (device_call(sc->sc_dev, PCI_BUS_GET_CHILD_DEVHANDLE(&args)) != 0) {
 		/*
 		 * The call is either not supported or the requested
 		 * device was not found in the platform device tree.

Index: src/sys/dev/pci/pcivar.h
diff -u src/sys/dev/pci/pcivar.h:1.115 src/sys/dev/pci/pcivar.h:1.116
--- src/sys/dev/pci/pcivar.h:1.115	Wed May 12 23:22:33 2021
+++ src/sys/dev/pci/pcivar.h	Wed Sep 15 17:33:08 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: pcivar.h,v 1.115 2021/05/12 23:22:33 thorpej Exp $	*/
+/*	$NetBSD: pcivar.h,v 1.116 2021/09/15 17:33:08 thorpej Exp $	*/
 
 /*
  * Copyright (c) 1996, 1997 Christopher G. Demetriou.  All rights reserved.
@@ -277,31 +277,6 @@ struct pci_softc {
 #define PCI_SC_DEVICESC(d, f) sc_devices[(d) * 8 + (f)]
 };
 
-/*
- * pci-bus-get-child-devhandle device call
- *
- *	Called to get the device handle for a device, represented
- *	by the pcitag_t with the PCI segment represented by the
- *	pci_chipset_tag_t.  The PCI bus's device_t is the one
- *	passed to device_call(), and the device whose handle is
- *	being requested must be a direct child of that bus,
- *	otherwise the behavior is undefined.
- *
- *	Call returns 0 if successful, or an error code upon failure:
- *
- *	ENOTSUP		The device handle implementation for the
- *			PCI bus does not support this device call.
- *
- *	ENODEV		The PCI device represented by the pcitag_t
- *			was not found in a bus-scoped search of the
- *			platform device tree.
- */
-struct pci_bus_get_child_devhandle_args {
-	pci_chipset_tag_t pc;		/* IN */
-	pcitag_t tag;			/* IN */
-	devhandle_t devhandle;		/* OUT */
-};
-
 extern struct cfdriver pci_cd;
 
 extern bool pci_mapreg_map_enable_decode;

Index: src/sys/kern/subr_device.c
diff -u src/sys/kern/subr_device.c:1.8 src/sys/kern/subr_device.c:1.9
--- src/sys/kern/subr_device.c:1.8	Sat Aug  7 18:16:42 2021
+++ src/sys/kern/subr_device.c	Wed Sep 15 17:33:08 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: subr_device.c,v 1.8 2021/08/07 18:16:42 thorpej Exp $	*/
+/*	$NetBSD: subr_device.c,v 1.9 2021/09/15 17:33:08 thorpej Exp $	*/
 
 /*
  * Copyright (c) 2006, 2021 The NetBSD Foundation, Inc.
@@ -27,12 +27,14 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_device.c,v 1.8 2021/08/07 18:16:42 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_device.c,v 1.9 2021/09/15 17:33:08 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/device.h>
 #include <sys/systm.h>
 
+#include <sys/device_calls.h>
+
 /* Root device. */
 device_t			root_device;
 
@@ -285,17 +287,17 @@ device_handle(device_t dev)
 }
 
 int
-device_call(device_t dev, const char *name, void *arg)
+device_call_generic(device_t dev, const struct device_call_generic *gen)
 {
 	devhandle_t handle = device_handle(dev);
 	device_call_t call;
 	devhandle_t call_handle;
 
-	call = devhandle_lookup_device_call(handle, name, &call_handle);
+	call = devhandle_lookup_device_call(handle, gen->name, &call_handle);
 	if (call == NULL) {
 		return ENOTSUP;
 	}
-	return call(dev, call_handle, arg);
+	return call(dev, call_handle, gen->args);
 }
 
 int
@@ -308,5 +310,5 @@ device_enumerate_children(device_t dev,
 		.callback_arg = callback_arg,
 	};
 
-	return device_call(dev, "device-enumerate-children", &args);
+	return device_call(dev, DEVICE_ENUMERATE_CHILDREN(&args));
 }

Index: src/sys/sys/Makefile
diff -u src/sys/sys/Makefile:1.176 src/sys/sys/Makefile:1.177
--- src/sys/sys/Makefile:1.176	Fri Aug 14 00:53:16 2020
+++ src/sys/sys/Makefile	Wed Sep 15 17:33:08 2021
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.176 2020/08/14 00:53:16 riastradh Exp $
+#	$NetBSD: Makefile,v 1.177 2021/09/15 17:33:08 thorpej Exp $
 
 .include <bsd.own.mk>
 
@@ -70,4 +70,10 @@ INCSYMLINKS+=	../soundcard.h ${INCSDIR}/
 namei: namei.src gennameih.awk
 	${TOOL_AWK} -f gennameih.awk < namei.src
 
+device_calls.h: ${.CURDIR}/../kern/device_calls
+	echo "${TOOL_AWK} -f ${.CURDIR}/../kern/gendevcalls.awk \
+	    ${.CURDIR}/../kern/device_calls > ${.CURDIR}/device_calls.h"
+	${TOOL_AWK} -f ${.CURDIR}/../kern/gendevcalls.awk \
+	    ${.CURDIR}/../kern/device_calls > ${.CURDIR}/device_calls.h
+
 .include <bsd.kinc.mk>

Index: src/sys/sys/device.h
diff -u src/sys/sys/device.h:1.174 src/sys/sys/device.h:1.175
--- src/sys/sys/device.h:1.174	Sun Aug 15 22:08:01 2021
+++ src/sys/sys/device.h	Wed Sep 15 17:33:08 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: device.h,v 1.174 2021/08/15 22:08:01 thorpej Exp $ */
+/* $NetBSD: device.h,v 1.175 2021/09/15 17:33:08 thorpej Exp $ */
 
 /*
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -791,21 +791,20 @@ device_t	shutdown_next(struct shutdown_s
  * the device autoconfiguration subsystem.  It is the responsibility
  * of each device tree back end to implement these calls.
  *
- * device-enumerate-children
- *
- *	Enumerates the direct children of a device, invoking the
- *	callback for each one.  The callback is passed the devhandle_t
- *	corresponding to the child device, as well as a user-supplied
- *	argument.  If the callback returns true, then enumeration
- *	continues.  If the callback returns false, enumeration is stopped.
+ * We define a generic interface; individual device calls feature
+ * type checking of the argument structure.  The argument structures
+ * and the call binding data are automatically generated from device
+ * call interface descriptions by gendevcalls.awk.
  */
-
-struct device_enumerate_children_args {
-	bool	(*callback)(device_t, devhandle_t, void *);
-	void *	callback_arg;
+struct device_call_generic {
+	const char *name;
+	void *args;
 };
 
-int		device_call(device_t, const char *, void *);
+int	device_call_generic(device_t, const struct device_call_generic *);
+
+#define	device_call(dev, call)						\
+	device_call_generic((dev), &(call)->generic)
 
 #endif /* _KERNEL */
 

Added files:

Index: src/sys/dev/pci/pci_calls.h
diff -u /dev/null src/sys/dev/pci/pci_calls.h:1.1
--- /dev/null	Wed Sep 15 17:33:09 2021
+++ src/sys/dev/pci/pci_calls.h	Wed Sep 15 17:33:08 2021
@@ -0,0 +1,90 @@
+/*	$NetBSD: pci_calls.h,v 1.1 2021/09/15 17:33:08 thorpej Exp $	*/
+
+/*
+ * THIS FILE IS AUTOMATICALLY GENERATED.  DO NOT EDIT.
+ *
+ * generated from:
+ *	NetBSD: pci_calls,v 1.1 2021/09/15 17:26:07 thorpej Exp
+ */
+
+/*-
+ * Copyright (c) 2021 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jason R. Thorpe.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * Device calls used by the PCI subsystem.
+ */
+
+#ifndef _PCI_CALLS_H_
+#define _PCI_CALLS_H_
+
+#include <sys/device.h>
+
+#include <dev/pci/pcivar.h>
+
+/*
+ * pci-bus-get-child-devhandle
+ *
+ * Retrieve the devhandle for the PCI device represented by 'tag'
+ * in the PCI segment represented by 'pc'.  The PCI bus's device_t
+ * is the one that's passed in the call, and the device whose handle
+ * is being requested must be a direct child of that bus, otherwise
+ * behavior is undefined.
+ *
+ * Call returns 0 if successful, or an error code upon failure:
+ *
+ * ENOTSUP	The device handle implementation for the
+ *		PCI bus does not support this device call.
+ *
+ * ENODEV	The PCI device represented by the pcitag_t
+ *		was not found in a bus-scoped search of the
+ *		platform device tree.
+ */
+struct pci_bus_get_child_devhandle_args {
+	pci_chipset_tag_t pc;		/* IN */
+	pcitag_t tag;			/* IN */
+	devhandle_t devhandle;		/* OUT */
+};
+
+union pci_bus_get_child_devhandle_binding {
+	struct device_call_generic generic;
+	struct {
+		const char *name;
+		struct pci_bus_get_child_devhandle_args *args;
+	} binding;
+};
+
+#define PCI_BUS_GET_CHILD_DEVHANDLE_STR "pci-bus-get-child-devhandle"
+
+#define PCI_BUS_GET_CHILD_DEVHANDLE(_args_) \
+	&((const union pci_bus_get_child_devhandle_binding){ \
+		.binding.name = "pci-bus-get-child-devhandle", \
+		.binding.args = (_args_), \
+	})
+
+#endif /* _PCI_CALLS_H_ */

Index: src/sys/sys/device_calls.h
diff -u /dev/null src/sys/sys/device_calls.h:1.1
--- /dev/null	Wed Sep 15 17:33:09 2021
+++ src/sys/sys/device_calls.h	Wed Sep 15 17:33:08 2021
@@ -0,0 +1,78 @@
+/*	$NetBSD: device_calls.h,v 1.1 2021/09/15 17:33:08 thorpej Exp $	*/
+
+/*
+ * THIS FILE IS AUTOMATICALLY GENERATED.  DO NOT EDIT.
+ *
+ * generated from:
+ *	NetBSD: device_calls,v 1.1 2021/09/15 17:26:06 thorpej Exp
+ */
+
+/*-
+ * Copyright (c) 2021 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jason R. Thorpe.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * Device calls used by the device autoconfiguration subsystem
+ */
+
+#ifndef _DEVICE_CALLS_H_
+#define _DEVICE_CALLS_H_
+
+#include <sys/device.h>
+
+/*
+ * device-enumerate-children
+ *
+ * Enumerates the direct children of a device, invoking the callback for
+ * each one.  The callback is passed the devhandle_t corresponding to the
+ * child device, as well as a user-supplied argument.  If the callback
+ * returns true, then enumeration continues.  If the callback returns false,
+ * enumeration is stopped.
+ */
+struct device_enumerate_children_args {
+	bool	(*callback)(device_t, devhandle_t, void *);
+	void *	callback_arg;
+};
+
+union device_enumerate_children_binding {
+	struct device_call_generic generic;
+	struct {
+		const char *name;
+		struct device_enumerate_children_args *args;
+	} binding;
+};
+
+#define DEVICE_ENUMERATE_CHILDREN_STR "device-enumerate-children"
+
+#define DEVICE_ENUMERATE_CHILDREN(_args_) \
+	&((const union device_enumerate_children_binding){ \
+		.binding.name = "device-enumerate-children", \
+		.binding.args = (_args_), \
+	})
+
+#endif /* _DEVICE_CALLS_H_ */

Reply via email to