Hi,
I am not sure whether the pull-request mechanism for linux-imx on github works, so I am posting the patch here. If required, I can also open a PR on github.
For our purposes we tried using the SEMA4 driver found in linux-imx, but the driver was not serving our needs, and I believe it was essentially broken, both by design and by implementation.
Identified problems:
- if a remote core was holding a gate, and the driver attempted to lock the gate (and of course failed), there would be no ISR when the remote processor releases the gate. This bug is a consequence of OR-ing the SEMA4_Gaten register instead of a direct value write: driver would try to write 0b11 instead, which is treated as a "no-op".
- Using a spinlock in imx_sema4_mutex_lock can lead to a kernel bug if a caller is not aware that this call is basically converting the context into an atomic one. It also doesn't make sense to lock a global flag when a single gate is being locked.
- The lock/unlock dance in IRQ, followed by a wake_up call, is hard to follow. By the time the caller is woken up and has taken control there are no guarantees we have the gate locked. While this may be okay, I don't think it is a good design to have the caller do trylock or lock again when woken up. Instead, the mutex driver should behave as a standard mutex driver.
This patch ensures that only one user can hold a gate, and it improves IRQ handling from SEMA4 module. There is only a simple lock in the ISR, The code is simplified and made more robust.
Please let me know whether the change is acceptable and whether I need to submit it as a pull request on your github repo.
Cheers,
Sava