You have an instance of your softc structure for each instance of your device. That would usually have a mutex. You can use the si_drv1
member of the cdev
to keep a pointer back to the softc
. Something like:
struct mydev_softc {
struct mtx m_lock;
struct cdev* m_cdev;
device_t m_dev;
/* ... whatever else you need ... */
};
static int mydev_attach(device_t dev)
{
struct mydev_softc* sc = device_get_softc(dev);
mtx_init(&sc->m_lock);
sc->m_cdev = make_dev(...);
sc->m_cdev->si_drv1 = sc;
sc->m_dev = dev;
/* Plus whatever else you need */
}
I have left out all the other driver initialisation stuff so you can see this part.