Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 29 Apr 2010 07:53:34 -0400
From:      John Baldwin <jhb@freebsd.org>
To:        freebsd-drivers@freebsd.org
Subject:   Re: How to designate parameter array to the driver module?
Message-ID:  <201004290753.34712.jhb@freebsd.org>
In-Reply-To: <tencent_0F6A26E91F1921DA3353827F@qq.com>
References:  <tencent_0F6A26E91F1921DA3353827F@qq.com>

next in thread | previous in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201004290753.34712.jhb>