Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is dev_id parameter in request_irq?

In the function declaration

int request_irq(unsigned int irq,
                irqreturn_t (*handler)(int, void *, struct pt_regs *),
                unsigned long irqflags,
                const char *devname,
                void *dev_id);

Is dev_id an 'in' parameter or an 'out' parameter ? Where do we get this number from ?

like image 981
Sagar Jain Avatar asked Oct 01 '22 06:10

Sagar Jain


1 Answers

Dev_id is an input argument and must be globally unique. Normally the address of the device data structure is used as the Dev_id.
It has value NULL if the interrupt line is NOT shared. It holds relevance only when the interrupt line is being shared. When it is shared, this parameter uniquely identifies the interrupt handler on the shared IRQ.

But lately in order to process interrupts faster, the linux kernel has moved to request_threaded_irq.

For eg, in the linux kernel, i2c driver for wm8903 audio codec uses this API in the following manner - using request_threaded_irq() but use of dev_id is identical.

the device struct is:

117 struct wm8903_priv {
118         struct wm8903_platform_data *pdata;
119         struct device *dev;
120         struct snd_soc_codec *codec;
121         struct regmap *regmap;
122 
123         int sysclk;
124         int irq;
125 
126         int fs;
127         int deemph;
128 
129         int dcs_pending;
130         int dcs_cache[4];
131 
132         /* Reference count */
133         int class_w_users;
134 
135         struct snd_soc_jack *mic_jack;
136         int mic_det;
137         int mic_short;
138         int mic_last_report;
139         int mic_delay;
140 
141 #ifdef CONFIG_GPIOLIB
142         struct gpio_chip gpio_chip;
143 #endif
144 };

The handler defines a pointer to this struct:

2029         struct wm8903_priv *wm8903; //this is the dev_id parameter

And then calls the request_threaded_irq(),

 ret = request_threaded_irq(i2c->irq, NULL, wm8903_irq,
2156                                            trigger | IRQF_ONESHOT,
2157                                            "wm8903", wm8903);

lxr code

like image 104
brokenfoot Avatar answered Oct 13 '22 12:10

brokenfoot