[email protected] (Kengo NAKAHARA) writes:

>Currently(after cryptosoft.c:r1.44), software encryption driver
>(swcrypto0) is initialized twice, that is, swcr_init() is called
>below two call paths.
>    (1) swcrypto_attach()
>        <= called from module initialization
>    (2) swcryptoattach()
>        <= called from autoconf(9) initialization

>Hmm, compare with pseudo interfaces like gif(4), It seems the
>swcryptoattach() should do nothing.


In this case, yes.

Modules have their own module info data structures compiled by the
linker, for a builtin module their modcmd function is called in
module_init_class().

pseudo devices have no bus attachment, their attach routines are
compiled by config(1) and called in config_finalize() after all
builtin modules have been initialized.

A run-time loaded module gets its modcmd function called much
later in module_load().


A modular pseudo device driver can take two paths:

1. augment pre-modular structure

xxxattach(num) {
        /* do initialization as pseudo-device */
}

modcmd(cmd, arg) {
        ...
        switch (cmd) {
        case MODULE_CMD_INIT:
#ifdef _MODULE
                /* do initialization */
#endif
                break;
        case MODULE_CMD_FINI:
#ifdef _MODULE
                /* do finalization */
#endif
                break;
        ...
        }
}

2. replace pre-modular initialization

xxxattach(num) {
        /* dummy */
}

modcmd(cmd, arg) {
        switch (cmd) {
        case MODULE_CMD_INIT:
                /* do always initialization here */
                break;
        case MODULE_CMD_FINI:
                /* do always finalization here */
                break;
        ...
        }
}


Most drivers chose the first path, because they need another initialization
for cdevsw/bdevsw which is handled by autoconf when the driver is builtin.
Only as a loaded module, the modcmd() has to handle this part.

3. augment pre-modular structure for a UNIX driver

xxxattach(num) {
        /* do initialization as pseudo-device */
}

modcmd(cmd, arg) {
        ...
        switch (cmd) {
        case MODULE_CMD_INIT:
#ifdef _MODULE
                /* do initialization */
                /* devsw_attach */
#endif
                break;
        case MODULE_CMD_FINI:
#ifdef _MODULE
                /* devsw_detach */
                /* do finalization */
#endif
                break;
        ...
        }
}

-- 
-- 
                                Michael van Elst
Internet: [email protected]
                                "A potential Snark may lurk in every tree."

Reply via email to