Subject: Re: sysctl: How to get softc address in a helper function?
To: TAMURA Kent <kent@NetBSD.org>
From: Andrew Brown <atatat@atatdot.net>
List: tech-kern
Date: 10/24/2004 20:32:37
On Sun, Oct 24, 2004 at 03:35:02PM +0900, TAMURA Kent wrote:
>How to get softc address in a sysctl helper function? I'm
>trying to implement per-device-instance sysctl items (not
>per-device-driver like ath and bge.)
pass the softc address to the createv call?
>The foo_attach() function creates a node and leaf items, and
>saves their MIB numbers into a softc instance. To check values
>in a helper function, we need to refer the softc to determine
>which sysctl item is processed. I have no idea how to pass the
>softc address to the helper function.
>
>
>The following is a dirty hacking code using sysctlnode::__rsvd.
>Of course, I don't commit it.
doe this work?
--------------------------------
/* sysctl setup */
err = sysctl_createv(NULL, 0, NULL, NULL, 0,
CTLTYPE_NODE, "hw", NULL, NULL, 0, NULL, 0,
CTL_HW, CTL_EOL);
if (err != 0)
goto sysctl_err;
err = sysctl_createv(NULL, 0, NULL, &node, 0,
CTLTYPE_NODE, sc->sc_dev.dv_xname, NULL, NULL, 0,
NULL, 0, CTL_HW, CTL_CREATE, CTL_EOL);
if (err != 0)
goto sysctl_err;
node_mib = node->sysctl_num;
err = sysctl_createv(NULL, 0, NULL, &node, CTLFLAG_READWRITE,
CTLTYPE_INT, "ac97rate",
SYSCTL_DESCR("AC'97 link rate; normal value is 48000"),
auich_sysctl_verify, 0, sc, 0,
CTL_HW, node_mib, CTL_CREATE, CTL_EOL);
if (err != 0)
goto sysctl_err;
--------------------------------
static int
auich_sysctl_verify(SYSCTLFN_ARGS)
{
int error, t;
struct sysctlnode node;
struct auich_softc *sc;
node = *rnode;
sc = node.sysctl_data;
t = sc->sc_ac97_clock;
node.sysctl_data = &t;
error = sysctl_lookup(SYSCTLFN_CALL(&node));
if (error || newp == NULL)
return error;
if (t < 48000 || t > 96000)
return EINVAL;
sc->sc_ac97_clock = t;
return 0;
}
--------------------------------
note that you don't need to track the mib number of you're not going
to handle more than one type of request with the helper, and that you
can use sysctl_data to hold the address of the softc.
--
|-----< "CODE WARRIOR" >-----|
codewarrior@daemon.org * "ah! i see you have the internet
twofsonet@graffiti.com (Andrew Brown) that goes *ping*!"
werdna@squooshy.com * "information is power -- share the wealth."