Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/thorpej-i2c-spi-conf2]: src/sys/sys Add a devhandle_subclass() helper fu...



details:   https://anonhg.NetBSD.org/src/rev/f2e485dd2298
branches:  thorpej-i2c-spi-conf2
changeset: 985865:f2e485dd2298
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Sat Sep 11 17:22:35 2021 +0000

description:
Add a devhandle_subclass() helper function to simplify the common case
and use it.  Improve some comments.

diffstat:

 sys/arch/macppc/dev/cuda.c           |  19 +++++++------------
 sys/arch/macppc/dev/ki2c.c           |   6 +++---
 sys/arch/sparc64/sparc64/ofw_patch.c |  12 +++++-------
 sys/kern/subr_device.c               |  20 ++++++++++++++++++--
 sys/sys/device.h                     |   5 ++++-
 5 files changed, 37 insertions(+), 25 deletions(-)

diffs (160 lines):

diff -r 14373fa547bc -r f2e485dd2298 sys/arch/macppc/dev/cuda.c
--- a/sys/arch/macppc/dev/cuda.c        Sat Sep 11 15:22:57 2021 +0000
+++ b/sys/arch/macppc/dev/cuda.c        Sat Sep 11 17:22:35 2021 +0000
@@ -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 @@
        }
 
        /*
-        * 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;
diff -r 14373fa547bc -r f2e485dd2298 sys/arch/macppc/dev/ki2c.c
--- a/sys/arch/macppc/dev/ki2c.c        Sat Sep 11 15:22:57 2021 +0000
+++ b/sys/arch/macppc/dev/ki2c.c        Sat Sep 11 17:22:35 2021 +0000
@@ -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 @@
        }
 
        /*
-        * 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);
diff -r 14373fa547bc -r f2e485dd2298 sys/arch/sparc64/sparc64/ofw_patch.c
--- a/sys/arch/sparc64/sparc64/ofw_patch.c      Sat Sep 11 15:22:57 2021 +0000
+++ b/sys/arch/sparc64/sparc64/ofw_patch.c      Sat Sep 11 17:22:35 2021 +0000
@@ -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 @@
        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);
 }
 
diff -r 14373fa547bc -r f2e485dd2298 sys/kern/subr_device.c
--- a/sys/kern/subr_device.c    Sat Sep 11 15:22:57 2021 +0000
+++ b/sys/kern/subr_device.c    Sat Sep 11 17:22:35 2021 +0000
@@ -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 @@
 }
 
 /*
+ * 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.
  */
 
diff -r 14373fa547bc -r f2e485dd2298 sys/sys/device.h
--- a/sys/sys/device.h  Sat Sep 11 15:22:57 2021 +0000
+++ b/sys/sys/device.h  Sat Sep 11 17:22:35 2021 +0000
@@ -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 @@
 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 *);



Home | Main Index | Thread Index | Old Index