Skip to content

Commit

Permalink
- Remove devhandle_impl_inherit() and re-implement as devhandle_impl_…
Browse files Browse the repository at this point in the history
…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.)
  • Loading branch information
thorpej committed Aug 27, 2024
1 parent 5f1c95d commit a741953
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 13 deletions.
33 changes: 25 additions & 8 deletions sys/kern/subr_device.c
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -147,11 +147,28 @@ devhandle_lookup_device_call(devhandle_t handle, const char *name,
}

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 *))
{
memcpy(impl, super, sizeof(*impl));
impl->super = super;
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 *))
{
devhandle_impl_subclass(new_impl, handle.impl, new_lookup);
handle.impl = new_impl;

return handle;
}

/*
Expand Down Expand Up @@ -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;

Expand Down
18 changes: 13 additions & 5 deletions sys/sys/device.h
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 */

Expand Down

0 comments on commit a741953

Please sign in to comment.