From owner-freebsd-drivers@FreeBSD.ORG Thu Apr 29 12:46:26 2010 Return-Path: Delivered-To: freebsd-drivers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 5E2FD106570F for ; Thu, 29 Apr 2010 12:46:26 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from cyrus.watson.org (cyrus.watson.org [65.122.17.42]) by mx1.freebsd.org (Postfix) with ESMTP id 31E358FC17 for ; Thu, 29 Apr 2010 12:46:26 +0000 (UTC) Received: from bigwig.baldwin.cx (66.111.2.69.static.nyinternet.net [66.111.2.69]) by cyrus.watson.org (Postfix) with ESMTPSA id E04CB46B0D; Thu, 29 Apr 2010 08:46:25 -0400 (EDT) Received: from jhbbsd.localnet (smtp.hudson-trading.com [209.249.190.9]) by bigwig.baldwin.cx (Postfix) with ESMTPA id C73608A021; Thu, 29 Apr 2010 08:46:24 -0400 (EDT) From: John Baldwin To: freebsd-drivers@freebsd.org Date: Thu, 29 Apr 2010 07:53:34 -0400 User-Agent: KMail/1.12.1 (FreeBSD/7.3-CBSD-20100217; KDE/4.3.1; amd64; ; ) References: In-Reply-To: MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-15" Content-Transfer-Encoding: 7bit Message-Id: <201004290753.34712.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.0.1 (bigwig.baldwin.cx); Thu, 29 Apr 2010 08:46:24 -0400 (EDT) X-Virus-Scanned: clamav-milter 0.95.1 at bigwig.baldwin.cx X-Virus-Status: Clean X-Spam-Status: No, score=-2.6 required=4.2 tests=AWL,BAYES_00 autolearn=ham version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on bigwig.baldwin.cx Cc: Subject: Re: How to designate parameter array to the driver module? X-BeenThere: freebsd-drivers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Writing device drivers for FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 29 Apr 2010 12:46:26 -0000 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