Handler function

The prototype of the minidriver handler function is:

int my_handler (int state, void *data);

The arguments are:

state
Indicates when the handler is being called. It can have one of the following values, defined in <sys/syspage.h>, and presented here in chronological order:
  • MDRIVER_INIT: The driver is being initialized. The handler is called with this state only once, when you register the handler by calling mdriver_add().
  • MDRIVER_STARTUP: The driver is being called from somewhere in startup.
  • MDRIVER_STARTUP_PREPARE: Preparations must take place for minidriver operation outside the startup environment.
  • MDRIVER_STARTUP_FINI: The last call to the driver from within the startup.
  • MDRIVER_KERNEL: The driver is being called during kernel initialization.
  • MDRIVER_PROCESS: The driver is being called during process manager/system initialization.
  • MDRIVER_INTR_ATTACH: A process is calling InterruptAttach() or InterruptAttachEvent() with the same interrupt number as the minidriver is attached to. If you want the full driver to take over processing the interrupt, the minidriver handler should return 1 to indicate that it wants to exit.
data
The virtual address of the data area, converted from the physical address that you provided as the data_paddr parameter to mdriver_add().
Note: If you're working with an ARM platform, your minidriver handler function must be written as Position Independent Code (PIC). This means that when your handler is in the MDRIVER_KERNEL, MDRIVER_PROCESS, or MDRIVER_INTR_ATTACH state, you must not use global or static variables.

The handler function should return:

Don't assume that just because the handler has been called that the device actually needs servicing.