3.8.3 Using callbacks
The calls to create an event take two important parameters: the callback and the parameter pointer.
The callback function is invoked when the event occurs. Using callbacks appropriately is not difficult-as long as the following rules are followed:
The parameter pointer can point to any static (not on the stack) structure. The parameter pointer is used to provide state information for the event invocation. The parameter pointer is particularly useful if multiple events must be handled by the same callback.
The callback function, when invoked, may only assume its priority level, its parameter pointer, and that it has a stack. It must derive all context from the parameter pointer and the static data left in its module. This makes writing callbacks somewhat more challenging than normal driver code.
3.8.3.1 Debugging callbacks
Debugging callbacks is a little like debugging interrupt handlers in that one is not always sure when a callback is invoked. Most normal debugging facilities function as expected in callbacks.
There can be a temptation to write one's driver as a series of callbacks. This is not recommended since normal code is easier to debug, and managing a large number of the context structures addressed by parameter pointers becomes difficult to maintain.
TIP: Minimize the use of callbacks. Only use a callback when an operation cannot be implemented as part of UEFI Driver initialization or through a protocol services provided by the UEFI Driver.