Skip to content

Commit e64dc40

Browse files
committed
Introduce the notion of a "system default" device call provider. This
is useful on a platform like sparc, where a single booted kernel can support OpenFirmware, pre-OFW OpenBOOT, or the "old ROM" universe that does not have a platform device tree, but has platform-specific logic for handling some kinds of device properties. The SYSDFLT get a crack if the normal by-handle device call lookup fails.
1 parent a06abdc commit e64dc40

2 files changed

Lines changed: 30 additions & 4 deletions

File tree

sys/kern/subr_device.c

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $NetBSD: subr_device.c,v 1.16 2025/10/04 01:12:15 thorpej Exp $ */
1+
/* $NetBSD: subr_device.c,v 1.17 2025/10/12 23:34:23 thorpej Exp $ */
22

33
/*
44
* Copyright (c) 2006, 2021, 2025 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
2727
*/
2828

2929
#include <sys/cdefs.h>
30-
__KERNEL_RCSID(0, "$NetBSD: subr_device.c,v 1.16 2025/10/04 01:12:15 thorpej Exp $");
30+
__KERNEL_RCSID(0, "$NetBSD: subr_device.c,v 1.17 2025/10/12 23:34:23 thorpej Exp $");
3131

3232
#include <sys/param.h>
3333
#include <sys/device.h>
@@ -122,6 +122,27 @@ devhandle_compare(devhandle_t handle1, devhandle_t handle2)
122122
return 0;
123123
}
124124

125+
/* There has to be at last one entry per link set. */
126+
static const struct device_call_descriptor sysdflt_dummy_descriptor;
127+
_DEVICE_CALL_REGISTER(sysdflt_device_calls, sysdflt_dummy)
128+
129+
static device_call_t
130+
sysdflt_lookup_device_call(devhandle_t handle, const char *name,
131+
devhandle_t *call_handlep)
132+
{
133+
__link_set_decl(sysdflt_device_calls, struct device_call_descriptor);
134+
struct device_call_descriptor * const *desc;
135+
136+
__link_set_foreach(desc, sysdflt_device_calls) {
137+
/* NULL check is for the dummy descriptor. */
138+
if ((*desc)->name != NULL &&
139+
strcmp((*desc)->name, name) == 0) {
140+
return (*desc)->call;
141+
}
142+
}
143+
return NULL;
144+
}
145+
125146
device_call_t
126147
devhandle_lookup_device_call(devhandle_t handle, const char *name,
127148
devhandle_t *call_handlep)
@@ -144,7 +165,9 @@ devhandle_lookup_device_call(devhandle_t handle, const char *name,
144165
}
145166
}
146167
}
147-
return NULL;
168+
169+
/* Last chance: Check to see if a system default has been registered. */
170+
return sysdflt_lookup_device_call(handle, name, call_handlep);
148171
}
149172

150173
void

sys/sys/device.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $NetBSD: device.h,v 1.191 2025/10/03 14:02:10 thorpej Exp $ */
1+
/* $NetBSD: device.h,v 1.192 2025/10/12 23:34:23 thorpej Exp $ */
22

33
/*
44
* Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -235,6 +235,9 @@ static const struct device_call_descriptor __CONCAT(_c_,_descriptor) = {\
235235
}; \
236236
_DEVICE_CALL_REGISTER(_g_, _c_)
237237

238+
#define SYSDFLT_DEVICE_CALL_REGISTER(_n_, _c_) \
239+
DEVICE_CALL_REGISTER(sysdflt_device_calls, _n_, _c_)
240+
238241
struct devhandle_impl {
239242
devhandle_type_t type;
240243
const struct devhandle_impl * super;

0 commit comments

Comments
 (0)