Module Name: src
Committed By: thorpej
Date: Sat Sep 11 17:22:36 UTC 2021
Modified Files:
src/sys/arch/macppc/dev [thorpej-i2c-spi-conf2]: cuda.c ki2c.c
src/sys/arch/sparc64/sparc64 [thorpej-i2c-spi-conf2]: ofw_patch.c
src/sys/kern [thorpej-i2c-spi-conf2]: subr_device.c
src/sys/sys [thorpej-i2c-spi-conf2]: device.h
Log Message:
Add a devhandle_subclass() helper function to simplify the common case
and use it. Improve some comments.
To generate a diff of this commit:
cvs rdiff -u -r1.29.2.4 -r1.29.2.5 src/sys/arch/macppc/dev/cuda.c
cvs rdiff -u -r1.32.2.3 -r1.32.2.4 src/sys/arch/macppc/dev/ki2c.c
cvs rdiff -u -r1.7.14.4 -r1.7.14.5 src/sys/arch/sparc64/sparc64/ofw_patch.c
cvs rdiff -u -r1.8 -r1.8.2.1 src/sys/kern/subr_device.c
cvs rdiff -u -r1.173 -r1.173.2.1 src/sys/sys/device.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/macppc/dev/cuda.c
diff -u src/sys/arch/macppc/dev/cuda.c:1.29.2.4 src/sys/arch/macppc/dev/cuda.c:1.29.2.5
--- src/sys/arch/macppc/dev/cuda.c:1.29.2.4 Sat Sep 11 15:22:57 2021
+++ src/sys/arch/macppc/dev/cuda.c Sat Sep 11 17:22:35 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: cuda.c,v 1.29.2.4 2021/09/11 15:22:57 thorpej Exp $ */
+/* $NetBSD: cuda.c,v 1.29.2.5 2021/09/11 17:22:35 thorpej Exp $ */
/*-
* Copyright (c) 2006 Michael Lorenz
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cuda.c,v 1.29.2.4 2021/09/11 15:22:57 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cuda.c,v 1.29.2.5 2021/09/11 17:22:35 thorpej Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -307,17 +307,12 @@ cuda_attach(device_t parent, device_t se
}
/*
- * Normally the i2c bus instance would automatically inherit
- * our devhandle, but we provide our own i2c device enumeration
- * method, so we need to supply the bus instance with our own
- * device handle implementation, using the one we got from
- * OpenFirmware as the "super".
+ * Subclass our device handle so we can override
+ * "i2c-enumerate-devices" and give that to the
+ * i2c bus instance.
*/
- devhandle_t devhandle = devhandle_from_of(sc->sc_node);
- devhandle_impl_inherit(&sc->sc_devhandle_impl, devhandle.impl);
- sc->sc_devhandle_impl.lookup_device_call =
- cuda_devhandle_lookup_device_call;
- devhandle.impl = &sc->sc_devhandle_impl;
+ devhandle_t devhandle = devhandle_subclass(device_handle(self),
+ &sc->sc_devhandle_impl, cuda_devhandle_lookup_device_call);
iic_tag_init(&sc->sc_i2c);
sc->sc_i2c.ic_cookie = sc;
Index: src/sys/arch/macppc/dev/ki2c.c
diff -u src/sys/arch/macppc/dev/ki2c.c:1.32.2.3 src/sys/arch/macppc/dev/ki2c.c:1.32.2.4
--- src/sys/arch/macppc/dev/ki2c.c:1.32.2.3 Sat Sep 11 14:47:06 2021
+++ src/sys/arch/macppc/dev/ki2c.c Sat Sep 11 17:22:35 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: ki2c.c,v 1.32.2.3 2021/09/11 14:47:06 thorpej Exp $ */
+/* $NetBSD: ki2c.c,v 1.32.2.4 2021/09/11 17:22:35 thorpej Exp $ */
/* Id: ki2c.c,v 1.7 2002/10/05 09:56:05 tsubai Exp */
/*-
@@ -381,8 +381,8 @@ ki2c_attach(device_t parent, device_t se
}
/*
- * Set up our handle implementation (we provide our own
- * i2c enumeration call).
+ * Set up our handle implementation so that we can override
+ * "i2c-enumerate-devices".
*/
devhandle = device_handle(self);
devhandle_impl_inherit(&sc->sc_devhandle_impl, devhandle.impl);
Index: src/sys/arch/sparc64/sparc64/ofw_patch.c
diff -u src/sys/arch/sparc64/sparc64/ofw_patch.c:1.7.14.4 src/sys/arch/sparc64/sparc64/ofw_patch.c:1.7.14.5
--- src/sys/arch/sparc64/sparc64/ofw_patch.c:1.7.14.4 Sat Sep 11 13:02:29 2021
+++ src/sys/arch/sparc64/sparc64/ofw_patch.c Sat Sep 11 17:22:36 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: ofw_patch.c,v 1.7.14.4 2021/09/11 13:02:29 thorpej Exp $ */
+/* $NetBSD: ofw_patch.c,v 1.7.14.5 2021/09/11 17:22:36 thorpej Exp $ */
/*-
* Copyright (c) 2020, 2021 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ofw_patch.c,v 1.7.14.4 2021/09/11 13:02:29 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ofw_patch.c,v 1.7.14.5 2021/09/11 17:22:36 thorpej Exp $");
#include <sys/param.h>
#include <sys/kmem.h>
@@ -163,17 +163,15 @@ add_i2c_devices(device_t dev, const stru
devhandle_t devhandle = device_handle(dev);
fixup->i2c_super_handle = devhandle;
- /* Sub-class the devhandle_impl. */
- devhandle_impl_inherit(&fixup->i2c_devhandle_impl, devhandle.impl);
- fixup->i2c_devhandle_impl.lookup_device_call =
- i2c_fixup_lookup_device_call;
+ /* Sub-class it so we can override "i2c-enumerate-devices". */
+ devhandle = devhandle_subclass(devhandle, &fixup->i2c_devhandle_impl,
+ i2c_fixup_lookup_device_call);
/*
* ...and slide that on into the device. This handle will be
* passed on to the iic bus instance, and our enumeration method
* will get called to enumerate the child devices.
*/
- devhandle.impl = &fixup->i2c_devhandle_impl;
device_set_handle(dev, devhandle);
}
Index: src/sys/kern/subr_device.c
diff -u src/sys/kern/subr_device.c:1.8 src/sys/kern/subr_device.c:1.8.2.1
--- src/sys/kern/subr_device.c:1.8 Sat Aug 7 18:16:42 2021
+++ src/sys/kern/subr_device.c Sat Sep 11 17:22:36 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.8.2.1 2021/09/11 17:22:36 thorpej Exp $ */
/*
* Copyright (c) 2006, 2021 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
*/
#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.8.2.1 2021/09/11 17:22:36 thorpej Exp $");
#include <sys/param.h>
#include <sys/device.h>
@@ -106,6 +106,22 @@ devhandle_impl_inherit(struct devhandle_
}
/*
+ * Helper function that provides a short-hand method of the common
+ * "subclass a device handle" flow.
+ */
+devhandle_t
+devhandle_subclass(devhandle_t handle,
+ struct devhandle_impl *new_impl,
+ device_call_t (*new_lookup)(devhandle_t, const char *, devhandle_t *))
+{
+ devhandle_impl_inherit(new_impl, handle.impl);
+ new_impl->lookup_device_call = new_lookup;
+ handle.impl = new_impl;
+
+ return handle;
+}
+
+/*
* Accessor functions for the device_t type.
*/
Index: src/sys/sys/device.h
diff -u src/sys/sys/device.h:1.173 src/sys/sys/device.h:1.173.2.1
--- src/sys/sys/device.h:1.173 Sat Aug 7 18:16:42 2021
+++ src/sys/sys/device.h Sat Sep 11 17:22:36 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: device.h,v 1.173 2021/08/07 18:16:42 thorpej Exp $ */
+/* $NetBSD: device.h,v 1.173.2.1 2021/09/11 17:22:36 thorpej Exp $ */
/*
* Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -670,6 +670,9 @@ devhandle_t device_handle(device_t);
bool devhandle_is_valid(devhandle_t);
void devhandle_invalidate(devhandle_t *);
devhandle_type_t devhandle_type(devhandle_t);
+devhandle_t devhandle_subclass(devhandle_t, struct devhandle_impl *,
+ device_call_t (*)(devhandle_t, const char *,
+ devhandle_t *));
device_call_t devhandle_lookup_device_call(devhandle_t, const char *,
devhandle_t *);