Doudts in "softc" and "device_get_softc(dev)"

Michael M. Press deathjestr at gmail.com
Mon Feb 19 17:54:30 UTC 2007


>
> sizeof(struct xx_softc ) is 68
> sizeof(struct xx_if_softc ) is 1186
>

The softc structures are not, in general, of a fixed size. They may be
of different sizes
for different types of devices.

>
>      struct xx_softc    *sc;
>      struct xx_if_softc *if_sc;
>
>      sc_if = device_get_softc(dev);
>      sc = device_get_softc(device_get_parent(dev));
>
>      sc_if-> .....
>      sc-> ....
>
> Both allocation uses the same function. How it
> possible ?  can we
> access
> all structure member ?
>

device_get_softc returns a pointer to the device's softc structure.
This function probably
isn't aware of what the softc structure itself looks like, but it
doesn't need to be. If it
needed to copy the structure it would need to know its size, but it is
not copying it, it
is only returning a pointer to it. You can access all members of the
structure returned
to you by device_get_softc.


More information about the freebsd-drivers mailing list