How to designate parameter array to the driver module?
John Baldwin
jhb at freebsd.org
Thu Apr 29 12:46:26 UTC 2010
On Wednesday 28 April 2010 6:25:32 am KGB wrote:
> Hi all:
> I want to designate parameter array to the driver module.In linux ,I
can the MACRO module_param_array. So I want to know similar approach in
freeBSD 7?
>
> Can someone give me advice?
>
> Thanks in advance.
In FreeBSD settings are passed to kernel modules via tunable strings set in
the kernel environment (either via /boot/loader.conf or using kenv(1)). You
can then fetch these settings in a module via the TUNABLE_* macros. For
example:
/* Number of widgets for each foo device. */
static int foo_widgets = DEFAULT_WIDGET_COUNT;
TUNABLE_INT("hw.foo.widgets", &foo_widgets);
A user can then override the default value by setting 'hw.foo.widgets=N' in
the kernel environment. If you wish the value to also be tunable at runtime
then you can expose it via sysctl as well. It is generally a good idea to do
report tunables via read-only sysctls even if they aren't adjustable at
runtime, thus:
SYSCTL_NODE(_hw, OID_AUTO, foo, CTLFLAG_RD, NULL, "foo driver settings");
/* Number of widgets for each foo device. */
static int foo_widgets = DEFAULT_WIDGET_COUNT;
TUNABLE_INT("hw.foo.widgets", &foo_widgets);
SYSCTL_INT(_hw_foo, OID_AUTO, widgets, CTLFLAG_RDTUN, &foo_widgets, 0,
"Number of widgets for each foo device");
If you need to pass in more complex data structures than simple settings then
the approach may depend on what sort of data you are loading. If you wish to
load a chunk of firmware, then you can use the firmware(9) interface which
will let you store the firmware in a separate kernel module that can be loaded
from the boot loader or on-demand at runtime.
--
John Baldwin
More information about the freebsd-drivers
mailing list