Yes, the buffer buffer will work.
You just need to fill the buffer from the interrupt handler, and you will read it from the my_read .
A truly naive and really really ineffective implementation can be (untested):
static irqreturn_t irq_handler(int irq, void *dev_id) { struct my_dev *dev = dev_id; buf[buf_wr] = read_device(dev); buf_wr++; if (buf_wr >= BUFSIZE) buf_wr = 0; wake_up(&wq); return IRQ_HANDLED; } static ssize_t my_read(struct file *file, char __user *ubuf, size_t sz, loff_t *ppos) { int n, ret; ret = wait_event_interruptible(wq, buf_wr != buf_rd); if (ret) return ret; n = buf_wr - buf_rd; if (n < 0) n += BUFSIZE; n = min(count, n); ret = copy_to_user(ubuf, buf, n); buf_rd += n; if (buf_rd >= BUFSIZE) buf_rd -= BUFSIZE; if (ret) return ret; *ppos += n; return 1; }
You can also use DMA or mmap or both to get something more efficient.
source share