Search code examples
operating-systemlinux-device-driverinterrupt-handling

relation between device driver and interrupt handler?


It seems a basic question, but I am confused about what specific work do device driver and interrupt handler do?

In my understanding, a device arises an interrupt, CPU notices it, CPU saves state and jumps to interrupt handler, the handler services the device, CPU resumes processing of previous work. If this procedure is correct, what is the role of a device driver?

I'm new to OS, many thanks.


Solution

  • If this procedure is correct ...

    Yes, it is correct.

    Relation between device driver and interrupt handler?

    The interrupt handler is a part of the device driver.

    ... what is the role of a device driver?

    The device driver contains all code that is required to access a certain device - for example a mouse.

    Let's take a PS/2 mouse as an example:

    Whenever the mouse has some data, an interrupt is triggered. This means that the CPU executes an interrupt handler in the way you described it in your question.

    The interrupt handler is some code (for example a function) in the device driver.

    This function may read the data from the mouse, calculate the cursor position from the data read and store the position in a variable.

    The device driver also contains another function which is called whenever an application asks for information from the device.

    This function may then return the cursor position calculated in the interrupt handler to the application.