Module Name: src Committed By: thorpej Date: Tue Aug 27 13:44:56 UTC 2024
Modified Files: src/sys/kern: subr_device.c src/sys/sys: device.h Log Message: - Remove devhandle_impl_inherit() and re-implement as devhandle_impl_subclass() and a helper devhandle_subclass(). - Add a devhandle_t argument to device_call_generic(); don't imply it from the device; let the device_call() wrapper own that logic. (Ride the bump to 10.99.12; I've been sitting on this change for ages waiting for a version bump to go by.) To generate a diff of this commit: cvs rdiff -u -r1.13 -r1.14 src/sys/kern/subr_device.c cvs rdiff -u -r1.188 -r1.189 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/kern/subr_device.c diff -u src/sys/kern/subr_device.c:1.13 src/sys/kern/subr_device.c:1.14 --- src/sys/kern/subr_device.c:1.13 Mon Mar 28 12:38:59 2022 +++ src/sys/kern/subr_device.c Tue Aug 27 13:44:55 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: subr_device.c,v 1.13 2022/03/28 12:38:59 riastradh Exp $ */ +/* $NetBSD: subr_device.c,v 1.14 2024/08/27 13:44:55 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.13 2022/03/28 12:38:59 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: subr_device.c,v 1.14 2024/08/27 13:44:55 thorpej Exp $"); #include <sys/param.h> #include <sys/device.h> @@ -147,11 +147,28 @@ devhandle_lookup_device_call(devhandle_t } void -devhandle_impl_inherit(struct devhandle_impl *impl, - const struct devhandle_impl *super) +devhandle_impl_subclass(struct devhandle_impl *new_impl, + const struct devhandle_impl *super, + device_call_t (*new_lookup)(devhandle_t, const char *, devhandle_t *)) +{ + new_impl->type = super->type; + new_impl->super = super; + new_impl->lookup_device_call = new_lookup; +} + +/* + * 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 *)) { - memcpy(impl, super, sizeof(*impl)); - impl->super = super; + devhandle_impl_subclass(new_impl, handle.impl, new_lookup); + handle.impl = new_impl; + + return handle; } /* @@ -345,9 +362,9 @@ device_handle(device_t dev) } int -device_call_generic(device_t dev, const struct device_call_generic *gen) +device_call_generic(device_t dev, devhandle_t handle, + const struct device_call_generic *gen) { - devhandle_t handle = device_handle(dev); device_call_t call; devhandle_t call_handle; Index: src/sys/sys/device.h diff -u src/sys/sys/device.h:1.188 src/sys/sys/device.h:1.189 --- src/sys/sys/device.h:1.188 Mon Jan 15 18:15:37 2024 +++ src/sys/sys/device.h Tue Aug 27 13:44:55 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: device.h,v 1.188 2024/01/15 18:15:37 thorpej Exp $ */ +/* $NetBSD: device.h,v 1.189 2024/08/27 13:44:55 thorpej Exp $ */ /* * Copyright (c) 2021 The NetBSD Foundation, Inc. @@ -622,11 +622,16 @@ bool devhandle_is_valid(devhandle_t); devhandle_t devhandle_invalid(void); devhandle_type_t devhandle_type(devhandle_t); int devhandle_compare(devhandle_t, 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 *); -void devhandle_impl_inherit(struct devhandle_impl *, - const struct devhandle_impl *); +void devhandle_impl_subclass(struct devhandle_impl *, + const struct devhandle_impl *, + device_call_t (*)(devhandle_t, const char *, + devhandle_t *)); device_t deviter_first(deviter_t *, deviter_flags_t); void deviter_init(deviter_t *, deviter_flags_t); @@ -717,10 +722,13 @@ struct device_call_generic { void *args; }; -int device_call_generic(device_t, const struct device_call_generic *); +int device_call_generic(device_t, devhandle_t, + const struct device_call_generic *); #define device_call(dev, call) \ - device_call_generic((dev), &(call)->generic) + device_call_generic((dev), device_handle(dev), &(call)->generic) +#define devhandle_call(handle, call) \ + device_call_generic(NULL, (handle), &(call)->generic) #endif /* _KERNEL */