I have a device driver I am working on. It works this way:
1. User app sends ioctl cmd 0x01 to driver that puts it to sleep.
2. User app sends another ioctl cmd 0x02 to driver that wakes it up.
I am doing this because my hardware is not ready, so I don't have a device to talk to yet.
Issue: When I send ioctl cmd 0x01 to put the driver to sleep, my user app sleeps/hangs but when I send ioctl cmd 0x02, it does not get signaled to wake up. I print out the semaphore count to see whats going on and notice that for each case, my_sem.count == 0 before the call to down()/up().
In general what is it about drivers I don't understand? It appears that my ioctl handler has a different copy of my_sem for every ioctl cmd I send with my user app. When I send several consecutive cmds for up(), I expect to see the count increase for every ioctl cmd that calls up(), but it always prints out ZERO before up() and ONE after up().
/* PSEUDO CODE */
// global defn
DEFINE_SEMAPHORE(my_sem);
.
.
.
// file ops ioctl handler
int foo_CharIoctl(struct file * file,
unsigned int cmd,
unsigned long arg)
{
sema_init(&my_sem, 0);
.
.
.
switch(cmd)
{
case 0x01:
printf my_sem.count;
down_killable(&my_sem);
printf my_sem.count;
case 0x02:
printf my_sem.count;
up(&my_sem);
printf my_sem.count;
...
}
}