0

I have a Linux driver where there are many interrupts to be handled by a single tasklet function.

I want to register the same tasklet for all of them but change its behavior according to which irq it was received on. Can I do this?

Is there an alternative solution that you know of?

Please do not suggest to declare the parameter during DECLARE_TASKLET() I already know this does not work as the value is static and not passed by the irq handler.

artless noise
  • 21,212
  • 6
  • 68
  • 105
user627119
  • 163
  • 1
  • 11

1 Answers1

1

I got this solved by using workqueues.

Each interrupt handler receives a different instance of a data structure, the one that has been registered during request_irq().

The structure contains a work_struct as one of its fields.

You define multiple work_structs, for each irq.

You call the workqueue function by calling INIT_WORK() from the irq handler, passing the work struct field as an argument, which is part of the original structure.

The workqueue function then uses

container_of(work_struct_ptr, struct your_original_struct, work_struct_fieldname);

to obtain the instance of your data for that particular workqueue call.

In conclusion, this way you can have multiple interrupt lines, being serviced by same interrupt handler, same workqueue function, but working on different data structures.

Hope this helps.

user627119
  • 163
  • 1
  • 11